Skip to content
Open
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
62 changes: 62 additions & 0 deletions .github/workflows/test-electron.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Test Electron Launch

on:
push:
branches: [master]
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: |
package-lock.json
web/package-lock.json
native/package-lock.json

- name: Install dependencies
run: |
npm ci --ignore-scripts
cd web && npm ci

- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Install native addon dependencies
working-directory: native
run: npm ci

- name: Build native addon
working-directory: native
run: npm run build

- name: Build web + tsc
run: npm run build

- name: Install Playwright browsers
run: npx playwright install --with-deps chromium

- name: Bundle Electron
working-directory: packages/electron
run: node electron/build.mjs

- name: Prepare pack (copy resources)
working-directory: packages/electron
run: node electron/prepare-pack.mjs

- name: Test electron-builder
working-directory: packages/electron
run: npx electron-builder --config electron-builder.yml --linux --dir --publish never

- name: Run Playwright smoke test
run: xvfb-run -a npx vitest run packages/electron/__tests__/launch.test.ts
env:
CI: true
73 changes: 69 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions packages/electron/__tests__/launch.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import { _electron as electron, ElectronApplication } from 'playwright';
import path from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const rootDir = path.resolve(__dirname, '..');

describe.runIf(process.env.CI || process.env.RUN_E2E_SMOKE)('Electron Launch Smoke Test', () => {
let app: ElectronApplication;

beforeAll(async () => {
// We pass an empty string to use the built executable
let executablePath = '';
if (process.platform === 'win32') {
executablePath = path.join(rootDir, 'release', 'win-unpacked', 'Codex Proxy.exe');
} else if (process.platform === 'darwin') {
executablePath = path.join(rootDir, 'release', 'mac', 'Codex Proxy.app', 'Contents', 'MacOS', 'Codex Proxy');
} else {
executablePath = path.join(rootDir, 'release', 'linux-unpacked', '@codex-proxyelectron');
}

// We need to bypass native transport errors by either disabling or supplying curl-cli in local.yaml
const userDataDir = path.join(rootDir, 'release', '.test-user-data');

app = await electron.launch({
executablePath,
args: [
'--no-sandbox',
'--disable-gpu',
'--disable-dev-shm-usage',
`--user-data-dir=${userDataDir}`,
],
env: {
...process.env,
NODE_ENV: 'test',
DISABLE_NATIVE_TRANSPORT: '1',
ELECTRON_ENABLE_LOGGING: '1', // Important for seeing errors
},
});

app.process().stdout?.on('data', (data) => console.log(`stdout: ${data.toString()}`));
app.process().stderr?.on('data', (data) => console.error(`stderr: ${data.toString()}`));
}, 60000); // Allow time to launch

afterAll(async () => {
if (app) {
await app.close();
}
}, 20000);

it('launches successfully and opens the main window', async () => {
const window = await app.firstWindow();
expect(window).toBeTruthy();

// Check if the window is visible and not crashed
const isClosed = window.isClosed();
expect(isClosed).toBe(false);

// Optionally wait for some title or element to be sure the frontend is loaded,
// but simply verifying the window isn't crashed satisfies the smoke test requirements.
const title = await window.title();
expect(title).toBeTypeOf('string'); // The app has some title
}, 30000);
});
4 changes: 3 additions & 1 deletion packages/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
"electron-updater": "^6.3.0"
},
"devDependencies": {
"@playwright/test": "^1.59.1",
"electron": "^35.7.5",
"electron-builder": "^26.0.0",
"esbuild": "^0.25.12"
"esbuild": "^0.25.12",
"playwright": "^1.59.1"
}
}
Loading