Merge pull request #3510 from gsd-build/fix/3509-test-suite-cli-break-when-repo-path-cont
fix(tests): use array args for space-containing paths — closes #3509
This commit is contained in:
5
.changeset/fix-3509-path-spaces-test-suite.md
Normal file
5
.changeset/fix-3509-path-spaces-test-suite.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
type: Fixed
|
||||
pr: 3510
|
||||
---
|
||||
**Test suite and CLI no longer break when repo path contains spaces** — `dispatcher --cwd=`, `frontmatter-cli`, `profile-pipeline`, and `commands` no longer split paths on whitespace. (#3510)
|
||||
141
tests/bug-3509-path-spaces.test.cjs
Normal file
141
tests/bug-3509-path-spaces.test.cjs
Normal file
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
* Regression tests for #3509 — CLI breaks when repo path contains spaces
|
||||
*
|
||||
* Root cause: test code embedded space-containing paths into runGsdTools()
|
||||
* string args; the helper's whitespace tokenizer truncated paths at the first
|
||||
* space. All calls that carry dynamic paths must use the array form of
|
||||
* runGsdTools() so execFileSync receives the full path as a single argv slot.
|
||||
*
|
||||
* These tests create a tmpdir whose prefix intentionally contains a space so
|
||||
* they remain red on a broken codebase regardless of the host machine's
|
||||
* tmpdir location.
|
||||
*/
|
||||
|
||||
const { test, describe, beforeEach, afterEach } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
const { runGsdTools } = require('./helpers.cjs');
|
||||
|
||||
// Create a tmpdir whose name always contains a space — this is the invariant
|
||||
// that was violated on /Volumes/Mini Me/... machines.
|
||||
function createSpacedTmpDir(prefix = 'path with spaces-') {
|
||||
return fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
||||
}
|
||||
|
||||
function cleanup(dir) {
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
// ─── dispatcher --cwd= with space in path ────────────────────────────────────
|
||||
|
||||
describe('bug-3509: --cwd= survives spaces in path', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = createSpacedTmpDir();
|
||||
fs.mkdirSync(path.join(tmpDir, '.planning', 'phases'), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(tmpDir, '.planning', 'STATE.md'),
|
||||
'# Project State\n\n## Current Position\n\nPhase: 1 of 1 (Test)\n'
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => cleanup(tmpDir));
|
||||
|
||||
test('--cwd= array form passes full path with spaces to dispatcher', () => {
|
||||
// Array form: path is a single argv slot, never split on whitespace
|
||||
const result = runGsdTools(['--cwd=' + tmpDir, 'state', 'load'], process.cwd());
|
||||
assert.ok(result.success, `--cwd= with spaced path should succeed, got: ${result.error}`);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── frontmatter-cli file path with spaces ───────────────────────────────────
|
||||
|
||||
describe('bug-3509: frontmatter get/set/merge/validate survive spaces in file path', () => {
|
||||
let tmpDir;
|
||||
let tmpFile;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = createSpacedTmpDir();
|
||||
tmpFile = path.join(tmpDir, 'test.md');
|
||||
fs.writeFileSync(tmpFile, '---\nphase: 01\nplan: 01\ntype: execute\n---\nbody');
|
||||
});
|
||||
|
||||
afterEach(() => cleanup(tmpDir));
|
||||
|
||||
test('frontmatter get returns parsed fields when file path contains spaces', () => {
|
||||
const result = runGsdTools(['frontmatter', 'get', tmpFile]);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
const parsed = JSON.parse(result.output);
|
||||
assert.strictEqual(parsed.phase, '01', 'phase field should be "01"');
|
||||
});
|
||||
|
||||
test('frontmatter set works when file path contains spaces', () => {
|
||||
const setResult = runGsdTools(['frontmatter', 'set', tmpFile, '--field', 'phase', '--value', '02']);
|
||||
assert.ok(setResult.success, `set failed: ${setResult.error}`);
|
||||
// Verify behaviorally — round-trip via frontmatter get rather than reading the file
|
||||
// and grepping (which trips lint-no-source-grep even on tmp files).
|
||||
const getResult = runGsdTools(['frontmatter', 'get', tmpFile]);
|
||||
assert.ok(getResult.success, `get failed: ${getResult.error}`);
|
||||
const parsed = JSON.parse(getResult.output);
|
||||
assert.strictEqual(parsed.phase, '02', 'field should be updated to "02"');
|
||||
});
|
||||
|
||||
test('frontmatter validate works when file path contains spaces', () => {
|
||||
// Plan frontmatter schema — file path contains a space; must reach validation, not fail on path
|
||||
const result = runGsdTools(['frontmatter', 'validate', tmpFile, '--schema', 'plan']);
|
||||
// Should succeed (exit 0) and return structured JSON with valid/missing, not a path-split error
|
||||
assert.ok(result.success, `Command should exit 0, got: ${result.error}`);
|
||||
const out = JSON.parse(result.output);
|
||||
assert.ok('valid' in out, 'should return structured JSON with "valid" field');
|
||||
});
|
||||
});
|
||||
|
||||
// ─── verify-path-exists with absolute path containing spaces ─────────────────
|
||||
|
||||
describe('bug-3509: verify-path-exists survives absolute paths with spaces', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = createSpacedTmpDir();
|
||||
fs.mkdirSync(path.join(tmpDir, '.planning', 'phases'), { recursive: true });
|
||||
});
|
||||
|
||||
afterEach(() => cleanup(tmpDir));
|
||||
|
||||
test('absolute path with spaces resolves correctly via array form', () => {
|
||||
const absFile = path.join(tmpDir, 'abs-test.txt');
|
||||
fs.writeFileSync(absFile, 'content');
|
||||
|
||||
const result = runGsdTools(['verify-path-exists', absFile], tmpDir);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
const output = JSON.parse(result.output);
|
||||
assert.strictEqual(output.exists, true, 'file should be found');
|
||||
assert.strictEqual(output.type, 'file');
|
||||
});
|
||||
});
|
||||
|
||||
// ─── profile-pipeline --path with spaces ─────────────────────────────────────
|
||||
|
||||
describe('bug-3509: scan-sessions --path survives spaces in path', () => {
|
||||
let tmpDir;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = createSpacedTmpDir();
|
||||
});
|
||||
|
||||
afterEach(() => cleanup(tmpDir));
|
||||
|
||||
test('scan-sessions --path with spaces returns empty array, not path-split error', () => {
|
||||
const sessionsDir = path.join(tmpDir, 'projects');
|
||||
fs.mkdirSync(sessionsDir, { recursive: true });
|
||||
|
||||
const result = runGsdTools(['scan-sessions', '--path', sessionsDir, '--raw'], tmpDir);
|
||||
assert.ok(result.success, `Failed: ${result.error}`);
|
||||
const out = JSON.parse(result.output);
|
||||
assert.ok(Array.isArray(out), 'should return an array');
|
||||
assert.strictEqual(out.length, 0, 'should be empty for empty sessions dir');
|
||||
});
|
||||
});
|
||||
@@ -1031,7 +1031,7 @@ describe('verify-path-exists command', () => {
|
||||
const absFile = path.join(tmpDir, 'abs-test.txt');
|
||||
fs.writeFileSync(absFile, 'content');
|
||||
|
||||
const result = runGsdTools(`verify-path-exists ${absFile}`, tmpDir);
|
||||
const result = runGsdTools(['verify-path-exists', absFile], tmpDir);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
|
||||
const output = JSON.parse(result.output);
|
||||
|
||||
@@ -48,7 +48,7 @@ describe('dispatcher error paths', () => {
|
||||
path.join(tmpDir, '.planning', 'STATE.md'),
|
||||
'# Project State\n\n## Current Position\n\nPhase: 1 of 1 (Test)\n'
|
||||
);
|
||||
const result = runGsdTools(`--cwd=${tmpDir} state load`, process.cwd());
|
||||
const result = runGsdTools(['--cwd=' + tmpDir, 'state', 'load'], process.cwd());
|
||||
assert.strictEqual(result.success, true, `Should succeed with --cwd=, got: ${result.error}`);
|
||||
});
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ afterEach(() => {
|
||||
describe('frontmatter get', () => {
|
||||
test('returns all fields as JSON', () => {
|
||||
const file = writeTempFile('---\nphase: 01\nplan: 01\ntype: execute\n---\nbody text');
|
||||
const result = runGsdTools(`frontmatter get ${file}`);
|
||||
const result = runGsdTools(['frontmatter', 'get', file]);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
const parsed = JSON.parse(result.output);
|
||||
assert.strictEqual(parsed.phase, '01');
|
||||
@@ -52,7 +52,7 @@ describe('frontmatter get', () => {
|
||||
|
||||
test('returns specific field with --field', () => {
|
||||
const file = writeTempFile('---\nphase: 01\nplan: 02\ntype: tdd\n---\nbody');
|
||||
const result = runGsdTools(`frontmatter get ${file} --field phase`);
|
||||
const result = runGsdTools(['frontmatter', 'get', file, '--field', 'phase']);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
const parsed = JSON.parse(result.output);
|
||||
assert.strictEqual(parsed.phase, '01');
|
||||
@@ -60,7 +60,7 @@ describe('frontmatter get', () => {
|
||||
|
||||
test('returns error for missing field', () => {
|
||||
const file = writeTempFile('---\nphase: 01\n---\n');
|
||||
const result = runGsdTools(`frontmatter get ${file} --field nonexistent`);
|
||||
const result = runGsdTools(['frontmatter', 'get', file, '--field', 'nonexistent']);
|
||||
// The command succeeds (exit 0) but returns an error object in JSON
|
||||
assert.ok(result.success, 'Command should exit 0');
|
||||
const parsed = JSON.parse(result.output);
|
||||
@@ -77,7 +77,7 @@ describe('frontmatter get', () => {
|
||||
|
||||
test('handles file with no frontmatter', () => {
|
||||
const file = writeTempFile('Plain text with no frontmatter delimiters.');
|
||||
const result = runGsdTools(`frontmatter get ${file}`);
|
||||
const result = runGsdTools(['frontmatter', 'get', file]);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
const parsed = JSON.parse(result.output);
|
||||
assert.deepStrictEqual(parsed, {}, 'Should return empty object for no frontmatter');
|
||||
@@ -89,7 +89,7 @@ describe('frontmatter get', () => {
|
||||
describe('frontmatter set', () => {
|
||||
test('updates existing field', () => {
|
||||
const file = writeTempFile('---\nphase: 01\ntype: execute\n---\nbody');
|
||||
const result = runGsdTools(`frontmatter set ${file} --field phase --value "02"`);
|
||||
const result = runGsdTools(['frontmatter', 'set', file, '--field', 'phase', '--value', '02']);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
|
||||
// Read back and verify
|
||||
@@ -101,7 +101,7 @@ describe('frontmatter set', () => {
|
||||
|
||||
test('adds new field', () => {
|
||||
const file = writeTempFile('---\nphase: 01\n---\nbody');
|
||||
const result = runGsdTools(`frontmatter set ${file} --field status --value "active"`);
|
||||
const result = runGsdTools(['frontmatter', 'set', file, '--field', 'status', '--value', 'active']);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
|
||||
const content = fs.readFileSync(file, 'utf-8');
|
||||
@@ -132,7 +132,7 @@ describe('frontmatter set', () => {
|
||||
test('preserves body content after set', () => {
|
||||
const bodyText = '\n\n# My Heading\n\nSome paragraph with special chars: $, %, &.';
|
||||
const file = writeTempFile('---\nphase: 01\n---' + bodyText);
|
||||
runGsdTools(`frontmatter set ${file} --field phase --value "02"`);
|
||||
runGsdTools(['frontmatter', 'set', file, '--field', 'phase', '--value', '02']);
|
||||
|
||||
const content = fs.readFileSync(file, 'utf-8');
|
||||
assert.ok(content.includes('# My Heading'), 'heading should be preserved');
|
||||
@@ -177,7 +177,7 @@ describe('frontmatter merge', () => {
|
||||
|
||||
test('returns error for invalid JSON data', () => {
|
||||
const file = writeTempFile('---\nphase: 01\n---\nbody');
|
||||
const result = runGsdTools(`frontmatter merge ${file} --data 'not json'`);
|
||||
const result = runGsdTools(['frontmatter', 'merge', file, '--data', 'not json']);
|
||||
// cmdFrontmatterMerge calls error() which exits with code 1
|
||||
assert.ok(!result.success, 'Command should fail with non-zero exit code');
|
||||
assert.ok(result.error.includes('Invalid JSON'), 'Error should mention invalid JSON');
|
||||
@@ -202,7 +202,7 @@ must_haves:
|
||||
---
|
||||
body`;
|
||||
const file = writeTempFile(content);
|
||||
const result = runGsdTools(`frontmatter validate ${file} --schema plan`);
|
||||
const result = runGsdTools(['frontmatter', 'validate', file, '--schema', 'plan']);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
const parsed = JSON.parse(result.output);
|
||||
assert.strictEqual(parsed.valid, true, 'Should be valid');
|
||||
@@ -212,7 +212,7 @@ body`;
|
||||
|
||||
test('reports invalid with missing fields', () => {
|
||||
const file = writeTempFile('---\nphase: 01\n---\nbody');
|
||||
const result = runGsdTools(`frontmatter validate ${file} --schema plan`);
|
||||
const result = runGsdTools(['frontmatter', 'validate', file, '--schema', 'plan']);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
const parsed = JSON.parse(result.output);
|
||||
assert.strictEqual(parsed.valid, false, 'Should be invalid');
|
||||
@@ -236,7 +236,7 @@ completed: 2026-02-25
|
||||
---
|
||||
body`;
|
||||
const file = writeTempFile(content);
|
||||
const result = runGsdTools(`frontmatter validate ${file} --schema summary`);
|
||||
const result = runGsdTools(['frontmatter', 'validate', file, '--schema', 'summary']);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
const parsed = JSON.parse(result.output);
|
||||
assert.strictEqual(parsed.valid, true, 'Should be valid for summary schema');
|
||||
@@ -252,7 +252,7 @@ score: 5/5
|
||||
---
|
||||
body`;
|
||||
const file = writeTempFile(content);
|
||||
const result = runGsdTools(`frontmatter validate ${file} --schema verification`);
|
||||
const result = runGsdTools(['frontmatter', 'validate', file, '--schema', 'verification']);
|
||||
assert.ok(result.success, `Command failed: ${result.error}`);
|
||||
const parsed = JSON.parse(result.output);
|
||||
assert.strictEqual(parsed.valid, true, 'Should be valid for verification schema');
|
||||
@@ -261,7 +261,7 @@ body`;
|
||||
|
||||
test('returns error for unknown schema', () => {
|
||||
const file = writeTempFile('---\nphase: 01\n---\n');
|
||||
const result = runGsdTools(`frontmatter validate ${file} --schema unknown`);
|
||||
const result = runGsdTools(['frontmatter', 'validate', file, '--schema', 'unknown']);
|
||||
// cmdFrontmatterValidate calls error() which exits with code 1
|
||||
assert.ok(!result.success, 'Command should fail with non-zero exit code');
|
||||
assert.ok(result.error.includes('Unknown schema'), 'Error should mention unknown schema');
|
||||
|
||||
@@ -28,7 +28,7 @@ describe('scan-sessions command', () => {
|
||||
test('returns empty array for empty sessions directory', () => {
|
||||
const sessionsDir = path.join(tmpDir, 'projects');
|
||||
fs.mkdirSync(sessionsDir, { recursive: true });
|
||||
const result = runGsdTools(`scan-sessions --path ${sessionsDir} --raw`, tmpDir);
|
||||
const result = runGsdTools(['scan-sessions', '--path', sessionsDir, '--raw'], tmpDir);
|
||||
assert.ok(result.success, `Failed: ${result.error}`);
|
||||
const out = JSON.parse(result.output);
|
||||
assert.ok(Array.isArray(out), 'should return an array');
|
||||
@@ -47,7 +47,7 @@ describe('scan-sessions command', () => {
|
||||
].join('\n');
|
||||
fs.writeFileSync(path.join(projectDir, 'session-001.jsonl'), sessionData);
|
||||
|
||||
const result = runGsdTools(`scan-sessions --path ${sessionsDir} --raw`, tmpDir);
|
||||
const result = runGsdTools(['scan-sessions', '--path', sessionsDir, '--raw'], tmpDir);
|
||||
assert.ok(result.success, `Failed: ${result.error}`);
|
||||
const out = JSON.parse(result.output);
|
||||
assert.ok(Array.isArray(out), 'should return array');
|
||||
@@ -65,7 +65,7 @@ describe('scan-sessions command', () => {
|
||||
fs.writeFileSync(path.join(projectDir, `session-${i}.jsonl`), data + '\n');
|
||||
}
|
||||
|
||||
const result = runGsdTools(`scan-sessions --path ${sessionsDir} --raw`, tmpDir);
|
||||
const result = runGsdTools(['scan-sessions', '--path', sessionsDir, '--raw'], tmpDir);
|
||||
assert.ok(result.success, `Failed: ${result.error}`);
|
||||
const out = JSON.parse(result.output);
|
||||
assert.strictEqual(out[0].sessionCount, 3);
|
||||
@@ -102,7 +102,7 @@ describe('extract-messages command', () => {
|
||||
messages.map(m => JSON.stringify(m)).join('\n')
|
||||
);
|
||||
|
||||
const result = runGsdTools(`extract-messages my-project --path ${sessionsDir} --raw`, tmpDir);
|
||||
const result = runGsdTools(['extract-messages', 'my-project', '--path', sessionsDir, '--raw'], tmpDir);
|
||||
assert.ok(result.success, `Failed: ${result.error}`);
|
||||
const out = JSON.parse(result.output);
|
||||
assert.strictEqual(out.messages_extracted, 2, 'should extract 2 genuine user messages');
|
||||
@@ -128,7 +128,7 @@ describe('extract-messages command', () => {
|
||||
messages.map(m => JSON.stringify(m)).join('\n')
|
||||
);
|
||||
|
||||
const result = runGsdTools(`extract-messages filter-test --path ${sessionsDir} --raw`, tmpDir);
|
||||
const result = runGsdTools(['extract-messages', 'filter-test', '--path', sessionsDir, '--raw'], tmpDir);
|
||||
assert.ok(result.success, `Failed: ${result.error}`);
|
||||
const out = JSON.parse(result.output);
|
||||
assert.strictEqual(out.messages_extracted, 2, 'should only extract 2 genuine external messages');
|
||||
|
||||
Reference in New Issue
Block a user