-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathlegacy-request-compatibility.test.ts
More file actions
63 lines (54 loc) · 2.41 KB
/
Copy pathlegacy-request-compatibility.test.ts
File metadata and controls
63 lines (54 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
import type { MessageConnection } from "vscode-jsonrpc/node.js";
import { describe, expect, it, vi } from "vitest";
import {
createServerRpc,
type CatalogClientContract,
type CatalogSearchRequest,
type McpPlanInstallRequest,
type McpPlanInstallSource,
} from "../src/generated/rpc.js";
// Requests that declare x-legacy-parameters keep one object argument in TypeScript:
// later inputs are optional properties, so existing calls are unchanged.
const contract: CatalogClientContract = {
protocolVersion: 3,
requiredCapabilities: ["mcp-install-planning"],
};
const source: McpPlanInstallSource = {
kind: "candidate",
candidateHandle: "candidate",
searchId: "search",
};
function recordingRpc() {
const sendRequest = vi.fn(async () => ({ kind: "unavailable", message: "offline" }));
const rpc = createServerRpc({ sendRequest } as unknown as MessageConnection);
return { rpc, sendRequest };
}
describe("x-legacy-parameters in TypeScript", () => {
it("keeps existing object calls unchanged", async () => {
const { rpc, sendRequest } = recordingRpc();
const plan: McpPlanInstallRequest = { contract, source, scope: "user" };
const search: CatalogSearchRequest = { contract, query: "catalogue query", limit: 4 };
await rpc.mcp.planInstall(plan);
await rpc.catalog.search(search);
expect(sendRequest.mock.calls).toEqual([
["mcp.planInstall", { contract, source, scope: "user" }],
["catalog.search", { contract, query: "catalogue query", limit: 4 }],
]);
});
it("sends added optional inputs through the same method", async () => {
const { rpc, sendRequest } = recordingRpc();
await rpc.mcp.planInstall({ contract, source, policySessionId: "session" });
await rpc.catalog.search({
contract,
query: "catalogue query",
policySessionId: "session",
});
expect(sendRequest.mock.calls).toEqual([
["mcp.planInstall", { contract, source, policySessionId: "session" }],
["catalog.search", { contract, query: "catalogue query", policySessionId: "session" }],
]);
});
});