Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/npm-launcher-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: npm launcher tests

on:
pull_request:
paths:
- 'npm/bin/coven-code'
- 'scripts/npm-launcher.test.mjs'
- '.github/workflows/npm-launcher-tests.yml'
workflow_dispatch:

permissions:
contents: read

jobs:
launcher:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
timeout-minutes: 5
steps:
- uses: actions/checkout@v5
with:
persist-credentials: false
- uses: actions/setup-node@v6
with:
node-version: '24'
package-manager-cache: false
- run: node scripts/npm-launcher.test.mjs
4 changes: 4 additions & 0 deletions npm/bin/coven-code
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ const result = spawnSync(binary, process.argv.slice(2), {
env: process.env,
});

if (result.error) {
console.error(`coven-code: failed to launch native binary: ${result.error.message}`);
}

process.exit(result.status ?? 1);
46 changes: 46 additions & 0 deletions scripts/npm-launcher.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import assert from 'node:assert/strict';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { spawnSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';

const root = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
const fixture = fs.mkdtempSync(path.join(os.tmpdir(), 'coven-launcher-'));
try {
fs.mkdirSync(path.join(fixture, 'bin'));
fs.mkdirSync(path.join(fixture, 'native'));
const launcher = path.join(fixture, 'bin/coven-code');
const binary = path.join(fixture, 'native/coven-code');
fs.copyFileSync(path.join(root, 'npm/bin/coven-code'), launcher);
const run = (...args) => spawnSync(process.execPath, [launcher, ...args], {
encoding: 'utf8', timeout: 5000,
env: { ...process.env, COVEN_LAUNCHER_TEST: 'inherited' },
});

const missing = run();
assert.equal(missing.status, 1);
assert.match(missing.stderr, /native binary not found/);
assert.ok(missing.stderr.includes(binary));

fs.writeFileSync(binary, '#!/bin/sh\nprintf "%s\\n" "$1" "$COVEN_LAUNCHER_TEST"\nexit 7\n', { mode: 0o755 });
const success = run('argument with spaces');
assert.equal(success.status, 7);
assert.equal(success.stdout, 'argument with spaces\ninherited\n');
assert.equal(success.stderr, '');

fs.chmodSync(binary, 0o644);
const denied = run();
assert.equal(denied.status, 1);
assert.match(denied.stderr, /EACCES/);
assert.ok(denied.stderr.includes(binary));

fs.writeFileSync(binary, '#!/nonexistent/coven-test-interpreter\n');
fs.chmodSync(binary, 0o755);
const interpreter = run();
assert.equal(interpreter.status, 1);
assert.match(interpreter.stderr, /ENOENT/);
assert.ok(interpreter.stderr.includes(binary));
} finally {
fs.rmSync(fixture, { recursive: true, force: true });
}
Loading