refactor(gui): slot system standard — single register, four props shares, framework store seat
The definitive slot model for the web client, replacing the first-generation
define/register two-step, ScopedSlots whitelist faces, and binding handles:
- 'root' is the only a-priori slot (SlotsService built-in); the shell renders
exactly ctx.slots.renderSlot('root', {}).
- register is the single API: children = slot declaration + render
authorization + runtime spec in one options object; misconfiguration fails
loud at load (duplicate declaration, undeclared contribution, one store
handle under two scopes).
- Component props arrive in four auto-derived shares: PropsRuntime<K>
(owner params + session/global standard kits via declare-merge),
PropsRenderSlots<S>, PropsStore<H>, and the inject business face.
sessionId is framework-supplied; hooks are framework-made only.
- Framework store seat: defineStore factories declare schema/actions/persist;
read = useStore, write = baked actions only; store scope derives from the
mounting entry; per-session persist keys and clearPersisted lifecycle.
- inject factories read the apply closure's own ctx (binding handles retired;
root-ctx back door closed); SessionProvider is self-wired render-prop.
- Rendering sits behind the SlotRenderer install seam; runtime stays
React-free; ownership ledger keyed to the single entry axis closes the
stale-authority window (StaleAuthorizationError probes).
Docs: the slot type-chain note is refreshed in place as the slot system
standard RFC (bilingual pair re-recorded); the web client architecture RFC
defers its slot sections there; packages/client/AGENTS.md gains the slot and
props discipline; gui-testing/web-styling notes drop missions/ references.
Tests: suites rewritten to the standard (props fed directly, real store
engines via createXXXStore().create(), no render machinery); load-time
negative samples for declaration/authorization/store conflicts; verified by
real-host playwright run (three columns, empty state, collapse, keyed session
remount, cross-slot selection sharing).
docs(ui-sidebar): point contract reference at the committed slot standard RFC
missions/ is workspace-local and never committed; the README must not cite it.
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
// @vitest-environment jsdom
|
||||
// Client apply wiring: ctx.layout provided, the four layout-owned slots
|
||||
// defined, teardown cascades (service unprovided + slot specs removed + list
|
||||
// subscription dropped). Node half and the invariant companion ride along —
|
||||
// they are one-line surfaces the aggregate coverage gate still requires
|
||||
// exercised.
|
||||
// Client apply wiring under the terminal register form: ctx.layout provided,
|
||||
// ONE register() call declares the four child slots + seats the store factory
|
||||
// + wires the panel actions through the inject hook; teardown cascades
|
||||
// (service unprovided + declarations gone + registration cleared). Node half
|
||||
// and the invariant companion ride along — one-line surfaces the aggregate
|
||||
// coverage gate still requires exercised.
|
||||
|
||||
import { Context } from 'cordis'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { createSnapshotStore } from '@deepseek-ai/dsh-client-web-react'
|
||||
import { SlotsService } from '@deepseek-ai/dsh-client-runtime/client'
|
||||
import type { SessionListState } from '@deepseek-ai/dsh-client-runtime/client'
|
||||
import { apply, inject, LayoutService } from '@deepseek-ai/dsh-client-ui-layout/client'
|
||||
import { apply as nodeApply } from '@deepseek-ai/dsh-client-ui-layout'
|
||||
import * as invariant from '@deepseek-ai/dsh-client-ui-layout/invariant'
|
||||
@@ -18,8 +17,6 @@ async function bench() {
|
||||
const ctx = new Context()
|
||||
const slotsFiber = ctx.plugin(SlotsService)
|
||||
await slotsFiber.await()
|
||||
const list = createSnapshotStore<SessionListState>({ ids: [], byId: {} })
|
||||
ctx.provide('sessions', { list })
|
||||
return { ctx, slots: ctx.get('slots') as SlotsService }
|
||||
}
|
||||
|
||||
@@ -28,28 +25,31 @@ describe('ui-layout client apply', () => {
|
||||
expect(inject).toContain('slots')
|
||||
})
|
||||
|
||||
it('provides ctx.layout and defines the four layout-owned slots', async () => {
|
||||
it('provides ctx.layout and registers AppFrame into root with the four child declarations', async () => {
|
||||
const { ctx, slots } = await bench()
|
||||
const fiber = ctx.plugin({ inject: ['slots'], apply })
|
||||
await fiber.await()
|
||||
expect(ctx.get('layout')).toBeInstanceOf(LayoutService)
|
||||
// The one register() call occupied 'root'…
|
||||
expect(slots.entries('root')).toHaveLength(1)
|
||||
// …and declared the four children in the ledger.
|
||||
expect(slots.spec('sidebar')).toEqual({ kind: 'single', scope: 'root' })
|
||||
expect(slots.spec('conversation')).toEqual({ kind: 'single', scope: 'session' })
|
||||
expect(slots.spec('details')).toEqual({ kind: 'single', scope: 'session' })
|
||||
expect(slots.spec('conversation.empty')).toEqual({ kind: 'single', scope: 'root' })
|
||||
})
|
||||
|
||||
it('teardown unwinds service, slot specs, and the prune subscription', async () => {
|
||||
it('teardown unwinds the service, the root registration, and the child declarations', async () => {
|
||||
const { ctx, slots } = await bench()
|
||||
const fiber = ctx.plugin({ inject: ['slots'], apply })
|
||||
await fiber.await()
|
||||
const layout = ctx.get('layout') as LayoutService
|
||||
const disposeSpy = vi.spyOn(layout, 'dispose')
|
||||
await fiber.dispose()
|
||||
expect(ctx.get('layout')).toBeUndefined()
|
||||
expect(slots.entries('root')).toHaveLength(0)
|
||||
expect(slots.spec('sidebar')).toBeUndefined()
|
||||
expect(slots.spec('conversation.empty')).toBeUndefined()
|
||||
expect(disposeSpy).toHaveBeenCalledTimes(1)
|
||||
// The built-in root declaration survives entry teardown (runtime-owned).
|
||||
expect(slots.spec('root')).toEqual({ kind: 'single', scope: 'root' })
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user