generated from coulomb/repo-seed
Add self-scoping review UI
This commit is contained in:
158
tests/test_self_scoping_web_ui.py
Normal file
158
tests/test_self_scoping_web_ui.py
Normal file
@@ -0,0 +1,158 @@
|
||||
import json
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from repo_registry.web_api.app import app
|
||||
|
||||
|
||||
def write_json(path, payload):
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(json.dumps(payload), encoding="utf-8")
|
||||
|
||||
|
||||
def seed_review_artifacts(root):
|
||||
write_json(
|
||||
root / "golden" / "profile.json",
|
||||
{
|
||||
"profile_id": "profile-v1",
|
||||
"ability": {
|
||||
"expected_capabilities": [
|
||||
{
|
||||
"name": "Scan Repositories Into Observed Facts",
|
||||
"primary_class": "analysis",
|
||||
"expected_features": [],
|
||||
}
|
||||
]
|
||||
},
|
||||
"forbidden_native_capabilities": [
|
||||
{"name": "Route LLM Requests Across Providers"}
|
||||
],
|
||||
},
|
||||
)
|
||||
write_json(
|
||||
root / "assessments" / "baseline.json",
|
||||
{
|
||||
"artifact_id": "baseline-run",
|
||||
"target_repository": {"repo_slug": "repo-scoping"},
|
||||
"engine_identity": {"engine_commit": "old"},
|
||||
"generated_tree": {
|
||||
"abilities": [
|
||||
{
|
||||
"name": "Map Repositories Into Reviewable Scope Profiles",
|
||||
"capabilities": [
|
||||
{
|
||||
"name": "Scan Repositories Into Observed Facts",
|
||||
"primary_class": "analysis",
|
||||
"features": [
|
||||
{
|
||||
"name": "HTTP API surface",
|
||||
"type": "API",
|
||||
"location": "src/repo_registry/web_api/app.py",
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
}
|
||||
]
|
||||
},
|
||||
"known_regression_patterns": [],
|
||||
},
|
||||
)
|
||||
write_json(
|
||||
root / "assessments" / "run.json",
|
||||
{
|
||||
"artifact_id": "run-1",
|
||||
"target_repository": {"repo_slug": "repo-scoping"},
|
||||
"engine_identity": {"engine_commit": "abc123"},
|
||||
"generated_tree": {
|
||||
"abilities": [
|
||||
{
|
||||
"name": "Support Repo Registry",
|
||||
"capabilities": [
|
||||
{
|
||||
"name": "Route LLM Requests Across Providers",
|
||||
"primary_class": "llm-integration",
|
||||
"features": [
|
||||
{
|
||||
"name": "HTTP API surface",
|
||||
"type": "API",
|
||||
"location": "src/repo_registry/web_api/app.py",
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
}
|
||||
]
|
||||
},
|
||||
"known_regression_patterns": [],
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def test_self_scoping_ui_compares_and_records_outcome(tmp_path, monkeypatch):
|
||||
root = tmp_path / "self-scoping"
|
||||
seed_review_artifacts(root)
|
||||
monkeypatch.setenv("REPO_REGISTRY_SELF_SCOPING_ROOT", str(root))
|
||||
client = TestClient(app)
|
||||
|
||||
index = client.get("/ui/self-scoping")
|
||||
assert index.status_code == 200
|
||||
assert "Self-Scoping Review" in index.text
|
||||
|
||||
review = client.get(
|
||||
"/ui/self-scoping/review",
|
||||
params={"golden": "golden/profile.json", "assessment": "assessments/run.json"},
|
||||
)
|
||||
assert review.status_code == 200
|
||||
assert "Route LLM Requests Across Providers" in review.text
|
||||
assert "regression" in review.text
|
||||
|
||||
saved = client.post(
|
||||
"/ui/self-scoping/review",
|
||||
data={
|
||||
"golden_path": "golden/profile.json",
|
||||
"assessment_path": "assessments/run.json",
|
||||
"outcome": "prefer_golden",
|
||||
"reviewer": "codex",
|
||||
"notes": "Provider routing is not native scope.",
|
||||
"comparison_status": "regression",
|
||||
},
|
||||
follow_redirects=False,
|
||||
)
|
||||
assert saved.status_code == 303
|
||||
assert list((root / "outcomes").glob("*.json"))
|
||||
|
||||
|
||||
def test_self_scoping_ui_compares_two_assessment_runs(tmp_path, monkeypatch):
|
||||
root = tmp_path / "self-scoping"
|
||||
seed_review_artifacts(root)
|
||||
monkeypatch.setenv("REPO_REGISTRY_SELF_SCOPING_ROOT", str(root))
|
||||
client = TestClient(app)
|
||||
|
||||
review = client.get(
|
||||
"/ui/self-scoping/run-review",
|
||||
params={
|
||||
"baseline": "assessments/baseline.json",
|
||||
"challenger": "assessments/run.json",
|
||||
},
|
||||
)
|
||||
assert review.status_code == 200
|
||||
assert "Assessment Run Comparison" in review.text
|
||||
assert "Baseline only" in review.text
|
||||
assert "Challenger only" in review.text
|
||||
|
||||
saved = client.post(
|
||||
"/ui/self-scoping/run-review",
|
||||
data={
|
||||
"baseline_path": "assessments/baseline.json",
|
||||
"challenger_path": "assessments/run.json",
|
||||
"outcome": "prefer_baseline",
|
||||
"reviewer": "codex",
|
||||
"notes": "Baseline preserves native scanning capability.",
|
||||
"comparison_status": "needs_review",
|
||||
},
|
||||
follow_redirects=False,
|
||||
)
|
||||
assert saved.status_code == 303
|
||||
records = [json.loads(path.read_text()) for path in (root / "outcomes").glob("*.json")]
|
||||
assert any(record["decision_scope"] == "assessment-pair-comparison" for record in records)
|
||||
Reference in New Issue
Block a user