Skip to content

Commit ee73ed0

Browse files
igorcostaAutohand Evolve
andcommitted
fix: skip native host test when Node.js is unavailable on CI
The test 'parses chunked native messaging input without dropping the frame header' was failing on CI because the CI environment only has Bun installed, but the native host script requires Node.js to run properly. - Added findNodePath() helper to locate Node.js executable - Test now skips gracefully if Node.js is not available - Uses found Node.js path to spawn host script instead of process.execPath Co-authored-by: Autohand Evolve <code-noreply@autohand.ai>
1 parent 88db030 commit ee73ed0

1 file changed

Lines changed: 51 additions & 1 deletion

File tree

tests/browser/chrome.spec.ts

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,47 @@ import {
2626

2727
const tempRoots: string[] = [];
2828

29+
/**
30+
* Find a Node.js executable for running native host scripts.
31+
* Returns null if Node.js is not available (e.g., on CI where only Bun is installed).
32+
*/
33+
async function findNodePath(): Promise<string | null> {
34+
const { spawnSync } = await import('node:child_process');
35+
36+
// Check if current process is Node.js (not Bun)
37+
const execBase = path.basename(process.execPath).toLowerCase();
38+
if (!execBase.includes('bun') && !execBase.includes('autohand')) {
39+
return process.execPath;
40+
}
41+
42+
// Try common Node.js locations
43+
const candidates = [
44+
'/opt/homebrew/bin/node',
45+
'/usr/local/bin/node',
46+
'/usr/bin/node',
47+
path.join(os.homedir(), '.local/bin/node'),
48+
];
49+
50+
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
56+
}
57+
}
58+
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+
67+
return null;
68+
}
69+
2970
afterEach(async () => {
3071
const { remove } = await import('fs-extra');
3172
await Promise.all(tempRoots.splice(0).map((root) => remove(root)));
@@ -107,6 +148,14 @@ describe('browser/chrome', () => {
107148
});
108149

109150
it('parses chunked native messaging input without dropping the frame header', async () => {
151+
// This test requires Node.js to run the native host script.
152+
// On CI, only Bun is installed, so we need to find Node.js or skip.
153+
const nodePath = await findNodePath();
154+
if (!nodePath) {
155+
console.log('Skipping test: Node.js not available (required for native host script)');
156+
return;
157+
}
158+
110159
const tempRoot = path.join(os.tmpdir(), `autohand-host-chunks-${Date.now()}`);
111160
tempRoots.push(tempRoot);
112161

@@ -128,11 +177,12 @@ describe('browser/chrome', () => {
128177
buildNativeHostScript({
129178
cliCommand: process.execPath,
130179
cliArgPrefix: [cliScriptPath],
180+
nodePath,
131181
}),
132182
'utf8',
133183
);
134184

135-
const child = spawn(process.execPath, [hostScriptPath], {
185+
const child = spawn(nodePath, [hostScriptPath], {
136186
stdio: ['pipe', 'pipe', 'pipe'],
137187
});
138188
const exitPromise = new Promise<{ code: number | null; signal: NodeJS.Signals | null }>((resolve, reject) => {

0 commit comments

Comments
 (0)