Skip to content

feat(demo-app): demo.sonicjs.com app with auto-reseed#986

Open
lane711 wants to merge 2 commits into
mainfrom
lane711/demo-app-seed-plan
Open

feat(demo-app): demo.sonicjs.com app with auto-reseed#986
lane711 wants to merge 2 commits into
mainfrom
lane711/demo-app-seed-plan

Conversation

@lane711

@lane711 lane711 commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

New workspace app for the public demo at demo.sonicjs.com. Always runs the latest main and wipes + reseeds its data on every deploy and every 2 hours, so visitors can freely edit content, upload media, and explore the admin without permanently changing anything.

What's included

  • 4 code-defined collections (no DB tables): blog_post, page, testimonial, faq — plus sample content and SVG media assets seeded to R2.
  • Demo-login prefill — login page pre-fills admin@sonicjs.com / sonicjs! via the demo-login plugin, hard-gated to ENVIRONMENT=demo.
  • Reset machinerydemo-seed plugin exposes POST /__demo/reseed (bearer-token + env gated) and a 0 */2 * * * cron, both sharing one runReseed (full wipe-all → R2 purge → seed types/media/content → re-activate login).
  • CI.github/workflows/deploy-demo.yml: on push to main, build core → type-check → reseed integration test → migrate → deploy → seed admin → reseed.
  • Localnpm run seed:demo (getPlatformProxy → runReseed).

Tests

  • Real-DB integration demo-app/src/plugins/demo-seed/__tests__/reseed.sqlite.test.ts — better-sqlite3 D1 shim + in-memory R2 stub; asserts summary counts, published-on-create, q_media_* generated columns, full-reset idempotency, and the exact routes/auth.ts demo-login gate query. Runs in CI before deploy.
  • E2E tests/e2e/82-demo-seed.spec.ts — credential prefill, seeded public API, reseed-endpoint auth (skipped unless DEMO_BASE_URL is set).

This integration test caught a real bug: ensureTypes seeded the 4 collection document_types with source:'user', which violates the document_types CHECK (code|plugin|system) — INSERT OR IGNORE silently dropped the rows. Masked in production (bootstrap registers the types first) but broke the fresh-DB fallback. Fixed to source:'system'.

Core changes (outside demo-app)

  • routes/auth.ts — the demo-login gate queried a plugins table that doesn't exist on greenfield (always threw → prefill permanently dead). Repointed at the document-model plugin status (type_id='plugin', data.status='active').
  • index.ts — export MediaDocumentService + MediaUploadMeta so the demo seed can upload media through the document model.

Before first deploy (operator)

Fill REPLACE_WITH_* D1/KV ids in demo-app/wrangler.toml; wrangler secret put BETTER_AUTH_SECRET DEMO_SEED_TOKEN; add CLOUDFLARE_API_TOKEN / CLOUDFLARE_ACCOUNT_ID / DEMO_SEED_TOKEN to GitHub Actions secrets. Steps in demo-app/README.md.

🤖 Generated with Claude Code

lane711 and others added 2 commits June 30, 2026 18:20
New workspace app for the public demo at demo.sonicjs.com. Always runs the
latest main and wipes + reseeds its data on every deploy and every 2 hours,
so visitors can freely edit content without permanently changing anything.

demo-app/:
- 4 code-defined collections (blog_post, page, testimonial, faq) plus sample
  content and SVG media seeded to R2
- demo-login prefill plugin (admin@sonicjs.com / sonicjs!), gated to
  ENVIRONMENT=demo
- demo-seed plugin: POST /__demo/reseed (bearer-token + env gated) and a
  "0 */2 * * *" cron, both sharing runReseed (full wipe-all -> R2 purge ->
  seed types/media/content -> re-activate login)
- scripts/seed-demo.ts for local reseed via getPlatformProxy
- README with operator provisioning + deploy steps

CI: .github/workflows/deploy-demo.yml — on push to main, builds core,
type-checks, applies D1 migrations, deploys, seeds admin, then reseeds.

E2E: tests/e2e/82-demo-seed.spec.ts (DEMO_BASE_URL-gated).

Core changes:
- routes/auth.ts: the demo-login gate queried a `plugins` table that does not
  exist on greenfield (always threw -> prefill permanently dead). Repoint at
  the document-model plugin status (type_id='plugin', data.status='active').
- index.ts: export MediaDocumentService + MediaUploadMeta so the demo seed can
  upload media through the document model.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add demo-app/src/plugins/demo-seed/__tests__/reseed.sqlite.test.ts — real
SQLite coverage for runReseed via core's better-sqlite3 D1 shim + an in-memory
R2 stub (closes the R10 gap; E2E 82 only covers the live path). Asserts summary
counts, published-on-create, q_media_* generated columns, full-reset idempotency
(second run wipes visitor edits and rebuilds 1:1), and the exact document row
routes/auth.ts gates the demo-login prefill on.

The test caught a real bug: ensureTypes seeded the 4 collection document_types
with source:'user', which violates the document_types CHECK
(source IN 'code','plugin','system'). INSERT OR IGNORE then silently dropped
those rows. Masked in production (bootstrap registers the types as 'system'
before reseed runs) but broke the fresh-DB fallback (local npm run seed:demo).
Fixed to source:'system', matching autoRegisterCollectionDocumentTypes.

- demo-app: add vitest devDep + test/test:watch scripts; exclude test files
  from the app tsc program (they are @ts-nocheck and run by vitest, and import
  core's shim from outside rootDir)
- CI: run npm test --workspace=demo-app before deploy in deploy-demo.yml

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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