mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-07 23:31:07 +00:00
45 lines
1.7 KiB
TypeScript
45 lines
1.7 KiB
TypeScript
import type { StreamFn } from "@mariozechner/pi-agent-core";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { __testing, createAnthropicBetaHeadersWrapper } from "./stream-wrappers.js";
|
|
|
|
const CONTEXT_1M_BETA = "context-1m-2025-08-07";
|
|
const OAUTH_BETA = "oauth-2025-04-20";
|
|
|
|
function runWrapper(apiKey: string | undefined): Record<string, string> | undefined {
|
|
const captured: { headers?: Record<string, string> } = {};
|
|
const base: StreamFn = (_model, _context, options) => {
|
|
captured.headers = options?.headers;
|
|
return {} as never;
|
|
};
|
|
const wrapper = createAnthropicBetaHeadersWrapper(base, [CONTEXT_1M_BETA]);
|
|
wrapper(
|
|
{ provider: "anthropic", id: "claude-opus-4-6" } as never,
|
|
{} as never,
|
|
{ apiKey } as never,
|
|
);
|
|
return captured.headers;
|
|
}
|
|
|
|
describe("anthropic stream wrappers", () => {
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("strips context-1m for subscription setup-token auth and warns", () => {
|
|
const warn = vi.spyOn(__testing.log, "warn").mockImplementation(() => undefined);
|
|
const headers = runWrapper("sk-ant-oat01-123");
|
|
expect(headers?.["anthropic-beta"]).toBeDefined();
|
|
expect(headers?.["anthropic-beta"]).toContain(OAUTH_BETA);
|
|
expect(headers?.["anthropic-beta"]).not.toContain(CONTEXT_1M_BETA);
|
|
expect(warn).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
it("keeps context-1m for API key auth", () => {
|
|
const warn = vi.spyOn(__testing.log, "warn").mockImplementation(() => undefined);
|
|
const headers = runWrapper("sk-ant-api-123");
|
|
expect(headers?.["anthropic-beta"]).toBeDefined();
|
|
expect(headers?.["anthropic-beta"]).toContain(CONTEXT_1M_BETA);
|
|
expect(warn).not.toHaveBeenCalled();
|
|
});
|
|
});
|