Skip to content

refactor: let tests drive the hover delays with a clock of their own - #491

Merged
M4n0x merged 1 commit into
mainfrom
refactor/test-clock
Nov 8, 2026
Merged

M4n0x merged 1 commit into
mainfrom
refactor/test-clock

Conversation

@M4n0x

@M4n0x M4n0x commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

Problem

DECISIONS.md settles that code whose tests depend on time takes a clock, with the test clock in the repository. WidgetPopup's hover delays slept on the real clock. So the tests that check them either slept for real or, in the two tests that reproduce #482's race, blocked the main actor with Thread.sleep for 250 ms. That adds the very main-actor contention that made tests flaky on CI.

Changes

  • WidgetPopup takes a clock (any Clock<Duration>, ContinuousClock() by default) for its three hover waits: the hover delay, the 200 ms steps of the path into a popup, and the close delay. The app behaves as before. Animation waits stay on the real clock.

  • TestClock, in the tests:

    • it moves only when a test advances it;
    • it reports how many tasks are sleeping on it;
    • it handles a cancel that comes before a sleep is registered.

    Four tests cover it.

  • aHoverCancelledAfterItsWaitRanOutDoesNotShow and aPopupEnteredAfterItsCloseDelayRanOutStaysOpen use it instead of holdMainActor, which is gone. They wait until the hover task is sleeping (and require it), advance the clock so the wait ends, then move into the popup before the main actor runs what's left. That's exactly A cancelled hover can still show a tooltip or close its popup when the Mac is busy #482's race, with nothing blocked.

  • Not in this pull request: hoveringPopupsWaitsAndKeepsBothTheWidgetAndPopupReachable and the hover triangle test still sleep for real. Moving them, then the expiry and failure-streak timers, comes next.

Testing

  • The TestClock tests and both converted tests pass.
  • With the two try Task.checkCancellation() lines from fix: keep a cancelled hover from showing a tooltip or closing its popup late #483 removed, both converted tests failed 3 of 3 runs. I put the lines back.
  • Full local run: everything passes except the three tests that fail without this change on this Mac (pinnedPopupsStayOnScreenAndReturnUnderTheirWidget and the two package review tests).

Merging

One commit; any merge method works.

Claude Opus 5.5 via Claude Code

WidgetPopup's hover delays waited on the real clock, so tests of them slept, or blocked the main
actor to line up a race. WidgetPopup now takes a clock, the real one by default, and TestClock in
the tests moves only when a test advances it. The two late-cancel tests use it instead of holding
the main actor, and still fail without the cancellation checks from #483.
@M4n0x
M4n0x requested a review from Seb-GRAF as a code owner November 8, 2026 13:09
@coderabbitai

coderabbitai Bot commented Nov 8, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

WidgetPopup now accepts a clock dependency and uses it for hover-related waits. Tests add a manually advanced TestClock and use it to check sleep deadlines, cancellation, hover behavior, and popup-close timing.

Changes: Popup hover timing

Layer / File(s) Summary
Inject clock for popup waits
Sources/StableBar/WidgetPopup.swift
WidgetPopup accepts a Clock<Duration> with a ContinuousClock() default. The initial hover delay, hover-path polling, and delayed-close wait use the injected clock.
Control hover timing in tests
Tests/StableBarTests/TestClock.swift, Tests/StableBarTests/PresentationIntegrationTests.swift
TestClock supports manually advanced deadlines and cancellation. Integration tests inject it to check hover cancellation and popup-close timing without blocking the main actor or waiting in real time.

Possibly related issues

  • Issue 482 describes a cancelled hover wait that can still run its tooltip or close action while the main actor is busy. This PR changes the tests for that scenario to use TestClock.

Possibly related PRs

  • Seb-GRAF/StableBar#483: Adds cancellation checks and regression tests that this PR converts to use TestClock.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 2dcd5

Popup timing retains its production default, and no actionable merge-blocking risk is established. The change is ready for normal merge checks.

Security architecture risk: Minimal · up to 2dcd5

The change makes hover timing controllable in tests while preserving the production clock, action guards, and cancellation checks. No material security risk was identified in the changed behavior.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed authority is limited to selecting the timing dependency during in-process popup construction. The inspected production callers retain the default; the change does not provide an external input path for selecting an arbitrary clock.

Trust Boundaries and Controls

  • observed — The injected clock is private and immutable after initialization. Existing main-actor isolation, widget-action gating, and post-wait cancellation checks remain in place; none is delegated to the clock implementation.

Resilience and Maintainability Implications

  • inferred — The retained post-wait checks contain the cancellation-after-timer-fire race even if a sleep resumes successfully. Task replacement, re-entry cancellation, and close cleanup retain their previous ownership and terminal-state behavior.
Pre-merge checks: Passed 3

Check name Status Explanation
Description check Passed The description follows the repository template closely. It has Problem, Changes, Testing, and Merging sections, and it ends with the model and harness line that the Description check reads. The Probl…
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: Description check

Explanation

The description follows the repository template closely. It has Problem, Changes, Testing, and Merging sections, and it ends with the model and harness line that the Description check reads. The Problem section explains the time-dependent test issue, and it links to #482 but does not use a closing keyword such as "Fixes #" for an issue. The Changes section lists the WidgetPopup clock injection, the TestClock helper, and the converted tests, and it explains the scope exclusions. The Testing section reports the TestClock tests, the converted tests, the cancellation-check regression run, and the full local run with three named failing tests. It does not describe any visible UI change, so the screenshot and scene requirement does not apply. The Merging section states that one commit exists and that any merge method works. The Title line is not part of the description body, so the title is outside this check. The description is complete and specific, so it passes.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

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

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1181904 and 2dcd541.

Files selected for processing: 3

  • Sources/StableBar/WidgetPopup.swift
  • Tests/StableBarTests/PresentationIntegrationTests.swift
  • Tests/StableBarTests/TestClock.swift

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

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Before and after

main at 1181904 → this pull request at 2dcd541 · 50 screens drawn in one CI job · 0 changed

50 unchanged screens

docs/essentials-clock-settings-dark, docs/essentials-clock-settings-light, docs/essentials-dark, docs/essentials-light, docs/essentials-settings-dark, docs/essentials-settings-light, docs/hero-dark, docs/hero-light, docs/popups-dark, docs/popups-light, docs/settings-dark, docs/settings-light, docs/themes-dark, docs/themes-light, scenes/app-menu-popup-dark, scenes/app-menu-popup-light, scenes/apple-menu-settings-dark, scenes/apple-menu-settings-light, scenes/crowded-edit-bar-dark, scenes/crowded-edit-bar-light, scenes/dock-badges-bar-dark, scenes/dock-badges-bar-light, scenes/essentials-clock-popup-dark, scenes/essentials-clock-popup-light, scenes/gruvbox-bar-dark, scenes/gruvbox-bar-light, scenes/horizontal-list-popup-dark, scenes/horizontal-list-popup-light, scenes/settings-bar-dark, scenes/settings-bar-light, scenes/settings-bar-placement-dark, scenes/settings-bar-placement-light, scenes/settings-general-dark, scenes/settings-general-light, scenes/settings-general-spaces-dark, scenes/settings-general-spaces-light, scenes/settings-theme-dark, scenes/settings-theme-light, scenes/settings-uninstall-dark, scenes/settings-uninstall-failed-dark, scenes/settings-uninstall-failed-light, scenes/settings-uninstall-light, scenes/slider-end-stop-popup-dark, scenes/slider-end-stop-popup-light, scenes/starter-bar-dark, scenes/starter-bar-light, scenes/starter-edit-bar-dark, scenes/starter-edit-bar-light, scenes/update-popup-dark, scenes/update-popup-light

Visual review: 50 screens, none changed.

@M4n0x
M4n0x merged commit e630e3e into main Nov 8, 2026
15 checks passed
@M4n0x
M4n0x deleted the refactor/test-clock branch November 8, 2026 13:33
M4n0x added a commit that referenced this pull request Nov 8, 2026
…te API rule

Betas of 0.9.0 built after #337 skip unknown properties too. #490 put every private call in
PrivateAPI.swift, and #491 added the test clock, so the entries now say so and link them.
@stablebar-releases

Copy link
Copy Markdown

🎉 This PR is included in version 0.12.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant