Commit 318176c
committed
test(coverage): drive mcp to >=95% line + branch coverage
Adds tests for every src/* surface: the InstantClient HTTP client (error
envelope branches, requestMultipart edges, empty-2xx sentinel), the
index.ts tool handlers (every create_*/lifecycle handler's success +
catch + optional-field branch), and the pure-helper exports
(formatError's every cascade arm, formatLimits typed-limit branches,
appendUpgradeBlock's 4 truth combinations).
To unit-test the tool handlers and helpers directly, src/index.ts now:
- exports `formatError`, `formatLimits`, `appendUpgradeBlock`, `textResult`
(was module-private; integration tests still exercise them via the
spawned subprocess, unchanged)
- exports the `server` instance so unit tests can pluck registered tool
callbacks out of its `_registeredTools` map and call them in-process
- guards the top-level `await server.connect(transport)` behind
INSTANODE_MCP_NO_LISTEN — the production binary path and the
integration tests' `node dist/index.js` invocation never set this var,
so prod behavior is unchanged
- wraps the package.json version read in a try/catch with a "dev"
fallback (mirrors client.ts's User-Agent resolver) so unit tests
importing from a non-canonical build path don't crash before any
test code runs
Coverage on src/ (via dist-test/src/, where `npm test` measures
--experimental-test-coverage):
Before: client 93.71% / 76.77%, index 92.29% / 30.77%
After: client 100.00% / 95.04%, index 99.70% / 95.00%
(index uncovered lines 995-997 = the production
`await server.connect()` path, unreachable in unit tests)
All files: 99.81% lines / 95.03% branches
Test count: 87 -> 248 passing (161 new unit-level tests across three
new/extended files):
- test/client-unit.test.ts (extended; was 25 tests, now 73)
- test/index-unit.test.ts (new; 35 tests for the pure helpers)
- test/tools-unit.test.ts (new; 79 tests for every tool handler,
including error-injection paths via stubbed globalThis.fetch)
Integration suite (87 tests) unchanged and still passing — the
new unit-level coverage is additive.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent b3d0d5f commit 318176c
5 files changed
Lines changed: 2552 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
| 50 | + | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
63 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
64 | 82 | | |
65 | 83 | | |
66 | 84 | | |
| |||
85 | 103 | | |
86 | 104 | | |
87 | 105 | | |
88 | | - | |
| 106 | + | |
89 | 107 | | |
90 | 108 | | |
91 | 109 | | |
| |||
152 | 170 | | |
153 | 171 | | |
154 | 172 | | |
155 | | - | |
| 173 | + | |
156 | 174 | | |
157 | 175 | | |
158 | 176 | | |
159 | | - | |
| 177 | + | |
160 | 178 | | |
161 | 179 | | |
162 | 180 | | |
| |||
172 | 190 | | |
173 | 191 | | |
174 | 192 | | |
175 | | - | |
| 193 | + | |
176 | 194 | | |
177 | 195 | | |
178 | 196 | | |
| |||
1136 | 1154 | | |
1137 | 1155 | | |
1138 | 1156 | | |
1139 | | - | |
1140 | | - | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
0 commit comments