Add --mode api|token support to anthropic-auth

This commit is contained in:
William Valentin
2026-02-15 20:20:39 -08:00
parent 42c526bce9
commit 4b8007c90d
3 changed files with 92 additions and 3 deletions
+52
View File
@@ -129,4 +129,56 @@ describe('anthropic-auth command', () => {
consoleLog.mockRestore();
consoleError.mockRestore();
});
it('accepts --mode api and stores API key', async () => {
mockLoadStoredAnthropicAuth.mockReturnValue(null);
mockReadlineAnswers(['sk-ant-from-mode']);
const program = new Command();
const { registerAnthropicAuthCommand } = await import('./anthropic-auth.js');
registerAnthropicAuthCommand(program);
const consoleLog = vi.spyOn(console, 'log').mockImplementation(() => undefined);
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => undefined);
await program.parseAsync(['node', 'test', 'anthropic-auth', '--mode', 'api']);
expect(mockStoreAnthropicAuth).toHaveBeenCalledWith('sk-ant-from-mode');
expect(mockStoreAnthropicAuthToken).not.toHaveBeenCalled();
expect(consoleError).not.toHaveBeenCalled();
consoleLog.mockRestore();
consoleError.mockRestore();
});
it('accepts --mode token and stores auth token', async () => {
mockLoadStoredAnthropicAuthToken.mockReturnValue(null);
mockReadlineAnswers(['tok-from-mode']);
const program = new Command();
const { registerAnthropicAuthCommand } = await import('./anthropic-auth.js');
registerAnthropicAuthCommand(program);
const consoleLog = vi.spyOn(console, 'log').mockImplementation(() => undefined);
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => undefined);
await program.parseAsync(['node', 'test', 'anthropic-auth', '--mode', 'token']);
expect(mockStoreAnthropicAuthToken).toHaveBeenCalledWith('tok-from-mode');
expect(mockStoreAnthropicAuth).not.toHaveBeenCalled();
expect(consoleError).not.toHaveBeenCalled();
consoleLog.mockRestore();
consoleError.mockRestore();
});
it('fails on conflicting --token and --mode api options', async () => {
const program = new Command();
const { registerAnthropicAuthCommand } = await import('./anthropic-auth.js');
registerAnthropicAuthCommand(program);
await expect(
program.parseAsync(['node', 'test', 'anthropic-auth', '--token', '--mode', 'api']),
).rejects.toThrow(/Conflicting options/);
});
});