Repository navigation
test(desktop): repair five deterministically failing desktop Swift suites - #11604
Conversation
…ites Reported as flakes; every one fails 100% of the time, including when its suite runs alone in its own process. The green run that suggested a flake never ran a Swift test — that push touched only .github, so the suite step is recorded as skipped. Each failure is a test that outlived the product decision it was written against, or a harness that quietly stopped rendering what it claims to measure. - Rewind's bottom margin is PageGlassLane's, not a mirror of its own top gap, now that the shell is flush with its glass - The modal scrim's undimmed probes are derived from ShellModalScrimLayout and run over every bounds case, so a full-width lane no longer voids the precondition - The glass panel renders through NSHostingView: ImageRenderer cannot draw the InkGlassHitRegionReporter representable and substituted a placeholder for the whole panel, so the clip assertions measured nothing - The transcript-geometry guard asserts the layout loop it was written for rather than the .onGeometryChange mechanism the restored prompt rail legitimately uses again - The proactive-lane max-deadline guard is reachable only through actor reentrancy, so its test holds two 429s in flight instead of expecting a second sequential attempt to reach the network No product behaviour changed; every edit is under Desktop/Tests. Failure-Class: none Co-Authored-By: Claude Opus 5 <[email protected]>
There was a problem hiding this comment.
2 issues found across 5 files
Confidence score: 4/5
- In
desktop/macos/Desktop/Tests/GlassSurfaceReviewRegressionTests.swift, the newthrow XCTSkipbranches can turn rendering-harness setup failures (nil bitmap/cgImage/CGContext) into skipped tests, which can hide real visual regressions by reporting green instead of failing — treat harness-construction failures as assertions/failures (or split environment preconditions from test assertions) so regressions stay visible. - In
desktop/macos/Desktop/Tests/AgentPillLifecycleTests.swift, the tripwire around.onGeometryChange(for: ChatTranscriptContentFrame.self)targets a dead type fromChatTranscriptGeometry.swift, so the test can add noise without protecting active behavior — retarget the assertion to a live geometry path or remove the dead-code sentinel to reduce false confidence.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="desktop/macos/Desktop/Tests/AgentPillLifecycleTests.swift">
<violation number="1" location="desktop/macos/Desktop/Tests/AgentPillLifecycleTests.swift:1177">
P3: The new tripline asserts `ChatMessagesView` never uses `.onGeometryChange(for: ChatTranscriptContentFrame.self)`, but that type is dead code — `struct ChatTranscriptContentFrame` (ChatTranscriptGeometry.swift:23) is referenced nowhere in the product source; transcript measurement now flows through `ChatScrollPositionDetector`/`ChatTranscriptGeometry.setContent`. So the assertion can only pass and guards nothing about the real layout loop, contradicting the comment's claim that these checks "close the layout loop." The meaningful facts here are the `@State` (not `@StateObject`/`@ObservedObject`) assertions; the `ChatTranscriptContentFrame` check should guard the actual mechanism (e.g., no `onGeometryChange`/position reads feeding observed state) or be dropped as a false-confidence contract.</violation>
</file>
<file name="desktop/macos/Desktop/Tests/GlassSurfaceReviewRegressionTests.swift">
<violation number="1" location="desktop/macos/Desktop/Tests/GlassSurfaceReviewRegressionTests.swift:119">
P2: The three added `throw XCTSkip` guards mean the test is reported green (skipped) whenever the rendering harness itself fails — nil bitmap rep, nil `cgImage`, or failed `CGContext` creation — rather than failing the suite. That is exactly the false-green the PR is trying to eliminate, and it diverges from this repo's established `cacheDisplay` pixel-test pattern: `GlassLegibilityTests` and `ShellStatusIconLegibilityTests` use `try XCTUnwrap(...)` so a broken harness hard-fails the test instead of silently passing it. Use `XCTUnwrap`/failed-assertion errors here too, so a real regression in the clip behavior can never be masked by a skipped suite.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| host.frame = NSRect(origin: .zero, size: size) | ||
| host.layoutSubtreeIfNeeded() | ||
|
|
||
| guard let representation = host.bitmapImageRepForCachingDisplay(in: host.bounds) else { |
There was a problem hiding this comment.
P2: The three added throw XCTSkip guards mean the test is reported green (skipped) whenever the rendering harness itself fails — nil bitmap rep, nil cgImage, or failed CGContext creation — rather than failing the suite. That is exactly the false-green the PR is trying to eliminate, and it diverges from this repo's established cacheDisplay pixel-test pattern: GlassLegibilityTests and ShellStatusIconLegibilityTests use try XCTUnwrap(...) so a broken harness hard-fails the test instead of silently passing it. Use XCTUnwrap/failed-assertion errors here too, so a real regression in the clip behavior can never be masked by a skipped suite.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Tests/GlassSurfaceReviewRegressionTests.swift, line 119:
<comment>The three added `throw XCTSkip` guards mean the test is reported green (skipped) whenever the rendering harness itself fails — nil bitmap rep, nil `cgImage`, or failed `CGContext` creation — rather than failing the suite. That is exactly the false-green the PR is trying to eliminate, and it diverges from this repo's established `cacheDisplay` pixel-test pattern: `GlassLegibilityTests` and `ShellStatusIconLegibilityTests` use `try XCTUnwrap(...)` so a broken harness hard-fails the test instead of silently passing it. Use `XCTUnwrap`/failed-assertion errors here too, so a real regression in the clip behavior can never be masked by a skipped suite.</comment>
<file context>
@@ -87,11 +92,36 @@ final class GlassSurfaceReviewRegressionTests: XCTestCase {
+ host.frame = NSRect(origin: .zero, size: size)
+ host.layoutSubtreeIfNeeded()
+
+ guard let representation = host.bitmapImageRepForCachingDisplay(in: host.bounds) else {
+ throw XCTSkip("AppKit did not vend a bitmap for the SwiftUI glass surface")
+ }
</file context>
| // `ChatTranscriptGeometry`, which this view holds as a plain `@State` reference and therefore | ||
| // does not observe — only the rail overlay does. Assert the facts that actually close the | ||
| // layout loop rather than the mechanism that happened to be absent. | ||
| XCTAssertFalse(source.contains(".onGeometryChange(for: ChatTranscriptContentFrame.self)")) |
There was a problem hiding this comment.
P3: The new tripline asserts ChatMessagesView never uses .onGeometryChange(for: ChatTranscriptContentFrame.self), but that type is dead code — struct ChatTranscriptContentFrame (ChatTranscriptGeometry.swift:23) is referenced nowhere in the product source; transcript measurement now flows through ChatScrollPositionDetector/ChatTranscriptGeometry.setContent. So the assertion can only pass and guards nothing about the real layout loop, contradicting the comment's claim that these checks "close the layout loop." The meaningful facts here are the @State (not @StateObject/@ObservedObject) assertions; the ChatTranscriptContentFrame check should guard the actual mechanism (e.g., no onGeometryChange/position reads feeding observed state) or be dropped as a false-confidence contract.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Tests/AgentPillLifecycleTests.swift, line 1177:
<comment>The new tripline asserts `ChatMessagesView` never uses `.onGeometryChange(for: ChatTranscriptContentFrame.self)`, but that type is dead code — `struct ChatTranscriptContentFrame` (ChatTranscriptGeometry.swift:23) is referenced nowhere in the product source; transcript measurement now flows through `ChatScrollPositionDetector`/`ChatTranscriptGeometry.setContent`. So the assertion can only pass and guards nothing about the real layout loop, contradicting the comment's claim that these checks "close the layout loop." The meaningful facts here are the `@State` (not `@StateObject`/`@ObservedObject`) assertions; the `ChatTranscriptContentFrame` check should guard the actual mechanism (e.g., no `onGeometryChange`/position reads feeding observed state) or be dropped as a false-confidence contract.</comment>
<file context>
@@ -1164,10 +1164,20 @@ import XCTest
+ // `ChatTranscriptGeometry`, which this view holds as a plain `@State` reference and therefore
+ // does not observe — only the rail overlay does. Assert the facts that actually close the
+ // layout loop rather than the mechanism that happened to be absent.
+ XCTAssertFalse(source.contains(".onGeometryChange(for: ChatTranscriptContentFrame.self)"))
+ XCTAssertTrue(source.contains("@State private var transcriptGeometry = ChatTranscriptGeometry()"))
+ XCTAssertFalse(source.contains("@StateObject private var transcriptGeometry"))
</file context>
These are not flakes
Five desktop Swift tests were reported as intermittent. They are not: every one of them fails
100% of the time, including when its suite is run alone in its own process, so ordering,
parallelism and shared process state are all ruled out.
Measured on
c2458931bfbefore this change:--filter Suite/)GlassSurfaceReviewRegressionTestsRewindSurfaceLayoutTestsShellModalScrimDismissTestsProactiveLaneClientTestsAgentPillLifecycleTestsThe evidence that suggested a flake was a green Desktop Swift Static & Test Contracts on
c2458931bf17 minutes after a red one. That run never ran a Swift test:c2458931bftouches only.github/**, soshould_run_testswas false and theTest desktop Swift appstep is recorded asskipped. The green is real but vacuous, andmainhas in fact been red for these suites since thecommits below landed.
What actually broke each one
Each failure is a test that outlived the product decision it was written against, or a harness that
silently stopped rendering what it claims to measure.
RewindSurfaceLayoutTests.testTheGapCornerAndMarginsAreTheProductsOwn— assertedbottomGap == topGap.1fcb920616flushed the shell to its glass and setPageGlassLaneLayout.bottomGapto 0 so AppKit's resize rim sits on the visible panel. Thesection's claim is delegation, not equality, so it now asserts
bottomGapisPageGlassLaneLayout's — which is what stops Rewind holding its own opinion about the margin.ShellModalScrimDismissTests.testAClickOutsideThePaintedDimStillRunsTheDismiss— itsprecondition was that the dim is clamped to a lane narrower than the window. The same commit set
DesktopWindowLayoutPolicy.windowInsetto 0, so the lane fills the window and the side band itclicked in no longer exists. The claim — modality is host scale while only the paint is
bounded — is still true and still worth holding, so the probes are now derived from
ShellModalScrimLayoutitself and run over everyShellModalScrimBounds. Today that exercisesthe
.contentAreatop gap; if a lane clamp ever returns, the side band comes back with it forfree. A guard fails the test if no surface insets its paint at all, so this cannot decay into
asserting nothing.
GlassSurfaceReviewRegressionTests.testInkGlassPanelClipsReturnedContentButNotAnOuterOverlay— the interesting one.
15a51fb985addedInkGlassHitRegionReporter, anNSViewRepresentable,inside
inkGlassPanelso a glass surface keeps the pointer inside the window.ImageRenderercannot draw a representable: it substitutes a placeholder graphic for the entire panel, and
every pixel this test read back described that placeholder rather than the glass. The test was
not measuring the clip at all — and would not have measured it even had it passed. It now
renders through a real
NSHostingView+cacheDisplay, converts the probe point at the bitmap'sbacking scale, and asserts the invariant rather than a colour: the returned red rectangle paints
inside the corner's curve (a control, so a harness that renders nothing fails) and is gone 8 pt
further out. The old
greenComponent < 0.5assertion was an absolute-lightness proxy that thepanel's pinned colour scheme makes untrue regardless of the renderer.
AgentPillLifecycleTests.testSharedChatMessagesOpenAndSendFollowLatest— a static contractthat banned any
.onGeometryChange(for:inChatMessagesView.swift. That started life(
22327060b2) as the precise pair "noChatTranscriptContentFrameread, notranscriptGeometry.setRowOffset" and was broadened to the blanket form while the prompt rail wasdeleted.
9294191a61restored the rail, which measures rows again — but writes intoChatTranscriptGeometry, which the view holds as a plain@Statereference and therefore doesnot observe; only the rail overlay does. The guard now asserts the facts that actually close
the
FC-selection-overlay-layout-loop: no content-frame read back through the transcript'slayout, and the geometry object is held off the view's observed state (
@State, never@StateObject/@ObservedObject).ProactiveLaneClientTests.testLaterShorterRetryWindowDoesNotShortenActiveCooldown— assertedthat two sequential 429s both reach the network. They cannot:
complete()checks the cooldownbefore it sends, so once the first 429 arms a window the second attempt never leaves the
process and no competing
Retry-Aftercan arrive. The guard it means to test(
armQuotaCooldownkeeping the later of two deadlines) is only reachable through actorreentrancy — two calls already in flight when the responses land. The test now drives exactly
that, deterministically: the URL stub parks every request until both are in flight, so both are
guaranteed past the cooldown check before either response is delivered. Verified by mutation —
deleting the
existing > newDeadlineguard fromProactiveLaneClientmakes it fail.No product behaviour changed. Every edit is under
desktop/macos/Desktop/Tests/; the oneproduct file touched during investigation (
ProactiveLaneClient.swift, for the mutation check) wasrestored byte-for-byte.
Proof
After the change, on this branch:
dev-feedback.py --onceProactiveLaneClientTests|AgentPillLifecycleTests|ShellModalScrimDismissTestsRewindSurfaceLayoutTests|GlassSurfaceReviewRegressionTestsShellModalScrimDismissTests|RewindSurfaceLayoutTests|GlassSurfaceReviewRegressionTestsProactiveLaneClientTestsaloneGlass|Shell|Rewind|ProactiveAlso green: the proactive/desktop gate (
ContextBucket|ContextProactivity|ContextDelivery| ContextVisit|ContextDestination|ContextSubject|ContextTitle|CandidateSink) at 148 tests, 0failures;
check_desktop_test_quality.pywith debt unchanged at its baseline (54 source-readingfiles / 147 sites / 16 waits);
check-main-actor-xctest-hooks.py; andpr-preflightat 18/18.OMI_SWIFT_TEST_SUITE_WORKERS=4 ./scripts/swift-test-suites.shran 616 suites with exactly onefailure, described below. All five suites this PR repairs pass there.
One unrelated failure the full run surfaced — a real flake, left out of scope
ChatCitationTests.testRewindCitationFocusIsOneShotAndPreservesExactScreenshotIDfails in the4-worker run and passes 6/6 alone (real preferences home and a fresh
CFFIXED_USER_HOME/TMPDIRalike). It is untouched by this diff and predates it.
Unlike the five above it is genuinely non-deterministic:
RewindCitationFocusState.requestsilentlyclears instead of storing whenever
RewindCaptureOwnerSnapshot.capture()returns nil, and thathappens while the process-global
RewindCaptureOwnerGeneration.transitionActiveflag is set. Thetest establishes no owner state and fences nothing, so it depends on whatever the process happens to
be doing. Fixing it means giving it explicit owner setup — which also moves the suite into the
runner's derived sequential cluster — so it belongs in its own change rather than bolted onto a
test-hygiene PR.
Changelog
No fragment: this is test-only.
desktop/macos/Desktop/Tests/is an explicit path exemption in.github/scripts/check-desktop-changelog.py, andchangelog/README.mdscopes fragments touser-facing PRs.
Follow-up worth doing separately (not in this PR)
maincarried five deterministically-failing suites without a red required check, because theDesktop Swift Static & Test Contractsjob skips the Swift suite whenever a push touches no Swiftpaths. A
.github-only or backend-only commit therefore publishes a green exact-SHA verdict thatsays nothing about the tests, and release planning consumes it.
Failure-Class: none
Co-Authored-By: Claude Opus 5 [email protected]