(
session: CopilotSession,
eventType: TEventType,
description: string,
predicate: (event: Extract<SessionEvent, { type: TEventType }>) => boolean = () => true
)
| 5 | const compactionTimeoutMs = 60_000; |
| 6 | |
| 7 | function getNextSessionEvent<TEventType extends SessionEvent["type"]>( |
| 8 | session: CopilotSession, |
| 9 | eventType: TEventType, |
| 10 | description: string, |
| 11 | predicate: (event: Extract<SessionEvent, { type: TEventType }>) => boolean = () => true |
| 12 | ): Promise<Extract<SessionEvent, { type: TEventType }>> { |
| 13 | return new Promise((resolve, reject) => { |
| 14 | let unsubscribe: () => void = () => {}; |
| 15 | const timeout = setTimeout(() => { |
| 16 | unsubscribe(); |
| 17 | reject(new Error(`Timed out waiting for ${description}`)); |
| 18 | }, compactionTimeoutMs); |
| 19 | |
| 20 | unsubscribe = session.on((event) => { |
| 21 | if (event.type === eventType) { |
| 22 | const typedEvent = event as Extract<SessionEvent, { type: TEventType }>; |
| 23 | if (predicate(typedEvent)) { |
| 24 | clearTimeout(timeout); |
| 25 | unsubscribe(); |
| 26 | resolve(typedEvent); |
| 27 | } |
| 28 | } else if (event.type === "session.error") { |
| 29 | clearTimeout(timeout); |
| 30 | unsubscribe(); |
| 31 | reject(new Error(`${event.data.message}\n${event.data.stack}`)); |
| 32 | } |
| 33 | }); |
| 34 | }); |
| 35 | } |
| 36 | |
| 37 | describe("Compaction", async () => { |
| 38 | const { copilotClient: client } = await createSdkTestContext(); |
no test coverage detected
searching dependent graphs…