Skip to content

Commit 60f1460

Browse files
committed
test(control-ui): pin repeated same-method e2e waits with after-cursor
waitForRequest(method) is satisfied by ANY prior request of that method and returns the latest match, so a second same-method wait in one page context can return a stale earlier request on slow runners. Add the opt-in { after: priorCount } cursor (same shape as PR #125107's helper change) and pin the 11 genuinely stale-prone waits: chat-composer- capability-menu, claude-sessions (3), desktop-panel, model-providers (3, replacing expect.poll count workarounds), session-management.group- defaults (3). Skipped: cloud-workers-settings (owned by PR #125107), chat-attachment-read-lifecycle (ring asserted empty), login-gate (waits follow app-initiated stale-build reloads, which restart the ring).
1 parent daafb2b commit 60f1460

6 files changed

Lines changed: 58 additions & 26 deletions

‎ui/src/e2e/chat-composer-capability-menu.e2e.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,9 +776,14 @@ suite.define(() => {
776776
await everywhereDialog.getByLabel("URL or command").fill("docs-mcp --stdio");
777777
await everywhereDialog.getByLabel("Transport").selectOption("stdio");
778778
const sessionPatchCount = (await gateway.getRequests("sessions.patch")).length;
779+
// Pin past the session-scoped config.patch above so a slow runner can't
780+
// return it stale for the everywhere-scoped save.
781+
const configPatchesBeforeEverywhereAdd = (await gateway.getRequests("config.patch")).length;
779782
await gateway.deferNext("config.patch");
780783
await everywhereDialog.getByRole("button", { name: "Add server" }).click();
781-
const everywhereConfigPatch = await gateway.waitForRequest("config.patch");
784+
const everywhereConfigPatch = await gateway.waitForRequest("config.patch", {
785+
after: configPatchesBeforeEverywhereAdd,
786+
});
782787
expect(configPatchRaw(everywhereConfigPatch)).toEqual({
783788
mcp: {
784789
servers: {

‎ui/src/e2e/claude-sessions.e2e.test.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,9 @@ suite.define(() => {
892892
element.scrollTop = 0;
893893
element.parentElement?.querySelector<HTMLButtonElement>(".chat-history-available")?.click();
894894
});
895-
await gateway.waitForRequest("chat.history");
895+
// Pin each wait past the earlier chat.history traffic so a slow runner
896+
// can't return a stale load-time or prior-page request.
897+
await gateway.waitForRequest("chat.history", { after: initialRequestCount });
896898
await page.locator(".chat-history-loading").waitFor();
897899
expect(await showEarlier.getAttribute("aria-busy")).toBe("true");
898900
if (artifactDir) {
@@ -911,7 +913,7 @@ suite.define(() => {
911913
const failedRequestCount = (await gateway.getRequests("chat.history")).length;
912914
await gateway.deferNext("chat.history");
913915
await showEarlier.click();
914-
await gateway.waitForRequest("chat.history");
916+
await gateway.waitForRequest("chat.history", { after: failedRequestCount });
915917
await page.locator(".chat-history-loading").waitFor();
916918
expect(await gateway.getRequests("chat.history")).toHaveLength(failedRequestCount + 1);
917919
await gateway.resolveDeferred("chat.history", {
@@ -956,7 +958,7 @@ suite.define(() => {
956958
expect(await gateway.getRequests("chat.history")).toHaveLength(firstPageRequestCount);
957959
await gateway.deferNext("chat.history");
958960
await showEarlier.click();
959-
await gateway.waitForRequest("chat.history");
961+
await gateway.waitForRequest("chat.history", { after: firstPageRequestCount });
960962
expect((await gateway.getRequests("chat.history")).at(-1)?.params).toMatchObject({
961963
limit: 100,
962964
offset: 140,

‎ui/src/e2e/desktop-panel.e2e.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,9 +652,11 @@ suite.define(() => {
652652
await gateway.resolveDeferred("desktop.launch", { app: "browser", status: "ready" });
653653
await expect.poll(async () => await browserButton.getAttribute("aria-busy")).toBe("false");
654654

655+
// Pin past the first launch so a slow runner can't return it stale.
656+
const launchesBeforeRetry = (await gateway.getRequests("desktop.launch")).length;
655657
await gateway.deferNext("desktop.launch");
656658
await browserButton.click();
657-
await gateway.waitForRequest("desktop.launch");
659+
await gateway.waitForRequest("desktop.launch", { after: launchesBeforeRetry });
658660
await gateway.rejectDeferred("desktop.launch", {
659661
message: "worker desktop app launch unavailable; try again",
660662
});

‎ui/src/e2e/model-providers.e2e.test.ts‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -712,12 +712,15 @@ describeControlUiE2e("Control UI Models mocked Gateway E2E", () => {
712712

713713
await openaiCard.getByRole("button", { name: "Replace key" }).click();
714714
await openaiCard.getByLabel("API key").fill(openaiInputValue);
715+
// The { after } cursor waits for and returns the save-triggered patch,
716+
// so a slow runner can't hand back an earlier config.patch stale.
715717
const patchCount = (await gateway.getRequests("config.patch")).length;
716718
await openaiCard.getByRole("button", { name: "Save" }).click();
717-
await expect
718-
.poll(async () => (await gateway.getRequests("config.patch")).length)
719-
.toBe(patchCount + 1);
720-
const keyPatch = requestRaw(await gateway.waitForRequest("config.patch"));
719+
const keyPatch = requestRaw(
720+
await gateway.waitForRequest("config.patch", {
721+
after: patchCount,
722+
}),
723+
);
721724
expect(keyPatch).toEqual({
722725
models: { providers: { openai: providerConfig(openaiInputValue) } },
723726
});
@@ -755,10 +758,9 @@ describeControlUiE2e("Control UI Models mocked Gateway E2E", () => {
755758
})
756759
.getByRole("button", { name: "Save" })
757760
.click();
758-
await expect
759-
.poll(async () => (await gateway.getRequests("config.patch")).length)
760-
.toBe(defaultPatchCount + 1);
761-
expect(requestRaw(await gateway.waitForRequest("config.patch"))).toEqual({
761+
expect(
762+
requestRaw(await gateway.waitForRequest("config.patch", { after: defaultPatchCount })),
763+
).toEqual({
762764
agents: {
763765
defaults: {
764766
model: "anthropic/claude-sonnet-4-5",
@@ -822,10 +824,9 @@ describeControlUiE2e("Control UI Models mocked Gateway E2E", () => {
822824
});
823825
const addPatchCount = (await gateway.getRequests("config.patch")).length;
824826
await addSection.getByRole("button", { name: "Save provider" }).click();
825-
await expect
826-
.poll(async () => (await gateway.getRequests("config.patch")).length)
827-
.toBe(addPatchCount + 1);
828-
expect(requestRaw(await gateway.waitForRequest("config.patch"))).toEqual({
827+
expect(
828+
requestRaw(await gateway.waitForRequest("config.patch", { after: addPatchCount })),
829+
).toEqual({
829830
models: { providers: { google: providerConfig(googleInputValue) } },
830831
});
831832
await page.locator('[data-provider-id="google"]').waitFor();

‎ui/src/e2e/session-management.group-defaults.e2e.test.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,19 +275,25 @@ suite.define(() => {
275275
await page.locator(".new-session-page__message").fill("wait for fresh defaults");
276276
await expect.poll(() => start.isEnabled()).toBe(true);
277277

278+
// Pin each wait past earlier sessions.groups.list traffic (the route
279+
// load already fetched the catalog) so a slow runner can't return a
280+
// stale earlier request.
281+
const groupListsBeforeInvalidation = (await gateway.getRequests("sessions.groups.list"))
282+
.length;
278283
await gateway.deferNext("sessions.groups.list");
279284
await gateway.emitGatewayEvent("sessions.changed", { reason: "groups" });
280-
await gateway.waitForRequest("sessions.groups.list");
285+
await gateway.waitForRequest("sessions.groups.list", { after: groupListsBeforeInvalidation });
281286
await expect.poll(() => start.isDisabled()).toBe(true);
282287
await expect
283288
.poll(() => page.locator(".new-session-page__catalog-unavailable button").isDisabled())
284289
.toBe(true);
290+
const groupListsBeforeReject = (await gateway.getRequests("sessions.groups.list")).length;
285291
await gateway.deferNext("sessions.groups.list");
286292
await gateway.rejectDeferred("sessions.groups.list", {
287293
code: "UNAVAILABLE",
288294
message: "catalog reload failed",
289295
});
290-
await gateway.waitForRequest("sessions.groups.list");
296+
await gateway.waitForRequest("sessions.groups.list", { after: groupListsBeforeReject });
291297
await expect
292298
.poll(() => page.locator(".new-session-page__catalog-unavailable").textContent())
293299
.toContain("This session target is unavailable.");
@@ -405,9 +411,12 @@ suite.define(() => {
405411
await expect.poll(() => defaultsAction.textContent()).toContain("Retry");
406412
await expect.poll(() => defaultsAction.isEnabled()).toBe(true);
407413

414+
// Pin past the load-time sessions.groups.list so the retry wait can't
415+
// return it stale.
416+
const groupListsBeforeRetry = (await gateway.getRequests("sessions.groups.list")).length;
408417
await gateway.deferNext("sessions.groups.list");
409418
await defaultsAction.click();
410-
await gateway.waitForRequest("sessions.groups.list");
419+
await gateway.waitForRequest("sessions.groups.list", { after: groupListsBeforeRetry });
411420
await gateway.resolveDeferred("sessions.groups.list", {
412421
groups: [{ name: "Client work", position: 0 }],
413422
});

‎ui/src/test-helpers/control-ui-e2e.ts‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,14 @@ export type MockGatewayControls = {
496496
allowedSessionVisibilities: Array<"shared" | "read-only" | "suggest" | "draft">;
497497
hasMultipleSessionSharingIdentities: boolean;
498498
}) => Promise<void>;
499-
waitForRequest: (method: string) => Promise<MockGatewayRequest>;
499+
/**
500+
* Resolves with a captured request for `method`. Without `after` this is
501+
* satisfied by ANY prior request of the method (and returns the latest), so
502+
* a second same-method wait can return a stale earlier request on slow
503+
* runners; pass `after` = the pre-action count from `getRequests(method)`
504+
* to wait for and return the next new request instead.
505+
*/
506+
waitForRequest: (method: string, options?: { after?: number }) => Promise<MockGatewayRequest>;
500507
};
501508

502509
const chromiumExecutableOverrideEnvKey = "PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH";
@@ -2619,27 +2626,33 @@ function createMockGatewayControls(
26192626
gateway.setSessionSharingPolicy(nextPolicy);
26202627
}, policy);
26212628
},
2622-
async waitForRequest(method) {
2629+
async waitForRequest(method, options) {
26232630
const deadline = Date.now() + controlUiE2eWaitTimeoutMs;
2631+
const after = options?.after;
26242632
for (let attempt = 0; attempt < 2; attempt += 1) {
26252633
try {
26262634
await page.waitForFunction(
2627-
(targetMethod) => {
2635+
({ targetMethod, priorCount }) => {
26282636
const gateway = (
26292637
window as Window & {
26302638
openclawControlUiE2eGateway?: {
26312639
requests: MockGatewayRequest[];
26322640
};
26332641
}
26342642
).openclawControlUiE2eGateway;
2635-
return Boolean(gateway?.requests.some((request) => request.method === targetMethod));
2643+
const matching =
2644+
gateway?.requests.filter((request) => request.method === targetMethod) ?? [];
2645+
return matching.length > (priorCount ?? 0);
26362646
},
2637-
method,
2647+
{ targetMethod: method, priorCount: after ?? 0 },
26382648
// Request capture is non-rendering state. Interval polling avoids background-page
26392649
// requestAnimationFrame throttling when CI runs several headless pages concurrently.
26402650
{ polling: 25, timeout: Math.max(1, deadline - Date.now()) },
26412651
);
2642-
const request = (await getRequests(method)).at(-1);
2652+
const matching = await getRequests(method);
2653+
// With an `after` cursor, return the first NEW request; otherwise keep
2654+
// the historical latest-match behavior existing callers rely on.
2655+
const request = after === undefined ? matching.at(-1) : matching.at(after);
26432656
if (request) {
26442657
return request;
26452658
}

0 commit comments

Comments
 (0)