mirror of
https://github.com/deepseek-ai/deepseek-harness
synced 2026-08-15 21:04:50 +00:00
Registrations declare a dictionary namespace (locale: NS) and the renderer
synthesizes a typed t prop for the entry's component from the installed
LocaleFace; the seat binding is re-derived per locale revision, so a language
switch hands out fresh t references and memoized consumers re-render through
ordinary shallow comparison. LocaleNamespaceMap is the declare-merge table
(namespace -> dictionary key union); TranslateNS<'ns'> is the
namespace-addressed translate type (namespace keys plus the shared common
vocabulary), carried by the t seat and by the locale service's typed bind.
LocaleService implements the face (lookup ns -> common -> zh -> key,
revision-carrying snapshots with subscriber isolation) and installs it
through the boot-once slots.installLocale seam, mirroring the renderer
install. The typed register(ns, {zh, en}) overload checks each dictionary
against the namespace's key union and requires every shipped locale, so a
missing or extra key and an unbalanced translation are compile errors.
Dictionary registration bumps the face revision without emitting
locale/change — the event now means exactly 'the active locale switched',
so registration-heavy boot cannot storm event listeners.
74 lines
3.3 KiB
TypeScript
74 lines
3.3 KiB
TypeScript
/**
|
|
* 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 } from 'vitest'
|
|
import { SlotsService } from '@deepseek-ai/dsh-client-runtime/client'
|
|
import { LocaleService } from '@deepseek-ai/dsh-client-locale/client'
|
|
import { QuestionComposer } from '../src/client/QuestionComposer.tsx'
|
|
import { apply, inject } from '../src/client/index.ts'
|
|
|
|
async function bench() {
|
|
const ctx = new Context()
|
|
await ctx.plugin(SlotsService).await()
|
|
const slots = ctx.get('slots') as SlotsService
|
|
// The composer slot exists only while its declaring entry is live.
|
|
slots.register(
|
|
{ name: 'root', children: { 'conversation.composer': { kind: 'chain', scope: 'session' } } } as never,
|
|
() => null,
|
|
)
|
|
// 'conversation' inject is an ordering edge (the declaring plugin provides
|
|
// it after declaring the chain); the bench declares the chain itself.
|
|
ctx.provide('conversation', {})
|
|
ctx.provide('locale', new LocaleService(ctx))
|
|
return { ctx, slots }
|
|
}
|
|
|
|
describe('apply', () => {
|
|
it('declares the services it binds', () => {
|
|
expect(inject).toEqual(['slots', 'conversation', 'locale'])
|
|
})
|
|
|
|
it('fails loud when no live entry has declared the composer slot', async () => {
|
|
const ctx = new Context()
|
|
await ctx.plugin(SlotsService).await()
|
|
// Satisfy the ordering inject without declaring the chain: apply must
|
|
// then hit the undeclared-slot throw, not sit waiting on the service.
|
|
ctx.provide('conversation', {})
|
|
ctx.provide('locale', new LocaleService(ctx))
|
|
await expect(ctx.plugin({ inject: [...inject], apply }))
|
|
.rejects.toThrow(/slot "conversation.composer" is not declared/)
|
|
})
|
|
|
|
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()
|
|
})
|
|
|
|
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)
|
|
await fiber.dispose()
|
|
expect(slots.entries('conversation.composer')).toHaveLength(0)
|
|
})
|
|
})
|