feat(demo-app): demo.sonicjs.com app with auto-reseed#986
Open
lane711 wants to merge 2 commits into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
New workspace app for the public demo at demo.sonicjs.com. Always runs the latest
mainand 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
blog_post,page,testimonial,faq— plus sample content and SVG media assets seeded to R2.admin@sonicjs.com/sonicjs!via thedemo-loginplugin, hard-gated toENVIRONMENT=demo.demo-seedplugin exposesPOST /__demo/reseed(bearer-token + env gated) and a0 */2 * * *cron, both sharing onerunReseed(full wipe-all → R2 purge → seed types/media/content → re-activate login)..github/workflows/deploy-demo.yml: on push tomain, build core → type-check → reseed integration test → migrate → deploy → seed admin → reseed.npm run seed:demo(getPlatformProxy →runReseed).Tests
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 exactroutes/auth.tsdemo-login gate query. Runs in CI before deploy.tests/e2e/82-demo-seed.spec.ts— credential prefill, seeded public API, reseed-endpoint auth (skipped unlessDEMO_BASE_URLis set).This integration test caught a real bug:
ensureTypesseeded the 4 collectiondocument_typeswithsource:'user', which violates thedocument_typesCHECK (code|plugin|system) —INSERT OR IGNOREsilently dropped the rows. Masked in production (bootstrap registers the types first) but broke the fresh-DB fallback. Fixed tosource:'system'.Core changes (outside demo-app)
routes/auth.ts— the demo-login gate queried apluginstable 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— exportMediaDocumentService+MediaUploadMetaso the demo seed can upload media through the document model.Before first deploy (operator)
Fill
REPLACE_WITH_*D1/KV ids indemo-app/wrangler.toml;wrangler secret put BETTER_AUTH_SECRET DEMO_SEED_TOKEN; addCLOUDFLARE_API_TOKEN/CLOUDFLARE_ACCOUNT_ID/DEMO_SEED_TOKENto GitHub Actions secrets. Steps indemo-app/README.md.🤖 Generated with Claude Code