* Build a fake `Session` whose `prompt()` either rejects with a * caller-supplied error OR fans out a pre-recorded event sequence * through any subscribed listener — covering the two distinct error * paths that AcpSession.prompt routes through * `mapPromptError` / `authRequiredFromPayloa
(
sessionId: string,
opts: { script?: readonly Event[]; rejectWith?: Error },
)
| 66 | * `mapPromptError` / `authRequiredFromPayload`. |
| 67 | */ |
| 68 | function makeScriptedSession( |
| 69 | sessionId: string, |
| 70 | opts: { script?: readonly Event[]; rejectWith?: Error }, |
| 71 | ): ScriptedSession { |
| 72 | const listeners = new Set<(event: Event) => void>(); |
| 73 | let unsubCount = 0; |
| 74 | const session = { |
| 75 | id: sessionId, |
| 76 | prompt: async (_input: unknown) => { |
| 77 | if (opts.rejectWith) throw opts.rejectWith; |
| 78 | if (opts.script) { |
| 79 | for (const ev of opts.script) { |
| 80 | for (const fn of listeners) fn(ev); |
| 81 | } |
| 82 | } |
| 83 | }, |
| 84 | cancel: async () => undefined, |
| 85 | onEvent: (fn: (event: Event) => void) => { |
| 86 | listeners.add(fn); |
| 87 | return () => { |
| 88 | unsubCount += 1; |
| 89 | listeners.delete(fn); |
| 90 | }; |
| 91 | }, |
| 92 | } as unknown as Session; |
| 93 | return { session, unsubscribeCount: () => unsubCount }; |
| 94 | } |
| 95 | |
| 96 | const textBlock = (text: string): ContentBlock => ({ type: 'text', text }); |
| 97 |
no test coverage detected