test_api_review_provider.py python
97 lines 3.3 KB
Raw
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1 docs: MuseHub-first before ISR #74 — staging solidify NEXT Human 12 hours ago
1 """Integration tests for headless API freeze review (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 (
10 FakeHttpTransport,
11 api_provider_factory,
12 api_unreachable_provider_factory,
13 git_status_runner,
14 run_cli,
15 seed_freeze_repo,
16 write_config,
17 )
18
19
20 def test_api_provider_pass_via_fake_transport(tmp_path: Path, monkeypatch) -> None:
21 monkeypatch.setenv("OVERSEER_REVIEW_API_KEY", "ci-key")
22 monkeypatch.setenv("OVERSEER_REVIEW_API_URL", "https://review.example.com/v1")
23 artifact = seed_freeze_repo(tmp_path, config_name="config-api-reviewer.yaml")
24 rel = artifact.relative_to(tmp_path).as_posix()
25 transport = FakeHttpTransport(review_body=json.dumps({"findings": []}).encode("utf-8"))
26 code = run_cli(
27 ["review", "--freeze", rel, "--json"],
28 cwd=tmp_path,
29 runner=git_status_runner(),
30 kit=kit_root(),
31 review_provider_factory=api_provider_factory(transport),
32 json_mode=True,
33 )
34 assert code == 0
35 assert any(call["method"] == "POST" and "/review" in call["url"] for call in transport.calls)
36
37
38 def test_api_provider_findings_exit_7(tmp_path: Path, monkeypatch) -> None:
39 monkeypatch.setenv("OVERSEER_REVIEW_API_KEY", "ci-key")
40 monkeypatch.setenv("OVERSEER_REVIEW_API_URL", "https://review.example.com/v1")
41 artifact = seed_freeze_repo(tmp_path, config_name="config-api-reviewer.yaml")
42 rel = artifact.relative_to(tmp_path).as_posix()
43 review_body = json.dumps(
44 {
45 "findings": [
46 {
47 "check": "C3",
48 "severity": "MAJOR",
49 "category": "consistency",
50 "path": rel,
51 "line": 1,
52 "message": "Inconsistent exit table.",
53 }
54 ]
55 }
56 ).encode("utf-8")
57 transport = FakeHttpTransport(review_body=review_body)
58 code = run_cli(
59 ["review", "--freeze", rel, "--json"],
60 cwd=tmp_path,
61 runner=git_status_runner(),
62 kit=kit_root(),
63 review_provider_factory=api_provider_factory(transport),
64 json_mode=True,
65 )
66 assert code == 7
67
68
69 def test_api_unreachable_human_escalation(tmp_path: Path) -> None:
70 artifact = seed_freeze_repo(tmp_path, config_name="config-api-reviewer.yaml")
71 rel = artifact.relative_to(tmp_path).as_posix()
72 code = run_cli(
73 ["review", "--freeze", rel, "--json"],
74 cwd=tmp_path,
75 runner=git_status_runner(),
76 kit=kit_root(),
77 review_provider_factory=api_unreachable_provider_factory(),
78 json_mode=True,
79 )
80 assert code == 8
81
82
83 def test_api_review_failure_escalates_human(tmp_path: Path, monkeypatch) -> None:
84 monkeypatch.setenv("OVERSEER_REVIEW_API_KEY", "ci-key")
85 monkeypatch.setenv("OVERSEER_REVIEW_API_URL", "https://review.example.com/v1")
86 artifact = seed_freeze_repo(tmp_path, config_name="config-api-reviewer.yaml")
87 rel = artifact.relative_to(tmp_path).as_posix()
88 transport = FakeHttpTransport(fail_review=True)
89 code = run_cli(
90 ["review", "--freeze", rel, "--json"],
91 cwd=tmp_path,
92 runner=git_status_runner(),
93 kit=kit_root(),
94 review_provider_factory=api_provider_factory(transport),
95 json_mode=True,
96 )
97 assert code == 8
File History 2 commits
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1 docs: MuseHub-first before ISR #74 — staging solidify NEXT Human 12 hours ago
sha256:4671b7f787ddbe63ced31c895b688c77ab495653b65a730b423329f26b3c1439 feat: K1-P1 complete — agent provenance, build-verification… Sonnet 4.6 patch 52 days ago