Three parallel diagnostic agents (G: sdk/install path-sep, H: hook scripts, I: worktree/workspace) characterised the remaining windows-22 failures on23b52f1a. Patches by class: CRLF in test parsers / file-content reads - bug-2136-sh-hook-version: shebang check split('\n') → split(/\r?\n/) - bug-3542-executor-git-stash-prohibition: strip \r from read content (git rewrites stashed text with CRLF on win autocrlf=true checkout) - workspace: BOM-strip + explicit \r strip in parseCommandFile (BOM at byte 0 defeats /^---/ anchor → fmMatch null → fm.name undefined) Windows path-separator / 8.3-shortname normalization - bug-3491-nested-git-worktree: use fs.realpathSync.native to expand %TEMP% RUNNER~1 → runneradmin; normalize sep before path-equality - prune-orphaned-worktrees: normalize \\→/ before substring includes (git emits forward-slash in --porcelain on Windows even when path.join produced backslashes) - bug-3017-codex-hook-absolute-node: accept POSIX path OR path with drive-letter prefix in hookPath equality assertion - bug-3126-global-skills-base-runtime-path: use path.join for expected /xdg/<runtime> values (production calls path.join → \xdg\… on win32) Test under-specified platform / forgot win32 env - bug-2979-hook-absolute-node: pass {platform:'linux'} to buildHookCommand + rewriteLegacyManagedNodeHookCommands so the POSIX-branch tests don't pick up the #3393 GitBash code path - bug-3288-model-catalog + bug-3571-config-manifest: also set USERPROFILE alongside HOME so os.homedir() on win32 redirects to the test fixture instead of the runner's real ~ External-cmd resolution - bug-2647-outer-tarball-sdk-dist: use npm.cmd + {shell:true} on win32 so execFileSync resolves PATHEXT (literal `npm` is ENOENT) ESM loader: tests/runtime-bridge-sync-smoke.test.cjs already migrated to pathToFileURL in23b52f1a(cluster E). Explicit per-test/describe skip on win32 (with required string reasons to satisfy no-unconditional-win32-skip guard) - feat-3347-graphify-auto-update-hook: 3 describes — harness spawns bash/kill/sleep + the hook itself is bash - feat-3595-fs-fault-injection: move \t and \n filenames into the POSIX-only branch (NTFS forbids 0x00–0x1F in filenames) - bug-2775/2829/3033/3231/3359: POSIX shim under ~/.local/bin with chmod 0o755 — not how Windows install works - bug-3211: single subtest where cp.execSync reassignment isn't picked up on win32 (POSIX coverage via the mock; live windows behavior covered by 3211-D which keeps running) - install-path-detection: parses sh-style export PATH= rc files; Windows has no rc files (registry Path) - worktree-safety-policy: single test using POSIX /repo/wt fixture paths that can't be expressed under win32 path.resolve Validated: plex2 (ubuntu docker) 11224/0 pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
320 lines
9.9 KiB
JavaScript
320 lines
9.9 KiB
JavaScript
/**
|
|
* Regression test for #2620 — installer should not suggest adding an absolute
|
|
* PATH export when the user's rc file already contains a HOME-relative entry
|
|
* that covers the same directory.
|
|
*
|
|
* Covers `homePathCoveredByRc(globalBin, homeDir, rcFileNames?)` which parses
|
|
* each rc file's `export PATH=` lines, substitutes `$HOME` / `${HOME}` / `~`,
|
|
* and returns true when any resolved PATH entry equals globalBin.
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const { test, describe, before, after } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('fs');
|
|
const os = require('os');
|
|
const path = require('path');
|
|
|
|
const INSTALL_PATH = path.join(__dirname, '..', 'bin', 'install.js');
|
|
|
|
const isWindows = process.platform === 'win32';
|
|
const PROJECTION_PATH = path.join(
|
|
__dirname,
|
|
'..',
|
|
'get-shit-done',
|
|
'bin',
|
|
'lib',
|
|
'shell-command-projection.cjs',
|
|
);
|
|
|
|
function loadInstaller() {
|
|
process.env.GSD_TEST_MODE = '1';
|
|
delete require.cache[require.resolve(INSTALL_PATH)];
|
|
return require(INSTALL_PATH);
|
|
}
|
|
|
|
function createTempHome() {
|
|
return fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-home-'));
|
|
}
|
|
|
|
function cleanup(dir) {
|
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
}
|
|
|
|
describe('installer HOME-relative PATH detection (#2620)',
|
|
{ skip: isWindows ? 'POSIX-only: parses sh-style "export PATH=" rc files; Windows has no rc files and uses registry Path' : false },
|
|
() => {
|
|
let installer;
|
|
let projection;
|
|
before(() => {
|
|
installer = loadInstaller();
|
|
projection = require(PROJECTION_PATH);
|
|
});
|
|
|
|
test('homePathCoveredByRc is exported', () => {
|
|
assert.strictEqual(
|
|
typeof installer.homePathCoveredByRc,
|
|
'function',
|
|
'bin/install.js must export homePathCoveredByRc for #2620',
|
|
);
|
|
});
|
|
|
|
test('detects $HOME/.npm-global/bin pattern', () => {
|
|
const home = createTempHome();
|
|
try {
|
|
fs.writeFileSync(
|
|
path.join(home, '.zshrc'),
|
|
'export PATH="$HOME/.npm-global/bin:$PATH"\n',
|
|
);
|
|
const globalBin = path.join(home, '.npm-global', 'bin');
|
|
assert.strictEqual(installer.homePathCoveredByRc(globalBin, home), true);
|
|
} finally {
|
|
cleanup(home);
|
|
}
|
|
});
|
|
|
|
test('detects ${HOME}/.npm-global/bin pattern', () => {
|
|
const home = createTempHome();
|
|
try {
|
|
fs.writeFileSync(
|
|
path.join(home, '.bashrc'),
|
|
'export PATH="${HOME}/.npm-global/bin:$PATH"\n',
|
|
);
|
|
const globalBin = path.join(home, '.npm-global', 'bin');
|
|
assert.strictEqual(installer.homePathCoveredByRc(globalBin, home), true);
|
|
} finally {
|
|
cleanup(home);
|
|
}
|
|
});
|
|
|
|
test('detects ~/.npm-global/bin tilde form', () => {
|
|
const home = createTempHome();
|
|
try {
|
|
fs.writeFileSync(
|
|
path.join(home, '.profile'),
|
|
'export PATH=~/.npm-global/bin:$PATH\n',
|
|
);
|
|
const globalBin = path.join(home, '.npm-global', 'bin');
|
|
assert.strictEqual(installer.homePathCoveredByRc(globalBin, home), true);
|
|
} finally {
|
|
cleanup(home);
|
|
}
|
|
});
|
|
|
|
test('detects absolute path that exactly matches globalBin', () => {
|
|
const home = createTempHome();
|
|
try {
|
|
const globalBin = path.join(home, '.npm-global', 'bin');
|
|
fs.writeFileSync(
|
|
path.join(home, '.zshrc'),
|
|
`export PATH="${globalBin}:$PATH"\n`,
|
|
);
|
|
assert.strictEqual(installer.homePathCoveredByRc(globalBin, home), true);
|
|
} finally {
|
|
cleanup(home);
|
|
}
|
|
});
|
|
|
|
test('returns false when rc files exist but do not cover globalBin', () => {
|
|
const home = createTempHome();
|
|
try {
|
|
fs.writeFileSync(
|
|
path.join(home, '.zshrc'),
|
|
'export PATH="$HOME/.cargo/bin:$PATH"\nexport FOO=bar\n',
|
|
);
|
|
const globalBin = path.join(home, '.npm-global', 'bin');
|
|
assert.strictEqual(installer.homePathCoveredByRc(globalBin, home), false);
|
|
} finally {
|
|
cleanup(home);
|
|
}
|
|
});
|
|
|
|
test('returns false when no rc files exist', () => {
|
|
const home = createTempHome();
|
|
try {
|
|
const globalBin = path.join(home, '.npm-global', 'bin');
|
|
assert.strictEqual(installer.homePathCoveredByRc(globalBin, home), false);
|
|
} finally {
|
|
cleanup(home);
|
|
}
|
|
});
|
|
|
|
test('swallows unreadable rc files without throwing', () => {
|
|
const home = createTempHome();
|
|
try {
|
|
const rc = path.join(home, '.zshrc');
|
|
fs.mkdirSync(rc); // directory where a file is expected — reading throws
|
|
const globalBin = path.join(home, '.npm-global', 'bin');
|
|
assert.doesNotThrow(() => installer.homePathCoveredByRc(globalBin, home));
|
|
assert.strictEqual(installer.homePathCoveredByRc(globalBin, home), false);
|
|
} finally {
|
|
cleanup(home);
|
|
}
|
|
});
|
|
|
|
test('ignores commented-out export PATH lines', () => {
|
|
const home = createTempHome();
|
|
try {
|
|
fs.writeFileSync(
|
|
path.join(home, '.zshrc'),
|
|
'# export PATH="$HOME/.npm-global/bin:$PATH"\n',
|
|
);
|
|
const globalBin = path.join(home, '.npm-global', 'bin');
|
|
assert.strictEqual(installer.homePathCoveredByRc(globalBin, home), false);
|
|
} finally {
|
|
cleanup(home);
|
|
}
|
|
});
|
|
|
|
test('matches globalBin regardless of trailing slash', () => {
|
|
const home = createTempHome();
|
|
try {
|
|
fs.writeFileSync(
|
|
path.join(home, '.zshrc'),
|
|
'export PATH="$HOME/.npm-global/bin/:$PATH"\n',
|
|
);
|
|
const globalBin = path.join(home, '.npm-global', 'bin');
|
|
assert.strictEqual(installer.homePathCoveredByRc(globalBin, home), true);
|
|
} finally {
|
|
cleanup(home);
|
|
}
|
|
});
|
|
|
|
// CodeRabbit finding: bare relative PATH segments (e.g. `bin`) must not be
|
|
// resolved against $HOME. Relative segments depend on the shell's cwd at
|
|
// lookup time and are unrelated to $HOME/bin.
|
|
test('does not treat bare relative PATH segment as HOME-relative', () => {
|
|
const home = createTempHome();
|
|
try {
|
|
fs.writeFileSync(
|
|
path.join(home, '.zshrc'),
|
|
'export PATH="bin:$PATH"\n',
|
|
);
|
|
const globalBin = path.join(home, 'bin');
|
|
assert.strictEqual(
|
|
installer.homePathCoveredByRc(globalBin, home),
|
|
false,
|
|
'relative PATH segments must not be resolved against $HOME',
|
|
);
|
|
} finally {
|
|
cleanup(home);
|
|
}
|
|
});
|
|
|
|
test('does not treat nested relative PATH segment as HOME-relative', () => {
|
|
const home = createTempHome();
|
|
try {
|
|
fs.writeFileSync(
|
|
path.join(home, '.zshrc'),
|
|
'export PATH="node_modules/.bin:$PATH"\n',
|
|
);
|
|
const globalBin = path.join(home, 'node_modules', '.bin');
|
|
assert.strictEqual(
|
|
installer.homePathCoveredByRc(globalBin, home),
|
|
false,
|
|
);
|
|
} finally {
|
|
cleanup(home);
|
|
}
|
|
});
|
|
|
|
// CodeRabbit actionable 1 + nitpick: the installer's PATH-export
|
|
// suggestion banner must be suppressed when an rc file already covers
|
|
// globalBin via a HOME-relative entry.
|
|
test('maybeSuggestPathExport suppresses suggestion when rc covers globalBin', () => {
|
|
const home = createTempHome();
|
|
try {
|
|
const globalBin = path.join(home, '.npm-global', 'bin');
|
|
fs.mkdirSync(globalBin, { recursive: true });
|
|
fs.writeFileSync(
|
|
path.join(home, '.zshrc'),
|
|
'export PATH="$HOME/.npm-global/bin:$PATH"\n',
|
|
);
|
|
|
|
const logs = [];
|
|
const origLog = console.log;
|
|
console.log = (...args) => { logs.push(args.join(' ')); };
|
|
try {
|
|
installer.maybeSuggestPathExport(globalBin, home);
|
|
} finally {
|
|
console.log = origLog;
|
|
}
|
|
|
|
const joined = logs.join('\n');
|
|
assert.ok(
|
|
!/echo 'export PATH=/.test(joined),
|
|
`installer should not emit absolute export suggestion; got:\n${joined}`,
|
|
);
|
|
} finally {
|
|
cleanup(home);
|
|
}
|
|
});
|
|
|
|
test('maybeSuggestPathExport emits suggestion when rc does not cover globalBin', () => {
|
|
const home = createTempHome();
|
|
try {
|
|
const globalBin = path.join(home, '.npm-global', 'bin');
|
|
fs.mkdirSync(globalBin, { recursive: true });
|
|
fs.writeFileSync(
|
|
path.join(home, '.zshrc'),
|
|
'export PATH="$HOME/.cargo/bin:$PATH"\n',
|
|
);
|
|
|
|
const logs = [];
|
|
const origLog = console.log;
|
|
console.log = (...args) => { logs.push(args.join(' ')); };
|
|
try {
|
|
installer.maybeSuggestPathExport(globalBin, home);
|
|
} finally {
|
|
console.log = origLog;
|
|
}
|
|
|
|
const joined = logs.join('\n');
|
|
assert.equal(
|
|
typeof projection.projectPersistentPathExportActions,
|
|
'function',
|
|
'shell command projection module must export projectPersistentPathExportActions',
|
|
);
|
|
const projected = projection.projectPersistentPathExportActions({
|
|
targetDir: globalBin,
|
|
platform: process.platform,
|
|
});
|
|
assert.ok(Array.isArray(projected.shellActions), 'projected.shellActions must be an array');
|
|
assert.ok(projected.shellActions.length >= 2, 'expected at least zsh/bash projected actions');
|
|
for (const action of projected.shellActions) {
|
|
assert.ok(
|
|
joined.includes(action.command),
|
|
`installer should render projected command "${action.command}". Output:\n${joined}`,
|
|
);
|
|
}
|
|
} finally {
|
|
cleanup(home);
|
|
}
|
|
});
|
|
|
|
test('maybeSuggestPathExport is a no-op when globalBin already on process.env.PATH', () => {
|
|
const home = createTempHome();
|
|
const origPath = process.env.PATH;
|
|
try {
|
|
const globalBin = path.join(home, '.npm-global', 'bin');
|
|
fs.mkdirSync(globalBin, { recursive: true });
|
|
process.env.PATH = `${globalBin}${path.delimiter}${origPath || ''}`;
|
|
|
|
const logs = [];
|
|
const origLog = console.log;
|
|
console.log = (...args) => { logs.push(args.join(' ')); };
|
|
try {
|
|
installer.maybeSuggestPathExport(globalBin, home);
|
|
} finally {
|
|
console.log = origLog;
|
|
}
|
|
|
|
assert.strictEqual(logs.length, 0, `expected no output when on PATH; got:\n${logs.join('\n')}`);
|
|
} finally {
|
|
if (origPath === undefined) delete process.env.PATH; else process.env.PATH = origPath;
|
|
cleanup(home);
|
|
}
|
|
});
|
|
});
|