Skip to content

Commit a2bdbcc

Browse files
committed
fix(ui): retain cloud profiles after refresh failure
1 parent 1af9b07 commit a2bdbcc

2 files changed

Lines changed: 91 additions & 5 deletions

File tree

‎ui/src/e2e/new-session-page.cloud-dispatch.e2e.test.ts‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
import { mkdir } from "node:fs/promises";
2+
import path from "node:path";
13
import { expect, it } from "vitest";
24
import { createDeferred } from "../../../test/helpers/promise.js";
5+
import { CLOUD_PROFILE_RETRY_DELAYS_MS } from "../pages/new-session/cloud-profile-discovery.ts";
36
import {
47
ONE_PIXEL_PNG_B64,
58
SESSION_LIST_DEFAULTS,
69
TARGET_REPO,
710
WORKSPACE,
811
captureUiProof,
12+
captureUiProofEnabled,
913
controlUiSessionPath,
1014
controlUiSessionUrl,
1115
createNewSessionPageE2eSuite,
@@ -21,13 +25,25 @@ import {
2125
const suite = createNewSessionPageE2eSuite();
2226
const SESSION_PLACEMENT_STARTUP_RUNTIME_REQUEST =
2327
/\/assets\/session-placement-startup\.runtime-[^/?]+\.js(?:\?.*)?$/;
28+
const cloudProfileRefreshProofDir = path.join(
29+
process.cwd(),
30+
".artifacts",
31+
"control-ui-e2e",
32+
"cloud-profile-refresh-retention",
33+
);
2434

2535
suite.define(() => {
2636
it("dispatches a cloud target before sending its first turn and shows placement", async () => {
37+
if (captureUiProofEnabled) {
38+
await mkdir(cloudProfileRefreshProofDir, { recursive: true });
39+
}
2740
const context = await suite.browser.newContext({
2841
locale: "en-US",
2942
serviceWorkers: "block",
3043
viewport: { height: 900, width: 1280 },
44+
...(captureUiProofEnabled
45+
? { recordVideo: { dir: cloudProfileRefreshProofDir, size: { height: 900, width: 1280 } } }
46+
: {}),
3147
});
3248
const page = await context.newPage();
3349
const runtimeLoad = createDeferred();
@@ -269,6 +285,69 @@ suite.define(() => {
269285
.toBeGreaterThan(failedProfileRequests);
270286
await expect.poll(() => startButton.isDisabled()).toBe(false);
271287

288+
if (captureUiProofEnabled) {
289+
await trigger.click();
290+
await page.screenshot({
291+
animations: "disabled",
292+
fullPage: true,
293+
path: path.join(cloudProfileRefreshProofDir, "01-before-refresh.png"),
294+
});
295+
await page.keyboard.press("Escape");
296+
}
297+
298+
await page.clock.install();
299+
await gateway.setMethodResponse("environments.list", {
300+
__mockError: { code: "UNAVAILABLE", message: "profile catalog remains unavailable" },
301+
});
302+
await gateway.deferNext("environments.list");
303+
const requestsBeforePersistentFailure = (await gateway.getRequests("environments.list"))
304+
.length;
305+
await gateway.emitGatewayEvent("node.runnerInventory.changed");
306+
await gateway.waitForRequest("environments.list", {
307+
after: requestsBeforePersistentFailure,
308+
});
309+
await expect.poll(() => startButton.isDisabled()).toBe(true);
310+
if (captureUiProofEnabled) {
311+
await page.screenshot({
312+
animations: "disabled",
313+
fullPage: true,
314+
path: path.join(cloudProfileRefreshProofDir, "02-refresh-pending.png"),
315+
});
316+
}
317+
await gateway.rejectDeferred("environments.list", {
318+
code: "UNAVAILABLE",
319+
message: "profile catalog remains unavailable",
320+
});
321+
322+
for (const delayMs of CLOUD_PROFILE_RETRY_DELAYS_MS) {
323+
const requestsBeforeRetry = (await gateway.getRequests("environments.list")).length;
324+
await page.clock.runFor(delayMs + 1);
325+
await gateway.waitForRequest("environments.list", { after: requestsBeforeRetry });
326+
}
327+
await page.clock.resume();
328+
expect(await gateway.getRequests("environments.list")).toHaveLength(
329+
requestsBeforePersistentFailure + 1 + CLOUD_PROFILE_RETRY_DELAYS_MS.length,
330+
);
331+
await expect.poll(() => trigger.getAttribute("data-cloud-profile")).toBe("aws");
332+
await expect.poll(() => trigger.getAttribute("data-machine-class")).toBe("fast");
333+
await pollLocatorText(trigger.locator(".new-session-page__trigger-label")).toBe("aws · Fast");
334+
await expect.poll(() => startButton.isDisabled()).toBe(false);
335+
await trigger.click();
336+
const retainedCloudProfile = place.getByRole("button", { name: "Cloud · aws" });
337+
await expect.poll(() => retainedCloudProfile.isDisabled()).toBe(false);
338+
expect(await retainedCloudProfile.getAttribute("title")).toBe(
339+
"Cloud worker provider: crabbox",
340+
);
341+
await expect.poll(() => place.getByRole("button", { name: /Fast/ }).isVisible()).toBe(true);
342+
if (captureUiProofEnabled) {
343+
await page.screenshot({
344+
animations: "disabled",
345+
fullPage: true,
346+
path: path.join(cloudProfileRefreshProofDir, "03-after-retry-exhaustion.png"),
347+
});
348+
}
349+
await page.keyboard.press("Escape");
350+
272351
await startButton.click();
273352

274353
const create = await gateway.waitForRequest("sessions.create");
@@ -297,6 +376,13 @@ suite.define(() => {
297376
profileId: "aws",
298377
machineClass: "fast",
299378
});
379+
if (captureUiProofEnabled) {
380+
await page.screenshot({
381+
animations: "disabled",
382+
fullPage: true,
383+
path: path.join(cloudProfileRefreshProofDir, "04-session-dispatch.png"),
384+
});
385+
}
300386
const describeRequestsAfterNavigation = (await gateway.getRequests("sessions.describe"))
301387
.length;
302388
await expect.poll(() => page.url()).toContain(controlUiSessionPath(sessionKey));

‎ui/src/pages/new-session/draft-gateway-state.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ export class DraftGatewayState {
134134
this.callbacks.requestUpdate();
135135
},
136136
onError: () => {
137-
// Keep the last environment catalog across a transient client refresh on this Gateway.
138-
this.cloudProfilesValue = [];
139-
this.cloudProfilesReadyValue = false;
137+
// A failed refresh cannot invalidate this Gateway's last successful place catalog.
140138
this.scheduleCloudProfileRetry();
141139
this.callbacks.requestUpdate();
142140
},
@@ -497,8 +495,10 @@ export class DraftGatewayState {
497495
return;
498496
}
499497
if (this.cloudProfileRetryAttempt >= CLOUD_PROFILE_RETRY_DELAYS_MS.length) {
500-
this.applyCloudProfiles([]);
501-
this.cloudProfilesReadyValue = true;
498+
if (!this.cloudProfilesReadyValue) {
499+
this.applyCloudProfiles([]);
500+
this.cloudProfilesReadyValue = true;
501+
}
502502
return;
503503
}
504504
const delayMs = CLOUD_PROFILE_RETRY_DELAYS_MS[this.cloudProfileRetryAttempt];

0 commit comments

Comments
 (0)