audit follow-up: reduce warning hotspots in automation and gateway tests
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import type { ManagedSession } from '../../session/index.js';
|
||||
import type { ModelClient } from '../../models/types.js';
|
||||
import type { ModelRouter } from '../../models/router.js';
|
||||
|
||||
const {
|
||||
mockLoadStoredAnthropicAuth,
|
||||
@@ -33,6 +36,30 @@ vi.mock('node:readline', () => ({
|
||||
emitKeypressEvents: vi.fn(),
|
||||
}));
|
||||
|
||||
function asSession(value: unknown): ManagedSession {
|
||||
return value as ManagedSession;
|
||||
}
|
||||
|
||||
function asModelClient(value: unknown): ModelClient {
|
||||
return value as ModelClient;
|
||||
}
|
||||
|
||||
function asModelRouter(value: unknown): ModelRouter {
|
||||
return value as ModelRouter;
|
||||
}
|
||||
|
||||
function minimalTuiPrivates(value: unknown): {
|
||||
rl: { pause: () => void; resume: () => void };
|
||||
prompt: (text: string) => Promise<string>;
|
||||
handleLoginCommand: (provider: string) => Promise<void>;
|
||||
} {
|
||||
return value as {
|
||||
rl: { pause: () => void; resume: () => void };
|
||||
prompt: (text: string) => Promise<string>;
|
||||
handleLoginCommand: (provider: string) => Promise<void>;
|
||||
};
|
||||
}
|
||||
|
||||
describe('MinimalTui login re-auth confirmation', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
@@ -57,20 +84,20 @@ describe('MinimalTui login re-auth confirmation', () => {
|
||||
};
|
||||
|
||||
const tui = new MinimalTui({
|
||||
session: mockSession as any,
|
||||
modelClient: {} as any,
|
||||
modelRouter: {} as any,
|
||||
session: asSession(mockSession),
|
||||
modelClient: asModelClient({}),
|
||||
modelRouter: asModelRouter({}),
|
||||
systemPrompt: 'test',
|
||||
});
|
||||
|
||||
(tui as any).rl = { pause: vi.fn(), resume: vi.fn() };
|
||||
const promptMock = vi.spyOn(tui as any, 'prompt')
|
||||
minimalTuiPrivates(tui).rl = { pause: vi.fn(), resume: vi.fn() };
|
||||
const promptMock = vi.spyOn(minimalTuiPrivates(tui), 'prompt')
|
||||
.mockResolvedValueOnce('') // default -> API key path
|
||||
.mockResolvedValueOnce('n'); // confirmation
|
||||
|
||||
const consoleLog = vi.spyOn(console, 'log').mockImplementation(() => undefined);
|
||||
|
||||
await (tui as any).handleLoginCommand('anthropic');
|
||||
await minimalTuiPrivates(tui).handleLoginCommand('anthropic');
|
||||
|
||||
expect(promptMock).toHaveBeenCalled();
|
||||
expect(mockStoreAnthropicAuth).not.toHaveBeenCalled();
|
||||
@@ -98,23 +125,23 @@ describe('MinimalTui login re-auth confirmation', () => {
|
||||
};
|
||||
|
||||
const tui = new MinimalTui({
|
||||
session: mockSession as any,
|
||||
modelClient: {} as any,
|
||||
modelRouter: {} as any,
|
||||
session: asSession(mockSession),
|
||||
modelClient: asModelClient({}),
|
||||
modelRouter: asModelRouter({}),
|
||||
systemPrompt: 'test',
|
||||
});
|
||||
|
||||
const pause = vi.fn();
|
||||
const resume = vi.fn();
|
||||
(tui as any).rl = { pause, resume };
|
||||
vi.spyOn(tui as any, 'prompt')
|
||||
minimalTuiPrivates(tui).rl = { pause, resume };
|
||||
vi.spyOn(minimalTuiPrivates(tui), 'prompt')
|
||||
.mockResolvedValueOnce('') // default -> API key path
|
||||
.mockResolvedValueOnce('y'); // confirmation
|
||||
|
||||
const consoleLog = vi.spyOn(console, 'log').mockImplementation(() => undefined);
|
||||
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
||||
|
||||
await (tui as any).handleLoginCommand('anthropic');
|
||||
await minimalTuiPrivates(tui).handleLoginCommand('anthropic');
|
||||
|
||||
expect(mockStoreAnthropicAuth).toHaveBeenCalledWith('new-anthropic-key');
|
||||
expect(pause).toHaveBeenCalled();
|
||||
|
||||
Reference in New Issue
Block a user