| 1 | import { describe, expect, it, vi } from 'vitest' |
| 2 | |
| 3 | const modelRuntimeState = vi.hoisted(() => ({ |
| 4 | bindCurrentModelTemperatureControl: vi.fn() |
| 5 | })) |
| 6 | |
| 7 | vi.mock('../../../src/main/config/locale-utils', () => ({ |
| 8 | readAppLocale: vi.fn(async () => 'zh'), |
| 9 | uiText: vi.fn((_locale: string, zh: string) => zh) |
| 10 | })) |
| 11 | |
| 12 | vi.mock('../../../src/main/agent-runtime/model', () => ({ |
| 13 | bindCurrentModelTemperatureControl: modelRuntimeState.bindCurrentModelTemperatureControl |
| 14 | })) |
| 15 | |
| 16 | vi.mock('@shared/model-timeout', () => ({ |
| 17 | MODEL_TIMEOUT_PROFILES: ['planning', 'design', 'agent', 'document'], |
| 18 | resolveModelTimeoutMs: vi.fn(() => 1000) |
| 19 | })) |
| 20 | |
| 21 | describe('resolveModelConfigForTask temperature control', () => { |
| 22 | it('binds the selected model temperature setting to the current async task', async () => { |
| 23 | modelRuntimeState.bindCurrentModelTemperatureControl.mockClear() |
| 24 | const { resolveModelConfigForTask } = |
| 25 | await import('../../../src/main/config/model-config-utils') |
| 26 | const ctx = { |
| 27 | db: { |
| 28 | getModelConfig: vi.fn(async () => ({ |
| 29 | id: 'model-1', |
| 30 | name: 'Reasoning model', |
| 31 | provider: 'openai', |
| 32 | model: 'reasoner', |
| 33 | apiKey: 'secret', |
| 34 | baseUrl: '', |
| 35 | maxTokens: 4096, |
| 36 | disableTemperature: 1, |
| 37 | thinkingParameterMode: 'omit' |
| 38 | })) |
| 39 | }, |
| 40 | decryptApiKey: vi.fn((value: unknown) => String(value)) |
| 41 | } |
| 42 | |
| 43 | const config = await resolveModelConfigForTask(ctx as never, { |
| 44 | modelConfigId: 'model-1', |
| 45 | purpose: 'test' |
| 46 | }) |
| 47 | await Promise.resolve() |
| 48 | |
| 49 | expect(config.disableTemperature).toBe(true) |
| 50 | expect(config.thinkingParameterMode).toBe('omit') |
| 51 | expect(modelRuntimeState.bindCurrentModelTemperatureControl).toHaveBeenCalledWith( |
| 52 | expect.objectContaining({ |
| 53 | id: 'model-1', |
| 54 | disableTemperature: true, |
| 55 | thinkingParameterMode: 'omit' |
| 56 | }) |
| 57 | ) |
| 58 | }) |
| 59 | }) |
| 60 |