Spaces:
Sleeping
Sleeping
Commit Β·
22e3bdb
1
Parent(s): b87bd2d
docs(spec): error/risk audit framework design (awaiting review)
Browse files5-tier exhaustive audit + functionality test framework, grounded in this
session's failure cascade + standing silent-failure risks. Tier 4 = both
fast-smoke and exhaustive E2E. Local commit only β not pushed (no redeploy).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
docs/superpowers/specs/2026-05-17-error-audit-framework-design.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Error / Risk Audit Framework β Design Spec
|
| 2 |
+
|
| 3 |
+
| Field | Value |
|
| 4 |
+
| --- | --- |
|
| 5 |
+
| Project | Insurance Sales Portfolio Expert |
|
| 6 |
+
| Date | 2026-05-17 |
|
| 7 |
+
| Status | Draft β awaiting user spec review |
|
| 8 |
+
| Goal | One runnable, exhaustive framework that mechanically catches **every class of error/risk** before commit/deploy, and **tests all functionality**, so the failure cascade of the 2026-05-16/17 recovery session cannot recur silently. |
|
| 9 |
+
|
| 10 |
+
## 1. Purpose & non-goals
|
| 11 |
+
|
| 12 |
+
**Purpose:** a single command that, run before commit / before push / after deploy,
|
| 13 |
+
fails loudly on any known risk class with concrete evidence β replacing the
|
| 14 |
+
ad-hoc, reactive checking that let symlinks, un-LFS'd blobs, dead symbols, a
|
| 15 |
+
CSS-comment 500, and stale docs reach (or nearly reach) production.
|
| 16 |
+
|
| 17 |
+
**Non-goals (YAGNI):** not a CI server, not a replacement for `pytest` (it
|
| 18 |
+
*orchestrates* it), not a linter rewrite (it *invokes* `ruff`/`tsc`), no new
|
| 19 |
+
test framework. It is an orchestrator + a set of project-specific risk checks
|
| 20 |
+
that don't exist in any off-the-shelf tool.
|
| 21 |
+
|
| 22 |
+
## 2. Risk taxonomy β the checks (this is "all risks")
|
| 23 |
+
|
| 24 |
+
Every check is grounded in a real incident this session or a standing
|
| 25 |
+
memory-logged silent-failure risk.
|
| 26 |
+
|
| 27 |
+
### Tier 1 β Repo integrity (fast; pre-commit)
|
| 28 |
+
- **T1.1 no tracked symlinks** β `git ls-files -s` mode `120000` β FAIL (the `rag/corpus`/`rag/extracted` Docker-build killer).
|
| 29 |
+
- **T1.2 LFS coverage** β every path matching an LFS pattern in `.gitattributes` is an LFS pointer in the index; any tracked binary >512 KB not LFS β FAIL (the insurer-logos / HF pre-receive-hook rejection).
|
| 30 |
+
- **T1.3 no real secrets** β no tracked file is a real `.env`/key material (allow `*.example`, docs, scripts that *read* secrets); entropy/key-shape scan of staged content.
|
| 31 |
+
- **T1.4 .gitignore robustness** β for each ignore intent (caches, `rag/corpus`, `rag/extracted`, `rag/vectors`) assert both file and dir forms are ignored (trailing-slash gap that committed the symlinks).
|
| 32 |
+
- **T1.5 no junk committed** β `tools/.pdf_text_cache/`, `.pytest_cache/`, `.DS_Store`, `frontend/out/`, `.next/`, `node_modules/`, `*.tsbuildinfo` not tracked.
|
| 33 |
+
|
| 34 |
+
### Tier 2 β Code soundness (pre-commit)
|
| 35 |
+
- **T2.1 AST parse** β every `*.py` parses.
|
| 36 |
+
- **T2.2 runtime-import** β import **every** `backend/**` + `rag/**` module in a subprocess; any `ImportError`/`NameError` β FAIL (the import-injected-into-docstring class; AST is necessary-not-sufficient).
|
| 37 |
+
- **T2.3 dead-symbol scan** β no code reference to deleted modules/symbols: `orchestrator`, `sales_brain`, `qa_brain`, `faithfulness`, `translator`, `profile_extractor`, `get_judge_llm`, `get_fast_brain_llm` (comments/docstrings = WARN, code = FAIL).
|
| 38 |
+
- **T2.4 comment footgun** β `*/` inside a CSS/JS/C block-comment body β FAIL (the app-wide 500).
|
| 39 |
+
- **T2.5 path-literal regression** β no `"40-data"` path *construction* in `backend/**`/`rag/**` (must use `settings.DATA_DIR`); descriptive prose = WARN.
|
| 40 |
+
- **T2.6 lint/typecheck** β `ruff check` (py) + `tsc --noEmit` (frontend) clean.
|
| 41 |
+
|
| 42 |
+
### Tier 3 β Build & test gates
|
| 43 |
+
- **T3.1 pytest** β bare `pytest` (clean-clone scoping) green; record count, FAIL on any fail/error/collection-error.
|
| 44 |
+
- **T3.2 next build** β `npm run build` exit 0 + static export emitted (`frontend/out/*.html`).
|
| 45 |
+
- **T3.3 backend boot** β `uvicorn` app imports; a local instance answers `/api/health` ok.
|
| 46 |
+
|
| 47 |
+
### Tier 4 β Functionality (BOTH sub-tiers)
|
| 48 |
+
- **T4-smoke (fast):** each API endpoint touched once locally β `health, version, coverage` (counts sane vs expected β148/20/~7.3k), `chat` (one turn returns a reply), `upload-policy` (accept a real PDF β quarantined; reject a junk PDF), `profile`, `scorecard`, `session/clear`. Each Playwright surface loaded once @ desktop+390px (no console error, no horizontal overflow).
|
| 49 |
+
- **T4-e2e (exhaustive):** full Playwright journeys β fact-find β recommendation with **inline cards**; marketplace browse + filter; compare modal (β€4); profileβpremium live recompute; voice copy correct on touch vs desktop; PDF upload UI β in-chat ack; session reset/recall; admin panel gated. Plus the existing `pytest` unit/contract suite (security gates, scoring, premium, recall, conversation logic) is the deterministic backbone.
|
| 50 |
+
|
| 51 |
+
### Tier 5 β Deploy safety (pre-push + post-deploy)
|
| 52 |
+
- **T5.1 LFS pre-push validation** β simulate HF's rule: any to-be-pushed file matching an LFS pattern that isn't a pointer β FAIL *before* the push (pre-empts the pre-receive-hook rejection).
|
| 53 |
+
- **T5.2 Dockerfile coherence** β every `COPY <src>` exists in the tree; dataset-hydration step won't collide (no tracked `rag/corpus|extracted|vectors`).
|
| 54 |
+
- **T5.3 post-deploy guarded verify** β HF runtime API `runtime.sha` **actually equals the pushed commit** (never trust "RUNNING"; the LFS-quota silent-failure rule); live smoke: `/api/health` ok, frontend 200, an insurer-logo asset returns real `image/png` (LFS materialized), `/api/coverage` counts sane.
|
| 55 |
+
- **T5.4 standing tripwires** β ChromaDB `link_lists.bin` / `_hf_dataset_backup` bloat, disk-free, quarantine-TTL sanity; stale-doc present-state scan (docs asserting the deleted architecture as current) = WARN.
|
| 56 |
+
|
| 57 |
+
## 3. Architecture
|
| 58 |
+
|
| 59 |
+
A modular Python package `audit/` in the repo:
|
| 60 |
+
|
| 61 |
+
```
|
| 62 |
+
audit/
|
| 63 |
+
__main__.py # CLI: python -m audit [--static|--build|--functional|--deploy|--all] [--json]
|
| 64 |
+
core.py # Check protocol, Result(PASS/WARN/FAIL, evidence), runner, report, exit code
|
| 65 |
+
tier1_repo.py # T1.* checks
|
| 66 |
+
tier2_code.py # T2.*
|
| 67 |
+
tier3_build.py # T3.*
|
| 68 |
+
tier4_functional.py# T4-smoke + T4-e2e (drives the playwright-skill scripts)
|
| 69 |
+
tier5_deploy.py # T5.* (read-only; never mutates prod)
|
| 70 |
+
selftest/ # one deliberately-broken fixture per check β proves the auditor itself works
|
| 71 |
+
tools/audit # thin entrypoint: `tools/audit --all`
|
| 72 |
+
.githooks/pre-commit # optional: runs --static
|
| 73 |
+
.githooks/pre-push # optional: runs --build + T5.1/T5.2
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
**Check contract (isolation principle):** every check is a function
|
| 77 |
+
`def check(ctx) -> Result` β pure, independent, returns `PASS|WARN|FAIL` +
|
| 78 |
+
human-readable evidence + the exact remediation. No check depends on another's
|
| 79 |
+
side effects. New risk class = one new function; nothing else changes.
|
| 80 |
+
|
| 81 |
+
**Runner:** executes selected tiers, prints a per-check table + a final
|
| 82 |
+
summary, exits non-zero iff any `FAIL` (WARN never fails the gate but is always
|
| 83 |
+
shown). `--json` for machine use / future CI.
|
| 84 |
+
|
| 85 |
+
**Tiers map to when:** `--static` = Tier 1+2 (pre-commit, seconds);
|
| 86 |
+
`--build` = +Tier 3; `--functional` = +Tier 4 (needs local backend + Playwright);
|
| 87 |
+
`--deploy` = Tier 5; `--all` = everything (exhaustive).
|
| 88 |
+
|
| 89 |
+
**Self-verifying:** `audit/selftest/` holds a deliberately-broken fixture for
|
| 90 |
+
each check; `python -m audit --selftest` asserts every check *fails on the
|
| 91 |
+
broken fixture* β so a silently-broken auditor (the deepest risk) is itself
|
| 92 |
+
caught.
|
| 93 |
+
|
| 94 |
+
## 4. Error handling
|
| 95 |
+
|
| 96 |
+
- A check that errors internally β reported `FAIL` (never silently skipped β silence-is-not-success).
|
| 97 |
+
- Tier 4/5 needing an unavailable resource (no local backend, no network) β explicit `SKIP` with reason in the report (never a false `PASS`), and `--all` records skips prominently.
|
| 98 |
+
- Read-only against production: Tier 5 only does HTTP GET + `git ls-remote`; never pushes/mutates.
|
| 99 |
+
|
| 100 |
+
## 5. Testing the framework
|
| 101 |
+
|
| 102 |
+
The `--selftest` suite (broken-fixture-per-check) is the framework's own test;
|
| 103 |
+
it runs in `--all`. Additionally a tiny `tests/test_audit_selftest.py` so the
|
| 104 |
+
auditor's integrity is itself in the 215-green `pytest` gate.
|
| 105 |
+
|
| 106 |
+
## 6. Out of scope (explicit)
|
| 107 |
+
|
| 108 |
+
CI/CD server config; auto-fixing (it reports + gives the exact remediation, it
|
| 109 |
+
does not mutate code); replacing pytest/ruff/tsc; auditing other repos.
|
| 110 |
+
|
| 111 |
+
## 7. Open items
|
| 112 |
+
|
| 113 |
+
None β Tier-4 resolved to **both** sub-tiers per user. Ready for plan.
|