Skip to content

test: cover every tool handler and the stdio guard, coverage 88% → 99.7% - #163

Merged
mathieumaf merged 3 commits into
mainfrom
t3/improve-test-coverage
Dec 3, 2026
Merged

mathieumaf merged 3 commits into
mainfrom
t3/improve-test-coverage

Conversation

@mathieumaf

Copy link
Copy Markdown
Contributor

Description

A coverage scan showed that the handlers of list_cantons and get_publication_history never ran in tests, and that list_institutions, search_tenders and startServer() (the MCP_TRANSPORT guard from SECURITY.md) were only partly covered. Several test files didn't call the tool at all: they tested a hand-written copy of its logic ("mirror" helpers), so they stayed green whatever the real code did.

This PR tests the real code instead and raises the CI coverage floors. src/ is unchanged.

Statements Branches Functions Lines
main 88.42 % 78.34 % 91.89 % 88.85 %
this PR 99.74 % 97.53 % 99.09 % 100 %
new floor (vitest.config.ts) 97 95 97 97
tests/
├── helpers/in-process-server.ts   new: server + stubbed fetch, fresh module graph per test (no cache leaks)
├── index.test.ts                  new: entry point logs, then exits 1, when startup fails
├── server.test.ts                 + startServer(): MCP_TRANSPORT is reset to stdio before run() is called
├── tools/
│   ├── list-cantons, get-publication-history, list-institutions   mirror tests → handler tests
│   ├── search-tenders              + handler: URL mapping, pagination, language, empty, errors
│   ├── search-proc-offices, get-tender-details   + empty results, institutionId, non-404 errors
│   └── search-*-codes, browse-*-tree (8 files)  mirror blocks removed: code-tools.test.ts covers them
├── utils/formatting.test.ts       + formatProject, formatHeader, every optional section of formatPublicationDetails
├── utils/errors.test.ts           + 429/503, statuses outside 4xx/5xx, Node network error codes
└── api/client.test.ts, prompts/analyze-tender.test.ts   + debug cache-hit log, "(root)" argument error

Related issue

None. Follows a coverage scan.

Type of change

  • Tooling (checks, CI, release)

Evidence

Checks (the five from AGENTS.md, Node 26): lint, typecheck, format:check and build are clean. test:coverage runs 517 tests, all passing, above the new floors.

Node 22 and 24: the suite also passes on each, with the same numbers: 99.74 / 97.53 / 99.09 / 100.

The new tests catch real regressions. I broke src/ on purpose, ran the suite, then restored the file:

Mutation in src/ Result
server.ts: drop the MCP_TRANSPORT = "stdio" reset 3 tests fail
server.ts: move the reset after run() 3 tests fail
list-cantons.ts: unknown code falls back to ?, or TI removed from the names 1 test fails
get-publication-history.ts: stop treating simap's 400 as "no history" 1 test fails
list-institutions.ts: stop matching Italian names 2 tests fail
search-tenders.ts: default page size 20 → 10, or always format in de 1 test fails
formatting.ts: stop upper-casing the currency 2 tests fail
index.ts: exit(0), or exit before logging 1 test fails

On main, the files rewritten here passed whatever the handler did, because they never imported it.

Removing the mirror tests changed no coverage number (547 → 517 tests, same percentages), which confirms they never ran the real code.

Stability: 5 consecutive full runs, all green. No new test sends a 5xx, so the client's retry backoff never adds delay. At most 8 requests per file, well under the 60/min limit.

Not verified: CI itself, until this PR's checks run.

Follow-ups, not in this PR:

  • get_publication_history looks labels up with labels[pubType] || pubType. A pubType of constructor would print a function. search_proc_offices already guards this with Object.hasOwn.
  • The existing "today's Zurich date" test in search-tenders.test.ts reads the clock twice and can fail at midnight.

Risk

Tier: High, because vitest.config.ts (what defines the checks) is High in AGENTS.md. Everything else is under tests/ (Low).
Blast radius: no runtime change: src/ and package.json are untouched. If a floor turns out too tight on a CI runner, CI fails until it is lowered. Each floor sits 2 to 3 points under the value measured on Node 22, 24 and 26.
Revert: git revert.

Checklist

  • Added or updated tests
  • Added a changeset if the change is user-visible (npx changeset): not user-visible, tests and CI floors only
  • Updated documentation if needed: no pattern changed

Council review

Rounds: 3

Member Round 1 Round 2 Round 3
Claude Opus 5.5 8/10 9/10 9/10
GPT-6.2 Sol 8/10 9/10 10/10
Gemini 4 Neon 8/10 10/10 10/10

Fixed from review: the MCP_TRANSPORT test now checks the value when run() is called (all three members). Also fixed: the language test uses fr, the cantons test rejects code fallbacks, the remaining 8 mirror blocks are removed, a duplicate injection test is dropped, and the entry point is checked to log before it exits. Declined: the Zurich midnight race, which predates this PR (listed above).

🤖 Generated with Claude Code

mathieumaf and others added 3 commits December 3, 2026 09:30
…e floors

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mirror tests)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Dec 3, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 023bfd9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-03T08:44:36.525508Z 023bfd9 PR opened
🔒 Security Review ✅ Completed 2026-12-03T08:45:46.676759Z 023bfd9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@mathieumaf
mathieumaf merged commit 4594c44 into main Dec 3, 2026
6 checks passed
@mathieumaf
mathieumaf deleted the t3/improve-test-coverage branch December 3, 2026 09:07
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