test_api_review_integrity.py
python
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1
docs: MuseHub-first before ISR #74 — staging solidify NEXT
Human
1 day ago
| 1 | """Data-integrity tests for API freeze review responses (K11).""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import json |
| 6 | from pathlib import Path |
| 7 | |
| 8 | from cli.kit_root import kit_root |
| 9 | from tests.support import FakeHttpTransport, api_provider_factory, git_status_runner, run_cli, seed_freeze_repo |
| 10 | from tools.freeze_reviewer.findings import assign_finding_ids, stable_sort_findings |
| 11 | from tools.freeze_reviewer.providers.api_response import parse_review_response |
| 12 | from tools.freeze_reviewer.types import Finding |
| 13 | |
| 14 | |
| 15 | def test_api_findings_stable_sort_matches_engine(tmp_path: Path) -> None: |
| 16 | rel = "docs/FREEZE.md" |
| 17 | payload = json.dumps( |
| 18 | { |
| 19 | "findings": [ |
| 20 | { |
| 21 | "check": "C2", |
| 22 | "severity": "MAJOR", |
| 23 | "category": "completeness", |
| 24 | "path": rel, |
| 25 | "line": 10, |
| 26 | "message": "b", |
| 27 | }, |
| 28 | { |
| 29 | "check": "C1", |
| 30 | "severity": "MAJOR", |
| 31 | "category": "completeness", |
| 32 | "path": rel, |
| 33 | "line": 1, |
| 34 | "message": "a", |
| 35 | }, |
| 36 | ] |
| 37 | } |
| 38 | ).encode("utf-8") |
| 39 | parsed = parse_review_response(payload, default_path=rel) |
| 40 | assigned = assign_finding_ids(parsed) |
| 41 | assert assigned[0].id == "F1" |
| 42 | assert assigned[0].line == 1 |
| 43 | assert assigned[1].id == "F2" |
| 44 | assert stable_sort_findings(parsed)[0].line == 1 |
| 45 | |
| 46 | |
| 47 | def test_identical_api_inputs_identical_cli_json(tmp_path: Path, monkeypatch) -> None: |
| 48 | monkeypatch.setenv("OVERSEER_REVIEW_API_KEY", "ci-key") |
| 49 | monkeypatch.setenv("OVERSEER_REVIEW_API_URL", "https://review.example.com/v1") |
| 50 | artifact = seed_freeze_repo(tmp_path, config_name="config-api-reviewer.yaml") |
| 51 | rel = artifact.relative_to(tmp_path).as_posix() |
| 52 | review_body = json.dumps( |
| 53 | { |
| 54 | "findings": [ |
| 55 | { |
| 56 | "check": "C8", |
| 57 | "severity": "MINOR", |
| 58 | "category": "consistency", |
| 59 | "path": rel, |
| 60 | "line": 2, |
| 61 | "message": "Citation nit.", |
| 62 | } |
| 63 | ] |
| 64 | } |
| 65 | ).encode("utf-8") |
| 66 | |
| 67 | def run_once() -> str: |
| 68 | import io |
| 69 | from contextlib import redirect_stdout |
| 70 | |
| 71 | from cli.context import CliContext |
| 72 | from cli.main import main |
| 73 | from cli.output import OutputContext |
| 74 | |
| 75 | transport = FakeHttpTransport(review_body=review_body) |
| 76 | buffer = io.StringIO() |
| 77 | ctx = CliContext.create( |
| 78 | runner=git_status_runner(), |
| 79 | cwd=tmp_path, |
| 80 | kit=kit_root(), |
| 81 | output=OutputContext(json_mode=True), |
| 82 | review_provider_factory=api_provider_factory(transport), |
| 83 | ) |
| 84 | with redirect_stdout(buffer): |
| 85 | main(["review", "--freeze", rel, "--dry-run", "--json"], ctx=ctx) |
| 86 | payload = json.loads(buffer.getvalue()) |
| 87 | payload.pop("stamp", None) |
| 88 | return json.dumps(payload, sort_keys=True) |
| 89 | |
| 90 | assert run_once() == run_once() |
File History
2 commits
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1
docs: MuseHub-first before ISR #74 — staging solidify NEXT
Human
1 day ago
sha256:4671b7f787ddbe63ced31c895b688c77ab495653b65a730b423329f26b3c1439
feat: K1-P1 complete — agent provenance, build-verification…
Sonnet 4.6
patch
52 days ago