Skip to content

test(toolpath-desktop): vitest + unit tests for classify and flattenChatHead#45

Merged
eliothedeman merged 1 commit into
mainfrom
eliot/issue-40-frontend-vitest
Apr 22, 2026
Merged

test(toolpath-desktop): vitest + unit tests for classify and flattenChatHead#45
eliothedeman merged 1 commit into
mainfrom
eliot/issue-40-frontend-vitest

Conversation

@eliothedeman
Copy link
Copy Markdown
Collaborator

Summary

  • Wires up Vitest as the frontend unit-test runner (Node environment, bun run test / bun run test:watch). No jsdom — the two modules under test are pure TS.
  • Adds 5 tests for classify.ts covering the user / assistant / tool / system cases plus readStructural's preference for conversation-type payloads when multiple artifacts are present.
  • Adds 5 tests for flattenChatHead in tree.ts covering the linear HEAD chain, tool.invoke sibling attachment, non-tool-sibling filter, bare Step doc fallback, and detached-HEAD fallback.

Closes #40.

Test plan

  • bun run test — 10 / 10 passing.
  • bun run check — svelte-check stays green (pre-existing a11y warnings only).
  • bun run build — Vite production build succeeds.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 22, 2026

🔍 Preview deployed: https://5810d552.toolpath.pages.dev

Copy link
Copy Markdown
Collaborator Author

@eliothedeman eliothedeman left a comment

Choose a reason for hiding this comment

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

Summary

Covers all 10 tests named in #40 with minimal, readable fixtures. Tooling is cleanly wired, CI is green, no scope creep.

Notes

  • classify.test.ts:17-42 — all 4 classify cases (user/assistant/tool/system) present; fixtures use the correct flat wire shape ({ type, role, text }), which is exactly the shape the original bug misread.
  • classify.test.ts:45-62 — the readStructural multi-artifact test genuinely constructs a 2-artifact change map (file:///tmp/out.txt + tool://Edit) and asserts the tool payload wins. This is the regression the issue describes.
  • tree.test.ts:50-64 — linear chain test checks both id order and kind sequence, catching either ordering or classification regressions.
  • tree.test.ts:66-81 — tool.invoke sibling attachment test verifies s2.toolInvocations[0].id === "s3" AND that s3 is absent from the top-level list, which catches both prior bugs (missed splice, lost attachment).
  • tree.test.ts:83-94 — non-tool sibling filter correctly uses a user sibling and asserts toolInvocations === [].
  • tree.test.ts:96-115 — bare Step doc fallback and detached-HEAD fallback both present; the latter uses a literal "missing" head id, exactly the detached case.
  • vitest.config.ts:7environment: "node" with no jsdom (jsdom is only a transitive optional peer, not an install dep). Matches the issue's "pure TS" note.
  • package.json — adds test and test:watch scripts; only new devDep is vitest.
  • bun.lock — additions are vitest's own transitive deps (@vitest/*, chai, tinybench, etc.); no unrelated churn.
  • No Svelte component tests, no extra helpers beyond the three local fixture builders. Scope is tight.
  • gh pr checks 45 — both test and deploy pass.

Verdict

Comment (would approve, but can't self-approve). Tests map 1:1 to the issue, fixtures exercise the actual regressions (not just the happy paths), and the tooling additions are minimal. Safe to merge.

…tenChatHead

Regression coverage for two pure-TS modules added in #34 that hit real
bugs during development — both would have been caught by a ~20-line
test. Wires up Vitest as the frontend test runner (Node environment,
no jsdom needed for these pure-TS tests).

classify.ts: five cases covering user / assistant / tool / system
branches plus readStructural's preference for conversation-type
payloads over sibling file artifacts.

tree.ts: five cases covering flattenChatHead's HEAD-chain lineariser,
the tool.invoke sibling attachment, the non-tool-sibling filter, the
bare-Step fallback, and the detached-HEAD fallback.

Closes #40
@eliothedeman eliothedeman force-pushed the eliot/issue-40-frontend-vitest branch from 0c5c5c1 to 1ad44a5 Compare April 22, 2026 21:02
@eliothedeman eliothedeman merged commit 375e2b1 into main Apr 22, 2026
2 checks 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.

toolpath-desktop: add frontend unit tests for classify.ts + flattenChatHead

1 participant