The windows-test-parity ratchet greps test source for fs.rmSync-without-
maxRetries (and six other Windows-portability anti-patterns), failing when an
integer offender COUNT exceeds a frozen baseline (rmSync: 95). A count ratchet
is a Goodhart metric: fixing one offender and adding another keeps the count
constant, so a new defect slips through green. Replace it — and every other
count ratchet in the repo — with a layered, masking-proof design.
Behavioral seam test
- tests/helpers-cleanup.test.cjs proves helpers.cleanup() carries the Windows
EBUSY retry budget. cleanup() delegates retries to Node's fs.rmSync via
maxRetries (it owns no loop), so the test asserts the option contract
(recursive/force/maxRetries>0/retryDelay>0) + real-FS removal + the cwd-guard,
rather than a loop that does not exist. The EBUSY risk is now tested ONCE at
the helper, not approximated textually at every call site.
Write-time ESLint rule (AST-accurate, replaces the grep)
- eslint-rules/no-raw-rmsync-in-tests.cjs (error in tests/**/*.test.cjs) bans
raw fs.rmSync, steering to cleanup(). Catches member, computed (fs['rmSync']),
destructured and aliased forms; escape hatch is inline
`// eslint-disable-next-line local/no-raw-rmsync-in-tests -- <reason>` only.
- Migrated 336 raw fs.rmSync teardown calls across ~116 test files to cleanup().
~18 genuinely load-bearing sites (mid-test SUT/fault-injection removals,
error-swallowing or name-colliding local teardown helpers) keep the raw call
with an inline eslint-disable + reason.
Shared anti-ratchet primitive
- scripts/lib/allowlist-ratchet.cjs:
- assertWithinAllowlist: fails on NOVEL ids (new offender introduced) AND on
STALE ids (a known offender was fixed but not pruned) — identity, not count,
and a ratchet DOWN toward zero.
- assertTightCeiling: a size/length budget whose ceiling must stay within a
grace band of the high-water mark, so budgets may only tighten, never creep.
Ratchets converted onto the primitive
- windows-test-parity-guard.test.cjs: rmSync rule deleted (now ESLint-enforced);
the remaining six patterns moved from integer baselines to named-set
allowlists with ratchet-down.
- scripts/lint-test-file-count.{cjs,allowlist.json}: per-module integer counts →
named filename sets (closes the swap-a-file-keep-the-count blind spot); a
module dropping under cap now FAILS to force pruning its allowlist entry.
- enh-2790 skill-count `<= 63` → named skill allowlist (ratchets toward ~58).
Size budgets hardened (tighten-only)
- agent-size / workflow-size / feat-3039 help-tiered: ceilings lowered to the
current high-water mark and an assertTightCeiling anti-creep check added per
tier. Fixed external-contract limits (description ≤100 chars, agent ≤100 KB)
are intentionally left as-is — they are not grandfathered creeping budgets.
No user-facing behavior change (tests + tooling only); no USER_FACING_PREFIXES
touched, so no changeset fragment is required.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
138 lines
5.8 KiB
JavaScript
138 lines
5.8 KiB
JavaScript
/**
|
|
* 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, cleanup } = 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));
|
|
}
|
|
|
|
// ─── 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');
|
|
});
|
|
});
|