Skip to content

feat: add exitOverride parameter for testing#8

Merged
arran4 merged 6 commits intomainfrom
add-exit-override-15427993918389103174
Feb 28, 2026
Merged

feat: add exitOverride parameter for testing#8
arran4 merged 6 commits intomainfrom
add-exit-override-15427993918389103174

Conversation

@google-labs-jules
Copy link
Contributor

Adds an optional exitOverride function parameter to unixSingleInstance to intercept calls to exit(). This allows testing scenarios that normally terminate the process without actually killing the test runner. When provided, the override is called with the intended exit code, and the function returns false.

Also adds a test case to verify exitOverride is correctly triggered when a second instance tries to start.


PR created automatically by Jules for task 15427993918389103174 started by @arran4

Adds an optional `exitOverride` function parameter to `unixSingleInstance` to intercept calls to `exit()`. This allows testing scenarios that normally terminate the process without actually killing the test runner. When provided, the override is called with the intended exit code, and the function returns `false`.

Also adds a test case to verify `exitOverride` is correctly triggered when a second instance tries to start.
@google-labs-jules
Copy link
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jules we may also want to overload (probably by way of interface) without breaking the existing users of the interface a way to overwrite the socket component for the purpose of logic testing, simulated sockets. We should also ensure that the socket code is tested against a real machine but that can be done once it's decoupled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've abstracted the socket component into a new SocketProvider interface with a DefaultSocketProvider that falls back to the original dart:io logic. I've also updated unixSingleInstance to accept an optional SocketProvider parameter. The tests are still passing and running against a real socket on the filesystem to verify that the decoupling works properly.

Introduces a `SocketProvider` interface to decouple the socket logic from `dart:io`. This allows test runners to mock or simulate sockets without relying on a real filesystem. `unixSingleInstance` now accepts an optional `socketProvider` parameter which defaults to `DefaultSocketProvider()`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jules please produce tests around this too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a test that specifically utilizes the new SocketProvider injection point by providing a MockSocketProvider. It verifies that unixSingleInstance correctly attempts to bind via the injected provider rather than the default dart:io implementation.

Adds a `MockSocketProvider` in the test suite to verify that a custom `SocketProvider` can be correctly passed to `unixSingleInstance`. The test proves the dependency is utilized instead of defaulting to `dart:io` implementations.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jules we can have a test or two testing the real world unix socket too if we don't already. Do what is necessary to increase assurance as well as coverage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first two existing tests in the suite (First instance returns true and Second instance returns false and sends args to first instance) already use the default socket provider to create a real world UNIX socket in the system's temporary directory. To increase coverage and assurance, I've added a new test (Dead socket is deleted and first instance starts) that verifies the system can recover correctly when it encounters a stale socket file from a previously crashed instance.

@arran4
Copy link
Owner

arran4 commented Feb 28, 2026

@jules is there a chance that the interface is missing the clean up logic

Adds a new test "Dead socket is deleted and first instance starts" to simulate the cleanup of a stale socket file from a previously crashed process. This uses the default real-world socket implementation, increasing coverage on the file deletion path.
@google-labs-jules
Copy link
Contributor Author

@jules is there a chance that the interface is missing the clean up logic

Good catch! I've updated the SocketProvider interface to also include checkSocketExists and clearSocket methods, and updated unixSingleInstance to use those instead of dart:io File methods. Now the cleanup logic is fully abstracted and can be mocked or simulated without touching the real file system.

Adds `checkSocketExists` and `clearSocket` to the `SocketProvider` interface to fully decouple the dependency on `dart:io` `File` operations. Updates `unixSingleInstance` to use these new provider methods, allowing tests to properly mock or simulate the cleanup phase of dead socket files.
@arran4 arran4 merged commit 80aee77 into main Feb 28, 2026
1 of 2 checks passed
@arran4 arran4 deleted the add-exit-override-15427993918389103174 branch February 28, 2026 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant