remote.client.spec.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * TestRemote's own contract: subscription and disposal, dispatch driven by the
  3. * internal plumbing event, the silent drop for an unsubscribed name, and the
  4. * `$mount` refusal that sends a spec to the real Client Remote service.
  5. */
  6. import { Context } from '@deepseek-ai/cordis'
  7. import { describe, expect, it } from 'vitest'
  8. import { TestRemote } from '../src/remote.ts'
  9. describe('TestRemote', () => {
  10. it('delivers a forwarded event to its subscribers and stops after disposal', async () => {
  11. const ctx = new Context()
  12. const remote = new TestRemote(ctx)
  13. const seen: string[] = []
  14. const off = remote.$on('settings/document-updated', (ns: string) => {
  15. seen.push(ns)
  16. })
  17. remote.emit('settings/document-updated', ['ui-theme', 1])
  18. expect(seen).toEqual(['ui-theme'])
  19. off()
  20. remote.emit('settings/document-updated', ['ui-theme', 2])
  21. expect(seen).toEqual(['ui-theme'])
  22. await ctx.fiber.dispose()
  23. })
  24. it('drops a forwarded event nobody subscribed to', async () => {
  25. const ctx = new Context()
  26. const remote = new TestRemote(ctx)
  27. // No subscriber for this name: the emit must be inert rather than throwing,
  28. // because the wire carries whatever the Host allowlist selected.
  29. expect(() => { remote.emit('credentials/reference-updated', ['DEEPSEEK_API_KEY']) }).not.toThrow()
  30. await ctx.fiber.dispose()
  31. })
  32. it('refuses $mount, which needs the real Client Remote service', async () => {
  33. const ctx = new Context()
  34. const remote = new TestRemote(ctx)
  35. await expect(remote.$mount()).rejects.toThrow('needs the real Client Remote service')
  36. await ctx.fiber.dispose()
  37. })
  38. })