




















@@ -54,6 +54,10 @@ function latestStreamableFetch() {
5454return fetch;
5555}
565657+function runtimeFetchCall(index: number) {
58+return runtimeFetchMock.mock.calls.at(index);
59+}
60+5761describe("resolveMcpTransport", () => {
5862beforeEach(() => {
5963runtimeFetchMock.mockReset();
@@ -91,12 +95,12 @@ describe("resolveMcpTransport", () => {
9195});
92969397expect(runtimeFetchMock).toHaveBeenCalledTimes(2);
94-expect(runtimeFetchMock.mock.calls[0]?.[0]).toBe("https://mcp.example.com/mcp");
95-expect(runtimeFetchMock.mock.calls[0]?.[1]?.redirect).toBe("manual");
96-expect(runtimeFetchMock.mock.calls[1]?.[0]).toBe("https://redirect.example/next");
97-expect(runtimeFetchMock.mock.calls[1]?.[1]?.redirect).toBe("manual");
98+expect(runtimeFetchCall(0)?.[0]).toBe("https://mcp.example.com/mcp");
99+expect(runtimeFetchCall(0)?.[1]?.redirect).toBe("manual");
100+expect(runtimeFetchCall(1)?.[0]).toBe("https://redirect.example/next");
101+expect(runtimeFetchCall(1)?.[1]?.redirect).toBe("manual");
9810299-const redirectedHeaders = new Headers(runtimeFetchMock.mock.calls[1]?.[1]?.headers);
103+const redirectedHeaders = new Headers(runtimeFetchCall(1)?.[1]?.headers);
100104expect(redirectedHeaders.get("x-api-key")).toBeNull();
101105expect(redirectedHeaders.get("accept")).toBe("application/json, text/event-stream");
102106expect(redirectedHeaders.get("user-agent")).toBe("node");
@@ -128,11 +132,11 @@ describe("resolveMcpTransport", () => {
128132});
129133130134expect(runtimeFetchMock).toHaveBeenCalledTimes(2);
131-expect(runtimeFetchMock.mock.calls[1]?.[0]).toBe("https://redirect.example/mcp");
132-expect(runtimeFetchMock.mock.calls[1]?.[1]?.method).toBe("POST");
133-expect(runtimeFetchMock.mock.calls[1]?.[1]?.body).toBe(body);
135+expect(runtimeFetchCall(1)?.[0]).toBe("https://redirect.example/mcp");
136+expect(runtimeFetchCall(1)?.[1]?.method).toBe("POST");
137+expect(runtimeFetchCall(1)?.[1]?.body).toBe(body);
134138135-const redirectedHeaders = new Headers(runtimeFetchMock.mock.calls[1]?.[1]?.headers);
139+const redirectedHeaders = new Headers(runtimeFetchCall(1)?.[1]?.headers);
136140expect(redirectedHeaders.get("x-api-key")).toBeNull();
137141expect(redirectedHeaders.get("content-type")).toBe("application/json");
138142});
@@ -158,11 +162,11 @@ describe("resolveMcpTransport", () => {
158162});
159163160164expect(runtimeFetchMock).toHaveBeenCalledTimes(2);
161-expect(runtimeFetchMock.mock.calls[1]?.[0]).toBe("https://mcp.example.com/mcp");
162-expect(runtimeFetchMock.mock.calls[1]?.[1]?.method).toBe("GET");
163-expect(runtimeFetchMock.mock.calls[1]?.[1]?.body).toBeUndefined();
165+expect(runtimeFetchCall(1)?.[0]).toBe("https://mcp.example.com/mcp");
166+expect(runtimeFetchCall(1)?.[1]?.method).toBe("GET");
167+expect(runtimeFetchCall(1)?.[1]?.body).toBeUndefined();
164168165-const redirectedHeaders = new Headers(runtimeFetchMock.mock.calls[1]?.[1]?.headers);
169+const redirectedHeaders = new Headers(runtimeFetchCall(1)?.[1]?.headers);
166170expect(redirectedHeaders.get("content-type")).toBeNull();
167171});
168172此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。