fix(coding-agent): warn on Anthropic subscription auth
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
import { InteractiveMode } from "../src/modes/interactive/interactive-mode.js";
|
||||
|
||||
describe("InteractiveMode.maybeWarnAboutAnthropicSubscriptionAuth", () => {
|
||||
test("warns once when Anthropic subscription auth is detected", async () => {
|
||||
const fakeThis: any = {
|
||||
anthropicSubscriptionWarningShown: false,
|
||||
session: {
|
||||
modelRegistry: {
|
||||
authStorage: {
|
||||
get: vi.fn().mockReturnValue(undefined),
|
||||
},
|
||||
getApiKeyForProvider: vi.fn().mockResolvedValue("sk-ant-oat01-test"),
|
||||
},
|
||||
},
|
||||
showWarning: vi.fn(),
|
||||
};
|
||||
|
||||
await (InteractiveMode as any).prototype.maybeWarnAboutAnthropicSubscriptionAuth.call(fakeThis, {
|
||||
provider: "anthropic",
|
||||
});
|
||||
await (InteractiveMode as any).prototype.maybeWarnAboutAnthropicSubscriptionAuth.call(fakeThis, {
|
||||
provider: "anthropic",
|
||||
});
|
||||
|
||||
expect(fakeThis.showWarning).toHaveBeenCalledTimes(1);
|
||||
expect(fakeThis.session.modelRegistry.getApiKeyForProvider).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test("warns when Anthropic OAuth is stored even if token refresh lookup would fail", async () => {
|
||||
const fakeThis: any = {
|
||||
anthropicSubscriptionWarningShown: false,
|
||||
session: {
|
||||
modelRegistry: {
|
||||
authStorage: {
|
||||
get: vi.fn().mockReturnValue({ type: "oauth" }),
|
||||
},
|
||||
getApiKeyForProvider: vi.fn().mockResolvedValue(undefined),
|
||||
},
|
||||
},
|
||||
showWarning: vi.fn(),
|
||||
};
|
||||
|
||||
await (InteractiveMode as any).prototype.maybeWarnAboutAnthropicSubscriptionAuth.call(fakeThis, {
|
||||
provider: "anthropic",
|
||||
});
|
||||
|
||||
expect(fakeThis.showWarning).toHaveBeenCalledTimes(1);
|
||||
expect(fakeThis.session.modelRegistry.getApiKeyForProvider).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("does not warn for non-Anthropic models", async () => {
|
||||
const fakeThis: any = {
|
||||
anthropicSubscriptionWarningShown: false,
|
||||
session: {
|
||||
modelRegistry: {
|
||||
authStorage: {
|
||||
get: vi.fn(),
|
||||
},
|
||||
getApiKeyForProvider: vi.fn(),
|
||||
},
|
||||
},
|
||||
showWarning: vi.fn(),
|
||||
};
|
||||
|
||||
await (InteractiveMode as any).prototype.maybeWarnAboutAnthropicSubscriptionAuth.call(fakeThis, {
|
||||
provider: "openai",
|
||||
});
|
||||
|
||||
expect(fakeThis.showWarning).not.toHaveBeenCalled();
|
||||
expect(fakeThis.session.modelRegistry.getApiKeyForProvider).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user