Spaces:
Paused
Paused
icebear icebear0828 commited on
fix: macOS Electron login error -86 (EBADARCH) due to wrong-arch curl binary (#96) (#98)
Browse filesCI built both arm64/x64 DMGs on a single arm64 runner, bundling only
the arm64 curl-impersonate into both. Intel Mac users got EBADARCH when
spawning the binary during OAuth token exchange.
- Split macOS CI into per-arch jobs with --arch flag for setup-curl.ts
- Add --arch override to setup-curl.ts for cross-compilation
- Improve spawn error message to diagnose architecture mismatch
Co-authored-by: icebear0828 <icebear0828@users.noreply.github.com>
Files changed (6)
24 unmodified lines2526272829303116 unmodified lines484950515253546 unmodified lines616263646566676824 unmodified linesartifact: windows- os: macos-latestplatform: macartifact: macos- os: ubuntu-latestplatform: linuxartifact: linux16 unmodified linesrun: npm ci --ignore-scripts- name: Setup curl-impersonaterun: npx tsx scripts/setup-curl.tsenv:GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}6 unmodified lines- name: Build apprun: npm run app:build- name: Pack (${{ matrix.platform }})run: npx electron-builder --config electron-builder.yml --${{ matrix.platform }} --publish never- name: Upload artifactsuses: actions/upload-artifact@v424 unmodified lines25262728293031323334353616 unmodified lines535455565758596 unmodified lines666768697071727324 unmodified linesartifact: windows- os: macos-latestplatform: macarch: arm64artifact: macos-arm64- os: macos-latestplatform: macarch: x64artifact: macos-x64- os: ubuntu-latestplatform: linuxartifact: linux16 unmodified linesrun: npm ci --ignore-scripts- name: Setup curl-impersonaterun: npx tsx scripts/setup-curl.ts ${{ matrix.arch && format('--arch {0}', matrix.arch) || '' }}env:GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}6 unmodified lines- name: Build apprun: npm run app:build- name: Pack (${{ matrix.platform }}${{ matrix.arch && format('-{0}', matrix.arch) || '' }})run: npx electron-builder --config electron-builder.yml --${{ matrix.platform }} ${{ matrix.arch && format('--{0}', matrix.arch) || '' }} --publish never- name: Upload artifactsuses: actions/upload-artifact@v4
7 unmodified lines89101112137 unmodified lines### Fixed- 默认关闭 desktop context 注入:之前每次请求注入 ~1500 token 的 Codex Desktop 系统提示,导致 prompt_tokens 虚高;新增 `model.inject_desktop_context` 配置项(默认 `false`),需要时可手动开启 (#95)### Added7 unmodified lines8910111213147 unmodified lines### Fixed- macOS Electron 桌面版登录报 `spawn Unknown system error -86`:CI 在 arm64 runner 上同时构建 arm64/x64 DMG,但只下载 arm64 的 curl-impersonate,导致 Intel Mac 用户 spawn 失败(EBADARCH);拆分为 per-arch 构建 + `setup-curl.ts` 支持 `--arch` 交叉下载;错误提示改为明确的架构不匹配诊断 (#96)- 默认关闭 desktop context 注入:之前每次请求注入 ~1500 token 的 Codex Desktop 系统提示,导致 prompt_tokens 虚高;新增 `model.inject_desktop_context` 配置项(默认 `false`),需要时可手动开启 (#95)### Added
26 unmodified lines272829303132333435191 unmodified lines22722822923023123223326 unmodified linesdestName: string;}function getPlatformInfo(version: string): PlatformInfo {const platform = process.platform;const arch = process.arch;if (platform === "linux") {const archStr = arch === "arm64" ? "aarch64-linux-gnu" : "x86_64-linux-gnu";191 unmodified lines// Resolve latest version from GitHubconst version = await getLatestVersion();console.log(`[setup] curl-impersonate setup (${version})`);console.log(`[setup] Platform: ${process.platform}-${process.arch}`);const info = getPlatformInfo(version);const isWindowsDll = process.platform === "win32";26 unmodified lines272829303132333435363738394041424344191 unmodified lines23623723823924024124224326 unmodified linesdestName: string;}/** Parse --arch flag from CLI args to override process.arch (for cross-compilation). */function getTargetArch(): string {const idx = process.argv.indexOf("--arch");if (idx !== -1 && process.argv[idx + 1]) {return process.argv[idx + 1];}return process.arch;}function getPlatformInfo(version: string): PlatformInfo {const platform = process.platform;const arch = getTargetArch();if (platform === "linux") {const archStr = arch === "arm64" ? "aarch64-linux-gnu" : "x86_64-linux-gnu";191 unmodified lines// Resolve latest version from GitHubconst version = await getLatestVersion();console.log(`[setup] curl-impersonate setup (${version})`);const targetArch = getTargetArch();console.log(`[setup] Platform: ${process.platform}-${targetArch}${targetArch !== process.arch ? ` (cross: host=${process.arch})` : ""}`);const info = getPlatformInfo(version);const isWindowsDll = process.platform === "win32";
12345678910111213141516171819202122232425262728293031323334import { describe, it, expect, vi } from "vitest";
vi.mock("../curl-binary.js", () => ({ resolveCurlBinary: () => "/mock/bin/curl-impersonate", getChromeTlsArgs: () => [], getProxyArgs: () => [], isImpersonate: () => true,}));
import { formatSpawnError } from "../curl-cli-transport.js";
describe("formatSpawnError", () => { it("returns architecture mismatch hint for errno -86 (EBADARCH)", () => { const err = Object.assign(new Error("spawn Unknown system error -86"), { errno: -86 }); const msg = formatSpawnError(err); expect(msg).toContain("wrong CPU architecture"); expect(msg).toContain(process.arch); expect(msg).toContain("npm run setup"); expect(msg).toContain("/mock/bin/curl-impersonate"); });
it("detects -86 from error message when errno is not set", () => { const err = new Error("spawn Unknown system error -86"); const msg = formatSpawnError(err); expect(msg).toContain("wrong CPU architecture"); });
it("returns generic message for other spawn errors", () => { const err = new Error("spawn ENOENT"); const msg = formatSpawnError(err); expect(msg).toBe("curl spawn error: spawn ENOENT"); expect(msg).not.toContain("architecture"); });});123456789101112131415161718192021222324252627282930import { describe, it, expect } from "vitest";import { execFileSync } from "child_process";import { resolve } from "path";
const SETUP_SCRIPT = resolve(__dirname, "../../../scripts/setup-curl.ts");
describe("setup-curl --arch flag", () => { it("uses --arch override in platform line", () => { const output = execFileSync( "npx", ["tsx", SETUP_SCRIPT, "--check", "--arch", "x64"], { encoding: "utf-8", timeout: 30_000 }, ); // Should report x64 as target, with cross-compilation note if host differs expect(output).toContain(`${process.platform}-x64`); if (process.arch !== "x64") { expect(output).toContain(`cross: host=${process.arch}`); } });
it("defaults to host arch without --arch flag", () => { const output = execFileSync( "npx", ["tsx", SETUP_SCRIPT, "--check"], { encoding: "utf-8", timeout: 30_000 }, ); expect(output).toContain(`${process.platform}-${process.arch}`); expect(output).not.toContain("cross:"); });});159 unmodified lines16016116216316416516661 unmodified lines2282292302312322333 unmodified lines237238239240241242243159 unmodified linesif (signal) {signal.removeEventListener("abort", onAbort);}reject(new Error(`curl spawn error: ${err.message}`));});});}61 unmodified lines}}/** Execute curl via execFile and parse the status code from the output. */function execCurl(args: string[]): Promise<{ status: number; body: string }> {return new Promise((resolve, reject) => {3 unmodified lines{ maxBuffer: 2 * 1024 * 1024 },(err, stdout, stderr) => {if (err) {reject(new Error(`curl failed: ${err.message} ${stderr}`));return;}159 unmodified lines16016116216316416516661 unmodified lines2282292302312322332342352362372382392402412422432442452462472482492502513 unmodified lines255256257258259260261262263264265266267159 unmodified linesif (signal) {signal.removeEventListener("abort", onAbort);}reject(new Error(formatSpawnError(err)));});});}61 unmodified lines}}/*** Format a spawn error with architecture hint for EBADARCH (-86) on macOS.* This commonly happens when curl-impersonate binary doesn't match the CPU arch.*/export function formatSpawnError(err: Error & { errno?: number; code?: string }): string {// errno -86 = EBADARCH (Bad CPU type in executable) on macOSif (err.errno === -86 || err.message.includes("-86")) {const binary = resolveCurlBinary();return (`curl-impersonate binary has wrong CPU architecture for this system. ` +`Binary: ${binary}, Host arch: ${process.arch}. ` +`Fix: run "npm run setup -- --force" to download the correct binary, ` +`or delete bin/curl-impersonate to fall back to system curl.`);}return `curl spawn error: ${err.message}`;}/** Execute curl via execFile and parse the status code from the output. */function execCurl(args: string[]): Promise<{ status: number; body: string }> {return new Promise((resolve, reject) => {3 unmodified lines{ maxBuffer: 2 * 1024 * 1024 },(err, stdout, stderr) => {if (err) {const castErr = err as Error & { errno?: number };// Check for EBADARCH first (architecture mismatch)if (castErr.errno === -86 || err.message.includes("-86")) {reject(new Error(formatSpawnError(castErr)));} else {reject(new Error(`curl failed: ${err.message} ${stderr}`));}return;}
.github/workflows/release.yml+9-4
CHANGELOG.md+1
scripts/setup-curl.ts+12-2
src/tls/__tests__/curl-cli-transport.test.tsAdded+34
src/tls/__tests__/setup-curl-arch.test.tsAdded+30
src/tls/curl-cli-transport.ts+26-2