Add --mode api|token support to anthropic-auth
This commit is contained in:
@@ -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/);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user