from agent_evaluation.evaluators import ExpectedFilesParams from pathlib import Path import pytest from agent_evaluation.datasets.models import EvaluationCase from agent_evaluation.evaluators import EvaluationContext, expected_files_present from agent_evaluation.config import SkillEvaluationConfig from agent_evaluation.models import SkillBundle, TaskArtifact from agent_evaluation.testpoints import compile_test_points, compile_testpoint_set from .support import profile_text def _skill(tmp_path: Path, text: str = """## Runtime State Machine 1. `Preflight: First` 2. `Stage 1: Second` 3. `Handoff: Third` """) -> Path: root = tmp_path / "skill" root.mkdir() (root / "SKILL.md").write_text(f"---\nname: demo\n---\n{text}", encoding="utf-8") (root / "skill.yaml").write_text( profile_text(" execution:\n - id: expected_files_present\n params:\n expected_files: [result.md]\n trace:\n - id: duration_within_limit\n params: {max_duration_seconds: 10}\n"), encoding="utf-8", ) return root def test_testpoint_compiler_uses_runtime_state_machine_order(tmp_path): skill = SkillBundle.load(_skill(tmp_path, """# Stage 99: not a testpoint ## Runtime State Machine 1. `Preflight: First` 2. `Stage 1: Second` 3. `Handoff: Third` ## Another Section 1. `Stage 99: also not a testpoint` """)) points = compile_test_points(skill) assert [(point.test_point_id, point.ordinal, point.name) for point in points] == [ ("preflight", 1, "Preflight: First"), ("stage-1", 2, "Stage 1: Second"), ("handoff", 3, "Handoff: Third"), ] assert [point.previous_test_point_id for point in points] == [None, "preflight", "stage-1"] assert compile_testpoint_set(skill).set_hash == compile_testpoint_set(skill).set_hash def test_testpoint_compiler_reads_all_veritas_runtime_items(tmp_path): source = Path("/research/d7/gds/pyhan25/agent_eval/data/veritas-ut-testplan-gen/SKILL.md") skill = SkillBundle.load(source) points = compile_test_points(skill) assert len(points) == 14 assert [point.test_point_id for point in points] == [ "preflight", "stage-1", "stage-2", "stage-3", "stage-4", "stage-5", "handoff", "stage-6", "stage-7", "stage-8", "stage-9", "stage-10", "stage-11", "stage-12", ] def test_testpoint_compiler_rejects_missing_runtime_state_machine(tmp_path): skill = SkillBundle.load(_skill(tmp_path, "# no stage\n")) with pytest.raises(ValueError, match="Runtime State Machine"): compile_test_points(skill) def test_testpoint_compiler_rejects_duplicate_ids(tmp_path): skill = SkillBundle.load(_skill(tmp_path, """## Runtime State Machine 1. `Stage 1: First` 2. `Stage 1: Duplicate` """)) with pytest.raises(ValueError, match="duplicate"): compile_test_points(skill) def test_testpoint_compiler_accepts_arbitrary_labels_without_stage_or_colon(tmp_path): skill = SkillBundle.load(_skill(tmp_path, """## Runtime State Machine 1. `Prepare inputs` 2. `Review: confirm outputs` """)) points = compile_test_points(skill) assert [point.test_point_id for point in points] == ["prepare-inputs", "review"] def test_expected_files_evaluator_checks_workspace(tmp_path): root = tmp_path / "workspace" / "ai-output" root.mkdir(parents=True) (root / "result.md").write_text("ok", encoding="utf-8") skill = SkillBundle.load(_skill(tmp_path)) context = EvaluationContext( EvaluationCase("case-1", "build", {}), TaskArtifact( "run-1", "case-1", "completed", {}, metadata={"task_workspace": str(root.parent)}, ), skill, compile_testpoint_set(skill), ) assert expected_files_present(context, ExpectedFilesParams(**{"expected_files": ["result.md"]})).label == "pass" assert expected_files_present(context, ExpectedFilesParams(**{"expected_files": ["missing.md"]})).label == "fail" with pytest.raises(ValueError, match="escapes"): expected_files_present(context, ExpectedFilesParams(**{"expected_files": ["../secret"]})) def test_evaluation_profile_hash_is_independent_from_skill_bundle_hash(tmp_path): root = _skill(tmp_path) first = SkillBundle.load(root) first_profile = SkillEvaluationConfig.resolve(root) first_points = compile_testpoint_set(first) (root / "skill.yaml").write_text((root / "skill.yaml").read_text().replace("max_duration_seconds: 10", "max_duration_seconds: 20"), encoding="utf-8") second = SkillBundle.load(root) second_profile = SkillEvaluationConfig.resolve(root) second_points = compile_testpoint_set(second) assert first.entrypoint_hash == second.entrypoint_hash assert first.bundle_hash == second.bundle_hash assert first_points.set_hash == second_points.set_hash assert first_profile.profile_hash != second_profile.profile_hash