Skip to content

fix(test): deterministic shimmer state-machine tests (kills the wall-clock flake) - #7

Merged
wei18 merged 1 commit into
mainfrom
fix/practice-hub-flaky-test
May 20, 2026
Merged

wei18 merged 1 commit into
mainfrom
fix/practice-hub-flaky-test

Conversation

@wei18

@wei18 wei18 commented May 20, 2026

Copy link
Copy Markdown
Owner

Summary

Replace the flaky wall-clock `overThresholdDrawShowsShimmer` test with two deterministic state-machine tests.

Diagnosis

The previous test relied on wall-clock timing to catch an intermediate state:

```swift
let drawTask = Task { await viewModel.drawPuzzle() }
try? await Task.sleep(nanoseconds: 400_000_000)
let mid = viewModel.loadingState // expect .drawingShimmer
```

Internally `drawPuzzle` spawns a `shimmerTask` that sleeps 50ms then calls `promoteToShimmer()`. Under parallel `@MainActor` contention (many SudokuUI snapshot suites run concurrently and hold the global main actor for tens of ms each during `NSHostingView` rendering), the 50ms shimmer wake-up can be deferred past the test's 400ms read. State stays at `.drawingQuiet` → test fails. Passes 3/3 when run alone (no contention).

Fix

Split into two deterministic tests on the only state-machine branch the timer was verifying:

Test Asserts
`promoteToShimmerFlipsFromDrawingQuiet` `setLoadingStateForTesting(.drawingQuiet)` then `promoteToShimmer()` → state == `.drawingShimmer`
`promoteToShimmerNoOpFromNonQuietStates` `.idle` and `.failed` states unchanged by `promoteToShimmer()`

The "drawPuzzle actually spawns the shimmer task" integration concern remains covered by `subThresholdDrawSkipsShimmer`: if the timer gating were broken there, the sub-threshold path would land on `.drawingShimmer` instead of `.drawn`.

Verified

3 consecutive full-suite runs: 336/336 each (one test replaced with two, so net +1).

🤖 Generated with Claude Code

The previous overThresholdDrawShowsShimmer test was flaky under parallel
@mainactor contention: it kicked off drawPuzzle, slept 400ms, and asserted
the state was .drawingShimmer. The internal 50ms shimmer-wake task races
with whatever other @mainactor suites are running, and the global main
actor schedulers don't guarantee 50ms wake-up under heavy contention.
When the wake-up slipped past 400ms, the state was still .drawingQuiet
and the test failed.

Replace with two deterministic tests on the only branch the timer was
verifying (the promoteToShimmer state machine):

- promoteToShimmerFlipsFromDrawingQuiet: drive state to .drawingQuiet via
  the existing setLoadingStateForTesting seam, call promoteToShimmer,
  assert state == .drawingShimmer.
- promoteToShimmerNoOpFromNonQuietStates: drive state to .idle and
  .failed, call promoteToShimmer, assert no transition (the if-case
  guard inside promoteToShimmer).

The integration concern (drawPuzzle actually spawns the shimmer task)
remains covered by subThresholdDrawSkipsShimmer: if the timer gating
were broken, that test would land on .drawingShimmer instead of .drawn
under its sub-threshold delay.

Verified 3 consecutive full-suite runs: 336/336 each (335 + 1 from
split). Test count went up by 1 because we replaced one test with two.
@wei18
wei18 merged commit 819f04f into main May 20, 2026
@wei18
wei18 deleted the fix/practice-hub-flaky-test branch May 20, 2026 03:30
wei18 added a commit that referenced this pull request May 20, 2026
methodology.md gains dispatch contract item #7 + a new pattern documenting
how Phase 8 Part 1 sidebar stub slipped through to v1 feature-complete.

subagent-review-cycles skill gets a Phase TODO sweep checklist section.

impl-notes: meetings/2026-05-20_phase-todo-sweep-convention.impl-notes.md
wei18 added a commit that referenced this pull request May 20, 2026
methodology.md gains dispatch contract item #7 + a new pattern documenting
how Phase 8 Part 1 sidebar stub slipped through to v1 feature-complete.

subagent-review-cycles skill gets a Phase TODO sweep checklist section.

impl-notes: meetings/2026-05-20_phase-todo-sweep-convention.impl-notes.md
wei18 added a commit that referenced this pull request Jun 2, 2026
…st launch (#256)

* spec(adgate): remove 7-day grace period — banner always shows from first launch (#212)

User spec change 2026-06-02: drop the original "first-7-days no ads"
onboarding rule entirely. Banner appears from first launch, capped at
1/day with dismissed-that-day skip and Remove-Ads-IAP override
unchanged.

Code:
- AdGate.gracePeriodDays stays at 0 (was being restored to 7 per
  pre-change #212 spec — that ask is now withdrawn)
- shouldShowBanner() arithmetic branch retained as 0-valued knob so
  re-introducing a grace is one constant flip
- 4 disabled grace-boundary tests removed (no longer policy);
  bannerAlwaysVisibleAfterFirstLaunch smoke test added

Docs (user-facing):
- docs/privacy-policy.md — short notice + en + zh-Hant body updated to
  "Ads appear from first launch" (release-critical legal claim — was
  promising "first 7 days no ads"; would mismatch shipped behaviour)

Docs (internal):
- docs/v2/design.md — rule #6/#7, AdGateOutcome enum comment, the
  inline pseudo-code grace branch, wall-clock-bypass rationale, and
  the §決策 origin table all updated to reflect 0-grace policy
- docs/v2/plan.md — v2.5.2 phase description updated
- docs/v2/v2.5-readiness.md — manual-test checklist trimmed
  (T+0 should show banner; +8-days step removed)
- AdGate.swift inline comments

Tests: 16/16 AdGateLogicTests pass on this branch.

Closes #212 (with the policy spec inverted from the original ask).

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(docs): repair stale link paths from App/ → Sudoku/ rename + AdMob manifest URL

Pre-existing broken links surfaced by lychee on this PR because the
two files were modified for the gracePeriodDays spec change. None
of these breakages were introduced here; just cleaned up while in
the same diff.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

* fix(docs): drop unstable AdMob URL (was 404 in lychee)

---------

Co-authored-by: Claude Opus 4.7 <[email protected]>
wei18 added a commit that referenced this pull request Jun 3, 2026
…0) (#282)

* fix(minesweeper): scale board + add reveal/flag mode toggle (refs #278)

Tier-0 UX blockers from the Designer critique (#278), all in
MinesweeperBoardView. Three coupled fixes, one dispatch:

#1 Board scaling. The cell button was hardcoded frame(30,30) inside a
naked VStack/HStack with no GeometryReader, so Expert (16x30 ~ 960pt)
overflowed every iPhone and most Mac windows. The grid is now wrapped in
a GeometryReader that derives a single square cell side fitting the
NON-square board by its longer axis:
  cellSide = floor(min(availW/cols, availH/rows))
where availW/availH subtract the inter-cell spacing first. The cell
frame and the number/flag/mine glyph (font ~ cellSide * 0.55, replacing
the literal 16) both scale from it.

#2 Tap-target floor. minCellSide = 32pt. When the fitted side would drop
below the floor (e.g. Expert on iPhone fits ~10pt), cellSide is clamped
to 32 and the board scrolls (ScrollView([.horizontal,.vertical]))
instead of shrinking into an un-tappable grid. When it fits, the
ScrollView is inert.

#3 Discoverable reveal/flag toggle. Added an on-screen segmented Picker
(Reveal / Flag) above the board, modeled on Sudoku's pencil-mode toggle.
In Flag mode a tap flags; in Reveal mode a tap reveals. Long-press (iOS)
and right-click contextMenu (Mac) stay as flag accelerators in either
mode — Mac users no longer depend on an invisible right-click. Mode is
view-local @State (no engine semantics). Added .contentShape(Rectangle)
so the whole cell square is hit-testable.

Deferred: Tier-1 theme tokens, Tier-2 Mac side-rail (#6), win/lose
overlay (#7), VoiceOver (#10), .task loop cleanup (#9) — separate
dispatches.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* fix(minesweeper): address #278 Tier-0 CR — flag double-toggle + fit centering

CR REQUEST-CHANGES:
- iOS .flag-mode long-press double-toggle: in .flag mode the button tap +
  long-press both fired onToggleFlag, netting a no-op. Long-press now only
  flags in .reveal mode (redundant in .flag mode where tap already flags).
- Fitted board was pinned top-leading; now center the floored grid in the
  offered rect (mirrors Sudoku BoardView), only scrolling when clamped to floor.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
wei18 added a commit that referenced this pull request Jun 4, 2026
…#298 #7 #8)

#7: on a loss, surface every mine, not just the detonated cell. No engine
accessor needed — the actor snapshot already carries the full cells array
with isMine populated once mines are placed, so the renderer paints still-
hidden mines from cell.isMine when status == .lost. Detonated cell keeps
the bold mineHit red; surfaced mines use the soft mine fill. Correctly-
flagged mines keep their flag glyph. The Completion overlay (#292) sits on
top via the outer overlay, so the revealed board shows behind it.

#8 (partial): swap the mine glyph burst.fill -> xmark.octagon.fill for a
clearer hazard read. The covered-vs-revealed contrast raise + raised-tile
bevel are deferred — they churn the covered-board snapshot baseline, which
the sandbox can't re-record (see impl-notes).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
wei18 added a commit that referenced this pull request Jun 4, 2026
* feat(minesweeper): Mac side-rail 2-column board layout (refs #298 #6)

Add a horizontalSizeClass == .regular branch to MinesweeperBoardView so
the Mac/iPad detail pane no longer renders the iPhone vertical stack.
Mirrors Sudoku's BoardView.macLayout: centered + size-capped board (600pt
square) on the left, a 260pt control rail on the right carrying the status
bar + Reveal/Flag toggle (MS has no digit pad). Outer width capped at
900pt and centered.

Compact (iPhone) layout extracted unchanged; spacing literal 12 preserved
verbatim so the recorded covered-board snapshots don't churn. New Mac
layout uses theme.spacing tokens.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* feat(minesweeper): reveal all mines on loss + clearer mine glyph (refs #298 #7 #8)

#7: on a loss, surface every mine, not just the detonated cell. No engine
accessor needed — the actor snapshot already carries the full cells array
with isMine populated once mines are placed, so the renderer paints still-
hidden mines from cell.isMine when status == .lost. Detonated cell keeps
the bold mineHit red; surfaced mines use the soft mine fill. Correctly-
flagged mines keep their flag glyph. The Completion overlay (#292) sits on
top via the outer overlay, so the revealed board shows behind it.

#8 (partial): swap the mine glyph burst.fill -> xmark.octagon.fill for a
clearer hazard read. The covered-vs-revealed contrast raise + raised-tile
bevel are deferred — they churn the covered-board snapshot baseline, which
the sandbox can't re-record (see impl-notes).

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* feat(minesweeper): VoiceOver labels + flag action on board cells (refs #298 #10)

Mirror Sudoku's BoardCellView AX. Each cell collapses into one element with
a "Row R, Column C, <state>" label (1-based, state covers hidden/flagged/
N/empty/mine incl. the lost-mine surfacing), the .isButton trait, and a
named Flag/Unflag accessibilityAction so VoiceOver users can flag without
the long-press / right-click accelerators (which VO can't reach). Flag
action is inert on revealed cells and once the board is terminal.

Threads zero-based row/column into MinesweeperCellButton from the grid.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* refactor(minesweeper): replace TimelineView ticker with .task(id:) loop (refs #298 #9)

The status bar drove its 1 Hz elapsed refresh via a TimelineView whose
nested .task re-fired on every timeline tick (a .task re-fire footgun).
Replace with Sudoku BoardView's pattern: a single .task(id:) on the body
owning a `while !Task.isCancelled { if playing { refresh }; sleep(1) }`
loop, cancelled automatically on disappear, keyed on the VM identity so
Retry restarts it. Status bar is now a plain HStack reading the @observable
snapshot. Non-visible; correctness/perf only.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* refactor(minesweeper): board outer padding via theme spacing token (refs #298 #11)

Migrate MinesweeperBoardView's outer .padding() to theme.spacing.medium
(value-identical 16, no snapshot churn) and the new Mac layout to the
spacing scale. The compact VStack(spacing: 12) literal is deferred — it's
the only remaining spacing-scale literal and migrating it churns the
covered-board snapshot baseline (sandbox can't re-record). Grid geometry
constants (minCellSide, cellSpacing, cornerRadius) are tap-target/shape
values, left as literals. Also seals the #298 impl-notes.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
@wei18 wei18 mentioned this pull request Jul 9, 2026
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