Security audit (PASS, 2 MEDIUM + LOW): the global ceiling summed every non-deleted row, so rejected uploads ratcheted it toward storage_full with no disk used → in-flight rows by declared size, clean rows by byte_size, nothing else (pgTAP: rejected rows do not count, in-flight rows do); confirm refuses a deactivated account like begin; complete_avatar_job refuses a null sha256; begin / confirm / remove granted to authenticated only. Worker: SUPABASE_URL over http:// accepted only for loopback or a single-label Docker service name; ureq proxy(None); the job's keys must embed its owner and asset ids; backend_failure / claim_failed / sweep_failure lines carry the closed kind and the HTTP status, never the library's error text. e2e: uuid shape checked before the psql query. Contract revision 2 (oracle fixes).
7.4 KiB
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
- 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)
- 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 (the policy command clause is a line of its own;
select … for updaterow locks inside functions are not policies) - 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
- 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
- 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 - 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
- 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
- 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
- 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
- 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 - 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 "; ./node_modules/.bin/pnpm typecheck > /dev/null 2>&1 && ./node_modules/.bin/pnpm lint > /dev/null 2>&1 && echo GATE_OK EXPECT: Tests 37 passed (37) / Tests 300 passed (300) / GATE_OK
- 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
- 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
- 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
- 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, pnpm-lock.yaml (zod importer entry), docs/, CLAUDE.md, README.md, DEPLOY.md, CHANGELOG.md, .claude/tasks/** (TODO plan and this contract), .claude/memory/** (registries).
- revision 2 (2026-10-13, after verifier pass 1 ECARTS(4), all oracle/scope): criterion 2 third grep anchored to the policy clause; criterion 11 lint via the binary path (the literal
pnpm lintis intercepted by a sandbox output wrapper); FILE SCOPE widened to the lockfile and the tracking files.