chat-settings.client.spec.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { Context } from '@deepseek-ai/cordis'
  2. import { describe, expect, it } from 'vitest'
  3. import { SettingsProvider, type SettingsNamespace } from '@deepseek-ai/dsh-settings'
  4. import {
  5. CHAT_SETTINGS_NAMESPACE, DEFAULT_TRANSCRIPT_VIEW_MODE, apply,
  6. } from '../src/index.ts'
  7. class MemorySettings extends SettingsProvider {
  8. readonly writable = true
  9. protected load(): Promise<Record<string, unknown>> { return Promise.resolve({}) }
  10. protected persist(_ns: SettingsNamespace, _section: Record<string, unknown>): Promise<void> {
  11. return Promise.resolve()
  12. }
  13. }
  14. describe('ui-chat Host settings', () => {
  15. it('registers, validates, and disposes the transcript-view namespace', async () => {
  16. const ctx = new Context()
  17. await ctx.plugin(MemorySettings).await()
  18. const fiber = ctx.plugin({ apply })
  19. await fiber.await()
  20. const ns = CHAT_SETTINGS_NAMESPACE
  21. expect(ctx.settings.get(ns)).toEqual({ transcriptView: DEFAULT_TRANSCRIPT_VIEW_MODE })
  22. await ctx.settings.update(ns, { transcriptView: 'normal' })
  23. expect(ctx.settings.get(ns)).toEqual({ transcriptView: 'normal' })
  24. await expect(ctx.settings.update(ns, { transcriptView: 'dense' })).rejects.toThrow()
  25. await fiber.dispose()
  26. expect(ctx.settings.describe().map(row => row.ns)).not.toContain(ns)
  27. })
  28. it('loads without a settings provider', async () => {
  29. const ctx = new Context()
  30. await expect(ctx.plugin({ apply }).await()).resolves.toBeDefined()
  31. })
  32. })