test(mcp): share held-prompt completion fixtures (#16563)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-04 11:24:51 +08:00
1 parent 8c780e60d5
commit d7431cd005
1 file changed
+15 -45
+15 -45
View File
@@ -33,6 +33,16 @@ import {
} from "../../tests/support/lifecycleHarness.js";
import { createToolResultDelivery } from "./toolResult.js";
const heldPromptCompletion = (id: number, value: string): JSONRPCMessage => ({
jsonrpc: "2.0",
id,
method: "completion/complete",
params: {
ref: { type: "ref/prompt", name: "held" },
argument: { name: "topic", value },
},
});
const firstText = (result: {
readonly content: readonly {
readonly type: string;
@@ -1336,15 +1346,7 @@ describe("duplicate in-flight request IDs", () => {
const testLifetime = createDeferred<void>();
try {
await initializeClient(clientTransport, received);
await clientTransport.send({
jsonrpc: "2.0",
id: 7,
method: "completion/complete",
params: {
ref: { type: "ref/prompt", name: "held" },
argument: { name: "topic", value: "v" },
},
});
await clientTransport.send(heldPromptCompletion(7, "v"));
await replyGate.reached(
testLifetime.promise,
"first completion reply send",
@@ -1354,15 +1356,7 @@ describe("duplicate in-flight request IDs", () => {
method: "notifications/cancelled",
params: { requestId: 7, reason: "stop" },
});
await clientTransport.send({
jsonrpc: "2.0",
id: 7,
method: "completion/complete",
params: {
ref: { type: "ref/prompt", name: "held" },
argument: { name: "topic", value: "v" },
},
});
await clientTransport.send(heldPromptCompletion(7, "v"));
await expect
.poll(() => responseFor(received, 7, "error"))
.toMatchObject({
@@ -1386,15 +1380,7 @@ describe("duplicate in-flight request IDs", () => {
id: 7,
result: { completion: { values: ["value"] } },
});
await clientTransport.send({
jsonrpc: "2.0",
id: 7,
method: "completion/complete",
params: {
ref: { type: "ref/prompt", name: "held" },
argument: { name: "topic", value: "again" },
},
});
await clientTransport.send(heldPromptCompletion(7, "again"));
await handler.reached(testLifetime.promise, "reused completion id");
expect(signals).toHaveLength(2);
expect(signals[1]?.aborted).toBe(false);
@@ -1459,15 +1445,7 @@ describe("duplicate in-flight request IDs", () => {
const testLifetime = createDeferred<void>();
try {
await initializeClient(clientTransport, received);
await clientTransport.send({
jsonrpc: "2.0",
id: 7,
method: "completion/complete",
params: {
ref: { type: "ref/prompt", name: "held" },
argument: { name: "topic", value: "v" },
},
});
await clientTransport.send(heldPromptCompletion(7, "v"));
await first.reached(testLifetime.promise, "first completion handler");
await clientTransport.send({
jsonrpc: "2.0",
@@ -1479,15 +1457,7 @@ describe("duplicate in-flight request IDs", () => {
kind: "request-cancelled",
clientReason: "stop",
});
await clientTransport.send({
jsonrpc: "2.0",
id: 7,
method: "completion/complete",
params: {
ref: { type: "ref/prompt", name: "held" },
argument: { name: "topic", value: "next" },
},
});
await clientTransport.send(heldPromptCompletion(7, "next"));
await second.reached(
testLifetime.promise,
"reused completion after cancel",