File size: 1,568 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
import json
import zipfile

from arena.harness import main, run_harness


def test_run_harness_completes_run_and_writes_zip(tmp_path) -> None:
    result = run_harness(
        prompt="Build a tiny CLI",
        criteria=["README explains the project"],
        user_tests=["test -f README.md"],
        archive_root=tmp_path / "archives",
        output_dir=tmp_path / "out",
    )

    assert result.mode == "swarm"
    assert result.run.status == "completed"
    assert result.run.validation_report is not None
    assert result.run.validation_report.passed is True
    assert result.zip_path is not None

    with zipfile.ZipFile(result.zip_path) as zipped:
        assert {"README.md", "app.py", "harness_result.json", "pyproject.toml"}.issubset(
            set(zipped.namelist())
        )
        payload = json.loads(zipped.read("harness_result.json"))

    assert payload["run_id"] == result.run.id
    assert payload["workspace_dir"] == "/workspace"


def test_harness_cli_prints_json_summary_and_zip_path(tmp_path, capsys) -> None:
    exit_code = main([
        "--prompt",
        "Build docs",
        "--criteria",
        "docs exist",
        "--test",
        "test -f harness_result.json",
        "--output-dir",
        str(tmp_path),
    ])

    captured = capsys.readouterr()
    payload = json.loads(captured.out)

    assert exit_code == 0
    assert payload["mode"] == "swarm"
    assert payload["run"]["status"] == "completed"
    assert payload["run"]["validation_report"]["passed"] is True
    assert payload["zip_path"].endswith(".zip")