Spaces:
Sleeping
Sleeping
File size: 7,712 Bytes
a9df8b1 | 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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | from __future__ import annotations
import hashlib
import importlib.util
import json
import sys
from pathlib import Path
def _load_runner_module():
script_path = Path(__file__).resolve().parents[2] / "scripts" / "run_input_skill_eval.py"
spec = importlib.util.spec_from_file_location("run_input_skill_eval", script_path)
module = importlib.util.module_from_spec(spec)
assert spec and spec.loader
sys.modules[spec.name] = module
spec.loader.exec_module(module)
return module
def test_load_manifest_normalizes_fixture_paths_and_hash(tmp_path: Path) -> None:
runner = _load_runner_module()
fixture_root = tmp_path / "fixtures"
fixture_file = fixture_root / "document" / "runbook.md"
fixture_file.parent.mkdir(parents=True)
fixture_file.write_text("# Restart service\n\n1. Check status\n2. Restart safely\n", encoding="utf-8")
manifest = tmp_path / "manifest.json"
manifest.write_text(
json.dumps(
{
"fixtures": [
{
"source_id": "doc-restart-service",
"input_type": "document",
"domain": "software",
"content_file": "document/runbook.md",
"source_url": "https://example.test/runbook",
"paper_or_project": "local fixture",
"expected_skill_shape": "functional",
"license_note": "test-only",
}
]
}
),
encoding="utf-8",
)
cases = runner.load_manifest(manifest, fixture_root=fixture_root, max_chars=0)
assert len(cases) == 1
case = cases[0]
assert case.source_id == "doc-restart-service"
assert case.input_type == "document"
assert case.local_path == fixture_file
assert case.content.startswith("# Restart service")
assert case.content_sha256 == hashlib.sha256(case.content.encode("utf-8")).hexdigest()
assert case.manifest["domain"] == "software"
def test_candidate_payload_preserves_metadata_and_run_provenance() -> None:
runner = _load_runner_module()
case = runner.FixtureCase(
source_id="api-petstore-add-pet",
input_type="api_doc",
domain="api",
source_url="https://example.test/openapi.yaml",
paper_or_project="OpenAPI sample",
expected_skill_shape="atomic",
license_note="public docs",
local_path=Path("openapi.yaml"),
content="openapi: 3.0.0",
content_sha256="abc123",
manifest={},
truncated=False,
)
unit = {
"unit_id": "unit-1",
"source_type": "api_doc",
"proposed_skill_name": "Add Pet",
"proposed_description": "Create a pet through the API.",
"proposed_type": "atomic",
"index_keywords": ["petstore", "api"],
"metadata": {
"candidate_interface": {
"input_schema": {"type": "object", "required": ["name"]},
"output_schema": {"type": "object", "required": ["pet_id"]},
"preconditions": ["API server is reachable."],
"postconditions": ["Pet exists."],
},
"candidate_implementation": {
"prompt_template": "Call POST /pet with a valid body.",
"tool_calls": ["http.post"],
},
"candidate_relations": {"dependency_ids": ["auth_token_skill"]},
},
}
payload = runner.candidate_review_payload(unit, case, run_id="run-20260526")
assert payload["name"] == "add_pet_api_petstore_add_pet"
assert payload["source_type"] == "api_doc"
assert "eval-run:run-20260526" in payload["tags"]
assert "source-id:api-petstore-add-pet" in payload["tags"]
assert payload["dependency_ids"] == ["auth_token_skill"]
assert payload["tool_calls"] == ["http.post"]
provenance = payload["provenance"]
assert provenance["source_type"] == "api_doc"
assert provenance["source_ids"] == ["api-petstore-add-pet", "unit-1"]
context = provenance["creation_context"]
assert context["content_sha256"] == "abc123"
assert context["eval_run_id"] == "run-20260526"
assert context["fixture_import_mode"] == "isolated_eval_candidate"
def test_candidate_payload_uses_source_suffix_to_avoid_eval_name_collisions() -> None:
runner = _load_runner_module()
unit = {
"unit_id": "unit-1",
"source_type": "document",
"proposed_skill_name": "document_grounded_extractor",
"proposed_description": "Extract a document-grounded procedure.",
"proposed_type": "functional",
"metadata": {},
}
first = runner.FixtureCase(
source_id="document-kubernetes-pending-pod-runbook",
input_type="document",
domain="software",
source_url="https://example.test/a",
paper_or_project="test",
expected_skill_shape="functional",
license_note="test-only",
local_path=Path("a.md"),
content="a",
content_sha256="sha-a",
manifest={},
)
second = runner.FixtureCase(
source_id="document-kubernetes-termination-message",
input_type="document",
domain="software",
source_url="https://example.test/b",
paper_or_project="test",
expected_skill_shape="functional",
license_note="test-only",
local_path=Path("b.md"),
content="b",
content_sha256="sha-b",
manifest={},
)
first_payload = runner.candidate_review_payload(unit, first, run_id="run")
second_payload = runner.candidate_review_payload(unit, second, run_id="run")
assert first_payload["name"] != second_payload["name"]
assert first_payload["name"].startswith("document_grounded_extractor_")
assert second_payload["name"].startswith("document_grounded_extractor_")
def test_safe_filename_is_short_enough_for_windows_run_artifacts() -> None:
runner = _load_runner_module()
long_label = (
"version_document_document_skillsbench_03_instruction_"
"software_dependency_audit_1_snapshot"
)
filename = runner.safe_filename(long_label)
assert len(filename) <= 96
assert filename.startswith("version_document")
def test_score_fixture_record_rewards_full_workflow_more_than_parse_only() -> None:
runner = _load_runner_module()
parse_only = {
"parse": {
"http_status": 200,
"success": True,
"unit_count": 1,
"schema_completeness": 0.8,
"ctx2skill_evidence_completeness": 0.6,
"layer_correctness": 0.5,
},
"audit": {"status": "not_run"},
"create": {"status": "not_run"},
"graph": {"status": "not_run"},
"version": {"status": "not_run"},
"harness": {"status": "not_run"},
"skillsbench": {"status": "not_run"},
}
full_workflow = {
**parse_only,
"audit": {"http_status": 200, "passed": True, "audit_score": 0.9},
"create": {"http_status": 201, "success": True, "created_skill_id": "skill-1"},
"graph": {"http_status": 200, "skill_present": True, "relation_count": 2},
"version": {"http_status": 200, "business_diff_available": True, "snapshot_created": True},
"harness": {"status": "verified", "positive_pass": True, "negative_rejected": True},
"skillsbench": {"status": "mapped", "verifier_ran": True, "generated_pass": True},
}
parse_score = runner.score_fixture_record(parse_only)
full_score = runner.score_fixture_record(full_workflow)
assert 0 < parse_score < full_score
assert full_score >= 0.9
|