Skip to content

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

test(harness): make review-verdict tests robust to an ambient CHAT_SESSION_DIR

Jerome76a1ba2342a9
diff --git a/.claude/hooks/test/block-merger-without-review.test.mjs b/.claude/hooks/test/block-merger-without-review.test.mjs
index 63d99a52..08f7b6da 100644
--- a/.claude/hooks/test/block-merger-without-review.test.mjs
+++ b/.claude/hooks/test/block-merger-without-review.test.mjs
@@ -42,6 +42,11 @@ beforeAll(() => {
reviewsDir = join(CRM_TMP_ROOT, sanitizePath(APP_DIR), SESSION_ID, "reviews");
mkdirSync(reviewsDir, { recursive: true });
env = { ...process.env, APP_DIR, CRM_TMP_ROOT };
+ // Neutralise an ambient CHAT_SESSION_DIR: reviewsDir() prefers it over
+ // ctx.sessionDir (managed-launcher path), which would point the verdict flag
+ // away from this test's CRM_TMP_ROOT fixture. See reviews.test.mjs for the
+ // CHAT_SESSION_DIR-present behaviour.
+ delete env.CHAT_SESSION_DIR;
});
afterAll(() => rmSync(TMP, { recursive: true, force: true }));
diff --git a/.claude/hooks/test/record-review-verdict.test.mjs b/.claude/hooks/test/record-review-verdict.test.mjs
index d1472f15..2a3a8637 100644
--- a/.claude/hooks/test/record-review-verdict.test.mjs
+++ b/.claude/hooks/test/record-review-verdict.test.mjs
@@ -35,6 +35,12 @@ beforeAll(() => {
reviewsDir = join(CRM_TMP_ROOT, sanitizePath(APP_DIR), SESSION_ID, "reviews");
env = { ...process.env, APP_DIR, CRM_TMP_ROOT };
delete env.CLAUDE_AGENT_NAME;
+ // These tests assert the flag lands under ctx.sessionDir (CRM_TMP_ROOT/...).
+ // reviewsDir() prefers CHAT_SESSION_DIR when set (managed-launcher path), so a
+ // CHAT_SESSION_DIR inherited from the ambient env (e.g. CRM Builder's container)
+ // would redirect the flag and break the assertion — neutralise it here. The
+ // CHAT_SESSION_DIR-present path is covered by reviews.test.mjs.
+ delete env.CHAT_SESSION_DIR;
});
afterAll(() => rmSync(TMP, { recursive: true, force: true }));
diff --git a/.claude/hooks/test/reviews.test.mjs b/.claude/hooks/test/reviews.test.mjs
new file mode 100644
index 00000000..36f1ecde
--- /dev/null
+++ b/.claude/hooks/test/reviews.test.mjs
@@ -0,0 +1,35 @@
+// Unit tests for the review-verdict path resolution (lib/reviews.mjs).
+// reviewsDir() prefers CHAT_SESSION_DIR (set by a managed launcher such as CRM
+// Builder's chat-service, where <session_dir> is NOT the /tmp/<repo>/<id> path the
+// hooks recompute) and falls back to ctx.sessionDir otherwise. Both branches are
+// pinned here so the quality-reviewer's synchronous flag write and the hooks that
+// read/clear it never drift apart again.
+
+import { describe, test, expect, afterEach } from "vitest";
+import { reviewsDir, reviewFlag } from "../lib/reviews.mjs";
+
+const ORIG = process.env.CHAT_SESSION_DIR;
+afterEach(() => {
+ if (ORIG === undefined) delete process.env.CHAT_SESSION_DIR;
+ else process.env.CHAT_SESSION_DIR = ORIG;
+});
+
+describe("reviews path resolution", () => {
+ test("falls back to ctx.sessionDir when CHAT_SESSION_DIR is unset", () => {
+ delete process.env.CHAT_SESSION_DIR;
+ const ctx = { sessionDir: "/tmp/_app/uuid" };
+ expect(reviewsDir(ctx)).toBe("/tmp/_app/uuid/reviews");
+ expect(reviewFlag(ctx, "TASK-001", "quality-reviewer")).toBe(
+ "/tmp/_app/uuid/reviews/TASK-001-quality-reviewer",
+ );
+ });
+
+ test("prefers CHAT_SESSION_DIR (managed launcher) over ctx.sessionDir", () => {
+ process.env.CHAT_SESSION_DIR = "/chat-service/logs/uuid";
+ const ctx = { sessionDir: "/tmp/_app/uuid" };
+ expect(reviewsDir(ctx)).toBe("/chat-service/logs/uuid/reviews");
+ expect(reviewFlag(ctx, "TASK-001", "quality-reviewer")).toBe(
+ "/chat-service/logs/uuid/reviews/TASK-001-quality-reviewer",
+ );
+ });
+});