Merge remote-tracking branch 'origin/master' into mergebot/pr883

# Conflicts:
#	packages/client/ui-question/package.json
#	packages/client/ui-question/src/client/QuestionComposer.tsx
#	packages/client/ui-question/src/client/contract/slots.ts
#	packages/client/ui-question/src/client/index.ts
#	packages/client/ui-question/src/client/locales.ts
#	packages/client/ui-question/tests/browser-plugin.spec.ts
#	packages/client/ui-question/tests/question-composer.spec.tsx
This commit is contained in:
imccyu
2026-07-30 15:01:10 +08:00
254 changed files with 3802 additions and 1162 deletions

View File

@@ -1,19 +1,17 @@
/**
* apply wiring on a real cordis Context + SlotsService + LocaleService:
* QuestionComposer registered as the `question` entry of the
* conversation-declared composer slot, bilingual dictionaries registered
* under the `question` namespace, the locale share handed through the inject
* face, load-order fail-loud, and fiber-teardown unregistration. Component
* and domain-face behavior is covered props-direct in
* question-composer.spec.tsx; no renderer machinery here.
* apply wiring on a real cordis Context + SlotsService: QuestionComposer
* registered as the `question` entry of the conversation-declared composer
* slot with ZERO business face (data and verbs ride the dispatched carrier),
* load-order fail-loud, and fiber-teardown unregistration. Component and
* domain-face behavior is covered props-direct in question-composer.spec.tsx;
* no renderer machinery here.
*/
import { Context } from 'cordis'
import { describe, expect, it, vi } from 'vitest'
import { describe, expect, it } from 'vitest'
import { SlotsService } from '@deepseek-ai/dsh-client-runtime/client'
import { LocaleService } from '@deepseek-ai/dsh-client-locale/client'
import type { QuestionComposerInjected } from '../src/client/contract/slots.ts'
import { QuestionComposer } from '../src/client/QuestionComposer.tsx'
import { apply, inject, QUESTION_NS } from '../src/client/index.ts'
import { apply, inject } from '../src/client/index.ts'
async function bench() {
const ctx = new Context()
@@ -27,9 +25,8 @@ async function bench() {
// 'conversation' inject is an ordering edge (the declaring plugin provides
// it after declaring the chain); the bench declares the chain itself.
ctx.provide('conversation', {})
const locale = new LocaleService(ctx)
ctx.provide('locale', locale)
return { ctx, slots, locale }
ctx.provide('locale', new LocaleService(ctx))
return { ctx, slots }
}
describe('apply', () => {
@@ -48,41 +45,29 @@ describe('apply', () => {
.rejects.toThrow(/slot "conversation.composer" is not declared/)
})
it('registers the question entry: routing selector plus the locale share face', async () => {
const { ctx, slots, locale } = await bench()
it('registers the question entry: routing selector, no inject face', async () => {
const { ctx, slots } = await bench()
await ctx.plugin({ inject: [...inject], apply }).await()
const entry = slots.entries('conversation.composer')[0]!
expect(entry.component).toBe(QuestionComposer)
// The whole behavior surface rides the matched carrier: no business face;
// copy rides the standard locale seat.
expect(entry.inject).toBeUndefined()
expect(entry.locale).toBe('question')
// The selector narrows the chain currency: question wait in → that wait; none → null.
const select = entry.select as (owner: { interactions: readonly { kind: string }[] }) => unknown
const question = { kind: 'question' }
expect(select({ interactions: [{ kind: 'approval' }, question] })).toBe(question)
expect(select({ interactions: [{ kind: 'approval' }] })).toBeNull()
expect(select({ interactions: [] })).toBeNull()
// The inject face carries the namespace-bound translator and the live
// locale snapshot source (subscription rides locale/change).
const face = (entry.inject as unknown as () => QuestionComposerInjected)()
expect(face.t('action.submit')).toBe('提交')
expect(face.hooks.locale.getSnapshot()).toBe(locale.getLocale())
const changed = vi.fn()
const off = face.hooks.locale.subscribe(changed)
locale.setLocale('en')
expect(changed).toHaveBeenCalledTimes(1)
expect(face.t('action.submit')).toBe('Submit')
off()
locale.setLocale('zh')
expect(changed).toHaveBeenCalledTimes(1)
})
it('teardown unregisters the slot entry and the dictionaries', async () => {
const { ctx, slots, locale } = await bench()
it('teardown unregisters the slot entry', async () => {
const { ctx, slots } = await bench()
const fiber = ctx.plugin({ inject: [...inject], apply })
await fiber.await()
expect(slots.entries('conversation.composer')).toHaveLength(1)
expect(locale.bind(QUESTION_NS)('action.submit')).toBe('提交')
await fiber.dispose()
expect(slots.entries('conversation.composer')).toHaveLength(0)
// Unregistered namespace: the lookup chain bottoms out at the key itself.
expect(locale.bind(QUESTION_NS)('action.submit')).toBe('action.submit')
})
})

View File

@@ -8,35 +8,33 @@ import { PendingWait } from '@deepseek-ai/dsh-client-runtime/client'
import type { RpcReceipt } from '@deepseek-ai/dsh-client-connection/client'
import { RpcId } from '@deepseek-ai/dsh-client-connection/client'
import type { SnapshotSelectorHook } from '@deepseek-ai/dsh-client-ui-slots'
import type { LocaleDict, LocaleSnapshot, Translate } from '@deepseek-ai/dsh-client-locale/client'
import { PendingQuestion } from '../src/client/contract/slots.ts'
import { en, zh } from '../src/client/locales.ts'
import { PendingQuestion, type QuestionComposerProps } from '../src/client/contract/slots.ts'
import { QuestionComposer, parseRecommendedLabel } from '../src/client/QuestionComposer.tsx'
import { en, zh } from '../src/client/locales.ts'
import { en as commonEn } from '@deepseek-ai/dsh-client-locale/src/locales/en.ts'
import { zh as commonZh } from '@deepseek-ai/dsh-client-locale/src/locales/zh.ts'
afterEach(cleanup)
const SID = 's1' as SessionId
/** Dictionary-backed translate stub (the lookup chain is the locale package's contract, not re-tested here). */
const translateOver = (dict: LocaleDict): Translate => key => dict[key] ?? key
/** Seat stub over a dictionary pair mirroring the real lookup chain: package dictionary, then common vocabulary, then the key. */
const seatOver = (dict: Record<string, string>, common: Record<string, string>): QuestionComposerProps['t'] =>
(key => dict[key] ?? common[key] ?? key)
/** Locale-share stub: static snapshot, no subscription machinery. */
const useLocale: SnapshotSelectorHook<LocaleSnapshot> = select =>
select({ active: 'zh', locales: [], revision: 0 })
/** Framework standard-kit stubs: the composer consumes only the locale share;
/** Framework standard-kit stubs: the composer consumes only the locale seat;
* the composed props type mandates delivery of the rest (framework hooks are
* plain stubs per the client testing discipline). */
const kit = {
sessionId: SID,
t: translateOver(zh),
useLocale,
useSession: (() => { throw new Error('unused') }) as unknown as SnapshotSelectorHook<ConversationSnapshot>,
useSessions: (() => { throw new Error('unused') }) as unknown as SnapshotSelectorHook<SessionListState>,
useWorkspaces: (() => { throw new Error('unused') }) as unknown as SnapshotSelectorHook<WorkspaceListState>,
useProjection: (() => undefined) as never,
useInput: (() => { throw new Error('unused') }) as never,
inputActions: { setDraft: () => { throw new Error('unused') }, submit: () => { throw new Error('unused') } } as never,
// The seat's key domain is question ∪ common.
t: seatOver(zh, commonZh),
}
const QUESTIONS = [
@@ -245,7 +243,7 @@ describe('QuestionComposer', () => {
const respond = vi.fn(() => Promise.resolve<RpcReceipt>({ accepted: true }))
const carrier = new PendingWait(
'question', RpcId('solo'), SID, { questions: [{ id: 'detail', question: '补充你的要求' }] }, respond)
render(<QuestionComposer matched={carrier} interactions={[carrier]} {...kit} t={translateOver(en)} />)
render(<QuestionComposer matched={carrier} interactions={[carrier]} {...kit} t={seatOver(en, commonEn)} />)
expect(screen.getByLabelText('Dismiss all questions')).toBeTruthy()
expect(screen.getByRole('button', { name: 'Skip this question' })).toBeTruthy()
expect(screen.getByPlaceholderText('Type your answer')).toBeTruthy()