返回 DeepSeek-Reasonix
manual-creation-recovery.mjs
根目录 / desktop / frontend / bench / manual-creation-recovery.mjs
1 import assert from "node:assert/strict";
2 import { mkdir } from "node:fs/promises";
3 import { tmpdir } from "node:os";
4 import path from "node:path";
5 import { fileURLToPath } from "node:url";
6 import { createServer } from "vite";
7
8 const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
9 process.env.PLAYWRIGHT_BROWSERS_PATH ??= path.join(root, ".pw-browsers");
10 const { chromium } = await import("playwright");
11 const server = await createServer({ root, logLevel: "error", server: { host: "127.0.0.1", port: 0 } });
12 await server.listen();
13 let browser;
14 try {
15 browser = await chromium.launch({ headless: true, executablePath: process.env.CHROME_EXECUTABLE });
16 const page = await browser.newPage({ viewport: { width: 1100, height: 600 }, locale: "en-US" });
17 const errors = [];
18 page.on("pageerror", error => errors.push(error.message));
19 await page.goto(`http://127.0.0.1:${server.httpServer.address().port}/bench/manual-creation-recovery.html`);
20 await page.getByText(/You can type now/).waitFor();
21 assert.doesNotMatch(await page.locator("body").innerText(), /\/private\/old-project|global/);
22 const retry = page.getByRole("button", { name: "Try again", exact: true });
23 assert.equal(await retry.count(), 0, "automatic lock waiting needs no user decision");
24 await page.evaluate(() => window.creationFixture.setStatus("waiting_workspace"));
25 await page.getByText(/project is temporarily unavailable/).waitFor();
26 assert.equal(await retry.count(), 0, "temporary directory recovery needs no user decision");
27 await page.evaluate(() => window.creationFixture.setStatus("blocked"));
28 await page.getByText(/could not be prepared/).waitFor();
29 await page.getByText("Details", { exact: true }).click();
30 await page.getByRole("button", { name: "Export creation diagnostics" }).click();
31 assert.equal((await page.evaluate(() => window.creationFixture.counts())).exports, 1);
32 const evidence = process.env.REASONIX_CREATION_EVIDENCE ?? path.join(tmpdir(), "reasonix-creation-evidence");
33 await mkdir(evidence, { recursive: true });
34 await page.screenshot({ path: path.join(evidence, "recovery.png") });
35 await retry.click();
36 assert.equal(await retry.isDisabled(), true);
37 assert.equal((await page.evaluate(() => window.creationFixture.counts())).retries, 1);
38 await page.evaluate(() => window.creationFixture.finish());
39 await page.getByText(/You can type now/).waitFor();
40 assert.equal(await retry.count(), 0);
41 assert.equal(await page.locator("button").count(), 0);
42 assert.deepEqual(errors, []);
43 console.log("PASS Chromium: automatic lock/directory recovery, coalesced failure retry, initialization feedback and optional diagnostics; no page errors");
44 } finally {
45 await browser?.close();
46 await server.close();
47 }
48
48 lines Plain Text