Skip to content

feat(showcase): safe simulated uploads demo (#586, phase 5) - #673

Merged
LudoLoops merged 1 commit into
mainfrom
586-showcase-uploads
Oct 26, 2026
Merged

LudoLoops merged 1 commit into
mainfrom
586-showcase-uploads

Conversation

@LudoLoops

Copy link
Copy Markdown
Contributor

What changed and why

Phase 5 of #586. This module is the first whose real flow needs a backend (auth + S3/R2), so the demo deliberately shows the policy and the states, never the write. That required one small, honest refactor so the demo cannot drift from the server.

Shared upload policy (single source)

  • The MIME allowlist moved out of +server.ts into src/lib/uploads/policy.ts (isomorphic, SVG still deliberately excluded): ALLOWED_MIME_TYPES, MAX_FILE_SIZE, and validateUploadFile() returning the endpoint's own codes.
  • The endpoint now delegates type/size validation to it and keeps the exact HTTP contract: 400 for file_type_not_allowed/invalid_size, 413 for file_too_large. Field-presence errors stay server-side.
  • tests/upload-security.test.ts was adapted (not weakened): the SVG/XSS assertion and the "deliberately EXCLUDED" documentation now target the shared policy, and the test additionally requires the endpoint to delegate.

Demo /showcase/uploads (+page.svelte + meta.ts, order: 50)

  • file picker + drop zone → validation through the shared policy → Skeleton Progress during a simulated upload → success state with the file name/size and a clearly labelled simulated key;
  • rejected files show the module's own localized error copy (type / too large / invalid);
  • the page states that FileUpload.svelte is what posts to the authenticated endpoint and stores in S3/R2 — this page never does: no fetch, no storage, no credentials.

Contracts, docs, artifacts

  • @svforge/uploads now declares ui.svforge (the route uses the kit) alongside auth.currentUser + i18n.messages; canonical svforge-modules.json, MODULE_CONTRACTS, templates.ts, module-recipes.ts regenerated through prebuild.
  • README lists the five demos; skeleton-baseline.md records the new page (Skeleton Progress, shared policy, no custom CSS).

Tests and checks

  • New tests/uploads-policy.test.ts (behaviour, not class strings): accepts at the limit; rejects SVG/unknown types, oversized, empty/NaN/Infinity; asserts the endpoint imports the shared policy and keeps 400/413 semantics with no duplicated allowlist.
  • New tests/uploads-demo.test.ts (jsdom, rendered): allowed file → Skeleton progressbar (with aria-valuenow) then “Selection accepted” + simulated key; SVG → localized type error; oversized → localized size error; fetch is stubbed to throw and asserted never called.
  • tests/showcase.test.ts: uploads delivery on a dashboard fixture (route + metadata + both catalogs, key parity, module error copy preserved) + capability assertion; and a new compile guard for every showcase demo page (catches the Svelte-syntax class of error these phases hit twice).
  • bash scripts/test-scaffold.sh base and base-ui-modules → green (no regression; uploads is not installable on a plain Base by design).
  • bun run test → 146 files / 1453 tests passed; bun run lint clean; bun run typecheck clean; bun run build:all OK; graphify stable across repeat runs.
  • Harness: dashboard-integrations (the profile that installs uploads) now asserts the demo route, meta.ts and both catalogs.

Remaining limitations / known problems

  • dashboard-integrations was not executed locally: it needs a reachable PostgreSQL, which this environment does not provide. Its new assertions run in the publish/ecosystem-drift matrices, and the same install path is covered locally by the dashboard-fixture delivery test. This is the one gate I could not run myself.
  • No real S3 round-trip is tested anywhere by design: the module's own upload path is the module's responsibility (with its security test pack), and the demo is explicitly a simulation.
  • Canvas-free but pointer-first like the other demos: no browser automation (Playwright is not a repo dependency); behaviour is covered by the jsdom suite above.

Part of #586 — phase 5 only. Remaining demos: blog, notifications, chat, oauth, email, audit (jobs/realtime only with a meaningful simulation), each on its own branch.

Fifth module demo, and the first one that must NOT do what the module does:
uploading needs auth + S3, so the page demonstrates the policy and the
progress/success/error states locally instead of writing anything.

- Shared policy: the MIME allowlist moves out of the endpoint into
  `src/lib/uploads/policy.ts` (isomorphic, SVG still deliberately excluded),
  exposing `ALLOWED_MIME_TYPES`, `MAX_FILE_SIZE` and `validateUploadFile()`.
  The endpoint now delegates type/size validation to it and keeps the exact
  codes/statuses (400 for type/size, 413 for too large), so a client
  pre-check can never disagree with the server.
- `@svforge/uploads` ships `src/routes/showcase/uploads/+page.svelte` plus
  its `meta.ts` (order 50): file picker + drop zone, validation through the
  shared policy, the Skeleton `Progress` affordance during a simulated
  upload, a success state with the (clearly labelled) simulated key, the
  module's own localized error copy for rejected files, and a note that the
  real `FileUpload.svelte` is what posts to the authenticated endpoint. No
  request, no storage, no credentials.
- Catalog copy for the page merged into both locales; the module now declares
  `ui.svforge` alongside its auth/i18n requirements.
- Canonical `svforge-modules.json` / `MODULE_CONTRACTS` updated;
  `templates.ts` and `module-recipes.ts` regenerated through prebuild.
- Tests: new `uploads-policy` behaviour suite (allowed/oversized/empty/
  disallowed, endpoint delegation), a rendered jsdom suite for the demo
  (progress -> success, localized type/size errors, `fetch` never called),
  the showcase suite extended (delivery on a dashboard fixture, catalog
  parity, capability) plus a compile guard for EVERY showcase demo page.
- `tests/upload-security.test.ts` now asserts the SVG-exclusion comment and
  allowlist in the shared policy while requiring the endpoint to delegate.
- Harness: `dashboard-integrations` (the profile that installs uploads)
  asserts the demo route, metadata and both catalogs; `base` and
  `base-ui-modules` stay green.

Verification: full suite 146 files / 1453 tests; lint; typecheck; `base` and
`base-ui-modules` scaffold profiles; graphify stable. `dashboard-integrations`
needs PostgreSQL and was not run locally (its new assertions run in the
publish/drift matrices).

Changeset: `@svforge/uploads` minor, `svforge` patch, `@svforge/addon-kit` patch.
@LudoLoops
LudoLoops merged commit 3f98e79 into main Oct 26, 2026
3 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 26, 2026
@LudoLoops
LudoLoops deleted the 586-showcase-uploads branch October 26, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant