docs(docs): Step 8 / R1 — files foundation, worker loop, avatar: CLAUDE, DEPLOY (.env.worker, CSP), SUPABASE, RUST, TEST_STRATEGY, WORKSPACE, IDENTITY §5, design README, plan as-built note, CHANGELOG; R1 plan and verifier contract
This commit is contained in:
1 parent
0c6053c174
commit
62eb4e5d82
13 files changed
+235
-35
No files matched your search
@@ -126,14 +126,16 @@ feat/findings-tree-v2 merged (FindingsTreePicker tracked in HEAD); all work belo
|
||||
- [x] 7.8 tests: config, authStore (fake client), locale sync, forms, guards, shell, dashboard, account; i18n parity; pgTAP 009 (PGlite + real stack 280/280); root check + docker build green; headless e2e vs local stack 20/20 (signup via Mailpit, recovery, logout, mobile)
|
||||
- [x] 7.9 docs (IDENTITY.md, SUPABASE.md, CLAUDE.md, CHANGELOG, plan note); memory BDR-041, LRN-047, EVAL-015, journal; gates: verifier ECARTS(2) → open-redirect fix + contract CHECK → CONFORME 16/16; security PASS (MEDIUM fixed, 3 LOW closed, TOTP enforcement = documented gap). User validated 2026-10-12; user action still open: `.env.example` += `APP_AUTH_PROVIDERS=` (file edit denied here)
|
||||
- [ ] 7.10 follow-ups kept by the user (2026-10-12), each owned by a later step: MFA mandatory before any sensitive admin feature (has_mfa helper + enrolment UI, IDENTITY.md §4; first admin screen); professional verification distinct from the SIRET format check (Step 11); real tests of Google and Apple once the provider ids exist (config.toml env(), APP_AUTH_PROVIDERS); integration of the report tool into the signed-in /app space (Step 14 gating); mockup elements not built yet listed in docs/design/README.md (bell, avatar photo → Step 8, stat tiles, tabs, mobile tab bar)
|
||||
- [ ] Step 8 — files foundation + Supabase Storage (analysis 2026-10-12 on chore/step-08-files-analysis: docs/development/STEP8_FILES_ANALYSIS.md; 3 plan-challengers (47 findings folded, rev 2); AWAITING USER DECISIONS D1–D9 + go; nothing implemented). User brief: 8 private buckets closed by default, quarantine + server validation, allowlist SVG, avatar in Mon compte (upload/preview/replace/delete/header), JPEG/PNG/WebP ≤ 5 MB resized + metadata stripped, no SVG avatar, service role never in the browser, portable self-hosted → managed, allowed + denied access tests
|
||||
- [ ] Step 8 = Rust R1 — files foundation + Supabase Storage + avatar (GO 2026-10-13: R0 validated, D1–D9 validated with D1 = Rust worker, D3 = top-bar avatar + name linking to Mon compte; branch feature/step-08-files-foundation, cut from the R0 tip because `gitflow finish` of R0 was refused by the harness classifier: the owner runs it). Analysis: docs/development/STEP8_FILES_ANALYSIS.md; contract-level spec written first in docs/development/STORAGE.md. Out: SVG upload (Step 13), other buckets' flows, PDF/anatomy ports, webhooks, CI/CD, VPS deploy, release 0.2.0
|
||||
- [x] 8.0 analysis: facts (existing bucket + policy pattern, sanitiser, edge runtime off, CSP, deploy), design (assets table authority, server-built keys, quarantine prefix, worker `faunosteo_worker` with sharp + pdf sanitiser, storage.objects policies through assets, Storage API signing under RLS, sweeper/reconcile, backups file volume + restic, managed migration by rows), 10 security answers, scope, tests, risks, D1–D8
|
||||
- [ ] 8.1 migration 20261012100000_files_foundation (asset_status, assets, 7 buckets, avatar predicates, avatars policies, purge queue + triggers, storage ceiling, 9 RPCs, revokes) + pgTAP 010 allowed/denied + policy census (one bucket literal per policy) + 001 census + types regen
|
||||
- [ ] 8.2 worker → SUPERSEDED by Rust R1 (RUST_ARCHITECTURE_REVIEW Part IV, D1 = native Rust worker): `crates/worker` keyed `run` loop + keyless `decode` child, lease claim, PUT→complete→DELETE order, sweeper (purge queue + quarantine by key), per-stage deadlines, Dockerfile (distroless/static) + compose service (read-only, cpus 1, internal network) + .env.worker.example, fixtures + sandbox tests on the production image, local-stack integration test
|
||||
- [ ] 8.3 packages/supabase assets service (begin/upload/confirm/remove/fetchOwnAvatar/downloadAvatar, closed failure kinds; no signed URL)
|
||||
- [ ] 8.4 app: avatar block in Mon compte (picker, canvas ≤1024 JPEG transport, preview, save, processing, supersede, delete), UserBadge photo, top bar avatar (D3), authStore blob URL, i18n, tests; design toolchain + impeccable detect
|
||||
- [ ] 8.5 docs: STORAGE.md (model, keys, statuses, purge/grace rules, reconciliation query, backup ordering + invariant, managed migration runbook), DEPLOY.md (worker, env file, network, CSP connect-src), SUPABASE.md, CLAUDE.md, CHANGELOG, plan note (worker early, SVG processor → Step 13); CI jobs
|
||||
- [ ] 8.6 verify: root check, PGlite + real stack pgTAP, types, docker builds (app + worker), real-stack e2e (sign allowed/denied), gates verifier + security; memory; stop for user validation
|
||||
- [ ] 8.1 migration 20261013100000_files_foundation: `asset_status`, `assets` (lease token added for stale-task refusal), 7 buckets (avatars open: 5 MiB, jpeg/png/webp; 6 closed; sheet bucket untouched), `private.can_read_avatar_object` / `can_upload_avatar_object`, storage.objects SELECT + INSERT policies, `private.object_purge_queue` + status/delete triggers (48 h final key of a deleted row, 1 h quarantine and rejected), `private.storage_ceiling()`, RPCs begin_avatar_upload / confirm_asset_upload / remove_avatar (authenticated), claim_avatar_jobs / complete_avatar_job / reject_avatar_job / mark_quarantine_purged / claim_purges / ack_purge / claim_quarantine_leftovers / expire_pending_uploads (service_role), closed error messages (P0001), explicit revokes, column grants
|
||||
- [ ] 8.2 pgTAP 010: allowed + denied twins for every RPC and policy, the 8 scenarios of the owner's brief (cross-user read, cross-user replace/delete, anon, quarantine never readable, final key never uploadable, superseded/removed row never completes, stale lease refused, late bytes inert), purge queue contents and grace, policy census (one bucket literal per policy, 2/1/0 per bucket, total pinned), audit rows; 001 census += the two predicates; shim adjustments if needed; real stack `db:reset` + `db:test`; `db:types` + schema-types map
|
||||
- [ ] 8.3 crates/worker R1 (fork A): `config` (env, no secret printed), `log` (JSON lines, field allowlist, child stderr escaped and truncated), `backend` trait + `http` (ureq 3, rustls + ring, PostgREST rpc + Storage object endpoints, 30 s timeouts, 5 MiB download cap, strict key validation before any URL), `decoder` trait over `Spawner`, `job` (claim → download → decode → PUT clean → complete → DELETE quarantine → mark purged; refusals → reject; `Broken` → alert + stop; complete refused → nothing deleted, the queue owns the object), `sweep` (claim_purges/ack, quarantine leftovers, expire pending), `watchdog` (per-stage deadlines, exit on overrun), `run` loop + `run --check`; unit tests on a fake backend + fake decoder; seccomp derivation re-run (the parent gained TLS/HTTP code, the child must stay at the traced set); JWT exp logged at start
|
||||
- [ ] 8.4 packages/supabase `assets.ts` (fork B): beginAvatarUpload, uploadToQuarantine, confirmAssetUpload, removeAvatar, fetchOwnAvatarState, downloadAvatar, closed `AssetFailure` kinds (P0001 messages → kinds; storage errors → network/unknown); tests on a stub client
|
||||
- [ ] 8.5 app (fork B): `account/avatarTransport.ts` (magic-byte sniff jpeg/png/webp, never SVG, createImageBitmap → canvas ≤ 1024 → JPEG 0.9, ≤ 5 MiB after transport), `AvatarSection` in Mon compte (circle photo/monogram, Modifier la photo, preview + Enregistrer/Annuler, processing with 1 s polling ≤ 30 s, rejection message per code, Supprimer with Dialog confirmation, in-flight row on mount), authStore `avatarUrl` blob (download under RLS, revoked on change/sign-out), `UserBadge` photo, top bar avatar + name → /app/account (D3), i18n FR/EN parity, component + store tests, `impeccable detect`
|
||||
- [ ] 8.6 integration: docker-compose `worker` service under profile `worker` (read-only, cap_drop ALL, no-new-privileges, mem 512m, cpus 1, pids 64, external Supabase network), `.env.worker` variables documented (file not editable here), real-stack e2e `pnpm --filter @faunosteo/supabase test:e2e` (worker container against the local stack: Alice flow clean + download 200, replace, remove, Bob 400, anon 400, quarantine 400, late signed-upload bytes swept, purge after grace via clock shift)
|
||||
- [ ] 8.7 docs: STORAGE.md final (model, keys, statuses, worker operations, purge/grace, reconciliation query, backup ordering + invariant, managed migration runbook), DEPLOY.md (worker service, env file, network, CSP connect-src), SUPABASE.md (worker in dev, buckets), RUST.md §3 (R1 loop), WORKSPACE.md, TEST_STRATEGY.md, IDENTITY.md §5 avatar steps, docs/design/README.md (avatar built), CLAUDE.md, CHANGELOG; CI yml untouched beyond a comment (no runner)
|
||||
- [ ] 8.8 verify: `pnpm check:all`, PGlite + real stack pgTAP, types diff, worker image + sandbox tests, e2e, gates verifier (contract) + security; memory (BDR/LRN/EVAL/journal); TEST FONCTIONNEL / TEST GRAPHIQUE signals; stop for the owner's manual validation, no merge into develop
|
||||
- [ ] Rust by default (rule adopted 2026-10-12, BDR-043; orientation + 10 principles VALIDATED by the owner 2026-10-12, BDR-044; study `docs/development/RUST_ARCHITECTURE_REVIEW.md` rev 2 + Annex A decision table + Annex B R0 scope on chore/step-08-files-analysis; AWAITING the owner's validation of decisions D-R1..D-R14 (D-R6 withdrawn); R0 and Step 8 NOT started until then). Roadmap (each phase: oracles frozen with the old code, consumer-driven deletion, rollback row, gates):
|
||||
- [ ] R0 foundation (GO 2026-10-12, BDR-045; branch feature/rust-r0-foundation; Annex B; owner constraints: builds reproducible in Docker, no Rust on the VPS, live deployment untouched, frontend never loads the module, no R1):
|
||||
- [x] R0.1 toolchain: `docker/rust-builder.Dockerfile` (rust:1.99.0-bookworm + wasm target + wasm-bindgen-cli 0.2.129 + cargo-deny 0.20.2 + rustfmt/clippy), `docker/rust-run.sh` (named volumes faunosteo_cargo_registry / faunosteo_rust_target), `docker/rust-check.sh`, `docker/wasm-build.sh` (CLI/crate version lock), root scripts rust:builder / rust:check / wasm:build / worker:test / worker:image
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
# CONTRACT — step-08 / Rust R1: files foundation, worker job loop, avatar
|
||||
- date: 2026-10-13 | flow: orchestrator + 2 forks, verifier gate | branch: feature/step-08-files-foundation (cut from the R0 tip 3f1105b)
|
||||
- status: dispatched after the implementation commits
|
||||
- spec: docs/development/STORAGE.md (contract), docs/development/STEP8_FILES_ANALYSIS.md (D1–D9, D1 = Rust worker), RUST_ARCHITECTURE_REVIEW.md Part IV, owner brief 2026-10-13 (sections 2–7)
|
||||
- diff range: 3f1105b..HEAD (run every CHECK from the repository root)
|
||||
|
||||
## REQUEST (IMMUTABLE)
|
||||
Step 8 = R1: `assets` table as the authority over user files, eight private buckets (only `avatars` open through policies evaluated on `assets`), quarantine upload path, deferred purge queue, browser and worker RPCs with closed error codes; the Rust worker's keyed job loop + sweeper on the R0 sandboxed decode child (unchanged); the avatar in Mon compte, the sidebar, the drawer and the top bar (link to Mon compte, no dropdown, no redesign); tests at every layer; real-stack e2e; docs. Out: other buckets' flows, SVG upload, PDF/anatomy ports, CI runner, deploy, release, merge into develop.
|
||||
|
||||
## ACCEPTANCE CRITERIA
|
||||
1. The SQL foundation applies on PGlite and every pgTAP file passes, including the new 010 (125 checks) and the extended 001 census.
|
||||
CHECK: pnpm --filter @faunosteo/supabase exec vitest run tests/db/pgtap.test.ts 2>&1 | grep -E "^ +Tests "
|
||||
EXPECT: Tests 11 passed (11)
|
||||
2. Exactly three policies are created by the migration (assets own-row SELECT, avatars read, avatars upload), the two Storage ones pin the bucket literal, and no UPDATE / DELETE policy exists on storage.objects.
|
||||
CHECK: grep -c "^create policy" supabase/migrations/20261013100000_files_foundation.sql; grep -c "on storage.objects" supabase/migrations/20261013100000_files_foundation.sql; grep -cE "for (update|delete)" supabase/migrations/20261013100000_files_foundation.sql
|
||||
EXPECT: 3 / 2 / 0
|
||||
3. The owner's column grant on assets excludes every lease and quarantine column.
|
||||
CHECK: sed -n '/^grant select ($/,/to authenticated;/p' supabase/migrations/20261013100000_files_foundation.sql | grep -c "lock_token\|quarantine_key\|locked_at\|attempts"
|
||||
EXPECT: 0
|
||||
4. Both worker verdict RPCs refuse a stale lease token (status uploaded AND token match).
|
||||
CHECK: grep -c "lock_token is distinct from lock_token" supabase/migrations/20261013100000_files_foundation.sql
|
||||
EXPECT: 2
|
||||
5. The eight scenarios of the owner's brief are named as pgTAP descriptions (cross-user read, cross-user replace/delete, anon, quarantine never readable, final key never written by the browser, superseded / removed row never completes, stale lease refused, late bytes swept) — at least 12 descriptions carry the `scenario:` marker.
|
||||
CHECK: grep -c "scenario:" supabase/tests/010_files_foundation.sql
|
||||
EXPECT: 13
|
||||
6. The R0 sandboxed child is untouched by R1 (decode, sandbox, spawn, webp_check unchanged in the range).
|
||||
CHECK: git diff 3f1105b..HEAD --stat -- crates/worker/src/decode.rs crates/worker/src/sandbox.rs crates/worker/src/spawn.rs crates/worker/src/webp_check.rs | wc -l
|
||||
EXPECT: 0
|
||||
7. The worker links no async runtime and no aws-lc-rs (ureq on rustls + ring, review deviation recorded).
|
||||
CHECK: . scripts/rust-env.sh && cargo tree -p faunosteo-worker --prefix none 2>/dev/null | grep -cE "^(tokio|reqwest|aws-lc-rs) "
|
||||
EXPECT: 0
|
||||
8. Keys from the database are validated before any URL (http, job, sweep all call the key validators) and no log or print site exposes the service key.
|
||||
CHECK: grep -n "validate_any_key\|validate_object_key\|validate_quarantine_key" crates/worker/src/http.rs crates/worker/src/job.rs crates/worker/src/sweep.rs | wc -l; grep -rn "println!\|eprintln!\|format!" crates/worker/src/ | grep -c "expose()"
|
||||
EXPECT: 5 / 0
|
||||
9. The native Rust gate is green (fmt, clippy -D warnings, core + worker tests including the 11 job-loop tests, ts-rs export, cargo deny).
|
||||
CHECK: bash scripts/rust-check.sh > /tmp/rust-check-verify.log 2>&1; echo "exit $?"; grep -cE "^test result: ok" /tmp/rust-check-verify.log
|
||||
EXPECT: exit 0 / at least 6
|
||||
10. The browser never selects `*` on assets and never holds a service role reference.
|
||||
CHECK: grep -n "from('assets')" -A2 packages/supabase/src/assets.ts | grep -c "'\*'"; grep -rn "SERVICE_ROLE\|service_role" apps/app/src packages/supabase/src | grep -v database.types | wc -l
|
||||
EXPECT: 0 / 0
|
||||
11. The Node gate is green with the new tests (supabase package 37, app 300).
|
||||
CHECK: pnpm --filter @faunosteo/supabase test:run 2>&1 | grep -E "^ +Tests "; pnpm --filter @faunosteo/app test:run 2>&1 | grep -E "^ +Tests "; pnpm typecheck > /dev/null 2>&1 && pnpm lint > /dev/null 2>&1 && echo GATE_OK
|
||||
EXPECT: Tests 37 passed (37) / Tests 300 passed (300) / GATE_OK
|
||||
12. The avatar transport refuses SVG by content and the UI section exists with the mockup's elements (change, save, cancel, remove, processing), strings in both dictionaries.
|
||||
CHECK: grep -c "svg" apps/app/tests/unit/account.avatarTransport.test.ts; grep -c "'account.avatar\." apps/app/src/i18n/fr.ts; grep -c "'account.avatar\." apps/app/src/i18n/en.ts
|
||||
EXPECT: 4 / 29 / 29
|
||||
13. The compose worker service is hardened and opt-in (profile), reads its own env file, joins the external Supabase network.
|
||||
CHECK: grep -c 'profiles: \["worker"\]\|read_only: true\|cap_drop: \[ALL\]' docker-compose.yml; grep -c "\.env\.worker" docker-compose.yml; docker compose --profile worker config --no-interpolate 2>&1 | grep -c "container_name: faunosteo_worker"
|
||||
EXPECT: 3 / 1 / 1
|
||||
14. The real-stack end-to-end suite and its runner exist, typecheck, and are documented; the e2e is not part of the default vitest include.
|
||||
CHECK: test -f packages/supabase/tests/e2e/avatar-flow.e2e.ts && test -x scripts/avatar-e2e.sh && grep -c "e2e:avatar" package.json docs/development/STORAGE.md | tr '\n' ' '; grep -c "e2e" packages/supabase/vitest.config.ts
|
||||
EXPECT: package.json:1 docs/development/STORAGE.md:1 / 0
|
||||
15. Docs updated: STORAGE.md present; CLAUDE.md, DEPLOY.md, SUPABASE.md, RUST.md, TEST_STRATEGY.md, WORKSPACE.md, IDENTITY.md, docs/design/README.md and CHANGELOG.md reference the step.
|
||||
CHECK: for f in CLAUDE.md DEPLOY.md docs/development/SUPABASE.md docs/development/RUST.md docs/development/TEST_STRATEGY.md docs/development/WORKSPACE.md docs/development/IDENTITY.md docs/design/README.md CHANGELOG.md; do printf '%s:%s ' "$f" "$(grep -cE 'STORAGE.md|Step 8|avatar' "$f")"; done
|
||||
EXPECT: every count ≥ 1
|
||||
|
||||
## FILE SCOPE
|
||||
supabase/migrations/20261013100000_files_foundation.sql, supabase/tests/{001_schema,010_files_foundation}.sql, packages/supabase/{src,tests,package.json,vitest.e2e.config.ts}, apps/app/src/{account,components/account,components/shell,state/authStore.ts,i18n}, apps/app/tests, crates/worker/**, Cargo.toml, Cargo.lock, deny.toml, docker-compose.yml, scripts/avatar-e2e.sh, package.json, docs/**, CLAUDE.md, README.md, DEPLOY.md, CHANGELOG.md.
|
||||
Reference in new issue
Block a user