session-remote-rejection.client.spec.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * A rejection from the Remote face, which the generated client raises only for
  3. * an assembly fault (wrong arity, an unmounted method, a withdrawn
  4. * contribution), propagates out of the Session command unchanged and records no
  5. * prompt error. Carrier failures never reject: they arrive as folded results,
  6. * covered by session.client.spec.ts.
  7. */
  8. import { describe, expect, it } from 'vitest'
  9. import type { SessionId } from '@deepseek-ai/dsh-api-remotes/client'
  10. import { Session } from '../src/client/sessions/session.ts'
  11. import type { SessionRemotes } from '../src/client/sessions/remotes.ts'
  12. const SID = 'fk-s1' as SessionId
  13. const PARENT = 'fk-parent' as SessionId
  14. /** Every command rejects with `message`; nothing else on the face is reachable from prompt or cancel. */
  15. function rejecting(message: string): SessionRemotes {
  16. const reject = (): Promise<never> => Promise.reject(new Error(message))
  17. return {
  18. $stream: () => { throw new Error('unused') },
  19. commands: { execute: reject },
  20. session: { prompt: reject, cancel: reject },
  21. subagents: { list: reject, prompt: reject, interruptByParent: reject },
  22. } as unknown as SessionRemotes
  23. }
  24. describe('Session over a rejecting Remote face', () => {
  25. it('propagates the rejection from prompt and cancel and records no prompt error', async () => {
  26. const session = new Session(SID, rejecting('assembly fault'))
  27. await expect(session.prompt([{ type: 'text', text: 'x' }], 'queue')).rejects.toThrow('assembly fault')
  28. await expect(session.cancel()).rejects.toThrow('assembly fault')
  29. expect(session.getSnapshot().promptError).toBeNull()
  30. })
  31. it('propagates the rejection from a subagent continuation prompt and interrupt', async () => {
  32. const session = new Session(SID, rejecting('assembly fault'), {
  33. address: { parentSessionId: PARENT, childSessionId: SID, mode: 'continuable' },
  34. parentAvailable: true,
  35. })
  36. await expect(session.prompt([{ type: 'text', text: 'x' }], 'queue')).rejects.toThrow('assembly fault')
  37. await expect(session.cancel()).rejects.toThrow('assembly fault')
  38. expect(session.getSnapshot().promptError).toBeNull()
  39. })
  40. })