test_print_next.py
python
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1
docs: MuseHub-first before ISR #74 — staging solidify NEXT
Human
12 hours ago
| 1 | """Unit — print_next extract + format (§ONS.12).""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | from pathlib import Path |
| 6 | |
| 7 | from tools.governance_hygiene.next_regen import extract_paste_fence_body |
| 8 | from tools.print_next.extract import ( |
| 9 | CURRENT_NEXT_HEADING, |
| 10 | CurrentNextError, |
| 11 | CurrentNextResult, |
| 12 | extract_current_next, |
| 13 | format_current_next, |
| 14 | ) |
| 15 | |
| 16 | VALID = """# Handover |
| 17 | |
| 18 | ### Paste-ready prompt — demo |
| 19 | |
| 20 | ```text |
| 21 | Phase demo. |
| 22 | Model: Auto |
| 23 | ``` |
| 24 | """ |
| 25 | |
| 26 | |
| 27 | def _write(tmp: Path, text: str) -> Path: |
| 28 | path = tmp / "docs" / "OVERSEER-HANDOVER.md" |
| 29 | path.parent.mkdir(parents=True, exist_ok=True) |
| 30 | path.write_text(text, encoding="utf-8") |
| 31 | return path |
| 32 | |
| 33 | |
| 34 | def test_valid_handover_heading_and_body(tmp_path: Path) -> None: |
| 35 | path = _write(tmp_path, VALID) |
| 36 | result = extract_current_next(path, repo_relative_path="docs/OVERSEER-HANDOVER.md", lane=None) |
| 37 | assert isinstance(result, CurrentNextResult) |
| 38 | assert result.heading == CURRENT_NEXT_HEADING |
| 39 | assert "Model: Auto" in result.fence |
| 40 | human = format_current_next(result) |
| 41 | assert human.startswith(CURRENT_NEXT_HEADING + "\n\n```text\n") |
| 42 | assert human.endswith("```\n") |
| 43 | |
| 44 | |
| 45 | def test_missing_file(tmp_path: Path) -> None: |
| 46 | missing = tmp_path / "docs" / "OVERSEER-HANDOVER.md" |
| 47 | result = extract_current_next( |
| 48 | missing, repo_relative_path="docs/OVERSEER-HANDOVER.md", lane=None |
| 49 | ) |
| 50 | assert isinstance(result, CurrentNextError) |
| 51 | assert result.reason == "handover_missing" |
| 52 | |
| 53 | |
| 54 | def test_heading_missing_even_if_other_fence(tmp_path: Path) -> None: |
| 55 | text = "# No paste heading\n\n```\nsome fence\nModel: Auto\n```\n" |
| 56 | path = _write(tmp_path, text) |
| 57 | result = extract_current_next(path, repo_relative_path="docs/OVERSEER-HANDOVER.md", lane=None) |
| 58 | assert isinstance(result, CurrentNextError) |
| 59 | assert result.reason == "heading_missing" |
| 60 | |
| 61 | |
| 62 | def test_fence_missing(tmp_path: Path) -> None: |
| 63 | text = "### Paste-ready prompt — x\n\nNo fence here.\n" |
| 64 | path = _write(tmp_path, text) |
| 65 | result = extract_current_next(path, repo_relative_path="docs/OVERSEER-HANDOVER.md", lane=None) |
| 66 | assert isinstance(result, CurrentNextError) |
| 67 | assert result.reason == "fence_missing" |
| 68 | |
| 69 | |
| 70 | def test_fence_empty(tmp_path: Path) -> None: |
| 71 | text = "### Paste-ready prompt — x\n\n```text\n \n```\n" |
| 72 | path = _write(tmp_path, text) |
| 73 | result = extract_current_next(path, repo_relative_path="docs/OVERSEER-HANDOVER.md", lane=None) |
| 74 | assert isinstance(result, CurrentNextError) |
| 75 | assert result.reason == "fence_empty" |
| 76 | |
| 77 | |
| 78 | def test_model_missing(tmp_path: Path) -> None: |
| 79 | text = "### Paste-ready prompt — x\n\n```text\nNo model label here.\n```\n" |
| 80 | path = _write(tmp_path, text) |
| 81 | result = extract_current_next(path, repo_relative_path="docs/OVERSEER-HANDOVER.md", lane=None) |
| 82 | assert isinstance(result, CurrentNextError) |
| 83 | assert result.reason == "model_missing" |
| 84 | |
| 85 | |
| 86 | def test_current_next_heading_exact() -> None: |
| 87 | assert CURRENT_NEXT_HEADING == "## CURRENT NEXT — paste this" |
| 88 | |
| 89 | |
| 90 | def test_reuses_extract_paste_fence_body(tmp_path: Path) -> None: |
| 91 | helper = extract_paste_fence_body(VALID) |
| 92 | assert helper is not None |
| 93 | path = _write(tmp_path, VALID) |
| 94 | outcome = extract_current_next(path, repo_relative_path="docs/OVERSEER-HANDOVER.md", lane=None) |
| 95 | assert isinstance(outcome, CurrentNextResult) |
| 96 | assert outcome.fence == helper |
File History
1 commit
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1
docs: MuseHub-first before ISR #74 — staging solidify NEXT
Human
12 hours ago