error.spec.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * Unit tests for the model-facing error remediation: the remedy appended to
  3. * guarded-mutation failures, code preservation, and passthrough behavior.
  4. */
  5. import { describe, expect, it } from 'vitest'
  6. import { FsError } from '@deepseek-ai/dsh-fs'
  7. import { remediateFsError } from '../src/error.ts'
  8. describe('remediateFsError', () => {
  9. it('appends the re-read remedy to FS_STALE_VERSION, preserving the code and chaining the cause', () => {
  10. const original = new FsError('cannot edit "x": file changed since it was read', 'FS_STALE_VERSION')
  11. const remedied = remediateFsError(original) as FsError
  12. expect(remedied).toBeInstanceOf(FsError)
  13. expect(remedied.message).toBe('cannot edit "x": file changed since it was read — re-read the file, then retry')
  14. expect(remedied.code).toBe('FS_STALE_VERSION')
  15. expect(remedied.cause).toBe(original)
  16. })
  17. it('appends the read remedy to FS_NOT_OBSERVED', () => {
  18. const remedied = remediateFsError(new FsError('edit requires reading "x" first', 'FS_NOT_OBSERVED')) as FsError
  19. expect(remedied.message).toBe('edit requires reading "x" first — read the file, then retry')
  20. expect(remedied.code).toBe('FS_NOT_OBSERVED')
  21. })
  22. it('leaves other FsError codes untouched', () => {
  23. const original = new FsError('no match anywhere', 'FS_EDIT_NOT_FOUND')
  24. expect(remediateFsError(original)).toBe(original)
  25. })
  26. it('leaves non-FsError values untouched', () => {
  27. const original = new Error('boom')
  28. expect(remediateFsError(original)).toBe(original)
  29. })
  30. })