plugin.client.spec.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { Context } from '@deepseek-ai/cordis'
  2. import { describe, expect, it } from 'vitest'
  3. import { SlotRegistry } from '@deepseek-ai/dsh-client-ui-renderer/client'
  4. import { apply as applyHost } from '../src/index.ts'
  5. import { apply, inject } from '../src/client/index.ts'
  6. import { ComposerAttachments } from '../src/client/ComposerAttachments.tsx'
  7. import { MessageImages } from '../src/client/MessageImages.tsx'
  8. async function bench() {
  9. const ctx = new Context()
  10. await ctx.plugin(SlotRegistry).await()
  11. ctx.slots.register({
  12. name: 'root',
  13. children: {
  14. 'conversation.input.attachments': { kind: 'single', scope: 'session-maybe' },
  15. 'conversation.message.images': { kind: 'single', scope: 'session' },
  16. 'conversation.trajectory.images': { kind: 'single', scope: 'session' },
  17. 'tool.call.images': { kind: 'single', scope: 'session' },
  18. },
  19. } as never, () => null)
  20. const fiber = ctx.plugin({ inject: [...inject], apply })
  21. await fiber.await()
  22. return { ctx, fiber }
  23. }
  24. describe('attachment plugin', () => {
  25. it('keeps the host half empty', () => {
  26. expect(() => { applyHost() }).not.toThrow()
  27. })
  28. it('registers all entries and removes them with the plugin fiber', async () => {
  29. const { ctx, fiber } = await bench()
  30. expect(inject).toEqual(['slots'])
  31. expect(ctx.slots.entries('conversation.input.attachments')).toMatchObject([{
  32. locale: 'conversation',
  33. component: ComposerAttachments,
  34. }])
  35. expect(ctx.slots.entries('conversation.message.images')).toMatchObject([{
  36. locale: 'conversation',
  37. component: MessageImages,
  38. }])
  39. expect(ctx.slots.entries('conversation.trajectory.images')).toMatchObject([{
  40. locale: 'conversation',
  41. component: MessageImages,
  42. }])
  43. expect(ctx.slots.entries('tool.call.images')).toMatchObject([{
  44. locale: 'conversation',
  45. component: MessageImages,
  46. }])
  47. await fiber.dispose()
  48. expect(ctx.slots.entries('conversation.input.attachments')).toHaveLength(0)
  49. expect(ctx.slots.entries('conversation.message.images')).toHaveLength(0)
  50. expect(ctx.slots.entries('conversation.trajectory.images')).toHaveLength(0)
  51. expect(ctx.slots.entries('tool.call.images')).toHaveLength(0)
  52. })
  53. })