2026-07-23 01:40:30 +08:00
|
|
|
// Dynamic-key escape hatches and untouched-key behavior of the terminal core.
|
2026-07-19 21:17:57 +08:00
|
|
|
import { describe, expect, it } from 'vitest'
|
2026-07-23 01:40:30 +08:00
|
|
|
import type { SlotComponent } from '@deepseek-ai/dsh-client-ui-slots'
|
|
|
|
|
import { SlotCore } from '@deepseek-ai/dsh-client-ui-slots'
|
2026-07-19 21:17:57 +08:00
|
|
|
|
|
|
|
|
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
|
|
|
interface SlotMap {
|
2026-07-23 01:40:30 +08:00
|
|
|
'surface.a': { kind: 'single'; scope: 'root' }
|
|
|
|
|
'surface.b': { kind: 'single'; scope: 'root' }
|
2026-07-19 21:17:57 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-23 01:40:30 +08:00
|
|
|
const Comp: SlotComponent<object> = () => null
|
2026-07-19 21:17:57 +08:00
|
|
|
|
|
|
|
|
describe('dynamic-key escape hatch', () => {
|
2026-07-23 01:40:30 +08:00
|
|
|
it('specDynamic reads wide-typed specs for string keys; undefined while undeclared', () => {
|
2026-07-19 21:17:57 +08:00
|
|
|
const core = new SlotCore()
|
|
|
|
|
expect(core.specDynamic('surface.a')).toBeUndefined()
|
2026-07-23 01:40:30 +08:00
|
|
|
core.register({ name: 'root', children: { 'surface.a': { kind: 'single', scope: 'root' } } }, Comp as never)
|
2026-07-19 21:17:57 +08:00
|
|
|
expect(core.specDynamic('surface.a')).toEqual({ kind: 'single', scope: 'root' })
|
2026-07-23 01:40:30 +08:00
|
|
|
expect(core.specDynamic('never.declared')).toBeUndefined()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('spec() narrows by SlotMap key', () => {
|
|
|
|
|
const core = new SlotCore()
|
|
|
|
|
core.register({ name: 'root', children: { 'surface.a': { kind: 'single', scope: 'root' } } }, Comp as never)
|
|
|
|
|
expect(core.spec('surface.a')).toEqual({ kind: 'single', scope: 'root' })
|
|
|
|
|
expect(core.spec('surface.b')).toBeUndefined()
|
2026-07-19 21:17:57 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('entries/getVersion on an untouched key return the frozen empty array and 0', () => {
|
|
|
|
|
const core = new SlotCore()
|
|
|
|
|
expect(core.entries('surface.b')).toHaveLength(0)
|
|
|
|
|
expect(core.entries('surface.b')).toBe(core.entries('surface.b'))
|
|
|
|
|
expect(core.getVersion('surface.b')).toBe(0)
|
|
|
|
|
})
|
|
|
|
|
|
2026-07-23 01:40:30 +08:00
|
|
|
it('isLive is false for entries the core never held', () => {
|
2026-07-19 21:17:57 +08:00
|
|
|
const core = new SlotCore()
|
2026-07-23 01:40:30 +08:00
|
|
|
expect(core.isLive({ component: Comp, options: {} })).toBe(false)
|
2026-07-19 21:17:57 +08:00
|
|
|
})
|
|
|
|
|
})
|