2026-07-27 16:12:40 +08:00
|
|
|
|
// @vitest-environment jsdom
|
|
|
|
|
|
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
|
|
|
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
|
|
import type { ModelTarget } from '@deepseek-ai/dsh-client-connection/client'
|
|
|
|
|
|
import { createSnapshotStore } from '@deepseek-ai/dsh-client-runtime/client'
|
2026-07-30 01:04:56 +08:00
|
|
|
|
import type { ComponentProps } from 'react'
|
2026-07-27 16:12:40 +08:00
|
|
|
|
import type { ModelDirectoryState } from '../src/client/directory.ts'
|
|
|
|
|
|
import { ModelSelect } from '../src/client/ModelSelect.tsx'
|
2026-07-30 01:04:56 +08:00
|
|
|
|
import { zh } from '../src/client/locales.ts'
|
2026-07-30 01:04:58 +08:00
|
|
|
|
import { zh as commonZh } from '@deepseek-ai/dsh-client-locale/src/locales/zh.ts'
|
2026-07-30 01:04:56 +08:00
|
|
|
|
|
2026-07-30 01:04:58 +08:00
|
|
|
|
// The seat's key domain is model ∪ common; the stub mirrors the real lookup
|
|
|
|
|
|
// chain: package dictionary, then common vocabulary, then the key.
|
2026-07-30 01:04:56 +08:00
|
|
|
|
const t: ComponentProps<typeof ModelSelect>['t'] = (key, params) => {
|
2026-07-30 01:04:58 +08:00
|
|
|
|
const template = (zh as Record<string, string>)[key]
|
|
|
|
|
|
?? (commonZh as Record<string, string>)[key]
|
|
|
|
|
|
?? key
|
2026-07-30 01:04:56 +08:00
|
|
|
|
return params === undefined
|
|
|
|
|
|
? template
|
|
|
|
|
|
: template.replace(/\{(\w+)\}/g, (match, name: string) => name in params ? String(params[name]) : match)
|
|
|
|
|
|
}
|
2026-07-27 16:12:40 +08:00
|
|
|
|
|
|
|
|
|
|
const reasoning = {
|
|
|
|
|
|
efforts: [
|
|
|
|
|
|
{ id: 'off', name: 'Off' },
|
|
|
|
|
|
{ id: 'high', name: 'High' },
|
|
|
|
|
|
{ id: 'max', name: 'Max', description: 'Largest budget' },
|
|
|
|
|
|
],
|
|
|
|
|
|
defaultEffort: 'high',
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function state(overrides: Partial<ModelDirectoryState> = {}): ModelDirectoryState {
|
|
|
|
|
|
return {
|
2026-07-29 16:36:07 +08:00
|
|
|
|
current: { provider: 'deepseek-official', model: 'deepseek-v4-flash' },
|
2026-07-27 16:12:40 +08:00
|
|
|
|
groups: [{
|
2026-07-29 16:36:07 +08:00
|
|
|
|
id: 'deepseek-official',
|
2026-07-27 16:12:40 +08:00
|
|
|
|
name: 'DeepSeek',
|
|
|
|
|
|
models: [{ id: 'deepseek-v4-flash', name: 'DeepSeek-V4-Flash', reasoning }],
|
|
|
|
|
|
}],
|
|
|
|
|
|
failures: [],
|
|
|
|
|
|
status: 'ready',
|
|
|
|
|
|
error: null,
|
|
|
|
|
|
...overrides,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
afterEach(cleanup)
|
|
|
|
|
|
|
|
|
|
|
|
describe('ModelSelect reasoning effort', () => {
|
|
|
|
|
|
it('renders adapter metadata and submits the effort as part of the session target', async () => {
|
2026-07-30 00:57:38 +08:00
|
|
|
|
const directory = createSnapshotStore<ModelDirectoryState>(state())
|
2026-07-27 16:12:40 +08:00
|
|
|
|
const select = vi.fn(async (target: ModelTarget) => {
|
2026-07-30 00:57:38 +08:00
|
|
|
|
directory.set(state({ current: target }))
|
2026-07-27 16:12:40 +08:00
|
|
|
|
return true
|
|
|
|
|
|
})
|
|
|
|
|
|
render(<ModelSelect
|
|
|
|
|
|
locked={false}
|
2026-07-30 23:33:07 +08:00
|
|
|
|
available
|
2026-07-27 16:12:40 +08:00
|
|
|
|
directory={directory}
|
|
|
|
|
|
load={vi.fn()}
|
|
|
|
|
|
select={select}
|
2026-07-30 01:04:56 +08:00
|
|
|
|
t={t}
|
2026-07-27 16:12:40 +08:00
|
|
|
|
/>)
|
|
|
|
|
|
|
|
|
|
|
|
const trigger = screen.getByRole('button', {
|
|
|
|
|
|
name: '选择模型,当前 DeepSeek-V4-Flash,推理等级 High',
|
|
|
|
|
|
})
|
|
|
|
|
|
fireEvent.click(trigger)
|
2026-07-30 01:04:56 +08:00
|
|
|
|
fireEvent.click(screen.getByRole('menuitem', { name: /推理等级/ }))
|
2026-07-27 16:12:40 +08:00
|
|
|
|
expect(screen.getAllByRole('menuitemradio').map(item => item.textContent))
|
|
|
|
|
|
.toEqual(['Off', 'High', 'MaxLargest budget'])
|
|
|
|
|
|
|
|
|
|
|
|
fireEvent.click(screen.getByRole('menuitemradio', { name: /Max/ }))
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
|
|
expect(select).toHaveBeenCalledWith({
|
2026-07-29 16:36:07 +08:00
|
|
|
|
provider: 'deepseek-official',
|
2026-07-27 16:12:40 +08:00
|
|
|
|
model: 'deepseek-v4-flash',
|
|
|
|
|
|
reasoningEffort: 'max',
|
|
|
|
|
|
})
|
|
|
|
|
|
expect(trigger.getAttribute('aria-label')).toBe('选择模型,当前 DeepSeek-V4-Flash,推理等级 Max')
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('offers provider default only when the adapter does not configure a model default', () => {
|
|
|
|
|
|
const directory = createSnapshotStore(state({
|
|
|
|
|
|
groups: [{
|
|
|
|
|
|
id: 'provider',
|
|
|
|
|
|
name: 'Provider',
|
|
|
|
|
|
models: [{
|
|
|
|
|
|
id: 'model',
|
|
|
|
|
|
name: 'Model',
|
|
|
|
|
|
reasoning: { efforts: [{ id: 'standard', name: 'Standard' }] },
|
|
|
|
|
|
}],
|
|
|
|
|
|
}],
|
|
|
|
|
|
current: { provider: 'provider', model: 'model' },
|
|
|
|
|
|
}))
|
|
|
|
|
|
render(<ModelSelect
|
|
|
|
|
|
locked={false}
|
2026-07-30 23:33:07 +08:00
|
|
|
|
available
|
2026-07-27 16:12:40 +08:00
|
|
|
|
directory={directory}
|
|
|
|
|
|
load={vi.fn()}
|
|
|
|
|
|
select={vi.fn().mockResolvedValue(true)}
|
2026-07-30 01:04:56 +08:00
|
|
|
|
t={t}
|
2026-07-27 16:12:40 +08:00
|
|
|
|
/>)
|
|
|
|
|
|
|
|
|
|
|
|
fireEvent.click(screen.getByRole('button', {
|
2026-07-30 00:57:38 +08:00
|
|
|
|
name: '选择模型,当前 Model,推理等级 Default',
|
2026-07-27 16:12:40 +08:00
|
|
|
|
}))
|
2026-07-30 01:04:56 +08:00
|
|
|
|
fireEvent.click(screen.getByRole('menuitem', { name: /推理等级/ }))
|
2026-07-27 16:12:40 +08:00
|
|
|
|
expect(screen.getAllByRole('menuitemradio').map(item => item.textContent))
|
2026-07-30 00:57:38 +08:00
|
|
|
|
.toEqual(['Default', 'Standard'])
|
2026-07-27 16:12:40 +08:00
|
|
|
|
})
|
2026-07-31 14:08:59 +08:00
|
|
|
|
|
|
|
|
|
|
it('prompts for a new selection when the current target is no longer advertised', () => {
|
|
|
|
|
|
const directory = createSnapshotStore(state({
|
|
|
|
|
|
current: { provider: 'deepseek-official', model: 'removed-model' },
|
|
|
|
|
|
}))
|
|
|
|
|
|
const select = vi.fn().mockResolvedValue(true)
|
|
|
|
|
|
render(<ModelSelect
|
|
|
|
|
|
locked={false}
|
2026-08-03 16:20:55 +08:00
|
|
|
|
available
|
2026-07-31 14:08:59 +08:00
|
|
|
|
directory={directory}
|
|
|
|
|
|
load={vi.fn()}
|
|
|
|
|
|
select={select}
|
|
|
|
|
|
t={t}
|
|
|
|
|
|
/>)
|
|
|
|
|
|
|
|
|
|
|
|
const trigger = screen.getByRole('button', { name: '选择模型' })
|
|
|
|
|
|
expect(trigger.textContent).toContain('选择模型')
|
|
|
|
|
|
fireEvent.click(trigger)
|
|
|
|
|
|
expect(screen.queryByRole('menuitem', { name: /推理等级/ })).toBeNull()
|
|
|
|
|
|
fireEvent.click(screen.getByRole('menuitem', { name: /模型/ }))
|
|
|
|
|
|
expect(screen.queryByText('removed-model')).toBeNull()
|
|
|
|
|
|
expect(screen.getByRole('menuitemradio', { name: 'DeepSeek-V4-Flash' })).toBeTruthy()
|
|
|
|
|
|
})
|
2026-08-03 16:20:55 +08:00
|
|
|
|
|
2026-07-30 23:33:07 +08:00
|
|
|
|
it('renders no Agent-bound control for an addressed subagent session', () => {
|
|
|
|
|
|
const load = vi.fn()
|
|
|
|
|
|
render(<ModelSelect
|
|
|
|
|
|
locked={false}
|
|
|
|
|
|
available={false}
|
|
|
|
|
|
directory={createSnapshotStore(state())}
|
|
|
|
|
|
load={load}
|
|
|
|
|
|
select={vi.fn().mockResolvedValue(false)}
|
|
|
|
|
|
t={t}
|
|
|
|
|
|
/>)
|
|
|
|
|
|
|
|
|
|
|
|
expect(screen.queryByRole('button')).toBeNull()
|
|
|
|
|
|
expect(load).not.toHaveBeenCalled()
|
|
|
|
|
|
})
|
2026-07-27 16:12:40 +08:00
|
|
|
|
})
|