File size: 4,911 Bytes
fd11263
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d26f22a
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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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