Skip to content

fix(docs): wire the savings leaderboard's Supabase anon key into the docs build#596

Open
jonsaadfalcon wants to merge 1 commit into
mainfrom
fix/docs-leaderboard-anon-key
Open

fix(docs): wire the savings leaderboard's Supabase anon key into the docs build#596
jonsaadfalcon wants to merge 1 commit into
mainfrom
fix/docs-leaderboard-anon-key

Conversation

@jonsaadfalcon

Copy link
Copy Markdown
Collaborator

Problem

The docs-site savings leaderboard (docs/javascripts/leaderboard.js) reads the public Supabase anon key from window.OPENJARVIS_SUPABASE_ANON_KEY, but nothing ever set that global. So the published leaderboard always shows "Leaderboard not configured yet." This is the docs half of the leaderboard wiring — the PyPI/desktop builds get the key via the VITE_SUPABASE_ANON_KEY build var (#588/#589), but the mkdocs site uses a separate window.* mechanism that was never connected.

Fix

Inject the key at docs-build time, mirroring the build-var approach:

  • docs/javascripts/leaderboard-config.js (new) — declares window.OPENJARVIS_SUPABASE_ANON_KEY, empty by default.
  • mkdocs.yml — load leaderboard-config.js before leaderboard.js so the global is set before it's read.
  • .github/workflows/docs.yml — before mkdocs build, regenerate the config file from the existing VITE_SUPABASE_ANON_KEY secret. The secret is read via env: (not inlined) and JSON-encoded into a JS string literal, so there's no injection surface.
  • tests/deployment/test_docs_leaderboard.py (new) — guards the load order and that the workflow injects the key.

The committed default is empty, so local mkdocs build and fork PRs (which have no secret) keep rendering the graceful "not configured" message. The anon key is public by design — Supabase Row-Level Security protects the data — so shipping it in the public docs bundle is expected.

Verification

  • Local mkdocs build with a simulated injected key: site/javascripts/leaderboard-config.js ships with the value, and the built HTML loads leaderboard-config.js before leaderboard.js.
  • The Supabase backend + an anon key were confirmed working separately (a direct GET /rest/v1/savings_entries returned live rows), so once this deploys, the docs leaderboard will populate.
  • tests/deployment/ — 25 passed (4 new); ruff clean.

🤖 Generated with Claude Code

…docs build

The docs-site leaderboard (docs/javascripts/leaderboard.js) reads the public
Supabase anon key from window.OPENJARVIS_SUPABASE_ANON_KEY, but nothing set it,
so the published leaderboard always rendered "Leaderboard not configured yet".

Add a generated config file (leaderboard-config.js) loaded before
leaderboard.js that supplies the global, and inject its value at docs-build
time from the existing VITE_SUPABASE_ANON_KEY repo secret. The committed
default is empty, so local `mkdocs build` and fork PRs (no secret) degrade
gracefully. The anon key is public by design (Supabase RLS protects the data).

- docs/javascripts/leaderboard-config.js: empty-default global declaration.
- mkdocs.yml: load leaderboard-config.js before leaderboard.js.
- docs.yml: write the config from the secret (read via env, JSON-encoded into a
  JS string literal to avoid injection) before `mkdocs build`.
- tests/deployment/test_docs_leaderboard.py: guard the wiring + load order.

Verified with a local `mkdocs build`: the generated config ships in site/ and
loads before leaderboard.js.

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