Files
deepseek-harness/packages/client/ui-conversation/tests/submission-policy.client.spec.ts
Chinesezjc b462d5fd69 Merge remote-tracking branch 'origin/master' into feat/web-message-feedback-ui
Adapt to two contract changes master introduced:

- The generated Remote face now wraps every business result in
  RemoteResult, folding carrier failures into an ok:false branch instead
  of rejecting. The controller reads that envelope at its three call
  sites and maps a carrier failure onto the same settled shape the
  controls already render; three specs cover the new branch.
- Client packages split their tsconfig into host and client halves, and
  the host aggregate now compiles any test not named *.client.spec.*.
  Rename this package's specs to the client convention and drop the
  ../connection project reference, which pointed at a solution file that
  no longer carries the client sources.

Keep master's mount loop with its rollback-on-failure in api-remotes and
add messageFeedbackRemote to it.
2026-08-12 10:43:23 +08:00

67 lines
3.0 KiB
TypeScript

// @vitest-environment jsdom
import { describe, expect, it, vi } from 'vitest'
import { stubSettingsScope } from '@deepseek-ai/dsh-client-test-runtime'
import {
ComposerSubmissionPolicy, DEFAULT_BUSY_ENTER_BEHAVIOR,
} from '../src/client/input/submission-policy.ts'
import type { ConversationSettings } from '../src/submission-settings.ts'
describe('ComposerSubmissionPolicy', () => {
it('defaults to Queue and only applies the preference while running', () => {
const policy = new ComposerSubmissionPolicy()
expect(policy.busyEnter.getSnapshot()).toBe(DEFAULT_BUSY_ENTER_BEHAVIOR)
expect(policy.resolve(false, 'enter', true)).toBe('queue')
expect(policy.resolve(false, 'accelerated', true)).toBe('queue')
expect(policy.resolve(true, 'enter', true)).toBe('queue')
expect(policy.resolve(true, 'accelerated', true)).toBe('steer')
expect(policy.resolve(true, 'enter', false)).toBe('queue')
expect(policy.resolve(true, 'accelerated', false)).toBe('queue')
const changed = vi.fn()
policy.busyEnter.subscribe(changed)
policy.setBusyEnter('steer')
expect(changed).toHaveBeenCalledTimes(1)
expect(policy.resolve(true, 'enter', true)).toBe('steer')
expect(policy.resolve(true, 'accelerated', true)).toBe('queue')
expect(policy.resolve(false, 'enter', true)).toBe('queue')
expect(policy.resolve(false, 'accelerated', true)).toBe('queue')
})
it('writes an explicit change through the scope after publishing it locally', () => {
const host = stubSettingsScope<ConversationSettings>()
const observed: string[] = []
let liveBehavior = (): string => 'unconstructed'
const scope: typeof host.scope = {
...host.scope,
set: (field, value) => {
observed.push(`${field}=${String(value)}:${liveBehavior()}`)
return host.scope.set(field, value)
},
}
const policy = new ComposerSubmissionPolicy(scope)
liveBehavior = () => policy.busyEnter.getSnapshot()
policy.setBusyEnter('steer')
expect(observed).toEqual(['busyEnter=steer:steer'])
expect(host.set).toHaveBeenCalledWith('busyEnter', 'steer')
expect(host.set).toHaveBeenCalledOnce()
})
it('adopts a Host preference without writing it back and leaves an identical write untouched', () => {
const host = stubSettingsScope<ConversationSettings>()
const policy = new ComposerSubmissionPolicy(host.scope)
host.publish({ status: 'ready', value: { busyEnter: 'steer' }, revision: 1, writable: true })
expect(policy.busyEnter.getSnapshot()).toBe('steer')
policy.setBusyEnter('steer')
expect(host.set).not.toHaveBeenCalled()
host.publish({ value: { busyEnter: 'steer' }, revision: 2 })
expect(policy.busyEnter.getSnapshot()).toBe('steer')
})
it('adopts a section already standing at construction', () => {
const host = stubSettingsScope<ConversationSettings>()
host.publish({ status: 'ready', value: { busyEnter: 'steer' }, revision: 1, writable: true })
const policy = new ComposerSubmissionPolicy(host.scope)
expect(policy.busyEnter.getSnapshot()).toBe('steer')
})
})