feat(dashboard): testable batch panel — extract to ES module + Vitest#68
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 (standingtech.mddebt). 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— pureisTerminal/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 (shouldClosemust stay open on non-terminal pending) and a divide-by-zero guard.editor-frontend/vitest.config.ts— include../sidecar/.../static_cw/**/*.test.jsso the existingfrontend (Vitest)CI job covers dashboard modules too. One project, no newnode_modules/job/toolchain.living_docs.html— inline panel script → atype="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
/cw-static/batch-panel.js→ 200,/api/batch/status/stream→ 200,batch-sectionhidden 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