


















@@ -30,6 +30,13 @@ function createTestDeps() {
3030};
3131}
323233+function requireRecord(value: unknown, label: string): Record<string, unknown> {
34+if (!value || typeof value !== "object" || Array.isArray(value)) {
35+throw new Error(`Expected ${label} to be an object`);
36+}
37+return value as Record<string, unknown>;
38+}
39+3340describe("createMantleAnthropicStreamFn", () => {
3441it("uses authToken bearer auth for Mantle Anthropic requests", () => {
3542const stream = { kind: "anthropic-stream" };
@@ -46,31 +53,24 @@ describe("createMantleAnthropicStreamFn", () => {
4653});
47544855expect(result).toBe(stream);
49-expect(deps.createClient).toHaveBeenCalledWith(
50-expect.objectContaining({
51-apiKey: null,
52-authToken: "bedrock-bearer-token",
53-baseURL: "https://bedrock-mantle.us-east-1.api.aws/anthropic",
54-defaultHeaders: expect.objectContaining({
55-accept: "application/json",
56-"anthropic-beta": "fine-grained-tool-streaming-2025-05-14",
57-"X-Test": "model-header",
58-"X-Caller": "caller-header",
59-}),
60-}),
61-);
62-expect(deps.stream).toHaveBeenCalledWith(
63-model,
64-context,
65-expect.objectContaining({
66-client: expect.objectContaining({
67-options: expect.objectContaining({
68-authToken: "bedrock-bearer-token",
69-}),
70-}),
71-thinkingEnabled: false,
72-}),
56+const clientOptions = requireRecord(deps.createClient.mock.calls[0]?.[0], "client options");
57+expect(clientOptions.apiKey).toBeNull();
58+expect(clientOptions.authToken).toBe("bedrock-bearer-token");
59+expect(clientOptions.baseURL).toBe("https://bedrock-mantle.us-east-1.api.aws/anthropic");
60+const defaultHeaders = requireRecord(clientOptions.defaultHeaders, "default headers");
61+expect(defaultHeaders.accept).toBe("application/json");
62+expect(defaultHeaders["anthropic-beta"]).toBe("fine-grained-tool-streaming-2025-05-14");
63+expect(defaultHeaders["X-Test"]).toBe("model-header");
64+expect(defaultHeaders["X-Caller"]).toBe("caller-header");
65+66+expect(deps.stream.mock.calls[0]?.[0]).toBe(model);
67+expect(deps.stream.mock.calls[0]?.[1]).toBe(context);
68+const streamOptions = requireRecord(deps.stream.mock.calls[0]?.[2], "stream options");
69+const client = requireRecord(streamOptions.client, "stream client");
70+expect(requireRecord(client.options, "stream client options").authToken).toBe(
71+"bedrock-bearer-token",
7372);
73+expect(streamOptions.thinkingEnabled).toBe(false);
7474});
75757676it("omits unsupported Opus 4.7 sampling and reasoning overrides", () => {
@@ -85,14 +85,11 @@ describe("createMantleAnthropicStreamFn", () => {
8585reasoning: "high",
8686});
878788-expect(deps.stream).toHaveBeenCalledWith(
89-model,
90-context,
91-expect.objectContaining({
92-temperature: undefined,
93-thinkingEnabled: false,
94-}),
95-);
88+expect(deps.stream.mock.calls[0]?.[0]).toBe(model);
89+expect(deps.stream.mock.calls[0]?.[1]).toBe(context);
90+const streamOptions = requireRecord(deps.stream.mock.calls[0]?.[2], "stream options");
91+expect(streamOptions.temperature).toBeUndefined();
92+expect(streamOptions.thinkingEnabled).toBe(false);
9693});
97949895it("normalizes Mantle provider URLs to the Anthropic endpoint", () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。