test(supabase): avatar e2e on the sandbox only, per-session seed secret

pnpm e2e:avatar is now an alias of pnpm db:sandbox avatar-e2e and the DEV
script scripts/avatar-e2e.sh is removed; the suite fails on any target but
the sandbox gateway and database; an occupied port 57800 stops the run before
anything starts. The sandbox replaces the seed accounts' DEV password by a
per-session secret.
This commit is contained in:
bchanot committed 2026-11-01 22:55:23 +01:00
1 parent 26e4b1b0ee
commit cdd43ac431
16 files changed
+64 -100

No files matched your search

+4 -4
View File
@@ -149,7 +149,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 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: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 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 DEV stack + packages/supabase/tests/e2e (owner's call only; `pnpm db:sandbox avatar-e2e` runs the same suite on the throwaway stack) pnpm e2e:avatar # = pnpm db:sandbox avatar-e2e: the worker container and packages/supabase/tests/e2e on the throwaway stack only (the suite refuses any other target; no DEV variant since 2026-11-01)
``` ```
## Test commands ## Test commands
@@ -270,7 +270,7 @@ faunosteo/
├─ packages/supabase/ ← @faunosteo/supabase ├─ packages/supabase/ ← @faunosteo/supabase
│ ├─ src/{index,client,database.types,anatomical-sheets,assets}.ts ← typed client, generated types, publish gate, avatar flow (closed AssetFailure kinds) │ ├─ src/{index,client,database.types,anatomical-sheets,assets}.ts ← typed client, generated types, publish gate, avatar flow (closed AssetFailure kinds)
│ ├─ src/{records,workspaces,clients,species,animals,relations,field-limits}.ts ← V1-1 record access (closed RecordFailure kinds, keyset pages), D-R7 bounds │ ├─ src/{records,workspaces,clients,species,animals,relations,field-limits}.ts ← V1-1 record access (closed RecordFailure kinds, keyset pages), D-R7 bounds
│ ├─ tests/e2e/avatar-flow.e2e.ts + vitest.e2e.config.ts ← real-stack end-to-end (`pnpm db:sandbox avatar-e2e`; `pnpm e2e:avatar` on DEV), skipped without the stack env and its database container │ ├─ tests/e2e/avatar-flow.e2e.ts + vitest.e2e.config.ts ← real-stack end-to-end (`pnpm e2e:avatar` = `pnpm db:sandbox avatar-e2e`), fails on any target but the sandbox gateway and database
│ └─ tests/{client,anatomical-sheets}.test.ts, tests/db/ ← PGlite harness, shim, pgTAP runner, schema↔types test │ └─ tests/{client,anatomical-sheets}.test.ts, tests/db/ ← PGlite harness, shim, pgTAP runner, schema↔types test
├─ supabase/ ├─ supabase/
│ ├─ config.toml, seed.sql ← CLI config (public schema only), local dev accounts │ ├─ config.toml, seed.sql ← CLI config (public schema only), local dev accounts
@@ -287,7 +287,7 @@ faunosteo/
│ ├─ core/ ← faunosteo-core: domain/{js,sheet,report,archive,editor,session} (contracts and rules; sheet/{size,keys,caps,review,report,verdict,preview,edit} since V1-2.2: server document measure, review groups and digests, the server verdict, PreviewSheet, the editor's commands, RUST.md §12), anatomy/{svg/{prescan,tree,sanitize,refs,number,serialize,clean},layer,compose} (R3: the one SVG reader, the layer, canvas + highlight composition), pdf/{read,json_js,import,write,compare} (R4: reader, writer and session, the archive check tool behind feature `cli`), ops.rs + facade.rs (`call`, `call_with_sheet`), json (JS number printing), curation/{text,ids,prettier_json,markdown,report_guard,legacy/*,draft/*} (R5, feature `curation`: Prettier layout, the legacy importer, the changeset applier, migration map, stats, seed SQL, CHANGELOG, REVIEW-REPORT, review drawings), curation/upload.rs (R5.5, feature `upload`: the upload rules, pure) + bin/report_compare.rs (`pnpm report:compare`) + bin/import_equine.rs (`pnpm r5:import-equine`) + bin/upload_sheet_assets/ (`pnpm assets:upload`, ureq; the three tools allowed std::fs); tests/{oracles,conformance,fixtures,pdf/LEDGER.tsv} frozen from the TypeScript (oracles/r3, oracles/r4, fixtures/svg/hostile); no I/O, no clock (lint-enforced) │ ├─ core/ ← faunosteo-core: domain/{js,sheet,report,archive,editor,session} (contracts and rules; sheet/{size,keys,caps,review,report,verdict,preview,edit} since V1-2.2: server document measure, review groups and digests, the server verdict, PreviewSheet, the editor's commands, RUST.md §12), anatomy/{svg/{prescan,tree,sanitize,refs,number,serialize,clean},layer,compose} (R3: the one SVG reader, the layer, canvas + highlight composition), pdf/{read,json_js,import,write,compare} (R4: reader, writer and session, the archive check tool behind feature `cli`), ops.rs + facade.rs (`call`, `call_with_sheet`), json (JS number printing), curation/{text,ids,prettier_json,markdown,report_guard,legacy/*,draft/*} (R5, feature `curation`: Prettier layout, the legacy importer, the changeset applier, migration map, stats, seed SQL, CHANGELOG, REVIEW-REPORT, review drawings), curation/upload.rs (R5.5, feature `upload`: the upload rules, pure) + bin/report_compare.rs (`pnpm report:compare`) + bin/import_equine.rs (`pnpm r5:import-equine`) + bin/upload_sheet_assets/ (`pnpm assets:upload`, ureq; the three tools allowed std::fs); tests/{oracles,conformance,fixtures,pdf/LEDGER.tsv} frozen from the TypeScript (oracles/r3, oracles/r4, fixtures/svg/hostile); no I/O, no clock (lint-enforced)
│ ├─ wasm/ ← faunosteo-wasm: wasm-bindgen facade (core_version, call, SheetHandle, PreviewBuilder → PreviewSheet, clean_svg; trap exports in the proofs build only) │ ├─ wasm/ ← faunosteo-wasm: wasm-bindgen facade (core_version, call, SheetHandle, PreviewBuilder → PreviewSheet, clean_svg; trap exports in the proofs build only)
│ └─ worker/ ← faunosteo-worker: plain main; `decode` sandboxed child (rlimits, seccomp allowlist, image → libwebp), parent Spawner + RIFF check; V1-2.3 `verify` sandboxed child (framed input → the core's `compute_verdict`) and `run --jobs sheet-verify` (verify_job, VerifyBackend: M6 RPCs + drawing downloads); 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 │ └─ worker/ ← faunosteo-worker: plain main; `decode` sandboxed child (rlimits, seccomp allowlist, image → libwebp), parent Spawner + RIFF check; V1-2.3 `verify` sandboxed child (framed input → the core's `compute_verdict`) and `run --jobs sheet-verify` (verify_job, VerifyBackend: M6 RPCs + drawing downloads); 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,report-compare,import-equine,upload-sheet-assets,sheet-assets-e2e,floor-clarification-check}.sh, wasm-stamp.mjs ← native Rust gate, wasm build (pkg + pkg-proofs + stamp), the pre-merge gate (`pnpm check:all`), the real-stack avatar e2e, the archive check tool (`pnpm report:compare`), the Rust pipeline (`pnpm r5:import-equine`) ├─ scripts/{rust-env,rust-check,wasm-build,check-all,report-compare,import-equine,upload-sheet-assets,sheet-assets-e2e,floor-clarification-check}.sh, wasm-stamp.mjs ← native Rust gate, wasm build (pkg + pkg-proofs + stamp), the pre-merge gate (`pnpm check:all`), the real-stack avatar e2e, the archive check tool (`pnpm report:compare`), the Rust pipeline (`pnpm r5:import-equine`)
├─ scripts/{dev-env,supabase,dev}.sh ← the DEV origin (LAN address) in one place; CLI wrapper; `pnpm dev` on that origin ├─ scripts/{dev-env,supabase,dev}.sh ← the DEV origin (LAN address) in one place; CLI wrapper; `pnpm dev` on that origin
├─ docker-compose.yml ← `app` service; `worker` and `worker-verify` (V1-2.3, `run --jobs sheet-verify`) services under the `worker` profile (read-only, cap_drop ALL, external Supabase network, `.env.worker`) ├─ docker-compose.yml ← `app` service; `worker` and `worker-verify` (V1-2.3, `run --jobs sheet-verify`) services 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 proofs (R0 module, R2 app image: app-image.sh) ├─ docker/rust-builder.Dockerfile, rust-run.sh, csp-proof/ ← reproducible Rust builder (alternative) + the CSP proofs (R0 module, R2 app image: app-image.sh)
@@ -489,7 +489,7 @@ release 0.2.0 unaffected.
- After PDF roundtrip tests fail: check the attachment bytes (the N-1 scanner reads them in the envelope suites), then the layered reader (report first, envelope metadata, snapshot/branding/labels), then the core's inflation (`pdf/read/inflate.rs`). Goldens under `apps/app/tests/fixtures/goldens/step6` and the R4 digests under `goldens/r4` are never regenerated without a user decision. - After PDF roundtrip tests fail: check the attachment bytes (the N-1 scanner reads them in the envelope suites), then the layered reader (report first, envelope metadata, snapshot/branding/labels), then the core's inflation (`pdf/read/inflate.rs`). Goldens under `apps/app/tests/fixtures/goldens/step6` and the R4 digests under `goldens/r4` are never regenerated without a user decision.
- Node 24 / pnpm 10.13.1: `corepack enable` or `corepack pnpm`; never a global install. - 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. - 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 db:sandbox avatar-e2e` (the avatar suite `packages/supabase/tests/e2e` and the real worker on the throwaway stack) in addition to `pnpm worker:test`; `pnpm e2e:avatar` starts a worker against the DEV stack and runs only on the owner's go (owner decision 2026-11-01); `docker compose --profile worker` serves the worker from `.env.worker` (never the app `.env`). - Storage or worker change: `pnpm db:sandbox avatar-e2e` (the avatar suite `packages/supabase/tests/e2e` and the real worker on the throwaway stack) in addition to `pnpm worker:test`; `pnpm e2e:avatar` is its alias (owner decision 2026-11-01: no avatar e2e against DEV, `scripts/avatar-e2e.sh` removed); `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` - 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`). on the real stack when Docker is available; regenerate types (`pnpm db:types`).
+2 -3
View File
@@ -111,9 +111,8 @@ pinned toolchain from `rust-toolchain.toml` on first use; see
`docs/development/RUST.md` §1 for the three `cargo install` / `rustup `docs/development/RUST.md` §1 for the three `cargo install` / `rustup
target add` lines and the Docker alternative. The files worker (profile target add` lines and the Docker alternative. The files worker (profile
photos, Step 8) runs as a container beside the local Supabase stack: photos, Step 8) runs as a container beside the local Supabase stack:
`pnpm worker:image`, then `pnpm db:sandbox avatar-e2e` for the real-stack `pnpm worker:image`, then `pnpm e2e:avatar` (= `pnpm db:sandbox avatar-e2e`) for the
end-to-end run on the throwaway stack (`pnpm e2e:avatar` runs it against the real-stack end-to-end run on the throwaway stack, or `docker compose --profile worker up worker` with a `.env.worker`
local DEV stack), or `docker compose --profile worker up worker` with a `.env.worker`
(`docs/development/STORAGE.md`). (`docs/development/STORAGE.md`).
Docker Compose (matches production topology): Docker Compose (matches production topology):
+1 -1
View File
@@ -102,7 +102,7 @@ Chromium (Playwright prints the install command), a stale core module
`pnpm check:all` runs `pnpm e2e:ui` when the pinned Chromium is installed; `pnpm check:all` runs `pnpm e2e:ui` when the pinned Chromium is installed;
otherwise it prints `SKIPPED` with the reason and the install command, and otherwise it prints `SKIPPED` with the reason and the install command, and
goes on. `pnpm e2e:shell` needs the sandbox and stays a separate run, like goes on. `pnpm e2e:shell` needs the sandbox and stays a separate run, like
`pnpm db:sandbox avatar-e2e`. The last lines of a green run state each browser suite: `pnpm e2e:avatar` (= `pnpm db:sandbox avatar-e2e`). The last lines of a green run state each browser suite:
`PASSED`, `SKIPPED` (environment missing, with the reason) or `NOT RUN` `PASSED`, `SKIPPED` (environment missing, with the reason) or `NOT RUN`
(`e2e:shell`). A suite that runs and fails stops `check:all` with (`e2e:shell`). A suite that runs and fails stops `check:all` with
`== FAILED: <stage>` and a non-zero exit, never a warning. Both suites keep `== FAILED: <stage>` and a non-zero exit, never a warning. Both suites keep
+1 -1
View File
@@ -35,7 +35,7 @@ never hard-coded in the sources.
Consumers: `scripts/supabase.sh` (every CLI call: `pnpm supabase …`, Consumers: `scripts/supabase.sh` (every CLI call: `pnpm supabase …`,
`pnpm db:start|stop|reset|test|types`), `scripts/dev.sh` (`pnpm dev`), `pnpm db:start|stop|reset|test|types`), `scripts/dev.sh` (`pnpm dev`),
`scripts/avatar-e2e.sh`. The address changes with `FAUNOSTEO_DEV_HOST=…` `scripts/db-sandbox.sh`. The address changes with `FAUNOSTEO_DEV_HOST=…`
in front of the command, without touching a source file. Calling the CLI in front of the command, without touching a source file. Calling the CLI
binary directly (`node_modules/.bin/supabase start`) leaves the literal binary directly (`node_modules/.bin/supabase start`) leaves the literal
`env(...)` text in the services: always go through `pnpm`. `env(...)` text in the services: always go through `pnpm`.
+1 -1
View File
@@ -130,7 +130,7 @@ VITE_AUTH_PROVIDERS=google pnpm dev # http://<host>:5173 from any device of th
(SUPABASE.md §8). (SUPABASE.md §8).
10. Profile photo (Step 8, worker container running: `pnpm worker:image` 10. Profile photo (Step 8, worker container running: `pnpm worker:image`
then `docker compose --profile worker up worker` or the container of then `docker compose --profile worker up worker` or the container of
`scripts/avatar-e2e.sh`): Mon compte → Modifier la photo with a phone `pnpm e2e:avatar` on the sandbox): Mon compte → Modifier la photo with a phone
JPEG → preview → Enregistrer → "Traitement en cours…" → the photo in the JPEG → preview → Enregistrer → "Traitement en cours…" → the photo in the
circle, the sidebar, the drawer (mobile) and the top bar (name beside it 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 on desktop, alone on mobile) linking to Mon compte; a renamed PNG is
+5 -5
View File
@@ -35,7 +35,7 @@ packages/supabase/
├─ src/anatomical-sheets.ts publishSheetVersion(): the core's verdict (`sheet.check`) as gate before the RPC ├─ src/anatomical-sheets.ts publishSheetVersion(): the core's verdict (`sheet.check`) as gate before the RPC
├─ src/assets.ts avatar flow: begin / quarantine upload / confirm / remove / own state / download, closed AssetFailure kinds ├─ 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/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` └─ tests/e2e/ real-stack end-to-end (avatar flow with the worker container), `pnpm e2e:avatar` on the sandbox
crates/core/src/domain/sheet/ canonical sheet document and its integrity rules (Rust core; `packages/domain` deleted at R5.7) crates/core/src/domain/sheet/ canonical sheet document and its integrity rules (Rust core; `packages/domain` deleted at R5.7)
``` ```
@@ -167,8 +167,7 @@ User files land in private buckets and are processed by the Rust worker
```bash ```bash
pnpm worker:image # faunosteo_worker:dev pnpm worker:image # faunosteo_worker:dev
pnpm e2e:avatar # starts the container on supabase_network_faunosteo, runs tests/e2e, stops it (DEV: the owner's call) pnpm e2e:avatar # = pnpm db:sandbox avatar-e2e: the suite and the worker on the throwaway stack (§5.1) only
pnpm db:sandbox avatar-e2e # the same suite and worker image on the throwaway stack (§5.1), the check of a storage or worker change
docker compose --profile worker up worker # the same container from docker-compose.yml, reading .env.worker docker compose --profile worker up worker # the same container from docker-compose.yml, reading .env.worker
``` ```
@@ -515,8 +514,9 @@ the scripts:
on the sandbox, clean and with those conditions reproduced (scenarios and on the sandbox, clean and with those conditions reproduced (scenarios and
mutations in the journal of 2026-10-27). DEV is not validated by `db:test` mutations in the journal of 2026-10-27). DEV is not validated by `db:test`
until a run there passes. until a run there passes.
- `pnpm e2e:avatar`: not part of this procedure; optional, the owner's call. - `pnpm e2e:avatar`: not part of this procedure. Since 2026-11-01 it runs on
It writes on DEV beyond its own fixture: it creates a temporary confirmed the sandbox only (owner decision; the DEV script `scripts/avatar-e2e.sh` is
removed). Its DEV run, as recorded on 2026-10-26, wrote on DEV beyond its own fixture: it creates a temporary confirmed
account `e2e-avatar-<time>@faunosteo.local` (and, after M1, its workspace), account `e2e-avatar-<time>@faunosteo.local` (and, after M1, its workspace),
deletes it at the end (a failed run leaves it), signs in as deletes it at the end (a failed run leaves it), signs in as
`bob@faunosteo.local` (sessions and `last_sign_in_at` of an existing `bob@faunosteo.local` (sessions and `last_sign_in_at` of an existing
+1 -1
View File
@@ -67,7 +67,7 @@ unit suites, 2 by the browser journeys.
| CSP on the image (R2) | the real app image behind the DEPLOY.md CSP in headless Chromium: with `'wasm-unsafe-eval'` the core runs the editor path, without it the degraded state and an untouched draft; no module request on `/login`, `/app/account`, `/` | `docker/csp-proof/app-image.sh` | before a merge touching the core loading or the image; manual (needs Chromium) | | CSP on the image (R2) | the real app image behind the DEPLOY.md CSP in headless Chromium: with `'wasm-unsafe-eval'` the core runs the editor path, without it the degraded state and an untouched draft; no module request on `/login`, `/app/account`, `/` | `docker/csp-proof/app-image.sh` | before a merge touching the core loading or the image; manual (needs Chromium) |
| 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 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 | | 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) | | Files e2e (real stack) | the worker container against the throwaway sandbox stack (since 2026-11-01; DEV before): 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` = `pnpm db:sandbox avatar-e2e`, `scripts/db-sandbox.sh`) | every Storage, worker or avatar change; not in `check:all` (needs the sandbox) |
Browser-only code (`svgToPng`, `DOMParser` in the importer) runs under Browser-only code (`svgToPng`, `DOMParser` in the importer) runs under
happy-dom where sufficient and under Playwright when real rendering matters happy-dom where sufficient and under Playwright when real rendering matters
+1 -1
View File
@@ -101,7 +101,7 @@ works as `corepack pnpm <cmd>`.
| `pnpm build` | typecheck + Vite build in every package | | `pnpm build` | typecheck + Vite build in every package |
| `pnpm check` | typecheck, test:run, lint, build in sequence (the Node gate) | | `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 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 e2e:avatar` | = `pnpm db:sandbox avatar-e2e`: real-stack end-to-end of the avatar flow, worker container + `packages/supabase/tests/e2e` on the throwaway stack only (`docs/development/STORAGE.md` §6; needs `pnpm db:sandbox up fresh` and `pnpm worker:image`) |
| `pnpm format` | Prettier on the whole repository | | `pnpm format` | Prettier on the whole repository |
Package-scoped: `pnpm --filter @faunosteo/app <script>`. Package-scoped: `pnpm --filter @faunosteo/app <script>`.
+1 -1
View File
@@ -46,7 +46,7 @@
"wasm:build:docker": "bash docker/rust-run.sh bash scripts/wasm-build.sh", "wasm:build:docker": "bash docker/rust-run.sh bash scripts/wasm-build.sh",
"worker:test": "docker build -f crates/worker/Dockerfile --target test -t faunosteo_worker:test .", "worker:test": "docker build -f crates/worker/Dockerfile --target test -t faunosteo_worker:test .",
"worker:image": "docker build -f crates/worker/Dockerfile -t faunosteo_worker:dev .", "worker:image": "docker build -f crates/worker/Dockerfile -t faunosteo_worker:dev .",
"e2e:avatar": "bash scripts/avatar-e2e.sh", "e2e:avatar": "bash scripts/db-sandbox.sh avatar-e2e",
"e2e:ui": "pnpm --filter @faunosteo/app e2e:ui", "e2e:ui": "pnpm --filter @faunosteo/app e2e:ui",
"e2e:shell": "bash scripts/db-sandbox.sh e2e-shell" "e2e:shell": "bash scripts/db-sandbox.sh e2e-shell"
}, },
+15 -12
View File
@@ -1,15 +1,15 @@
/** /**
* Avatar flow against a real stack and the worker container * Avatar flow against a real stack and the worker container
* (docs/development/STORAGE.md §4, §3; STEP8_FILES_ANALYSIS IV.2 "integration" * (docs/development/STORAGE.md §4, §3; STEP8_FILES_ANALYSIS IV.2 "integration"
* and "real-stack e2e"). Run through `pnpm db:sandbox avatar-e2e` (the throwaway * and "real-stack e2e"). Run through `pnpm e2e:avatar` (= `pnpm db:sandbox
* stack) or `pnpm e2e:avatar` (scripts/avatar-e2e.sh, the local DEV stack), both * avatar-e2e`): the throwaway stack only, the worker started with a 5 s sweep and
* starting the worker with a 5 s sweep and a 0 s quarantine grace. * a 0 s quarantine grace.
* *
* Environment: SUPABASE_URL, SUPABASE_ANON_KEY, SUPABASE_SERVICE_ROLE_KEY * Environment: SUPABASE_URL, SUPABASE_ANON_KEY, SUPABASE_SERVICE_ROLE_KEY
* (the service key is used for inspection only: listing objects and shifting * (the service key is used for inspection only: listing objects and shifting
* the purge clock through psql) and AVATAR_E2E_DB_CONTAINER, the database * the purge clock through psql) and AVATAR_E2E_DB_CONTAINER. The URL and the
* container of that same stack, named by the caller: no default, so a run never * container must be the sandbox's own: any other value, or a missing one, fails
* reaches another stack's database. Both accounts are made per run. * the run before any request. Both accounts are made per run.
*/ */
import { createHash, randomBytes } from 'node:crypto' import { createHash, randomBytes } from 'node:crypto'
import { execFileSync } from 'node:child_process' import { execFileSync } from 'node:child_process'
@@ -30,6 +30,11 @@ const URL_ = process.env.SUPABASE_URL
const ANON = process.env.SUPABASE_ANON_KEY const ANON = process.env.SUPABASE_ANON_KEY
const SERVICE = process.env.SUPABASE_SERVICE_ROLE_KEY const SERVICE = process.env.SUPABASE_SERVICE_ROLE_KEY
const DB_CONTAINER = process.env.AVATAR_E2E_DB_CONTAINER const DB_CONTAINER = process.env.AVATAR_E2E_DB_CONTAINER
/** The only target accepted: the gateway and database of `pnpm db:sandbox avatar-e2e`. */
const SANDBOX_URL = 'http://127.0.0.1:57800'
const SANDBOX_DB = 'faunosteo_dbsandbox_db'
if (URL_ !== SANDBOX_URL || DB_CONTAINER !== SANDBOX_DB || !ANON || !SERVICE)
throw new Error('avatar e2e: run it through pnpm e2e:avatar, on the sandbox stack only')
/** Per run, kept in memory only: both accounts are deleted after the suite. */ /** Per run, kept in memory only: both accounts are deleted after the suite. */
const PASSWORD = randomBytes(18).toString('base64url') const PASSWORD = randomBytes(18).toString('base64url')
const WORKER_WAIT_MS = 60_000 const WORKER_WAIT_MS = 60_000
@@ -37,7 +42,7 @@ const WORKER_WAIT_MS = 60_000
type Client = SupabaseClient<Database> type Client = SupabaseClient<Database>
function anonClient(): Client { function anonClient(): Client {
return createClient<Database>(URL_ ?? '', ANON ?? '', { return createClient<Database>(SANDBOX_URL, ANON ?? '', {
auth: { persistSession: false, autoRefreshToken: false }, auth: { persistSession: false, autoRefreshToken: false },
}) })
} }
@@ -50,7 +55,7 @@ async function signedIn(email: string): Promise<Client> {
} }
function serviceClient(): Client { function serviceClient(): Client {
return createClient<Database>(URL_ ?? '', SERVICE ?? '', { return createClient<Database>(SANDBOX_URL, SERVICE ?? '', {
auth: { persistSession: false, autoRefreshToken: false }, auth: { persistSession: false, autoRefreshToken: false },
}) })
} }
@@ -169,7 +174,7 @@ async function objectExists(service: Client, bucket: string, key: string): Promi
function psql(sql: string): string { function psql(sql: string): string {
return execFileSync('docker', [ return execFileSync('docker', [
'exec', DB_CONTAINER ?? '', 'psql', '-U', 'postgres', '-d', 'postgres', '-Atc', sql, 'exec', SANDBOX_DB, 'psql', '-U', 'postgres', '-d', 'postgres', '-Atc', sql,
]).toString().trim() ]).toString().trim()
} }
@@ -200,8 +205,6 @@ function sha256(bytes: Uint8Array): string {
// --- suite ------------------------------------------------------------------ // --- suite ------------------------------------------------------------------
const configured = Boolean(URL_ && ANON && SERVICE && DB_CONTAINER)
/** A confirmed throwaway account; resolves with its id. */ /** A confirmed throwaway account; resolves with its id. */
async function newAccount(service: Client, tag: string, name: string): Promise<{ id: string; email: string }> { async function newAccount(service: Client, tag: string, name: string): Promise<{ id: string; email: string }> {
const email = `e2e-${tag}-${Date.now()}@faunosteo.local` const email = `e2e-${tag}-${Date.now()}@faunosteo.local`
@@ -215,7 +218,7 @@ async function newAccount(service: Client, tag: string, name: string): Promise<{
return { id: created.data.user.id, email } return { id: created.data.user.id, email }
} }
describe.skipIf(!configured)('avatar flow on the real stack', () => { describe('avatar flow on the sandbox stack', () => {
const service = serviceClient() const service = serviceClient()
let alice: Client let alice: Client
let aliceId: string let aliceId: string
@@ -8,16 +8,15 @@
* factors and sessions made here are removed afterwards (as postgres), so the * factors and sessions made here are removed afterwards (as postgres), so the
* owner is back to no factor and the suite runs again on the same stack. * owner is back to no factor and the suite runs again on the same stack.
*/ */
import { confirmedAccount, errorCode, rest, rpc, signIn, sql } from './stack' import { SEED_PASSWORD, confirmedAccount, errorCode, rest, rpc, signIn, sql } from './stack'
import { claimsOf, enrolTotp, stepUp, verifyTotp } from './mfa' import { claimsOf, enrolTotp, stepUp, verifyTotp } from './mfa'
const OWNER = '10000000-0000-0000-0000-000000000001' const OWNER = '10000000-0000-0000-0000-000000000001'
const OWNER_EMAIL = 'owner@faunosteo.local' const OWNER_EMAIL = 'owner@faunosteo.local'
const OWNER_PASSWORD = 'LocalDev-only-password-1'
const FACTOR_PREFIX = 'seed-owner-test' const FACTOR_PREFIX = 'seed-owner-test'
const passwordSession = async (): Promise<string> => { const passwordSession = async (): Promise<string> => {
const session = await signIn(OWNER_EMAIL, OWNER_PASSWORD) const session = await signIn(OWNER_EMAIL, SEED_PASSWORD)
return session.body.access_token as string return session.body.access_token as string
} }
const refusal = (result: { status: number; body: unknown }) => const refusal = (result: { status: number; body: unknown }) =>
+2
View File
@@ -25,6 +25,8 @@ export const stack = {
serviceKey: need('SANDBOX_SERVICE_KEY'), serviceKey: need('SANDBOX_SERVICE_KEY'),
} }
const PG_PASSWORD = need('SANDBOX_PG_PASSWORD') const PG_PASSWORD = need('SANDBOX_PG_PASSWORD')
/** The seeded accounts' password in this sandbox session (db-sandbox.sh replaces the seed's). */
export const SEED_PASSWORD = need('SANDBOX_SEED_PASSWORD')
/** The password of the accounts a run creates: random per run, kept in memory only. */ /** The password of the accounts a run creates: random per run, kept in memory only. */
export const PASSWORD = randomBytes(18).toString('base64url') export const PASSWORD = randomBytes(18).toString('base64url')
+2 -2
View File
@@ -1,8 +1,8 @@
import { defineConfig } from 'vitest/config' import { defineConfig } from 'vitest/config'
/** /**
* Real-stack end-to-end suite (tests/e2e/*.e2e.ts): needs the local Supabase * Real-stack end-to-end suite (tests/e2e/*.e2e.ts): the throwaway stack and the
* stack and the worker container (scripts/avatar-e2e.sh starts both sides). * worker container, both started by `pnpm e2e:avatar` (scripts/db-sandbox.sh).
* Kept out of the default `test:run` include on purpose. * Kept out of the default `test:run` include on purpose.
*/ */
export default defineConfig({ export default defineConfig({
-59
View File
@@ -1,59 +0,0 @@
#!/usr/bin/env bash
# Real-stack end-to-end run of the avatar flow (docs/development/STORAGE.md §6):
# starts the worker container against the local Supabase stack with a fast sweep
# and no quarantine grace, runs packages/supabase/tests/e2e, stops the container.
# Needs: `pnpm db:start` done, Docker, the worker image (`pnpm worker:image`,
# built here when absent). The keys come from `supabase status`; the service key
# reaches the container through a 600-mode temporary env file, never the command line.
set -euo pipefail
cd "$(dirname "$0")/.."
network="${SUPABASE_NETWORK:-supabase_network_faunosteo}"
kong="${SUPABASE_INTERNAL_URL:-http://supabase_kong_faunosteo:8000}"
image="${WORKER_IMAGE:-faunosteo_worker:dev}"
name="faunosteo_worker_e2e"
. scripts/dev-env.sh
status="$(node_modules/.bin/supabase status -o env 2>/dev/null)" \
|| { echo "avatar-e2e: the local stack is not running (pnpm db:start)" >&2; exit 1; }
value() { printf '%s\n' "$status" | sed -n "s/^$1=\"\(.*\)\"$/\1/p"; }
api_url="$(value API_URL)"
anon_key="$(value ANON_KEY)"
service_key="$(value SERVICE_ROLE_KEY)"
[ -n "$api_url" ] && [ -n "$anon_key" ] && [ -n "$service_key" ] \
|| { echo "avatar-e2e: could not read the keys from supabase status" >&2; exit 1; }
if ! docker image inspect "$image" >/dev/null 2>&1; then
echo "== building $image"
docker build -f crates/worker/Dockerfile -t "$image" .
fi
env_file="$(mktemp)"
chmod 600 "$env_file"
cleanup() {
echo "== worker log (last lines)"
docker logs --tail 40 "$name" 2>/dev/null || true
docker rm -f "$name" >/dev/null 2>&1 || true
rm -f "$env_file"
}
trap cleanup EXIT
{
echo "SUPABASE_URL=$kong"
echo "SUPABASE_SERVICE_ROLE_KEY=$service_key"
echo "WORKER_ID=e2e"
echo "WORKER_POLL_SECONDS=1"
echo "WORKER_SWEEP_SECONDS=5"
echo "WORKER_QUARANTINE_GRACE_SECONDS=0"
} > "$env_file"
docker rm -f "$name" >/dev/null 2>&1 || true
echo "== starting $name on $network"
docker run -d --name "$name" --read-only --cap-drop ALL \
--security-opt no-new-privileges:true --memory 512m --cpus 1 --pids-limit 64 \
--network "$network" --env-file "$env_file" "$image" run >/dev/null
echo "== e2e suite"
SUPABASE_URL="$api_url" SUPABASE_ANON_KEY="$anon_key" SUPABASE_SERVICE_ROLE_KEY="$service_key" \
AVATAR_E2E_DB_CONTAINER="${AVATAR_E2E_DB_CONTAINER:-supabase_db_faunosteo}" \
pnpm --filter @faunosteo/supabase test:e2e
+25 -5
View File
@@ -17,7 +17,7 @@
# pnpm db:sandbox verify-e2e [args] the sheet verification worker against the sandbox: an # pnpm db:sandbox verify-e2e [args] the sheet verification worker against the sandbox: an
# unpublished gateway, the worker container, then # unpublished gateway, the worker container, then
# tests/sandbox/sheet-verification.sandbox.ts (args go to vitest) # tests/sandbox/sheet-verification.sandbox.ts (args go to vitest)
# pnpm db:sandbox avatar-e2e [args] the avatar worker (default mode: avatars + sweep) against the # pnpm db:sandbox avatar-e2e [args] (= pnpm e2e:avatar) the avatar worker (default mode: avatars + sweep) against the
# sandbox: a gateway on 127.0.0.1:$PORT_GATEWAY, the worker # sandbox: a gateway on 127.0.0.1:$PORT_GATEWAY, the worker
# container, then tests/e2e/avatar-flow.e2e.ts (args go to vitest) # container, then tests/e2e/avatar-flow.e2e.ts (args go to vitest)
# pnpm db:sandbox sql psql as postgres on stdin # pnpm db:sandbox sql psql as postgres on stdin
@@ -62,6 +62,7 @@ load_secrets() {
[ -f "$SECRETS" ] || die "not running (pnpm db:sandbox up fresh)" [ -f "$SECRETS" ] || die "not running (pnpm db:sandbox up fresh)"
. "$SECRETS" . "$SECRETS"
[ -n "${SB_PW:-}" ] && [ -n "${SB_JWT_SECRET:-}" ] && [ -n "${SB_ANON_KEY:-}" ] && [ -n "${SB_SERVICE_KEY:-}" ] \ [ -n "${SB_PW:-}" ] && [ -n "${SB_JWT_SECRET:-}" ] && [ -n "${SB_ANON_KEY:-}" ] && [ -n "${SB_SERVICE_KEY:-}" ] \
&& [ -n "${SB_SEED_PW:-}" ] \
|| die "secrets file incomplete (pnpm db:sandbox down, then up)" || die "secrets file incomplete (pnpm db:sandbox down, then up)"
export PGPASSWORD="$SB_PW" export PGPASSWORD="$SB_PW"
} }
@@ -87,6 +88,7 @@ new_secrets() {
return h + "." + b + "." + c.createHmac("sha256", secret).update(h + "." + b).digest("base64url"); }; return h + "." + b + "." + c.createHmac("sha256", secret).update(h + "." + b).digest("base64url"); };
const exp = Math.floor(Date.now() / 1000) + 30 * 86400; const exp = Math.floor(Date.now() / 1000) + 30 * 86400;
console.log("SB_PW=" + c.randomBytes(24).toString("hex")); console.log("SB_PW=" + c.randomBytes(24).toString("hex"));
console.log("SB_SEED_PW=" + c.randomBytes(24).toString("hex"));
console.log("SB_JWT_SECRET=" + secret); console.log("SB_JWT_SECRET=" + secret);
console.log("SB_ANON_KEY=" + jwt({ role: "anon", iss: "db-sandbox", exp })); console.log("SB_ANON_KEY=" + jwt({ role: "anon", iss: "db-sandbox", exp }));
console.log("SB_SERVICE_KEY=" + jwt({ role: "service_role", iss: "db-sandbox", exp })); console.log("SB_SERVICE_KEY=" + jwt({ role: "service_role", iss: "db-sandbox", exp }));
@@ -189,6 +191,18 @@ gotrue_accounts() {
--data-binary @- >/dev/null --data-binary @- >/dev/null
} }
# The seed gives its accounts the DEV password (supabase/seed.sql); the sandbox
# replaces it at once by this session's secret, through GoTrue, body on stdin.
seed_passwords() {
local id
for id in $(sb_psql -t -A -c "select id from auth.users where email like '%@faunosteo.local'"); do
[[ "$id" =~ ^[0-9a-f-]{36}$ ]] || die "unexpected seed account id"
printf '{"password":"%s"}' "$SB_SEED_PW" \
| curl -fsS -X PUT "http://127.0.0.1:$PORT_AUTH/admin/users/$id" \
-H @"$STATE/service-header" -H 'Content-Type: application/json' --data-binary @- >/dev/null
done
}
# A CLI workdir holding only the migrations before <version>; kept in the # A CLI workdir holding only the migrations before <version>; kept in the
# state folder and refilled at each run (the CLI writes .temp there). # state folder and refilled at each run (the CLI writes .temp there).
upgrade_workdir() { # version upgrade_workdir() { # version
@@ -218,10 +232,10 @@ cmd_up() {
start_services start_services
case "$mode" in case "$mode" in
fresh) fresh)
migrate_up . ; seed ;; migrate_up . ; seed; seed_passwords ;;
upgrade) upgrade)
migrate_up "$(upgrade_workdir "$2")" migrate_up "$(upgrade_workdir "$2")"
seed; gotrue_accounts seed; seed_passwords; gotrue_accounts
echo "== before: $(sb_psql -t -A -c 'select count(*) from public.profiles') profiles" echo "== before: $(sb_psql -t -A -c 'select count(*) from public.profiles') profiles"
if [ -n "${3:-}" ]; then if [ -n "${3:-}" ]; then
migrate_up "$(upgrade_workdir "$3")" migrate_up "$(upgrade_workdir "$3")"
@@ -242,7 +256,7 @@ cmd_down() {
# A test runner gets the endpoints and keys through its environment, never argv. # A test runner gets the endpoints and keys through its environment, never argv.
with_sandbox_env() ( with_sandbox_env() (
export SANDBOX_DB_CONTAINER="$DB" SANDBOX_PG_PASSWORD="$SB_PW" export SANDBOX_DB_CONTAINER="$DB" SANDBOX_PG_PASSWORD="$SB_PW" SANDBOX_SEED_PASSWORD="$SB_SEED_PW"
export SANDBOX_AUTH_URL="http://127.0.0.1:$PORT_AUTH" SANDBOX_REST_URL="http://127.0.0.1:$PORT_REST" export SANDBOX_AUTH_URL="http://127.0.0.1:$PORT_AUTH" SANDBOX_REST_URL="http://127.0.0.1:$PORT_REST"
export SANDBOX_STORAGE_URL="http://127.0.0.1:$PORT_STORAGE" SANDBOX_MAIL_URL="http://127.0.0.1:$PORT_MAIL" export SANDBOX_STORAGE_URL="http://127.0.0.1:$PORT_STORAGE" SANDBOX_MAIL_URL="http://127.0.0.1:$PORT_MAIL"
export SANDBOX_ANON_KEY="$SB_ANON_KEY" SANDBOX_SERVICE_KEY="$SB_SERVICE_KEY" export SANDBOX_ANON_KEY="$SB_ANON_KEY" SANDBOX_SERVICE_KEY="$SB_SERVICE_KEY"
@@ -322,11 +336,17 @@ cmd_verify_e2e() {
} }
# The avatar suite drives supabase-js through the gateway's loopback port; its # The avatar suite drives supabase-js through the gateway's loopback port; its
# psql calls name the sandbox database container, which it requires. # psql calls name the sandbox database container. The suite accepts no other
# target, and a port already taken stops the run before anything starts.
cmd_avatar_e2e() { cmd_avatar_e2e() {
worker_preflight "$AVATAR_WORKER" worker_preflight "$AVATAR_WORKER"
if (exec 3<>"/dev/tcp/127.0.0.1/$PORT_GATEWAY") 2>/dev/null; then
die "port 127.0.0.1:$PORT_GATEWAY is already in use: free it, nothing was started"
fi
trap 'worker_cleanup "$AVATAR_WORKER"' EXIT trap 'worker_cleanup "$AVATAR_WORKER"' EXIT
start_gateway -p 127.0.0.1:$PORT_GATEWAY:8000 start_gateway -p 127.0.0.1:$PORT_GATEWAY:8000
[ "$(docker port "$GATEWAY" 8000/tcp)" = "127.0.0.1:$PORT_GATEWAY" ] \
|| die "the gateway is not published on 127.0.0.1:$PORT_GATEWAY only"
start_worker "$AVATAR_WORKER" sandbox-avatar 512m \ start_worker "$AVATAR_WORKER" sandbox-avatar 512m \
$'WORKER_SWEEP_SECONDS=5\nWORKER_QUARANTINE_GRACE_SECONDS=0\n' run $'WORKER_SWEEP_SECONDS=5\nWORKER_QUARANTINE_GRACE_SECONDS=0\n' run
SUPABASE_URL="http://127.0.0.1:$PORT_GATEWAY" SUPABASE_ANON_KEY="$SB_ANON_KEY" \ SUPABASE_URL="http://127.0.0.1:$PORT_GATEWAY" SUPABASE_ANON_KEY="$SB_ANON_KEY" \
+1 -1
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck shell=bash # shellcheck shell=bash
# The one place the DEV origin is decided (docs/development/ENVIRONMENTS.md §2). # The one place the DEV origin is decided (docs/development/ENVIRONMENTS.md §2).
# Sourced by the wrappers (scripts/supabase.sh, scripts/dev.sh, scripts/avatar-e2e.sh): # Sourced by the wrappers (scripts/supabase.sh, scripts/dev.sh, scripts/db-sandbox.sh):
# every service the browser of another device must reach is addressed by the # every service the browser of another device must reach is addressed by the
# host's LAN address, never by 127.0.0.1 or localhost. # host's LAN address, never by 127.0.0.1 or localhost.
# #