Skip to content

Commit 9050ff0

Browse files
authored
test(acp): remove cleanup-only session seam (#124043)
* test(acp): remove cleanup-only session seam * test(infra): stabilize routing and PID readiness * test(gateway): synchronize post-rejection frame proof
1 parent 2e806ef commit 9050ff0

16 files changed

Lines changed: 111 additions & 214 deletions
Lines changed: 79 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ACP Core tests cover session behavior.
2-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
2+
import { beforeEach, describe, expect, it } from "vitest";
33
import { createInMemorySessionStore } from "./session.js";
44

55
describe("acp session manager", () => {
@@ -15,10 +15,6 @@ describe("acp session manager", () => {
1515
store = createInMemorySessionStore({ now });
1616
});
1717

18-
afterEach(() => {
19-
store.clearAllSessionsForTest();
20-
});
21-
2218
it("tracks active runs and clears on cancel", () => {
2319
const session = store.createSession({
2420
sessionKey: "acp:test",
@@ -95,24 +91,20 @@ describe("acp session manager", () => {
9591
idleTtlMs: Number.NaN,
9692
now,
9793
});
98-
try {
99-
boundedStore.createSession({
100-
sessionId: "first",
101-
sessionKey: "acp:first",
102-
cwd: "/tmp",
103-
});
104-
advance(1);
105-
boundedStore.createSession({
106-
sessionId: "second",
107-
sessionKey: "acp:second",
108-
cwd: "/tmp",
109-
});
94+
boundedStore.createSession({
95+
sessionId: "first",
96+
sessionKey: "acp:first",
97+
cwd: "/tmp",
98+
});
99+
advance(1);
100+
boundedStore.createSession({
101+
sessionId: "second",
102+
sessionKey: "acp:second",
103+
cwd: "/tmp",
104+
});
110105

111-
expect(boundedStore.hasSession("first")).toBe(true);
112-
expect(boundedStore.hasSession("second")).toBe(true);
113-
} finally {
114-
boundedStore.clearAllSessionsForTest();
115-
}
106+
expect(boundedStore.hasSession("first")).toBe(true);
107+
expect(boundedStore.hasSession("second")).toBe(true);
116108
});
117109

118110
it("falls back for non-finite max session options", () => {
@@ -121,26 +113,22 @@ describe("acp session manager", () => {
121113
idleTtlMs: 24 * 60 * 60 * 1_000,
122114
now,
123115
});
124-
try {
125-
for (let index = 0; index < 5_000; index += 1) {
126-
const session = boundedStore.createSession({
127-
sessionId: `session-${index}`,
128-
sessionKey: `acp:${index}`,
129-
cwd: "/tmp",
130-
});
131-
boundedStore.setActiveRun(session.sessionId, `run-${index}`, new AbortController());
132-
}
133-
134-
expect(() =>
135-
boundedStore.createSession({
136-
sessionId: "overflow",
137-
sessionKey: "acp:overflow",
138-
cwd: "/tmp",
139-
}),
140-
).toThrow(/session limit reached/i);
141-
} finally {
142-
boundedStore.clearAllSessionsForTest();
116+
for (let index = 0; index < 5_000; index += 1) {
117+
const session = boundedStore.createSession({
118+
sessionId: `session-${index}`,
119+
sessionKey: `acp:${index}`,
120+
cwd: "/tmp",
121+
});
122+
boundedStore.setActiveRun(session.sessionId, `run-${index}`, new AbortController());
143123
}
124+
125+
expect(() =>
126+
boundedStore.createSession({
127+
sessionId: "overflow",
128+
sessionKey: "acp:overflow",
129+
cwd: "/tmp",
130+
}),
131+
).toThrow(/session limit reached/i);
144132
});
145133

146134
it("reaps idle sessions before enforcing the max session cap", () => {
@@ -149,25 +137,21 @@ describe("acp session manager", () => {
149137
idleTtlMs: 1_000,
150138
now,
151139
});
152-
try {
153-
boundedStore.createSession({
154-
sessionId: "old",
155-
sessionKey: "acp:old",
156-
cwd: "/tmp",
157-
});
158-
advance(2_000);
159-
const fresh = boundedStore.createSession({
160-
sessionId: "fresh",
161-
sessionKey: "acp:fresh",
162-
cwd: "/tmp",
163-
});
140+
boundedStore.createSession({
141+
sessionId: "old",
142+
sessionKey: "acp:old",
143+
cwd: "/tmp",
144+
});
145+
advance(2_000);
146+
const fresh = boundedStore.createSession({
147+
sessionId: "fresh",
148+
sessionKey: "acp:fresh",
149+
cwd: "/tmp",
150+
});
164151

165-
expect(fresh.sessionId).toBe("fresh");
166-
expect(boundedStore.getSession("old")).toBeUndefined();
167-
expect(boundedStore.hasSession("old")).toBe(false);
168-
} finally {
169-
boundedStore.clearAllSessionsForTest();
170-
}
152+
expect(fresh.sessionId).toBe("fresh");
153+
expect(boundedStore.getSession("old")).toBeUndefined();
154+
expect(boundedStore.hasSession("old")).toBe(false);
171155
});
172156

173157
it("uses soft-cap eviction for the oldest idle session when full", () => {
@@ -176,35 +160,31 @@ describe("acp session manager", () => {
176160
idleTtlMs: 24 * 60 * 60 * 1_000,
177161
now,
178162
});
179-
try {
180-
const first = boundedStore.createSession({
181-
sessionId: "first",
182-
sessionKey: "acp:first",
183-
cwd: "/tmp",
184-
});
185-
advance(100);
186-
const second = boundedStore.createSession({
187-
sessionId: "second",
188-
sessionKey: "acp:second",
189-
cwd: "/tmp",
190-
});
191-
const controller = new AbortController();
192-
boundedStore.setActiveRun(second.sessionId, "run-2", controller);
193-
advance(100);
163+
const first = boundedStore.createSession({
164+
sessionId: "first",
165+
sessionKey: "acp:first",
166+
cwd: "/tmp",
167+
});
168+
advance(100);
169+
const second = boundedStore.createSession({
170+
sessionId: "second",
171+
sessionKey: "acp:second",
172+
cwd: "/tmp",
173+
});
174+
const controller = new AbortController();
175+
boundedStore.setActiveRun(second.sessionId, "run-2", controller);
176+
advance(100);
194177

195-
const third = boundedStore.createSession({
196-
sessionId: "third",
197-
sessionKey: "acp:third",
198-
cwd: "/tmp",
199-
});
178+
const third = boundedStore.createSession({
179+
sessionId: "third",
180+
sessionKey: "acp:third",
181+
cwd: "/tmp",
182+
});
200183

201-
expect(third.sessionId).toBe("third");
202-
expect(boundedStore.getSession(first.sessionId)).toBeUndefined();
203-
const retainedSession = boundedStore.getSession(second.sessionId);
204-
expect(retainedSession?.sessionId).toBe("second");
205-
} finally {
206-
boundedStore.clearAllSessionsForTest();
207-
}
184+
expect(third.sessionId).toBe("third");
185+
expect(boundedStore.getSession(first.sessionId)).toBeUndefined();
186+
const retainedSession = boundedStore.getSession(second.sessionId);
187+
expect(retainedSession?.sessionId).toBe("second");
208188
});
209189

210190
it("rejects when full and no session is evictable", () => {
@@ -213,23 +193,19 @@ describe("acp session manager", () => {
213193
idleTtlMs: 24 * 60 * 60 * 1_000,
214194
now,
215195
});
216-
try {
217-
const only = boundedStore.createSession({
218-
sessionId: "only",
219-
sessionKey: "acp:only",
196+
const only = boundedStore.createSession({
197+
sessionId: "only",
198+
sessionKey: "acp:only",
199+
cwd: "/tmp",
200+
});
201+
boundedStore.setActiveRun(only.sessionId, "run-only", new AbortController());
202+
203+
expect(() =>
204+
boundedStore.createSession({
205+
sessionId: "next",
206+
sessionKey: "acp:next",
220207
cwd: "/tmp",
221-
});
222-
boundedStore.setActiveRun(only.sessionId, "run-only", new AbortController());
223-
224-
expect(() =>
225-
boundedStore.createSession({
226-
sessionId: "next",
227-
sessionKey: "acp:next",
228-
cwd: "/tmp",
229-
}),
230-
).toThrow(/session limit reached/i);
231-
} finally {
232-
boundedStore.clearAllSessionsForTest();
233-
}
208+
}),
209+
).toThrow(/session limit reached/i);
234210
});
235211
});

‎packages/acp-core/src/session.ts‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export type AcpSessionStore = {
1919
clearActiveRun: (sessionId: string) => void;
2020
cancelActiveRun: (sessionId: string) => boolean;
2121
deleteSession: (sessionId: string) => boolean;
22-
clearAllSessionsForTest: () => void;
2322
};
2423

2524
type AcpSessionStoreOptions = {
@@ -189,14 +188,6 @@ export function createInMemorySessionStore(options: AcpSessionStoreOptions = {})
189188

190189
const deleteSession: AcpSessionStore["deleteSession"] = (sessionId) => removeSession(sessionId);
191190

192-
const clearAllSessionsForTest: AcpSessionStore["clearAllSessionsForTest"] = () => {
193-
for (const session of sessions.values()) {
194-
session.abortController?.abort();
195-
}
196-
sessions.clear();
197-
runIdToSessionId.clear();
198-
};
199-
200191
return {
201192
createSession,
202193
hasSession,
@@ -206,7 +197,6 @@ export function createInMemorySessionStore(options: AcpSessionStoreOptions = {})
206197
clearActiveRun,
207198
cancelActiveRun,
208199
deleteSession,
209-
clearAllSessionsForTest,
210200
};
211201
}
212202

‎src/acp/translator.bridge-test-helpers.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ export async function expectOversizedPromptRejected(params: { sessionId: string;
127127
const session = sessionStore.getSession(params.sessionId);
128128
expect(session?.activeRunId).toBeNull();
129129
expect(session?.abortController).toBeNull();
130-
131-
sessionStore.clearAllSessionsForTest();
132130
}
133131

134132
export type MockCallSource = { mock: { calls: Array<Array<unknown>> } };

‎src/acp/translator.event-ledger.test.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,6 @@ describe("ACP translator event ledger replay", () => {
277277
await expect(
278278
eventLedger.readReplayBySessionId({ sessionId: firstSession.sessionKey }),
279279
).resolves.toEqual({ complete: false, events: [] });
280-
281-
firstSessionStore.clearAllSessionsForTest();
282280
});
283281

284282
it("does not replay prompts that Gateway rejected before accepting the send", async () => {

‎src/acp/translator.final-snapshots.test.ts‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,10 @@ describe("acp final chat snapshots", () => {
6161
},
6262
});
6363
expect(sessionStore.getSession("snapshot-session")?.activeRunId).toBeNull();
64-
sessionStore.clearAllSessionsForTest();
6564
});
6665

6766
it("does not duplicate text when final repeats the last delta snapshot", async () => {
68-
const { agent, sessionUpdate, promptPromise, runId, sessionStore } =
69-
await createSnapshotHarness();
67+
const { agent, sessionUpdate, promptPromise, runId } = await createSnapshotHarness();
7068

7169
await agent.handleGatewayEvent({
7270
event: "chat",
@@ -101,12 +99,10 @@ describe("acp final chat snapshots", () => {
10199
"agent_message_chunk",
102100
);
103101
expect(chunks).toHaveLength(1);
104-
sessionStore.clearAllSessionsForTest();
105102
});
106103

107104
it("emits only the missing tail when the final snapshot extends prior deltas", async () => {
108-
const { agent, sessionUpdate, promptPromise, runId, sessionStore } =
109-
await createSnapshotHarness();
105+
const { agent, sessionUpdate, promptPromise, runId } = await createSnapshotHarness();
110106

111107
await agent.handleGatewayEvent({
112108
event: "chat",
@@ -148,6 +144,5 @@ describe("acp final chat snapshots", () => {
148144
content: { type: "text", text: " world" },
149145
},
150146
});
151-
sessionStore.clearAllSessionsForTest();
152147
});
153148
});

‎src/acp/translator.lifecycle.test.ts‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ describe("acp translator stable lifecycle handlers", () => {
160160
expect(typeof agent.closeSession).toBe("function");
161161
expect(capabilities.sessionCapabilities?.fork).toBeUndefined();
162162
expect("unstable_listSessions" in agent).toBe(false);
163-
164-
sessionStore.clearAllSessionsForTest();
165163
});
166164

167165
it("lists Gateway sessions through the stable handler with opaque cursors and cwd filtering", async () => {
@@ -219,8 +217,6 @@ describe("acp translator stable lifecycle handlers", () => {
219217
limit: 5,
220218
includeDerivedTitles: true,
221219
});
222-
223-
sessionStore.clearAllSessionsForTest();
224220
});
225221

226222
it("does not include sessions without workspace metadata in cwd-filtered lists", async () => {
@@ -244,8 +240,6 @@ describe("acp translator stable lifecycle handlers", () => {
244240

245241
expect(result.sessions.map((session) => session.sessionId)).toEqual(["agent:main:a1"]);
246242
expect(result.sessions.map((session) => session.cwd)).toEqual(["/work/a"]);
247-
248-
sessionStore.clearAllSessionsForTest();
249243
});
250244

251245
it("lists Gateway sessions with invalid updated timestamps", async () => {
@@ -271,8 +265,6 @@ describe("acp translator stable lifecycle handlers", () => {
271265

272266
expect(result.sessions).toHaveLength(1);
273267
expect(result.sessions[0]?.updatedAt).toBeUndefined();
274-
275-
sessionStore.clearAllSessionsForTest();
276268
});
277269

278270
it("rejects session/list cursors when the cwd filter changes", async () => {
@@ -314,8 +306,6 @@ describe("acp translator stable lifecycle handlers", () => {
314306
await expect(
315307
agent.listSessions(createListSessionsRequest({ cursor: filtered.nextCursor })),
316308
).rejects.toThrow(/cursor does not match the cwd filter/i);
317-
318-
sessionStore.clearAllSessionsForTest();
319309
});
320310

321311
it("rejects relative cwd filters for session/list", async () => {
@@ -327,8 +317,6 @@ describe("acp translator stable lifecycle handlers", () => {
327317
await expect(
328318
agent.listSessions(createListSessionsRequest({ cwd: "relative/path" })),
329319
).rejects.toThrow(/requires an absolute cwd/i);
330-
331-
sessionStore.clearAllSessionsForTest();
332320
});
333321

334322
it("resumes an existing Gateway session without replaying transcript history", async () => {
@@ -378,8 +366,6 @@ describe("acp translator stable lifecycle handlers", () => {
378366
},
379367
},
380368
});
381-
382-
sessionStore.clearAllSessionsForTest();
383369
});
384370

385371
it("rejects resume for a missing Gateway session without creating bridge state", async () => {
@@ -399,7 +385,6 @@ describe("acp translator stable lifecycle handlers", () => {
399385
).rejects.toThrow(/Session missing-session not found/i);
400386

401387
expect(sessionStore.hasSession("missing-session")).toBe(false);
402-
sessionStore.clearAllSessionsForTest();
403388
});
404389

405390
it("resolves prompts when chat send returns a terminal timeout ack", async () => {
@@ -521,7 +506,5 @@ describe("acp translator stable lifecycle handlers", () => {
521506
await expect(agent.closeSession(createCloseSessionRequest("missing-session"))).rejects.toThrow(
522507
/Session missing-session not found/i,
523508
);
524-
525-
sessionStore.clearAllSessionsForTest();
526509
});
527510
});

0 commit comments

Comments
 (0)