Skip to content

Commit c1e668c

Browse files
cliffhallclaude
andcommitted
test(everything): make the import-guard and cleanup tests fail on the regressions they guard
Copilot round 1 on #4978: re-import the launcher inside its test and check all three starters; assert no failed simulated-log send after cleanup; and reconnect under the departed session id to prove its subscription was removed (#4712). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent 055a060 commit c1e668c

3 files changed

Lines changed: 36 additions & 10 deletions

File tree

‎src/everything/__tests__/index.test.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,15 @@ describe("run", () => {
8282
expect(exit).toHaveBeenCalledWith(1);
8383
});
8484

85-
it("does not start anything when imported", () => {
86-
// The module was imported above, under vitest rather than as the binary.
85+
it("does not start anything when imported", async () => {
86+
// A fresh import, under vitest rather than as the binary: the entry-point
87+
// guard must keep it from starting any transport.
88+
vi.resetModules();
89+
await import("../index.js");
8790
expect(startStdioServer).not.toHaveBeenCalled();
91+
expect(startSseServer).not.toHaveBeenCalled();
92+
expect(startStreamableHttpServer).not.toHaveBeenCalled();
93+
expect(exit).not.toHaveBeenCalled();
8894
});
8995
});
9096

‎src/everything/__tests__/logging.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,16 @@ describe("toggle-simulated-logging", () => {
163163
const leaving = await connect();
164164
await toggle(leaving);
165165
await vi.waitFor(() => expect(messages(leaving)).toHaveLength(1));
166+
// A closed client receives nothing either way, so check the server side:
167+
// an interval that outlived cleanup would log each failed send.
168+
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
166169
await leaving.close();
167170
await vi.advanceTimersByTimeAsync(20000);
168171
expect(messages(leaving)).toHaveLength(1);
172+
expect(errorSpy).not.toHaveBeenCalledWith(
173+
"Simulated logging message failed:",
174+
expect.anything(),
175+
);
169176
});
170177

171178
it("logs, rather than throws, a message that cannot be sent", async () => {

‎src/everything/__tests__/resources.test.ts‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,27 @@ describe("resource subscriptions", () => {
231231
await session.client.subscribeResource({ uri: URI });
232232
await leaving.close();
233233

234-
await session.client.callTool({
235-
name: "toggle-subscriber-updates",
236-
arguments: {},
237-
});
238-
await vi.waitFor(() => expect(updates()).toEqual([URI]));
239-
expect(
240-
ofMethod(leaving.notifications, "notifications/resources/updated"),
241-
).toEqual([]);
234+
// A new client under the departed session's id, which never subscribed:
235+
// if cleanup had left the old subscription behind, its updates would
236+
// reach this client.
237+
const returning = await connect({ sessionId: leaving.sessionId });
238+
try {
239+
await returning.client.callTool({
240+
name: "toggle-subscriber-updates",
241+
arguments: {},
242+
});
243+
await session.client.callTool({
244+
name: "toggle-subscriber-updates",
245+
arguments: {},
246+
});
247+
await vi.advanceTimersByTimeAsync(5000);
248+
expect(updates()).toEqual([URI, URI]);
249+
expect(
250+
ofMethod(returning.notifications, "notifications/resources/updated"),
251+
).toEqual([]);
252+
} finally {
253+
await returning.close();
254+
}
242255
});
243256

244257
it("logs, rather than throws, an update that cannot be sent", async () => {

0 commit comments

Comments
 (0)