Skip to content

Commit fc478d1

Browse files
authored
Merge pull request #4969 from modelcontextprotocol/v2/chore/4854-ts-coverage-gate
ci(coverage): enforce the TypeScript per-file coverage gate in CI and local:gate
2 parents 9c0cf8f + 0645252 commit fc478d1

92 files changed

Lines changed: 12285 additions & 5140 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@modelcontextprotocol/server-everything": patch
3+
---
4+
5+
Internal refactor for in-process testing, with no change in behavior: the launcher only starts a transport when run as the binary, and the stdio, SSE and Streamable HTTP transport modules export their start-up (`startStdioServer`, `startSseServer`, `startStreamableHttpServer`, and `createApp()` for the HTTP transports) instead of starting a server when imported.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@modelcontextprotocol/server-filesystem": patch
3+
---
4+
5+
Internal: the server is now built by a `createServer()` factory in `server.ts`, and `index.ts` starts it over stdio only when run as the bin, with each server instance holding its own allowed directories. No change to the tools, their results, or how the allowed directories are resolved from arguments and Roots.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@modelcontextprotocol/server-memory": patch
3+
---
4+
5+
Build the server with an exported `createServer()` factory and start stdio only when the package is run as a program, so importing the module no longer starts a server. Behavior over stdio is unchanged.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@modelcontextprotocol/server-sequential-thinking": patch
3+
---
4+
5+
Build the server with an exported `createServer()` factory and attach stdio only when `index.js` runs as the binary, so the server can be tested in-process. No change to the tool, its schemas or its results.

‎.claude/skills/pre-push-gate/SKILL.md‎

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,40 @@ the server's own `tsc`. An error in a test file only shows in `typecheck`.
154154
Re-run just that suite to iterate: `npm test -w src/<server>`. Read the failure
155155
before changing a timeout: an assertion that races is a bug in the test.
156156

157+
### `coverage`
158+
159+
A TypeScript file is below 90% on lines, statements, functions or branches.
160+
Vitest names each file and dimension:
161+
162+
```
163+
ERROR: Coverage for branches (71.42%) does not meet global threshold (90%) for roots-utils.ts
164+
```
165+
166+
("global threshold" is Vitest's wording; with `perFile: true` it is checked
167+
per file.) The root `npm run coverage` carries on into the remaining
168+
workspaces after a failure, so **the failing report is not the last thing
169+
printed**: find the `npm ERR!` block, which names the workspace
170+
(`in workspace: @modelcontextprotocol/server-<name>`), and read the `ERROR:`
171+
lines just above it.
172+
173+
1. Re-run that server alone: `npm run coverage -w src/<server>`.
174+
2. Read its per-file table. The `Uncovered Line #s` column is where the
175+
missing tests go (a long list is truncated to `...`, and a long file name
176+
to `...-name.ts`; open `coverage/index.html` in the workspace, or narrow
177+
the run, for the full list). A branch shortfall with no uncovered lines is
178+
the untaken side of a condition, `??`, `?.` or default parameter.
179+
3. **Write the tests.** Drive what a client sees through a `Client` over the
180+
in-memory transport; call a helper directly only for its logic (`testing`
181+
skill).
182+
4. Only for code that genuinely cannot run, annotate it at the source with
183+
its reason, `/* v8 ignore next -- <reason> */` (or `start`/`stop` around a
184+
block). A branch that is merely awkward to reach is not unreachable.
185+
186+
**Never lower a threshold, drop `perFile`, or widen the coverage `exclude`**
187+
to get green; the gate is the rule in `AGENTS.md` **Always test new or
188+
modified code**. A failing _test_ in this stage is an ordinary test failure:
189+
fix it as under `test`, above.
190+
157191
### `validate:py`
158192

159193
The summary at the end names the failing server, and the step that failed is
@@ -221,8 +255,7 @@ The details of the lease are in
221255

222256
## Not part of the gate
223257

224-
`npm run skills:eval` (real model calls), `npm run coverage` (a report; no
225-
threshold is enforced yet) and `npm run pack:verify` (installs each package's
226-
publish artifact and boots it; needs the network, and belongs to the release
227-
flow) are separate commands. Run the eval suite when you
228-
add a skill or change a description.
258+
`npm run skills:eval` (real model calls) and `npm run pack:verify` (installs
259+
each package's publish artifact and boots it; needs the network, and belongs to
260+
the release flow) are separate commands. Run the eval suite when you add a
261+
skill or change a description.

‎.claude/skills/pre-push-gate/evals/evals.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
"prompt": "verify:no-test-retries is failing in my gate run but I never added a test retry. What is it matching?",
2424
"expect": "pre-push-gate"
2525
},
26+
{
27+
"prompt": "The coverage stage of my gate run went red, but the last report it printed was all green. How do I find what failed and fix it?",
28+
"expect": "pre-push-gate"
29+
},
2630
{
2731
"prompt": "What is 17 multiplied by 23?",
2832
"expect": null

‎.claude/skills/project-structure/SKILL.md‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ includes the tests) and `vitest.config.ts`.
2929
| Server | Layout | Where its features are registered |
3030
| --- | --- | --- |
3131
| `everything` | `index.ts` picks a transport from `argv`; `server/` holds the factory; `tools/`, `resources/`, `prompts/` hold one file per feature plus an `index.ts`; `transports/` holds one file per transport; `version.ts` reads the package version; `docs/` is shipped | Each feature file exports a `register…` function, wired into its area's `index.ts` (`registerTools`, `registerResources`, `registerPrompts`), which `server/index.ts` calls from `createServer()` |
32-
| `filesystem` | `index.ts` is the server; `lib.ts` holds the file operations and path validation; `path-utils.ts`, `path-validation.ts` and `roots-utils.ts` are focused helpers; `version.ts` reads the package version | Inline in `index.ts`, with `server.registerTool(...)` |
33-
| `memory` | `index.ts` is the server and the `KnowledgeGraphManager`; `version.ts` reads the package version | Inline in `index.ts`; the resource and its subscription handlers are exported `register…` functions in the same file |
34-
| `sequentialthinking` | `index.ts` is the server; `lib.ts` holds `SequentialThinkingServer`, the logic; `version.ts` reads the package version | Inline in `index.ts` |
32+
| `filesystem` | `index.ts` is the stdio entry point (argv → allowed directories, `main()`); `server.ts` exports `createServer(allowedDirectories)`; `lib.ts` holds the file operations and path validation, with the allow-list passed in rather than held globally; `path-utils.ts`, `path-validation.ts` and `roots-utils.ts` are focused helpers; `version.ts` reads the package version | Inline in `createServer()` in `server.ts`, with `server.registerTool(...)` |
33+
| `memory` | `index.ts` holds the `KnowledgeGraphManager`, `createServer(memoryFilePath)` and the stdio `main()`; `version.ts` reads the package version | Inline in `createServer()`; the resource and its subscription handlers are exported `register…` functions in the same file |
34+
| `sequentialthinking` | `index.ts` holds `createServer()` and the stdio `main()`; `lib.ts` holds `SequentialThinkingServer`, the logic; `version.ts` reads the package version | Inline in `createServer()` |
3535

3636
Three things about `everything` that the table cannot hold:
3737

@@ -50,11 +50,13 @@ Three things about `everything` that the table cannot hold:
5050
`structure.md`, and `src/everything/AGENTS.md` holds the rules that apply
5151
only inside that directory.
5252

53-
`filesystem`, `memory` and `sequentialthinking` run on import: each `index.ts`
54-
builds the server at module scope and connects stdio at the bottom of the
55-
file. That is why their logic lives in a separate module (`lib.ts`) or is
56-
exported from `index.ts` for the tests, and why a test cannot import a ready
57-
server from them. `/testing` covers what that means for a new test.
53+
**No server starts on import.** Each one builds its server in a
54+
`createServer(...)` factory, and its entry file connects a transport only when
55+
it is the process entry point (an `isEntryPoint()` or `isMainModule()` check
56+
that compares real paths, so the npm bin symlink still starts it). Keep it that
57+
way: a module that binds a port, connects stdio or installs a signal handler at
58+
import cannot be driven in-process by the tests. `/testing` covers the
59+
in-process harness.
5860

5961
## The Python servers
6062

@@ -88,7 +90,7 @@ importable.
8890
| --- | --- |
8991
| A tool, resource or prompt for `everything` | Its own kebab-case file in `tools/`, `resources/` or `prompts/`, exporting a `register…` function, wired into that directory's `index.ts` |
9092
| A transport for `everything` | `src/everything/transports/`, plus a `case` in `src/everything/index.ts` and a `start:…` script |
91-
| A tool for `filesystem`, `memory` or `sequentialthinking` | A `server.registerTool(...)` call in that server's `index.ts`; the logic it calls goes in `lib.ts` (or the class it extends) so a test can reach it |
93+
| A tool for `filesystem`, `memory` or `sequentialthinking` | A `server.registerTool(...)` call inside that server's `createServer()` (`server.ts` in `filesystem`, `index.ts` in the other two); the logic it calls goes in `lib.ts` (or the class it extends) |
9294
| A helper module for `everything` | A kebab-case `.ts` file in the feature area it supports, beside its users (`server/logging.ts`, `server/roots.ts`, `resources/session.ts`), imported with the `.js` extension |
9395
| A helper module for `filesystem`, `memory` or `sequentialthinking` | A kebab-case `.ts` file at the workspace root, imported with the `.js` extension |
9496
| A tool for a Python server | `server.py`: the tool-name enum member (`git`, `time`), the model, the `list_tools` entry, the `call_tool` branch |

0 commit comments

Comments
 (0)