Skip to content

Audit: testable cube logic, renderer optimization, PWA cache fix - #1

Merged
oc-RAM merged 3 commits into
mainfrom
claude/audit-optimize-unj0ty
Jul 10, 2026
Merged

Audit: testable cube logic, renderer optimization, PWA cache fix#1
oc-RAM merged 3 commits into
mainfrom
claude/audit-optimize-unj0ty

Conversation

@oc-RAM

@oc-RAM oc-RAM commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Overview

An audit / test / optimize pass on the CubeFlow trainer. The app keeps its zero-build, browser-only deployment model — the only new dependency (cube.js engine + Node test runner) is dev-only and gitignored.

Changes

🐛 Service worker never updated returning users

Same-origin app assets (app.js, styles.css, cube-renderer.js) were served cache-first against a static cache version, so any deploy after a visitor's first load would never reach them. Switched same-origin assets to stale-while-revalidate, precached the new logic module, bumped the cache version, and kept cache-first for immutable CDN libraries.

⚡ Renderer performance

  • The cube fully rebuilds after every move; it was cloning the shell geometry, shell material, and sticker geometry for all 26 cubelets on every rebuild. These immutable resources are now shared, so a move only allocates the 54 per-sticker materials it needs.
  • Replaced the always-on 60 fps requestAnimationFrame loop (which rendered forever even on a completely idle cube) with on-demand rendering — frames draw only when the view changes or OrbitControls damping is still settling.

🧪 Testability + tests (there were none)

  • Extracted the pure cube-state logic (validation, parity, scramble, move helpers) into src/cube-logic.js — no DOM/Three.js deps. app.js now maps machine-readable validation codes to its user-facing copy.
  • Added a node:test suite (test/cube-logic.test.mjs, 13 tests) covering count/center/corner-twist/edge-flip/parity validation, scramble well-formedness + determinism, and move-inversion round-trips.

📄 Tooling & docs

  • Added the GitHub Pages workflow the README already referenced (.github/workflows/pages.yml) — runs tests, then deploys the static site.
  • Updated README architecture + added a Tests section; added .gitignore for node_modules.

Verification

  • 13/13 unit tests pass (npm test).
  • Headless-Chromium smoke test of the refactored renderer (Three.js served locally, since the CDN is unreachable in the build env): modules load, 26 cubelets / 54 stickers build, validation works, a move animates end-to-end with a clean rebuild, and WebGL draws non-blank pixels — zero page errors.

Not included (deliberately)

The app still loads Three.js and cube.js from jsDelivr at runtime. Vendoring them into assets/vendor/ (as the README suggests) would make the PWA fully offline and dependency-free, but adds ~1 MB of library files to the repo — left as a follow-up call.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XDijW82Hm9yCyUpntvaRRp


Generated by Claude Code

claude added 3 commits July 10, 2026 15:09
…hing

Refactor and tighten the CubeFlow trainer without changing its
zero-build, browser-only deployment model.

Testability
- Extract pure cube-state logic (validation, parity, scramble, move
  helpers) into src/cube-logic.js with no DOM/Three.js dependencies so
  it can run under Node. app.js now imports these and maps machine-
  readable validation codes to its user-facing copy.
- Add a node:test suite (test/cube-logic.test.mjs) and package.json dev
  tooling. Covers count/center/corner/edge/parity validation, scramble
  well-formedness, and move inversion round-trips.

Renderer performance
- Share the shell geometry, shell material, and sticker geometry across
  all cubelets instead of cloning them on every rebuild (each move
  rebuilds the cube), cutting per-move allocations sharply.
- Replace the always-on requestAnimationFrame loop with on-demand
  rendering: frames are drawn only when the view changes or damping is
  still settling, so an idle cube no longer renders 60fps forever.

PWA reliability
- Service worker now uses stale-while-revalidate for same-origin assets
  so deployments reach returning visitors, precaches the new logic
  module, and keeps cache-first for immutable CDN libraries.

Tooling and docs
- Add the GitHub Pages workflow the README references (runs tests, then
  deploys the static site); update README architecture and add a Tests
  section; ignore node_modules.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XDijW82Hm9yCyUpntvaRRp
The Pages workflow only triggered on push to main, so PRs had zero CI
signal before merge. Split into a test.yml that runs on every PR and
push, and keep pages.yml focused on deploying main (it still runs the
test suite as a pre-deploy gate).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XDijW82Hm9yCyUpntvaRRp
Several elements (canvas-fallback, solve-empty, secondary-button/install
-button, cube-canvas) set `display` unconditionally in a normal-priority
author rule, which always wins over the user-agent stylesheet's
`[hidden] { display: none }` regardless of specificity. This made the
"3D view unavailable" fallback panel render on top of the working 3D
canvas on every single page load for every visitor, independent of
browser, WebGL, or CDN availability — reported as a live bug on GitHub
Pages and confirmed via DevTools (fallback.hidden was true, WebGL was
hardware-accelerated, and the Three.js/cube.js CDN requests returned
200, yet the panel stayed visible).

Add a single global `[hidden] { display: none !important; }` rule so
the native hidden attribute works everywhere, instead of patching each
affected selector individually.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XDijW82Hm9yCyUpntvaRRp
@oc-RAM
oc-RAM merged commit cb68bf1 into main Jul 10, 2026
1 check passed
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