diff --git a/.claude/tasks/TODO.md b/.claude/tasks/TODO.md index 1bb4ec65..5b6c5c1b 100644 --- a/.claude/tasks/TODO.md +++ b/.claude/tasks/TODO.md @@ -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 diff --git a/.claude/tasks/contracts/2026-10-13-step-08-r1-verify.md b/.claude/tasks/contracts/2026-10-13-step-08-r1-verify.md new file mode 100644 index 00000000..8217dc03 --- /dev/null +++ b/.claude/tasks/contracts/2026-10-13-step-08-r1-verify.md @@ -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. diff --git a/CHANGELOG.md b/CHANGELOG.md index 55bb8921..05dd439f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ Versions follow [Semantic Versioning](https://semver.org/). ## [Unreleased] +### Added (SaaS migration, plan Step 8 = Rust R1) + +- **Files foundation and profile photo (Step 8)** — `public.assets` as the authority over user files (status, owner, server-built keys, worker lease token), seven private Storage buckets (only `avatars` open, through SELECT / INSERT policies evaluated on `assets`; the six others closed until their step), a quarantine upload path (`begin_avatar_upload` → direct upload at the quarantine key → `confirm_asset_upload`), a deferred purge queue (48 h for a replaced or removed avatar, 1 h for quarantine and rejected uploads: the backup invariant) and the audited RPCs of the browser and of the worker (migration `20261013100000`, pgTAP 010 with 125 allowed and denied checks, policy census). **Rust worker job loop** (`crates/worker`, R1): the keyed parent claims leased jobs through PostgREST, downloads the quarantine bytes, hands them to the sandboxed `decode` child of R0 (empty environment, rlimits, seccomp allowlist unchanged), uploads the 512 × 512 lossy WebP, commits the row, deletes the quarantine object, rejects with closed codes (`unsupported_type`, `decode_failed`, `dimensions`, `processing_error`), sweeps expired uploads, the purge queue and quarantine leftovers; JSON line logs with a field allowlist; per-stage watchdog; Compose service `worker` (profile `worker`, read-only, no capability, external Supabase network, `.env.worker`). **Profile photo** in Mon compte (preview before any request, save, processing with polling, rejection messages, replacement, removal with confirmation) and in the sidebar, the mobile drawer and the top bar (name beside it on desktop, link to Mon compte); JPEG / PNG / WebP only, never SVG, downscaled to 1024 px in the browser as transport, judged again by the worker; the owner downloads the clean object under RLS (no signed URL). Real-stack end-to-end run `pnpm e2e:avatar`. Spec: `docs/development/STORAGE.md`. + ### Added (Rust foundation, plan R0) - **Rust by default** (rule adopted 2026-10-12, `docs/development/RUST_ARCHITECTURE_REVIEW.md`): Cargo workspace with three crates, `crates/core` (contracts and the JavaScript-compatible JSON formatter, no I/O by lint), `crates/wasm` (browser facade built into `packages/core-wasm/pkg`) and `crates/worker` (the future file-processing worker: sandboxed `decode` child with rlimits and a seccomp allowlist derived by `strace`, image decoding in pure Rust, lossy WebP through libwebp confined to the child, parent-side container check; `run --check` only, no job loop before R1). Reference toolchain in Docker (`docker/rust-builder.Dockerfile`, `pnpm rust:check`, `pnpm wasm:build`), worker image on `distroless/static`, CI job `rust`, nightly advisories, manual digest-tagged image workflow (no deploy). R0 proofs recorded in `docs/development/RUST.md`: `float_roundtrip` required for JSON parity, traps leave a wasm instance unusable (fresh instance per recovery), CSP needs `'wasm-unsafe-eval'`. No application behaviour, interface, archive or database change; the frontend does not load the module. diff --git a/CLAUDE.md b/CLAUDE.md index 78cc362e..19d3adf6 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -27,7 +27,12 @@ confirmation, password recovery, OAuth buttons driven by config, the guarded `/app` shell (dashboard, Mon compte with personal / professional / preferences / security sections) on Supabase Auth + `profiles` + `profile_roles`, language synced with `profiles.locale` (`docs/development/IDENTITY.md`). The local tool -routes stay unauthenticated. +routes stay unauthenticated. Step 8 (= Rust R1) added the files foundation: the +`assets` table as the authority over user files, seven private buckets (only +`avatars` open, through policies evaluated on `assets`), a quarantine upload path, +the Rust worker `crates/worker` (keyed job loop + keyless sandboxed decode child) +producing 512 × 512 WebP avatars, a deferred purge queue, and the profile photo in +Mon compte, the sidebar, the drawer and the top bar (`docs/development/STORAGE.md`). MVP species: equine only. Open-source MIT. --- @@ -112,6 +117,7 @@ pnpm rust:check:docker # the same rust-check.sh inside the builder image pnpm wasm:build:docker # the same wasm-build.sh inside the builder image pnpm worker:test # Docker only: crates/worker/Dockerfile stage test, sandbox tests + seccomp derivation on the musl binary pnpm worker:image # Docker only: runtime image faunosteo_worker:dev (distroless/static, `run --check`) +pnpm e2e:avatar # scripts/avatar-e2e.sh: worker container against the local stack + packages/supabase/tests/e2e (real-stack avatar flow) ``` ## Docker commands @@ -213,7 +219,8 @@ faunosteo/ │ │ ├─ brand/{Brand,AppHeader,Footer,LanguageSwitcher,HomeSpaceLink}.tsx │ │ ├─ auth/{AuthLayout,OAuthButtons,PasswordField,UnavailableNotice,AuthLink}.tsx │ │ ├─ shell/{AppLayout,SidebarNav,MobileDrawer,UserBadge,SignOutButton}.tsx -│ │ └─ account/{SectionCard,SaveRow,PersonalInfoForm,ProfessionalInfoForm,PreferencesForm,SecurityPanel,RoleBadges}.tsx +│ │ └─ account/{SectionCard,SaveRow,AvatarSection,PersonalInfoForm,ProfessionalInfoForm,PreferencesForm,SecurityPanel,RoleBadges}.tsx +│ ├─ account/avatarTransport.ts ← magic-byte sniff (never SVG), createImageBitmap → canvas ≤ 1024 px → JPEG transport blob │ ├─ pdf/ ← app side of @faunosteo/pdf (engine in packages/pdf) │ │ ├─ export.ts + import.ts ← exportReportToPdf (sheet snapshot + branding + browser rasterizer → engine), importReportFromPdf (ArchiveReadOutcome, ImportError kinds) │ │ └─ branding.ts + browserRasterizer.ts ← bundled src/assets/brand logos (?inline / ?raw) → Branding; Image/canvas Rasterizer adapter @@ -245,11 +252,12 @@ faunosteo/ │ ├─ src/curation/{schema,targets,fields,ops,rename,apply,types,assets,labels,stats,changelog,review-report,overlay,seed,sources,pipeline}.ts ← changeset → draft │ └─ tests/ ← counts preserved, special cases, determinism, curation ops, golden artifacts ├─ packages/supabase/ ← @faunosteo/supabase -│ ├─ src/{index,client,database.types,anatomical-sheets}.ts ← typed client, generated types, publish gate +│ ├─ src/{index,client,database.types,anatomical-sheets,assets}.ts ← typed client, generated types, publish gate, avatar flow (closed AssetFailure kinds) +│ ├─ tests/e2e/avatar-flow.e2e.ts + vitest.e2e.config.ts ← real-stack end-to-end (`pnpm e2e:avatar`), skipped without the stack env │ └─ tests/{client,anatomical-sheets}.test.ts, tests/db/ ← PGlite harness, shim, pgTAP runner, schema↔types test ├─ supabase/ │ ├─ config.toml, seed.sql ← CLI config (public schema only), local dev accounts -│ ├─ migrations/*.sql ← forward-only; foundation, profiles, platform_roles, anatomical_sheets, storage, sheet_document_schema_v2 +│ ├─ migrations/*.sql ← forward-only; foundation, profiles, platform_roles, anatomical_sheets, storage, sheet_document_schema_v2, profiles_professional, files_foundation (assets, buckets, avatar policies, purge queue, RPCs) │ ├─ seed/anatomical-sheets/equine/ │ │ ├─ legacy-sources/ ← the historical Horse.svg, Horse_head.svg, pathologies.json, vertebrae.ts (importer input, never edited) │ │ ├─ legacy-import/ ← GENERATED baseline: document, id map, IMPORT-REPORT, SVG copies (no SQL) @@ -261,8 +269,9 @@ faunosteo/ ├─ crates/ ← Rust workspace (Cargo.toml, rust-toolchain.toml, deny.toml, clippy.toml, .cargo/config.toml at the root) │ ├─ core/ ← faunosteo-core: contracts (report types), js_number + JS pretty formatter, facade `call(op, json)`; no I/O, no clock (lint-enforced) │ ├─ wasm/ ← faunosteo-wasm: wasm-bindgen facade (core_version, call, R0 trap proofs) -│ └─ worker/ ← faunosteo-worker: plain main; `decode` sandboxed child (rlimits, seccomp allowlist, image → libwebp), parent Spawner + RIFF check, `run --check`; Dockerfile, scripts/derive-seccomp.sh -├─ scripts/{rust-env,rust-check,wasm-build,check-all}.sh ← native Rust gate, wasm build, the pre-merge gate (`pnpm check:all`) +│ └─ worker/ ← faunosteo-worker: plain main; `decode` sandboxed child (rlimits, seccomp allowlist, image → libwebp), parent Spawner + RIFF check; R1 `run` loop: config, log (JSON lines, allowlist), keys, backend trait + http (ureq, PostgREST rpc + Storage objects), job, sweep, watchdog; Dockerfile, scripts/derive-seccomp.sh +├─ scripts/{rust-env,rust-check,wasm-build,check-all,avatar-e2e}.sh ← native Rust gate, wasm build, the pre-merge gate (`pnpm check:all`), the real-stack avatar e2e +├─ docker-compose.yml ← `app` service; `worker` service under the `worker` profile (read-only, cap_drop ALL, external Supabase network, `.env.worker`) ├─ docker/rust-builder.Dockerfile, rust-run.sh, csp-proof/ ← reproducible Rust builder (alternative) + the CSP proof ├─ .gitea/workflows/ci.yml ← PREPARED, never executed (no runner): rust job (builder image, scripts/rust-check.sh, types drift, wasm), install, typecheck, test, lint, build, docker (app + worker test stage + runtime) ├─ .gitea/workflows/{rust-advisories,release-images}.yml ← nightly RustSec advisories; manual digest-tagged image publication (no deploy) @@ -319,6 +328,15 @@ Identity (Step 7, docs/development/IDENTITY.md) → RequireAuth guards /app/* (→ /login?next=), AppLayout (sidebar / top bar / drawer), Dashboard, Account (updateOwnProfile) → no Supabase configured: status unavailable, auth screens show a notice, local tool unchanged +Files and avatar (Step 8 / R1, docs/development/STORAGE.md) + → AvatarSection: pick → avatarTransport (sniff jpeg/png/webp, bitmap → canvas ≤ 1024 → JPEG) → preview (no request) + → save: rpc begin_avatar_upload (row pending_upload, server-built keys) → storage upload at the quarantine key (INSERT policy) + → rpc confirm_asset_upload (uploaded) → poll own assets row 1 s ≤ 30 s → clean: download under the SELECT policy → blob URL in authStore + → worker (container faunosteo_worker, service key): claim_avatar_jobs (lease token) → GET quarantine → decode child (sandbox, 512² WebP) + → POST clean object (upsert) → complete_avatar_job (previous clean → deleted, enqueued 48 h) → DELETE quarantine → mark_quarantine_purged + → refusals: reject_avatar_job(closed code); sweeper: expire_pending_uploads, claim_purges/ack_purge, claim_quarantine_leftovers + → remove_avatar: rows → deleted, objects purged after the grace; a deleted / superseded row never completes (status + token guards) + Runtime config → Docker entrypoint writes env.js (window.__APP_CONFIG__) → index.html loads env.js before bundle @@ -415,6 +433,20 @@ Database (Supabase) operator scripts under `packages/*/scripts/` read it from the environment and are never bundled. - pgTAP files run on PGlite and on the real image: scope counts to fixture ids, pin `collate "C"` on text ordering. +### Files and Storage (migration 20261013100000, docs/development/STORAGE.md) +- `public.assets` is the authority over every user file: status, owner, keys, lease. Every write is an RPC; the browser + reads its own rows through an explicit column list (`select=*` is refused: lease columns are not granted). +- Object keys are server-built from uuids (`profiles///avatar.webp`, `quarantine///upload`); + policies on `storage.objects` compare whole strings through `assets` and pin one bucket literal each (census test). + A quarantine object is never readable by an API role; a final key is never writable by the browser. +- New buckets stay closed (row only, no policy) until their step writes the rules; `anatomical-sheet-assets` keeps its own policy. +- The worker holds the service key; the decode child has an empty environment, no file, no network, and is the only + process that decodes untrusted bytes. The parent checks the container header only. Rejections are closed codes. +- Deletions are row-driven: terminal rows enqueue their keys (48 h / 1 h grace), the sweeper serves the queue and the + quarantine leftovers; a clean row's object is never deleted. Backups: dump first, files within 48 h. +- Avatar UI follows the validated mockup: photo in Mon compte (Informations personnelles), sidebar, drawer and top bar + link to Mon compte; JPEG / PNG / WebP only, never SVG; no signed URL for the owner-only avatar (download under RLS). + ### Anatomical sheet model (packages/domain + migration 20261008110000) - `docs/development/ANATOMICAL_SHEET_MODEL.md` is the source of truth: document shape, issue codes, tables, RPCs. - Ids are stable slugs never derived from labels; labels are `{ fr, en }` objects. Annotation → findings is the @@ -514,6 +546,7 @@ the owner's validation before any implementation; release 0.2.0 unaffected). - After PDF roundtrip tests fail: check attachment bytes, then the layered reader (report first, envelope metadata, snapshot/branding/labels), then DecompressionStream inflation. Goldens under `apps/app/tests/fixtures/goldens/step6` are never regenerated without a user decision. - Node 24 / pnpm 10.13.1: `corepack enable` or `corepack pnpm`; never a global install. - Rust: native on the Ubuntu development machine (user-level rustup, never a global package, never on the VPS); `pnpm rust:check` and `pnpm wasm:build` run natively, the `:docker` variants reproduce them in the builder image. Before every Rust commit: `pnpm rust:check` green, `pnpm worker:test` green when `crates/worker` changed (Docker only: the sandbox tests and the seccomp derivation never run natively), the ts-rs types under `packages/core-wasm/types` committed, `Cargo.lock` committed. Before a merge: `pnpm check:all`. No CI runs on the forge: a workflow file is never cited as a passed check. The core takes ids, time and bytes as inputs (clippy `disallowed_methods`); the worker child is the only process that decodes untrusted bytes. +- Storage or worker change: `pnpm e2e:avatar` (worker container against the local stack, `packages/supabase/tests/e2e`) in addition to `pnpm worker:test`; `docker compose --profile worker` serves the worker from `.env.worker` (never the app `.env`). - SQL change: `pnpm --filter @faunosteo/supabase test:run` (PGlite) before commit; `pnpm db:reset && pnpm db:test` on the real stack when Docker is available; regenerate types (`pnpm db:types`). diff --git a/DEPLOY.md b/DEPLOY.md index 42da1d8d..f18bfd39 100644 --- a/DEPLOY.md +++ b/DEPLOY.md @@ -21,10 +21,13 @@ The host should publish only ports `22`, `80`, `443` to the internet. The container port (`8080` by default) should stay loopback-only — the host reverse proxy reads from it on `127.0.0.1:8080`. -Rust (plan R0, `docs/development/RUST.md`): the repository also builds a +Rust (plan R0/R1, `docs/development/RUST.md`): the repository also builds a worker image (`crates/worker/Dockerfile`, static musl binary on -`distroless/static`, container `faunosteo_worker`). It is not deployed yet -(its job loop arrives at R1); the live deployment above is unchanged. The +`distroless/static`, container `faunosteo_worker`, service `worker` under the +Compose profile `worker`). Since Step 8 it carries the files job loop (avatar +processing, purge sweeps: `docs/development/STORAGE.md` §3). It is not deployed +yet: it needs the self-hosted Supabase stack beside it, which production does +not run today; the live deployment above is unchanged. The production VPS never needs a Rust toolchain: Rust is compiled on the Ubuntu development machine (native toolchain) or inside Docker builder images, and production images will be pulled by digest ("Image deploy by digest", @@ -101,6 +104,28 @@ the service_role key never leaves the Supabase host (see The `.env` file is not sensitive but should still be `chmod 600` to keep local identity overrides private. +### Worker environment (`.env.worker`, Step 8) + +The files worker (`docker compose --profile worker up -d worker`) reads a +second env file, `.env.worker`, never the app `.env`: it holds the service +key. `chmod 600`, excluded from every backup copy of env files, readable +through `docker inspect` by the `docker` group (documented limit). The +assistant cannot write `.env*` files in this repository: create it by hand +from the table (STORAGE.md §3.2 lists the optional tuning variables). + +| Variable | Required | Notes | +| --- | --- | --- | +| `SUPABASE_URL` | yes | Kong origin on the Supabase compose network (`http://supabase_kong_faunosteo:8000` on the local CLI stack; the self-hosted stack's own Kong name in production). Never the public URL when the stack is on the same host. | +| `SUPABASE_SERVICE_ROLE_KEY` | yes | the service key; on self-hosted a long-lived JWT (revoking it = rotating `JWT_SECRET`). Never in `.env`, env.js or the repository. | +| `WORKER_ID` | no | tag of the log lines (default `worker-`). | + +The service joins the external network named by `SUPABASE_NETWORK` +(default `supabase_network_faunosteo`, the local CLI stack); it publishes no +port, runs read-only with every capability dropped, 512 MiB, 1 CPU, 64 pids. +Browser side, the production CSP `connect-src` must name the Supabase +origin the app talks to (already required since Step 7), and `img-src` +keeps `blob:` (the avatar is shown from a blob URL downloaded under RLS). + --- ## Provision the VPS diff --git a/README.md b/README.md index d4403bd8..70d57f92 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,11 @@ pnpm dev # http://localhost:5173 Rust (core, browser module, worker): a user-level `rustup` installs the pinned toolchain from `rust-toolchain.toml` on first use; see `docs/development/RUST.md` §1 for the three `cargo install` / `rustup -target add` lines and the Docker alternative. +target add` lines and the Docker alternative. The files worker (profile +photos, Step 8) runs as a container beside the local Supabase stack: +`pnpm worker:image`, then `pnpm e2e:avatar` for the real-stack end-to-end +run, or `docker compose --profile worker up worker` with a `.env.worker` +(`docs/development/STORAGE.md`). Docker Compose (matches production topology): diff --git a/docs/design/README.md b/docs/design/README.md index 6dbd6dde..51869928 100644 --- a/docs/design/README.md +++ b/docs/design/README.md @@ -33,7 +33,7 @@ step has built yet, with the step that owns them: | Bilans, Clients, Animaux, Agenda, Fiches anatomiques entries and screens | Steps 9 to 16 (clients/animals, cloud reports, agenda) | | Stat tiles (bilans créés, clients, animaux, rendez-vous) and "Derniers bilans" | once the reports and agenda tables exist; never invented numbers | | Notification bell | notifications step | -| Avatar photo and "Modifier la photo" | Step 8 (files foundation, avatar bucket) | +| Avatar photo and "Modifier la photo" | built in Step 8 (2026-10-13): circle + "Modifier la photo" in Informations personnelles, photo in the sidebar / drawer badge and in the top bar with the name on desktop (link to Mon compte, no dropdown) | | Bottom tab bar on mobile | with the first list screens (today only two destinations) | | Tabs in Mon compte | optional restructuring when "Cabinet et activité" gains fields (activity type, website) | | Password rule checklist | the mockup says 8 characters; the server policy is 12 with lower, upper and digit (config.toml); the hint text follows the server | diff --git a/docs/development/IDENTITY.md b/docs/development/IDENTITY.md index 53c7e4c4..e03839c7 100644 --- a/docs/development/IDENTITY.md +++ b/docs/development/IDENTITY.md @@ -18,7 +18,7 @@ by side until the plan's Step 14 decides what goes behind authentication. | `/reset-password` | none; needs the recovery session | new password ×2; "invalid or expired link" otherwise | | `/auth/callback` | none | landing of OAuth redirects and confirmation links; waits for the session then goes to `/app` (or `?next=`) | | `/app` | `RequireAuth` | dashboard: greeting, profile completeness card, local tool card, account card | -| `/app/account` | `RequireAuth` | Mon compte: personal, professional, preferences (language, timezone), security (password, MFA note, sign out) | +| `/app/account` | `RequireAuth` | Mon compte: profile photo (Step 8, `STORAGE.md` §4), personal, professional, preferences (language, timezone), security (password, MFA note, sign out) | `RequireAuth` waits for the client to read the persisted session, then sends a visitor to `/login?next=`; `next` is honoured only when it is a @@ -126,6 +126,16 @@ VITE_AUTH_PROVIDERS=google pnpm dev password → `/app`; sign out and sign in with the new password. 9. REST: anon cannot read profiles (`42501`), alice reads one row only (SUPABASE.md §8). +10. Profile photo (Step 8, worker container running: `pnpm worker:image` + then `docker compose --profile worker up worker` or the container of + `scripts/avatar-e2e.sh`): Mon compte → Modifier la photo with a phone + JPEG → preview → Enregistrer → "Traitement en cours…" → the photo in the + circle, the sidebar, the drawer (mobile) and the top bar (name beside it + on desktop, alone on mobile) linking to Mon compte; a renamed PNG is + accepted, an HTML or SVG file is refused at the picker; replace, then + Supprimer la photo → confirmation → monogram; sign in as bob: nothing of + alice shows; open the object path of alice's photo in a private window + → 400. Automated: `pnpm test:run` (auth store, locale sync, forms, guards, shell, dashboard, account, pgTAP 009), plus the headless end-to-end run described in diff --git a/docs/development/IMPLEMENTATION_PLAN.md b/docs/development/IMPLEMENTATION_PLAN.md index 63a9fb27..615298f6 100644 --- a/docs/development/IMPLEMENTATION_PLAN.md +++ b/docs/development/IMPLEMENTATION_PLAN.md @@ -238,6 +238,17 @@ Definition of Done: all eight buckets exist and are private; architecture §15.1 Risks: direct-to-bucket uploads bypassing the assets row (mitigate: insert policy on storage.objects requires a matching assets row). ``` +Step 8 as built (2026-10-13, `STEP8_FILES_ANALYSIS.md` D1–D9 + Rust R1, +`STORAGE.md`): the server-side processing is the Rust worker `crates/worker` +(the plan's `apps/worker` of Step 19 arrives early, in Rust, with one job +family); there is no `issue_signed_url` RPC (the Storage API signs after the +SELECT policy; the owner-only avatar is downloaded under RLS, no signed URL); +the SVG sanitiser and the user SVG upload path move to Step 13 with their +producer (the allowlist sanitiser already exists in `packages/pdf`); the +avatar pointer is derived from the single clean `assets` row (no +`profiles.avatar_asset_id`); the sheet bucket keeps its name +`anatomical-sheet-assets`. + ```text Step 9 (∥ Step 10) Name: Professional verification diff --git a/docs/development/RUST.md b/docs/development/RUST.md index 1cb9137f..9e2ddb26 100644 --- a/docs/development/RUST.md +++ b/docs/development/RUST.md @@ -1,12 +1,13 @@ # Rust in the Faunosteo monorepo -Status: plan R0 (foundation), 2026-10-12, on `feature/rust-r0-foundation`. Rule -and roadmap: `RUST_ARCHITECTURE_REVIEW.md` (rule "Rust by default", Part III -boundary rules, Part VI phases R0–R5, Annex B R0 scope, Annex C owner -amendments). R0 ships the toolchain, the workspace skeleton, the worker's -sandboxed child, the browser module loader and seven experimental proofs. No -application behaviour, interface, archive or database changes; the frontend -does not load the module before R2; the worker's job loop arrives at R1. +Status: plan R0 (foundation, validated 2026-10-13) and R1 (the Step 8 worker, +2026-10-13, `feature/step-08-files-foundation`). Rule and roadmap: +`RUST_ARCHITECTURE_REVIEW.md` (rule "Rust by default", Part III boundary +rules, Part IV the worker, Part VI phases R0–R5, Annex B R0 scope, Annex C +owner amendments). R0 shipped the toolchain, the workspace skeleton, the +worker's sandboxed child, the browser module loader and seven experimental +proofs; R1 ships the worker's job loop and sweeper for the avatar pipeline +(`STORAGE.md` §3). The frontend does not load the browser module before R2. ## 1. Toolchain: native on the development machine, reproducible in Docker, never on the VPS @@ -141,11 +142,36 @@ under a 10 s CPU limit. module each time (cache-busting import of the glue), `callCore()` parses the envelope, `isCoreBuilt()` lets the proofs skip when `pkg/` is absent. -## 3. The worker (R0 skeleton, R1 job loop) +## 3. The worker (R0 sandboxed child, R1 job loop) `faunosteo-worker` is one static musl binary with subcommands dispatched by a plain `main` (no async runtime, no thread), so `decode` installs its -sandbox in a single-threaded process: +sandbox in a single-threaded process. R1 (Step 8) adds the keyed parent: +`run` polls `claim_avatar_jobs` through PostgREST every 2 s, downloads the +quarantine object, feeds it to a `decode` child, uploads the 512 × 512 WebP +at the final key, commits the row (`complete_avatar_job` with the lease +token), deletes the quarantine object, and sweeps (expired uploads, the +purge queue, quarantine leftovers) every 10 minutes. Modules: `config` (env, +secret newtype that no Debug output prints, JWT expiry), `log` (JSON lines, +field allowlist, child stderr escaped and cut at 200 bytes), `keys` (strict +four-segment key shapes validated before any URL), `backend` (trait, closed +`BackendError`), `http` (ureq 3 on rustls + ring with the bundled roots, 30 s +global / 5 s connect timeouts, no redirect, `P0001` bodies → closed +refusals, the Storage API's HTTP 400 + `statusCode` 404 → 404), `decoder`, +`job` (the STORAGE.md §3.4 mapping), `sweep` (§3.5), `watchdog` (per-stage +deadlines, exit 21 on overrun; `Broken` child → exit 20), `run` +(`WORKER_ONCE`, `--check`). Library choice recorded against the review's +Part V list: `ureq` instead of `tokio` + `reqwest`, hand-written JSON lines +instead of `tracing`, a 25-line base64url decoder instead of `base64`: the +loop is sequential, nothing needs an async runtime, and the keyed process +keeps a smaller dependency tree (34 → 84 crates, `aws-lc-rs` absent, no +cmake on Alpine). The decode child's traced syscall set did not change with +the parent's TLS code (§5.4 re-run at R1: the same seven). Image 11.6 MB +(8.7 MB at R0: ring + rustls). Tests: `crates/worker/tests/job_loop.rs` (11, +fake backend + fake decoder) and the module unit tests run natively; the +real-stack end-to-end runs through `pnpm e2e:avatar` (`STORAGE.md` §6). + +The sandboxed child, unchanged from R0: - `decode`: refuses a non-empty environment; checks `Threads: 1` in `/proc/self/status`; disables core dumps (`PR_SET_DUMPABLE 0`, @@ -181,8 +207,10 @@ sandbox in a single-threaded process: child's stderr (≤ 4 KiB) is child-controlled text: R1 never logs it raw (LRN-044). - `run --check`: prints the resolved configuration without secrets (which - variables are set, the linked libwebp version, refused below 1.6.0). A - plain `run` does nothing before R1 and says so. + variables are set, the linked libwebp version, refused below 1.6.0, the + JWT expiry of the service key); exit 0 when startable or when no worker + variable is set at all, 2 on a partial configuration. `run` starts the loop + (STORAGE.md §3.2 for the variables). - `version`: binary, workspace and libwebp versions. - test hooks (`--features test-hooks`, never in a release build): fixtures generated in memory (no binary in git), `--no-seccomp` (rlimits only, @@ -406,8 +434,10 @@ pnpm check:all # everything above bu - The browser-side fresh-instance mechanism (static glue URL with a cache-busting query under Vite, or a Worker per instance) is designed, not built: R2 builds and tests it. -- HTTPS from the worker (CA bundle of distroless, `webpki-roots`): no HTTP - client in the R0 binary; R1 adds `reqwest` and the CI HTTPS call. +- HTTPS from the worker: R1 links `ureq` with rustls and the bundled + `webpki-roots` (distroless has no CA bundle; none is needed), but every + run so far targets the local stack over plain HTTP on the Docker network; + the first managed (HTTPS) target proves the roots. - The forge runner's cache and timings (§5.7), and the workflow files themselves: no runner exists, none of the three workflows has ever run (§4). diff --git a/docs/development/SUPABASE.md b/docs/development/SUPABASE.md index 587a302a..192e4467 100644 --- a/docs/development/SUPABASE.md +++ b/docs/development/SUPABASE.md @@ -16,7 +16,9 @@ supabase/ │ ├─ 20261008110000_anatomical_sheets.sql species, sheets, immutable versions, assets, lifecycle RPCs │ ├─ 20261008110100_private_execute_hardening.sql EXECUTE revoked from PUBLIC on the Step 3 helpers │ ├─ 20261009100000_sheet_asset_storage.sql bucket anatomical-sheet-assets + read policy through the sheet -│ └─ 20261010100000_sheet_document_schema_v2.sql document schema 2: references, review_status, count_range checks +│ ├─ 20261010100000_sheet_document_schema_v2.sql document schema 2: references, review_status, count_range checks +│ ├─ 20261011100000_profiles_professional.sql practice_name, professional_title, siret +│ └─ 20261013100000_files_foundation.sql assets table, seven private buckets, avatar policies through assets, purge queue, browser + worker RPCs (STORAGE.md) ├─ seed.sql LOCAL dev accounts + first owner (never run in prod) ├─ seed/anatomical-sheets/equine/ official equine sheet as a DRAFT, generated by `pnpm import:equine` │ ├─ legacy-sources/ the historical Horse.svg, Horse_head.svg, pathologies.json, vertebrae.ts (importer input) @@ -28,7 +30,9 @@ packages/supabase/ ├─ src/client.ts createBrowserClient() (anon key, PKCE) ├─ src/database.types.ts `supabase gen types` output ├─ src/anatomical-sheets.ts publishSheetVersion(): Zod + integrity gate before the RPC -└─ tests/db/ PGlite harness: runs the pgTAP files without Docker +├─ src/assets.ts avatar flow: begin / quarantine upload / confirm / remove / own state / download, closed AssetFailure kinds +├─ tests/db/ PGlite harness: runs the pgTAP files without Docker +└─ tests/e2e/ real-stack end-to-end (avatar flow with the worker container), `pnpm e2e:avatar` packages/domain/ └─ src/anatomical-sheet/ canonical sheet document (Zod), validateSheetDocument, createEmptySheetDocument ``` @@ -109,6 +113,22 @@ uploading, keeps objects already present, and calls read policy ignores a row whose upload was never confirmed, so a user who registers a known hash on their own sheet opens nothing. +### 3.2 Files worker (Storage, Step 8) + +User files land in private buckets and are processed by the Rust worker +(`crates/worker`, `docs/development/STORAGE.md`). Against the local stack: + +```bash +pnpm worker:image # faunosteo_worker:dev +pnpm e2e:avatar # starts the container on supabase_network_faunosteo, runs tests/e2e, stops it +docker compose --profile worker up worker # the same container from docker-compose.yml, reading .env.worker +``` + +`.env.worker` (not editable by the assistant): `SUPABASE_URL=http://supabase_kong_faunosteo:8000`, +`SUPABASE_SERVICE_ROLE_KEY=`, `WORKER_ID=dev`. +The service key stays in that file and in the shell; it never reaches the +app `.env`, env.js or a commit. + Seed accounts (local only, password `LocalDev-only-password-1`): | Email | Role | diff --git a/docs/development/TEST_STRATEGY.md b/docs/development/TEST_STRATEGY.md index 8786646d..8a2bb30c 100644 --- a/docs/development/TEST_STRATEGY.md +++ b/docs/development/TEST_STRATEGY.md @@ -19,7 +19,9 @@ Status: Step 0 deliverable, 2026-10-08. Current state: 32 files under | SQL/TS contract | generated types diff check | CI | every PR touching `supabase/` | | Rust core and facade | `cargo test` (unit + fixture tests reading the repository JSON in place), `clippy -D warnings`, `cargo deny`; ts-rs types drift check | `crates/*`, `pnpm rust:check` (native, `scripts/rust-check.sh`; same file in the builder image), `pnpm check:all` | before every Rust commit and every merge; CI job `rust` prepared, no runner yet | | Rust/TS contract | vitest proofs on the built module: byte equality with `JSON.stringify(…, null, 2)` on the real documents, optional/nullable shape read by the current Zod schemas, panic and stack traps, served size budget | `packages/core-wasm/tests` (skipped with a notice when `pkg/` is absent) | `pnpm check:all` (after the native `wasm:build`); CI `check` prepared | -| Worker sandbox | integration tests against the musl binary that ships: fixture corpus through the full sandbox, refusals, SIGSYS on a denied syscall, output cap, `RLIMIT_AS` abort, `RLIMIT_CPU`, deadline; seccomp allowlist derived by `strace` and compared | `crates/worker/tests`, Dockerfile stage `test` (`pnpm worker:test`, Docker only, never native) | every `crates/worker` commit, `pnpm check:all`; CI `docker` job prepared | +| Worker sandbox | integration tests against the musl binary that ships: fixture corpus through the full sandbox, refusals, SIGSYS on a denied syscall, output cap, `RLIMIT_AS` abort, `RLIMIT_CPU`, deadline; seccomp allowlist derived by `strace` and compared | `crates/worker/tests/sandbox.rs`, Dockerfile stage `test` (`pnpm worker:test`, Docker only, never native) | every `crates/worker` commit, `pnpm check:all`; CI `docker` job prepared | +| Worker job loop | native unit tests on a fake backend and a fake decoder: call order claim → download → decode → upload → commit → purge, every child outcome mapped to a closed code, no deletion on a refused commit, lease left on transport failures, sweeper targets and acks, key validation, config and secret redaction | `crates/worker/tests/job_loop.rs`, `crates/worker/src/*` unit tests (`pnpm rust:check`) | every Rust commit | +| Files e2e (real stack) | the worker container against the local Supabase stack: clean upload and owner-only download (Bob, anon, quarantine, direct final-key write refused), replacement and purge after the grace (queue clock shifted through psql), late signed-upload bytes swept, hostile uploads rejected with closed codes, removal and drained queue | `packages/supabase/tests/e2e/avatar-flow.e2e.ts` (`pnpm e2e:avatar`, `scripts/avatar-e2e.sh`) | every Storage, worker or avatar change; not in `check:all` (needs the stack) | Browser-only code (`svgToPng`, `DOMParser` in the importer) runs under happy-dom where sufficient and under Playwright when real rendering matters diff --git a/docs/development/WORKSPACE.md b/docs/development/WORKSPACE.md index 3e751080..2e09f100 100644 --- a/docs/development/WORKSPACE.md +++ b/docs/development/WORKSPACE.md @@ -94,6 +94,7 @@ works as `corepack pnpm `. | `pnpm build` | typecheck + Vite build in every package | | `pnpm check` | typecheck, test:run, lint, build in sequence (the Node gate) | | `pnpm check:all` | the whole pre-merge gate: native Rust check, types drift, wasm build, `pnpm check`, application and worker images (`docs/development/RUST.md` §4; no CI runs it yet) | +| `pnpm e2e:avatar` | real-stack end-to-end of the avatar flow: worker container against the local Supabase stack + `packages/supabase/tests/e2e` (`docs/development/STORAGE.md` §6; needs `pnpm db:start`) | | `pnpm format` | Prettier on the whole repository | Package-scoped: `pnpm --filter @faunosteo/app