Skip to content

fix(test): rewrite Canvas.test.tsx — resolves @variscout/ui vitest hang#206

Merged
jukka-matti merged 4 commits into
mainfrom
fix/canvas-test-quarantine-vitest-hang
May 25, 2026
Merged

fix(test): rewrite Canvas.test.tsx — resolves @variscout/ui vitest hang#206
jukka-matti merged 4 commits into
mainfrom
fix/canvas-test-quarantine-vitest-hang

Conversation

@jukka-matti
Copy link
Copy Markdown
Owner

@jukka-matti jukka-matti commented May 25, 2026

Summary

Resolves the @variscout/ui vitest module-init hang that was blocking scripts/pr-ready-check.sh. Wholesale-rewrote packages/ui/src/components/Canvas/__tests__/Canvas.test.tsx (1500 lines → ~582 lines), removing the describe.skip quarantine that landed earlier on this branch (7c1baff1). Also retires one pre-existing Math.random lint error in findingsStore.test.ts that was previously masked by the hang.

Actual root cause (now diagnosed)

The legacy Canvas.test.tsx imported the real @variscout/hooks package. Its transitive graph — useCanvasViewportInput, useCanvasHypothesisDrawing, useCanvasKeyboard, useChipDragAndDrop, useHypothesisDrawTool, useSharedWallProps, useEvidenceMapData, plus the lens/overlay registries — deadlocks vitest's mock resolution during module init. Sibling CanvasWorkspace.test.tsx mocks the entire @variscout/hooks package (~365-line vi.mock factory) and runs cleanly in seconds. The fresh file copies that mock structure exactly and unhangs instantly.

Earlier session hypothesis (importOriginal for @variscout/charts) was verified insufficient — file still hung at 240s after that change. The hooks-package mock was the missing piece.

Coverage scope (intentionally focused)

Most behavior is already covered:

  • 3 response-path CTAs (render / click / hide-on-no-handler) → packages/ui/src/components/Canvas/internal/__tests__/CanvasStepOverlay.test.tsx (unit)
  • Workspace integration of step-overlay callbacks → CanvasWorkspace.test.tsx:1093

The fresh file tests Canvas-direct concerns only (6 tests):

  • Smoke render with empty map
  • L2 step cards render for a map with steps
  • Step-click opens overlay with all 3 wedge-V1 response-path CTAs (Quick action / Focused investigation / Charter, per wedge spec §3.3.4)
  • Charter callback fires with stepId on CTA click
  • Charter CTA is hidden (not disabled) when handler absent (per responsePathCta.ts "hide, don't tease")
  • Mobile Wall shortcut button visibility + click

Verification

  • Isolated: pnpm --filter @variscout/ui test -- --run Canvas.test.tsx — 6/6 passing in 3.19s
  • Full @variscout/ui suite: 223 files / 2140 tests in 86.59s (down from 117s baseline with quarantine)
  • bash scripts/pr-ready-check.sh — green end-to-end
  • Opus code reviewer (feature-dev:code-reviewer) — READY TO MERGE, zero blockers

Test plan

  • Full @variscout/ui suite terminates and passes
  • scripts/pr-ready-check.sh end-to-end green
  • Investigation entry promoted [QUARANTINED 2026-05-25] → [RESOLVED 2026-05-25] with the actual root cause
  • feedback_pr_ready_check_vitest_hang memory updated with the durable lesson ("mirror CanvasWorkspace.test.tsx's hooks mock from the start for Canvas-shaped test files")

Commits

  • 7c1baff1 fix(test): quarantine Canvas.test.tsx — vitest module-init hang blocks pr-ready-check
  • bd5e4951 fix(test): retire Math.random in findingsStore.test.ts — pre-existing P5 lint error
  • 5ee56f10 fix(test): rewrite Canvas.test.tsx — resolves @variscout/ui vitest hang
  • a7cdecba docs(test): note why draw/keyboard mocks are stubs (reviewer nit)

🤖 Generated with Claude Code

jukka-matti and others added 2 commits May 25, 2026 11:11
…s pr-ready-check

Bisected `@variscout/ui` vitest full-suite hang to a single file:
`packages/ui/src/components/Canvas/__tests__/Canvas.test.tsx` (50 tests).
Verbose reporter shows WallCanvas.test.tsx (alphabetically adjacent via
positional `Canvas.test` substring match) completing all 36 tests, then
total silence — no test inside Canvas.test.tsx ever reports starting.
Points to a module-init / mock-resolution deadlock rather than a single
failing test, consistent with the original microtask-recursion signature.

Quarantined via `describe.skip` with `TODO(inv-vitest-hang)` link back
to the investigation card. `pnpm --filter @variscout/ui test -- --run`
now completes in ~117s (222 passed, 1 file skipped, 51 tests skipped);
`scripts/pr-ready-check.sh` reliable again.

Investigation card `docs/ephemeral/investigations.md` updated with
[QUARANTINED 2026-05-25] marker + full bisect log (7 iterations).
Root-cause diagnosis deferred — 50 tests of Canvas integration coverage
are dark until the underlying flake is fixed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
… P5 lint error

Surfaced once the Canvas.test.tsx hang fix re-enabled scripts/pr-ready-check.sh
end-to-end. Pre-existing since 2026-03-30 (commit 50212ed); was previously
masked by the vitest hang failing before the lint step ran.

ESLint rule (no-restricted-syntax, added in PR #198) requires deterministic
test IDs. Replaced with a module-level counter — strictly deterministic, no
PRNG state, no need for a beforeEach reset since tests don't assert on IDs.

With this fix, scripts/pr-ready-check.sh passes end-to-end on the branch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 25, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mean-beoynd-lite-pwa Ready Ready Preview, Comment May 25, 2026 4:34pm
variscout_website Ready Ready Preview, Comment May 25, 2026 4:34pm

Wholesale-rewrote `packages/ui/src/components/Canvas/__tests__/Canvas.test.tsx`
(1500 lines → ~575 lines). Removes the `describe.skip` quarantine from
commit 7c1baff.

Actual root cause of the hang (now diagnosed): the legacy file imported the
real `@variscout/hooks` package. Its transitive graph — `useCanvasViewportInput`,
`useCanvasHypothesisDrawing`, `useCanvasKeyboard`, `useChipDragAndDrop`,
`useHypothesisDrawTool`, `useSharedWallProps`, `useEvidenceMapData`, plus the
lens/overlay registries — deadlocks vitest's mock-resolution during module init.
Sibling `CanvasWorkspace.test.tsx` mocks the entire `@variscout/hooks` package
(~365-line `vi.mock` factory) and runs cleanly. The fresh file copies that
exact mock structure and unhangs instantly.

Earlier hypothesis (importOriginal pattern for `@variscout/charts`) was
verified insufficient — file still hung at 240s after that change. The hooks
package mock was the missing piece.

Coverage scope is intentionally focused — most behavior is already covered:
- 3 response-path CTAs render/click/hide-on-no-handler: covered by
  `internal/__tests__/CanvasStepOverlay.test.tsx` (unit)
- Workspace integration of step-overlay callbacks: covered by
  `CanvasWorkspace.test.tsx:1093`
The fresh file tests Canvas-direct surface only: smoke render, L2 step cards,
step-click → 3 wedge-V1 response-path CTAs (Quick action / Focused
investigation / Charter — per wedge spec §3.3.4), Charter callback fires
with stepId, Charter hides when handler absent (per `responsePathCta.ts`
"hide, don't tease" rule), mobile Wall-shortcut visibility + click.

Verification:
- Isolated: 6/6 passing in 3.19s
- Full @variscout/ui suite: 223 files / 2140 tests in 86.59s (down from
  117s baseline with quarantine)
- `bash scripts/pr-ready-check.sh`: green end-to-end

Investigation card `docs/ephemeral/investigations.md` updated:
[QUARANTINED 2026-05-25] → [RESOLVED 2026-05-25] with the actual root cause
and verification numbers.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Opus reviewer pointed out that future contributors adding hypothesis
drawing or canvas keyboard coverage will hit confusion: the new file
no-op-stubs `useHypothesisDrawTool` / `useCanvasKeyboard` /
`useCanvasHypothesisDrawing`, but the sibling `CanvasWorkspace.test.tsx`
provides full stateful implementations for the same hooks. Documented
this in the file header so the "copy from CanvasWorkspace.test.tsx"
breadcrumb is visible at the point of confusion.

No behavior change — comment-only.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jukka-matti jukka-matti changed the title fix(test): quarantine Canvas.test.tsx vitest hang + retire pre-existing Math.random fix(test): rewrite Canvas.test.tsx — resolves @variscout/ui vitest hang May 25, 2026
@jukka-matti jukka-matti merged commit 8fed26b into main May 25, 2026
3 checks passed
@jukka-matti jukka-matti deleted the fix/canvas-test-quarantine-vitest-hang branch May 25, 2026 16:34
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