From e0ab9dc8fb5eeae4ad7ac66cfeae4c41e8da4b85 Mon Sep 17 00:00:00 2001 From: carlos-alm Date: Tue, 7 Jul 2026 16:19:23 -0600 Subject: [PATCH] fix(hooks): point update-graph.sh fallback build path at dist/cli.js The PostToolUse hook's fallback branch (used when the codegraph binary isn't on PATH) invoked node against src/cli.js, a file that has never existed in this repo. The CLI entry point is TypeScript at src/cli.ts, compiled to dist/cli.js per package.json's bin.codegraph. Since stderr is redirected to /dev/null, the branch failed silently and the graph never rebuilt for contributors without a global codegraph install. Add a regression test asserting the hook never references src/cli.js and does invoke package.json's bin.codegraph entry point. --- .claude/hooks/update-graph.sh | 2 +- tests/unit/hook-fallback-build-path.test.ts | 31 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/unit/hook-fallback-build-path.test.ts diff --git a/.claude/hooks/update-graph.sh b/.claude/hooks/update-graph.sh index cf2a2cbd..73ada4dd 100644 --- a/.claude/hooks/update-graph.sh +++ b/.claude/hooks/update-graph.sh @@ -97,7 +97,7 @@ BUILD_OK=0 if command -v codegraph &>/dev/null; then codegraph build "$PROJECT_DIR" -d "$DB_PATH" $BUILD_FLAGS 2>/dev/null && BUILD_OK=1 || true else - node "${CLAUDE_PROJECT_DIR:-$PROJECT_DIR}/src/cli.js" build "$PROJECT_DIR" -d "$DB_PATH" $BUILD_FLAGS 2>/dev/null && BUILD_OK=1 || true + node "${CLAUDE_PROJECT_DIR:-$PROJECT_DIR}/dist/cli.js" build "$PROJECT_DIR" -d "$DB_PATH" $BUILD_FLAGS 2>/dev/null && BUILD_OK=1 || true fi # Update marker only if we did a full rebuild AND it succeeded diff --git a/tests/unit/hook-fallback-build-path.test.ts b/tests/unit/hook-fallback-build-path.test.ts new file mode 100644 index 00000000..e8157862 --- /dev/null +++ b/tests/unit/hook-fallback-build-path.test.ts @@ -0,0 +1,31 @@ +/** + * Regression guard for issue #1836: .claude/hooks/update-graph.sh's + * fallback build path (used when the `codegraph` binary isn't on PATH) + * invoked `node /src/cli.js`, a file that has never existed — + * the CLI entry point is TypeScript at src/cli.ts, compiled to dist/cli.js + * (see package.json's `bin.codegraph`). That branch silently failed + * (stderr redirected to /dev/null), so BUILD_OK stayed 0 and the graph + * never rebuilt for contributors without a global codegraph install. + */ +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { describe, expect, it } from 'vitest'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const REPO_ROOT = path.resolve(__dirname, '..', '..'); +const HOOK_PATH = path.join(REPO_ROOT, '.claude', 'hooks', 'update-graph.sh'); + +describe('update-graph.sh hook fallback build path', () => { + const script = fs.readFileSync(HOOK_PATH, 'utf8'); + const packageJson = JSON.parse(fs.readFileSync(path.join(REPO_ROOT, 'package.json'), 'utf8')); + const cliEntry = packageJson.bin.codegraph.replace(/^\.\//, ''); + + it('never references a nonexistent src/cli.js', () => { + expect(script).not.toMatch(/\bsrc\/cli\.js\b/); + }); + + it("invokes package.json's bin.codegraph entry point in the fallback branch", () => { + expect(script).toContain(`/${cliEntry}" build`); + }); +});