A full-featured CRM built with React, shadcn/ui, and Supabase.
Cover the five untested guards, and stop deleting a shared test-results
Jerome9c110b08dab8
diff --git a/.claude/hooks/cleanup-session.mjs b/.claude/hooks/cleanup-session.mjsindex 1866e890..6104d850 100755--- a/.claude/hooks/cleanup-session.mjs+++ b/.claude/hooks/cleanup-session.mjs@@ -1,8 +1,13 @@#!/usr/bin/env node// SessionEnd: tear down THIS session's harness scratch state when the Claude// session ends: remove every git worktree under <WORKTREE_BASE> (_session,-// simple, any leftover TASK-XXX), prune the admin refs, drop the base dir, and-// remove the Playwright test-results left in the repo.+// simple, any leftover TASK-XXX), prune the admin refs and drop the base dir.+//+// `$REPO/test-results` is deliberately NOT removed. The e2e suite runs in the+// `_session` worktree (e2e-on-feature-review.mjs -> e2e-smoke.sh), so its Playwright+// output lives at `<_session>/test-results` and goes away with the worktree below.+// The copy in the repo can therefore only come from a HUMAN `make test-e2e`, or from a+// concurrent session, and neither is ours to delete. It is gitignored either way.//// Branches are left intact: they are cheap, do not clutter the editor's Source// Control view (only worktrees do), and deleting them could drop work stopped at@@ -74,7 +79,6 @@ try {ctx.repo,(p) => p === ctx.worktreeBase || p.startsWith(ctx.worktreeBase + "/"),);- rmSync(join(REPO, "test-results"), { recursive: true, force: true });// This session's rendered board only (render-status.mjs). Per-session subdir,// so a concurrent session's board under .harness/<other-short> is left intact.rmSync(join(REPO, ".harness", ctx.sessionShort), {diff --git a/.claude/hooks/restrict-documentator-bash.mjs b/.claude/hooks/restrict-documentator-bash.mjsindex 24303e69..eb856a72 100755--- a/.claude/hooks/restrict-documentator-bash.mjs+++ b/.claude/hooks/restrict-documentator-bash.mjs@@ -9,9 +9,12 @@ import { createHookContext } from "./lib/context.mjs";// "documentator" (an Agent-dispatched documentator subagent, the same signal the// other PreToolUse hooks use). Read the payload first so agent_type is available.//-// Fail closed: a malformed payload is a block signal for this restricted agent,-// not a pass-through. Leave input empty so the !command guard below exits 2-// (exit 1 from an uncaught throw would let the Bash command through).+// Fail closed ONLY once the caller is known to be the documentator, which is the+// most this hook can do: it runs on EVERY caller's Bash, so an unparseable payload+// (identity unknowable) must pass through rather than block every agent in the run.+// With DOCUMENTATOR_RUN=1 the identity comes from the env, independent of the+// payload, so there a malformed payload DOES block: input stays empty and the+// !command guard below exits 2 (exit 1 from an uncaught throw would let it through).let input = {};try {input = JSON.parse(readFileSync(0, "utf8"));diff --git a/.claude/hooks/test/block-migration-writes.test.mjs b/.claude/hooks/test/block-migration-writes.test.mjsnew file mode 100644index 00000000..fed838be--- /dev/null+++ b/.claude/hooks/test/block-migration-writes.test.mjs@@ -0,0 +1,89 @@+// Tests for block-migration-writes.mjs. Migrations are deferred to the deploy-time+// round, which always runs on the shared <base>/simple worktree via the+// writing-migrations skill. The worktree path in the write target is the+// discriminator, since the dispatch intent is not visible at Write time.++import { spawnSync } from "node:child_process";+import { mkdtempSync, rmSync } from "node:fs";+import { tmpdir } from "node:os";+import { dirname, join } from "node:path";+import { fileURLToPath } from "node:url";+import { afterAll, describe, expect, test } from "vitest";++const HERE = dirname(fileURLToPath(import.meta.url));+const HOOK = join(HERE, "..", "block-migration-writes.mjs");+const TMP = mkdtempSync(join(tmpdir(), "block-migration-writes-"));+const WB = "/tmp/_repo/abcd1234";++afterAll(() => rmSync(TMP, { recursive: true, force: true }));++const run = (agentName, filePath) => {+ const env = { ...process.env, APP_DIR: TMP };+ delete env.CLAUDE_AGENT_NAME;+ if (agentName) env.CLAUDE_AGENT_NAME = agentName;+ return spawnSync("node", [HOOK], {+ input: JSON.stringify({+ tool_name: "Write",+ session_id: "mig-1234",+ tool_input: { file_path: filePath },+ }),+ env,+ encoding: "utf8",+ });+};++const isBlocked = (r) => r.stdout.includes('"decision":"block"');++describe("block-migration-writes", () => {+ test("a per-ticket developer writing a migration → blocked", () => {+ const r = run(+ "developer-TASK-003",+ `${WB}/TASK-003/supabase/migrations/20260101_add_col.sql`,+ );+ expect(r.status).toBe(0);+ expect(isBlocked(r)).toBe(true);+ expect(r.stdout).toContain("writing-migrations");+ });++ test("the same developer on the simple worktree → allowed (migration round)", () => {+ const r = run(+ "developer",+ `${WB}/simple/supabase/migrations/20260101_add_col.sql`,+ );+ expect(r.status).toBe(0);+ expect(isBlocked(r)).toBe(false);+ });++ test("migrations-pending is blocked for everyone, on any worktree", () => {+ for (const agent of ["developer", "developer-TASK-007", "merger", ""]) {+ const r = run(+ agent,+ `${WB}/simple/supabase/migrations-pending/20260101_x.sql`,+ );+ expect(isBlocked(r)).toBe(true);+ }+ });++ test("a developer writing application code → allowed", () => {+ const r = run(+ "developer-TASK-003",+ `${WB}/TASK-003/src/components/atomic-crm/deals/DealList.tsx`,+ );+ expect(isBlocked(r)).toBe(false);+ });++ test("a developer writing a declarative schema file → allowed", () => {+ // Schemas are the source of truth a ticket DOES edit; only migrations/ is deferred.+ const r = run(+ "developer-TASK-003",+ `${WB}/TASK-003/supabase/schemas/01_tables.sql`,+ );+ expect(isBlocked(r)).toBe(false);+ });++ test("an empty file_path is a no-op", () => {+ const r = run("developer-TASK-003", "");+ expect(r.status).toBe(0);+ expect(isBlocked(r)).toBe(false);+ });+});diff --git a/.claude/hooks/test/block-orchestrator-merge.test.mjs b/.claude/hooks/test/block-orchestrator-merge.test.mjsnew file mode 100644index 00000000..0718c5e8--- /dev/null+++ b/.claude/hooks/test/block-orchestrator-merge.test.mjs@@ -0,0 +1,122 @@+// Tests for block-orchestrator-merge.mjs. Only the dispatched `merger` may run+// merge-class git commands; if any other agent merges itself the pipeline looks+// healthy while the dev -> merger path is dead. The guard is OPT-IN, since in a plain+// checkout the main session is a general assistant that legitimately merges.+// Blocks are exit 2 + stderr (ctx.fail), not decision JSON.++import { spawnSync } from "node:child_process";+import { mkdtempSync, rmSync, writeFileSync } from "node:fs";+import { tmpdir } from "node:os";+import { dirname, join } from "node:path";+import { fileURLToPath } from "node:url";+import { afterAll, describe, expect, test } from "vitest";++const HERE = dirname(fileURLToPath(import.meta.url));+const HOOK = join(HERE, "..", "block-orchestrator-merge.mjs");+const TMP = mkdtempSync(join(tmpdir(), "block-orch-merge-"));++afterAll(() => rmSync(TMP, { recursive: true, force: true }));++const run = (agentName, command, { enabled = true, repo = TMP } = {}) => {+ const env = { ...process.env, APP_DIR: repo };+ delete env.CLAUDE_AGENT_NAME;+ delete env.ATOMIC_CRM_ENFORCE_MERGE_GUARD;+ delete env.HARNESS_ENFORCE_MERGE_GUARD;+ if (enabled) env.HARNESS_ENFORCE_MERGE_GUARD = "1";+ if (agentName) env.CLAUDE_AGENT_NAME = agentName;+ return spawnSync("node", [HOOK], {+ input: JSON.stringify({+ tool_name: "Bash",+ session_id: "merge-1234",+ tool_input: { command },+ }),+ env,+ encoding: "utf8",+ });+};++const blocked = (r) => r.status === 2;++describe("block-orchestrator-merge", () => {+ const MERGE_CLASS = [+ "git merge session/abcd1234",+ "git checkout main",+ "git checkout master",+ "git pull",+ "git worktree remove /tmp/_repo/abcd1234/TASK-001",+ ];++ test("inert unless the guard is explicitly enabled", () => {+ for (const cmd of MERGE_CLASS) {+ const r = run("", cmd, { enabled: false });+ expect(r.status).toBe(0);+ }+ });++ test.each(MERGE_CLASS)("the main session running '%s' → blocked", (cmd) => {+ const r = run("", cmd);+ expect(blocked(r)).toBe(true);+ expect(r.stderr).toContain("merger");+ });++ test.each(MERGE_CLASS)("a developer running '%s' → blocked", (cmd) => {+ expect(blocked(run("developer-TASK-002", cmd))).toBe(true);+ });++ test.each(MERGE_CLASS)(+ "the dispatched merger running '%s' → allowed",+ (cmd) => {+ expect(run("merger", cmd).status).toBe(0);+ expect(run("merger-TASK-002", cmd).status).toBe(0);+ },+ );++ test("a merge-class command chained after another is still caught", () => {+ expect(blocked(run("", "cd /tmp && git merge session/abcd1234"))).toBe(+ true,+ );+ expect(blocked(run("", "git fetch; git pull"))).toBe(true);+ });++ test("read-only git is allowed for everyone", () => {+ for (const cmd of ["git status", "git log --oneline -3", "git diff HEAD"]) {+ expect(run("", cmd).status).toBe(0);+ }+ });++ test("git merge-base stays allowed (read-only, not a merge)", () => {+ // The (\s|$) boundary after `merge` is what distinguishes it. Dropping that+ // boundary to "simplify" the regex would block a legitimate read-only command.+ expect(run("", "git merge-base main HEAD").status).toBe(0);+ });++ test("prose containing 'git merge ' is over-matched, deliberately", () => {+ // A textual mention is refused rather than parsed. Kept broad on purpose: the+ // guard is opt-in and fails LOUD with an explanatory message, so a rephrase costs+ // one turn, whereas a regex clever enough to tell code from prose would eventually+ // let a real merge through. Pinned so nobody "fixes" it into a bypass.+ expect(blocked(run("", "echo 'time to git merge later'"))).toBe(true);+ });++ test("the launcher's post-checkout script is merger-only when configured", () => {+ const repo = mkdtempSync(join(tmpdir(), "block-orch-merge-repo-"));+ writeFileSync(+ join(repo, "harness.config.json"),+ JSON.stringify({+ launcher: { postCheckoutScript: "/entrypoint/apply-app-variant.sh" },+ roles: { merger: { model: "haiku" } },+ }),+ );+ expect(+ blocked(run("", "bash /entrypoint/apply-app-variant.sh", { repo })),+ ).toBe(true);+ expect(+ run("merger", "bash /entrypoint/apply-app-variant.sh", { repo }).status,+ ).toBe(0);+ rmSync(repo, { recursive: true, force: true });+ });++ test("with no post-checkout script configured that clause stays inert", () => {+ expect(run("", "bash /entrypoint/apply-app-variant.sh").status).toBe(0);+ });+});diff --git a/.claude/hooks/test/cleanup-session.test.mjs b/.claude/hooks/test/cleanup-session.test.mjsindex a200851d..2e9e3b82 100644--- a/.claude/hooks/test/cleanup-session.test.mjs+++ b/.claude/hooks/test/cleanup-session.test.mjs@@ -69,17 +69,24 @@ const setup = () => {};describe("cleanup-session", () => {- test("removes the session worktrees, base dir and test-results", () => {- const { base, testResults, run, worktreeList } = setup();+ test("removes the session worktrees and base dir", () => {+ const { base, run, worktreeList } = setup();const r = run();expect(r.status).toBe(0);expect(existsSync(base)).toBe(false);- expect(existsSync(testResults)).toBe(false);// Only the main worktree remains registered.expect(worktreeList()).not.toContain("_session");expect(worktreeList()).not.toContain("/simple");});+ // The suite runs in the _session worktree, so the repo copy can only be a human's+ // `make test-e2e` output or a concurrent session's. Neither is this session's to drop.+ test("leaves the repo's Playwright test-results in place", () => {+ const { testResults, run } = setup();+ run();+ expect(existsSync(testResults)).toBe(true);+ });+test("leaves the shared .promote.lock in place (concurrent-promotion mutex)", () => {const { promoteLock, run } = setup();run();diff --git a/.claude/hooks/test/force-foreground-orchestrator-dispatch.test.mjs b/.claude/hooks/test/force-foreground-orchestrator-dispatch.test.mjsnew file mode 100644index 00000000..caf06ce6--- /dev/null+++ b/.claude/hooks/test/force-foreground-orchestrator-dispatch.test.mjs@@ -0,0 +1,100 @@+// Tests for force-foreground-orchestrator-dispatch.mjs. The gate exists because a+// nested subagent is never re-invoked when a background child completes, so a+// background pipeline dispatch orphans review/merge/promotion. Only an EXPLICIT+// run_in_background:false may pass: absent means the extension's background default,+// which IS the bug (3K loosened exactly this and neutered the gate).++import { spawnSync } from "node:child_process";+import { mkdtempSync, rmSync } from "node:fs";+import { tmpdir } from "node:os";+import { dirname, join } from "node:path";+import { fileURLToPath } from "node:url";+import { afterAll, describe, expect, test } from "vitest";++const HERE = dirname(fileURLToPath(import.meta.url));+const HOOK = join(HERE, "..", "force-foreground-orchestrator-dispatch.mjs");+const TMP = mkdtempSync(join(tmpdir(), "force-fg-dispatch-"));++afterAll(() => rmSync(TMP, { recursive: true, force: true }));++// `runInBackground` omitted entirely when `undefined`, so the payload matches what a+// client that never sends the field actually produces.+const run = ({ subagentType, prompt = "", runInBackground }) => {+ const toolInput = { subagent_type: subagentType, prompt };+ if (runInBackground !== undefined)+ toolInput.run_in_background = runInBackground;+ return spawnSync("node", [HOOK], {+ input: JSON.stringify({+ tool_name: "Agent",+ session_id: "fg-1234",+ tool_input: toolInput,+ }),+ env: { ...process.env, APP_DIR: TMP },+ encoding: "utf8",+ });+};++const isBlocked = (r) => r.stdout.includes('"decision":"block"');++describe("force-foreground-orchestrator-dispatch", () => {+ const PIPELINE = [+ "planner",+ "developer",+ "quality-reviewer",+ "merger",+ "test-writer",+ ];++ test.each(PIPELINE)("%s dispatched in the background → blocked", (role) => {+ const r = run({ subagentType: role, runInBackground: true });+ expect(r.status).toBe(0);+ expect(isBlocked(r)).toBe(true);+ expect(r.stdout).toContain(role);+ });++ // The regression that matters: absent is NOT the same as false.+ test.each(PIPELINE)(+ "%s dispatched with run_in_background absent → blocked",+ (role) => {+ const r = run({ subagentType: role });+ expect(isBlocked(r)).toBe(true);+ },+ );++ test.each(PIPELINE)("%s dispatched with explicit false → allowed", (role) => {+ const r = run({ subagentType: role, runInBackground: false });+ expect(r.status).toBe(0);+ expect(isBlocked(r)).toBe(false);+ });++ // main -> orchestrator and the fire-and-forget documentator are pipeline:false in+ // harness.config.json, so their background dispatch is correct and must pass.+ test.each(["orchestrator", "documentator"])(+ "%s in the background → allowed (not a pipeline role)",+ (role) => {+ expect(+ isBlocked(run({ subagentType: role, runInBackground: true })),+ ).toBe(false);+ },+ );++ test("recognises the child role from the prompt's ROLE: line", () => {+ const r = run({+ subagentType: "",+ prompt: "ROLE: merger\nTASK_ID: TASK-004\n",+ runInBackground: true,+ });+ expect(isBlocked(r)).toBe(true);+ expect(r.stdout).toContain("merger");+ });++ test("an unparseable payload allows the dispatch (fail-open)", () => {+ const r = spawnSync("node", [HOOK], {+ input: "not json",+ env: { ...process.env, APP_DIR: TMP },+ encoding: "utf8",+ });+ expect(r.status).toBe(0);+ expect(isBlocked(r)).toBe(false);+ });+});diff --git a/.claude/hooks/test/record-merger-stage.test.mjs b/.claude/hooks/test/record-merger-stage.test.mjsnew file mode 100644index 00000000..1af45852--- /dev/null+++ b/.claude/hooks/test/record-merger-stage.test.mjs@@ -0,0 +1,106 @@+// Tests for record-merger-stage.mjs, the dispatch->Bash bridge that carries a+// merger's promotion authorization. A PreToolUse(Bash) hook cannot see the merger's+// dispatch prompt, so the authorization is recorded here at dispatch time and read+// later by block-wave-merger-promote.mjs. Getting `promote` wrong in either direction+// is serious: true for a wave merger lets partial work reach the base branch, false+// for the promotion merger wedges the pipeline.++import { spawnSync } from "node:child_process";+import {+ existsSync,+ mkdirSync,+ mkdtempSync,+ readFileSync,+ rmSync,+} from "node:fs";+import { tmpdir } from "node:os";+import { dirname, join } from "node:path";+import { fileURLToPath } from "node:url";+import { afterEach, beforeEach, describe, expect, test } from "vitest";+import { sanitizePath } from "../lib/paths.mjs";++const HERE = dirname(fileURLToPath(import.meta.url));+const HOOK = join(HERE, "..", "record-merger-stage.mjs");+const SESSION_ID = "ms7c3d2e-1111-2222-3333-444455556666";++let TMP, APP_DIR, sessionDir, env;++const run = (subagentType, prompt) =>+ spawnSync("node", [HOOK], {+ input: JSON.stringify({+ tool_name: "Agent",+ session_id: SESSION_ID,+ tool_input: { subagent_type: subagentType, prompt },+ }),+ env,+ encoding: "utf8",+ });++const marker = () => {+ const p = join(sessionDir, "merger-stage.json");+ return existsSync(p) ? JSON.parse(readFileSync(p, "utf8")) : null;+};++beforeEach(() => {+ TMP = mkdtempSync(join(tmpdir(), "record-merger-stage-"));+ APP_DIR = join(TMP, "app");+ const TMP_ROOT = join(TMP, "scratch");+ sessionDir = join(TMP_ROOT, sanitizePath(APP_DIR), SESSION_ID);+ mkdirSync(APP_DIR, { recursive: true });+ env = { ...process.env, APP_DIR, HARNESS_TMP_ROOT: TMP_ROOT };+ delete env.CLAUDE_AGENT_NAME;+});++afterEach(() => rmSync(TMP, { recursive: true, force: true }));++describe("record-merger-stage", () => {+ test("a per-ticket wave merger is recorded as NOT authorized to promote", () => {+ const r = run("merger", "ROLE: merger\nTASK_ID: TASK-003\nSTAGE: a-only\n");+ expect(r.status).toBe(0);+ expect(marker().promote).toBe(false);+ expect(marker().taskId).toBe("TASK-003");+ });++ // The TASK-<n> id alone must be enough: a wave dispatch that forgot STAGE: a-only+ // still may not promote, or a missing line would silently authorize it.+ test("a TASK-<n> dispatch without STAGE: a-only is still not authorized", () => {+ run("merger", "ROLE: merger\nTASK_ID: TASK-011\n");+ expect(marker().promote).toBe(false);+ });++ test("the promotion merger is recorded as authorized", () => {+ run("merger", "ROLE: merger\nMODE: promote\nSESSION_SHORT_ID: abcd1234\n");+ expect(marker().promote).toBe(true);+ expect(marker().mode).toBe("promote");+ });++ test.each(["SIMPLE", "MIGRATION", "ROLLBACK"])(+ "the %s single-shot merger is recorded as authorized",+ (taskId) => {+ run("merger", `ROLE: merger\nTASK_ID: ${taskId}\n`);+ expect(marker().promote).toBe(true);+ },+ );++ // STAGE: a-only overrides mode, so a SIMPLE merger asked for Stage A only stays+ // unauthorized (the feature-review fix path merges into the session branch).+ test("STAGE: a-only wins over a promoting mode", () => {+ run("merger", "ROLE: merger\nTASK_ID: SIMPLE\nSTAGE: a-only\n");+ expect(marker().promote).toBe(false);+ });++ test("a non-merger dispatch records nothing", () => {+ const r = run("developer", "ROLE: developer\nTASK_ID: TASK-003\n");+ expect(r.status).toBe(0);+ expect(marker()).toBe(null);+ });++ test("prose naming another ticket cannot mis-key the marker", () => {+ run(+ "merger",+ "ROLE: merger\nTASK_ID: TASK-002\n\nTASK-001 is already merged; merge this one.",+ );+ expect(marker().taskId).toBe("TASK-002");+ expect(marker().promote).toBe(false);+ });+});diff --git a/.claude/hooks/test/restrict-documentator-bash.test.mjs b/.claude/hooks/test/restrict-documentator-bash.test.mjsnew file mode 100644index 00000000..dd6d47e1--- /dev/null+++ b/.claude/hooks/test/restrict-documentator-bash.test.mjs@@ -0,0 +1,125 @@+// Tests for restrict-documentator-bash.mjs. The documentator writes to MEMORY.md on+// the base branch, so its Bash surface is a read-only + commit-MEMORY.md whitelist.+// Blocks are exit 2 + stderr (ctx.error), not decision JSON. It must fail CLOSED: a+// malformed payload blocks, since an uncaught throw (exit 1) would let the command run.++import { spawnSync } from "node:child_process";+import { mkdtempSync, rmSync } from "node:fs";+import { tmpdir } from "node:os";+import { dirname, join } from "node:path";+import { fileURLToPath } from "node:url";+import { afterAll, describe, expect, test } from "vitest";++const HERE = dirname(fileURLToPath(import.meta.url));+const HOOK = join(HERE, "..", "restrict-documentator-bash.mjs");+const TMP = mkdtempSync(join(tmpdir(), "restrict-doc-bash-"));+const REPO = "/workspaces/app";++afterAll(() => rmSync(TMP, { recursive: true, force: true }));++const run = (command, { via = "agent_type", raw = null } = {}) => {+ const env = { ...process.env, APP_DIR: TMP };+ delete env.DOCUMENTATOR_RUN;+ delete env.CLAUDE_AGENT_NAME;+ if (via === "env") env.DOCUMENTATOR_RUN = "1";+ const payload = JSON.stringify({+ tool_name: "Bash",+ session_id: "doc-1234",+ agent_type: via === "agent_type" ? "documentator" : "",+ tool_input: { command },+ });+ return spawnSync("node", [HOOK], {+ input: raw ?? payload,+ env,+ encoding: "utf8",+ });+};++const blocked = (r) => r.status === 2;++describe("restrict-documentator-bash", () => {+ const ALLOWED = [+ "git log --oneline -20",+ "git show HEAD",+ "git diff HEAD~1",+ `git -C ${REPO} diff --stat main..session/abcd1234`,+ `git -C ${REPO} log --oneline -5`,+ "ls adr/",+ "wc -l MEMORY.md",+ `git -C ${REPO} add MEMORY.md`,+ `git -C ${REPO} -c user.name=Documentator -c [email protected] commit -m "docs: capture"`,+ `git -C ${REPO} -c [email protected] -c user.name=Documentator commit -m "docs: capture"`,+ ];++ test.each(ALLOWED)("'%s' → allowed", (cmd) => {+ expect(run(cmd).status).toBe(0);+ });++ const REFUSED = [+ "rm -rf src",+ "npm install lodash",+ `git -C ${REPO} push origin main`,+ `git -C ${REPO} add src/App.tsx`,+ "git commit -m 'sneaky'", // no pinned author identity+ `git -C ${REPO} -c user.name=Someone -c [email protected] commit -m "x"`,+ ];++ test.each(REFUSED)("'%s' → blocked", (cmd) => {+ const r = run(cmd);+ expect(blocked(r)).toBe(true);+ expect(r.stderr).toContain("documentator");+ });++ // Metacharacters are rejected BEFORE the whitelist, so a permitted prefix cannot+ // smuggle a second command past it.+ const SMUGGLING = [+ "git log; rm -rf /",+ "git log && npm publish",+ "git log | tee /tmp/x",+ "git log `whoami`",+ "git log $(id)",+ "git log > /tmp/out",+ "git log\nrm -rf src",+ ];++ test.each(SMUGGLING)("'%s' → blocked as a metacharacter", (cmd) => {+ const r = run(cmd);+ expect(blocked(r)).toBe(true);+ expect(r.stderr).toContain("metacharacters");+ });++ test("recognised via DOCUMENTATOR_RUN=1 as well as agent_type", () => {+ expect(run("rm -rf src", { via: "env" }).status).toBe(2);+ expect(run("git log", { via: "env" }).status).toBe(0);+ });++ test("any other agent passes through untouched", () => {+ const r = spawnSync("node", [HOOK], {+ input: JSON.stringify({+ tool_name: "Bash",+ session_id: "doc-1234",+ agent_type: "developer",+ tool_input: { command: "rm -rf src" },+ }),+ env: { ...process.env, APP_DIR: TMP },+ encoding: "utf8",+ });+ expect(r.status).toBe(0);+ });++ // This hook runs on EVERY caller's Bash, so identity is what decides. Once the+ // caller is known to be the documentator (env var, independent of the payload) a+ // malformed payload blocks. When identity is only knowable FROM the payload, it has+ // to pass through: blocking would refuse every agent's Bash for the whole run.+ test("an unparseable payload fails CLOSED when identity comes from the env", () => {+ expect(run("", { via: "env", raw: "not json" }).status).toBe(2);+ });++ test("an unparseable payload passes through when identity is unknowable", () => {+ expect(run("", { raw: "not json" }).status).toBe(0);+ });++ test("an empty command is blocked", () => {+ expect(run("").status).toBe(2);+ });+});diff --git a/.gitignore b/.gitignoreindex 8887c0a3..e86e4fdd 100644--- a/.gitignore+++ b/.gitignore@@ -42,7 +42,7 @@ public/r/!supabase/functions/.env.claude/settings.local.json-# Harness scratch (promotion lock; worktrees + test-results also cleaned at SessionEnd)+# Harness scratch (promotion lock, kept on purpose; worktrees cleaned at SessionEnd).promote.lock# Rendered per-session harness board (render-status hook; cleaned at SessionEnd)/.harness/