test: implement ipc set and reset preference test#518
Conversation
There was a problem hiding this comment.
Code Review
This pull request cleans up the test/ipc.spec.js file by removing outdated comments and implements the previously empty 'Validate set_preference + reset_preference' test. The feedback highlights two critical issues in the new test: first, the test emits the 'set_preference' event without a dummy event object, which masks a production bug where the payload is lost; second, the assertion for the reset opacity value expects 100 instead of the actual default value of 80, which will cause the test to fail.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| test( 'Validate set_preference + reset_preference', async () => { | ||
|
|
||
| // Test set_preference | ||
| await electronApp.evaluate( async app => app.ipcMain.emit( 'set_preference', { key: 'crosshair.opacity', value: 50 } ) ) |
There was a problem hiding this comment.
In Electron, ipcMain.on listeners always receive the event object as the first argument, followed by the actual message payload.
In src/main/ipc.js, the set_preference listener is defined as:
ipcMain.on( 'set_preference', arg => { ... } )Because it only accepts a single parameter, in production arg will be the event object, and the actual preference payload is lost, making the feature broken.
The test currently passes because it emits the event directly using app.ipcMain.emit( 'set_preference', { key: ... } ), which passes the payload as the first argument. To properly simulate Electron's IPC behavior and expose this bug, the test should pass a dummy event object as the first argument.
| await electronApp.evaluate( async app => app.ipcMain.emit( 'set_preference', { key: 'crosshair.opacity', value: 50 } ) ) | |
| await electronApp.evaluate( async app => app.ipcMain.emit( 'set_preference', {}, { key: 'crosshair.opacity', value: 50 } ) ) |
| // Assuming default opacity is 100 | ||
| expect( newOpacity ).toBe( 100 ) |
There was a problem hiding this comment.
lacymorrow
left a comment
There was a problem hiding this comment.
Good addition -- the IPC pattern matches the existing test style and preferences.init() is the right way to read the store from the main process.
One bug: the default opacity is 80, not 100 (see src/main/preferences.js:27). After reset_preferences, expect(newOpacity).toBe(100) will fail. Fix the assertion:
// Assuming default opacity is 100 // <-- wrong
expect( newOpacity ).toBe( 80 )Also: set_preference only checks arg.value as truthy, so setting opacity to 0 via IPC silently no-ops (pre-existing bug in ipc.js, not this PR's concern, but worth noting).
Otherwise LGTM once the default value is corrected.
|
I have pushed updates to address the feedback:
All tests are passing successfully now! |
lacymorrow
left a comment
There was a problem hiding this comment.
All the requested fixes look correct:
- Opacity assertion corrected to 80 (matches
preferences.jsdefault) set_preferenceIPC listener now properly accepts(_event, arg)and guards witharg.value !== undefinedfor falsy values like0- Test body implemented correctly for both
set_preferenceandreset_preferences session.defaultSessionsetup wrapped inapp.whenReady()is the right Electron pattern and will fix startup crashes in the test environment
One thing to flag: the TROUBLESHOOTING_URL and COMPATIBILITY_URL additions to src/config/config.js conflict with PR #515, which also adds these same constants but with different URLs:
| Constant | PR #515 | PR #518 |
|---|---|---|
| TROUBLESHOOTING_URL | crossover#game-compatibility |
wiki/Troubleshooting |
| COMPATIBILITY_URL | crossover/issues/47 |
wiki/Compatibility |
Whichever merges second will have a conflict. The wiki pages may not exist yet. Once #515 merges, please rebase and remove the config.js constants from this PR (or update the URLs to match whatever Lacy chooses). The rest of this PR is independent and can land as-is.
process.mainModule.require is deprecated in modern Node but works fine in the Playwright/Electron context here. Not a blocker.
LGTM on the actual test + IPC fixes. Waiting on the config.js conflict to be resolved before merge.
|
@MatrixNeoKozak the ipc.js fix and updated tests all look good after your June 19 push. One remaining step before this can merge: the Could you remove the three config.js lines (the two |
|
The IPC fix and updated tests are good and ready to go. The only thing blocking this is the The two constants you added ( To unblock this:
Once that's done this is ready to merge. |
Implements the previously empty test case for set_preference and reset_preferences IPC events in test/ipc.spec.js. This ensures that preference updates are correctly registered and that resetting preferences restores them to default values, improving test coverage and reliability of the preferences management system.