#!/usr/bin/env python3 """Verify the OIDC client module is single-sourced and byte-identical. Checks, in order, and exits non-zero naming every failure: 1. canonical ops-docs/scripts/shared/oidc_client.py == member-dashboard/app/oidc.py (byte-identical, sha256) == admin-panel/app/oidc.py (byte-identical, sha256) 2. each repo's tests/test_oidc_sync.py pins the CANONICAL revision (so CI — which has no ops-docs checkout — still goes red when a repo copy is hand-edited). 3. each repo's app/main.py calls oidc.configure(...) with THAT repo's identity literal (cookie name + salt preserved from the pre-consolidation apps, so existing sessions survive). Run from anywhere: python3 ops-docs/scripts/check-oidc-sync.py This is the pre-deploy gate for either thin app; sync-oidc-module.sh runs it at the end of every sync. """ import hashlib import re import sys from pathlib import Path HERE = Path(__file__).resolve().parent # ops-docs/scripts REPOS = HERE.parent.parent # ~/repos CANONICAL = HERE / "shared" / "oidc_client.py" # repo name -> (copy path, pin-test path, main path, expected configure call) APPS = { "member-dashboard": ( "app/oidc.py", "tests/test_oidc_sync.py", "app/main.py", 'oidc.configure("member-dashboard", "member_oidc_session", ' '"member-dashboard-oidc-session")', ), "admin-panel": ( "app/oidc.py", "tests/test_oidc_sync.py", "app/main.py", 'oidc.configure("admin-panel", "admin_oidc_session", ' '"admin-panel-oidc-session")', ), } def sha256_file(p: Path) -> str: return hashlib.sha256(p.read_bytes()).hexdigest() def main() -> int: failures = [] if not CANONICAL.exists(): print(f"FAIL canonical module missing: {CANONICAL}") return 1 canon_sha = sha256_file(CANONICAL) print(f"canonical {CANONICAL.relative_to(REPOS)} sha256={canon_sha[:16]}…") for repo, (copy_rel, pin_rel, main_rel, expected_configure) in APPS.items(): repo_dir = REPOS / repo copy = repo_dir / copy_rel pin = repo_dir / pin_rel app_main = repo_dir / main_rel if not copy.exists(): failures.append(f"{repo}: copy missing: {copy}") continue copy_sha = sha256_file(copy) if copy_sha == canon_sha: print(f"ok - {repo}: {copy_rel} byte-identical to canonical " f"(sha256={copy_sha[:16]}…)") else: failures.append( f"{repo}: {copy_rel} DRIFTED from canonical\n" f" canonical sha256={canon_sha}\n" f" copy sha256={copy_sha}\n" f" fix: edit the canonical file and run " f"ops-docs/scripts/sync-oidc-module.sh — never hand-edit the copy.") if pin.exists() and canon_sha in pin.read_text(): print(f"ok - {repo}: pin test records this canonical revision") else: failures.append( f"{repo}: {pin_rel} does not pin canonical revision {canon_sha[:16]}… " f"(run sync-oidc-module.sh to re-pin)") if app_main.exists() and expected_configure in app_main.read_text(): print(f"ok - {repo}: main.py configures the app identity") else: failures.append( f"{repo}: {main_rel} does not call the expected identity literal:\n" f" {expected_configure}") if failures: print() print(f"FAILED: {len(failures)} problem(s)") for f in failures: print(" - " + f) return 1 print() print("oidc module sync: all copies byte-identical, pins current, identities wired") return 0 if __name__ == "__main__": sys.exit(main())