Skip to content

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

Spend the red-e2e reject budget per verdict, not once per session

Jerome5582c4126649
diff --git a/.claude/hooks/completion-invariant.mjs b/.claude/hooks/completion-invariant.mjs
index fea55b53..6ea54c93 100755
--- a/.claude/hooks/completion-invariant.mjs
+++ b/.claude/hooks/completion-invariant.mjs
@@ -31,7 +31,8 @@ const REJECT_LIMIT = 2; // reject at most twice, then allow + mark for recovery
// A red e2e is not an orphaned pipeline, so it gets its own single-shot budget and no
// recovery marker: reject once to force the orchestrator to actually react to the result
// it was supposed to read, then let the stop through. Its own 2-round fix bound takes it
-// from there, and "never wedge the pipeline" still holds.
+// from there, and "never wedge the pipeline" still holds. The budget is spent per
+// verdict (keyed on the result's session sha), not once per session.
const E2E_REJECT_LIMIT = 1;
let ctx;
@@ -143,13 +144,16 @@ function rejectOnceOnRedE2e() {
return;
}
- const rejects = readE2eRejects();
+ // The budget is per VERDICT, not per session: keyed on the sha the result was
+ // stamped with, so a later red suite gets its own attempt instead of inheriting
+ // a counter an earlier one already spent (which would silently never fire).
+ const key = result.sessionSha || "unknown";
+ const rejects = readE2eRejects(key);
if (rejects >= E2E_REJECT_LIMIT) {
- clearE2eRejects();
ctx.log(`red e2e persists after ${rejects} reject(s), allowing the stop`);
return;
}
- writeE2eRejects(rejects + 1);
+ writeE2eRejects(key, rejects + 1);
ctx.fail(
`Completion invariant: the end-of-feature e2e suite FAILED and you are stopping without ` +
`acting on it. Read <session_dir>/e2e-result.json, then either fix it (ONE developer on ` +
@@ -203,27 +207,23 @@ function e2eBreakerFile() {
}
return join(dir, "completion-invariant-e2e-rejects");
}
-function readE2eRejects() {
+// Stored as `<sessionSha> <count>`: a count recorded against another sha belongs
+// to an earlier verdict and reads as 0.
+function readE2eRejects(key) {
try {
- return parseInt(readFileSync(e2eBreakerFile(), "utf8"), 10) || 0;
+ const [seen, n] = readFileSync(e2eBreakerFile(), "utf8").split(" ");
+ return seen === key ? parseInt(n, 10) || 0 : 0;
} catch {
return 0;
}
}
-function writeE2eRejects(n) {
+function writeE2eRejects(key, n) {
try {
- writeFileSync(e2eBreakerFile(), String(n));
+ writeFileSync(e2eBreakerFile(), `${key} ${n}`);
} catch {
/* best effort */
}
}
-function clearE2eRejects() {
- try {
- unlinkSync(e2eBreakerFile());
- } catch {
- /* absent - fine */
- }
-}
function writeRecoveryMarker(branches) {
try {
writeFileSync(
diff --git a/.claude/hooks/test/completion-invariant.test.mjs b/.claude/hooks/test/completion-invariant.test.mjs
index 587752a4..fc85de42 100644
--- a/.claude/hooks/test/completion-invariant.test.mjs
+++ b/.claude/hooks/test/completion-invariant.test.mjs
@@ -92,6 +92,14 @@ const unmergedTaskBranch = (taskId) => {
g("checkout", "-q", "main");
};
+const advanceSessionBranch = (name) => {
+ g("checkout", "-q", `session/${SHORT}`);
+ writeFileSync(join(APP_DIR, name), "fix");
+ g("add", "-A");
+ g("commit", "-q", "-m", `fix: ${name}`);
+ 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");
@@ -152,6 +160,20 @@ describe("completion-invariant — red e2e", () => {
expect(run(transcriptWithMeta("orchestrator")).status).toBe(0);
});
+ test("gives a later red suite its own attempt after an intervening green one", () => {
+ const tp = transcriptWithMeta("orchestrator");
+ writeE2eResult("failed", sessionHead());
+ expect(run(tp).status).toBe(2);
+
+ advanceSessionBranch("fix.txt");
+ writeE2eResult("passed", sessionHead());
+ expect(run(tp).status).toBe(0);
+
+ advanceSessionBranch("more.txt");
+ writeE2eResult("failed", sessionHead());
+ expect(run(tp).status).toBe(2);
+ });
+
test("keeps the e2e budget separate from the orphan-branch budget", () => {
writeE2eResult("failed");
const tp = transcriptWithMeta("orchestrator");