File size: 2,502 Bytes
31c8075
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import importlib.util
from pathlib import Path


def load_task_module():
    path = Path(__file__).resolve().parents[1] / "scripts" / "task.py"
    spec = importlib.util.spec_from_file_location("project_task", path)
    assert spec is not None
    module = importlib.util.module_from_spec(spec)
    assert spec.loader is not None
    spec.loader.exec_module(module)
    return module


def test_task_commands_replace_make_targets() -> None:
    task = load_task_module()

    dev, _ = task.command_for("dev")
    gradio, _ = task.command_for("gradio")
    harness, _ = task.command_for("harness")
    test, _ = task.command_for("test")
    verify, _ = task.command_for("verify")
    validator_smoke, _ = task.command_for("validator-smoke")

    assert dev == ["uv", "run", "uvicorn", "app:app", "--host", "127.0.0.1", "--port", "8790"]
    assert gradio == ["uv", "run", "python", "app.py"]
    assert harness == ["uv", "run", "python", "-m", "arena.harness"]
    assert test == ["uv", "run", "pytest", "tests_python"]
    assert verify == []
    assert validator_smoke == ["uv", "run", "python", "-m", "arena.smoke", "validator"]


def test_daytona_validator_smoke_sets_provider_override() -> None:
    task = load_task_module()

    _, env = task.command_for("daytona-validator-smoke")

    assert env == {"VALIDATOR_SANDBOX_PROVIDER": "daytona"}


def test_test_task_replaces_default_target_when_args_are_supplied() -> None:
    task = load_task_module()

    command, _ = task.command_for_invocation("test", ["tests_python/test_task_runner.py", "-q"])

    assert command == ["uv", "run", "pytest"]


def test_verify_runs_tests_then_agent_harness() -> None:
    task = load_task_module()

    commands = task._verify_commands()

    assert commands == [
        (["uv", "run", "pytest", "tests_python"], {}),
        (
            [
                "uv",
                "run",
                "python",
                "-m",
                "arena.harness",
                "--prompt",
                "Build a tiny CLI",
                "--test",
                "test -f README.md",
            ],
            {},
        ),
    ]


def test_dotenv_loader_preserves_existing_env(tmp_path) -> None:
    task = load_task_module()
    env = {"EXISTING": "from-env"}
    env_file = tmp_path / ".env"
    env_file.write_text("EXISTING=from-file\nNEW_VALUE='loaded'\n# ignored\n")

    task._load_dotenv(env_file, env)

    assert env["EXISTING"] == "from-env"
    assert env["NEW_VALUE"] == "loaded"