|
5 | 5 | */ |
6 | 6 |
|
7 | 7 | import type { Content } from '@google/genai'; |
8 | | -import { mkdtemp, rm, writeFile } from 'node:fs/promises'; |
9 | | -import { tmpdir } from 'node:os'; |
10 | | -import { join } from 'node:path'; |
11 | | -import { afterEach, describe, expect, it, vi } from 'vitest'; |
| 8 | +import { beforeEach, describe, expect, it, vi } from 'vitest'; |
12 | 9 | import type { Config } from '../config/config.js'; |
13 | | -import { generateSessionRecap } from './sessionRecap.js'; |
14 | 10 |
|
15 | | -describe('generateSessionRecap', () => { |
16 | | - let tempDir: string | undefined; |
| 11 | +const runSideQueryMock = vi.hoisted(() => vi.fn()); |
| 12 | + |
| 13 | +vi.mock('../utils/sideQuery.js', () => ({ |
| 14 | + runSideQuery: runSideQueryMock, |
| 15 | +})); |
17 | 16 |
|
18 | | - afterEach(async () => { |
19 | | - if (tempDir) { |
20 | | - await rm(tempDir, { recursive: true, force: true }); |
21 | | - tempDir = undefined; |
22 | | - } |
| 17 | +describe('generateSessionRecap', () => { |
| 18 | + beforeEach(() => { |
| 19 | + vi.resetModules(); |
| 20 | + runSideQueryMock.mockReset(); |
23 | 21 | }); |
24 | 22 |
|
25 | 23 | it('opts into the configured output language preference for recap prompts', async () => { |
26 | | - tempDir = await mkdtemp(join(tmpdir(), 'qwen-session-recap-')); |
27 | | - const outputLanguagePath = join(tempDir, 'output-language.md'); |
28 | | - await writeFile(outputLanguagePath, 'Always answer in Chinese.\n'); |
29 | | - |
30 | 24 | const history: Content[] = [ |
31 | 25 | { role: 'user', parts: [{ text: 'fix the failing auth test' }] }, |
32 | 26 | { role: 'model', parts: [{ text: 'I found the mocked token issue.' }] }, |
33 | 27 | ]; |
34 | | - const generateText = vi.fn().mockResolvedValue({ |
| 28 | + runSideQueryMock.mockResolvedValue({ |
35 | 29 | text: '<recap>Auth test fix is in progress.</recap>', |
36 | 30 | usage: undefined, |
37 | 31 | }); |
38 | 32 | const config = { |
39 | 33 | getGeminiClient: vi.fn(() => ({ |
40 | 34 | getChat: () => ({ getHistory: () => history }), |
41 | 35 | })), |
42 | | - getBaseLlmClient: vi.fn(() => ({ generateText })), |
43 | | - getModel: vi.fn(() => 'qwen3-coder-plus'), |
44 | | - getOutputLanguageFilePath: vi.fn(() => outputLanguagePath), |
45 | 36 | } as unknown as Config; |
| 37 | + const abortSignal = new AbortController().signal; |
| 38 | + const { generateSessionRecap } = await import('./sessionRecap.js'); |
46 | 39 |
|
47 | | - const result = await generateSessionRecap( |
48 | | - config, |
49 | | - new AbortController().signal, |
50 | | - ); |
| 40 | + const result = await generateSessionRecap(config, abortSignal); |
51 | 41 |
|
52 | 42 | expect(result).toBe('Auth test fix is in progress.'); |
53 | | - expect(generateText).toHaveBeenCalledWith( |
| 43 | + expect(runSideQueryMock).toHaveBeenCalledWith( |
| 44 | + config, |
54 | 45 | expect.objectContaining({ |
| 46 | + purpose: 'session-recap', |
| 47 | + respectOutputLanguagePreference: true, |
55 | 48 | systemInstruction: expect.stringContaining( |
56 | 49 | 'You generate session recaps', |
57 | 50 | ), |
58 | | - promptId: 'side-query:session-recap', |
59 | 51 | maxAttempts: 1, |
| 52 | + abortSignal, |
60 | 53 | }), |
61 | 54 | ); |
62 | | - expect(generateText).toHaveBeenCalledWith( |
| 55 | + expect(runSideQueryMock).toHaveBeenCalledWith( |
| 56 | + config, |
63 | 57 | expect.objectContaining({ |
64 | | - systemInstruction: expect.stringContaining( |
65 | | - 'User output language preference from output-language.md:\nAlways answer in Chinese.', |
66 | | - ), |
| 58 | + contents: expect.arrayContaining(history), |
67 | 59 | }), |
68 | 60 | ); |
69 | 61 | }); |
|
0 commit comments