TypeScript
chore(mobile): e2e runner retries pool failures and reports them apart from app failures
Julius Marmingecb7e3814d71c
diff --git a/scripts/mobile-e2e.ts b/scripts/mobile-e2e.tsindex 9b3466dd2a7..a198197a6a9 100644--- a/scripts/mobile-e2e.ts+++ b/scripts/mobile-e2e.ts@@ -8,10 +8,16 @@ import * as NodePath from "node:path";import * as NodeProcess from "node:process";import * as NodeURL from "node:url";-import { Device, type Pool, run } from "./mobile-e2e/device.ts";+import { Device, type Pool, poolError, run } from "./mobile-e2e/device.ts";import { runJourney, type StepResult } from "./mobile-e2e/journey.ts";import { POSES, type Pose } from "./mobile-e2e/poses.ts";-import { failedChecks, poseFailed, type PoseResult, renderReport } from "./mobile-e2e/report.ts";+import {+ failedChecks,+ poolBlocked,+ poseFailed,+ type PoseResult,+ renderReport,+} from "./mobile-e2e/report.ts";import { reviewPose } from "./mobile-e2e/review.ts";import {reserveAvailablePort,@@ -247,11 +253,17 @@ async function main() {issuePairUrl(environment, host),);const runOne = async (pose: Pose) => {- const first = await attempt(pose, runId);+ let result = await attempt(pose, runId);// A pose that failed before its first screen usually met the pool, not the app.- if (!first.error || first.steps.length > 0) return first;- log(pose.id, `retrying after: ${first.error.split("\n")[0]}`);- return attempt(pose, `${runId}-retry`);+ for (+ let retry = 1;+ retry <= 2 && result.error && (result.steps.length === 0 || poolError(result.error));+ retry+++ ) {+ log(pose.id, `retrying after: ${result.error.split("\n")[0]}`);+ result = await attempt(pose, `${runId}-retry${retry}`);+ }+ return result;};// Each platform has its own workers, so each gets its own limit; one Mac runs every// iOS simulator, and recording several at once on a shared pool times it out.@@ -289,20 +301,25 @@ async function main() {);log(result.pose.id,- [result.error, ...failures].filter(Boolean).join("; ") ||+ [poolBlocked(result) ? `blocked by the pool: ${result.error}` : result.error, ...failures]+ .filter(Boolean)+ .join("; ") ||`passed${result.findings?.length ? `, ${result.findings.length} review findings` : ""}`,);}- const failed = reviewed.filter(poseFailed).length;+ const failed = reviewed.filter((result) => poseFailed(result) && !poolBlocked(result)).length;+ const blocked = reviewed.filter(poolBlocked).length;NodeProcess.stdout.write(`${JSON.stringify({report,poses: reviewed.length,failed,+ blocked,findings: reviewed.reduce((count, result) => count + (result.findings?.length ?? 0), 0),})}\n`,);- process.exitCode = failed ? 1 : 0;+ // A pose the pool blocked was not tested, so it fails the run too.+ process.exitCode = failed || blocked ? 1 : 0;} finally {if (metro?.pid) {try {diff --git a/scripts/mobile-e2e/device.ts b/scripts/mobile-e2e/device.tsindex 5a8175eab22..fd0517f97ac 100644--- a/scripts/mobile-e2e/device.ts+++ b/scripts/mobile-e2e/device.ts@@ -67,6 +67,13 @@ export class AgentDeviceError extends Error {}const TRANSIENT =/Remote daemon is unavailable|not connected to the gateway|still finishing a previous command|Invalid daemon response|Daemon request timed out|no worker connected/i;+/** Failures that say the pool could not serve the pose, not that the app misbehaved. */+export const poolError = (message: string) =>+ TRANSIENT.test(message) ||+ /Daemon connection closed|WORKER_UNREACHABLE|xcrun timed out|refused by simlock|is not available on this simlock/i.test(+ message,+ );+export class Device {readonly pose: Pose;readonly session: string;diff --git a/scripts/mobile-e2e/journey.ts b/scripts/mobile-e2e/journey.tsindex 65e3cfa6d1b..afb0393b5f8 100644--- a/scripts/mobile-e2e/journey.ts+++ b/scripts/mobile-e2e/journey.ts@@ -113,26 +113,43 @@ export async function runJourney(findLabel(snapshot, /^(Dismiss|OK|Close)$/) !== undefined? findLabel(snapshot, /^Could not|failed|went wrong/i): undefined;- for (let dialogs = 0; ; dialogs++) {- const launch = await device.waitFor(- (snapshot) => loaded(snapshot) || errorDialog(snapshot) !== undefined,- "the app to load",- 180_000,- );- const dialog = errorDialog(launch);- if (!dialog || dialogs >= 3) break;- await capture("launch error", launch, [- check("no error dialog on launch", false, dialog.label ?? "error dialog"),- ]);- await device.agent(["press", `label="${findLabel(launch, /^(Dismiss|OK|Close)$/)!.label}"`]);- await delay(1_000);- }+ let dialogs = 0;+ /** Waits for `ready`, recording and dismissing up to three error dialogs on the way. */+ const settle = async (+ ready: (snapshot: Snapshot) => boolean,+ label: string,+ timeoutMs: number,+ ) => {+ for (;;) {+ const snapshot = await device.waitFor(+ (current) => ready(current) || errorDialog(current) !== undefined,+ label,+ timeoutMs,+ );+ const dialog = errorDialog(snapshot);+ if (!dialog || dialogs >= 3) return snapshot;+ dialogs++;+ await capture("launch error", snapshot, [+ check("no error dialog on launch", false, dialog.label ?? "error dialog"),+ ]);+ await device.agent([+ "press",+ `label="${findLabel(snapshot, /^(Dismiss|OK|Close)$/)!.label}"`,+ ]);+ await delay(1_000);+ }+ };+ await settle(loaded, "the app to load", 180_000);let threads: Snapshot | null = null;for (let attempt = 1; attempt <= 2 && !threads; attempt++) {const pairing = new URLSearchParams({ pairingUrl: await pair(), autoConnect: "1" });await device.openUrl(`t3code-dev://connections/new?${pairing}`);- threads = await device- .waitFor((snapshot) => threadRow(snapshot) !== undefined, "the paired thread list", 60_000)+ threads = await settle(+ (snapshot) => threadRow(snapshot) !== undefined,+ "the paired thread list",+ 60_000,+ )+ .then((snapshot) => (threadRow(snapshot) ? snapshot : null)).catch(() => null);}if (!threads) throw new Error("the app did not show the fixture threads after pairing");diff --git a/scripts/mobile-e2e/report.ts b/scripts/mobile-e2e/report.tsindex 177255fb62a..72f03942225 100644--- a/scripts/mobile-e2e/report.ts+++ b/scripts/mobile-e2e/report.ts@@ -2,6 +2,7 @@import * as NodePath from "node:path";+import { poolError } from "./device.ts";import type { StepResult } from "./journey.ts";import type { Pose } from "./poses.ts";@@ -28,6 +29,10 @@ export const failedChecks = (result: PoseResult) =>export const poseFailed = (result: PoseResult) =>result.error !== undefined || failedChecks(result).length > 0;+/** The pool never let the pose finish, so it says nothing about the app. */+export const poolBlocked = (result: PoseResult) =>+ result.error !== undefined && poolError(result.error) && failedChecks(result).length === 0;+const escapeHtml = (value: string) =>value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");@@ -75,16 +80,17 @@ export function renderReport(results: ReadonlyArray<PoseResult>, outputDirectory}).join("");const error = result.error- ? `<td class="bad"><h3>stopped</h3>${result.stopped ? `<a href="${relative(result.stopped)}"><img src="${relative(result.stopped)}"></a>` : ""}<p class="fail">${escapeHtml(result.error)}</p></td>`+ ? `<td class="bad"><h3>${poolBlocked(result) ? "blocked by the pool" : "stopped"}</h3>${result.stopped ? `<a href="${relative(result.stopped)}"><img src="${relative(result.stopped)}"></a>` : ""}<p class="fail">${escapeHtml(result.error)}</p></td>`: "";return `<tr><th>${escapeHtml(result.pose.id)}<br><small>${escapeHtml(describePose(result.pose))}</small></th>${cells}${error}</tr>`;}).join("");- const failed = results.filter(poseFailed).length;+ const failed = results.filter((result) => poseFailed(result) && !poolBlocked(result)).length;+ const blocked = results.filter(poolBlocked).length;const findings = results.reduce((count, result) => count + (result.findings?.length ?? 0), 0);return `<!doctype html><meta charset="utf-8"><title>Mobile E2E</title><style>body{font:14px system-ui;margin:24px}table{border-collapse:collapse}td,th{border:1px solid #ddd;padding:8px;vertical-align:top;text-align:left}td{width:190px}td.bad{background:#fff5f4}h3{margin:0 0 6px;font-size:13px}img{width:180px;display:block;margin:0 0 6px}img.lag{outline:3px solid #b42318}.pass{color:#16794a}.fail{color:#b42318}.review{color:#7a4b00}.review.high{color:#b42318}ul{padding-left:16px;margin:4px 0}small{color:#666}</style>-<h1>Mobile E2E · ${results.length} poses · ${failed === 0 ? "all checks passed" : `${failed} with failing checks`} · ${findings} review findings</h1>+<h1>Mobile E2E · ${results.length} poses · ${failed === 0 ? "all checks passed" : `${failed} with failing checks`}${blocked ? ` · ${blocked} blocked by the pool` : ""} · ${findings} review findings</h1><p><span class="fail">✗</span> failed check <span class="review">◆</span> agent review finding</p><table>${rows}</table>`;}