test_track_o_contract.py
python
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1
docs: MuseHub-first before ISR #74 — staging solidify NEXT
Human
3 days ago
| 1 | """Unit tests — Track O product-contract parse/presence helpers (§O0.8 unit).""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | from pathlib import Path |
| 6 | |
| 7 | from tools.track_o.validate import ( |
| 8 | ABS_MACHINE_PATH_RE, |
| 9 | MINIMAL_VALID_CONTRACT, |
| 10 | SECRET_ASSIGNMENT_RE, |
| 11 | STAGE_LABELS, |
| 12 | check_deferred_ceremony, |
| 13 | check_no_abs_machine_paths, |
| 14 | check_no_secret_patterns, |
| 15 | check_rejection_keywords, |
| 16 | check_stage_labels, |
| 17 | validate_contract_fixture, |
| 18 | validate_contract_text, |
| 19 | ValidationResult, |
| 20 | ) |
| 21 | |
| 22 | KIT_ROOT = Path(__file__).resolve().parents[2] |
| 23 | CONTRACT = KIT_ROOT / "docs" / "TRACK-O-NORMIE-CUSTODY-PRODUCT-CONTRACT.md" |
| 24 | |
| 25 | |
| 26 | def test_stage_labels_include_four_normie_stages() -> None: |
| 27 | assert STAGE_LABELS[0].endswith("Start") |
| 28 | assert "Work" in STAGE_LABELS[1] |
| 29 | assert "GitHub backup" in STAGE_LABELS[2] |
| 30 | assert "Knowtation bind" in STAGE_LABELS[3] |
| 31 | |
| 32 | |
| 33 | def test_minimal_fixture_passes_unit_checks() -> None: |
| 34 | result = validate_contract_fixture(MINIMAL_VALID_CONTRACT) |
| 35 | assert result.ok, result.errors |
| 36 | |
| 37 | |
| 38 | def test_real_contract_has_required_stage_labels() -> None: |
| 39 | text = CONTRACT.read_text(encoding="utf-8") |
| 40 | result = ValidationResult(ok=True) |
| 41 | check_stage_labels(text, result) |
| 42 | assert result.ok, result.errors |
| 43 | |
| 44 | |
| 45 | def test_real_contract_has_stage3_ceremony_keywords() -> None: |
| 46 | text = CONTRACT.read_text(encoding="utf-8") |
| 47 | result = ValidationResult(ok=True) |
| 48 | check_deferred_ceremony(text, result) |
| 49 | assert result.ok, result.errors |
| 50 | |
| 51 | |
| 52 | def test_real_contract_has_rejection_keywords() -> None: |
| 53 | text = CONTRACT.read_text(encoding="utf-8") |
| 54 | result = ValidationResult(ok=True) |
| 55 | check_rejection_keywords(text, result) |
| 56 | assert result.ok, result.errors |
| 57 | |
| 58 | |
| 59 | def test_real_contract_no_abs_machine_paths() -> None: |
| 60 | text = CONTRACT.read_text(encoding="utf-8") |
| 61 | result = ValidationResult(ok=True) |
| 62 | check_no_abs_machine_paths(text, result, label="contract") |
| 63 | assert result.ok, result.errors |
| 64 | assert not ABS_MACHINE_PATH_RE.search(text) |
| 65 | |
| 66 | |
| 67 | def test_real_contract_no_secret_assignment_patterns() -> None: |
| 68 | text = CONTRACT.read_text(encoding="utf-8") |
| 69 | result = ValidationResult(ok=True) |
| 70 | check_no_secret_patterns(text, result, label="contract") |
| 71 | assert result.ok, result.errors |
| 72 | assert not SECRET_ASSIGNMENT_RE.search(text) |
| 73 | |
| 74 | |
| 75 | def test_missing_stage_fails_closed() -> None: |
| 76 | bad = MINIMAL_VALID_CONTRACT.replace("### Stage 4 — Optional Knowtation bind", "### Stage X") |
| 77 | result = ValidationResult(ok=True) |
| 78 | validate_contract_text(bad, result) |
| 79 | assert not result.ok |
| 80 | assert any(e.startswith("missing_stage:") for e in result.errors) |
File History
1 commit
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1
docs: MuseHub-first before ISR #74 — staging solidify NEXT
Human
3 days ago