Merge pull request #2739 from gsd-build/fix/2732-graphify-cli-invocation

fix(graphify): update CLI invocation from legacy flag form to subcommand
This commit is contained in:
Tom Boucher
2026-04-26 11:49:09 -04:00
committed by GitHub
3 changed files with 68 additions and 16 deletions

View File

@@ -153,7 +153,7 @@ gsd-tools path: $HOME/.claude/get-shit-done/bin/gsd-tools.cjs
1. **Invoke graphify:** 1. **Invoke graphify:**
Run from the project root: Run from the project root:
``` ```
graphify . --update graphify update .
``` ```
This builds the knowledge graph with SHA256 incremental caching. This builds the knowledge graph with SHA256 incremental caching.
Timeout: up to 5 minutes (or as configured via graphify.build_timeout). Timeout: up to 5 minutes (or as configured via graphify.build_timeout).

View File

@@ -102,26 +102,55 @@ function checkGraphifyInstalled() {
} }
/** /**
* Detect graphify version via python3 importlib.metadata and check compatibility. * Detect graphify version and check compatibility.
* Tested range: >=0.4.0,<1.0 * Tested range: >=0.4.0,<1.0
* *
* Detection strategy:
* 1. Try `graphify --version` (works for most CLI installations, incl. venv installs)
* 2. Fall back to python3 importlib.metadata (legacy / system Python path)
* 3. Return null version gracefully if both fail
*
* @returns {{ version: string|null, compatible: boolean|null, warning: string|null }} * @returns {{ version: string|null, compatible: boolean|null, warning: string|null }}
*/ */
function checkGraphifyVersion() { function checkGraphifyVersion() {
const result = childProcess.spawnSync('python3', [ // Strategy 1: try `graphify --version` directly (2s timeout -- fast path)
'-c', const versionResult = childProcess.spawnSync('graphify', ['--version'], {
'from importlib.metadata import version; print(version("graphifyy"))',
], {
stdio: 'pipe', stdio: 'pipe',
encoding: 'utf-8', encoding: 'utf-8',
timeout: 5000, timeout: 2000,
}); });
if (result.status !== 0 || !result.stdout || !result.stdout.trim()) { let versionStr = null;
if (!versionResult.error && versionResult.status === 0) {
const raw = (versionResult.stdout || '').trim();
// graphify --version may emit "graphify 0.4.23" or just "0.4.23"
const match = raw.match(/(\d+\.\d+(?:\.\d+)*)/);
if (match) {
versionStr = match[1];
}
}
// Strategy 2: fall back to python3 importlib.metadata
if (!versionStr) {
const pyResult = childProcess.spawnSync('python3', [
'-c',
'from importlib.metadata import version; print(version("graphifyy"))',
], {
stdio: 'pipe',
encoding: 'utf-8',
timeout: 5000,
});
if (!pyResult.error && pyResult.status === 0 && pyResult.stdout && pyResult.stdout.trim()) {
versionStr = pyResult.stdout.trim();
}
}
if (!versionStr) {
return { version: null, compatible: null, warning: 'Could not determine graphify version' }; return { version: null, compatible: null, warning: 'Could not determine graphify version' };
} }
const versionStr = result.stdout.trim();
const parts = versionStr.split('.').map(Number); const parts = versionStr.split('.').map(Number);
if (parts.length < 2 || parts.some(isNaN)) { if (parts.length < 2 || parts.some(isNaN)) {

View File

@@ -384,18 +384,41 @@ describe('checkGraphifyVersion', () => {
assert.ok(result.warning.includes('Could not parse')); assert.ok(result.warning.includes('Could not parse'));
}); });
test('calls python3 with importlib.metadata', () => { test('tries graphify --version first before python3', () => {
let capturedCmd; const calls = [];
let capturedArgs;
mock.method(childProcess, 'spawnSync', (cmd, args) => { mock.method(childProcess, 'spawnSync', (cmd, args) => {
capturedCmd = cmd; calls.push({ cmd, args });
capturedArgs = args;
return { status: 0, stdout: '0.4.3\n', stderr: '', error: undefined, signal: null }; return { status: 0, stdout: '0.4.3\n', stderr: '', error: undefined, signal: null };
}); });
checkGraphifyVersion(); checkGraphifyVersion();
assert.strictEqual(capturedCmd, 'python3'); assert.strictEqual(calls.length, 1, 'exactly one spawnSync call — no python3 fallback');
assert.ok(capturedArgs.some(arg => arg.includes('importlib.metadata'))); assert.strictEqual(calls[0].cmd, 'graphify');
assert.ok(calls[0].args.includes('--version'), 'graphify called with --version');
const python3Calls = calls.filter(c => c.cmd === 'python3');
assert.strictEqual(python3Calls.length, 0, 'no python3 fallback when graphify --version succeeds');
});
test('falls back to python3 importlib.metadata when graphify --version fails', () => {
const calls = [];
mock.method(childProcess, 'spawnSync', (cmd, args) => {
calls.push({ cmd, args });
if (cmd === 'graphify') {
return { status: 1, stdout: '', stderr: 'unknown option', error: undefined, signal: null };
}
// python3 fallback
return { status: 0, stdout: '0.4.3\n', stderr: '', error: undefined, signal: null };
});
const result = checkGraphifyVersion();
assert.strictEqual(result.version, '0.4.3');
assert.strictEqual(result.compatible, true);
assert.ok(calls.length >= 2, 'at least two spawnSync calls (graphify attempt + python3 fallback)');
assert.strictEqual(calls[0].cmd, 'graphify', 'graphify call precedes python3 fallback');
assert.ok(calls[0].args.includes('--version'), 'graphify --version attempted first');
const lastCall = calls[calls.length - 1];
assert.strictEqual(lastCall.cmd, 'python3', 'python3 fallback fires last');
assert.ok(lastCall.args.some(arg => arg.includes('importlib.metadata')));
}); });
}); });