(runDir: string)
| 37 | ); |
| 38 | |
| 39 | const run = async (runDir: string) => { |
| 40 | // Throwaway HOME = fresh ~/.executor data dir, fresh electron-store |
| 41 | // settings, no collision with a real desktop install on this machine. |
| 42 | const home = mkdtempSync(join(tmpdir(), "executor-desktop-e2e-")); |
| 43 | const videoTmp = join(runDir, ".video-tmp"); |
| 44 | let stepIndex = 0; |
| 45 | |
| 46 | const app = await _electron.launch({ |
| 47 | executablePath: electronBinary, |
| 48 | args: [appDir], |
| 49 | cwd: appDir, |
| 50 | env: { ...process.env, HOME: home }, |
| 51 | recordVideo: { dir: videoTmp, size: { width: 1280, height: 800 } }, |
| 52 | timeout: 120_000, |
| 53 | }); |
| 54 | |
| 55 | try { |
| 56 | // firstWindow resolves only after the sidecar boots (the window is |
| 57 | // created with the server's URL) — this wait IS the boot assertion. |
| 58 | const page = await app.firstWindow({ timeout: 120_000 }); |
| 59 | const step = async (label: string, body: () => Promise<void>) => { |
| 60 | await body(); |
| 61 | stepIndex += 1; |
| 62 | const slug = label.toLowerCase().replace(/[^a-z0-9]+/g, "-"); |
| 63 | await page.screenshot({ |
| 64 | path: join(runDir, `${String(stepIndex).padStart(2, "0")}-${slug}.png`), |
| 65 | }); |
| 66 | }; |
| 67 | |
| 68 | await step("app boots into the web console", async () => { |
| 69 | await page.getByText("Settings").first().waitFor({ timeout: 120_000 }); |
| 70 | }); |
| 71 | |
| 72 | let sidecarPid = 0; |
| 73 | await step("the local server is killed (SIGKILL)", async () => { |
| 74 | const manifestPath = join(home, ".executor/server-control/server.json"); |
| 75 | const manifest = JSON.parse(readFileSync(manifestPath, "utf8")) as { pid: number }; |
| 76 | sidecarPid = manifest.pid; |
| 77 | expect(sidecarPid, "sidecar pid recorded in the server manifest").toBeGreaterThan(0); |
| 78 | process.kill(sidecarPid, "SIGKILL"); |
| 79 | await page.getByText("stopped unexpectedly").waitFor({ timeout: 30_000 }); |
| 80 | }); |
| 81 | |
| 82 | await step("crash screen offers restart, update, and diagnostics", async () => { |
| 83 | await page.locator("#restart").waitFor({ timeout: 5_000 }); |
| 84 | await page.locator("#update").waitFor({ timeout: 5_000 }); |
| 85 | await page.locator("#export").waitFor({ timeout: 5_000 }); |
| 86 | }); |
| 87 | |
| 88 | await step("restart server heals the app", async () => { |
| 89 | await page.locator("#restart").click(); |
| 90 | await page.getByText("Settings").first().waitFor({ timeout: 120_000 }); |
| 91 | }); |
| 92 | |
| 93 | const healedManifest = JSON.parse( |
| 94 | readFileSync(join(home, ".executor/server-control/server.json"), "utf8"), |
| 95 | ) as { pid: number }; |
| 96 | expect(healedManifest.pid, "restarted sidecar is a new process").not.toBe(sidecarPid); |
no test coverage detected