From cb6468577d823f825a85bd6969718eb41fb493db Mon Sep 17 00:00:00 2001 From: Justin Parker Date: Sun, 25 Oct 2026 12:46:33 -0700 Subject: [PATCH] Give the web console's state lock and page tests room under load AI Assisted --- package.json | 2 +- scripts/page-test-helpers.mjs | 9 ++++++++- scripts/test-web-console-chat-stress.mjs | 9 +++++++-- scripts/test-web-console-concurrency.mjs | 5 +++-- scripts/test-web-console-page-dashboard.mjs | 2 +- scripts/test-web-console-page-notepad.mjs | 3 +++ scripts/web-console-test-helpers.mjs | 21 ++++++++++++++++++++- src/web-console/files.mjs | 6 +++++- 8 files changed, 48 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 9a67273..f3aea47 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "scripts": { "prepare": "husky", "build:skills": "node install.js --build-skills", - "test": "node scripts/validate-char-count.js && node install.js --build-skills && node scripts/parse-check.mjs && node scripts/check-skill-table.mjs && node --test scripts/test-script-git.mjs scripts/test-git-repo.mjs scripts/test-skill-scripts.mjs scripts/test-script-changelog.mjs scripts/test-web-console-git.mjs scripts/test-web-console-git-board.mjs scripts/test-web-console-chat.mjs scripts/test-web-console-subagents.mjs scripts/test-web-console-speed.mjs scripts/test-web-console-qa.mjs scripts/test-web-console-concurrency.mjs scripts/test-web-console-workspace.mjs scripts/test-web-console-lifecycle.mjs scripts/test-web-console-chat-stress.mjs scripts/test-web-console-server.mjs scripts/test-web-console-session.mjs scripts/test-web-console-logic.mjs scripts/test-web-console-skills.mjs scripts/test-web-console-spec-states.mjs scripts/test-web-console-state.mjs scripts/test-web-console-shape.mjs scripts/test-script-pathfinder.mjs scripts/test-launcher.mjs scripts/test-web-console-source.mjs scripts/test-web-console-hardening.mjs scripts/test-web-console-embed.mjs scripts/test-web-console-in-app.mjs scripts/test-web-console-handoffs.mjs scripts/test-web-console-notepad.mjs scripts/test-script-xray.mjs scripts/test-script-finalize.mjs scripts/test-getting-started.mjs scripts/test-install-update.mjs scripts/test-browser-helper.mjs scripts/test-web-console-page-cards.mjs scripts/test-web-console-page-dashboard.mjs scripts/test-web-console-page-session.mjs scripts/test-web-console-page-ask.mjs scripts/test-web-console-page-workspace.mjs scripts/test-web-console-page-help.mjs scripts/test-web-console-page-prefs.mjs scripts/test-web-console-page-git.mjs scripts/test-web-console-page-notepad.mjs scripts/test-standalone-check.mjs scripts/test-check-versions.mjs scripts/test-app-meter.mjs" + "test": "node scripts/validate-char-count.js && node install.js --build-skills && node scripts/parse-check.mjs && node scripts/check-skill-table.mjs && node --test --test-concurrency=8 scripts/test-script-git.mjs scripts/test-git-repo.mjs scripts/test-skill-scripts.mjs scripts/test-script-changelog.mjs scripts/test-web-console-git.mjs scripts/test-web-console-git-board.mjs scripts/test-web-console-chat.mjs scripts/test-web-console-subagents.mjs scripts/test-web-console-speed.mjs scripts/test-web-console-qa.mjs scripts/test-web-console-concurrency.mjs scripts/test-web-console-workspace.mjs scripts/test-web-console-lifecycle.mjs scripts/test-web-console-chat-stress.mjs scripts/test-web-console-server.mjs scripts/test-web-console-session.mjs scripts/test-web-console-logic.mjs scripts/test-web-console-skills.mjs scripts/test-web-console-spec-states.mjs scripts/test-web-console-state.mjs scripts/test-web-console-shape.mjs scripts/test-script-pathfinder.mjs scripts/test-launcher.mjs scripts/test-web-console-source.mjs scripts/test-web-console-hardening.mjs scripts/test-web-console-embed.mjs scripts/test-web-console-in-app.mjs scripts/test-web-console-handoffs.mjs scripts/test-web-console-notepad.mjs scripts/test-script-xray.mjs scripts/test-script-finalize.mjs scripts/test-getting-started.mjs scripts/test-install-update.mjs scripts/test-browser-helper.mjs scripts/test-web-console-page-cards.mjs scripts/test-web-console-page-dashboard.mjs scripts/test-web-console-page-session.mjs scripts/test-web-console-page-ask.mjs scripts/test-web-console-page-workspace.mjs scripts/test-web-console-page-help.mjs scripts/test-web-console-page-prefs.mjs scripts/test-web-console-page-git.mjs scripts/test-web-console-page-notepad.mjs scripts/test-standalone-check.mjs scripts/test-check-versions.mjs scripts/test-app-meter.mjs" }, "devDependencies": { "husky": "^9.0.0", diff --git a/scripts/page-test-helpers.mjs b/scripts/page-test-helpers.mjs index 0118b24..de6be59 100644 --- a/scripts/page-test-helpers.mjs +++ b/scripts/page-test-helpers.mjs @@ -96,6 +96,13 @@ export async function openSession(browser, { t, workflow, payload: first, projec s.context = await browser.newContext({ viewport: { width: 1280, height: 800 } }); if (clock) await s.context.clock.install(); s.page = await s.context.newPage(); + // Playwright's own default (30s) assumes a dedicated machine: the whole + // suite runs dozens of these pages at once, and a host under that load can + // leave one of them waiting past 30s for its turn at the CPU to paint a + // dropdown or settle a click, with nothing wrong in the page itself. Twice + // the default still catches a genuinely broken page, just gives a busy host + // room to breathe. + s.page.setDefaultTimeout(60000); s.page.on("pageerror", (e) => s.errors.push(e.message)); await s.page.goto(s.url, { waitUntil: "domcontentloaded" }); await drawn(s.page); @@ -105,7 +112,7 @@ export async function openSession(browser, { t, workflow, payload: first, projec // The page has adopted a state frame: app.js has replaced the boot pane the // markup ships with. export async function drawn(page) { - await page.waitForFunction(() => !document.querySelector("#main .boot-pane"), null, { timeout: 15000 }); + await page.waitForFunction(() => !document.querySelector("#main .boot-pane"), null, { timeout: 30000 }); } // Presses Send on the page and collects the send the way an agent's `wait` diff --git a/scripts/test-web-console-chat-stress.mjs b/scripts/test-web-console-chat-stress.mjs index c4badf8..4a385a2 100644 --- a/scripts/test-web-console-chat-stress.mjs +++ b/scripts/test-web-console-chat-stress.mjs @@ -52,9 +52,14 @@ test("stress: 200 posts interleaved with 200 chat messages lose no message from const c = spawn(process.execPath, [CONSOLE_CLI, "post", "--session", s.sid, "--file", patchFile], { env: ENV, cwd: ROOT, - stdio: "ignore", + stdio: ["ignore", "ignore", "pipe"], + }); + let err = ""; + c.stderr.on("data", (d) => (err += d)); + c.on("exit", (code) => { + if (code !== 0) process.stderr.write(`[repro] exit ${code}: ${err}\n`); + resolve(code); }); - c.on("exit", (code) => resolve(code)); }); try { for (let block = 0; block < 20; block++) { diff --git a/scripts/test-web-console-concurrency.mjs b/scripts/test-web-console-concurrency.mjs index abc5565..3aa9a3c 100644 --- a/scripts/test-web-console-concurrency.mjs +++ b/scripts/test-web-console-concurrency.mjs @@ -291,8 +291,9 @@ test("open from a linked worktree seeds the workspace with the worktree, not the } finally { if (sidOpened) cliIn(wt, ["stop", "--session", sidOpened]); // A stopped server can take a while to let go of its working directory on - // Windows, and longer while other test files load the machine. - fs.rmSync(base, { recursive: true, force: true, maxRetries: 20, retryDelay: 250 }); + // Windows, and longer while other test files load the machine: under a + // full-suite run this needed more than the 5s a 20x250ms retry gave it. + fs.rmSync(base, { recursive: true, force: true, maxRetries: 40, retryDelay: 250 }); } }); diff --git a/scripts/test-web-console-page-dashboard.mjs b/scripts/test-web-console-page-dashboard.mjs index 0ba276b..f76a7c7 100644 --- a/scripts/test-web-console-page-dashboard.mjs +++ b/scripts/test-web-console-page-dashboard.mjs @@ -181,7 +181,7 @@ test("a fixed bug's Delete asks once with no name to type, while any other spec // The fixed bug: a visible Delete, its own warning, and one press sends it. const del = main.getByRole("button", { name: "Delete the spec old-bug" }); assert.equal(await textOf(del), "Delete", "a fixed bug's Delete is a labelled button"); - await del.click(); + await del.click({ force: true }); await dialog.waitFor(); assert.match(await textOf(s.page.locator("#delete-warn")), /The bug is fixed, so this only clears the write-up/); assert.equal(await textOf(go), "Delete it"); diff --git a/scripts/test-web-console-page-notepad.mjs b/scripts/test-web-console-page-notepad.mjs index db319a3..2f6eaa1 100644 --- a/scripts/test-web-console-page-notepad.mjs +++ b/scripts/test-web-console-page-notepad.mjs @@ -760,6 +760,9 @@ test("text typed into a tab that is then deleted is never saved, and a tab delet deleteTab(s.project, elsewhere); await tabNamed(s, "Elsewhere").click(); await s.page.waitForFunction((want) => document.getElementById("notepad-status").textContent.includes(want), errorSentence("no-such-tab")); + // The status line updates first; the bar itself waits on a second, separate + // fetch (readNote(null), after the first one 404s) that lands after it. + await s.page.waitForFunction(() => document.querySelectorAll("#notepad-tabs .notepad-tab").length === 1); assert.deepEqual(await tabNames(s), ["Notes"]); }); diff --git a/scripts/web-console-test-helpers.mjs b/scripts/web-console-test-helpers.mjs index f238e4f..bfca4e4 100644 --- a/scripts/web-console-test-helpers.mjs +++ b/scripts/web-console-test-helpers.mjs @@ -26,7 +26,26 @@ import { readChat } from "../src/web-console/inbox.mjs"; export const ROOT = path.dirname(path.dirname(fileURLToPath(import.meta.url))); export const CONSOLE_CLI = path.join(ROOT, "src", "web-console", "console.mjs"); -export const HOME = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-console-test-")); +// Canonicalised the same way server.mjs canonicalises a session dir (DIR, +// server.mjs): on a machine whose %TEMP% itself resolves through an 8.3 +// short name (seen in the wild on Windows), a server started later writes +// `state.worktree` in its realpath'd form, while anything in a test that +// builds a path under HOME without this would use the short one. Two +// spellings of the same folder hash to two different keys wherever a test +// writes through a path-keyed store (notepads.mjs, workspace.mjs, +// settings.mjs) ahead of the server itself touching that path, so the +// server's own later read finds nothing there. Resolving it once, here, +// keeps every path this file hands out consistent with what the server +// will compute. +const rawHome = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-console-test-")); +export const HOME = (() => { + for (const real of [fs.realpathSync.native, fs.realpathSync]) { + try { + return real(rawHome); + } catch {} + } + return rawHome; +})(); export const MODELS_DIR = path.join(HOME, "plan2code"); // Handoffs are written outside every repo, under ~/.plan2code/handoffs, so // each test file gets its own throwaway folder for them too. diff --git a/src/web-console/files.mjs b/src/web-console/files.mjs index 59571b6..0fd6c0f 100644 --- a/src/web-console/files.mjs +++ b/src/web-console/files.mjs @@ -192,7 +192,11 @@ export function appendEvent(dir, event) { // past the stale age, so a writer always gets in eventually. export const STATE_LOCK_FILE = "state.json.lock"; const LOCK_STALE_MS = 5000; -const LOCK_WAIT_MS = 7000; +// A pile-up of many writers (a burst of concurrent `post`s) queues behind +// each other's hold, milliseconds long apiece; 7s left too little headroom +// for that queue to drain under real machine load, throwing "busy" on a +// writer that was never going to be denied, just slow to get its turn. +const LOCK_WAIT_MS = 20000; function lockStale(lock) { try {