Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """Deterministic static-analysis regression for Phase 08-04: generated-resume | |
| history (R19). The extension JS can't run headless, so we assert the wiring | |
| CONTRACT by source inspection. ASCII-only output. | |
| Proves: | |
| * popup.html has a collapsible History UI (#history-toggle + #history-list). | |
| * popup.js renders a restorable history list (renderHistory / restoreFromHistory | |
| reusing applyResult, reading ats_results via RESULTS_KEY, refreshing on | |
| chrome.storage.onChanged, showing per-entry scores + status). | |
| * background.js raises MAX_SAVED above 10 and guards the chrome.storage.local | |
| quota (approxSize + stripOldestArtifacts + BYTE_BUDGET) without changing the | |
| R15 contract (normalizeUrl + ats_results + status:'running'). | |
| Exit code: 0 when every assertion passes, 1 otherwise. | |
| """ | |
| import os | |
| import re | |
| import sys | |
| REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| EXT = os.path.join(REPO_ROOT, "extension") | |
| POPUP_HTML = os.path.join(EXT, "popup", "popup.html") | |
| POPUP_JS = os.path.join(EXT, "popup", "popup.js") | |
| BG = os.path.join(EXT, "background.js") | |
| _failures = [] | |
| def _read(path): | |
| with open(path, encoding="utf-8") as fh: | |
| return fh.read() | |
| def check(condition, message): | |
| if condition: | |
| print(f" [PASS] {message}") | |
| else: | |
| print(f" [FAIL] {message}") | |
| _failures.append(message) | |
| def test_popup_html(): | |
| print("[1] popup.html has the collapsible History UI") | |
| h = _read(POPUP_HTML) | |
| check("history-list" in h, "popup.html has #history-list container") | |
| check("history-toggle" in h, "popup.html has #history-toggle control") | |
| def test_popup_js(): | |
| print("[2] popup.js renders a restorable, re-downloadable history list") | |
| js = _read(POPUP_JS) | |
| for token in ("renderHistory", "restoreFromHistory", "applyResult", "RESULTS_KEY"): | |
| check(token in js, f"popup.js references '{token}'") | |
| check("chrome.storage.onChanged" in js, | |
| "history refreshes on chrome.storage.onChanged") | |
| check(("external_score" in js or "external_coverage_pct" in js) and "status" in js, | |
| "history surfaces per-entry external score + status") | |
| def test_background(): | |
| print("[3] background.js raises retention + guards the quota (R15 intact)") | |
| js = _read(BG) | |
| m = re.search(r"MAX_SAVED\s*=\s*(\d+)", js) | |
| check(bool(m) and int(m.group(1)) > 10, | |
| f"MAX_SAVED raised above 10 (got {m.group(1) if m else 'n/a'})") | |
| for token in ("approxSize", "stripOldestArtifacts", "BYTE_BUDGET"): | |
| check(token in js, f"quota guard references '{token}'") | |
| check("normalizeUrl" in js and "ats_results" in js, | |
| "ats_results key + normalizeUrl contract unchanged") | |
| check("status: 'running'" in js or 'status: "running"' in js | |
| or "'running'" in js, | |
| "R15 running marker preserved") | |
| def main(): | |
| print("=" * 66) | |
| print("Phase 08-04 verification: generated-resume history (R19)") | |
| print("=" * 66) | |
| test_popup_html() | |
| test_popup_js() | |
| test_background() | |
| print("-" * 66) | |
| if _failures: | |
| print(f"FAIL - {len(_failures)} check(s) failed:") | |
| for f in _failures: | |
| print(f" - {f}") | |
| return 1 | |
| print("PASS - history browse/restore UI + quota-guarded retention verified") | |
| return 0 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |