Skip to content

Commit e0ab9dc

Browse files
committed
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.
1 parent 5d99bf0 commit e0ab9dc

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

.claude/hooks/update-graph.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ BUILD_OK=0
9797
if command -v codegraph &>/dev/null; then
9898
codegraph build "$PROJECT_DIR" -d "$DB_PATH" $BUILD_FLAGS 2>/dev/null && BUILD_OK=1 || true
9999
else
100-
node "${CLAUDE_PROJECT_DIR:-$PROJECT_DIR}/src/cli.js" build "$PROJECT_DIR" -d "$DB_PATH" $BUILD_FLAGS 2>/dev/null && BUILD_OK=1 || true
100+
node "${CLAUDE_PROJECT_DIR:-$PROJECT_DIR}/dist/cli.js" build "$PROJECT_DIR" -d "$DB_PATH" $BUILD_FLAGS 2>/dev/null && BUILD_OK=1 || true
101101
fi
102102

103103
# Update marker only if we did a full rebuild AND it succeeded
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Regression guard for issue #1836: .claude/hooks/update-graph.sh's
3+
* fallback build path (used when the `codegraph` binary isn't on PATH)
4+
* invoked `node <project>/src/cli.js`, a file that has never existed —
5+
* the CLI entry point is TypeScript at src/cli.ts, compiled to dist/cli.js
6+
* (see package.json's `bin.codegraph`). That branch silently failed
7+
* (stderr redirected to /dev/null), so BUILD_OK stayed 0 and the graph
8+
* never rebuilt for contributors without a global codegraph install.
9+
*/
10+
import fs from 'node:fs';
11+
import path from 'node:path';
12+
import { fileURLToPath } from 'node:url';
13+
import { describe, expect, it } from 'vitest';
14+
15+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
16+
const REPO_ROOT = path.resolve(__dirname, '..', '..');
17+
const HOOK_PATH = path.join(REPO_ROOT, '.claude', 'hooks', 'update-graph.sh');
18+
19+
describe('update-graph.sh hook fallback build path', () => {
20+
const script = fs.readFileSync(HOOK_PATH, 'utf8');
21+
const packageJson = JSON.parse(fs.readFileSync(path.join(REPO_ROOT, 'package.json'), 'utf8'));
22+
const cliEntry = packageJson.bin.codegraph.replace(/^\.\//, '');
23+
24+
it('never references a nonexistent src/cli.js', () => {
25+
expect(script).not.toMatch(/\bsrc\/cli\.js\b/);
26+
});
27+
28+
it("invokes package.json's bin.codegraph entry point in the fallback branch", () => {
29+
expect(script).toContain(`/${cliEntry}" build`);
30+
});
31+
});

0 commit comments

Comments
 (0)