File size: 3,340 Bytes
b8e3338 | 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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | import json
import pytest
from agentescape_port.adapter import ROOT, generate
@pytest.mark.parametrize("difficulty", [5, 25])
def test_generated_task_is_a_standalone_harbor_snapshot(tmp_path, difficulty):
pytest.importorskip("harbor")
from harbor.models.task.task import Task
from harbor.tasks.client import TaskClient
source = next((ROOT / f"data/questions/{difficulty}/narrative").glob("*.json"))
row = generate(source, tmp_path / "generated")
task = tmp_path / "generated" / row["id"]
isolated = tmp_path / "isolated"
TaskClient()._materialize_task_tree(task, isolated)
import shutil
shutil.rmtree(task)
loaded = Task(isolated)
assert loaded.config.metadata["scenario_sha256"] == row["scenario_sha256"]
assert (
isolated / "environment/puzzle/scenario.json"
).read_bytes() == source.read_bytes()
assert (isolated / "solution/scenario.json").read_bytes() == source.read_bytes()
assert all(not p.is_symlink() for p in isolated.rglob("*"))
assert (
"RUN mkdir -p /evidence && chmod 0755 /evidence"
in (isolated / "environment/puzzle/Dockerfile").read_text()
)
for relative in [
"environment/agent/cli.py",
"environment/puzzle/service.py",
"environment/puzzle/worker.py",
"environment/puzzle/child.py",
"environment/puzzle/upstream/simulator.py",
"solution/oracle.py",
"tests/grade.py",
"tests/Dockerfile",
]:
assert (isolated / relative).is_file()
def test_catalog_matches_source_scenarios():
from agentescape_port.adapter import digest, task_id
rows = json.loads((ROOT / "catalog.json").read_text())["tasks"]
sources = list((ROOT / "data/questions").glob("*/narrative/*.json"))
assert len(rows) == len(sources) == 270
assert {r["id"]: r["scenario_sha256"] for r in rows} == {
task_id(p): digest(p) for p in sources
}
def test_publication_excludes_generated_copies_and_removes_legacy_tasks(
tmp_path, monkeypatch
):
import huggingface_hub
from types import SimpleNamespace
from agentescape_port import publish
(tmp_path / "reports").mkdir()
reports = {
"corpus.json": {
"tasks": 270,
"successes": 270,
"templates_executed": list(range(33)),
},
"worker-isolation.json": [{"passed": True}],
"openenv-smoke.json": {"results": [{"ok": True, "reward": 1.0}] * 2},
}
for name, content in reports.items():
(tmp_path / "reports" / name).write_text(json.dumps(content))
captured = {}
class API:
def create_repo(self, *args, **kwargs):
pass
def repo_info(self, *args, **kwargs):
return SimpleNamespace(private=True, sha="base")
def upload_folder(self, **kwargs):
captured.update(kwargs)
return SimpleNamespace(oid="new", commit_url="test")
monkeypatch.setattr(huggingface_hub, "HfApi", API)
monkeypatch.setattr(publish, "ROOT", tmp_path)
monkeypatch.setattr("sys.argv", ["publish"])
publish.main()
assert "tasks/**" not in captured["allow_patterns"]
assert "catalog.json" in captured["allow_patterns"]
assert captured["delete_patterns"] == ["tasks/**"]
assert "generated/**" in captured["ignore_patterns"]
|