command.client.spec.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import { describe, expect, it } from 'vitest'
  2. import { Context } from '@deepseek-ai/cordis'
  3. import type { CommandDefinition, CommandInvocation } from '@deepseek-ai/dsh-commands'
  4. import * as SessionLogDownload from '../src/index.ts'
  5. describe('/export Web download command', () => {
  6. it('registers one pathless command and removes it with the plugin fiber', async () => {
  7. let descriptor: CommandDefinition | undefined
  8. const ctx = new Context()
  9. ctx.provide('commands', {
  10. register(next: CommandDefinition) {
  11. descriptor = next
  12. return () => { descriptor = undefined }
  13. },
  14. } as never)
  15. const fiber = await ctx.plugin(SessionLogDownload)
  16. expect(descriptor).toMatchObject({
  17. name: 'export',
  18. description: 'Download this Session log as a ZIP archive',
  19. })
  20. const invoke = (rawInput: string) => descriptor?.handler({ rawInput } as CommandInvocation)
  21. await expect(invoke('')).resolves.toEqual({
  22. kind: 'success', text: 'Session log download requested.',
  23. })
  24. await expect(invoke(' output.zip')).resolves.toEqual({
  25. kind: 'error', text: 'The Web /export command does not accept a path.',
  26. })
  27. await fiber.dispose()
  28. expect(descriptor).toBeUndefined()
  29. })
  30. })