summaryrefslogtreecommitdiff
path: root/evals/drill/setup.py
blob: 74ea1efcaf4dcc962c5ce65ee6fc21319f579b67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from __future__ import annotations

import subprocess
from pathlib import Path

from setup_helpers import HELPER_REGISTRY
from setup_helpers.base import create_base_repo


def clone_template(template_dir: Path, workdir: Path) -> None:
    """Clone (or build) template_dir into workdir with full git history."""
    create_base_repo(workdir, template_dir)


def run_helpers(helper_names: list[str], workdir: Path, fixtures_dir: Path) -> None:
    for name in helper_names:
        helper = HELPER_REGISTRY.get(name)
        if helper is None:
            raise ValueError(f"Unknown setup helper: {name}")
        if name == "create_base_repo":
            helper(workdir, fixtures_dir / "template-repo")  # ty: ignore[invalid-argument-type, too-many-positional-arguments, missing-argument]
        elif name == "symlink_superpowers":
            import os

            helper(workdir, os.environ["SUPERPOWERS_ROOT"])  # ty: ignore[invalid-argument-type, too-many-positional-arguments, missing-argument]
        else:
            helper(workdir)  # ty: ignore[invalid-argument-type, missing-argument]


def run_assertions(assertions: list[str], workdir: Path) -> None:
    for assertion in assertions:
        result = subprocess.run(
            assertion,
            shell=True,
            cwd=workdir,
            capture_output=True,
            text=True,
        )
        if result.returncode != 0:
            raise AssertionError(
                f"Setup assertion failed: {assertion}\n"
                f"stdout: {result.stdout}\nstderr: {result.stderr}"
            )