| 1 | import assert from "node:assert/strict"; |
| 2 | import { mkdir } from "node:fs/promises"; |
| 3 | import path from "node:path"; |
| 4 | import { fileURLToPath } from "node:url"; |
| 5 | import { createServer } from "vite"; |
| 6 | |
| 7 | const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); |
| 8 | process.env.PLAYWRIGHT_BROWSERS_PATH ??= path.join(root, ".pw-browsers"); |
| 9 | const { chromium } = await import("playwright"); |
| 10 | const server = await createServer({ root, logLevel: "error", server: { host: "127.0.0.1", port: 0 } }); |
| 11 | await server.listen(); |
| 12 | let browser; |
| 13 | try { |
| 14 | browser = await chromium.launch({ headless: true, executablePath: process.env.CHROME_EXECUTABLE }); |
| 15 | const page = await browser.newPage({ viewport: { width: 1280, height: 800 } }); |
| 16 | const errors = []; |
| 17 | page.on("pageerror", error => errors.push(error.message)); |
| 18 | await page.goto(`http://127.0.0.1:${server.httpServer.address().port}/bench/draft-recovery.html`); |
| 19 | const alert = page.locator(".session-draft-attention"); |
| 20 | await alert.waitFor(); |
| 21 | assert.equal(await alert.locator(".session-draft-surface__error").count(), 1); |
| 22 | assert.equal(await alert.locator("button").count(), 1, "only submission recovery is offered"); |
| 23 | assert.match(await alert.locator('[role="status"]').innerText(), /Session startup|会话启动|工作階段啟動/); |
| 24 | await alert.locator("button").click(); |
| 25 | assert.equal(await page.evaluate(() => window.draftRecoveryRetries()), 1); |
| 26 | const evidence = process.env.REASONIX_DRAFT_EVIDENCE ?? "/tmp/reasonix-draft-recovery-evidence"; |
| 27 | await mkdir(evidence, { recursive: true }); |
| 28 | await page.screenshot({ path: path.join(evidence, "runtime-failure.png") }); |
| 29 | await page.evaluate(() => window.paintDraftRecovery(true)); |
| 30 | assert.equal(await alert.locator("button").isDisabled(), true); |
| 31 | assert.deepEqual(errors, []); |
| 32 | console.log("PASS real Chromium: distinct startup error, one error row, resume routing, retry disabled while pending"); |
| 33 | } finally { |
| 34 | await browser?.close(); |
| 35 | await server.close(); |
| 36 | } |
| 37 |