Skip to content

feat(dashboard): testable batch panel — extract to ES module + Vitest#68

Merged
silversurfer562 merged 4 commits into
mainfrom
feat/dashboard-js-testing
Jun 17, 2026
Merged

feat(dashboard): testable batch panel — extract to ES module + Vitest#68
silversurfer562 merged 4 commits into
mainfrom
feat/dashboard-js-testing

Conversation

@silversurfer562

Copy link
Copy Markdown
Member

Makes the Cowork dashboard's interactive JS testable without a build step, and applies the pattern to the batch-status panel shipped in #67. Full spec (Phase 1–3, approved) is included in specs/dashboard-js-testing/.

Problem

The dashboard's logic lives as 8 inline <script> blocks in Jinja templates — structurally untestable. The editor-frontend is well-covered by Vitest; the dashboard had zero frontend tests (standing tech.md debt). The batch panel from #67 had a non-trivial client state machine verified only by hand.

Approach (no build step)

  • static_cw/batch-panel.js — pure isTerminal / batchView / shouldClose, DOM-free. Loads as a native ES module in the browser (<script type="module">); imports directly in Node for Vitest (no jsdom, no bundler). Logic lifted verbatim from the former inline IIFE.
  • static_cw/batch-panel.test.js — 7 cases incl. the reconnect-suppression invariant (shouldClose must stay open on non-terminal pending) and a divide-by-zero guard.
  • editor-frontend/vitest.config.ts — include ../sidecar/.../static_cw/**/*.test.js so the existing frontend (Vitest) CI job covers dashboard modules too. One project, no new node_modules/job/toolchain.
  • living_docs.html — inline panel script → a type="module" glue shim that imports the module and only touches the DOM. Behavior-preserving.
  • static_cw/README.md — the "testing dashboard JS" pattern, so the other 7 inline blocks can be migrated the same way (follow-on work).

Verification

  • Vitest: 107 passed (10 files) — 14 dashboard assertions + all 9 editor suites still collected/green (glob not narrowed).
  • Live: /cw-static/batch-panel.js → 200, /api/batch/status/stream → 200, batch-section hidden on no-batch, zero console errors — identical to pre-extraction.

Scope: only the batch panel. The other inline blocks follow the documented pattern in later PRs.

🤖 Generated with Claude Code

silversurfer562 and others added 4 commits June 14, 2026 19:35
Spec to make the Cowork dashboard's inline-template JS testable: extract
pure logic into no-build ES modules under static_cw/, cover with the
existing Vitest harness (currently scoped to editor-frontend only), and
wire a root-level CI job. Batch panel (attune-gui#67) is the reference
implementation; remaining 7 inline script blocks follow incrementally.

Decisions baked in (overridable at review): plain ES modules / no build
step; pure-logic-first test depth; batch-panel-as-reference scope.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Pattern: pure logic → plain ES module in static_cw/ (served as-is, no
build); inline <script> shrinks to a DOM-glue shim that imports it;
Vitest tests the pure module directly.

Test runner: extend editor-frontend's existing Vitest project to include
../sidecar/.../static_cw/**/*.test.js (reuses the green frontend CI job,
no new node_modules/toolchain) — chosen over a separate root project.

Also corrects a Phase 1 inaccuracy: there is NO root package.json;
vitest lives only in editor-frontend.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
8 ordered tasks: extract batch-panel pure logic to a no-build ES module,
7 Vitest cases, extend editor-frontend's include glob, rewrite the inline
panel as a type=module glue shim, verify (vitest + live), pattern doc.
Phases 1-3 all approved 2026-06-14.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Make the Living Docs batch-progress panel's logic testable without a
build step (specs/dashboard-js-testing):

- static_cw/batch-panel.js — pure isTerminal / batchView / shouldClose,
  DOM-free (loads as a native ES module in the browser, imports in Node
  for Vitest). Logic lifted verbatim from the former inline IIFE.
- static_cw/batch-panel.test.js — 7 cases incl. the reconnect-suppression
  invariant and a divide-by-zero guard.
- editor-frontend/vitest.config.ts — include static_cw/**/*.test.js so the
  existing frontend (Vitest) CI job covers dashboard modules too (one
  project, no new node_modules/job).
- living_docs.html — inline panel script becomes a <script type="module">
  glue shim that imports the module; behavior-preserving.
- static_cw/README.md — the "testing dashboard JS" pattern for migrating
  the remaining inline blocks.

Vitest: 107 passed (editor + dashboard). Verified live: module 200, SSE
200, panel hidden on no-batch, no console errors — identical to before.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@silversurfer562 silversurfer562 merged commit b22de54 into main Jun 17, 2026
6 checks passed
@silversurfer562 silversurfer562 deleted the feat/dashboard-js-testing branch June 17, 2026 11:13
silversurfer562 added a commit that referenced this pull request Jun 17, 2026
Phases 1-3 approved 2026-06-14. Extract shouldKeepPolling + POLL_INTERVAL_MS
to a tested static_cw module; convert the poller block to type=module glue.
Stacks on #68 for the static_cw infra + Vitest glob.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
silversurfer562 added a commit that referenced this pull request Jun 17, 2026
Apply the dashboard-js-testing pattern to the Living Docs poller
(specs/living-docs-poller-testing):

- static_cw/living-docs-poller.js — pure shouldKeepPolling(rows) +
  POLL_INTERVAL_MS, DOM/timer-free; defensive over non-array / missing
  computed_state.
- static_cw/living-docs-poller.test.js — 6 cases (stop/continue/empty/
  defensive + cadence constant).
- living_docs.html — poller <script> becomes <script type="module">
  importing the module; inline .some(...) → shouldKeepPolling, 1500 →
  POLL_INTERVAL_MS. All timer/DOM/visibility glue unchanged.

Vitest: 113 passed (poller + batch-panel + editor). Verified live: module
200, page intact, batch SSE still 200, no console errors — behavior
identical. Stacks on #68.

Badge/action map de-dup remains a separate deferred spec.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
silversurfer562 added a commit that referenced this pull request Jun 17, 2026
* docs(specs): living-docs-poller-testing — Phase 1 requirements (draft)

Follow-on to dashboard-js-testing. Scope: extract + Vitest-test the
Living Docs poll state machine (shouldKeepPolling / scheduling) using the
approved no-build ES-module pattern. Behavior-preserving; no API change.

The Jinja↔JS badge/action mapping duplication is noted but explicitly
deferred to its own follow-up spec (needs an API-payload decision).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* docs(specs): living-docs-poller-testing — design + tasks (approved)

Phases 1-3 approved 2026-06-14. Extract shouldKeepPolling + POLL_INTERVAL_MS
to a tested static_cw module; convert the poller block to type=module glue.
Stacks on #68 for the static_cw infra + Vitest glob.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* feat(dashboard): extract Living Docs poll decision to a tested module

Apply the dashboard-js-testing pattern to the Living Docs poller
(specs/living-docs-poller-testing):

- static_cw/living-docs-poller.js — pure shouldKeepPolling(rows) +
  POLL_INTERVAL_MS, DOM/timer-free; defensive over non-array / missing
  computed_state.
- static_cw/living-docs-poller.test.js — 6 cases (stop/continue/empty/
  defensive + cadence constant).
- living_docs.html — poller <script> becomes <script type="module">
  importing the module; inline .some(...) → shouldKeepPolling, 1500 →
  POLL_INTERVAL_MS. All timer/DOM/visibility glue unchanged.

Vitest: 113 passed (poller + batch-panel + editor). Verified live: module
200, page intact, batch SSE still 200, no console errors — behavior
identical. Stacks on #68.

Badge/action map de-dup remains a separate deferred spec.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

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