-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_check_docs_private_markers.py
More file actions
139 lines (117 loc) · 4.58 KB
/
Copy pathtest_check_docs_private_markers.py
File metadata and controls
139 lines (117 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env python3
# FLOOR
"""Red floor for check_docs_private_markers.py (Pub2/T3-B).
Proves, on isolated temp trees (no real repo), one tooth per expurgation rule
and the two refinements that make the guard usable:
- L1/L2/L3/L4 each fire on their own private-marker shape (version tag,
family repere, error code, session anchor). Neuter any single rule and its
fixture flips green -> the floor FAILs: each rule is load-bearing (mutation
teeth).
- a section cross-reference and the Markdown token H1 do NOT fire - they are
excluded by construction (tight prefixes), not by an allow-list.
- the SVG pair: a repere in <text> fires, but the SAME shape inside a
<path d="..."> (where S is a smooth-bezier operator, not a repere) does NOT
- the guard reads text, never attributes.
- a title/desc leak fires (accessible text is in scope).
- a non-scanned suffix (.txt) is ignored (surface scope).
- a combined doc fires all four codes at once (they coexist).
- an absent docs/ fails loud (exit-2 path), never assumes a clean tree.
Exit 0 = every behaviour holds; exit 1 = a regression.
"""
from __future__ import annotations
import importlib.util
import sys
import tempfile
from pathlib import Path
_HERE = Path(__file__).resolve().parent
_spec = importlib.util.spec_from_file_location(
"check_docs_private_markers", _HERE / "check_docs_private_markers.py"
)
cdm = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(cdm)
_passed = 0
_failed = 0
def _check(label: str, cond: bool) -> None:
global _passed, _failed
if cond:
_passed += 1
print(f" [OK] {label}")
else:
_failed += 1
print(f" [FAIL] {label}")
def _audit(files: dict[str, str]):
"""Write {relpath: content} under <tmp>/docs/, return the code set found."""
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
for rel, content in files.items():
target = root / "docs" / rel
target.parent.mkdir(parents=True, exist_ok=True)
target.write_text(content, encoding="utf-8")
return {f.code for f in cdm.audit(root)}
def _svg(inner: str) -> str:
return f'<svg xmlns="http://www.w3.org/2000/svg">{inner}</svg>\n'
# --- one tooth per rule ------------------------------------------------------
_check(
"L1 fires: a leaked version tag",
_audit({"METHOD.md": "# doc\n\nderived from v0.52 privately.\n"}) == {"L1"},
)
_check(
"L2 fires: a leaked family repere",
_audit({"METHOD.md": "# doc\n\nfamily S44 blocks G11.\n"}) == {"L2"},
)
_check(
"L3 fires: a leaked error code",
_audit({"METHOD.md": "# doc\n\nerror E142 was logged.\n"}) == {"L3"},
)
_check(
"L4 fires: a leaked session anchor",
_audit({"METHOD.md": "# doc\n\nratified _2247 that night.\n"}) == {"L4"},
)
# --- excluded by construction (no allow-list) --------------------------------
_whitelist = "# d\n\nSee \u00a74 and \u00a713; the H1 heading token.\n"
_check(
"GREEN: section cross-ref and H1 token do not fire",
_audit({"METHOD.md": _whitelist}) == set(),
)
_clean = "# guide\n\nPlain prose, no private markers.\n"
_check(
"GREEN: clean prose fires nothing",
_audit({"getting-started.md": _clean}) == set(),
)
# --- SVG pair: text in scope, path attribute out of scope --------------------
_check(
"SVG <text> leak fires L2",
_audit({"fig.svg": _svg("<text>S44</text>")}) == {"L2"},
)
_check(
"SVG <path d=...> with the same shape does NOT fire (attributes unread)",
_audit({"fig.svg": _svg('<path d="M0 0 S44 10 20 30"/>')}) == set(),
)
_check(
"SVG <title>/<desc> accessible text is in scope",
_audit({"fig.svg": _svg("<title>see E9</title><desc>ok</desc>")}) == {"L3"},
)
# --- surface scope: non-scanned suffix ignored -------------------------------
_check(
"non-scanned suffix (.txt) is ignored",
_audit({"NOTES.txt": "S44 v0.52 E142 _2247\n"}) == set(),
)
# --- codes coexist -----------------------------------------------------------
_check(
"combined doc fires all four codes",
_audit({"METHOD.md": "# doc\n\nv0.52 S44 E142 _2247 all leak.\n"}) == {"L1", "L2", "L3", "L4"},
)
# --- absent docs/ fails loud -------------------------------------------------
_absent_ok = False
with tempfile.TemporaryDirectory() as _tmp:
try:
cdm.audit(Path(_tmp))
except FileNotFoundError:
_absent_ok = True
_check("absent docs/ raises FileNotFoundError (exit-2 path)", _absent_ok)
print(f"\nran {_passed + _failed} assertions, {_failed} failed")
if _failed:
print("RESULT : FAIL (exit 1)")
sys.exit(1)
print("FLOOR GREEN - all checks pass.")
sys.exit(0)