A full-featured CRM built with React, shadcn/ui, and Supabase.
Run e2e once at end of feature, not per ticket stop
Jeromed1eb80468fa3
diff --git a/.claude/agents/developer.md b/.claude/agents/developer.mdindex fb6f9cfb..5f1701e2 100644--- a/.claude/agents/developer.md+++ b/.claude/agents/developer.md@@ -96,7 +96,7 @@ The orchestrator parses this line by regex. Any other format is treated as `FAIL```DONE: branch=<BRANCH_NAME> commit=<short_sha> files=[<comma-separated modified paths, relative to repo root>]```- The SubagentStop validation chain runs typecheck + prettier + unit + e2e before your stop is accepted. If validation fails, fix the issues, commit, and stop again.+ The SubagentStop validation chain runs typecheck + prettier + lint + unit before your stop is accepted. If validation fails, fix the issues, commit, and stop again.If anything is unresolvably broken, emit: `FAILED: <one-line reason>`@@ -108,7 +108,7 @@ If your spawn prompt contains a `RETRY_FEEDBACK=...` block, you are on a retry a1. Read the bullets in `RETRY_FEEDBACK` carefully. They come from the `quality-reviewer` and describe issues with your previous attempt.2. Apply targeted fixes only for the listed issues. Do not refactor unrelated code.-3. Commit your fixes. The SubagentStop validation chain (typecheck + prettier + unit + e2e) runs automatically when you stop — failures come back to you as stderr and you fix and re-stop until it passes, exactly as for a fresh attempt.+3. Commit your fixes. The SubagentStop validation chain (typecheck + prettier + lint + unit) runs automatically when you stop — failures come back to you as stderr and you fix and re-stop until it passes, exactly as for a fresh attempt.4. Emit the OUTPUT CONTRACT line with the new HEAD commit sha.If you cannot resolve the feedback (e.g. test infrastructure broken, missing context), emit `FAILED: <reason citing the unresolvable feedback>`.@@ -168,7 +168,7 @@ Bash writes bypass the harness's edit tracking and reach reviewers unformatted.## Validation commands — DO NOT RUN MANUALLY-See `.claude/rules/validation-commands.md` for the full list and rationale. Short version: typecheck / prettier / unit / e2e / lint / build are blocked by `bash-guard`. After implementation + commit, emit the OUTPUT CONTRACT line and stop — the SubagentStop validation chain (typecheck + prettier + unit + e2e) runs automatically before your stop is accepted. If validation fails, fix the issues, commit, and stop again.+See `.claude/rules/validation-commands.md` for the full list and rationale. Short version: typecheck / prettier / unit / e2e / lint / build are blocked by `bash-guard`. After implementation + commit, emit the OUTPUT CONTRACT line and stop — the SubagentStop validation chain (typecheck + prettier + lint + unit) runs automatically before your stop is accepted. If validation fails, fix the issues, commit, and stop again.**Escalate a harness/infra defect, do NOT work around it.** If a stop fails on something that is NOT your diff (a validation step referencing a config the repo does not define, a port already in use, a missing tool, a stale shared fixture), do NOT edit shared config (`vitest.config.ts`, `.claude/settings.json`, root `.env`, build config) from your worktree to make it pass. That pollutes every other ticket. Emit `FAILED: harness config gap: <what broke>` so it is fixed centrally. Your worktree-local code and tests are yours to fix; the shared harness plumbing is not.@@ -260,6 +260,6 @@ Implement the plan. Stick to ticket scope.- JSDoc on every non-trivial exported function.- No features outside ticket scope. An adjacent problem you notice (a nearby bug, a tempting refactor) is REPORTED in your final message, never fixed silently in this diff (`coding-style.md` scope discipline).- e2e tests in `e2e/` if ticket touches UI/filters/forms/interactions, unless acceptance criteria say otherwise. Call `Skill({skill: "e2e-conventions"})` and `Skill({skill: "playwright-testing"})` before writing e2e tests. Don't run them — ship the spec, CI executes.-- Silent mode: Playwright `--headless`, Vite without `--open`, Vitest without `browser.ui`.+- Silent mode: Playwright without `--headed` / `--ui` / `--debug` (headless is its default), Vite without `--open`, Vitest without `browser.ui`.- **Self-verification in the browser (optional, before commit).** When a change is behavior-visible and you want to confirm it renders before handing off to review, drive it via the Playwright MCP against a demo-mode server you start **inside your own worktree** (never `$REPO`). The launch command and port base come from `config.app` (`smokeCommand` + `portBase`, currently `npm run dev:demo` and `5300`): `cd <WORKTREE_PATH> && npm run dev:demo -- --port <PORT> --strictPort` (run in background; pick a port unique to this task, e.g. `5300` + the TASK number). Demo mode is FakeRest + auto-authenticated (no Supabase, no login); with `config.app.hashRouting` the app uses hash routing, so navigate to `http://localhost:<PORT>/#/<route>`. Prefer `browser_snapshot` (accessibility tree, token-cheap) over `browser_take_screenshot` (reserve pixels for visual/legibility checks). **Always tear down** `browser_close` and kill the server before you stop, or the SubagentStop validation chain stalls. This is for your own confidence; the quality-reviewer re-verifies in its Part C. It does **not** replace the required e2e spec.- Architecture Decision Records: load `Skill({skill: "adr-writing"})` only when the change introduces a structural decision (see WORKFLOW step 3). Skip by default.diff --git a/.claude/agents/quality-reviewer.md b/.claude/agents/quality-reviewer.mdindex 48d2af41..76efdc7c 100644--- a/.claude/agents/quality-reviewer.md+++ b/.claude/agents/quality-reviewer.md@@ -455,12 +455,14 @@ interactively via the Playwright MCP against a demo-mode server you start insidestalls the SubagentStop validation chain.A red criterion verified here is a `[FAIL]` → REJECTED. The `npx playwright-screenshot --headless <url> out.png` CLI remains a fallback for a single static-shot when no interaction is needed.+screenshot <url> out.png` CLI remains a fallback for a single static shot when no+interaction is needed (it is headless by default).### C.4 e2e spec sanity (read-only)-Execution is the SubagentStop validation chain's job (`validate-on-stop.mjs`).+Execution happens once at end-of-feature, on the integrated `_session` worktree+(`.claude/scripts/e2e-smoke.sh`, driven by the orchestrator); the per-ticket+SubagentStop chain does NOT run e2e.Here you only verify the spec file exists when acceptance criteria require it andthat it targets the right route/component. (Presence of a test for every newbehavior is also enforced by A.7.)diff --git a/.claude/agents/test-writer.md b/.claude/agents/test-writer.mdindex 833adedd..756845e8 100644--- a/.claude/agents/test-writer.md+++ b/.claude/agents/test-writer.md@@ -52,7 +52,7 @@ its commits.## Validation & output-The SubagentStop validation chain (typecheck + prettier + unit + e2e) runs on+The SubagentStop validation chain (typecheck + prettier + lint + unit) runs onyour stop, scoped to your worktree, exactly as it does for the developer. Do NOTrun it manually (`.claude/rules/validation-commands.md`). If it fails, fix thetests and commit again on the next turn.diff --git a/.claude/hooks/bash-guard.mjs b/.claude/hooks/bash-guard.mjsindex b93de10a..ab971998 100755--- a/.claude/hooks/bash-guard.mjs+++ b/.claude/hooks/bash-guard.mjs@@ -26,15 +26,15 @@ if (!cmd) process.exit(0);// Browser rules — any caller: this sandbox has no display, a headed run hangs forever.const opensHeadedPlaywright = (c) =>/playwright/.test(c) &&- /(screenshot|test|codegen)/.test(c) &&- !c.includes("--headless");+ (/(--headed|--ui\b|--debug\b)/.test(c) ||+ /playwright\s+(open|codegen)\b/.test(c));const opensViteBrowser = (c) =>/(vite|npm run (dev|start|start-demo))/.test(c) && c.includes("--open");const BROWSER_RULES = [[opensHeadedPlaywright,- "Playwright must always use --headless. Add --headless to the command.",+ "Playwright must stay headless (this sandbox has no display): drop --headed / --ui / --debug, and don't run `playwright open` / `codegen`. Headless is the default, no flag needed.",],[opensViteBrowser,@@ -127,7 +127,7 @@ const CATEGORY_RULES = {],e2e: [runsE2eTests,- "e2e tests: the validation hooks run playwright in full mode only; in demo mode they're skipped. Don't run them manually.",+ "e2e tests: per-ticket validation does NOT run playwright (a ticket can be mid-feature). The orchestrator runs the suite once at end-of-feature, on the integrated session worktree via e2e-smoke.sh. Write the spec, don't run it.",],lint: [runsLint,@@ -142,8 +142,8 @@ const CATEGORY_RULES = {// Which categories to guard comes from the SAME config the validation chain runs// (kills the triple-encoding: runner, guard, and doc no longer drift). Each// validation step's kind maps to a category (lint included — it is now a chain-// step), plus validation.extraForbidden (build — never run during tickets, not-// part of the chain). Fail-open to ALL categories if the config can't be read,+// step), plus validation.extraForbidden (build, e2e — never run during tickets,+// not part of the chain). Fail-open to ALL categories if the config can't be read,// so a malformed config never weakens the guard.const KIND_TO_CATEGORY = {format: "prettier",diff --git a/.claude/hooks/lib/validation.mjs b/.claude/hooks/lib/validation.mjsindex aba5daa8..48453eb2 100644--- a/.claude/hooks/lib/validation.mjs+++ b/.claude/hooks/lib/validation.mjs@@ -177,7 +177,8 @@ function runStep(ctx, step, { cwd, base }) {// every developer stop). Steps are declared in harness.config.json's// `validation.steps` (single source of truth, shared with bash-guard) and run in// config order: steps without `cwd:"repo"` run per dirty worktree (fail-fast);-// `cwd:"repo"` steps (e2e) run once in the repo after the per-worktree pass.+// `cwd:"repo"` steps run once in the repo after the per-worktree pass (none today:+// e2e is end-of-feature only, run by the orchestrator on the session worktree).// VALIDATE_DRY_RUN=1 skips everything, =fail simulates a failure. A malformed// config fails closed. Returns { ok:true, skipReason? } or { ok:false, step, output }.export function runValidationSteps(ctx, { worktree = "", base = "" } = {}) {@@ -236,7 +237,7 @@ export function runValidationSteps(ctx, { worktree = "", base = "" } = {}) {const r = runStep(ctx, step, { cwd: ctx.repo, base });if (!r.ok) {progress(`[validate:repo] ${step.id} FAILED`);- ctx.log(`FAIL step=${step.id} exit`);+ ctx.log(`FAIL step=${step.id}\n${r.output}`);return { ok: false, step: step.id, output: r.output + "\n" };}ctx.log(`${step.id} OK`);diff --git a/.claude/hooks/test/bash-guard.test.mjs b/.claude/hooks/test/bash-guard.test.mjsindex c0c0b074..002383b5 100644--- a/.claude/hooks/test/bash-guard.test.mjs+++ b/.claude/hooks/test/bash-guard.test.mjs@@ -17,7 +17,7 @@ afterAll(() => {});const runHook = (agent, command) => {- const env = { ...process.env, CRM_TMP_ROOT: tmpRoot };+ const env = { ...process.env, HARNESS_TMP_ROOT: tmpRoot };delete env.CLAUDE_AGENT_NAME;const input = JSON.stringify({tool_name: "Bash",@@ -33,7 +33,7 @@ const runHook = (agent, command) => {const runHookWithConfig = (agent, command, config) => {const repo = mkdtempSync(join(tmpdir(), "bash-guard-repo-"));writeFileSync(join(repo, "harness.config.json"), JSON.stringify(config));- const env = { ...process.env, CRM_TMP_ROOT: tmpRoot, APP_DIR: repo };+ const env = { ...process.env, HARNESS_TMP_ROOT: tmpRoot, APP_DIR: repo };delete env.CLAUDE_AGENT_NAME;delete env.CLAUDE_PROJECT_DIR;const input = JSON.stringify({@@ -51,27 +51,46 @@ const isBlocked = (r) => r.stdout.includes('"decision":"block"');describe("bash-guard hook", () => {describe("browser rules — any caller", () => {- test("headed playwright test from main session → blocked", () => {- const r = runHook("", "npx playwright test");+ test("playwright test --headed from main session → blocked", () => {+ const r = runHook("", "npx playwright test --headed");expect(r.status).toBe(0);expect(isBlocked(r)).toBe(true);- expect(r.stdout).toContain("--headless");+ expect(r.stdout).toContain("--headed");+ });++ test("playwright test --ui / --debug → blocked", () => {+ expect(isBlocked(runHook("", "npx playwright test --ui"))).toBe(true);+ expect(isBlocked(runHook("", "npx playwright test --debug"))).toBe(true);});- test("headed playwright screenshot from merger → blocked", () => {+ test("playwright open / codegen from merger → blocked", () => {+ expect(+ isBlocked(+ runHook("merger", "npx playwright open http://localhost:5173"),+ ),+ ).toBe(true);+ expect(isBlocked(runHook("merger", "npx playwright codegen"))).toBe(true);+ });++ test("plain playwright test from main session → allowed (headless default)", () => {+ const r = runHook("", "npx playwright test");+ expect(r.status).toBe(0);+ expect(isBlocked(r)).toBe(false);+ });++ test("playwright screenshot from merger → allowed (headless default)", () => {const r = runHook("merger","npx playwright screenshot http://localhost:5173 out.png",);- expect(isBlocked(r)).toBe(true);+ expect(isBlocked(r)).toBe(false);});- test("playwright with --headless from main session → allowed", () => {+ test("playwright MCP cli with --headless → allowed", () => {const r = runHook("",- "npx playwright screenshot --headless http://localhost:5173 out.png",+ "node node_modules/@playwright/mcp/cli.js --headless --isolated",);- expect(r.status).toBe(0);expect(isBlocked(r)).toBe(false);});@@ -92,7 +111,7 @@ describe("bash-guard hook", () => {["developer", "npx tsc --noEmit"],["developer", "npx vitest run"],["developer", "npm run prettier:apply"],- ["quality-reviewer", "npx playwright test --headless"],+ ["quality-reviewer", "npx playwright test"],["quality-reviewer", "make lint"],["developer", "npm run build"],];diff --git a/.claude/rules/validation-commands.md b/.claude/rules/validation-commands.mdindex dd67e38e..81d21003 100644--- a/.claude/rules/validation-commands.md+++ b/.claude/rules/validation-commands.md@@ -10,13 +10,18 @@ guard, so they can never drift:- `validate-on-stop.mjs` (SubagentStop) runs the whole chain after everydeveloper / test-writer stop: the format step (prettier auto-fix + commit),- typecheck, lint (eslint, scoped to the stop's changed files), the unit steps,- then e2e once in the repo (full mode only). A failed step rejects the stop; the- agent's internal loop fixes it and only a green stop returns control to the+ typecheck, lint (eslint, scoped to the stop's changed files) and the unit steps.+ A failed step rejects the stop; the agent's internal loop fixes it and only a+ green stop returns control to the orchestrator.+ **e2e is NOT in this chain**: a ticket can legitimately be mid-feature, and the+ chain's `cwd:"repo"` steps run in the base-branch checkout, so a per-stop e2e run+ only ever tested code the ticket had not touched. The suite runs once at+ end-of-feature on the integrated `_session` worktree, via+ `.claude/scripts/e2e-smoke.sh` (isolated slot-leased Supabase), driven by theorchestrator.- `bash-guard.mjs` (PreToolUse Bash) blocks `developer` / `quality-reviewer` from- running those same commands manually, plus `validation.extraForbidden` (build).- The forbidden set is DERIVED from `validation.steps`, not hardcoded here.+ running those same commands manually, plus `validation.extraForbidden` (build,+ e2e). The forbidden set is DERIVED from `validation.steps`, not hardcoded here.## Why blocked (developer / quality-reviewer)diff --git a/harness.config.json b/harness.config.jsonindex 95692790..9c99f253 100644--- a/harness.config.json+++ b/harness.config.json@@ -43,16 +43,9 @@"projects": ["functions"],"changedScoped": true,"condition": { "pathExists": "supabase/functions" }- },- {- "id": "e2e",- "kind": "e2e",- "command": "npx playwright test",- "cwd": "repo",- "condition": { "modeNot": "demo" }}],- "extraForbidden": ["build"]+ "extraForbidden": ["build", "e2e"]},"worktree": {"provision": "npm-link"