Skip to content

Commit 07adbff

Browse files
committed
fix(test): repair mcp-cli-activation-preview in-process connect after JSONbored#7764's entrypoint guard
JSONbored#7764 gated the bin's top-level `await server.connect(new StdioServerTransport())` behind isProcessEntrypoint() (realpath(argv[1]) === realpath(this module)). JSONbored#7887's activation-preview test set argv[1] to the bare string "loopover-mcp", so realpathSync throws, the guard is false, the top-level connect is skipped, its mocked in-memory transport is never wired to the server, and client.connect hangs to the 10s hook timeout. JSONbored#7887 merged just before JSONbored#7764, so its CI never saw the guard; main has been latently red on this test since. Point argv[1] at the bin's own resolved path so the guard is satisfied on import. Surfaced here because this PR's bin change pulls the mcp-cli-*.test.ts suite into scoped selection.
1 parent 58e65dd commit 07adbff

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

test/unit/mcp-cli-activation-preview.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,18 @@ beforeAll(async () => {
4747
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
4848
holder.serverTransport = serverTransport;
4949

50-
// cliArgs[0] === undefined skips the module's `if (cliArgs[0] && cliArgs[0] !== "--stdio")` CLI-dispatch
51-
// guard (which would runCli + process.exit), so importing just registers the tools and connects our
52-
// in-memory transport instead of a real stdio one.
53-
const originalArgv = process.argv;
54-
process.argv = [process.execPath, "loopover-mcp"];
5550
// Import the .ts source explicitly (not the .js): a committed/build-artifact .js on disk would otherwise be
5651
// resolved and instrumented under its .js path, so codecov/patch would map the new lines to the wrong file.
5752
// A non-literal specifier keeps tsc from rejecting the .ts extension (TS5097) while vitest still loads it.
5853
const binTsModule = "../../packages/loopover-mcp/bin/loopover-mcp.ts";
54+
// #7764 gated the bin's top-level `await server.connect(new StdioServerTransport())` behind
55+
// isProcessEntrypoint() (realpath(argv[1]) === realpath(this module)). Point argv[1] at the bin's own
56+
// resolved path so that guard is satisfied on import — otherwise the top-level connect is skipped, our
57+
// mocked in-memory transport is never wired to the server, and client.connect below hangs to the timeout.
58+
// argv[2..] stays empty, so the `if (cliArgs[0] && cliArgs[0] !== "--stdio")` CLI-dispatch guard (runCli +
59+
// process.exit) is still skipped — importing only registers the tools and connects our transport.
60+
const originalArgv = process.argv;
61+
process.argv = [process.execPath, join(process.cwd(), "packages/loopover-mcp/bin/loopover-mcp.ts")];
5962
await import(/* @vite-ignore */ binTsModule);
6063
process.argv = originalArgv;
6164

0 commit comments

Comments
 (0)