Skip to content

Commit d92e843

Browse files
igorcostaAutohand Evolve
andcommitted
fix: properly find Node.js on GitHub Actions CI
The previous fix was returning paths from 'which node' that don't actually exist on GitHub Actions. Node.js is installed in /opt/hostedtoolcache/node/ on CI, not /usr/local/bin/. Changes: - Verify paths exist with existsSync before returning them - Add GitHub Actions tool cache path to candidates - Try 'which node' first but verify the path works - Only return paths that pass both existsSync and --version checks Co-authored-by: Autohand Evolve <code-noreply@autohand.ai>
1 parent 68dd8c7 commit d92e843

1 file changed

Lines changed: 25 additions & 17 deletions

File tree

tests/browser/chrome.spec.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,38 +32,46 @@ const tempRoots: string[] = [];
3232
*/
3333
async function findNodePath(): Promise<string | null> {
3434
const { spawnSync } = await import('node:child_process');
35+
const { existsSync } = await import('node:fs');
3536

3637
// Check if current process is Node.js (not Bun)
3738
const execBase = path.basename(process.execPath).toLowerCase();
3839
if (!execBase.includes('bun') && !execBase.includes('autohand')) {
3940
return process.execPath;
4041
}
4142

42-
// Try common Node.js locations
43+
// Try 'which node' or 'where node' first (most reliable)
44+
const command = process.platform === 'win32' ? 'where' : 'which';
45+
const whichResult = spawnSync(command, ['node'], { stdio: 'pipe' });
46+
if (whichResult.status === 0) {
47+
const found = whichResult.stdout?.toString().trim().split('\n')[0];
48+
if (found && existsSync(found)) {
49+
// Verify it actually works
50+
const result = spawnSync(found, ['--version'], { stdio: 'pipe' });
51+
if (result.status === 0) return found;
52+
}
53+
}
54+
55+
// Try common Node.js locations (including GitHub Actions tool cache)
4356
const candidates = [
44-
'/opt/homebrew/bin/node',
45-
'/usr/local/bin/node',
46-
'/usr/bin/node',
57+
'/opt/hostedtoolcache/node/current/bin/node', // GitHub Actions
58+
'/opt/homebrew/bin/node', // macOS Homebrew
59+
'/usr/local/bin/node', // Common Linux/macOS
60+
'/usr/bin/node', // Linux
4761
path.join(os.homedir(), '.local/bin/node'),
4862
];
4963

5064
for (const candidate of candidates) {
51-
try {
52-
const result = spawnSync(candidate, ['--version'], { stdio: 'pipe' });
53-
if (result.status === 0) return candidate;
54-
} catch {
55-
// continue
65+
if (existsSync(candidate)) {
66+
try {
67+
const result = spawnSync(candidate, ['--version'], { stdio: 'pipe' });
68+
if (result.status === 0) return candidate;
69+
} catch {
70+
// continue
71+
}
5672
}
5773
}
5874

59-
// Try 'which node' or 'where node'
60-
const command = process.platform === 'win32' ? 'where' : 'which';
61-
const result = spawnSync(command, ['node'], { stdio: 'pipe' });
62-
if (result.status === 0) {
63-
const found = result.stdout?.toString().trim().split('\n')[0];
64-
if (found) return found;
65-
}
66-
6775
return null;
6876
}
6977

0 commit comments

Comments
 (0)