Download tests/test_materialization.py from HuggingFaceSwarms/AgentEscapeBench: direct link, hf CLI and curl.
- Browser
- Download file 3.34 kB
-
https://huggingface.co/datasets/HuggingFaceSwarms/AgentEscapeBench/resolve/refs%2Fpr%2F3/tests/test_materialization.py
- Command line
-
hf download hf://datasets/HuggingFaceSwarms/AgentEscapeBench@refs/pr/3/tests/test_materialization.py
-
curl -L -o test_materialization.py https://huggingface.co/datasets/HuggingFaceSwarms/AgentEscapeBench/resolve/refs%2Fpr%2F3/tests/test_materialization.py
3.34 kB
| import json | |
| import pytest | |
| from agentescape_port.adapter import ROOT, generate | |
| 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"] | |