Skip to content

test(macos): isolate workspace notification observers - #1168

Open
juan-apa wants to merge 1 commit into
AprilNEA:masterfrom
juan-apa:fix/flaky-macos-tray-tests
Open

test(macos): isolate workspace notification observers#1168
juan-apa wants to merge 1 commit into
AprilNEA:masterfrom
juan-apa:fix/flaky-macos-tray-tests

Conversation

@juan-apa

Copy link
Copy Markdown
Contributor

Summary

Stop the macOS tray lifecycle tests from affecting each other through the process-global NSWorkspace notification center. Under the default parallel Rust test harness, one test could deliver session notifications to the other test's observer and leave its device-I/O gate suspended.

Changes

  • Extract notification registration into a helper that accepts its notification center and workspace object.
  • Keep production registration on NSWorkspace's notification center.
  • Give each tray lifecycle test a private NSNotificationCenter, preserving selector-level coverage without cross-test delivery.

Testing

  • Reproduced the original failure on the fifth repeated default-parallel tray test run.
  • Ran the two tray tests 100 consecutive times under the default parallel harness after the fix.
  • cargo fmt --all -- --check
  • RUSTFLAGS="-D warnings" cargo clippy -p openlogi-agent --all-targets -- -D warnings
  • RUSTFLAGS="-D warnings" cargo test -p openlogi-agent
  • RUSTFLAGS="-D warnings" cargo test --workspace --all-targets
  • Not runtime-tested on hardware; this is a test-isolation change and does not alter lifecycle transitions.

Refs #1142
Unblocks #1167

@juan-apa
juan-apa requested a review from AprilNEA as a code owner August 30, 2026 16:38
@greptile-apps

greptile-apps Bot commented Aug 30, 2026

Copy link
Copy Markdown

Greptile Summary

This PR isolates macOS tray lifecycle tests from the process-global workspace notification center without changing production observer registration.

  • Extracts observer registration into a helper accepting an explicit notification center and workspace.
  • Retains the production NSWorkspace notification center path.
  • Uses a private notification center in each lifecycle test to prevent cross-test notification delivery.

Confidence Score: 5/5

The PR appears safe to merge because production observer behavior is preserved and the tests retain direct coverage of lifecycle selector delivery through isolated notification centers.

The helper receives the same workspace notification center and workspace object in production, while each test consistently registers and posts through its own private center with the matching object filter.

Important Files Changed

Filename Overview
crates/openlogi-agent/src/tray.rs Refactors observer installation for dependency injection and isolates notification delivery between parallel tests while preserving production filters and selectors.

Reviews (1): Last reviewed commit: "test(macos): isolate workspace notificat..." | Re-trigger Greptile

@davidbudnick davidbudnick added type: bug Something is broken or behaves incorrectly platform: macos macOS-specific issue labels Sep 3, 2026
@yuzi-co

yuzi-co commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

The two macOS test failures I've been hitting aren't area-specific — worth landing this for everyone.

Same assertion on three unrelated branches within the last hour: #1250 (ci/narrow-nix-ci-triggers, touches no Rust at all), and #970 / #942 (both mine, neither touches openlogi-agent). All three: tray::tests::startup_stays_suspended_when_the_display_is_already_asleep, assertion failed: gate.allows_io() at tray.rs:578.

#1236 proposes a Mutex<()> around the two tests instead. Both work, but this one looks like the better fix to me: a private NSNotificationCenter per test makes cross-test delivery structurally impossible and keeps the tests parallel, where the mutex leaves the global center shared and turns isolation into a convention every future test in the module has to remember.

Verification favours this one too — 100 consecutive runs here after reproducing the failure, versus #1236 not being runnable on its author's machine at all. For an intermittent race a single green CI run isn't much signal either way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform: macos macOS-specific issue type: bug Something is broken or behaves incorrectly

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants