






















@@ -74,6 +74,16 @@ function latestAnthropicRequestHeaders() {
7474return new Headers(latestAnthropicRequest().init?.headers);
7575}
767677+function guardedFetchCall(
78+callIndex = 0,
79+): [unknown, { method?: unknown; headers?: HeadersInit } | undefined] {
80+const call = guardedFetchMock.mock.calls[callIndex];
81+if (!call) {
82+throw new Error(`expected guarded fetch call ${callIndex + 1}`);
83+}
84+return call as [unknown, { method?: unknown; headers?: HeadersInit } | undefined];
85+}
86+7787function requireRecord(value: unknown, label: string): Record<string, unknown> {
7888if (!value || typeof value !== "object" || Array.isArray(value)) {
7989throw new Error(`Expected ${label}`);
@@ -178,7 +188,7 @@ describe("anthropic transport stream", () => {
178188);
179189180190expect(buildGuardedModelFetchMock).toHaveBeenCalledWith(model);
181-const [url, init] = guardedFetchMock.mock.calls.at(0) ?? [];
191+const [url, init] = guardedFetchCall();
182192expect(url).toBe("https://api.anthropic.com/v1/messages");
183193expect(init?.method).toBe("POST");
184194const headers = new Headers(init?.headers);
@@ -241,8 +251,9 @@ describe("anthropic transport stream", () => {
241251} as AnthropicStreamOptions,
242252);
243253244-expect(guardedFetchMock.mock.calls.at(0)?.[0]).toBe("https://custom-proxy.example/v1/messages");
245-expect(guardedFetchMock.mock.calls.at(0)?.[1]?.method).toBe("POST");
254+const [url, init] = guardedFetchCall();
255+expect(url).toBe("https://custom-proxy.example/v1/messages");
256+expect(init?.method).toBe("POST");
246257expect(latestAnthropicRequestHeaders().get("anthropic-beta")).toBeNull();
247258});
248259@@ -468,8 +479,9 @@ describe("anthropic transport stream", () => {
468479);
469480const result = await stream.result();
470481471-expect(guardedFetchMock.mock.calls.at(0)?.[0]).toBe("https://api.anthropic.com/v1/messages");
472-const headers = new Headers(guardedFetchMock.mock.calls.at(0)?.[1]?.headers);
482+const [url, init] = guardedFetchCall();
483+expect(url).toBe("https://api.anthropic.com/v1/messages");
484+const headers = new Headers(init?.headers);
473485expect(headers.get("authorization")).toBe("Bearer sk-ant-oat-example");
474486expect(headers.get("x-app")).toBe("cli");
475487expect(headers.get("user-agent")).toContain("claude-cli/");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。