Skip to content

fix(stats): login loop, telemetry, collection dashboard, auto-deploy - #1010

Open
lane711 wants to merge 8 commits into
mainfrom
lane711/stats-login-redirect-loop
Open

fix(stats): login loop, telemetry, collection dashboard, auto-deploy#1010
lane711 wants to merge 8 commits into
mainfrom
lane711/stats-login-redirect-loop

Conversation

@lane711

@lane711 lane711 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Fix login redirect loop on stats.sonicjs.com — add CACHE_KV KV binding to packages/stats/wrangler.toml (Better Auth requires it for session storage)
  • Fix installation_id always unknown — read from CACHE_KV ?? KV instead of missing KV binding
  • Add deploy_url (origin only) to project_snapshot telemetry
  • Stats dashboard: full collection list + custom collections panel (flat JSON scan of all snapshots, SYSTEM_COLLECTIONS exclusion set)
  • Stats dashboard: deployed sites table from deploy_url snapshots
  • Auto-deploy stats on every merge to main — remove paths filter from deploy workflow, bump to Node 22, npm install over npm ci

CI test fixes (25 failures → 0)

  • plugin-middleware.test.ts: call invalidatePluginStatusCache() in each beforeEach — module-level _pluginStatusCache Map was never cleared between tests
  • document-scalar-schema.ts: export resetScalarSchemaCache() — module-level _columnCache/_indexCache/_cacheInitPromise persisted across fresh :memory: DB instances
  • d1-sqlite.ts: call resetScalarSchemaCache() in createTestD1() so every fresh test DB starts with a clean PRAGMA cache
  • migrations-d45.test.ts: add beforeEach reset (creates own DB, not via createTestD1)
  • table-sorting.test.ts: fix broken import @sonicjs-cms/core/templates (unbuilt dist) → relative source path
  • catalog.ts: scheduleKvWrite accepts null | undefined ctx
  • api.ts: add tryCtx() helper to safely access c.executionCtx (throws in test environments without ExecutionContext) — fixes 500 in cache integration test

Test plan

  • CI passes on this PR
  • Login to stats.sonicjs.com succeeds and session persists
  • Stats dashboard shows collection list + custom collections panel
  • Future merges to main auto-deploy stats site

🤖 Generated with Claude Code

Without CACHE_KV, withCloudflare had kv=undefined — session writes
silently failed, causing a login-success → redirect → "please login"
loop on stats.sonicjs.com.

Reuses the shared KV namespace (a16f8246fc294d809c90b0fb2df6d363)
for both default and production envs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…anges

Removes the path filter so stats.sonicjs.com always runs the latest
version of @sonicjs-cms/core after any merge to main.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
wrangler >=4 requires Node >=22. Lock file was also out of sync with
current esbuild/emnapi versions; npm install resolves fresh rather
than failing on the stale lock file.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…oard

- Removes LIMIT 20 / slice(15) so all collections appear in the table
- Sorts by installations desc (most-adopted first) — chart still capped at top 20
- Adds "Custom Collections" side-by-side card: filters to installations = 1
  (user-defined collections unique to one install), sorted by doc count
- Both tables are scrollable (max-h-96) so the page doesn't balloon

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ding

bootstrap.ts read c.env.KV but the binding is named CACHE_KV in wrangler.toml.
KV was always undefined → installationId defaulted to 'unknown' on every
project_snapshot event, making per-installation analytics useless.

Falls back to c.env.KV for any deployment that uses the legacy name.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
SQL bug: HAVING created_at = MAX(created_at) picked collection_counts
arbitrarily (SQLite GROUP BY semantics) — most snapshot rows were silently
dropped. Now reads collection_names from every snapshot row directly.

Logic bug: "installations = 1" as the custom filter was wrong since all
existing snapshots carry installation_id='unknown', collapsing them all
into one fake installation. Replaced with a SYSTEM_COLLECTIONS exclusion
set (menu_item, plugin, plugin_activity, rbac_role, rbac_verb,
rbac_user_roles, content, media) — everything else is user-defined.

System collections shown dimmed with [sys] label in the All Collections
table so they're still visible but visually deprioritized.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Captures the scheme+host of the first cold-start request so the stats
dashboard can show which domains are running SonicJS. No path, query
string, or user data is collected — only the origin (e.g.
"https://example.com").

Dashboard adds a "Deployed Sites" table showing all unique origins +
snapshot counts. Hidden when no deploy_url data exists yet.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lane711 lane711 changed the title fix(stats): add CACHE_KV binding to fix login redirect loop fix(stats): login loop, telemetry, collection dashboard, auto-deploy Jul 24, 2026
- plugin-middleware.test.ts: call invalidatePluginStatusCache() in each
  beforeEach so module-level _pluginStatusCache is cleared between tests
- document-scalar-schema.ts: export resetScalarSchemaCache() to let test
  harnesses reset the per-isolate PRAGMA cache when a fresh DB is created
- d1-sqlite.ts: call resetScalarSchemaCache() in createTestD1() so each
  fresh :memory: DB starts with a clean column cache
- migrations-d45.test.ts: add beforeEach resetScalarSchemaCache() (test
  creates its own DB directly, not via createTestD1)
- table-sorting.test.ts: fix broken import from @sonicjs-cms/core/templates
  (unbuilt dist) → relative source path ../../templates/table.template
- catalog.ts: scheduleKvWrite accepts null/undefined ctx so route-level
  calls don't throw in environments without executionCtx
- api.ts: add tryCtx() helper that safely accesses c.executionCtx,
  replacing all 9 raw c.executionCtx args to scheduleKvWrite

Co-Authored-By: Claude Sonnet 4.6 <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