Skip to content

Commit 014181d

Browse files
t3dotggclaude
andcommitted
test(server): cover the same clientRequestId from another caller
Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent e90fe9d commit 014181d

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

‎apps/server/src/mcp/toolkits/threads/handlers.test.ts‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { ThreadsToolkit } from "./tools.ts";
2828

2929
const PROJECT_ID = ProjectId.make("project-1");
3030
const THREAD_ID = ThreadId.make("thread-1");
31+
const OTHER_THREAD_ID = ThreadId.make("thread-2");
3132

3233
const testCrypto = Crypto.make({
3334
randomBytes: (size) => new Uint8Array(size).fill(7),
@@ -37,9 +38,10 @@ const testCrypto = Crypto.make({
3738

3839
const invocation = (
3940
capabilities: ReadonlyArray<McpInvocationContext.McpCapability>,
41+
threadId: ThreadId = THREAD_ID,
4042
): McpInvocationContext.McpInvocationScope => ({
4143
environmentId: EnvironmentId.make("environment-1"),
42-
threadId: THREAD_ID,
44+
threadId,
4345
providerSessionId: "provider-session-1",
4446
providerInstanceId: ProviderInstanceId.make("codex"),
4547
capabilities: new Set(capabilities),
@@ -81,7 +83,7 @@ const makeHarness = Effect.fn("makeThreadsToolkitHarness")(function* (
8183
options: HarnessOptions = {},
8284
) {
8385
const commands = yield* Ref.make<ReadonlyArray<OrchestrationCommand>>([]);
84-
const threads = options.threads ?? [makeThread()];
86+
const threads = options.threads ?? [makeThread(), makeThread({ id: OTHER_THREAD_ID })];
8587
const dispatch: OrchestrationEngineShape["dispatch"] = (command) =>
8688
Effect.gen(function* () {
8789
const rejection = options.reject?.(command) ?? null;
@@ -108,6 +110,7 @@ const makeHarness = Effect.fn("makeThreadsToolkitHarness")(function* (
108110
const call = (
109111
params: Parameters<typeof toolkit.handle<"start_thread">>[1],
110112
capabilities: ReadonlyArray<McpInvocationContext.McpCapability> = ["threads"],
113+
caller: ThreadId = THREAD_ID,
111114
) =>
112115
toolkit.handle("start_thread", params).pipe(
113116
Stream.unwrap,
@@ -116,7 +119,10 @@ const makeHarness = Effect.fn("makeThreadsToolkitHarness")(function* (
116119
Effect.map(
117120
(chunk) => chunk.at(-1)!.result as Tool.Success<typeof ThreadsToolkit.tools.start_thread>,
118121
),
119-
Effect.provideService(McpInvocationContext.McpInvocationContext, invocation(capabilities)),
122+
Effect.provideService(
123+
McpInvocationContext.McpInvocationContext,
124+
invocation(capabilities, caller),
125+
),
120126
Effect.provide(dependencies),
121127
);
122128
return { commands, call };
@@ -217,10 +223,17 @@ describe("threads toolkit handlers", () => {
217223
`server:mcp-thread-turn-start:${first.threadId}`,
218224
]);
219225

220-
// A different request id, and a call without one, each get a new thread.
226+
// A different request id, the same id from another caller, and a call
227+
// without an id each get their own thread.
221228
const other = yield* harness.call({ prompt: "Do it", clientRequestId: "req-2" });
229+
const otherCaller = yield* harness.call(
230+
{ prompt: "Do it", clientRequestId: "req-1" },
231+
["threads"],
232+
OTHER_THREAD_ID,
233+
);
222234
const anonymous = yield* harness.call({ prompt: "Do it" });
223235
expect(other.threadId).not.toBe(first.threadId);
236+
expect(otherCaller.threadId).not.toBe(first.threadId);
224237
expect(anonymous.threadId).not.toMatch(/^mcp-/);
225238
}),
226239
);

0 commit comments

Comments
 (0)