Skip to content

test(desktop): repair five deterministically failing desktop Swift suites - #11604

Merged
Git-on-my-level merged 1 commit into
mainfrom
fix/desktop-test-flakes
Aug 15, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
fix/desktop-test-flakes

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Aug 15, 2026 •

Copy link
Copy Markdown
Member

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 c2458931bf before this change:

suite (run alone, --filter Suite/) pass fail
GlassSurfaceReviewRegressionTests 0 3
RewindSurfaceLayoutTests 0 3
ShellModalScrimDismissTests 0 3
ProactiveLaneClientTests 0 3
AgentPillLifecycleTests 0 3
all five together (the reported repro) 0 5

The evidence that suggested a flake was a green Desktop Swift Static & Test Contracts on
c2458931bf 17 minutes after a red one. That run never ran a Swift test: c2458931bf touches only
.github/**, so should_run_tests was false and the Test desktop Swift app step is recorded as
skipped. The green is real but vacuous, and main has in fact been red for these suites since the
commits 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.

  1. RewindSurfaceLayoutTests.testTheGapCornerAndMarginsAreTheProductsOwn — asserted
    bottomGap == topGap. 1fcb920616 flushed the shell to its glass and set
    PageGlassLaneLayout.bottomGap to 0 so AppKit's resize rim sits on the visible panel. The
    section's claim is delegation, not equality, so it now asserts bottomGap is
    PageGlassLaneLayout's — which is what stops Rewind holding its own opinion about the margin.

  2. ShellModalScrimDismissTests.testAClickOutsideThePaintedDimStillRunsTheDismiss — its
    precondition was that the dim is clamped to a lane narrower than the window. The same commit set
    DesktopWindowLayoutPolicy.windowInset to 0, so the lane fills the window and the side band it
    clicked 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
    ShellModalScrimLayout itself and run over every ShellModalScrimBounds. Today that exercises
    the .contentArea top gap; if a lane clamp ever returns, the side band comes back with it for
    free. A guard fails the test if no surface insets its paint at all, so this cannot decay into
    asserting nothing.

  3. GlassSurfaceReviewRegressionTests.testInkGlassPanelClipsReturnedContentButNotAnOuterOverlay
    — the interesting one. 15a51fb985 added InkGlassHitRegionReporter, an NSViewRepresentable,
    inside inkGlassPanel so a glass surface keeps the pointer inside the window. ImageRenderer
    cannot 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's
    backing 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.5 assertion was an absolute-lightness proxy that the
    panel's pinned colour scheme makes untrue regardless of the renderer.

  4. AgentPillLifecycleTests.testSharedChatMessagesOpenAndSendFollowLatest — a static contract
    that banned any .onGeometryChange(for: in ChatMessagesView.swift. That started life
    (22327060b2) as the precise pair "no ChatTranscriptContentFrame read, no
    transcriptGeometry.setRowOffset" and was broadened to the blanket form while the prompt rail was
    deleted. 9294191a61 restored the rail, which measures rows again — but writes into
    ChatTranscriptGeometry, which the view holds as a plain @State reference and therefore does
    not 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's
    layout, and the geometry object is held off the view's observed state (@State, never
    @StateObject/@ObservedObject).

  5. ProactiveLaneClientTests.testLaterShorterRetryWindowDoesNotShortenActiveCooldown — asserted
    that two sequential 429s both reach the network. They cannot: complete() checks the cooldown
    before it sends, so once the first 429 arms a window the second attempt never leaves the
    process and no competing Retry-After can arrive. The guard it means to test
    (armQuotaCooldown keeping the later of two deadlines) is only reachable through actor
    reentrancy — 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 > newDeadline guard from ProactiveLaneClient makes it fail.

No product behaviour changed. Every edit is under desktop/macos/Desktop/Tests/; the one
product file touched during investigation (ProactiveLaneClient.swift, for the mutation check) was
restored byte-for-byte.

Proof

After the change, on this branch:

run pass fail
reported combined repro, via dev-feedback.py --once 15 0
ProactiveLaneClientTests|AgentPillLifecycleTests|ShellModalScrimDismissTests 10 0
RewindSurfaceLayoutTests|GlassSurfaceReviewRegressionTests 10 0
ShellModalScrimDismissTests|RewindSurfaceLayoutTests|GlassSurfaceReviewRegressionTests 10 0
ProactiveLaneClientTests alone 10 0
Glass|Shell|Rewind|Proactive 10 0

Also green: the proactive/desktop gate (ContextBucket|ContextProactivity|ContextDelivery| ContextVisit|ContextDestination|ContextSubject|ContextTitle|CandidateSink) at 148 tests, 0
failures
; check_desktop_test_quality.py with debt unchanged at its baseline (54 source-reading
files / 147 sites / 16 waits); check-main-actor-xctest-hooks.py; and pr-preflight at 18/18.

OMI_SWIFT_TEST_SUITE_WORKERS=4 ./scripts/swift-test-suites.sh ran 616 suites with exactly one
failure, 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.testRewindCitationFocusIsOneShotAndPreservesExactScreenshotID fails in the
4-worker run and passes 6/6 alone (real preferences home and a fresh CFFIXED_USER_HOME/TMPDIR
alike). It is untouched by this diff and predates it.

Unlike the five above it is genuinely non-deterministic: RewindCitationFocusState.request silently
clears instead of storing whenever RewindCaptureOwnerSnapshot.capture() returns nil, and that
happens while the process-global RewindCaptureOwnerGeneration.transitionActive flag is set. The
test 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, and changelog/README.md scopes fragments to
user-facing PRs.

Follow-up worth doing separately (not in this PR)

main carried five deterministically-failing suites without a red required check, because the
Desktop Swift Static & Test Contracts job skips the Swift suite whenever a push touches no Swift
paths. A .github-only or backend-only commit therefore publishes a green exact-SHA verdict that
says nothing about the tests, and release planning consumes it.

Failure-Class: none
Co-Authored-By: Claude Opus 5 [email protected]

Review in cubic

…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]>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2 issues found across 5 files

Confidence score: 4/5

  • In desktop/macos/Desktop/Tests/GlassSurfaceReviewRegressionTests.swift, the new throw XCTSkip branches 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 from ChatTranscriptGeometry.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 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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>

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