present.spec.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { describe, expect, it } from 'vitest'
  2. import { presentInspectCall, presentMountCall, presentUnmountCall } from '../src/present.ts'
  3. import { setup } from './helpers.ts'
  4. /**
  5. * Render-intent presenters: pure functions of the call args (no I/O, no
  6. * session state — they run on replay too), wired onto the registered tools.
  7. */
  8. describe('presenters', () => {
  9. it('cordis_inspect renders a generic read card titled with the section', () => {
  10. expect(presentInspectCall({})).toEqual({ card: 'generic', kind: 'read', title: 'Inspect cordis runtime' })
  11. expect(presentInspectCall({ what: 'api' })).toEqual({ card: 'generic', kind: 'read', title: 'Inspect cordis runtime: api' })
  12. expect(presentInspectCall({ what: 'events', name: 'tools/change' })).toEqual({
  13. card: 'generic',
  14. kind: 'read',
  15. title: 'Inspect cordis runtime: events: tools/change',
  16. })
  17. })
  18. it('cordis_mount renders a generic execute card carrying the code as raw input', () => {
  19. expect(presentMountCall({ code: 'return (ctx) => {}' })).toEqual({
  20. card: 'generic',
  21. kind: 'execute',
  22. title: 'Mount plugin into live cordis runtime',
  23. rawInput: { code: 'return (ctx) => {}' },
  24. })
  25. })
  26. it('cordis_unmount renders a generic delete card titled with the id', () => {
  27. expect(presentUnmountCall({ id: 'dyn-1' })).toEqual({ card: 'generic', kind: 'delete', title: 'Unmount dyn-1' })
  28. })
  29. it('is wired onto the registered definitions through the defineTool soft-validation path', async () => {
  30. const ctx = await setup()
  31. expect(ctx.tools.get('cordis_inspect')!.presentCall!({ what: 'tools' })).toEqual({
  32. card: 'generic',
  33. kind: 'read',
  34. title: 'Inspect cordis runtime: tools',
  35. })
  36. expect(ctx.tools.get('cordis_inspect')!.presentCall!({ what: 'api', name: 'tools' })).toMatchObject({
  37. title: 'Inspect cordis runtime: api: tools',
  38. })
  39. expect(ctx.tools.get('cordis_mount')!.presentCall!({ code: 'return 1' })).toMatchObject({ kind: 'execute' })
  40. expect(ctx.tools.get('cordis_unmount')!.presentCall!({ id: 'dyn-2' })).toMatchObject({ title: 'Unmount dyn-2' })
  41. // Soft validation: presenter args that fail the schema render as no card, never a throw.
  42. expect(ctx.tools.get('cordis_unmount')!.presentCall!({ id: 42 })).toBeUndefined()
  43. })
  44. })