generated from coulomb/repo-seed
106 lines
3.6 KiB
Python
106 lines
3.6 KiB
Python
import json
|
|
|
|
import pytest
|
|
|
|
from repo_scoping.self_scoping.review_store import (
|
|
list_assessment_artifacts,
|
|
list_golden_profiles,
|
|
load_json_artifact,
|
|
record_assessment_outcome,
|
|
record_assessment_pair_outcome,
|
|
)
|
|
|
|
|
|
def write_json(path, payload):
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
path.write_text(json.dumps(payload), encoding="utf-8")
|
|
|
|
|
|
def test_review_store_lists_and_loads_artifacts(tmp_path):
|
|
root = tmp_path / "self-scoping"
|
|
write_json(
|
|
root / "golden" / "profile.json",
|
|
{"profile_id": "repo-scoping-golden-v1", "title": "Golden", "updated_at": "2026-05-15"},
|
|
)
|
|
write_json(
|
|
root / "assessments" / "run.json",
|
|
{"artifact_id": "known-bad-run", "created_at": "2026-05-15T10:00:00Z"},
|
|
)
|
|
|
|
assert list_golden_profiles(root)[0].path == "golden/profile.json"
|
|
assert list_assessment_artifacts(root)[0].artifact_id == "known-bad-run"
|
|
assert load_json_artifact("assessments/run.json", root)["artifact_id"] == "known-bad-run"
|
|
|
|
|
|
def test_review_store_rejects_paths_outside_root(tmp_path):
|
|
root = tmp_path / "self-scoping"
|
|
write_json(root / "golden" / "profile.json", {"profile_id": "profile"})
|
|
|
|
with pytest.raises(ValueError):
|
|
load_json_artifact("../outside.json", root)
|
|
|
|
|
|
def test_record_assessment_outcome_is_append_only_json(tmp_path):
|
|
root = tmp_path / "self-scoping"
|
|
write_json(root / "golden" / "profile.json", {"profile_id": "profile-v1"})
|
|
write_json(
|
|
root / "assessments" / "run.json",
|
|
{
|
|
"artifact_id": "run-1",
|
|
"engine_identity": {"engine_commit": "abc123", "engine_release": "v1"},
|
|
},
|
|
)
|
|
|
|
record = record_assessment_outcome(
|
|
golden_path="golden/profile.json",
|
|
assessment_path="assessments/run.json",
|
|
outcome="prefer_golden",
|
|
reviewer="codex",
|
|
notes="Known provider-routing regression remains present.",
|
|
comparison_status="regression",
|
|
root=root,
|
|
)
|
|
|
|
outcome_files = list((root / "outcomes").glob("*.json"))
|
|
assert len(outcome_files) == 1
|
|
persisted = json.loads(outcome_files[0].read_text(encoding="utf-8"))
|
|
assert persisted == record
|
|
assert persisted["schema_version"] == "self-scoping-review-outcome/v1"
|
|
assert persisted["golden_profile_id"] == "profile-v1"
|
|
assert persisted["assessment_artifact_id"] == "run-1"
|
|
assert persisted["engine_identity"]["engine_commit"] == "abc123"
|
|
|
|
|
|
def test_record_assessment_pair_outcome_keeps_both_release_bindings(tmp_path):
|
|
root = tmp_path / "self-scoping"
|
|
write_json(
|
|
root / "assessments" / "baseline.json",
|
|
{
|
|
"artifact_id": "baseline-run",
|
|
"engine_identity": {"engine_commit": "old"},
|
|
},
|
|
)
|
|
write_json(
|
|
root / "assessments" / "challenger.json",
|
|
{
|
|
"artifact_id": "challenger-run",
|
|
"engine_identity": {"engine_commit": "new"},
|
|
},
|
|
)
|
|
|
|
record = record_assessment_pair_outcome(
|
|
baseline_path="assessments/baseline.json",
|
|
challenger_path="assessments/challenger.json",
|
|
outcome="prefer_challenger",
|
|
reviewer="codex",
|
|
notes="Hierarchy is closer to native repo-scoping utility.",
|
|
comparison_status="needs_review",
|
|
root=root,
|
|
)
|
|
|
|
assert record["decision_scope"] == "assessment-pair-comparison"
|
|
assert record["baseline_assessment_artifact_id"] == "baseline-run"
|
|
assert record["challenger_assessment_artifact_id"] == "challenger-run"
|
|
assert record["baseline_engine_identity"]["engine_commit"] == "old"
|
|
assert record["challenger_engine_identity"]["engine_commit"] == "new"
|