use npm list instead of custom traversal to get native module versions#70
Open
achou11 wants to merge 3 commits into
Open
use npm list instead of custom traversal to get native module versions#70achou11 wants to merge 3 commits into
achou11 wants to merge 3 commits into
Conversation
gmaclennan
added a commit
that referenced
this pull request
May 19, 2026
…ycleStateTransitions (#71) ## Summary Fixes a race in [`testFullLifecycleStateTransitions`](ios/Tests/NodeJSServiceTests.swift#L582) that intermittently fails the macOS Swift Package Tests job ([example failure on #70](https://github.com/digidem/comapeo-core-react-native/actions/runs/26056852629/job/76606978112)): ``` NodeJSServiceTests.swift:624: error: -[ComapeoCoreTests.NodeJSServiceTests testFullLifecycleStateTransitions] : XCTAssertLessThan failed: ("3") is not less than ("2") - STOPPING should come before STOPPED ``` The recorded `transitions` array ended up `[starting, started, stopped, stopping]` rather than the expected `[starting, started, stopping, stopped]`. ## The race Same shape as PR #59, slightly different underlying mechanic. PR #59 fixed the sister test `testStopSendsShutdownMessageOverIPC`; this test was introduced in PR #47 and wasn't covered by that fix. `NodeJSService.applyAndEmit` releases the service lock *before* invoking `onStateChange?(derived)` ([NodeJSService.swift:277](ios/NodeJSService.swift#L277), then [:319](ios/NodeJSService.swift#L319)) — a deliberate requirement of [`testObserverCanReenterLockedMethodFromCallback`](ios/Tests/NodeJSServiceTests.swift#L634), which asserts the callback can re-enter locked methods like `cleanup()` without deadlocking. The state mutations are linearised under the lock, but the post-unlock observer invocations are not. The test calls `signalExit()` *before* `service.stop(timeout: 1)`: ```swift // Stop signalExit() service.stop(timeout: 1) ``` That makes the node thread's `applyAndEmit` (writing `nodeRuntime = .exited(.requested)` → derives STOPPED) race the main thread's `applyAndEmit` from inside `stop()` (writing `stopRequested = true` → derives STOPPING). Even when the locked state transitions run in the right order, the post-unlock `onStateChange` callbacks can be reordered by thread scheduling, so the recorded array sees STOPPED before STOPPING. On a quiet runner the main thread usually wins; on a loaded macOS-14-arm64 CI runner it sometimes loses. ## The fix Identical pattern to PR #59: dispatch `stop()` to a background queue, register a STOPPING expectation, and `wait(for: [stoppingExpectation])` before calling `signalExit()`. That pins the observer ordering — STOPPING is appended to `transitions` before the node thread is ever unblocked, so the later STOPPED append from the node thread necessarily lands at a higher index. ```swift let stopFinished = expectation(description: "stop() returned") DispatchQueue.global().async { service.stop(timeout: 1) stopFinished.fulfill() } wait(for: [stoppingExpectation], timeout: 5) signalExit() wait(for: [stopFinished], timeout: 5) ``` ## Test plan - [ ] `swift test --filter NodeJSServiceTests/testFullLifecycleStateTransitions` × 50 — all pass - [ ] `swift test` (full suite) — clean (I'm on a Linux container so can't run `swift test` here; verifying via CI on this PR.) https://claude.ai/code/session_01BRgG9bgdFy9pZCov2uHyef --- _Generated by [Claude Code](https://claude.ai/code/session_01BRgG9bgdFy9pZCov2uHyef)_ Co-authored-by: Claude <noreply@anthropic.com>
Member
|
Added 835f46a just because spawning an |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently not an issue, but somehow had a deps tree locally such that
npm list sodium-nativelooked like this:When running
npm backend:build, onlysodium-native@4.3.3was detected and built for, which caused runtime errors related to failing to load the library forsodium-native@5.1.0. I've since updated locally such that it now looks like this, which works with the existing implementation:The custom fs traversal for finding versions most likely doesn't account for the "extra" layer seen with
sodium-universalin the failing example. Instead of updating the existing implementation, I think it'd be safer to use npm directly via itslscommand (docs). Passing the--parseableflag causes the stdout to be a newline-separated list of absolute paths to the module e.g.From an eye test, this approach is slightly slower than the existing approach but is less prone to error.