config.host.spec.ts 1.3 KB

1234567891011121314151617181920212223242526272829
  1. /** Host configuration supplies bounded Office reuse settings to browser pages. */
  2. import { Context } from '@deepseek-ai/cordis'
  3. import type { IndexInjection } from '@deepseek-ai/dsh-host-webserver'
  4. import { expect, it, onTestFinished } from 'vitest'
  5. import { Config } from '../src/config.ts'
  6. import * as host from '../src/index.ts'
  7. it('exposes only Client reuse limits on the Host entry', () => {
  8. expect(host.Config).toBe(Config)
  9. expect(Config({})).toEqual({ office: {
  10. maxCachedEntries: 8, maxCachedBytes: 64 * 1024 * 1024, maxPending: 8, maxReaders: 32,
  11. } })
  12. for (const key of ['maxCachedEntries', 'maxCachedBytes']) expect(() => Config({ office: { [key]: 0 } })).toThrow()
  13. })
  14. it('embeds YAML cache settings in browser pages and withdraws them on disposal', async () => {
  15. const ctx = new Context()
  16. onTestFinished(async () => { await ctx.fiber.dispose() })
  17. const config = Config({ office: { maxCachedEntries: 2 } })
  18. const fiber = ctx.plugin(host, config)
  19. await fiber.await()
  20. const rows: IndexInjection[] = []
  21. ctx.emit('webserver/index-inject', rows)
  22. expect(rows).toEqual([{ kind: 'global', name: '__DSH_DOCUMENT_PREVIEW_CONFIG__', value: config }])
  23. await fiber.dispose()
  24. const after: IndexInjection[] = []
  25. ctx.emit('webserver/index-inject', after)
  26. expect(after).toEqual([])
  27. })