A full-featured CRM built with React, shadcn/ui, and Supabase.
Fix the orphan invariant looking for verdict flags in a directory that never exists
Jerome94b26451dd89
diff --git a/.claude/hooks/completion-invariant.mjs b/.claude/hooks/completion-invariant.mjsindex fc13d402..fea55b53 100755--- a/.claude/hooks/completion-invariant.mjs+++ b/.claude/hooks/completion-invariant.mjs@@ -24,6 +24,7 @@ import { join } from "node:path";import { createHookContext } from "./lib/context.mjs";import { readAgentMeta } from "./lib/agent-meta.mjs";import { getUnmergedTaskBranches, git } from "./lib/git.mjs";+import { reviewFlag } from "./lib/reviews.mjs";import { sessionBranch, simpleBranch } from "./lib/topology.mjs";const REJECT_LIMIT = 2; // reject at most twice, then allow + mark for recovery@@ -66,13 +67,16 @@ try {// Only an APPROVED-but-unmerged branch is "orphaned by a stall". A branch with no// APPROVED review flag is a FAILED or still-in-review ticket, not our concern -// flagging it would be a false positive on every failed-ticket run.+ // Resolve the flag through reviews.mjs, the single source of truth shared with+ // block-merger-without-review: TICKETS_DIR == <session_dir>, so the flags live at+ // <session_dir>/reviews/. Hand-rolling it from ctx.ticketsDir looked in+ // <session_dir>/tickets/reviews/ (nothing sets TICKETS_DIR in a hook's env), a+ // directory that never exists, so this invariant silently never fired.const orphaned = unmerged.map((u) => u.branch).filter((br) => {const taskId = br.split("/").pop(); // <short>/TASK-XXX -> TASK-XXX- return existsSync(- join(ctx.ticketsDir, "reviews", `${taskId}-quality-reviewer`),- );+ return existsSync(reviewFlag(ctx, taskId, "quality-reviewer"));});if (orphaned.length === 0) {@@ -125,6 +129,20 @@ function rejectOnceOnRedE2e() {}if (result?.status !== "failed") return;+ // A session serves several requests. A red verdict from an earlier one describes a+ // commit that later merges have moved past, so it must not reject THIS request's+ // stop. An absent sha cannot be verified, so it still rejects: swallowing a real red+ // suite is the worse failure.+ const head = git(["rev-parse", sessionBranch(ctx)]);+ if (+ result.sessionSha &&+ head.status === 0 &&+ result.sessionSha !== head.stdout.trim()+ ) {+ ctx.log("red e2e predates the current session head, ignoring");+ return;+ }+const rejects = readE2eRejects();if (rejects >= E2E_REJECT_LIMIT) {clearE2eRejects();diff --git a/.claude/hooks/e2e-on-feature-review.mjs b/.claude/hooks/e2e-on-feature-review.mjsindex 48f61cf1..1a9c18a6 100644--- a/.claude/hooks/e2e-on-feature-review.mjs+++ b/.claude/hooks/e2e-on-feature-review.mjs@@ -23,8 +23,9 @@ import { createHookContext } from "./lib/context.mjs";import { readAgentMeta } from "./lib/agent-meta.mjs";import { appendProgress } from "./lib/progress-log.mjs";import { bash } from "./lib/process.mjs";+import { git } from "./lib/git.mjs";import { reviewFlag } from "./lib/reviews.mjs";-import { sessionWorktreePath } from "./lib/topology.mjs";+import { sessionBranch, sessionWorktreePath } from "./lib/topology.mjs";const FEATURE_REVIEW_KEY = "FEATURE";const E2E_TIMEOUT_MS = 15 * 60 * 1000;@@ -38,18 +39,31 @@ const e2eResultPath = (ctx) =>const classify = (status, output) =>status !== 0 ? "failed" : /^SKIP:/m.test(output) ? "skipped" : "passed";-function isFeatureReview(input) {- const meta = readAgentMeta(input);- if (meta && /feature-review/i.test(meta.description)) return true;+// The dispatch prompt's `MODE:` line is the precise signal, and unlike the reviewer's+// FINAL message it is written at the top of the transcript, so it is long flushed by+// the time we stop. Read it first and let a `feature-smoke` match END the lookup: the+// smoke dispatch has no description template, so an improvised description containing+// "feature-review" would otherwise trigger a second, duplicate suite run.+function reviewMode(input) {const tp = input.agent_transcript_path || input.transcript_path;- if (!tp || !existsSync(tp)) return false;- try {- return /MODE:\s*feature-review/.test(readFileSync(tp, "utf8"));- } catch {- return false;+ if (tp && existsSync(tp)) {+ try {+ const m = readFileSync(tp, "utf8").match(+ /MODE:\s*(feature-review|feature-smoke)/,+ );+ if (m) return m[1];+ } catch {+ // fall through to the dispatch description+ }}+ const meta = readAgentMeta(input);+ return meta && /feature-review/i.test(meta.description)+ ? "feature-review"+ : "";}+const isFeatureReview = (input) => reviewMode(input) === "feature-review";+const input = JSON.parse(readFileSync(0, "utf8"));const ctx = createHookContext(input, "e2e-on-feature-review");@@ -95,6 +109,10 @@ try {kind: "e2e-result",status,source: src,+ // The session-branch commit the suite actually ran against. A session serves+ // several requests, so this is what lets a reader tell "this verdict is about+ // the code as it stands" from "this verdict predates later merges".+ sessionSha: git(["rev-parse", sessionBranch(ctx)]).stdout.trim(),finishedAt: new Date().toISOString(),output: output.split("\n").slice(-40).join("\n"),},diff --git a/.claude/hooks/render-status.mjs b/.claude/hooks/render-status.mjsindex 38890c1f..0c54d1ad 100755--- a/.claude/hooks/render-status.mjs+++ b/.claude/hooks/render-status.mjs@@ -89,6 +89,23 @@ function liveWorktrees() {const approved = (id) =>existsSync(join(reviewsDir(ctx), `${id}-quality-reviewer`));+// The e2e verdict lives only in e2e-result.json (e2e-on-feature-review.mjs writes it),+// so without this the board showed every ticket green while the integrated suite was red.+const E2E_ICON = { passed: "✅", skipped: "⏭", failed: "❌" };+function e2eLine() {+ try {+ const p = join(+ process.env.CHAT_SESSION_DIR || ctx.sessionDir,+ "e2e-result.json",+ );+ if (!existsSync(p)) return "_not run this round_";+ const r = JSON.parse(readFileSync(p, "utf8"));+ return `${E2E_ICON[r.status] ?? "?"} **${r.status}**${r.finishedAt ? ` · ${r.finishedAt}` : ""}`;+ } catch {+ return "_unreadable_";+ }+}+function recentActivity(max = 25) {const lines = readFileSync(progressLog, "utf8").split("\n")@@ -188,6 +205,9 @@ function build() {? worktrees.map((w) => `- \`${w}\``).join("\n"): "_none (nothing in flight)_","",+ "## End-of-feature e2e",+ e2eLine(),+ "","## Changes",diff? `Full patch in \`session.diff\` (same folder).\n\n\`\`\`\n${diff.stat}\n\`\`\``diff --git a/.claude/hooks/test/completion-invariant.test.mjs b/.claude/hooks/test/completion-invariant.test.mjsindex 4b8c83d0..587752a4 100644--- a/.claude/hooks/test/completion-invariant.test.mjs+++ b/.claude/hooks/test/completion-invariant.test.mjs@@ -16,10 +16,20 @@ let TMP, APP_DIR, sessionDir, env;const g = (...args) =>spawnSync("git", ["-C", APP_DIR, ...args], { encoding: "utf8" });-const writeE2eResult = (status) =>+const sessionHead = () =>+ spawnSync("git", ["-C", APP_DIR, "rev-parse", `session/${SHORT}`], {+ encoding: "utf8",+ }).stdout.trim();++const writeE2eResult = (status, sessionSha = undefined) =>writeFileSync(join(sessionDir, "e2e-result.json"),- JSON.stringify({ kind: "e2e-result", status, output: "1 failed" }),+ JSON.stringify({+ kind: "e2e-result",+ status,+ output: "1 failed",+ ...(sessionSha === undefined ? {} : { sessionSha }),+ }),);const transcriptWithMeta = (agentType) => {@@ -66,6 +76,38 @@ beforeEach(() => {afterEach(() => rmSync(TMP, { recursive: true, force: true }));+// TICKETS_DIR == <session_dir> (orchestrator.md "Environment"), so the reviewer's+// verdict flags live at <session_dir>/reviews/, which is what reviews.mjs resolves.+const approveTask = (taskId) => {+ const dir = join(sessionDir, "reviews");+ mkdirSync(dir, { recursive: true });+ writeFileSync(join(dir, `${taskId}-quality-reviewer`), "");+};++const unmergedTaskBranch = (taskId) => {+ g("checkout", "-q", "-b", `${SHORT}/${taskId}`, `session/${SHORT}`);+ writeFileSync(join(APP_DIR, `${taskId}.txt`), "work");+ g("add", "-A");+ g("commit", "-q", "-m", `feat(${taskId}): work`);+ g("checkout", "-q", "main");+};++describe("completion-invariant — orphaned work", () => {+ test("rejects the stop when APPROVED work is not merged into the session branch", () => {+ unmergedTaskBranch("TASK-001");+ approveTask("TASK-001");+ const r = run(transcriptWithMeta("orchestrator"));+ expect(r.status).toBe(2);+ expect(r.stderr).toContain("TASK-001");+ });++ test("accepts an unmerged branch with no APPROVED verdict", () => {+ unmergedTaskBranch("TASK-002");+ const r = run(transcriptWithMeta("orchestrator"));+ expect(r.status).toBe(0);+ });+});+describe("completion-invariant — red e2e", () => {test("rejects the orchestrator's stop once when the e2e suite failed", () => {writeE2eResult("failed");@@ -100,6 +142,16 @@ describe("completion-invariant — red e2e", () => {expect(run(transcriptWithMeta("developer")).status).toBe(0);});+ test("rejects a red suite recorded against the current session head", () => {+ writeE2eResult("failed", sessionHead());+ expect(run(transcriptWithMeta("orchestrator")).status).toBe(2);+ });++ test("ignores a red suite from an earlier request, whose commit has moved on", () => {+ writeE2eResult("failed", "0000000000000000000000000000000000000000");+ expect(run(transcriptWithMeta("orchestrator")).status).toBe(0);+ });+test("keeps the e2e budget separate from the orphan-branch budget", () => {writeE2eResult("failed");const tp = transcriptWithMeta("orchestrator");diff --git a/.claude/hooks/test/e2e-on-feature-review.test.mjs b/.claude/hooks/test/e2e-on-feature-review.test.mjsindex 8ff8a474..ebcce221 100644--- a/.claude/hooks/test/e2e-on-feature-review.test.mjs+++ b/.claude/hooks/test/e2e-on-feature-review.test.mjs@@ -154,6 +154,18 @@ describe("e2e-on-feature-review", () => {expect(result().status).toBe("passed");});+ // The smoke dispatch has no description template, so an improvised description+ // mentioning the review must not trigger a second suite run.+ test("does not launch for a feature-smoke dispatch, whatever its description says", () => {+ writeSmoke(SMOKE.record);+ approve();+ const tp = transcriptWithMeta("Feature-review smoke of the same feature");+ writeFileSync(tp, "ROLE: quality-reviewer (MODE: feature-smoke)\n");+ const r = run(tp);+ expect(r.status).toBe(0);+ expect(existsSync(join(APP_DIR, "ran-with-src"))).toBe(false);+ });+test("skips gracefully when the session worktree is absent", () => {writeSmoke(SMOKE.record);approve();diff --git a/.claude/hooks/test/render-status.test.mjs b/.claude/hooks/test/render-status.test.mjsindex e2861fd3..af8e4687 100644--- a/.claude/hooks/test/render-status.test.mjs+++ b/.claude/hooks/test/render-status.test.mjs@@ -102,6 +102,20 @@ describe("render-status", () => {expect(md).toContain("`TASK-002`");// The recent-activity block echoes the progress log.expect(md).toContain("TASK-001 merged");+ // No e2e verdict on disk yet: say so rather than imply the suite is green.+ expect(md).toContain("## End-of-feature e2e");+ expect(md).toContain("_not run this round_");+ });++ test("surfaces a red end-of-feature e2e on the board", () => {+ const { base, outDir, run } = setup();+ writeFileSync(+ join(base, "e2e-result.json"),+ JSON.stringify({ kind: "e2e-result", status: "failed" }),+ );+ run();+ const md = readFileSync(join(outDir, "STATUS.md"), "utf8");+ expect(md).toContain("❌ **failed**");});test("renders TICKETS.md with full per-ticket detail", () => {