link-check and render-check each held a byte-identical pages() that walked the filesystem, so gitignored HANDOFF.md could redden a repo-wide gate — 024 had to carry "clear HANDOFF.md first" as a run condition, and a handoff had to be written link-free. Both now import a shared pages() from _pages.py, whose census comes from git ls-files --cached --others --exclude-standard: tracked plus untracked-but-not-ignored is exactly not-ignored, so a page is walked before it is ever added. Where git cannot answer — not a repo, no git on PATH — the walk falls back to the old rglob rather than shrinking to nothing, and the catch is narrow so an unnamed git failure still surfaces. 023 and 019 each state the old walk in their Contract, so both take superseded-by-026; their Contract and Verify are untouched, per 022. 023 also cited the docstring the walk moved out of, so that cite follows it to _pages.py — a cite is a working pointer at every status, per 022 — and _pages.py words that docstring on one line, because a cite symbol that wraps never resolves. 026 passed its muster gate (matches: yes) and flips to implemented. Its Justification loses three lines to fit the tally: block; its Contract and Verify are byte-identical. blueprint 026
97 lines
3.3 KiB
Python
Executable File
97 lines
3.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Validate the rendered loop shape. Usage: render-check <repo-root>
|
|
|
|
Errors (exit 1): the owner page carrying no loop block or more than one,
|
|
a render site diverging from the owner, the retired flat form surviving.
|
|
Nothing warns yet; the tally keeps the siblings' shape.
|
|
|
|
`OKF/ARCHITECTURE.md` flow 1 is the sole owner of the shape; every other
|
|
site is a byte-copy of it or a pointer to it, and a pointer is legal. A
|
|
missing owner block is an error rather than a silent pass because a check
|
|
that cannot fail is not a check: comparing two copies against a vacuum
|
|
matches them both.
|
|
|
|
`OKF/blueprints/` is skipped. A locked blueprint's Contract is immutable,
|
|
so a rule that could turn one red would be unfixable by design, and
|
|
blueprints quote retired forms as record. A page git ignores is skipped
|
|
too: the walk is `_pages.py`'s.
|
|
"""
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from _pages import pages
|
|
|
|
OWNER = "OKF/ARCHITECTURE.md"
|
|
SENTINEL = "substrate (rare) write-OKF — scaffold, or refresh when stale"
|
|
RETIRED = "chart → blueprint"
|
|
|
|
|
|
def render_sites(text):
|
|
"""Fenced blocks opening on the sentinel, as (line number, lines).
|
|
|
|
The line number is the fence's, 1-based, so an error reads as a cite.
|
|
"""
|
|
sites, start, block = [], 0, None
|
|
for number, line in enumerate(text.splitlines(), 1):
|
|
if line.startswith("```"):
|
|
if block is None:
|
|
start, block = number, []
|
|
else:
|
|
if block and block[0].rstrip() == SENTINEL:
|
|
sites.append((start, block))
|
|
block = None
|
|
elif block is not None:
|
|
block.append(line)
|
|
return sites
|
|
|
|
|
|
def diverges(site, canon):
|
|
"""First 1-based line at which a copy departs from the owner.
|
|
|
|
Trailing whitespace is stripped per line and nothing else is
|
|
normalised: the block is box-drawing art whose column positions carry
|
|
the fork, so a reflowed copy is a broken diagram, not a variant.
|
|
"""
|
|
site = [line.rstrip() for line in site]
|
|
canon = [line.rstrip() for line in canon]
|
|
for number, (copied, owned) in enumerate(zip(site, canon), 1):
|
|
if copied != owned:
|
|
return number
|
|
return min(len(site), len(canon)) + 1 if len(site) != len(canon) else 0
|
|
|
|
|
|
def main(argv):
|
|
if len(argv) != 2:
|
|
print("usage: render-check <repo-root>", file=sys.stderr)
|
|
return 2
|
|
root = Path(argv[1]).resolve()
|
|
if not root.is_dir():
|
|
print(f"not a directory: {root}", file=sys.stderr)
|
|
return 2
|
|
|
|
errors = []
|
|
owner = root / OWNER
|
|
owned = render_sites(owner.read_text()) if owner.exists() else []
|
|
if len(owned) != 1:
|
|
errors.append(f"{OWNER}: {len(owned)} loop blocks, expected 1")
|
|
|
|
for page, rel in pages(root):
|
|
text = page.read_text()
|
|
if RETIRED in text:
|
|
errors.append(f"{rel}: retired flat form: {RETIRED}")
|
|
if len(owned) != 1 or page == owner:
|
|
continue
|
|
for number, site in render_sites(text):
|
|
line = diverges(site, owned[0][1])
|
|
if line:
|
|
errors.append(f"{rel}:{number}: diverges from {OWNER} at block line {line}")
|
|
|
|
for line in errors:
|
|
print(f"ERROR {line}")
|
|
print(f"{len(errors)} error(s), 0 warning(s)")
|
|
return 1 if errors else 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main(sys.argv))
|