Repository navigation
A fake WKNavigation was killing the test host, hiding a whole suite - #8633
Conversation
📝 WalkthroughWalkthroughBrowser discard/restore tests now retain stubbed ChangesBrowser discard/restore test stability
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 25✅ Passed checks (25 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
5b3f16c to
cc0c329
Compare
cc0c329 to
81409ed
Compare
|
Measured on a combined build at c59bbdf (current On unfixed Also correcting the record on how this sat open. I re-derived the cause later in the day by running |
Greptile SummaryThis PR fixes two distinct xctest host crashes in
Confidence Score: 5/5Safe to merge — all changes are confined to the test target, fixing crashes that previously swallowed an entire test suite without a failure verdict. The two fixes are surgical, well-documented, and match established patterns already used dozens of times in this test file. No production code is touched, no assertions are changed, and the suite now passes all eight tests where it previously killed the host. Files Needing Attention: No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Test calls BrowserDiscardRestoreNavigationStub.make()"] --> B["WKNavigation() allocated"]
B --> C["Appended to @MainActor static retained array"]
C --> D["WKNavigation reference returned to test"]
D --> E["Test uses navigation by identity only"]
E --> F["Test completes — retained array keeps object alive"]
F --> G["No dealloc during test run → host survives"]
H["NSWindow created in test"] --> I["isReleasedWhenClosed = false set"]
I --> J["defer: window.close() runs"]
J --> K["AppKit does not release — ARC still holds ref"]
K --> L["No double-free → host survives"]
Reviews (2): Last reviewed commit: "cmuxTests: the same suite closes a test-..." | Re-trigger Greptile |
BrowserDiscardRestorePolicyCancelTests logs that it started and then produces no verdict at all, which is what a dead host looks like rather than a failing assertion. That is why the suite reads as consistent with the product when you go through it test by test: it does not fail, it dies, and it takes every suite sharing the host down with it. The cause is constructing WKNavigation directly. WebKit builds the embedded C++ API::Navigation itself, so a bare WKNavigation() carries unconstructed storage. Allocating one is harmless; releasing it is not. Reproduced outside the test bundle, deterministically: EXC_BREAKPOINT inside CFRetain from -[WKNavigation dealloc] with WebKit initialised, and SIGSEGV through WebCoreObjCScheduleDeallocateOnMainRunLoop from the same dealloc without it. The first death needs no window: the fake is stored as the pending restore navigation, the next call clears that reference, and the release traps mid-assertion before anything prints. That also explains why no output survives. The probe reproduced the missing-log signature too: with stdout on a pipe, the crash discards the buffer, so even the line printed just before it never reaches the log. The bookkeeping under test only ever compares these by identity, so the fakes are minted through a helper that keeps them retained for the run. No assertion changes. WKNavigation() appears nowhere else in the repo. Whether the eight tests then pass is a separate question this crash has been hiding.
…ases Retaining the fake navigations got this suite far enough to run and pass several tests where it previously produced nothing, which confirmed the first cause and exposed a second one in the same file. One test builds an NSWindow, holds it through ARC, and closes it in a defer without disabling AppKit's close-time release, so the last retain goes away underneath the live references and the host aborts instead of a test failing. That is the same defect already proven in the shortcut routing suite, and about forty other closing sites in cmuxTests already guard against it.
81409ed to
34c2460
Compare
Bugbot is paused — on-demand spend limit reachedBugbot uses usage-based billing for this team and has hit its on-demand spend limit. A team admin can raise the spend limit in the Cursor dashboard, or wait for the next billing cycle to continue. |
What was happening
BrowserDiscardRestorePolicyCancelTestslogged that it started and then produced no verdict at all. That is a dead test host, not a failing test, and it is worse than a red suite: the host takes down every suite batched with it, so any batched measurement including this one was untrustworthy. Reading the eight tests one by one finds nothing wrong with them, which is exactly what you would expect — the suite does not fail, it dies.Cause, and a second one behind it
The suite constructs
WKNavigation()directly. WebKit builds that object's embedded C++API::Navigationitself, so a bare instance carries unconstructed storage. Allocating one is harmless; releasing it is not. Reproduced outside the test bundle, deterministically:EXC_BREAKPOINTinsideCFRetainfrom-[WKNavigation dealloc]with WebKit initialised, andSIGSEGVthroughWebCoreObjCScheduleDeallocateOnMainRunLoopfrom the same dealloc without it. The earliest death needs no window: the fake is stored as the pending restore navigation, the next call clears that reference, and the release traps mid-assertion.WKNavigation()appears nowhere else in the repo.That also explains why no output survives: with stdout on a pipe, the crash discards the buffer, so even the line printed immediately before it never reaches the log.
The bookkeeping under test only ever compares these by identity, so the fakes are now minted through a helper that keeps them retained for the run.
Fixing that got the suite far enough to run and pass several tests, which exposed a second killer in the same file: one test builds an
NSWindow, holds it through ARC, and closes it in adeferwithout disabling AppKit's close-time release, so the last retain goes away underneath live references. About forty other closing sites incmuxTestsalready guard against this, and the same defect was separately confirmed in another suite.Verification
Measured on a macOS builder, the suite run alone in both arms:
No assertion changed.
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Summary by cubic
Prevents xctest host crashes by replacing fake
WKNavigation()with a retained stub and disablingNSWindowclose-time release in one test. TheBrowserDiscardRestorePolicyCancelTestssuite now runs and passes instead of killing the host.BrowserDiscardRestoreNavigationStub.make()to create and retainWKNavigationinstances for the test run.WKNavigation()calls with the stub to avoid WebKit dealloc traps.window.isReleasedWhenClosed = falsein the window-close test to prevent double release.Written for commit 34c2460. Summary will update on new commits.
Summary by CodeRabbit