browser-plugin.spec.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * apply wiring on a real cordis Context + SlotsService: QuestionComposer
  3. * registered as the `question` entry of the conversation-declared composer
  4. * slot with ZERO business face (data and verbs ride the dispatched carrier),
  5. * load-order fail-loud, and fiber-teardown unregistration. Component and
  6. * domain-face behavior is covered props-direct in question-composer.spec.tsx;
  7. * no renderer machinery here.
  8. */
  9. import { Context } from 'cordis'
  10. import { describe, expect, it } from 'vitest'
  11. import { SlotsService } from '@deepseek-ai/dsh-client-runtime/client'
  12. import { QuestionComposer } from '../src/client/QuestionComposer.tsx'
  13. import { apply, inject } from '../src/client/index.ts'
  14. async function bench() {
  15. const ctx = new Context()
  16. await ctx.plugin(SlotsService).await()
  17. const slots = ctx.get('slots') as SlotsService
  18. // Stand-in for ui-conversation's conversation entry: the composer slot only
  19. // exists while a live entry declares it in children (declaration account:
  20. // design §2.2).
  21. slots.register(
  22. { name: 'root', children: { 'conversation.composer': { kind: 'chain', scope: 'session' } } } as never,
  23. () => null,
  24. )
  25. return { ctx, slots }
  26. }
  27. describe('apply', () => {
  28. it('declares the services it binds', () => {
  29. expect(inject).toEqual(['slots'])
  30. })
  31. it('fails loud when no live entry has declared the composer slot', async () => {
  32. const ctx = new Context()
  33. await ctx.plugin(SlotsService).await()
  34. await expect(ctx.plugin({ inject: [...inject], apply }))
  35. .rejects.toThrow(/slot "conversation.composer" is not declared/)
  36. })
  37. it('registers the question entry: routing selector, no inject face', async () => {
  38. const { ctx, slots } = await bench()
  39. await ctx.plugin({ inject: [...inject], apply }).await()
  40. const entry = slots.entries('conversation.composer')[0]!
  41. expect(entry.component).toBe(QuestionComposer)
  42. // The whole behavior surface rides the matched carrier: no business face.
  43. expect(entry.inject).toBeUndefined()
  44. // The selector narrows the chain currency: question wait in → that wait; none → null.
  45. const select = entry.select as (owner: { interactions: readonly { kind: string }[] }) => unknown
  46. const question = { kind: 'question' }
  47. expect(select({ interactions: [{ kind: 'approval' }, question] })).toBe(question)
  48. expect(select({ interactions: [{ kind: 'approval' }] })).toBeNull()
  49. expect(select({ interactions: [] })).toBeNull()
  50. })
  51. it('teardown unregisters the slot entry', async () => {
  52. const { ctx, slots } = await bench()
  53. const fiber = ctx.plugin({ inject: [...inject], apply })
  54. await fiber.await()
  55. expect(slots.entries('conversation.composer')).toHaveLength(1)
  56. await fiber.dispose()
  57. expect(slots.entries('conversation.composer')).toHaveLength(0)
  58. })
  59. })