Compare commits

...

2 Commits

Author SHA1 Message Date
Affaan Mustafa
2e43eac8d9 fix: export codex sync env to child scripts 2026-03-30 02:08:33 -04:00
Affaan Mustafa
f015f3eb75 test: isolate package-manager dependent hooks and formatter tests 2026-03-30 02:08:33 -04:00
4 changed files with 92 additions and 15 deletions

View File

@@ -460,16 +460,28 @@ fi
log "Installing global git safety hooks" log "Installing global git safety hooks"
if [[ "$MODE" == "dry-run" ]]; then if [[ "$MODE" == "dry-run" ]]; then
"$HOOKS_INSTALLER" --dry-run HOME="$HOME" \
CODEX_HOME="$CODEX_HOME" \
AGENTS_HOME="${AGENTS_HOME:-$HOME/.agents}" \
ECC_GLOBAL_HOOKS_DIR="${ECC_GLOBAL_HOOKS_DIR:-$CODEX_HOME/git-hooks}" \
"$HOOKS_INSTALLER" --dry-run
else else
"$HOOKS_INSTALLER" HOME="$HOME" \
CODEX_HOME="$CODEX_HOME" \
AGENTS_HOME="${AGENTS_HOME:-$HOME/.agents}" \
ECC_GLOBAL_HOOKS_DIR="${ECC_GLOBAL_HOOKS_DIR:-$CODEX_HOME/git-hooks}" \
"$HOOKS_INSTALLER"
fi fi
log "Running global regression sanity check" log "Running global regression sanity check"
if [[ "$MODE" == "dry-run" ]]; then if [[ "$MODE" == "dry-run" ]]; then
printf '[dry-run] %s\n' "$SANITY_CHECKER" printf '[dry-run] %s\n' "$SANITY_CHECKER"
else else
"$SANITY_CHECKER" HOME="$HOME" \
CODEX_HOME="$CODEX_HOME" \
AGENTS_HOME="${AGENTS_HOME:-$HOME/.agents}" \
ECC_GLOBAL_HOOKS_DIR="${ECC_GLOBAL_HOOKS_DIR:-$CODEX_HOME/git-hooks}" \
"$SANITY_CHECKER"
fi fi
log "Sync complete" log "Sync complete"

View File

@@ -1221,9 +1221,14 @@ async function runTests() {
fs.writeFileSync(path.join(rootDir, '.prettierrc'), '{}'); fs.writeFileSync(path.join(rootDir, '.prettierrc'), '{}');
fs.writeFileSync(filePath, 'export const value = 1;\n'); fs.writeFileSync(filePath, 'export const value = 1;\n');
createCommandShim(binDir, 'npx', logFile); createCommandShim(binDir, 'npx', logFile);
const isolatedHome = path.join(testDir, 'isolated-home');
fs.mkdirSync(path.join(isolatedHome, '.claude'), { recursive: true });
const stdinJson = JSON.stringify({ tool_input: { file_path: filePath } }); const stdinJson = JSON.stringify({ tool_input: { file_path: filePath } });
const result = await runScript(path.join(scriptsDir, 'post-edit-format.js'), stdinJson, withPrependedPath(binDir)); const result = await runScript(path.join(scriptsDir, 'post-edit-format.js'), stdinJson, withPrependedPath(binDir, {
HOME: isolatedHome,
USERPROFILE: isolatedHome
}));
assert.strictEqual(result.code, 0, 'Should exit 0 for config-only repo'); assert.strictEqual(result.code, 0, 'Should exit 0 for config-only repo');
const logEntries = readCommandLog(logFile); const logEntries = readCommandLog(logFile);

View File

@@ -37,6 +37,33 @@ function cleanupTestDir(testDir) {
fs.rmSync(testDir, { recursive: true, force: true }); fs.rmSync(testDir, { recursive: true, force: true });
} }
function withIsolatedHome(fn) {
const isolatedHome = fs.mkdtempSync(path.join(os.tmpdir(), 'pm-home-'));
const originalHome = process.env.HOME;
const originalUserProfile = process.env.USERPROFILE;
process.env.HOME = isolatedHome;
process.env.USERPROFILE = isolatedHome;
try {
return fn(isolatedHome);
} finally {
if (originalHome !== undefined) {
process.env.HOME = originalHome;
} else {
delete process.env.HOME;
}
if (originalUserProfile !== undefined) {
process.env.USERPROFILE = originalUserProfile;
} else {
delete process.env.USERPROFILE;
}
fs.rmSync(isolatedHome, { recursive: true, force: true });
}
}
// Test suite // Test suite
function runTests() { function runTests() {
console.log('\n=== Testing package-manager.js ===\n'); console.log('\n=== Testing package-manager.js ===\n');
@@ -711,9 +738,11 @@ function runTests() {
const originalEnv = process.env.CLAUDE_PACKAGE_MANAGER; const originalEnv = process.env.CLAUDE_PACKAGE_MANAGER;
try { try {
delete process.env.CLAUDE_PACKAGE_MANAGER; delete process.env.CLAUDE_PACKAGE_MANAGER;
const result = pm.getPackageManager({ projectDir: testDir }); withIsolatedHome(() => {
assert.strictEqual(result.name, 'npm', 'Should default to npm'); const result = pm.getPackageManager({ projectDir: testDir });
assert.strictEqual(result.source, 'default'); assert.strictEqual(result.name, 'npm', 'Should default to npm');
assert.strictEqual(result.source, 'default');
});
} finally { } finally {
if (originalEnv !== undefined) { if (originalEnv !== undefined) {
process.env.CLAUDE_PACKAGE_MANAGER = originalEnv; process.env.CLAUDE_PACKAGE_MANAGER = originalEnv;

View File

@@ -58,6 +58,33 @@ function cleanupTmpDirs() {
tmpDirs.length = 0; tmpDirs.length = 0;
} }
function withIsolatedHome(fn) {
const isolatedHome = fs.mkdtempSync(path.join(os.tmpdir(), 'resolve-fmt-home-'));
const originalHome = process.env.HOME;
const originalUserProfile = process.env.USERPROFILE;
process.env.HOME = isolatedHome;
process.env.USERPROFILE = isolatedHome;
try {
return fn(isolatedHome);
} finally {
if (originalHome !== undefined) {
process.env.HOME = originalHome;
} else {
delete process.env.HOME;
}
if (originalUserProfile !== undefined) {
process.env.USERPROFILE = originalUserProfile;
} else {
delete process.env.USERPROFILE;
}
fs.rmSync(isolatedHome, { recursive: true, force: true });
}
}
function runTests() { function runTests() {
console.log('\n=== Testing resolve-formatter.js ===\n'); console.log('\n=== Testing resolve-formatter.js ===\n');
@@ -168,10 +195,12 @@ function runTests() {
run('resolveFormatterBin: falls back to npx for biome', () => { run('resolveFormatterBin: falls back to npx for biome', () => {
const root = makeTmpDir(); const root = makeTmpDir();
const result = resolveFormatterBin(root, 'biome'); withIsolatedHome(() => {
const expectedBin = process.platform === 'win32' ? 'npx.cmd' : 'npx'; const result = resolveFormatterBin(root, 'biome');
assert.strictEqual(result.bin, expectedBin); const expectedBin = process.platform === 'win32' ? 'npx.cmd' : 'npx';
assert.deepStrictEqual(result.prefix, ['@biomejs/biome']); assert.strictEqual(result.bin, expectedBin);
assert.deepStrictEqual(result.prefix, ['@biomejs/biome']);
});
}); });
run('resolveFormatterBin: uses local prettier binary when available', () => { run('resolveFormatterBin: uses local prettier binary when available', () => {
@@ -188,10 +217,12 @@ function runTests() {
run('resolveFormatterBin: falls back to npx for prettier', () => { run('resolveFormatterBin: falls back to npx for prettier', () => {
const root = makeTmpDir(); const root = makeTmpDir();
const result = resolveFormatterBin(root, 'prettier'); withIsolatedHome(() => {
const expectedBin = process.platform === 'win32' ? 'npx.cmd' : 'npx'; const result = resolveFormatterBin(root, 'prettier');
assert.strictEqual(result.bin, expectedBin); const expectedBin = process.platform === 'win32' ? 'npx.cmd' : 'npx';
assert.deepStrictEqual(result.prefix, ['prettier']); assert.strictEqual(result.bin, expectedBin);
assert.deepStrictEqual(result.prefix, ['prettier']);
});
}); });
run('resolveFormatterBin: returns null for unknown formatter', () => { run('resolveFormatterBin: returns null for unknown formatter', () => {