2026-06-18 07:57:06 +02:00
|
|
|
import json
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
from openultrasast.config import load_config
|
2026-10-13 11:06:09 +02:00
|
|
|
from openultrasast.harness import HarnessRuntime, HarnessTraceWriter, write_harness_config
|
2026-06-18 07:57:06 +02:00
|
|
|
|
|
|
|
|
|
2026-10-13 11:06:09 +02:00
|
|
|
def test_runtime_emits_stage_events(tmp_path: Path) -> None:
|
2026-06-18 07:57:06 +02:00
|
|
|
trace_path = tmp_path / "events.jsonl"
|
|
|
|
|
runtime = HarnessRuntime(
|
|
|
|
|
scan_id="scan-1",
|
|
|
|
|
config=load_config(None),
|
|
|
|
|
trace_writer=HarnessTraceWriter(trace_path),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
result = runtime.run_stage("preprocess", lambda: "ok")
|
|
|
|
|
|
|
|
|
|
events = [json.loads(line) for line in trace_path.read_text().splitlines()]
|
|
|
|
|
assert result == "ok"
|
2026-10-13 11:06:09 +02:00
|
|
|
assert [event["event_type"] for event in events] == ["stage_start", "stage_end"]
|
2026-06-18 07:57:06 +02:00
|
|
|
|
|
|
|
|
|
2026-10-13 11:06:09 +02:00
|
|
|
def test_harness_config_serializes_models_and_prompt_hashes(tmp_path: Path) -> None:
|
2026-06-18 07:57:06 +02:00
|
|
|
config_path = tmp_path / "openultrasast.toml"
|
2026-06-18 10:06:21 +02:00
|
|
|
config_path.write_text('[models]\nranker = "openrouter/ranker"\n')
|
2026-06-18 07:57:06 +02:00
|
|
|
output = tmp_path / "harness.json"
|
|
|
|
|
|
|
|
|
|
write_harness_config(
|
|
|
|
|
config=load_config(config_path),
|
|
|
|
|
path=output,
|
|
|
|
|
prompts={"ranker": "score files"},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
payload = json.loads(output.read_text())
|
|
|
|
|
assert payload["model_roles"]["ranker"] == "openrouter/ranker"
|
|
|
|
|
assert len(payload["prompt_hashes"]["ranker"]) == 64
|