Add API vs Coding Plan mode selection for Z.AI auth

This commit is contained in:
William Valentin
2026-02-15 20:06:35 -08:00
parent 6a31ee2885
commit 99ad53a1ee
4 changed files with 84 additions and 4 deletions
+21 -1
View File
@@ -60,7 +60,7 @@ describe('zai-auth command', () => {
it('re-prompts and stores new key when credential exists and user answers yes', async () => {
mockLoadStoredZaiAuth.mockReturnValue({ api_key: 'existing-key', created_at: '2026-02-16T00:00:00.000Z' });
mockReadlineAnswers(['y', 'new-zai-key']);
mockReadlineAnswers(['y', '1', 'new-zai-key']);
const program = new Command();
const { registerZaiAuthCommand } = await import('./zai-auth.js');
@@ -77,4 +77,24 @@ describe('zai-auth command', () => {
consoleLog.mockRestore();
consoleError.mockRestore();
});
it('supports --mode plan without interactive mode selection', async () => {
mockLoadStoredZaiAuth.mockReturnValue(null);
mockReadlineAnswers(['new-zai-plan-key']);
const program = new Command();
const { registerZaiAuthCommand } = await import('./zai-auth.js');
registerZaiAuthCommand(program);
const consoleLog = vi.spyOn(console, 'log').mockImplementation(() => undefined);
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => undefined);
await program.parseAsync(['node', 'test', 'zai-auth', '--mode', 'plan']);
expect(mockStoreZaiAuth).toHaveBeenCalledWith('new-zai-plan-key');
expect(consoleError).not.toHaveBeenCalled();
consoleLog.mockRestore();
consoleError.mockRestore();
});
});