File size: 3,191 Bytes
fd11263 | 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 | """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
|