ut-evaluation / testing /agent_evaluation /tests /test_documentation_examples.py
Codex
Replace the dataset with the current testing tree and the three UT docs.
d26f22a
Raw History Blame Contribute Delete
3.19 kB
"""Execute documented extension contracts with synthetic inputs, never an Agent."""
from pathlib import Path
import re
import subprocess
import sys
import pytest
from agent_evaluation.config import SkillEvaluationConfig
from agent_evaluation.datasets.builder import build_dataset
from agent_evaluation.datasets.loader import JsonDatasetLoader
from agent_evaluation.evaluators import build_evaluators
from agent_evaluation.models import SkillBundle
from agent_evaluation.testpoints import compile_testpoint_set
GUIDE = Path(__file__).parents[1] / "docs/quick-extension-guide.md"
def examples():
return dict(re.findall(r'cat > "\$EXT_ROOT/([^"\n]+)" <<\'EOF\'\n(.*?)\nEOF',
GUIDE.read_text(), re.S))
def test_guide_shell_and_python_syntax():
for block in re.findall(r"```bash\n(.*?)\n```", GUIDE.read_text(), re.S):
checked = subprocess.run(["bash", "-n"], input=block, text=True, capture_output=True)
assert checked.returncode == 0, checked.stderr
for filename, content in examples().items():
if filename.endswith(".py"):
compile(content, filename, "exec")
def test_guide_skill_profile_and_dataset_contract(tmp_path, monkeypatch):
snippets = examples()
for filename in ("skill/SKILL.md", "skill/skill.yaml", "my_loader.py",
"dataset-source/dataset.yaml", "dataset-source/cases/CASE_001.txt"):
target = tmp_path / filename
target.parent.mkdir(parents=True, exist_ok=True)
target.write_text(snippets[filename], encoding="utf-8")
monkeypatch.syspath_prepend(str(tmp_path))
try:
manifest, cases = build_dataset(tmp_path / "dataset-source/dataset.yaml", tmp_path / "bundles")
assert len(cases) == 1 and cases[0].case_id == "CASE_001"
assert manifest.case_count == 1
dataset = JsonDatasetLoader().load(tmp_path / "bundles/my-dataset/v1")
assert [c.to_dict() for c in dataset.cases] == [c.to_dict() for c in cases]
skill = SkillBundle.load(tmp_path / "skill")
profile = SkillEvaluationConfig.resolve(skill.root, None)
points = compile_testpoint_set(skill)
assert [point.test_point_id for point in points.test_points] == ["stage-1", "stage-2"]
evaluators = build_evaluators(skill=skill, profile=profile, testpoint_set=points)
assert [e.evaluator_id for e in evaluators] == ["execution.expected_files_present"]
finally:
sys.modules.pop("my_loader", None)
@pytest.mark.parametrize("filename", ["my_evaluators.py", "my_instrumentation.py"])
def test_guide_registration_examples_are_executable(filename):
source = examples()[filename]
if filename == "my_evaluators.py":
source += '''
from agent_evaluation.evaluators import get_evaluator_definition
assert get_evaluator_definition("execution", "output_count").evaluator_id == "output_count"
'''
# Isolate registry mutations from the test process. No provider or collector.
completed = subprocess.run([sys.executable, "-c", source],
cwd=Path(__file__).parents[2], capture_output=True, text=True)
assert completed.returncode == 0, completed.stderr