failure-line.client.spec.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * One sentence per endpoint code, and the transport's own words for anything else.
  3. */
  4. import { describe, expect, it } from 'vitest'
  5. import type { RemoteFailure } from '@deepseek-ai/dsh-api-remotes/client'
  6. import type { TranslateNS } from '@deepseek-ai/dsh-client-ui-slots'
  7. // The namespace declaration `TranslateNS<'sidebarDocumentPreview'>` resolves against.
  8. import type {} from '../src/client/index.ts'
  9. import { failureLine } from '../src/client/failure-line.ts'
  10. /** Key-echoing translate that also shows its parameters, so a formatted value is visible. */
  11. const t: TranslateNS<'sidebarDocumentPreview'> = (key, params) =>
  12. params === undefined ? key : `${key}(${Object.entries(params).map(([k, v]) => `${k}=${String(v)}`).join(',')})`
  13. function failure(code: string, details: Record<string, unknown> = {}, message = 'boom'): RemoteFailure {
  14. return { code, message, details } as unknown as RemoteFailure
  15. }
  16. describe('failureLine', () => {
  17. it('names each workspace-file code', () => {
  18. expect(failureLine(t, failure('workspace-file/not-found'))).toBe('error.notFound')
  19. expect(failureLine(t, failure('workspace-file/not-text'))).toBe('error.notText')
  20. expect(failureLine(t, failure('workspace-file/not-regular-file'))).toBe('error.notRegularFile')
  21. })
  22. it('states the byte cap the way a person reads one', () => {
  23. expect(failureLine(t, failure('workspace-file/too-large', { limit: 512 }))).toBe('error.tooLarge(limit=512 B)')
  24. expect(failureLine(t, failure('workspace-file/too-large', { limit: 4096 }))).toBe('error.tooLarge(limit=4 KB)')
  25. expect(failureLine(t, failure('workspace-file/too-large', { limit: 3 * 1024 * 1024 }))).toBe('error.tooLarge(limit=3 MB)')
  26. })
  27. it('passes any other failure through in its own words', () => {
  28. expect(failureLine(t, failure('gateway/internal', {}, 'socket closed'))).toBe('error.unavailable(message=socket closed)')
  29. })
  30. })