From 5f4feaddd56471622dd7f2428761c66311cb1ad1 Mon Sep 17 00:00:00 2001 From: CodeSigils Date: Fri, 21 Aug 2026 18:20:51 +0300 Subject: [PATCH] fix: remove dead code, consolidate regex, fix unreachable, simplify version check --- .github/scripts/_url_contract.py | 2 +- scripts/_common.py | 12 ------------ scripts/check-version-consistency.py | 13 ++++++------- scripts/cron-health.py | 3 +-- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/.github/scripts/_url_contract.py b/.github/scripts/_url_contract.py index 77c75af..0f635e5 100644 --- a/.github/scripts/_url_contract.py +++ b/.github/scripts/_url_contract.py @@ -124,7 +124,7 @@ def check_url(entry: dict[str, Any], timeout: int = 15) -> CheckResult: time.sleep(0.25 * (attempt + 1)) continue return CheckResult("ERROR", tracker.count, str(exc), entry["url"]) - raise AssertionError("unreachable") + raise RuntimeError("unreachable — for loop always returns") def contract_drift_reasons(entry: dict[str, Any], result: CheckResult) -> list[str]: diff --git a/scripts/_common.py b/scripts/_common.py index cdfabc2..a6284e6 100644 --- a/scripts/_common.py +++ b/scripts/_common.py @@ -131,18 +131,6 @@ def fail(message: str, hint: str | None = None) -> None: print(f" HINT: {hint}", file=sys.stderr) -def contains_markdown_phrase(text: str, phrase: str) -> bool: - """Check if *phrase* exists in *text* with whitespace normalization. - - Collapses runs of whitespace (spaces, tabs, newlines) to single spaces - before matching, so formatting changes don't cause false negatives. - """ - import re as _re - normalized = _re.sub(r"\s+", " ", text) - phrase_normalized = _re.sub(r"\s+", " ", phrase) - return phrase_normalized in normalized - - # ── unsafe probe detection ──────────────────────────────────────────────── UNSAFE_PROBE_PATTERNS: list[tuple[str, str]] = [ diff --git a/scripts/check-version-consistency.py b/scripts/check-version-consistency.py index b1a5da4..f957897 100644 --- a/scripts/check-version-consistency.py +++ b/scripts/check-version-consistency.py @@ -71,16 +71,15 @@ def main() -> int: return 0 # Check consistency - versions = set(sources.values()) - if len(versions) > 1: + citation_ver = sources.get(CITATION_CFF) + pyproject_ver = sources.get(PYPROJECT_TOML) + if citation_ver != pyproject_ver: for source, ver in sorted(sources.items()): errors.append(f"version-mismatch: {source} has version {ver!r}") - # Show what they should be - most_common = max(versions, key=lambda v: sum(1 for sv in sources.values() if sv == v)) - errors.append(f"version-mismatch: expected all sources to use {most_common!r}") + expected = citation_ver or pyproject_ver + errors.append(f"version-mismatch: expected all sources to use {expected!r}") else: - ver = versions.pop() - print(f"PASS: all version sources agree on {ver!r}") + print(f"PASS: all version sources agree on {citation_ver!r}") if errors: for error in errors: diff --git a/scripts/cron-health.py b/scripts/cron-health.py index 66f5c5f..ebdb163 100644 --- a/scripts/cron-health.py +++ b/scripts/cron-health.py @@ -13,10 +13,9 @@ import re import sys -from _common import ROOT, find_markdown_files +from _common import ROOT, SKILL_REF_RE, find_markdown_files RELATIVE_LINK_RE = re.compile(r"\[.*?\]\(((?!https?://|mailto:|#)[^)]+)\)") -SKILL_REF_RE = re.compile(r"\]\((references/[^)\s]+\.md)\)") def check_link_rot() -> list[str]: