Codex
Replace the dataset with the current testing tree and the three UT docs.
d26f22a
Raw History Blame Contribute Delete
3.56 kB
"""Deterministic ``AgentAdapter`` for tests and orchestration smoke runs."""
from __future__ import annotations
import tempfile
import time
import uuid
from dataclasses import dataclass
from pathlib import Path
from ...config import SkillEvaluationConfig
from ...datasets.models import EvaluationCase
from ...models import ExecutionEvidence, SkillBundle, TaskArtifact
from ...testpoints import compile_test_points
def _expected_files(profile: SkillEvaluationConfig) -> list[str]:
params = profile.params_for("execution", "expected_files_present") or {}
return list(params.get("expected_files", []) or [])
@dataclass
class SimulatorAdapter:
"""Produce deterministic execution evidence without running a real agent."""
behavior: str = "pass"
def start(self) -> None:
"""The simulator has no external runtime to start."""
def stop(self) -> None:
"""The simulator has no external runtime to stop."""
def run(
self,
case: EvaluationCase,
skill: SkillBundle,
profile: SkillEvaluationConfig,
) -> TaskArtifact:
started = time.monotonic()
stages = [point.test_point_id for point in compile_test_points(skill)]
observed = stages if self.behavior != "missing-testpoint" else stages[:-1]
validation_ok = self.behavior != "validation-fail"
expected_files = _expected_files(profile)
if self.behavior == "missing-file":
expected_files = expected_files[:-1] if expected_files else []
files = (
expected_files
)
workspace = Path(tempfile.mkdtemp(prefix=f"skill-eval-{case.case_id}-"))
output_root = workspace / "ai-output"
output_root.mkdir(parents=True, exist_ok=True)
for path in files:
target = output_root / path
target.parent.mkdir(parents=True, exist_ok=True)
target.write_text(
f"{path}\n" + "\n".join(observed),
encoding="utf-8",
)
duration = time.monotonic() - started
final_output = (
f"Generated outputs for {case.case_id}; stages: {' -> '.join(observed)}"
)
tool_calls = [{"name": step, "status": "ok"} for step in observed]
changed_files = [f"ai-output/{path}" for path in files]
return TaskArtifact(
run_id=f"sim-{uuid.uuid4().hex[:12]}",
case_id=case.case_id,
status="completed" if validation_ok else "failed",
output={
"final_output": final_output,
"tool_calls": tool_calls,
"validation": [{
"command": "fixture-contract-check",
"exit_code": 0 if validation_ok else 1,
"status": "passed" if validation_ok else "failed",
}],
"changed_files": changed_files,
},
metadata={
"fixture": case.metadata.get("fixture"),
"skill_id": skill.skill_id,
"skill_version": skill.version,
"duration_seconds": duration,
"task_workspace": str(workspace),
},
execution=ExecutionEvidence(
final_output=final_output,
tool_calls=tool_calls,
changed_files=changed_files,
duration_seconds=duration,
task_workspace=str(workspace),
returncode=0 if validation_ok else 1,
),
)
__all__ = ["SimulatorAdapter"]