chore(memory): R2 delivered — BDR-050, LRN-054, BLK-010, EVAL-020, journal, TODO, verify contract

This commit is contained in:
bchanot committed 2026-10-14 01:05:13 +02:00
1 parent e49009e363
commit 651f1fef13
7 files changed
+93 -8

No files matched your search

+10 -8
View File
@@ -166,14 +166,16 @@ feat/findings-tree-v2 merged (FindingsTreePicker tracked in HEAD); all work belo
- [ ] R2 domain core (before Step 9): sheet/report/archive contracts, `SheetHandle` + `SheetIndexData`, reducers, Finding builder, vertebra selection, publish gate; wasm facade (JSON strings, ts-rs types, poison + reinstantiate, lazy init); app switched; 3 envelopes frozen first; N-1 reader test; draft quarantine; conformance fixtures + generated pgTAP; `packages/domain` frozen for engine/pipeline
- plan + contract: `.claude/tasks/plans/2026-10-13-rust-r2-domain-core.md` (rev 2 after 3 challenges, 45 findings folded); branch `feature/rust-r2-domain-core`; owner wording of the 4 new strings validated 2026-10-13
- [x] R2.0 freeze: 3 archive envelopes (demo, v2full, v2unresolved; FR, no logos, fixed time) + verbatim N-1 Zod copy (`packages/core-wasm/tests/n-1`) (3114d67); Zod output oracles of the reference documents (`crates/core/tests/oracles`)
- [ ] R2.0b characterisation set of the TS quirks (migrate, rebase, reducers, numeric literals, surrogates) + hostile-input verdict table per constraint site
- [ ] R2.1 Rust contracts: js semantics, sheet, report v2/v3/identity/map, snapshot/branding/labels/envelope; ts-rs types; byte-equal on oracles + frozen envelopes
- [ ] R2.2 Rust rules: 21 integrity rules + check, create_empty, index + SheetIndexData, read/migrate, rebase, snapshot build/assert, envelope layered read, draft restore; ported domain suites; conformance fixtures + generated pgTAP 011 + drift test
- [ ] R2.3 Rust editor rules: zone click + reducers, finding toggle, vertebra initial/sync/select, report new/add/remove/move
- [ ] R2.4 facade + runtime: SheetHandle, ops, typed failures; core-wasm runtime (lazy, generation, poison, spare glue, cap 3, retry), Node/browser sources, globalSetup stamp, pkg vs pkg-proofs; trap/load tests; size; checkpoint report to the owner
- [ ] R2.5 app switch: provider/useSheet degraded states, SheetIndex class, store `{ok}` actions, persistence + quarantine, click chain, pickers, finding picker, import/export, Home + /new availability, publish gate fail-closed, ESLint restriction, pickLocaleLabel, deletions; suites green, changed assertions listed
- [ ] R2.6 images + serving: Dockerfile wasm stage, ignores, nginx compression, check:all, CSP proof on the image (Chromium + Firefox/WebKit if present), measurements
- [ ] R2.7 docs (RUST.md R2 + census, CLAUDE.md, WORKSPACE, TEST_STRATEGY, packages/README, DEPLOY note, CHANGELOG), verifier + security gates, memory, LAN manual procedure; STOP (no merge)
- [x] R2.0b characterisation frozen from the TS: 84 report/archive cases + 765 Zod verdicts (fork B), 49 editor cases (fork C), 26 conformance fixtures (fork A), horse-slice JSON
- [x] R2.1 Rust contracts (ee07008): byte-equal to Zod output on draft + legacy sheets, demo report; the 3 frozen envelopes round-trip byte-equal
- [x] R2.2 Rust rules (0c47d0f, 21906c4): integrity rules, check, create, index data, read/migrate (612 leaves), rebase, snapshot, layered read, session restore/import; pgTAP 011 generated (PGlite 12/12, real 446/446)
- [x] R2.3 editor rules (3639c87) + facade ops (6c0533c)
- [x] R2.4 runtime (343d6f4): lazy, poison, offline recovery, per-generation handles, cap 3, retry, pkg/pkg-proofs, BUILD_STAMP; browser-checked dev + build; measurements (794dfd9)
- [x] R2.5 app switch (74fcb37) + publish gate fail-closed (6891f9e); app 313/313 on the real core (fork D adapted 17 files, 24 new tests, found 2 src bugs fixed)
- [x] R2.6 image + serving (7be94d4): wasm stage, gzip_static 372 KB served, CSP proof on the image 15/15 (Chromium only; no Firefox/WebKit build here), check:all green 2 min 17 s
- [x] R2.7 docs (8e8c58e: RUST.md §8, CLAUDE.md, WORKSPACE, TEST_STRATEGY, packages/README, DEPLOY, CHANGELOG), verifier 12/12 + floor ECARTS(2) (deleted tests, owner micro-gate), security PASS ×2 (follow-ups e49009e), memory BDR-050 LRN-054 BLK-010 EVAL-020; STOP (no merge)
- [ ] R2 owner points: manual LAN validation (procedure in the delivery note), L1 decision (lone surrogate → U+FFFD), approve the 2 deleted test files (floor), worktree cleanup (BLK-010), then merge go
- [ ] R2 follow-ups: Firefox/WebKit CSP run (no browser build here), import in a Web Worker (R4), React error boundary (not decided), base images by digest (Step 27), wording of the storage-full degraded notice
- [ ] R3 anatomy core: tree, one sanitiser, serialiser, layer renderer, `compose_view_svg`; app canvas switched; composed views frozen as trees first
- [ ] R4 pdf core: reader (Web Worker, BLK-009 browser measurements) + writer (`pdf-writer`, Std14 AFM, draw log; lines/rects/colours golden frozen with the TS engine first, D-R2) + `report-compare` tool; `packages/pdf` deleted; N-1 scanner reads R4 PDFs
- [ ] R5 curation pipeline + importer + upload tool: seed golden regenerated once (new `documentSha256`, D-R5), `packages/anatomy` + `packages/domain` deleted, docs map; all before Step 13
@@ -0,0 +1,49 @@
# CONTRACT — Rust R2: domain core in Rust, used by the application
- date: 2026-10-14 | flow: orchestrator + 4 forks (3 worktrees + 1 in tree), plan challenges ×3, verifier gate | branch: feature/rust-r2-domain-core (off develop 1a7ee7d)
- status: dispatched after the implementation, test and doc commits
- spec: `.claude/tasks/plans/2026-10-13-rust-r2-domain-core.md` (plan + revision 2 §5, which wins), `docs/development/RUST_ARCHITECTURE_REVIEW.md` VI.2 R2 row, VI.3, VI.4, owner brief 2026-10-13 (R2 go: §2 scope, §3 compatibility, §5 runtime, §6 CSP and measures, §7 no UI redesign, §9 tests, §12 exclusions)
- diff range: 1a7ee7d..HEAD (run every CHECK from the repository root; `. scripts/rust-env.sh` first for cargo)
## REQUEST (IMMUTABLE)
Migrate the existing domain core of Faunosteo to Rust and switch the application to it, with no business behaviour change without a separate decision: sheet / report / archive contracts, SheetHandle and index, observation reducers, finding construction, vertebra selection, publish checks, related transformations and validations, in crates/core and the wasm facade; consumers switched; React, DOM, forms and Supabase services stay in their layers. Preserve Report v3, v2 PDF imports, autonomous archives, observations, findings, vertebrae, annotations, sheet versions, unresolved content, FR/EN, old data; freeze the three archive envelopes first; keep a permanent N-1 reader test; JSON rules (absent optionals, nullable, number format) conformant; no silent loss. Lazy wasm, explicit instantiation failures, no reuse after a trap, degraded behaviour when unavailable. CSP with 'wasm-unsafe-eval' only; measure size, init, op times, page impact, memory; no wasm on pages that do not need it. No UI redesign (four new strings validated by the owner). Out: R3, R4, R5, Step 9, CI/CD, deploy, release 0.2.0, merge into develop.
## ACCEPTANCE CRITERIA
1. The native Rust gate is green (fmt, clippy -D warnings, tests, ts-rs export, cargo deny).
CHECK: bash scripts/rust-check.sh > /tmp/r2-verify-rust.log 2>&1; echo "exit $?"
EXPECT: exit 0
2. The core carries at least 135 passing tests (contracts, rules, oracles, conformance).
CHECK: . scripts/rust-env.sh && cargo test -p faunosteo-core 2>&1 | grep "test result" | awk '{s+=$4; f+=$6} END {print s, f}'
EXPECT: 135 0 (first number ≥ 135, second 0)
3. The application sources no longer import the TypeScript domain, and no domain rule or the deleted service is reachable from them by name.
CHECK: grep -rln "@faunosteo/domain" apps/app/src | wc -l; grep -rnE "decideZoneClick|collectVertebrae|buildSheetIndex|buildSheetSnapshot|rebaseReportOnSheet|readReportDocument|readArchiveDocument|zoneInteraction" apps/app/src | wc -l; test -e apps/app/src/services/zoneInteraction.ts; echo $?
EXPECT: 0 / 0 / 1
4. The application suite passes on the real core (313 tests), including the four new R2 suites.
CHECK: bash scripts/wasm-build.sh > /dev/null 2>&1; ./node_modules/.bin/pnpm --filter @faunosteo/app exec vitest run 2>&1 | grep -E "^ +Tests "; ls apps/app/tests/unit/ | grep -cE "n-1.reader|state.quarantine|routes.EditorRoute.degraded|state.coreFailures"
EXPECT: Tests 313 passed (313) / 4
5. The Step 6 goldens, the seed and the other packages' fixtures are untouched by R2, and the three frozen archive envelopes are unchanged since their freeze commit.
CHECK: git diff --stat 1a7ee7d..HEAD -- apps/app/tests/fixtures/goldens/step6 supabase/seed packages/domain/tests/fixtures packages/pdf/tests packages/anatomy/tests | wc -l; git diff --stat 3114d67..HEAD -- apps/app/tests/fixtures/goldens/r2 | wc -l
EXPECT: 0 / 0
6. The shipped module carries no trap export and stays under the 600 KB compressed budget.
CHECK: grep -cE "panic_for_test|recurse_for_test" packages/core-wasm/pkg/faunosteo_wasm.d.ts; gzip -9 -c packages/core-wasm/pkg/faunosteo_wasm_bg.wasm | wc -c
EXPECT: 0 / a number ≤ 600000
7. No auth, account, shell or entry module references the core runtime (the module is only loaded from the sheet pages).
CHECK: grep -rl "@/core/" apps/app/src/app/routes/auth apps/app/src/app/routes/app apps/app/src/components/shell apps/app/src/components/account apps/app/src/app/App.tsx apps/app/src/main.tsx | wc -l
EXPECT: 0
8. Only the content failure kinds set a draft aside, and the core-wasm suite proves the runtime (lazy load, trap, recovery, handle rebuild, cap, retry, size).
CHECK: grep -c "outcome.kind !== 'invalid' && outcome.kind !== 'unsupported_version'" apps/app/src/state/reportStore.ts; ./node_modules/.bin/pnpm --filter @faunosteo/core-wasm exec vitest run 2>&1 | grep -E "^ +Tests "
EXPECT: 1 / Tests 25 passed (25)
9. The publish gate fails closed and runs on the real core; the SQL suite (incl. the generated conformance file 011) passes on PGlite.
CHECK: grep -c "refuses publication when the validator cannot run" packages/supabase/tests/anatomical-sheets.test.ts; ./node_modules/.bin/pnpm --filter @faunosteo/supabase exec vitest run 2>&1 | grep -E "^ +Tests "; ./node_modules/.bin/pnpm --filter @faunosteo/supabase exec vitest run tests/db/pgtap.test.ts 2>&1 | grep -E "^ +Tests "
EXPECT: 1 / Tests 39 passed (39) / Tests 12 passed (12)
10. The four validated strings exist in both dictionaries.
CHECK: for k in sheet.core_unavailable sheet.core_retry core.action_failed editor.draft_quarantined home.import.error_core_unavailable; do printf "%s/%s " $(grep -c "'$k'" apps/app/src/i18n/fr.ts) $(grep -c "'$k'" apps/app/src/i18n/en.ts); done
EXPECT: 1/1 1/1 1/1 1/1 1/1
11. Documentation records the migration (RUST.md §8, DEPLOY.md R2 notes, CHANGELOG).
CHECK: grep -c "^## 8. R2" docs/development/RUST.md; grep -c "From R2 on" DEPLOY.md; grep -c "Rust R2" CHANGELOG.md
EXPECT: 1 / 1 / 1
12. The whole pre-merge gate passes.
CHECK: bash scripts/check-all.sh > /tmp/r2-verify-all.log 2>&1; echo "exit $?"; grep -c "== all checks passed" /tmp/r2-verify-all.log
EXPECT: exit 0 / 1
## FILE SCOPE
crates/core/**, crates/wasm/**, Cargo.toml, Cargo.lock, packages/core-wasm/**, packages/supabase/{src/anatomical-sheets.ts,src/index.ts,package.json,tests/anatomical-sheets.test.ts,vitest.config.ts}, packages/domain/tests/r2-*.test.ts, apps/app/{src,tests,scripts,eslint.config.js,vitest.config.ts,package.json}, supabase/tests/011_sheet_conformance.sql, scripts/{wasm-build.sh,wasm-stamp.mjs}, Dockerfile, docker/nginx.conf, docker/csp-proof/app-image.{sh,mjs}, .gitignore, .dockerignore, .prettierignore, pnpm-lock.yaml, docs/development/{RUST,WORKSPACE,TEST_STRATEGY}.md, packages/README.md, CLAUDE.md, DEPLOY.md, CHANGELOG.md, .claude/tasks/** (plan, TODO, this contract), .claude/memory/** (registries).