| |
| |
| |
| |
| |
|
|
| import { vi } from 'vitest'; |
| import { CommandContext } from '../ui/commands/types.js'; |
| import { LoadedSettings } from '../config/settings.js'; |
| import { GitService } from '@qwen-code/qwen-code-core'; |
| import { SessionStatsState } from '../ui/contexts/SessionContext.js'; |
|
|
| |
| type DeepPartial<T> = T extends object |
| ? { |
| [P in keyof T]?: DeepPartial<T[P]>; |
| } |
| : T; |
|
|
| |
| |
| |
| |
| |
| |
| |
| export const createMockCommandContext = ( |
| overrides: DeepPartial<CommandContext> = {}, |
| ): CommandContext => { |
| const defaultMocks: CommandContext = { |
| invocation: { |
| raw: '', |
| name: '', |
| args: '', |
| }, |
| services: { |
| config: null, |
| settings: { merged: {} } as LoadedSettings, |
| git: undefined as GitService | undefined, |
| logger: { |
| log: vi.fn(), |
| logMessage: vi.fn(), |
| saveCheckpoint: vi.fn(), |
| loadCheckpoint: vi.fn().mockResolvedValue([]), |
| |
| } as any, |
| }, |
| ui: { |
| addItem: vi.fn(), |
| clear: vi.fn(), |
| setDebugMessage: vi.fn(), |
| pendingItem: null, |
| setPendingItem: vi.fn(), |
| loadHistory: vi.fn(), |
| toggleCorgiMode: vi.fn(), |
| toggleVimEnabled: vi.fn(), |
| |
| } as any, |
| session: { |
| sessionShellAllowlist: new Set<string>(), |
| stats: { |
| sessionStartTime: new Date(), |
| lastPromptTokenCount: 0, |
| metrics: { |
| models: {}, |
| tools: { |
| totalCalls: 0, |
| totalSuccess: 0, |
| totalFail: 0, |
| totalDurationMs: 0, |
| totalDecisions: { accept: 0, reject: 0, modify: 0 }, |
| byName: {}, |
| }, |
| }, |
| promptCount: 0, |
| } as SessionStatsState, |
| }, |
| }; |
|
|
| |
| const merge = (target: any, source: any): any => { |
| const output = { ...target }; |
|
|
| for (const key in source) { |
| if (Object.prototype.hasOwnProperty.call(source, key)) { |
| const sourceValue = source[key]; |
| const targetValue = output[key]; |
|
|
| if ( |
| |
| Object.prototype.toString.call(sourceValue) === '[object Object]' && |
| Object.prototype.toString.call(targetValue) === '[object Object]' |
| ) { |
| output[key] = merge(targetValue, sourceValue); |
| } else { |
| |
| output[key] = sourceValue; |
| } |
| } |
| } |
| return output; |
| }; |
|
|
| return merge(defaultMocks, overrides); |
| }; |
|
|