
























@@ -72,6 +72,8 @@ function levelIds(profile: unknown): Array<unknown> {
7272return (levels as Array<{ id?: unknown }>).map((level) => level.id);
7373}
747475+const ANTHROPIC_SETUP_TOKEN = `sk-ant-oat01-${"a".repeat(80)}`;
76+7577describe("anthropic provider replay hooks", () => {
7678it("registers the claude-cli backend", () => {
7779const captured = capturePluginRegistration({ register: anthropicPlugin.register });
@@ -684,6 +686,61 @@ describe("anthropic provider replay hooks", () => {
684686expect(normalized).toBeUndefined();
685687});
686688689+it("stores setup-token expiry from a bounded duration", async () => {
690+vi.useFakeTimers();
691+vi.setSystemTime(1_000);
692+try {
693+const provider = await registerSingleProviderPlugin(anthropicPlugin);
694+const setupTokenAuth = provider.auth.find((entry) => entry.id === "setup-token");
695+if (!setupTokenAuth) {
696+throw new Error("expected Anthropic setup-token auth method");
697+}
698+699+const result = await setupTokenAuth.run({
700+opts: {
701+token: ANTHROPIC_SETUP_TOKEN,
702+tokenExpiresIn: "1h",
703+},
704+} as never);
705+706+expect(result?.profiles[0]?.credential).toMatchObject({
707+type: "token",
708+provider: "anthropic",
709+token: ANTHROPIC_SETUP_TOKEN,
710+expires: 3_601_000,
711+});
712+} finally {
713+vi.useRealTimers();
714+}
715+});
716+717+it("omits setup-token expiry when duration overflows the Date range", async () => {
718+vi.useFakeTimers();
719+vi.setSystemTime(8_640_000_000_000_000);
720+try {
721+const provider = await registerSingleProviderPlugin(anthropicPlugin);
722+const setupTokenAuth = provider.auth.find((entry) => entry.id === "setup-token");
723+if (!setupTokenAuth) {
724+throw new Error("expected Anthropic setup-token auth method");
725+}
726+727+const result = await setupTokenAuth.run({
728+opts: {
729+token: ANTHROPIC_SETUP_TOKEN,
730+tokenExpiresIn: "1h",
731+},
732+} as never);
733+734+expect(result?.profiles[0]?.credential).toEqual({
735+type: "token",
736+provider: "anthropic",
737+token: ANTHROPIC_SETUP_TOKEN,
738+});
739+} finally {
740+vi.useRealTimers();
741+}
742+});
743+687744it("resolves claude-cli synthetic oauth auth", async () => {
688745readClaudeCliCredentialsForRuntimeMock.mockReset();
689746readClaudeCliCredentialsForRuntimeMock.mockReturnValue({
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。