mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-12 12:43:32 +08:00
test: fix windows path shims for formatter hooks
This commit is contained in:
committed by
Affaan Mustafa
parent
d66bd6439b
commit
1c5e07ff77
@@ -104,6 +104,19 @@ function readCommandLog(logFile) {
|
|||||||
.map(line => JSON.parse(line));
|
.map(line => JSON.parse(line));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function withPrependedPath(binDir, env = {}) {
|
||||||
|
const pathKey = Object.keys(process.env).find(key => key.toLowerCase() === 'path')
|
||||||
|
|| (process.platform === 'win32' ? 'Path' : 'PATH');
|
||||||
|
const currentPath = process.env[pathKey] || process.env.PATH || '';
|
||||||
|
const nextPath = `${binDir}${path.delimiter}${currentPath}`;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...env,
|
||||||
|
[pathKey]: nextPath,
|
||||||
|
PATH: nextPath
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Test suite
|
// Test suite
|
||||||
async function runTests() {
|
async function runTests() {
|
||||||
console.log('\n=== Testing Hook Scripts ===\n');
|
console.log('\n=== Testing Hook Scripts ===\n');
|
||||||
@@ -744,9 +757,11 @@ async function runTests() {
|
|||||||
createCommandShim(binDir, 'npx', logFile);
|
createCommandShim(binDir, 'npx', logFile);
|
||||||
|
|
||||||
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, {
|
const result = await runScript(
|
||||||
PATH: `${binDir}${path.delimiter}${process.env.PATH || ''}`
|
path.join(scriptsDir, 'post-edit-format.js'),
|
||||||
});
|
stdinJson,
|
||||||
|
withPrependedPath(binDir)
|
||||||
|
);
|
||||||
|
|
||||||
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);
|
||||||
@@ -777,10 +792,11 @@ async function runTests() {
|
|||||||
createCommandShim(binDir, 'pnpm', logFile);
|
createCommandShim(binDir, 'pnpm', logFile);
|
||||||
|
|
||||||
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, {
|
const result = await runScript(
|
||||||
PATH: `${binDir}${path.delimiter}${process.env.PATH || ''}`,
|
path.join(scriptsDir, 'post-edit-format.js'),
|
||||||
CLAUDE_PACKAGE_MANAGER: 'pnpm'
|
stdinJson,
|
||||||
});
|
withPrependedPath(binDir, { CLAUDE_PACKAGE_MANAGER: 'pnpm' })
|
||||||
|
);
|
||||||
|
|
||||||
assert.strictEqual(result.code, 0, 'Should exit 0 when pnpm fallback is used');
|
assert.strictEqual(result.code, 0, 'Should exit 0 when pnpm fallback is used');
|
||||||
const logEntries = readCommandLog(logFile);
|
const logEntries = readCommandLog(logFile);
|
||||||
@@ -808,9 +824,11 @@ async function runTests() {
|
|||||||
createCommandShim(binDir, 'bunx', logFile);
|
createCommandShim(binDir, 'bunx', logFile);
|
||||||
|
|
||||||
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, {
|
const result = await runScript(
|
||||||
PATH: `${binDir}${path.delimiter}${process.env.PATH || ''}`
|
path.join(scriptsDir, 'post-edit-format.js'),
|
||||||
});
|
stdinJson,
|
||||||
|
withPrependedPath(binDir)
|
||||||
|
);
|
||||||
|
|
||||||
assert.strictEqual(result.code, 0, 'Should exit 0 when project config selects bun');
|
assert.strictEqual(result.code, 0, 'Should exit 0 when project config selects bun');
|
||||||
const logEntries = readCommandLog(logFile);
|
const logEntries = readCommandLog(logFile);
|
||||||
|
|||||||
Reference in New Issue
Block a user