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"
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
"$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
log "Running global regression sanity check"
if [[ "$MODE" == "dry-run" ]]; then
printf '[dry-run] %s\n' "$SANITY_CHECKER"
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
log "Sync complete"

View File

@@ -1221,9 +1221,14 @@ async function runTests() {
fs.writeFileSync(path.join(rootDir, '.prettierrc'), '{}');
fs.writeFileSync(filePath, 'export const value = 1;\n');
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 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');
const logEntries = readCommandLog(logFile);

View File

@@ -37,6 +37,33 @@ function cleanupTestDir(testDir) {
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
function runTests() {
console.log('\n=== Testing package-manager.js ===\n');
@@ -711,9 +738,11 @@ function runTests() {
const originalEnv = process.env.CLAUDE_PACKAGE_MANAGER;
try {
delete process.env.CLAUDE_PACKAGE_MANAGER;
const result = pm.getPackageManager({ projectDir: testDir });
assert.strictEqual(result.name, 'npm', 'Should default to npm');
assert.strictEqual(result.source, 'default');
withIsolatedHome(() => {
const result = pm.getPackageManager({ projectDir: testDir });
assert.strictEqual(result.name, 'npm', 'Should default to npm');
assert.strictEqual(result.source, 'default');
});
} finally {
if (originalEnv !== undefined) {
process.env.CLAUDE_PACKAGE_MANAGER = originalEnv;

View File

@@ -58,6 +58,33 @@ function cleanupTmpDirs() {
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() {
console.log('\n=== Testing resolve-formatter.js ===\n');
@@ -168,10 +195,12 @@ function runTests() {
run('resolveFormatterBin: falls back to npx for biome', () => {
const root = makeTmpDir();
const result = resolveFormatterBin(root, 'biome');
const expectedBin = process.platform === 'win32' ? 'npx.cmd' : 'npx';
assert.strictEqual(result.bin, expectedBin);
assert.deepStrictEqual(result.prefix, ['@biomejs/biome']);
withIsolatedHome(() => {
const result = resolveFormatterBin(root, 'biome');
const expectedBin = process.platform === 'win32' ? 'npx.cmd' : 'npx';
assert.strictEqual(result.bin, expectedBin);
assert.deepStrictEqual(result.prefix, ['@biomejs/biome']);
});
});
run('resolveFormatterBin: uses local prettier binary when available', () => {
@@ -188,10 +217,12 @@ function runTests() {
run('resolveFormatterBin: falls back to npx for prettier', () => {
const root = makeTmpDir();
const result = resolveFormatterBin(root, 'prettier');
const expectedBin = process.platform === 'win32' ? 'npx.cmd' : 'npx';
assert.strictEqual(result.bin, expectedBin);
assert.deepStrictEqual(result.prefix, ['prettier']);
withIsolatedHome(() => {
const result = resolveFormatterBin(root, 'prettier');
const expectedBin = process.platform === 'win32' ? 'npx.cmd' : 'npx';
assert.strictEqual(result.bin, expectedBin);
assert.deepStrictEqual(result.prefix, ['prettier']);
});
});
run('resolveFormatterBin: returns null for unknown formatter', () => {