test_review_stamp.py
python
sha256:8461d44b77376fbf06fa7c3e085d309e3010fd8d5886d63c63e69ce118811ad4
docs: record AFF-b feature-tip SHAs after AFF-b-ISR commit.
Human
4 days ago
| 1 | """Unit tests for review stamp behavior (§K5.7).""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | from pathlib import Path |
| 6 | from unittest.mock import patch |
| 7 | |
| 8 | import pytest |
| 9 | |
| 10 | from cli.atomic import WriteFailure |
| 11 | from tests.support import FIXTURES |
| 12 | from tools.freeze_reviewer.artifact import parse_artifact |
| 13 | from tools.freeze_reviewer.stamp import build_stamp, reference_digest, render_stamped_text, write_stamp |
| 14 | from tools.freeze_reviewer.types import ReviewerSettings |
| 15 | |
| 16 | |
| 17 | def _stamp(parsed): |
| 18 | return build_stamp( |
| 19 | parsed, |
| 20 | reviewer=ReviewerSettings("agent", "thinking-high", "local", "human"), |
| 21 | kit_version="0.1.0", |
| 22 | produced_by="checklist_engine", |
| 23 | provider_kind="rule_engine", |
| 24 | checklist_ids=["C1"], |
| 25 | checklist_source="builtin", |
| 26 | findings_count=0, |
| 27 | ) |
| 28 | |
| 29 | |
| 30 | def test_markdown_fence_gets_review_stamp(tmp_path: Path) -> None: |
| 31 | path = tmp_path / "docs" / "freeze.md" |
| 32 | path.parent.mkdir(parents=True) |
| 33 | path.write_text((FIXTURES / "freeze-artifact.md").read_text(encoding="utf-8"), encoding="utf-8") |
| 34 | parsed = parse_artifact(path, rel_path="docs/freeze.md") |
| 35 | text = render_stamped_text(parsed, _stamp(parsed)) |
| 36 | assert "review_stamp:" in text |
| 37 | assert "| Round |" not in text or "review_stamp:" in text |
| 38 | |
| 39 | |
| 40 | def test_yaml_whole_file_gets_top_level_stamp(tmp_path: Path) -> None: |
| 41 | path = tmp_path / "freeze.yaml" |
| 42 | path.write_text((FIXTURES / "freeze-artifact.yaml").read_text(encoding="utf-8"), encoding="utf-8") |
| 43 | parsed = parse_artifact(path, rel_path="freeze.yaml") |
| 44 | text = render_stamped_text(parsed, _stamp(parsed)) |
| 45 | assert text.startswith("phase:") |
| 46 | assert "review_stamp:" in text |
| 47 | |
| 48 | |
| 49 | def test_operator_forced_markdown_appends_marker(tmp_path: Path) -> None: |
| 50 | path = tmp_path / "notes.md" |
| 51 | path.write_text("# Notes only\n", encoding="utf-8") |
| 52 | parsed = parse_artifact(path, rel_path="notes.md") |
| 53 | text = render_stamped_text(parsed, _stamp(parsed)) |
| 54 | assert "<!-- overseer:review-stamp -->" in text |
| 55 | |
| 56 | |
| 57 | def test_idempotent_same_digest_noop(tmp_path: Path) -> None: |
| 58 | path = tmp_path / "freeze.yaml" |
| 59 | path.write_text((FIXTURES / "freeze-artifact.yaml").read_text(encoding="utf-8"), encoding="utf-8") |
| 60 | parsed = parse_artifact(path, rel_path="freeze.yaml") |
| 61 | stamp = _stamp(parsed) |
| 62 | write_stamp(path, parsed, stamp) |
| 63 | first = path.read_bytes() |
| 64 | reparsed = parse_artifact(path, rel_path="freeze.yaml") |
| 65 | stamp2 = _stamp(reparsed) |
| 66 | assert write_stamp(path, reparsed, stamp2) is False |
| 67 | assert path.read_bytes() == first |
| 68 | |
| 69 | |
| 70 | def test_atomic_failure_preserves_bytes(tmp_path: Path) -> None: |
| 71 | path = tmp_path / "freeze.yaml" |
| 72 | original = (FIXTURES / "freeze-artifact.yaml").read_text(encoding="utf-8") |
| 73 | path.write_text(original, encoding="utf-8") |
| 74 | parsed = parse_artifact(path, rel_path="freeze.yaml") |
| 75 | stamp = _stamp(parsed) |
| 76 | with patch("tools.freeze_reviewer.stamp.atomic_write_text", side_effect=WriteFailure(path, OSError("disk"))): |
| 77 | with pytest.raises(WriteFailure): |
| 78 | write_stamp(path, parsed, stamp) |
| 79 | assert path.read_text(encoding="utf-8") == original |
| 80 | |
| 81 | |
| 82 | def test_digest_uses_bom_strip_and_lf(tmp_path: Path) -> None: |
| 83 | path = tmp_path / "freeze.yaml" |
| 84 | path.write_bytes(b"\xef\xbb\xbfphase: K\r\noutputs:\r\n - id: a\r\n path: docs/a.md\r\n frozen: true\r\n") |
| 85 | parsed = parse_artifact(path, rel_path="freeze.yaml") |
| 86 | digest = reference_digest(parsed) |
| 87 | assert digest.startswith("sha256:") |
File History
1 commit
sha256:8461d44b77376fbf06fa7c3e085d309e3010fd8d5886d63c63e69ce118811ad4
docs: record AFF-b feature-tip SHAs after AFF-b-ISR commit.
Human
4 days ago