Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

Detect an unusable MCP browser, and stop slot 0 colliding with a human e2e run

Jerome23a4599ad24a
diff --git a/.claude/hooks/ensure-playwright-mcp.mjs b/.claude/hooks/ensure-playwright-mcp.mjs
index 0126cac4..f727f593 100644
--- a/.claude/hooks/ensure-playwright-mcp.mjs
+++ b/.claude/hooks/ensure-playwright-mcp.mjs
@@ -18,6 +18,7 @@
import { existsSync, statSync } from "node:fs";
import { readFileSync } from "node:fs";
import { spawn } from "node:child_process";
+import { createRequire } from "node:module";
import { join } from "node:path";
import { createHookContext } from "./lib/context.mjs";
@@ -32,8 +33,24 @@ const ctx = createHookContext(input, "ensure-playwright-mcp");
const repo = process.env.CLAUDE_PROJECT_DIR || process.cwd();
const mcpCli = join(repo, "node_modules", "@playwright", "mcp", "cli.js");
+// The package alone is not enough: with the cli.js present but its Chromium missing,
+// playwright-mcp.sh drops --executable-path and the MCP falls back to the `chrome`
+// channel, which provisioning never installs — every browser_navigate then dies with
+// "Chromium distribution 'chrome' is not found". Mirror that script's own predicate
+// (playwright-core's resolved executablePath) so the two can't drift.
+function chromiumPath() {
+ try {
+ const require_ = createRequire(join(repo, "package.json"));
+ return require_("playwright-core").chromium.executablePath();
+ } catch {
+ return "";
+ }
+}
+
+const chromium = existsSync(mcpCli) ? chromiumPath() : "";
+
// Present -> nothing to do. Fast path, no output (avoid per-session noise).
-if (existsSync(mcpCli)) {
+if (chromium && existsSync(chromium)) {
ctx.log("playwright MCP present");
process.exit(0);
}
@@ -75,7 +92,11 @@ if (!installing && process.env.PLAYWRIGHT_MCP_CHECK_ONLY !== "1") {
);
}
} else {
- ctx.log("playwright MCP missing -> install already in progress");
+ ctx.log(
+ installing
+ ? "playwright MCP unusable -> install already in progress"
+ : "playwright MCP unusable -> check-only, no install started",
+ );
}
// Warn the session: the MCP cannot connect mid-session, so feature-smoke degrades to
@@ -85,7 +106,7 @@ process.stdout.write(
hookSpecificOutput: {
hookEventName: "SessionStart",
additionalContext:
- `<playwright-mcp-status>NOT INSTALLED. The Playwright MCP browser is being ` +
+ `<playwright-mcp-status>NOT USABLE (package or Chromium missing). The Playwright MCP browser is being ` +
`provisioned in the background (log: ${installLog}). For THIS session the harness ` +
`feature-smoke (MODE: feature-smoke) cannot drive the UI and will fall back to ` +
`static/compile checks; the Supabase e2e-smoke (CLI Playwright) is unaffected. It ` +
diff --git a/.claude/hooks/test/ensure-playwright-mcp.test.mjs b/.claude/hooks/test/ensure-playwright-mcp.test.mjs
new file mode 100644
index 00000000..d2210c49
--- /dev/null
+++ b/.claude/hooks/test/ensure-playwright-mcp.test.mjs
@@ -0,0 +1,85 @@
+import { spawnSync } from "node:child_process";
+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { dirname, join } from "node:path";
+import { fileURLToPath } from "node:url";
+import { afterAll, beforeAll, describe, expect, test } from "vitest";
+
+const HERE = dirname(fileURLToPath(import.meta.url));
+const HOOK = join(HERE, "..", "ensure-playwright-mcp.mjs");
+
+let TMP;
+
+const makeRepo = ({ mcpCli = false, chromiumAt = null } = {}) => {
+ const repo = mkdtempSync(join(TMP, "repo-"));
+ writeFileSync(join(repo, "package.json"), '{"name":"fixture"}');
+ if (mcpCli) {
+ const mcp = join(repo, "node_modules", "@playwright", "mcp");
+ mkdirSync(mcp, { recursive: true });
+ writeFileSync(join(mcp, "cli.js"), "");
+ }
+ if (chromiumAt) {
+ const core = join(repo, "node_modules", "playwright-core");
+ mkdirSync(core, { recursive: true });
+ writeFileSync(
+ join(core, "package.json"),
+ '{"name":"playwright-core","version":"0.0.0-fixture","main":"index.js"}',
+ );
+ writeFileSync(
+ join(core, "index.js"),
+ `module.exports = { chromium: { executablePath: () => ${JSON.stringify(chromiumAt)} } };`,
+ );
+ }
+ return repo;
+};
+
+const run = (repo) =>
+ spawnSync("node", [HOOK], {
+ input: JSON.stringify({
+ session_id: "pw-mcp-1234",
+ hook_event_name: "SessionStart",
+ }),
+ env: {
+ ...process.env,
+ CLAUDE_PROJECT_DIR: repo,
+ PLAYWRIGHT_MCP_CHECK_ONLY: "1",
+ },
+ encoding: "utf8",
+ });
+
+const warns = (r) => r.stdout.includes("playwright-mcp-status");
+
+beforeAll(() => {
+ TMP = mkdtempSync(join(tmpdir(), "ensure-pw-mcp-"));
+});
+
+afterAll(() => rmSync(TMP, { recursive: true, force: true }));
+
+describe("ensure-playwright-mcp", () => {
+ test("warns when the MCP package is absent", () => {
+ const r = run(makeRepo());
+ expect(r.status).toBe(0);
+ expect(warns(r)).toBe(true);
+ });
+
+ test("warns when the package is present but Chromium cannot be resolved", () => {
+ const r = run(makeRepo({ mcpCli: true }));
+ expect(r.status).toBe(0);
+ expect(warns(r)).toBe(true);
+ });
+
+ test("warns when Chromium resolves to a path that does not exist", () => {
+ const r = run(
+ makeRepo({ mcpCli: true, chromiumAt: "/nonexistent/chrome" }),
+ );
+ expect(r.status).toBe(0);
+ expect(warns(r)).toBe(true);
+ });
+
+ test("stays silent when the package and the Chromium binary are both present", () => {
+ const existingBinary = process.execPath;
+ const r = run(makeRepo({ mcpCli: true, chromiumAt: existingBinary }));
+ expect(r.status).toBe(0);
+ expect(r.stdout).toBe("");
+ });
+});
diff --git a/.claude/scripts/e2e-smoke.sh b/.claude/scripts/e2e-smoke.sh
index 14fc1c4d..98e42c4c 100755
--- a/.claude/scripts/e2e-smoke.sh
+++ b/.claude/scripts/e2e-smoke.sh
@@ -3,9 +3,12 @@
# instance so multiple harness sessions can run it in parallel without colliding.
# Guaranteed teardown via `trap ... EXIT`.
#
-# Isolation per run: a leased SLOT (0..K-1) gives offset = slot*20, applied to the
+# Isolation per run: a leased SLOT (0..K-1) gives offset = (slot+1)*20, applied to the
# project_id, every Supabase port, and the app port + auth URLs, in a throwaway workdir.
# The flock lease also CAPS concurrency (K stacks max) so we never OOM the host.
+# The offset starts at 20, not 0, so no slot reuses the ports config.e2e.toml itself
+# declares (54340-54349, app 5175): those belong to a human `make start-e2e`, which does
+# not take part in the slot lease, and slot 0 used to collide with it.
#
# Exit codes: 0 = suite passed OR gracefully skipped (no slot / low RAM / cannot start);
# 1 = the e2e suite ran and FAILED. Skips are exit 0 by design (the caller
@@ -47,10 +50,10 @@ for i in $(seq 0 $((SLOTS - 1))); do
done
[ -z "$slot" ] && skip "all $SLOTS e2e slots busy; try again later."
-offset=$((slot * 20))
+offset=$(((slot + 1) * 20))
project="atomic-crm-e2e-$slot"
api_port=$((54341 + offset))
-app_port=$((5175 + slot))
+app_port=$((5176 + slot))
workroot="$(mktemp -d)"
workdir="$workroot/e2e" # supabase --workdir
mkdir -p "$workdir/supabase"