Skip to content

Fix Windows CI test failures: certificate-manager flakiness and native addon segfault - #3740

Merged
wojtekn merged 8 commits into
trunkfrom
fix-certificate-manager-test-flakiness
Jun 9, 2026
Merged

Fix Windows CI test failures: certificate-manager flakiness and native addon segfault#3740
wojtekn merged 8 commits into
trunkfrom
fix-certificate-manager-test-flakiness

Conversation

@wojtekn

@wojtekn wojtekn commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Related issues

  • Related to intermittent CI failures on trunk

How AI was used in this PR

Claude Code investigated the CI failure logs, identified root causes, and implemented the fixes, after thorough debugging and trying multiple different approaches.

Proposed Changes

This PR fixes two distinct Windows CI issues:

1. Flaky certificate-manager test

The rejects when sudo.exec reports an error test was intermittently failing on Windows CI. Each test called setPlatform('linux') individually, leaving a window where the prior test's afterEach (restoring the platform to win32) could race with the next test's async mock setup. Fixed by moving setPlatform('linux') into a beforeEach for the trustRootCA describe block so the platform is guaranteed to be set before any async code runs.

2. Node.js segfault on Windows CI

After the @mariozechner/pi-*@earendil-works/pi-* 0.78.0 migration (#3707), the new packages bundle native .node addons (clipboard-win32, win32-console-mode). When Vitest runs tests in its default threads pool, these native addons are loaded into worker threads and don't clean up properly on thread exit, causing a segfault that kills the entire test process.

Fixed by switching the CLI project's Vitest pool from threads to forks (apps/cli/vitest.config.ts). Each test file now runs in an isolated child process, so a native addon crash cannot propagate across files.

The pool change also surfaced two pre-existing test issues in export.test.ts and import.test.ts: with pool:forks, each test file runs as a child process which has process.send defined. Both commands use if (process.send) to choose between an IPC event handler and a logger event handler — the tests expect the logger path but were silently taking the IPC path. Fixed by stubbing process.send to undefined in beforeEach and restoring via vi.unstubAllGlobals() in afterEach.

Testing Instructions

  • npm test -- apps/cli/lib/tests/certificate-manager.test.ts — all 10 tests pass
  • npm test -- apps/cli/commands/tests/export.test.ts apps/cli/commands/tests/import.test.ts — all 12 tests pass

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
Moved setPlatform('linux') from each individual test into a beforeEach
for the trustRootCA describe block, and suppressed expected console.error
output with a spy. This prevents the platform from being in an
indeterminate state if a prior test's afterEach restore races with the
next test's async mock setup, which was the likely cause of intermittent
failures on the 'rejects when sudo.exec reports an error' test in CI.
@wpmobilebot

wpmobilebot commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing 4a111eb vs trunk

app-size

Metric trunk 4a111eb Diff Change
App Size (Mac) 1384.39 MB 1384.37 MB 0.02 MB ⚪ 0.0%

site-editor

Metric trunk 4a111eb Diff Change
load 1622 ms 1645 ms +23 ms ⚪ 0.0%

site-startup

Metric trunk 4a111eb Diff Change
siteCreation 9043 ms 9030 ms 13 ms ⚪ 0.0%
siteStartup 4427 ms 4422 ms 5 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

@wojtekn wojtekn changed the title Fix flaky certificate-manager tests on Windows CI Jun 9, 2026
@wojtekn
wojtekn requested a review from a team June 9, 2026 17:09
@wojtekn
wojtekn merged commit 493f6d8 into trunk Jun 9, 2026
12 of 13 checks passed
@wojtekn
wojtekn deleted the fix-certificate-manager-test-flakiness branch June 9, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants