* test: add Windows npm global install CI test (reproduces #262) This test packs the package and installs it globally with npm, then runs agent-browser --version. This reproduces the issue where npm-generated shims on Windows try to invoke /bin/sh which doesn't exist. The bin/agent-browser.js wrapper is added but not yet wired up, so this commit should fail CI to confirm the issue. * fix: Windows npm global install and npx support The shell script wrapper (bin/agent-browser) with #!/bin/sh shebang causes npm to generate Windows shims that try to invoke /bin/sh, which doesn't exist on Windows. This fix uses a hybrid approach: 1. Node.js wrapper (bin/agent-browser.js) as bin entry - Makes npx work on all platforms - ~100ms overhead (acceptable since npx has its own overhead) 2. postinstall patches bin entries for global installs - Windows: Overwrites .cmd/.ps1 shims to invoke .exe directly - Mac/Linux: Replaces symlink to point to native binary - Zero overhead for `npm i -g agent-browser` users on all platforms Also fixes PowerShell glob expansion in CI test. Fixes #262 * fix: Windows npm global install and npx support The shell script wrapper (bin/agent-browser) with #!/bin/sh shebang causes npm to generate Windows shims that try to invoke /bin/sh, which doesn't exist on Windows. This fix uses a hybrid approach: 1. Node.js wrapper (bin/agent-browser.js) as bin entry - Makes npx work on all platforms - ~100ms overhead (acceptable since npx has its own overhead) 2. postinstall patches bin entries for global installs - Windows: Overwrites .cmd/.ps1 shims to invoke .exe directly - Mac/Linux: Replaces symlink to point to native binary - Zero overhead for `npm i -g agent-browser` users on all platforms Also adds cross-platform CI tests for npm global install to catch regressions on all platforms (Ubuntu, macOS, Windows). Fixes #262 * test global install * remove dead code
This commit is contained in:
+103
-5
@@ -138,11 +138,6 @@ jobs:
|
||||
run: |
|
||||
Copy-Item cli/target/x86_64-pc-windows-msvc/release/agent-browser.exe bin/agent-browser-win32-x64.exe
|
||||
|
||||
- name: Test CMD wrapper works
|
||||
run: |
|
||||
bin\agent-browser.cmd --version
|
||||
shell: cmd
|
||||
|
||||
- name: Test agent-browser install command
|
||||
run: |
|
||||
$env:PATH = "$pwd\bin;$env:PATH"
|
||||
@@ -198,3 +193,106 @@ jobs:
|
||||
|
||||
- name: Run serverless integration test
|
||||
run: pnpm exec vitest run test/serverless.test.ts
|
||||
|
||||
global-install:
|
||||
name: Global Install (${{ matrix.os }})
|
||||
runs-on: ${{ matrix.os }}
|
||||
needs: rust
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
target: x86_64-unknown-linux-gnu
|
||||
binary: agent-browser-linux-x64
|
||||
- os: macos-latest
|
||||
target: aarch64-apple-darwin
|
||||
binary: agent-browser-darwin-arm64
|
||||
- os: windows-latest
|
||||
target: x86_64-pc-windows-msvc
|
||||
binary: agent-browser-win32-x64.exe
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup pnpm
|
||||
uses: pnpm/action-setup@v4
|
||||
with:
|
||||
version: 9
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
cache: pnpm
|
||||
|
||||
- name: Setup Rust toolchain
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
targets: ${{ matrix.target }}
|
||||
|
||||
- name: Cache Cargo dependencies
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/bin/
|
||||
~/.cargo/registry/index/
|
||||
~/.cargo/registry/cache/
|
||||
~/.cargo/git/db/
|
||||
cli/target/
|
||||
key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('cli/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cargo-${{ matrix.target }}-
|
||||
|
||||
- name: Build Rust CLI
|
||||
run: cargo build --release --manifest-path cli/Cargo.toml --target ${{ matrix.target }}
|
||||
|
||||
- name: Install npm dependencies
|
||||
run: pnpm install
|
||||
|
||||
- name: Build TypeScript
|
||||
run: pnpm build
|
||||
|
||||
- name: Copy CLI binary to bin directory (Unix)
|
||||
if: runner.os != 'Windows'
|
||||
run: cp cli/target/${{ matrix.target }}/release/agent-browser bin/${{ matrix.binary }}
|
||||
|
||||
- name: Copy CLI binary to bin directory (Windows)
|
||||
if: runner.os == 'Windows'
|
||||
run: Copy-Item cli/target/${{ matrix.target }}/release/agent-browser.exe bin/${{ matrix.binary }}
|
||||
|
||||
- name: Test npm global install
|
||||
run: |
|
||||
npm pack
|
||||
npm install -g agent-browser-*.tgz
|
||||
agent-browser --version
|
||||
shell: bash
|
||||
|
||||
- name: Verify symlink points to native binary (Unix)
|
||||
if: runner.os != 'Windows'
|
||||
run: |
|
||||
SYMLINK=$(npm prefix -g)/bin/agent-browser
|
||||
TARGET=$(readlink "$SYMLINK")
|
||||
echo "Symlink: $SYMLINK"
|
||||
echo "Target: $TARGET"
|
||||
if [[ "$TARGET" != *"${{ matrix.binary }}"* ]]; then
|
||||
echo "ERROR: Symlink should point to native binary, not JS wrapper"
|
||||
exit 1
|
||||
fi
|
||||
echo "✓ Symlink correctly points to native binary"
|
||||
shell: bash
|
||||
|
||||
- name: Verify shim points to native binary (Windows)
|
||||
if: runner.os == 'Windows'
|
||||
run: |
|
||||
$shimPath = "$(npm prefix -g)\agent-browser.cmd"
|
||||
$content = Get-Content $shimPath -Raw
|
||||
echo "Shim path: $shimPath"
|
||||
echo "Shim content:"
|
||||
echo $content
|
||||
if ($content -notmatch "agent-browser-win32-x64\.exe") {
|
||||
echo "ERROR: Shim should point to native .exe, not JS wrapper"
|
||||
exit 1
|
||||
}
|
||||
echo "✓ Shim correctly points to native binary"
|
||||
shell: pwsh
|
||||
|
||||
Reference in New Issue
Block a user