* fix(#2304): normalize Kimi tool vocabulary in PreToolUse guard payload checks
The Kimi [[hooks]] registrations translate the matcher to Kimi's tool
vocabulary (WriteFile|StrReplaceFile) but the guard scripts early-exit
unless the payload's tool_name is a Claude name (Write/Edit/MultiEdit),
so every guard was dormant on Kimi: the matcher fired, the script saw
WriteFile, and exit(0)'d.
Normalize the payload's tool_name at the top of each guard
(WriteFile -> Write, StrReplaceFile -> Edit; bare or module-qualified
kimi_cli.tools.file:* forms) before the check. Inlined per guard rather
than a hooks/lib/ helper because hook scripts are staged as standalone
files on every hook surface, and a sibling require is a staging
dependency that can fail silently.
Regression tests pipe Kimi-vocabulary payloads at each guard and assert
it engages (typed fields: exit status, decision, hookSpecificOutput) —
verified red against the pre-fix scripts, green after.
* fix(#2304): normalize Kimi tool_input fields and route block reasons to stderr
Cross-AI review of the initial fix, verified against kimi-cli source,
found the tool_name normalization alone leaves the guards dormant on a
real Kimi runtime: kimi-cli forwards tool_input verbatim
(src/kimi_cli/hooks/events.py), and its tool schemas
(src/kimi_cli/tools/file/{write,replace}.py) use path/content and
edit.old/edit.new (single Edit or list) — not Claude's
file_path/old_string/new_string. The guards read file_path, got '',
and exited 0 past the now-open tool_name gate.
Extend the per-guard normalization to the payload fields
(path -> file_path, edit -> old_string/new_string with list flattening),
and write the worktree guard's block reason to stderr as well as the
stdout JSON — Kimi feeds stderr, not stdout, back to the model on
exit 2 (docs/en/customization/hooks.md exit-code table).
Regression tests rewritten to Kimi's actual payload shapes (plus an
edit-list case and a stderr-reason assertion) — verified red against
the name-only fix, green after.
* fix(#2304): join all edit[] entries into old_string, matching new_string
Review nit on #2326: old_string took only edits[0].old while new_string
joined the whole list. Symmetric join removes the latent trap for any
future consumer sizing before/after content (e.g. the #2255 write guard).
* fix(#2304): normalize Kimi ReadFile vocabulary in read-injection scanner
Review Major 2 on #2326: gsd-read-injection-scanner.js had the identical
dormancy — its Kimi matcher fires on 'ReadFile' but the SCANNED_TOOLS
check only knew 'Read', so injected content in read files was never
flagged on Kimi installs.
Folds the same inlined normalization block into the scanner and extends
the shared KIMI_TOOL_NAMES map with ReadFile:'Read' in all four copies so
they stay byte-identical. Harmless in the three write guards: a
normalized 'Read' falls out of their Write/Edit allowlist exactly as the
unmapped name did. Field mapping verified against kimi-cli upstream
(src/kimi_cli/tools/file/read.py Params.path); the existing
path->file_path copy covers the scanner's file_path read.
* test(#2304): parity test binding the four inlined Kimi normalization copies
Review Major 1 on #2326: KIMI_TOOL_NAMES + normalizeKimiPayload is
deliberately inlined in four hook scripts (staging-dependency rationale,
unchanged), with the inverse table in bin/install.js — five
hand-maintained surfaces and nothing binding them.
Static binding, zero runtime coupling:
- the four inlined blocks must be byte-identical;
- each guard-map entry must be the value-inverse of
convertKimiToolName() for its Claude name;
- every guard-relevant Claude tool (Write/Edit/MultiEdit/Read) must have
a reverse entry — a vocabulary rename or extension that updates the
installer without updating the guards now fails in CI instead of
leaving a guard silently dormant (the #2304 recurrence door).
Negative-controlled: diverging one copy or dropping a map entry fails
the suite against the fixed code.
* test(#2304): regenerate golden parity fixtures for guard hook changes
CI red on #2326: all 10 golden-parity failures were the staged guard
hooks drifting from their fixtures. Regenerated with npm run gen:golden
(after npm run build) under throwaway HOME/CLAUDE_CONFIG_DIR; diff
verified to change exactly the four PR-touched guard entries per
surface, nothing else.
* test(#2304): regression tests for Kimi ReadFile engaging the scanner
Mirrors the per-guard Kimi vocabulary tests the PR added for the three
write guards: bare and module-qualified ReadFile produce the advisory,
path exclusions still apply post-normalization, unknown Kimi names stay
fail-open. Negative-controlled against the pre-fold scanner (the two
positive cases fail there; exclusion/fall-through correctly pass on
both sides).
* fix(#2304): normalize Kimi Shell vocabulary in workflow guard
Withdraws the disclosed out-of-scope split: verification showed the
Bash->Shell case needs NO different mapping — kimi-cli's Shell.Params
names its field `command` (src/kimi_cli/tools/shell/__init__.py), same
as Claude's Bash — and the guard's write branch (Write/Edit/MultiEdit
allowlist) was ALSO dormant on Kimi under its Shell|WriteFile|
StrReplaceFile matcher. Same defect class as the other four hooks.
Folds the identical inlined block into gsd-workflow-guard.js and
extends the shared map with Shell:'Bash' in all five copies (harmless
outside the workflow guard: a normalized Bash falls out of the other
guards' checks as before). Parity test now binds five copies and adds
Bash to the dormancy alarm. New workflow-guard test file exercises the
observable block (force-add on a worktree-agent branch): Shell bare and
module-qualified block with WORKTREE_AGENT_FORCE_ADD_FORBIDDEN, benign
Shell passes, Claude Bash unchanged — negative-controlled against the
pre-fold guard (the two Kimi cases fail there). Golden parity fixtures
regenerated; diff verified to change exactly the five guard entries per
surface.
* fix(#2304): map Kimi tool_output and route workflow-guard block to stderr
Third-party review (cross-AI verifier) caught two gaps in the revision:
1. Kimi PostToolUse events carry `tool_output`, not `tool_response`
(kimi-cli src/kimi_cli/hooks/events.py post_tool_use()), so the
read-injection scanner — which reads data.tool_response — was STILL
dormant on real Kimi payloads; the earlier tests passed because they
sent Claude-shaped payloads. The shared normalization block now maps
tool_output -> tool_response (inert in PreToolUse guards, where the
field is absent), and the scanner's Kimi tests send the real shape.
2. The workflow guard's force-add block wrote its reason to stdout only.
Kimi's exit-2 protocol feeds stderr back to the model — the exact
fix this PR already applied to the other blocking guard — so the
newly-awakened block would have been a silent denial. Reason now
also routed to stderr, asserted in the test.
Also: the scanner's "unknown name" test now uses a genuinely unmapped
name (FetchURL) — Shell stopped qualifying when it entered the map —
and the workflow guard's write branch (WriteFile advisory,
StrReplaceFile .planning pass) gains behavioral coverage. All five
copies stay byte-identical (parity test green); golden fixtures
regenerated, diff verified to the five guard entries per surface.
Negative-controlled: 3 new assertions fail against the pre-fix hooks.
* docs(#2304): update changeset to cover the full five-guard fix
Review round 2 (2026-07-18) flagged the changeset as stale: it was
written for the first commit and still described only the three guards
named in the issue. The shipped diff grew to five guards plus two
payload dimensions the original body never mentioned. The body now
names gsd-read-injection-scanner and gsd-workflow-guard, the ReadFile
and Shell vocabulary entries, the tool_output -> tool_response mapping,
and the workflow guard's stderr block-reason routing.
* test(#2304): regenerate kilo golden fixture after #2305 landed on next
The branch's fixture sweep predates 50efae13 (fix(#2305), PR #2327),
which made Kilo ship the five shared guard hooks. Rebased onto next and
re-ran the full generator sweep (gen:golden, size:baseline, and the
four registry/contract generators); the only delta across all of them
is kilo.json's five guard-hook hashes, matching this PR's hook edits.
* fix(#2304): fold Kimi normalization into the two shell hooks
The 2026-07-19 review found the last two guards with the #2304 dormancy:
- hooks/gsd-graphify-update.sh gated on tool_name == "Bash" but is
registered on Kimi with matcher 'Shell' — Gate 1 never matched and the
auto-rebuild was silently dormant. kimi-cli's Shell.Params names its
field `command` (src/kimi_cli/tools/shell/__init__.py), same as Claude
Bash, so only the name needs mapping: strip the module-path prefix,
map Shell -> Bash.
- hooks/gsd-phase-boundary.sh read only tool_input.file_path, but Kimi's
file tools name the field `path` (src/kimi_cli/tools/file/write.py +
replace.py) — the hook read '' and .planning/ writes went undetected.
Falls back to tool_input.path when file_path is absent, mirroring
normalizeKimiPayload's precedence in the JS guards.
The normalization is reimplemented in shell — a byte-identity assertion
cannot span the JS<->shell boundary, so the parity test gains a
shell-guard vocabulary block that pins both scripts' mapping facts to
convertKimiToolName's live vocabulary instead of faking a byte binding.
Behavior is covered by negative-controlled tests beside each hook's
existing suite (verified red against the pre-fix scripts): Kimi Shell
dispatch (bare + module-qualified) with a WriteFile negative control in
graphify-auto-update.slow.test.cjs, and Kimi path detection, file_path
precedence, and a non-.planning negative control in hooks-opt-in.test.cjs.
Changeset updated to name all seven guards; golden install-parity
fixtures regenerated (diff is exactly the two hook entries per runtime;
size baselines unchanged).
* fix(#2304): use a Map for KIMI_TOOL_NAMES so prototype keys cannot pass the guard fall-through
A bare bracket lookup on an object literal resolves 'constructor',
'__proto__', 'toString', 'valueOf' and 'hasOwnProperty' through
Object.prototype to truthy functions/objects, so `if (!mapped)` failed
to short-circuit and data.tool_name was assigned a non-string. Map.get
returns undefined for those keys — the same shape the repo already uses
in canonicalizeRuntimeName (src/runtime-name-policy.cts). Applied
identically to all five inlined copies (review M1, PR #2326).
No new bypass class: unrecognized strings already fail open by design;
this fixes the lookup being wrong, not the posture.
* test(#2304): enumerate normalized guards by scanning hooks/, not a hardcoded list
The parity test's file list was a literal five-entry array — a sixth guard
with its own copy-pasted normalization block would be silently uncovered,
the exact divergence mode the test exists to prevent (review M2). Now the
list is a scan of hooks/*.js for the KIMI_TOOL_NAMES marker, with a floor
assertion so a scan that finds nothing fails instead of passing vacuously.
Also parses the Map declaration introduced by the M1 fix, and carries the
allow-test-rule annotation documenting the source-text scanning (review m4).
* test(#2304): parse hook JSON output instead of substring-matching raw stdout
workflow-guard.test.cjs asserted on unparsed stdout while read-guard.test.cjs
in the same PR parses the JSON envelope first — match the better pattern at
all four assertion sites (review m5).
* test(#2304): regenerate golden parity fixtures after Map conversion in the five guards
* docs(#2304): reset changeset pr:0 placeholder for Phase 0 PR (#2507)
The closed PR #2326's changeset carried pr:2326. Phase 0 of epic #2505
re-lands this fix on a fresh branch; the pr: field will be backfilled
to the real Phase 0 PR number immediately after gh pr create returns.
* docs(changeset): backfill PR #2518 for Phase 0 (#2507)
---------
Co-authored-by: 0xdhx <darkhawkx@gmail.com>
783 lines
33 KiB
JavaScript
783 lines
33 KiB
JavaScript
'use strict';
|
|
|
|
// Tests for graphify.cjs — auto-update describe block.
|
|
// Split from the consolidated 2336-LOC file. Refs #3761.
|
|
//
|
|
// Regression for #3347: opt-in auto-update of the knowledge graph after
|
|
// main HEAD advances. Two sub-concerns: config-key surface (config.test)
|
|
// and hook behavior (hook.test). Both merged here.
|
|
|
|
const { describe, test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const os = require('node:os');
|
|
const { execFileSync, spawnSync } = require('child_process');
|
|
const { createTempProject, cleanup, runGsdTools, delay } = require('./helpers.cjs');
|
|
|
|
const {
|
|
graphifyStatus,
|
|
} = require('../gsd-core/bin/lib/graphify.cjs');
|
|
|
|
const {
|
|
VALID_CONFIG_KEYS,
|
|
isValidConfigKey,
|
|
} = require('../gsd-core/bin/lib/config-schema.cjs');
|
|
|
|
const {
|
|
CONFIG_DEFAULTS: CANONICAL_CONFIG_DEFAULTS,
|
|
} = require('../gsd-core/bin/lib/configuration.cjs');
|
|
|
|
const {
|
|
makeStatusProject,
|
|
} = require('./helpers/graphify.cjs');
|
|
|
|
// ─── auto-update describe ─────────────────────────────────────────────────────
|
|
|
|
describe('auto-update', () => {
|
|
describe('config-key surface', () => {
|
|
// Regression for #3347
|
|
|
|
test('VALID_CONFIG_KEYS contains graphify.auto_update', () => {
|
|
assert.ok(
|
|
VALID_CONFIG_KEYS.has('graphify.auto_update'),
|
|
'graphify.auto_update must be in VALID_CONFIG_KEYS so config-set accepts it',
|
|
);
|
|
});
|
|
|
|
test('isValidConfigKey accepts graphify.auto_update', () => {
|
|
assert.ok(
|
|
isValidConfigKey('graphify.auto_update'),
|
|
'isValidConfigKey must return true for graphify.auto_update',
|
|
);
|
|
});
|
|
|
|
test('isValidConfigKey still accepts the pre-existing graphify.enabled key', () => {
|
|
assert.ok(
|
|
isValidConfigKey('graphify.enabled'),
|
|
'regression guard: graphify.enabled must remain a valid key',
|
|
);
|
|
});
|
|
|
|
test('CANONICAL_CONFIG_DEFAULTS.graphify.auto_update is false', () => {
|
|
assert.ok(
|
|
CANONICAL_CONFIG_DEFAULTS.graphify !== undefined,
|
|
'CANONICAL_CONFIG_DEFAULTS must expose a graphify section',
|
|
);
|
|
assert.strictEqual(
|
|
CANONICAL_CONFIG_DEFAULTS.graphify.auto_update,
|
|
false,
|
|
'graphify.auto_update default must be false (opt-in per issue #3347 AC)',
|
|
);
|
|
});
|
|
|
|
test('config-set graphify.auto_update true succeeds', (t) => {
|
|
const tmpDir = createTempProject();
|
|
t.after(() => cleanup(tmpDir));
|
|
|
|
const result = runGsdTools(
|
|
['config-set', 'graphify.auto_update', 'true'],
|
|
tmpDir,
|
|
);
|
|
assert.ok(
|
|
result.success,
|
|
[
|
|
'config-set graphify.auto_update true should succeed,',
|
|
'got:',
|
|
'stdout: ' + result.output,
|
|
'stderr: ' + result.error,
|
|
].join('\n'),
|
|
);
|
|
});
|
|
|
|
test('config-set graphify.auto_update true writes to config.json', (t) => {
|
|
const tmpDir = createTempProject();
|
|
t.after(() => cleanup(tmpDir));
|
|
|
|
runGsdTools(['config-set', 'graphify.auto_update', 'true'], tmpDir);
|
|
|
|
const configPath = path.join(tmpDir, '.planning', 'config.json');
|
|
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
assert.strictEqual(
|
|
config.graphify?.auto_update,
|
|
true,
|
|
'config.json must have graphify.auto_update: true after config-set',
|
|
);
|
|
});
|
|
|
|
test('config-set graphify.auto_update false persists too', (t) => {
|
|
const tmpDir = createTempProject();
|
|
t.after(() => cleanup(tmpDir));
|
|
|
|
runGsdTools(['config-set', 'graphify.auto_update', 'true'], tmpDir);
|
|
runGsdTools(['config-set', 'graphify.auto_update', 'false'], tmpDir);
|
|
|
|
const configPath = path.join(tmpDir, '.planning', 'config.json');
|
|
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
assert.strictEqual(
|
|
config.graphify?.auto_update,
|
|
false,
|
|
'config-set must round-trip true → false',
|
|
);
|
|
});
|
|
|
|
test('graphifyStatus folds auto-update status=failed into stale=true', (t) => {
|
|
const tmpDir = makeStatusProject({
|
|
ts: '2026-05-15T12:00:00Z',
|
|
status: 'failed',
|
|
exit_code: 1,
|
|
duration_ms: 1234,
|
|
head_at_build: 'abcdef0',
|
|
graphify_version: null,
|
|
});
|
|
t.after(() => cleanup(tmpDir));
|
|
const s = graphifyStatus(tmpDir);
|
|
assert.strictEqual(s.stale, true, 'auto-build failure must set stale=true');
|
|
assert.ok(s.last_build_auto_update, 'last_build_auto_update must be exposed');
|
|
assert.strictEqual(s.last_build_auto_update.status, 'failed');
|
|
assert.strictEqual(s.last_build_auto_update.exit_code, 1);
|
|
});
|
|
|
|
test('graphifyStatus folds auto-update status=running into stale=true', (t) => {
|
|
const tmpDir = makeStatusProject({
|
|
ts: '2026-05-15T12:00:00Z',
|
|
status: 'running',
|
|
exit_code: null,
|
|
duration_ms: null,
|
|
head_at_build: 'abcdef0',
|
|
graphify_version: null,
|
|
});
|
|
t.after(() => cleanup(tmpDir));
|
|
const s = graphifyStatus(tmpDir);
|
|
assert.strictEqual(s.stale, true, 'auto-build in-flight must set stale=true');
|
|
assert.strictEqual(s.last_build_auto_update.status, 'running');
|
|
});
|
|
|
|
test('graphifyStatus leaves stale alone when auto-update status=ok and graph is fresh', (t) => {
|
|
const tmpDir = makeStatusProject({
|
|
ts: '2026-05-15T12:00:00Z',
|
|
status: 'ok',
|
|
exit_code: 0,
|
|
duration_ms: 1234,
|
|
head_at_build: 'abcdef0',
|
|
graphify_version: null,
|
|
});
|
|
t.after(() => cleanup(tmpDir));
|
|
const s = graphifyStatus(tmpDir);
|
|
assert.strictEqual(s.stale, false, 'fresh graph + ok auto-build => not stale');
|
|
assert.strictEqual(s.last_build_auto_update.status, 'ok');
|
|
});
|
|
|
|
test('graphifyStatus exposes last_build_auto_update: null when status file absent', (t) => {
|
|
const tmpDir = makeStatusProject(null);
|
|
t.after(() => cleanup(tmpDir));
|
|
const s = graphifyStatus(tmpDir);
|
|
assert.strictEqual(s.last_build_auto_update, null);
|
|
assert.strictEqual(s.stale, false, 'no status file => stale follows mtime only');
|
|
});
|
|
|
|
test('config-set graphify.auto_update does not perturb sibling graphify.enabled', (t) => {
|
|
const tmpDir = createTempProject();
|
|
t.after(() => cleanup(tmpDir));
|
|
|
|
runGsdTools(['config-set', 'graphify.enabled', 'true'], tmpDir);
|
|
runGsdTools(['config-set', 'graphify.auto_update', 'true'], tmpDir);
|
|
|
|
const configPath = path.join(tmpDir, '.planning', 'config.json');
|
|
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
assert.strictEqual(
|
|
config.graphify?.enabled,
|
|
true,
|
|
'graphify.enabled must be preserved when setting graphify.auto_update',
|
|
);
|
|
assert.strictEqual(
|
|
config.graphify?.auto_update,
|
|
true,
|
|
'graphify.auto_update must coexist with graphify.enabled',
|
|
);
|
|
});
|
|
});
|
|
|
|
// ─── hook tests ─────────────────────────────────────────────────────────────
|
|
|
|
const isWindows = process.platform === 'win32';
|
|
const HOOK = path.join(__dirname, '..', 'hooks', 'gsd-graphify-update.sh');
|
|
|
|
function createTempGitRepo(opts = {}) {
|
|
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-3347-'));
|
|
spawnSync('git', ['init', '-b', opts.defaultBranch || 'main'], {
|
|
cwd: tmpDir,
|
|
stdio: 'ignore',
|
|
});
|
|
execFileSync('git', ['config', 'user.email', 'test@example.com'], { cwd: tmpDir });
|
|
execFileSync('git', ['config', 'user.name', 'Test'], { cwd: tmpDir });
|
|
fs.writeFileSync(path.join(tmpDir, 'README.md'), '# test\n');
|
|
execFileSync('git', ['add', 'README.md'], { cwd: tmpDir });
|
|
execFileSync('git', ['commit', '-m', 'init'], { cwd: tmpDir, stdio: 'ignore' });
|
|
|
|
fs.mkdirSync(path.join(tmpDir, '.planning'), { recursive: true });
|
|
if (opts.config !== undefined) {
|
|
fs.writeFileSync(
|
|
path.join(tmpDir, '.planning', 'config.json'),
|
|
JSON.stringify(opts.config, null, 2),
|
|
);
|
|
}
|
|
return tmpDir;
|
|
}
|
|
|
|
function makeMockGraphifyBin(tmpDir, { exitCode = 0, sleepMs = 0 } = {}) {
|
|
const binDir = path.join(tmpDir, '.mock-bin');
|
|
fs.mkdirSync(binDir, { recursive: true });
|
|
const script = path.join(binDir, 'graphify');
|
|
const body = [
|
|
'#!/usr/bin/env bash',
|
|
'set -u',
|
|
sleepMs ? `sleep ${(sleepMs / 1000).toFixed(3)}` : '',
|
|
'mkdir -p graphify-out',
|
|
'echo \'{"nodes":[],"edges":[]}\' > graphify-out/graph.json',
|
|
'echo "mock report" > graphify-out/GRAPH_REPORT.md',
|
|
'echo "<html></html>" > graphify-out/graph.html',
|
|
`exit ${exitCode}`,
|
|
]
|
|
.filter(Boolean)
|
|
.join('\n');
|
|
fs.writeFileSync(script, body + '\n', { mode: 0o755 });
|
|
return binDir;
|
|
}
|
|
|
|
function runHook(tmpDir, toolPayload, { env = {}, pathPrepend = '' } = {}) {
|
|
const PATH = pathPrepend
|
|
? `${pathPrepend}${path.delimiter}${process.env.PATH || ''}`
|
|
: process.env.PATH || '';
|
|
return spawnSync('bash', [HOOK], {
|
|
cwd: tmpDir,
|
|
input: JSON.stringify(toolPayload),
|
|
env: {
|
|
...process.env,
|
|
PATH,
|
|
CI: '',
|
|
...env,
|
|
},
|
|
encoding: 'utf8',
|
|
timeout: 30000,
|
|
});
|
|
}
|
|
|
|
// Wait until the detached rebuild writes a terminal status, with a generous
|
|
// deadline. The detached subprocess can be slow under contended Docker; all
|
|
// assertions here are outcome-based, so we wait for the real terminal state
|
|
// rather than guessing a tight wall-clock budget (#382).
|
|
async function waitForBuildStatus(statusPath, terminal /* e.g. new Set(['ok']) */, { deadlineMs = 30000, stepMs = 25 } = {}) {
|
|
const deadline = Date.now() + deadlineMs;
|
|
let status;
|
|
while (Date.now() < deadline) {
|
|
if (fs.existsSync(statusPath)) {
|
|
try {
|
|
const parsed = JSON.parse(fs.readFileSync(statusPath, 'utf8'));
|
|
status = parsed;
|
|
if (parsed && terminal.has(parsed.status)) return parsed;
|
|
} catch { /* detached writer can briefly expose a partial JSON write */ }
|
|
}
|
|
await delay(stepMs);
|
|
}
|
|
return status; // last seen (may be undefined / non-terminal) — assertions below will report
|
|
}
|
|
|
|
async function cleanupHookRepo(tmpDir) {
|
|
// The hook detaches a graphify-rebuild subprocess that may still be writing
|
|
// into tmpDir when the test body returns. Wait for the rebuild PID to exit
|
|
// (lock file disappears on subprocess EXIT trap), then retry rmSync to
|
|
// absorb any remaining transient ENOTEMPTY race.
|
|
//
|
|
// Uses delay() instead of Atomics.wait so we yield the event loop
|
|
// without blocking the thread. Budget: 15 s — bumped from 4 s to give
|
|
// the detached child more time to exit under contended Docker (#382).
|
|
const lockPath = path.join(tmpDir, '.planning/graphs/.rebuild.lock');
|
|
const lockDeadline = Date.now() + 15000;
|
|
while (Date.now() < lockDeadline) {
|
|
if (!fs.existsSync(lockPath)) break;
|
|
try {
|
|
const pid = parseInt(fs.readFileSync(lockPath, 'utf8'), 10);
|
|
if (!Number.isFinite(pid) || pid <= 0) break;
|
|
execFileSync('kill', ['-0', String(pid)], { stdio: 'ignore' });
|
|
} catch {
|
|
break; // PID dead → safe to clean up
|
|
}
|
|
await delay(50); // yield 50 ms, then re-check
|
|
}
|
|
try {
|
|
// eslint-disable-next-line local/no-raw-rmsync-in-tests -- best-effort teardown: error is swallowed so cleanup() (which propagates) cannot be used here; a residual temp dir after a detached-subprocess race is harmless (#382)
|
|
fs.rmSync(tmpDir, { recursive: true, force: true, maxRetries: 8, retryDelay: 100 });
|
|
} catch { /* best-effort teardown: a residual temp dir is harmless; never fail the test (#382) */ }
|
|
}
|
|
|
|
describe('hook — bail paths (no side effects)',
|
|
{ skip: isWindows ? 'POSIX-only: harness spawns bash + kill -0 + sleep; the hook itself is a bash script under test' : false },
|
|
() => {
|
|
test('non-Bash tool call exits 0 with no status file', (t) => {
|
|
const tmpDir = createTempGitRepo({
|
|
config: { graphify: { enabled: true, auto_update: true } },
|
|
});
|
|
t.after(() => cleanupHookRepo(tmpDir));
|
|
const r = runHook(tmpDir, { tool_name: 'Edit', tool_input: { file_path: 'x' } });
|
|
assert.strictEqual(r.status, 0, 'hook must exit 0 on non-Bash tool');
|
|
assert.ok(
|
|
!fs.existsSync(path.join(tmpDir, '.planning/graphs/.last-build-status.json')),
|
|
'no status file should be created when bailing',
|
|
);
|
|
});
|
|
|
|
test('Bash but non-HEAD-advancing command exits 0 with no status file', (t) => {
|
|
const tmpDir = createTempGitRepo({
|
|
config: { graphify: { enabled: true, auto_update: true } },
|
|
});
|
|
t.after(() => cleanupHookRepo(tmpDir));
|
|
const r = runHook(tmpDir, { tool_name: 'Bash', tool_input: { command: 'ls -la' } });
|
|
assert.strictEqual(r.status, 0);
|
|
assert.ok(!fs.existsSync(path.join(tmpDir, '.planning/graphs/.last-build-status.json')));
|
|
});
|
|
|
|
test('git commit but graphify.enabled=false → no dispatch', (t) => {
|
|
const tmpDir = createTempGitRepo({
|
|
config: { graphify: { enabled: false, auto_update: true } },
|
|
});
|
|
t.after(() => cleanupHookRepo(tmpDir));
|
|
const r = runHook(tmpDir, { tool_name: 'Bash', tool_input: { command: 'git commit -m x' } });
|
|
assert.strictEqual(r.status, 0);
|
|
assert.ok(!fs.existsSync(path.join(tmpDir, '.planning/graphs/.last-build-status.json')));
|
|
});
|
|
|
|
test('git commit but graphify.auto_update=false → no dispatch (opt-in)', (t) => {
|
|
const tmpDir = createTempGitRepo({
|
|
config: { graphify: { enabled: true, auto_update: false } },
|
|
});
|
|
t.after(() => cleanupHookRepo(tmpDir));
|
|
const r = runHook(tmpDir, { tool_name: 'Bash', tool_input: { command: 'git commit -m x' } });
|
|
assert.strictEqual(r.status, 0);
|
|
assert.ok(
|
|
!fs.existsSync(path.join(tmpDir, '.planning/graphs/.last-build-status.json')),
|
|
'opt-in default-off: auto_update=false must suppress dispatch',
|
|
);
|
|
});
|
|
|
|
test('CI=true → no dispatch even with both gates true', (t) => {
|
|
const tmpDir = createTempGitRepo({
|
|
config: { graphify: { enabled: true, auto_update: true } },
|
|
});
|
|
t.after(() => cleanupHookRepo(tmpDir));
|
|
const mockBin = makeMockGraphifyBin(tmpDir);
|
|
const r = runHook(
|
|
tmpDir,
|
|
{ tool_name: 'Bash', tool_input: { command: 'git commit -m x' } },
|
|
{ env: { CI: 'true' }, pathPrepend: mockBin },
|
|
);
|
|
assert.strictEqual(r.status, 0);
|
|
assert.ok(!fs.existsSync(path.join(tmpDir, '.planning/graphs/.last-build-status.json')));
|
|
});
|
|
|
|
test('on non-default branch → no dispatch', (t) => {
|
|
const tmpDir = createTempGitRepo({
|
|
config: { graphify: { enabled: true, auto_update: true } },
|
|
});
|
|
t.after(() => cleanupHookRepo(tmpDir));
|
|
execFileSync('git', ['checkout', '-b', 'worktree-agent-abc'], {
|
|
cwd: tmpDir,
|
|
stdio: 'ignore',
|
|
});
|
|
const mockBin = makeMockGraphifyBin(tmpDir);
|
|
const r = runHook(
|
|
tmpDir,
|
|
{ tool_name: 'Bash', tool_input: { command: 'git commit -m x' } },
|
|
{ pathPrepend: mockBin },
|
|
);
|
|
assert.strictEqual(r.status, 0);
|
|
assert.ok(
|
|
!fs.existsSync(path.join(tmpDir, '.planning/graphs/.last-build-status.json')),
|
|
'branch check must filter worktree-agent-* (non-default-branch) commits',
|
|
);
|
|
});
|
|
|
|
test('graphify binary not on PATH → silent exit 0', (t) => {
|
|
const tmpDir = createTempGitRepo({
|
|
config: { graphify: { enabled: true, auto_update: true } },
|
|
});
|
|
t.after(() => cleanupHookRepo(tmpDir));
|
|
// Note: do NOT prepend mock bin; rely on real PATH not having graphify
|
|
const r = runHook(
|
|
tmpDir,
|
|
{ tool_name: 'Bash', tool_input: { command: 'git commit -m x' } },
|
|
{ env: { PATH: '/usr/bin:/bin' } },
|
|
);
|
|
assert.strictEqual(r.status, 0, 'must not break commits when graphify missing');
|
|
});
|
|
});
|
|
|
|
describe('hook — dispatch path (all gates pass)',
|
|
{ skip: isWindows ? 'POSIX-only: harness spawns bash + kill -0 + sleep; the hook itself is a bash script under test' : false },
|
|
() => {
|
|
test('writes status file with status=running synchronously before returning', async (t) => {
|
|
const tmpDir = createTempGitRepo({
|
|
config: { graphify: { enabled: true, auto_update: true } },
|
|
});
|
|
t.after(() => cleanupHookRepo(tmpDir));
|
|
// Sleep 2s in mock so we can observe the running state before completion
|
|
const mockBin = makeMockGraphifyBin(tmpDir, { sleepMs: 2000 });
|
|
|
|
const r = runHook(
|
|
tmpDir,
|
|
{ tool_name: 'Bash', tool_input: { command: 'git commit -m x' } },
|
|
{ pathPrepend: mockBin },
|
|
);
|
|
assert.strictEqual(r.status, 0, 'hook must return 0');
|
|
|
|
const statusPath = path.join(tmpDir, '.planning/graphs/.last-build-status.json');
|
|
assert.ok(fs.existsSync(statusPath), 'status file must be written synchronously');
|
|
const status = JSON.parse(fs.readFileSync(statusPath, 'utf8'));
|
|
assert.strictEqual(status.status, 'running', 'initial status must be "running"');
|
|
assert.ok(/^[0-9a-f]{7,40}$/.test(status.head_at_build), 'head_at_build must be a commit sha');
|
|
// Await the detached rebuild's terminal status so the subprocess has exited
|
|
// before the test returns. A dangling detached rebuild can outlive the chunk
|
|
// under `node --test --test-force-exit` and surface as a non-zero chunk exit.
|
|
const done = await waitForBuildStatus(statusPath, new Set(['ok', 'failed']));
|
|
assert.ok(done && (done.status === 'ok' || done.status === 'failed'),
|
|
'detached rebuild must reach a terminal status before the test returns');
|
|
});
|
|
|
|
test('completes to status=ok after detached graphify run succeeds', async (t) => {
|
|
const tmpDir = createTempGitRepo({
|
|
config: { graphify: { enabled: true, auto_update: true } },
|
|
});
|
|
t.after(() => cleanupHookRepo(tmpDir));
|
|
const mockBin = makeMockGraphifyBin(tmpDir, { exitCode: 0, sleepMs: 200 });
|
|
|
|
runHook(
|
|
tmpDir,
|
|
{ tool_name: 'Bash', tool_input: { command: 'git commit -m x' } },
|
|
{ pathPrepend: mockBin },
|
|
);
|
|
|
|
// Wait for the detached rebuild process to write the final status file.
|
|
// Uses waitForBuildStatus with a generous 30 s deadline so contended
|
|
// Docker is never racing a tight budget (#382). All assertions are
|
|
// outcome-based; the deadline is deterministic, not a timing assertion.
|
|
const statusPath = path.join(tmpDir, '.planning/graphs/.last-build-status.json');
|
|
const status = await waitForBuildStatus(statusPath, new Set(['ok']));
|
|
assert.ok(status, 'status file must exist after dispatch');
|
|
assert.strictEqual(status.status, 'ok', 'mock graphify exit=0 → status ok');
|
|
assert.strictEqual(status.exit_code, 0);
|
|
assert.ok(typeof status.duration_ms === 'number' && status.duration_ms >= 0);
|
|
});
|
|
|
|
test('completes to status=failed when graphify exits non-zero', async (t) => {
|
|
const tmpDir = createTempGitRepo({
|
|
config: { graphify: { enabled: true, auto_update: true } },
|
|
});
|
|
t.after(() => cleanupHookRepo(tmpDir));
|
|
const mockBin = makeMockGraphifyBin(tmpDir, { exitCode: 1, sleepMs: 100 });
|
|
|
|
runHook(
|
|
tmpDir,
|
|
{ tool_name: 'Bash', tool_input: { command: 'git commit -m x' } },
|
|
{ pathPrepend: mockBin },
|
|
);
|
|
|
|
// Wait for the detached rebuild process to write the final status file.
|
|
// Uses waitForBuildStatus with a generous 30 s deadline so contended
|
|
// Docker is never racing a tight budget (#382). All assertions are
|
|
// outcome-based; the deadline is deterministic, not a timing assertion.
|
|
const statusPath = path.join(tmpDir, '.planning/graphs/.last-build-status.json');
|
|
const status = await waitForBuildStatus(statusPath, new Set(['failed']));
|
|
assert.ok(status, 'status file must exist after dispatch');
|
|
assert.strictEqual(status.status, 'failed', 'mock graphify exit=1 → status failed');
|
|
assert.strictEqual(status.exit_code, 1);
|
|
});
|
|
|
|
test('lock file with a live PID prevents concurrent dispatch', (t) => {
|
|
const tmpDir = createTempGitRepo({
|
|
config: { graphify: { enabled: true, auto_update: true } },
|
|
});
|
|
t.after(() => cleanupHookRepo(tmpDir));
|
|
fs.mkdirSync(path.join(tmpDir, '.planning/graphs'), { recursive: true });
|
|
// Seed a live-PID lock pointing at our own process — kill -0 will succeed
|
|
fs.writeFileSync(path.join(tmpDir, '.planning/graphs/.rebuild.lock'), String(process.pid));
|
|
|
|
const mockBin = makeMockGraphifyBin(tmpDir);
|
|
const r = runHook(
|
|
tmpDir,
|
|
{ tool_name: 'Bash', tool_input: { command: 'git commit -m x' } },
|
|
{ pathPrepend: mockBin },
|
|
);
|
|
assert.strictEqual(r.status, 0);
|
|
// Status file should NOT be written because a rebuild is in flight
|
|
assert.ok(
|
|
!fs.existsSync(path.join(tmpDir, '.planning/graphs/.last-build-status.json')),
|
|
'live PID lock must suppress dispatch',
|
|
);
|
|
});
|
|
|
|
test('stale lock file (dead PID) is treated as absent', async (t) => {
|
|
const tmpDir = createTempGitRepo({
|
|
config: { graphify: { enabled: true, auto_update: true } },
|
|
});
|
|
t.after(() => cleanupHookRepo(tmpDir));
|
|
fs.mkdirSync(path.join(tmpDir, '.planning/graphs'), { recursive: true });
|
|
// PID 1 is init; kill -0 1 succeeds for root but fails for non-root.
|
|
// Use a very large PID number unlikely to exist (max pid = 4194304 on linux).
|
|
fs.writeFileSync(path.join(tmpDir, '.planning/graphs/.rebuild.lock'), '4194303');
|
|
|
|
const mockBin = makeMockGraphifyBin(tmpDir, { sleepMs: 500 });
|
|
const r = runHook(
|
|
tmpDir,
|
|
{ tool_name: 'Bash', tool_input: { command: 'git commit -m x' } },
|
|
{ pathPrepend: mockBin },
|
|
);
|
|
assert.strictEqual(r.status, 0);
|
|
const statusPath = path.join(tmpDir, '.planning/graphs/.last-build-status.json');
|
|
assert.ok(fs.existsSync(statusPath), 'stale lock must not block dispatch');
|
|
// Await terminal status so the detached rebuild is gone before returning (see above).
|
|
const done = await waitForBuildStatus(statusPath, new Set(['ok', 'failed']));
|
|
assert.ok(done && (done.status === 'ok' || done.status === 'failed'),
|
|
'detached rebuild must reach a terminal status before the test returns');
|
|
});
|
|
|
|
test('respects git.base_branch config override (default branch != main)', async (t) => {
|
|
const tmpDir = createTempGitRepo({
|
|
defaultBranch: 'trunk',
|
|
config: {
|
|
graphify: { enabled: true, auto_update: true },
|
|
git: { base_branch: 'trunk' },
|
|
},
|
|
});
|
|
t.after(() => cleanupHookRepo(tmpDir));
|
|
const mockBin = makeMockGraphifyBin(tmpDir, { sleepMs: 100 });
|
|
const r = runHook(
|
|
tmpDir,
|
|
{ tool_name: 'Bash', tool_input: { command: 'git commit -m x' } },
|
|
{ pathPrepend: mockBin },
|
|
);
|
|
assert.strictEqual(r.status, 0);
|
|
const statusPath = path.join(tmpDir, '.planning/graphs/.last-build-status.json');
|
|
assert.ok(
|
|
fs.existsSync(statusPath),
|
|
'hook must honor git.base_branch when default branch is not main',
|
|
);
|
|
// Await terminal status so the detached rebuild is gone before returning (see above).
|
|
const done = await waitForBuildStatus(statusPath, new Set(['ok', 'failed']));
|
|
assert.ok(done && (done.status === 'ok' || done.status === 'failed'),
|
|
'detached rebuild must reach a terminal status before the test returns');
|
|
});
|
|
});
|
|
|
|
// #2304 — Kimi tool vocabulary engages the hook: Kimi CLI registers this
|
|
// hook with matcher 'Shell' and forwards tool_name 'Shell' (possibly
|
|
// module-qualified). kimi-cli's Shell.Params names its field `command`
|
|
// (src/kimi_cli/tools/shell/__init__.py), same as Claude's Bash, so only
|
|
// the tool name needs normalization. Pre-fix, the Gate 1 `== "Bash"` check
|
|
// never matched on Kimi and the auto-rebuild was silently dormant.
|
|
describe('hook — Kimi tool vocabulary (#2304)',
|
|
{ skip: isWindows ? 'POSIX-only: harness spawns bash to invoke the .sh hook under test' : false },
|
|
() => {
|
|
test('dispatches on Kimi tool_name Shell (all gates pass)', async (t) => {
|
|
const tmpDir = createTempGitRepo({
|
|
config: { graphify: { enabled: true, auto_update: true } },
|
|
});
|
|
t.after(() => cleanupHookRepo(tmpDir));
|
|
const mockBin = makeMockGraphifyBin(tmpDir);
|
|
const r = runHook(
|
|
tmpDir,
|
|
{ tool_name: 'Shell', tool_input: { command: 'git commit -m x' } },
|
|
{ pathPrepend: mockBin },
|
|
);
|
|
assert.strictEqual(r.status, 0, 'hook must return 0');
|
|
const statusPath = path.join(tmpDir, '.planning/graphs/.last-build-status.json');
|
|
assert.ok(
|
|
fs.existsSync(statusPath),
|
|
'Kimi Shell must pass Gate 1 and dispatch — pre-fix the hook was silently dormant on Kimi (#2304)',
|
|
);
|
|
const done = await waitForBuildStatus(statusPath, new Set(['ok', 'failed']));
|
|
assert.ok(done && (done.status === 'ok' || done.status === 'failed'),
|
|
'detached rebuild must reach a terminal status before the test returns');
|
|
});
|
|
|
|
test('dispatches on module-qualified kimi_cli.tools.shell:Shell', async (t) => {
|
|
const tmpDir = createTempGitRepo({
|
|
config: { graphify: { enabled: true, auto_update: true } },
|
|
});
|
|
t.after(() => cleanupHookRepo(tmpDir));
|
|
const mockBin = makeMockGraphifyBin(tmpDir);
|
|
const r = runHook(
|
|
tmpDir,
|
|
{ tool_name: 'kimi_cli.tools.shell:Shell', tool_input: { command: 'git commit -m x' } },
|
|
{ pathPrepend: mockBin },
|
|
);
|
|
assert.strictEqual(r.status, 0);
|
|
const statusPath = path.join(tmpDir, '.planning/graphs/.last-build-status.json');
|
|
assert.ok(fs.existsSync(statusPath),
|
|
'module-qualified Kimi tool name must be recognized after prefix strip');
|
|
const done = await waitForBuildStatus(statusPath, new Set(['ok', 'failed']));
|
|
assert.ok(done && (done.status === 'ok' || done.status === 'failed'),
|
|
'detached rebuild must reach a terminal status before the test returns');
|
|
});
|
|
|
|
test('negative control: Kimi WriteFile does NOT dispatch', (t) => {
|
|
const tmpDir = createTempGitRepo({
|
|
config: { graphify: { enabled: true, auto_update: true } },
|
|
});
|
|
t.after(() => cleanupHookRepo(tmpDir));
|
|
const mockBin = makeMockGraphifyBin(tmpDir);
|
|
const r = runHook(
|
|
tmpDir,
|
|
// A command-shaped payload under a non-Shell Kimi tool: the name
|
|
// normalization must not widen Gate 1 beyond Shell→Bash.
|
|
{ tool_name: 'kimi_cli.tools.file:WriteFile', tool_input: { command: 'git commit -m x' } },
|
|
{ pathPrepend: mockBin },
|
|
);
|
|
assert.strictEqual(r.status, 0);
|
|
assert.ok(
|
|
!fs.existsSync(path.join(tmpDir, '.planning/graphs/.last-build-status.json')),
|
|
'non-Shell Kimi tools must still bail at Gate 1',
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('hook — HEAD-advancing command matchers',
|
|
{ skip: isWindows ? 'POSIX-only: harness spawns bash to invoke the .sh hook under test' : false },
|
|
() => {
|
|
for (const cmd of [
|
|
'git commit -m fix',
|
|
'git merge feature',
|
|
'git pull --ff-only',
|
|
'git rebase --continue',
|
|
'git cherry-pick abc123',
|
|
// #3653 — `gsd-tools query commit` invokes git via spawnSync('git', [...]),
|
|
// so the substring "git commit" never appears in tool_input.command.
|
|
// The hook must match the user-facing SDK invocation directly.
|
|
'gsd-tools query commit "docs: probe" --files .planning/STATE.md',
|
|
'npx gsd-tools query commit "docs: probe" --files .planning/STATE.md',
|
|
]) {
|
|
test(`dispatches on: ${cmd}`, async (t) => {
|
|
const tmpDir = createTempGitRepo({
|
|
config: { graphify: { enabled: true, auto_update: true } },
|
|
});
|
|
t.after(() => cleanupHookRepo(tmpDir));
|
|
const mockBin = makeMockGraphifyBin(tmpDir, { sleepMs: 100 });
|
|
runHook(
|
|
tmpDir,
|
|
{ tool_name: 'Bash', tool_input: { command: cmd } },
|
|
{ pathPrepend: mockBin },
|
|
);
|
|
const statusPath = path.join(tmpDir, '.planning/graphs/.last-build-status.json');
|
|
// Wait for any terminal status; we only assert the file exists,
|
|
// not which terminal value it holds (#382: generous deadline).
|
|
await waitForBuildStatus(statusPath, new Set(['ok', 'failed']));
|
|
assert.ok(
|
|
fs.existsSync(statusPath),
|
|
`must dispatch for HEAD-advancing op: ${cmd}`,
|
|
);
|
|
});
|
|
}
|
|
|
|
test('does NOT dispatch on SDK commit-to-subrepo prefix collision', (t) => {
|
|
const tmpDir = createTempGitRepo({
|
|
config: { graphify: { enabled: true, auto_update: true } },
|
|
});
|
|
t.after(() => cleanupHookRepo(tmpDir));
|
|
const mockBin = makeMockGraphifyBin(tmpDir, { sleepMs: 100 });
|
|
const r = runHook(
|
|
tmpDir,
|
|
{
|
|
tool_name: 'Bash',
|
|
tool_input: {
|
|
command: 'gsd-tools query commit-to-subrepo "msg" --files packages/foo',
|
|
},
|
|
},
|
|
{ pathPrepend: mockBin },
|
|
);
|
|
assert.strictEqual(r.status, 0);
|
|
assert.ok(
|
|
!fs.existsSync(path.join(tmpDir, '.planning/graphs/.last-build-status.json')),
|
|
'must NOT dispatch for commit-to-subrepo, which does not advance the outer repo HEAD',
|
|
);
|
|
});
|
|
|
|
// #1772 — agent runtimes (Claude Code's Bash tool among them) routinely
|
|
// emit HEAD-advancing commits as multi-line scripts (`cd /path` then
|
|
// `git add` then `git commit …`). The hook joins tool_name + "\n" +
|
|
// tool_input.command and must match the command across ALL its lines
|
|
// (line 2 through EOF), not just line 2 — otherwise a `git commit` that
|
|
// is not on the first command line silently no-ops the rebuild.
|
|
for (const cmd of [
|
|
"cd /tmp/repo\ngit add .\ngit commit -m 'multi-line commit'",
|
|
"cd /tmp/repo\ngit merge feature-branch",
|
|
"git fetch origin\ngit pull --ff-only",
|
|
]) {
|
|
test(`dispatches on multi-line command (#1772): ${cmd.split('\n').slice(0, 2).join(' ⏎ ')}…`, async (t) => {
|
|
const tmpDir = createTempGitRepo({
|
|
config: { graphify: { enabled: true, auto_update: true } },
|
|
});
|
|
t.after(() => cleanupHookRepo(tmpDir));
|
|
const mockBin = makeMockGraphifyBin(tmpDir, { sleepMs: 100 });
|
|
runHook(
|
|
tmpDir,
|
|
{ tool_name: 'Bash', tool_input: { command: cmd } },
|
|
{ pathPrepend: mockBin },
|
|
);
|
|
const statusPath = path.join(tmpDir, '.planning/graphs/.last-build-status.json');
|
|
await waitForBuildStatus(statusPath, new Set(['ok', 'failed']));
|
|
assert.ok(
|
|
fs.existsSync(statusPath),
|
|
`must dispatch for multi-line command where the HEAD-advancing op is not on line 1 (#1772): ${cmd}`,
|
|
);
|
|
});
|
|
}
|
|
|
|
test('multi-line command with NO HEAD-advancing op still no-ops (#1772 no-regression)', (t) => {
|
|
const tmpDir = createTempGitRepo({
|
|
config: { graphify: { enabled: true, auto_update: true } },
|
|
});
|
|
t.after(() => cleanupHookRepo(tmpDir));
|
|
const mockBin = makeMockGraphifyBin(tmpDir, { sleepMs: 100 });
|
|
const r = runHook(
|
|
tmpDir,
|
|
{
|
|
tool_name: 'Bash',
|
|
tool_input: {
|
|
// Multi-line, but only non-HEAD-advancing ops. Widening line
|
|
// extraction to 2..EOF must not cause a spurious dispatch.
|
|
command: 'cd /tmp/repo\nls -la\necho done',
|
|
},
|
|
},
|
|
{ pathPrepend: mockBin },
|
|
);
|
|
assert.strictEqual(r.status, 0);
|
|
assert.ok(
|
|
!fs.existsSync(path.join(tmpDir, '.planning/graphs/.last-build-status.json')),
|
|
'multi-line command without a HEAD-advancing git op must still no-op (#1772)',
|
|
);
|
|
});
|
|
|
|
// #3653 — only the SDK `commit` verb invokes git internally. Other
|
|
// `gsd-tools query` verbs (phase.complete, roadmap.update-plan-progress,
|
|
// state.begin-phase) mutate .md files but do NOT advance HEAD; matching
|
|
// them would cause a spurious rebuild per state mutation.
|
|
for (const cmd of [
|
|
'gsd-tools query phase.complete 109',
|
|
'gsd-tools query roadmap.update-plan-progress 109 W001',
|
|
'gsd-tools query state.begin-phase 110',
|
|
]) {
|
|
test(`does NOT dispatch on non-HEAD-advancing SDK verb: ${cmd}`, (t) => {
|
|
const tmpDir = createTempGitRepo({
|
|
config: { graphify: { enabled: true, auto_update: true } },
|
|
});
|
|
t.after(() => cleanupHookRepo(tmpDir));
|
|
const r = runHook(tmpDir, { tool_name: 'Bash', tool_input: { command: cmd } });
|
|
assert.strictEqual(r.status, 0);
|
|
assert.ok(
|
|
!fs.existsSync(path.join(tmpDir, '.planning/graphs/.last-build-status.json')),
|
|
`must NOT dispatch for non-HEAD-advancing SDK verb: ${cmd}`,
|
|
);
|
|
});
|
|
}
|
|
});
|
|
});
|