Skip to content

Commit 665203c

Browse files
stephentoubCopilot
andcommitted
Wait for pending permission hydration
Preserve the original permission request ID across resume, matching runtime behavior, but wait until the resumed session exposes that ID through pendingRequests before responding. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent a21926a commit 665203c

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

nodejs/test/e2e/pending_work_resume.e2e.test.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,26 @@ async function waitWithTimeout<T>(
5757
}
5858
}
5959

60-
async function waitForPendingPermissionRequestId(session: CopilotSession): Promise<string> {
60+
async function waitForPendingPermissionRequestId(
61+
session: CopilotSession,
62+
requestId: string
63+
): Promise<void> {
6164
const deadline = Date.now() + PENDING_WORK_TIMEOUT_MS;
65+
let seenRequestIds: string[] = [];
6266
do {
6367
const pending = await session.rpc.permissions.pendingRequests();
64-
const request = pending.items[0];
65-
if (request) {
66-
return request.requestId;
68+
seenRequestIds = pending.items.map((request) => request.requestId);
69+
if (seenRequestIds.includes(requestId)) {
70+
return;
6771
}
6872
await new Promise((resolve) => setTimeout(resolve, 100));
6973
} while (Date.now() < deadline);
7074

71-
throw new Error("Timeout waiting for pending permission request");
75+
throw new Error(
76+
`Timeout waiting for pending permission request ${requestId}. Saw: ${
77+
seenRequestIds.join(", ") || "<none>"
78+
}`
79+
);
7280
}
7381

7482
function waitForExternalToolRequests(
@@ -219,7 +227,7 @@ describe("Pending work resume", async () => {
219227
PENDING_WORK_TIMEOUT_MS,
220228
"originalPermissionRequest"
221229
);
222-
await permissionRequestedP;
230+
const permissionEvent = await permissionRequestedP;
223231
expect(initialRequest.kind).toBe("custom-tool");
224232

225233
await suspendedClient.forceStop();
@@ -236,7 +244,8 @@ describe("Pending work resume", async () => {
236244
}),
237245
],
238246
});
239-
const requestId = await waitForPendingPermissionRequestId(session2);
247+
const requestId = permissionEvent.data.requestId;
248+
await waitForPendingPermissionRequestId(session2, requestId);
240249

241250
const permissionResult =
242251
await session2.rpc.permissions.handlePendingPermissionRequest({

0 commit comments

Comments
 (0)