Skip to content

fix: counters/life-blocks broken due to missing Chart.js date adapter; dynamic rate; 22 milestones; E2E tests#16

Merged
nitrocode merged 2 commits into
mainfrom
copilot/fix-loading-tokens-issue
Apr 22, 2026
Merged

fix: counters/life-blocks broken due to missing Chart.js date adapter; dynamic rate; 22 milestones; E2E tests#16
nitrocode merged 2 commits into
mainfrom
copilot/fix-loading-tokens-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 22, 2026

initChart() threw an uncaught exception ("This method is not implemented: Check that a complete date adapter is provided") because Chart.js 4.x requires an explicit date adapter for type: 'time' axes. This crashed init() before initLifeBlocks() and requestAnimationFrame(updateCounters) could run — leaving the total counter on "Loading…", session tokens at 0, and life blocks blank.

Root fix — self-hosted Chart.js date adapter

New chart-date-adapter.js implements the full _adapters._date interface (no external deps, loaded from self). initChart() is also wrapped in try/catch so future chart failures can't cascade.

<!-- index.html load order -->
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.js" ...></script>
<script src="chart-date-adapter.js"></script>  <!-- new -->
<script src="script.js"></script>

Dynamic rate display

TOKENS_PER_SECOND was hardcoded in HTML and never updated. Added RATE_SCHEDULE (14 entries keyed to landmark AI events: ChatGPT launch, GPT-4, Claude 3 Opus, GPT-4o, Llama 3.1, DeepSeek R1, Claude Code GA, etc.) and getRateAtDate(date) to death-clock-core.js. The rate box is now updated every RAF cycle showing the current rate and the triggering event.

Milestones

Expanded from 7 → 22 milestones spanning 1 Trillion to 10 Quintillion tokens. New entries include near-term upcoming thresholds (Power Grid Strain, Arctic Ice-Free Summer, Wildfire Crisis, Permafrost Methane Bomb, Ocean Acidification Threshold, Jet Stream Collapse, etc.) and far-future collapse events.

DOM safety

With the last milestone at 10 Quintillion tokens (~1.2 M days away), lbRenderDays() would have created 1.2 million DOM elements. Capped at 3,650 blocks (~10 years) with a +Xy overflow indicator.

CSP

Added the Firefox-reported sha256-ZswfTY7H35rbv8WC7NXBoiC7WNu86vSzCDChNWwZZDM= hash to the script-src directive.

Tests

  • 110 Jest tests (up from 91): new suites for getRateAtDate, RATE_SCHEDULE invariants (monotonic dates/rates, required events present), and extended milestone checks (uniqueness, field presence, magnitude span).
  • 21 Playwright E2E tests (new in tests/e2e/): counter liveness, milestone card count/triggered state, life-block drill-down, chart canvas dimensions, theme toggle, XSS guard, zero uncaught JS errors.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file needed

@github-actions
Copy link
Copy Markdown
Contributor

👁️ PR Preview

🚀 Open Preview

Deployed from commit 0add16d · Updates on every push to this PR
(Preview is removed automatically when the PR is closed.)

@nitrocode nitrocode marked this pull request as ready for review April 22, 2026 07:48
@nitrocode nitrocode merged commit d821e2a into main Apr 22, 2026
3 checks passed
@nitrocode nitrocode deleted the copilot/fix-loading-tokens-issue branch April 22, 2026 07:48
github-actions Bot added a commit that referenced this pull request Apr 22, 2026
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.

2 participants