| 1 | """Focused tests for L3 safety policy.""" |
| 2 | |
| 3 | import os |
| 4 | import sys |
| 5 | |
| 6 | ROOT = os.path.join(os.path.dirname(__file__), "..") |
| 7 | sys.path.insert(0, ROOT) |
| 8 | |
| 9 | from oversight_core import l3_policy, watermark |
| 10 | |
| 11 | |
| 12 | def ok(msg: str) -> None: |
| 13 | print(f" [PASS] {msg}") |
| 14 | |
| 15 | |
| 16 | def test_risky_documents_default_l3_off(): |
| 17 | text = "The system MUST verify every request. SELECT * FROM users;" |
| 18 | decision = l3_policy.decide_l3( |
| 19 | filename="api-spec.md", |
| 20 | content_type="text/markdown", |
| 21 | text=text, |
| 22 | requested_mode="auto", |
| 23 | ) |
| 24 | assert not decision.enabled |
| 25 | assert decision.document_class == "technical_spec" |
| 26 | ok("technical/spec content disables L3 by default") |
| 27 | |
| 28 | |
| 29 | def test_full_l3_requires_ack_metadata(): |
| 30 | decision = l3_policy.decide_l3( |
| 31 | filename="brief.txt", |
| 32 | content_type="text/plain", |
| 33 | text="This report will begin with a large review and explain the issue.", |
| 34 | requested_mode="full", |
| 35 | ) |
| 36 | assert decision.enabled |
| 37 | assert decision.requires_ack |
| 38 | assert decision.mode == "full" |
| 39 | ok("explicit full L3 returns acknowledgement-required decision") |
| 40 | |
| 41 | |
| 42 | def test_safe_l3_preserves_protected_lines(): |
| 43 | mark_id = watermark.new_mark_id() |
| 44 | original = ( |
| 45 | "The Vendor MUST provide 5 kg by Friday.\n" |
| 46 | "This report will begin with a large review and explain the issue for Alice.\n" |
| 47 | " SELECT * FROM users;\n" |
| 48 | ) |
| 49 | marked = l3_policy.apply_l3_safe(original, mark_id, mode="full") |
| 50 | assert "The Vendor MUST provide 5 kg by Friday." in marked |
| 51 | assert "Alice" in marked |
| 52 | assert " SELECT * FROM users;" in marked |
| 53 | assert marked != original |
| 54 | ok("safe L3 preserves RFC2119/numeric/code lines while marking prose") |
| 55 | |
| 56 | |
| 57 | if __name__ == "__main__": |
| 58 | print("=" * 60) |
| 59 | print("oversight_core.l3_policy - focused unit tests") |
| 60 | print("=" * 60) |
| 61 | test_risky_documents_default_l3_off() |
| 62 | test_full_l3_requires_ack_metadata() |
| 63 | test_safe_l3_preserves_protected_lines() |
| 64 | print("\n ALL TESTS PASSED - 3/3") |