Skip to content

test: 100% coverage, enforced in CI - #40

Merged
ProjectAJ14 merged 8 commits into
mainfrom
test/full-coverage
Nov 2, 2026
Merged

ProjectAJ14 merged 8 commits into
mainfrom
test/full-coverage

Conversation

@ProjectAJ14

@ProjectAJ14 ProjectAJ14 commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Coverage goes from 44% to 100%: statements, branches, functions and lines, across src/, server/, public/*.mjs and vite.pwa.config.ts. That is 2,415 tests in 160 files.
  • Enforced: npm test now runs with coverage and vite.config.ts sets 100% thresholds, so CI and pre-push fail on any uncovered line.
  • New Claude rule .claude/rules/test-coverage.md (loaded every session, with a pointer in CLAUDE.md): new code always ships at 100%, with no v8 ignore comments, plus how to handle an unreachable branch.
  • Slow-runner headroom: testTimeout is 20 s and user-event types without per-key delay, because one modal test passed the 5 s default on CI.

Bug fixes found along the way

Each fix has a regression test that fails on the old code.

  • fix(query): the automatic LIMIT was skipped when a string or comment contained LIMIT n, TOP n or FETCH FIRST, e.g. WHERE note = 'LIMIT 3'.
  • fix(ai): few-shot example matching missed schema-qualified quoted tables such as public."Orders" and [dbo].[Customers].
  • fix(settings): an empty analytics chart showed "peak 0 · Jan undefined".

Test setup

  • New dev dependencies: @vitest/coverage-v8, jsdom (pinned to ^29 because jsdom 30 needs Node 22 and CI runs Node 20), and @testing-library/{react,dom,user-event}.
  • Component tests: use renderUi from src/utils/dom.testing.tsx (Mantine, router and jsdom stubs). Monaco and AG Grid are replaced with fakes that record their props.
  • fireReactHandler (src/utils/react-handler.testing.ts) calls a disabled button's handler directly, so guards behind disabled buttons are tested instead of left uncovered.

Refactor: unreachable branches

About 120 lines were guards that no input could reach.

  • Where a test could force the case, it now does.
  • Truly dead fallbacks were removed, for example ?? "invalid" on a zod error, which always has a message.
  • WriteRequestDetail is split so its six if (!id) guards are no longer needed.
  • Write-path fallbacks are kept and tested. No validation, capability, masking or production-rail check changed.

Test plan

  • npm run verify and npm run build pass
  • An untested file makes npm test fail on the threshold
  • The three regression tests fail with each bug put back
  • Checked end to end on a local Postgres connection:
    • Query API: the auto LIMIT applies to a query with 'LIMIT 3' in a string; a real LIMIT 4 and the no-limit setting are unchanged.
    • Write request page: the verify SELECT runs and Duplicate prefills the composer.
    • Artifact: a SQL block runs.
    • Settings: the analytics charts and the add-user credentials pop-up render correctly.
    • Sidebar: the table tree loads.

🤖 Generated with Claude Code

FROM public."Orders" read as "" and JOIN [dbo].[Customers] as "dbo",
so saved queries written that way were never offered as AI examples.
applyDefaultLimit / applyDefaultLimitMssql looked for LIMIT n, TOP n and
FETCH FIRST in the raw SQL, so WHERE note = 'LIMIT 3' (or a comment)
skipped the automatic limit. Check the scanned text instead.
With no days of data BarChart fell back to an empty date and rendered
"peak 0 · Jan undefined". It now shows no peak until there is data.
Adds component tests (jsdom + Testing Library, renderUi in
src/utils/dom.testing.tsx) and fills the server, utils, store and
mcp-bridge gaps. npm test now runs with coverage and vite.config.ts sets
100% thresholds, so CI and pre-push fail on any uncovered line.
Fallbacks and guards that duplicate an earlier check (a disabled button,
an exhaustive validator, a value that always has a default) are deleted
where truly dead. Write-path fallbacks are kept and now tested. No
validation, capability, masking or production-rail check changes.
A connection-modal test typed past the 5 s default on CI. Type without
per-key delays and raise testTimeout to 20 s.
@ProjectAJ14
ProjectAJ14 merged commit 151df22 into main Nov 2, 2026
1 check passed
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 2.7.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant