Two more diagnostic passes (clusters J: residuals in already-touched files,
K: 12 untouched files) plus a production-code path fix and a new
ratchet-style lint guard.
## Test-only fixes (14 files)
bug-1736, bug-2248, bug-2698 — replace inline 1s-budget rmSync with the
shared cleanup() helper (5s budget, 20×250ms retries). The earlier
inline maxRetries:10 / retryDelay:100 wasn't enough to absorb Windows
Defender's deferred-scan handle hold on cold runners.
bug-2256, skill-manifest — also override USERPROFILE alongside HOME in
beforeEach/runGsdTools calls. os.homedir() reads USERPROFILE on win32,
so HOME-only stubs leak the runner's real home into the SUT.
bug-2784, bug-3608, enh-2500, enh-2790, few-shot-calibration,
gsd-settings-advanced — CRLF tolerance: literal \n in regexes against
file content (frontmatter anchors, bash-fence regex, multi-line
numbered-list captures, awk-block extractors) becomes \r?\n; split('\n')
becomes split(/\r?\n/). Windows checkout with autocrlf=true puts \r
before every \n; .+ doesn't match \r in JS regex by default.
bug-2966 — three-part fix to extractStepRun (CRLF split), awk regex
(\r?\n), and conflict-marker parser (rawLine + \r$ strip).
bug-2969, config — normalize separators on test assertions where the
SUT correctly emits \ on win32 but the test compares against /.
prompt-injection-scan — normalize relPath via replace(/\\/g, '/') before
ALLOWLIST.has() lookup. ALLOWLIST keys are POSIX; path.relative returns
backslashes on win32 → falsely scans allowlisted security module → trips
the boundary-tag detector on its own legitimate detection code.
prune-orphaned-worktrees — use the existing canonicalPath +
listedWorktreePaths(repoDir).has(...) helpers instead of substring
matching the raw path. git stores long-form canonical paths
(runneradmin), but mkdtempSync returns 8.3 short-form (RUNNER~1) on
Windows runners; plain string compare misses every entry.
## Production-code fix (1 file)
get-shit-done/bin/lib/init.cjs — bug-3491 in_nested_subdir computation
canonicalizes both worktreeRoot and cwd via fs.realpathSync.native +
path.relative before declaring "nested." Windows runner cwd (8.3 short
name) vs git's --show-toplevel (long form, forward slashes) made the
raw string compare always say true even at the worktree root, breaking
the "init new-project at worktree root" subtest.
## New ratchet lint guard
tests/windows-test-parity-guard.test.cjs — scans tests/ for 7
anti-patterns that drove the Windows failure clusters. Each rule has a
baseline count snapshot from this PR; the test fails when a new
occurrence appears (count grows above baseline), ratcheting down as
existing offenders are fixed. Patterns covered:
G1 split('\n') after readFileSync (use /\r?\n/)
G2 ```bash\n fence regex (use ```bash\r?\n)
G3 ^---\n frontmatter anchor (use ^---\r?\n)
G4 hardcoded "/tmp/..." literal passed to fs.* (use os.tmpdir())
G5 bare 'npm' to execFileSync without {shell:true} on win32
G6 process.env.HOME stub with no USERPROFILE
G7 fs.rmSync({recursive,force}) without maxRetries
Future Windows-parity regressions get caught at PR time rather than
five iterations into a CI loop.
Validated: holodeck (ubuntu docker) 11232/0 pass (count +8 = the 7
new ratchet tests + parent describe).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
187 lines
7.5 KiB
JavaScript
187 lines
7.5 KiB
JavaScript
// allow-test-rule: pending-migration-to-typed-ir [#2974]
|
|
// Tracked in #2974 for migration to typed-IR assertions per CONTRIBUTING.md
|
|
// "Prohibited: Raw Text Matching on Test Outputs". Per-file review may
|
|
// reclassify some entries as source-text-is-the-product during migration.
|
|
|
|
/**
|
|
* Regression test for #2698: CRLF line endings break agent-block strip regexes
|
|
*
|
|
* The legacy `gsd-update-check` hook migration in bin/install.js uses two
|
|
* separate .replace() calls:
|
|
* 1. LF-only regex: /\n# GSD Hooks\n\[\[hooks\]\]\nevent = ...\n/
|
|
* 2. CRLF-only regex: /\r\n# GSD Hooks\r\n\[\[hooks\]\]\r\nevent = ...\r\n/
|
|
*
|
|
* These patterns fail when config.toml has mixed line endings — e.g. the
|
|
* "# GSD Hooks" header uses LF but the body uses CRLF, or vice versa. This
|
|
* can happen when the file is created cross-platform (Windows/Linux), when
|
|
* editors convert only part of the file, or when a previous GSD version wrote
|
|
* the block with different EOL than the file's dominant EOL.
|
|
*
|
|
* Fix: consolidate to a single \r?\n-aware regex that handles LF, CRLF, and
|
|
* any mix in a single pass, making the migration robust regardless of the
|
|
* platform the file was last written on.
|
|
*
|
|
* Test approach: write a `.codex/config.toml` with a stale gsd-update-check
|
|
* block that uses mixed line endings (header in LF, body in CRLF), then run
|
|
* install() and assert the stale block is gone.
|
|
*
|
|
* Note: The local Codex install writes to `.codex/` in the current directory.
|
|
* Tests `process.chdir(tmpDir)` and write fixtures to `tmpDir/.codex/`.
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
process.env.GSD_TEST_MODE = '1';
|
|
|
|
const { describe, test, before, beforeEach, afterEach } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const os = require('os');
|
|
const { execFileSync } = require('child_process');
|
|
|
|
const INSTALL_SRC = path.join(__dirname, '..', 'bin', 'install.js');
|
|
const BUILD_SCRIPT = path.join(__dirname, '..', 'scripts', 'build-hooks.js');
|
|
const { install, GSD_CODEX_MARKER } = require(INSTALL_SRC);
|
|
const { cleanup } = require('./helpers.cjs');
|
|
|
|
// Ensure hooks/dist/ is populated before install tests
|
|
before(() => {
|
|
execFileSync(process.execPath, [BUILD_SCRIPT], {
|
|
encoding: 'utf-8',
|
|
stdio: 'pipe',
|
|
});
|
|
});
|
|
|
|
describe('#2698: CRLF stale gsd-update-check block is removed on Codex reinstall', () => {
|
|
let tmpDir;
|
|
|
|
beforeEach(() => {
|
|
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-crlf-install-2698-'));
|
|
});
|
|
|
|
afterEach(() => {
|
|
// Use the shared 5s Windows-EBUSY retry budget instead of inline 1s.
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
// Helper: pre-populate .codex/config.toml with a GSD marker + stale hooks block
|
|
// using the given line ending for the stale hooks block header, and a potentially
|
|
// different EOL for the hooks body. This exercises the cross-platform mixed scenario.
|
|
function writeCodexConfigWithStaleHooks(dir, headerEol, bodyEol) {
|
|
// Build the stale block with header EOL for the "# GSD Hooks" line, but body EOL
|
|
// for the content lines (simulates a file edited by two different platforms).
|
|
const staleBlock = [
|
|
'# GSD Hooks', // line that starts the stale section
|
|
'[[hooks]]',
|
|
'event = "SessionStart"',
|
|
'command = "node /old/path/gsd-update-check.js"',
|
|
].join(bodyEol);
|
|
|
|
// Put the stale block in user content BEFORE the GSD marker. The GSD marker area
|
|
// will be regenerated by mergeCodexConfig during install(); the stale block in
|
|
// the user area is what the hooks migration must remove.
|
|
const content = [
|
|
'[features]',
|
|
'codex_hooks = true',
|
|
'',
|
|
].join(headerEol) + headerEol + staleBlock + headerEol + headerEol + GSD_CODEX_MARKER + headerEol;
|
|
|
|
const codexDir = path.join(dir, '.codex');
|
|
fs.mkdirSync(codexDir, { recursive: true });
|
|
const configPath = path.join(codexDir, 'config.toml');
|
|
fs.writeFileSync(configPath, content, 'utf-8');
|
|
return configPath;
|
|
}
|
|
|
|
function readHooksSessionStartCommands(codexHome) {
|
|
const hooksPath = path.join(codexHome, 'hooks.json');
|
|
if (!fs.existsSync(hooksPath)) return [];
|
|
const raw = fs.readFileSync(hooksPath, 'utf8').trim();
|
|
if (!raw) return [];
|
|
const parsed = JSON.parse(raw);
|
|
const table = (parsed.hooks && typeof parsed.hooks === 'object' && !Array.isArray(parsed.hooks))
|
|
? parsed.hooks
|
|
: parsed;
|
|
const sessionStart = Array.isArray(table.SessionStart) ? table.SessionStart : [];
|
|
return sessionStart.flatMap((entry) => [
|
|
...(typeof entry?.command === 'string' ? [entry.command] : []),
|
|
...(Array.isArray(entry?.hooks)
|
|
? entry.hooks.map((hook) => hook && hook.command).filter((cmd) => typeof cmd === 'string')
|
|
: []),
|
|
]);
|
|
}
|
|
|
|
test('LF config.toml: stale gsd-update-check block removed on reinstall', (t) => {
|
|
const origCwd = process.cwd();
|
|
t.after(() => { process.chdir(origCwd); });
|
|
process.chdir(tmpDir);
|
|
|
|
writeCodexConfigWithStaleHooks(tmpDir, '\n', '\n');
|
|
install(false, 'codex');
|
|
|
|
const configPath = path.join(tmpDir, '.codex', 'config.toml');
|
|
const content = fs.readFileSync(configPath, 'utf-8');
|
|
|
|
assert.ok(
|
|
!content.includes('gsd-update-check'),
|
|
'Stale gsd-update-check entry must be removed from LF config.toml (#2698)'
|
|
);
|
|
const hooksJsonCommands = readHooksSessionStartCommands(path.join(tmpDir, '.codex'));
|
|
assert.equal(
|
|
hooksJsonCommands.some((cmd) => cmd.includes('gsd-check-update')),
|
|
true,
|
|
'New gsd-check-update hook must appear in hooks.json after reinstall'
|
|
);
|
|
});
|
|
|
|
test('CRLF config.toml: stale gsd-update-check block removed on reinstall', (t) => {
|
|
const origCwd = process.cwd();
|
|
t.after(() => { process.chdir(origCwd); });
|
|
process.chdir(tmpDir);
|
|
|
|
writeCodexConfigWithStaleHooks(tmpDir, '\r\n', '\r\n');
|
|
install(false, 'codex');
|
|
|
|
const configPath = path.join(tmpDir, '.codex', 'config.toml');
|
|
const content = fs.readFileSync(configPath, 'utf-8');
|
|
|
|
assert.ok(
|
|
!content.includes('gsd-update-check'),
|
|
'Stale gsd-update-check entry must be removed from CRLF config.toml (#2698)'
|
|
);
|
|
const hooksJsonCommands = readHooksSessionStartCommands(path.join(tmpDir, '.codex'));
|
|
assert.equal(
|
|
hooksJsonCommands.some((cmd) => cmd.includes('gsd-check-update')),
|
|
true,
|
|
'New gsd-check-update hook must appear in hooks.json after reinstall'
|
|
);
|
|
});
|
|
|
|
test('mixed-EOL config.toml: stale block with LF header but CRLF body removed on reinstall', (t) => {
|
|
// This is the primary failure case: header line uses LF but the body uses CRLF.
|
|
// The old LF-only regex requires all-\n separators; the old CRLF-only regex requires
|
|
// all-\r\n separators. Neither matches a block with mixed endings, so the stale
|
|
// block survives reinstall with the old code (#2698).
|
|
const origCwd = process.cwd();
|
|
t.after(() => { process.chdir(origCwd); });
|
|
process.chdir(tmpDir);
|
|
|
|
// headerEol='\n' (file dominant), bodyEol='\r\n' (hook block from another platform)
|
|
writeCodexConfigWithStaleHooks(tmpDir, '\n', '\r\n');
|
|
install(false, 'codex');
|
|
|
|
const configPath = path.join(tmpDir, '.codex', 'config.toml');
|
|
const content = fs.readFileSync(configPath, 'utf-8');
|
|
|
|
assert.ok(
|
|
!content.includes('gsd-update-check'),
|
|
[
|
|
'Stale gsd-update-check block with mixed LF/CRLF endings must be removed (#2698).',
|
|
'Old code used two separate LF-only and CRLF-only regexes; neither matched mixed content.',
|
|
'Fix consolidates to a single \\r?\\n-aware regex.',
|
|
].join(' ')
|
|
);
|
|
});
|
|
});
|