Skip to content

test(capture): Make the status icon glyph test deterministic - #154

Merged
epilande merged 1 commit into
mainfrom
fix/flaky-status-icon-test
Nov 20, 2026
Merged

epilande merged 1 commit into
mainfrom
fix/flaky-status-icon-test

Conversation

@epilande

@epilande epilande commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Overview

Makes testTheGlyphIsDarkOnAWhiteRingAndWhiteOnTheUsualOnes deterministic by measuring the glyph's ink inside the ring instead of counting pixels past a brightness cutoff, and by drawing it under both Aqua and Dark Aqua.

Motivation

The test failed once in a review run on the Mac mini (saved on red counted 18 bright pixels, needing more than 30) and passed in CI and in other local runs.

The cause is the drawing appearance. systemRed is a dynamic color, and its Aqua variant is lighter (by Rec. 709 luma, about 0.39 against 0.42). A pixel only passed the luminance > 0.9 cutoff when the white glyph covered about 84% of it, so the count depended on how many of the glyph's antialiased edge pixels sat right around that coverage. Rendering saved on red at 2x on this Mac gives:

Appearance Bright pixels
Dark Aqua 33
Aqua 18

.gray and the copied glyph barely change, so only that one case was near the threshold. The Mac mini has automatic Light/Dark switching on (AppleInterfaceStyleSwitchesAutomatically = 1), which fits a run made while it was in Light mode. Scale and color space were already fixed by the test's own bitmap. This isn't an app bug: the glyph draws the same, and its contrast is covered by testEveryRingColorGetsAGlyphWithAtLeastThreeToOneContrast and testAlwaysOnConfirmationIsSolidAndReadableOverALightMenuBar.

Changes

Glyph test

  • StatusIconConfirmationTests.swift - For each glyph and ring (white with a black glyph, red and gray with a white glyph), sums each opaque pixel's coverage from the sampled fill toward the expected glyph color, within the ring's 8 pt radius, and asserts it matches the symbol's own ink at the same fitted size to within 10%. The expected glyph colors are hard-coded instead of read from ConfirmationIcon.glyphColor, so the test can't agree with a wrong pick. Each case is drawn under both Aqua and Dark Aqua through a drawing(in:) helper. The luminance < 0.1 == 0 check for white glyphs stays.
  • StatusIconConfirmationTests.swift - Moves the fill-to-glyph projection out of glyphBounds into glyphCoverage(from:toward:), which the new check shares with it, and adds inkArea(in:coverage:within:).

Breaking Changes

None

Testing

  • Measured ink ratios of 0.990 to 1.009 for both glyphs, all three rings and both appearances, so the 10% tolerance has about 10x headroom
  • Mutations to ConfirmationIcon.draw fail the test: no glyph (0.0), glyph at half opacity (0.50), always-white glyph (0.0 on white), glyph moved 4 pt (0.67) and 20 pt (0.0) off center
  • swift test: 1269 tests, 0 failures
  • xcodebuild test with PRODUCT_BUNDLE_IDENTIFIER=com.epilande.Annotate.isotest: 1269 tests, 1 skipped, 0 failures
  • StatusIconConfirmationTests 10 times with swift test and 10 iterations with xcodebuild -test-iterations, all passing
  • SwiftLint: 0 violations

testTheGlyphIsDarkOnAWhiteRingAndWhiteOnTheUsualOnes counted pixels
past a brightness cutoff, which depends on the fill under the glyph's
antialiased edges. systemRed is a dynamic color and is lighter in Aqua,
so on a Mac in Light mode the saved glyph on red counted 18 bright
pixels instead of 33, under the 30 the test required.

The test now sums the glyph's ink inside the ring (each pixel's
coverage from the fill toward the expected glyph color) and compares it
with the symbol's own ink at the same size, in both Aqua and Dark Aqua.
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The test now measures glyph coverage relative to fill color and compares ring glyph ink area with standalone symbol ink area across Aqua and Dark Aqua appearances.

Changes: Glyph coverage validation

Layer / File(s) Summary
Measure glyph coverage across appearances
AnnotateTests/StatusIconConfirmationTests.swift
glyphCoverage projects pixel color onto the fill-to-glyph color span. inkArea sums coverage, with an optional circular region. drawing(in:_:) runs test bodies under a named appearance. Updated assertions compare saved and copied ring glyph coverage with standalone symbol ink area in Aqua and Dark Aqua.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Possibly related PRs

Merge Risk: Minimal · up to 84608

This PR only makes a flaky status-icon test deterministic across Aqua and Dark Aqua appearances. It does not change product behavior, and no merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the test change (deterministic status icon glyph test, in the test(capture) scope). The raw summary and objectives both describe replacing the brightness-threshold pixel count with a f…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the test change (deterministic status icon glyph test, in the test(capture) scope). The raw summary and objectives both describe replacing the brightness-threshold pixel count with a fractional ink-coverage comparison, which the title does not name directly but which is the mechanism behind the deterministic result. The title is specific and accurate about the main purpose of the change, so it is judged to pass.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 05a1b424-14ca-47dd-9dfa-501a557cb0bc
Commits

Reviewing files that changed from the base of the PR and between 8e56c55 and 8460821.

Files selected for processing: 1

  • AnnotateTests/StatusIconConfirmationTests.swift

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@epilande
epilande merged commit 9363e1d into main Nov 20, 2026
2 checks passed
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