mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-05 00:33:27 +08:00
fix: normalize hook command execution in integration tests
This commit is contained in:
@@ -101,16 +101,28 @@ function runHookCommand(command, input = {}, env = {}, timeoutMs = 10000) {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const isWindows = process.platform === 'win32';
|
const isWindows = process.platform === 'win32';
|
||||||
const mergedEnv = { ...process.env, CLAUDE_PLUGIN_ROOT: REPO_ROOT, ...env };
|
const mergedEnv = { ...process.env, CLAUDE_PLUGIN_ROOT: REPO_ROOT, ...env };
|
||||||
const resolvedCommand = isWindows
|
const resolvedCommand = command.replace(
|
||||||
? command.replace(/\$\{([A-Z_][A-Z0-9_]*)\}/g, (_, name) => String(mergedEnv[name] || ''))
|
/\$\{([A-Z_][A-Z0-9_]*)\}/g,
|
||||||
: command;
|
(_, name) => String(mergedEnv[name] || '')
|
||||||
|
);
|
||||||
|
|
||||||
|
const nodeMatch = resolvedCommand.match(/^node\s+"([^"]+)"\s*(.*)$/);
|
||||||
|
const useDirectNodeSpawn = Boolean(nodeMatch);
|
||||||
const shell = isWindows ? 'cmd' : 'bash';
|
const shell = isWindows ? 'cmd' : 'bash';
|
||||||
const shellArgs = isWindows ? ['/d', '/s', '/c', resolvedCommand] : ['-lc', resolvedCommand];
|
const shellArgs = isWindows ? ['/d', '/s', '/c', resolvedCommand] : ['-lc', resolvedCommand];
|
||||||
|
const nodeArgs = nodeMatch
|
||||||
|
? [
|
||||||
|
nodeMatch[1],
|
||||||
|
...Array.from(
|
||||||
|
nodeMatch[2].matchAll(/"([^"]*)"|(\S+)/g),
|
||||||
|
m => m[1] !== undefined ? m[1] : m[2]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
: [];
|
||||||
|
|
||||||
const proc = spawn(shell, shellArgs, {
|
const proc = useDirectNodeSpawn
|
||||||
env: mergedEnv,
|
? spawn('node', nodeArgs, { env: mergedEnv, stdio: ['pipe', 'pipe', 'pipe'] })
|
||||||
stdio: ['pipe', 'pipe', 'pipe']
|
: spawn(shell, shellArgs, { env: mergedEnv, stdio: ['pipe', 'pipe', 'pipe'] });
|
||||||
});
|
|
||||||
|
|
||||||
let stdout = '';
|
let stdout = '';
|
||||||
let stderr = '';
|
let stderr = '';
|
||||||
|
|||||||
Reference in New Issue
Block a user