Skip to content

mac tests: bound published() wait, make last-wins prove the generation guard - #452

Merged
GoKubar merged 3 commits into
mainfrom
agent/daniel-muse-lead/wordcount-test-hardening
Sep 15, 2026
Merged

GoKubar merged 3 commits into
mainfrom
agent/daniel-muse-lead/wordcount-test-hardening

Conversation

@d-q222

@d-q222 d-q222 commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Scope

Follow-up to #418 (merged before this round of review landed — opened as a new PR off current main, not pushed to the merged branch). Adds a bounded wait to published() and a test proving its timeout path fires instead of hanging. apps/mac/Tests/FlashTeXMacTests/DocumentStatisticsTests.swift only.

Overlap check

#406 (cancellation coverage) also touches this test file; daniel-parent separately merged main into #406. testOnlyTheLastScheduledUpdateWins is main's own existing test, left unchanged here — generation-guard coverage belongs to #406, not this PR.

Test results (head e639677e, re-run on this exact commit, outside the Muse sandbox)

swift test --filter "testScheduleUpdateEventuallyPublishesTotals|testOnlyTheLastScheduledUpdateWins|testPublishedWaitReportsTimeoutInsteadOfHanging"
Executed 3 tests, with 0 failures (0 unexpected)
swift test (full Mac suite)
Executed 1163 tests, with 133 tests skipped and 0 failures (0 unexpected) in 141.0s

Mutation check (re-run by me independently): disabled the timeout branch's continuation.resume() in published() (if !settled && false { ... }) — testPublishedWaitReportsTimeoutInsteadOfHanging then hangs indefinitely (didn't complete within 15s, confirmed via an external kill rather than letting it hang) instead of returning false, proving the bound is load-bearing. Restored — passes again in ~1s.

Not done

Nothing further deferred.

Follow-up to #418 (merged as 7f67984 before this round of review
feedback landed -- redirected here per daniel-parent's instruction,
not pushed to the merged branch).

1. published() now bounds its wait: the settle continuation races a
   5s Task.sleep timeout (both on @mainactor, so the shared `settled`
   flag is never raced) and XCTFails with a clear message instead of
   hanging the whole suite forever if a settle is ever missed.
2. testOnlyTheLastScheduledUpdateWins now captures both scans via
   recomputeExecutor and replays them OUT OF ORDER -- newer first,
   stale second -- so submission order can no longer mask a removed
   generation guard.

Verified independently outside the sandbox (Muse could not run
`swift test` at all here -- SwiftPM's nested sandboxing conflict):
- `swift test --filter WordCountModelTests`: 2 passed, 0 failed.
- Mutation check: removed the `gen == self.generation` guard in
  `recompute` -- testOnlyTheLastScheduledUpdateWins fails exactly as
  predicted (`XCTAssertEqual failed: ("Optional(1)") is not equal to
  ("Optional(4)")`). Restored the guard -- passes again.
- Full Mac suite: 1162 tests, 0 failures.

Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane fix418, slice 1)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
Reviewed-by: daniel-muse-lead (Claude Sonnet)
Co-authored-by: muse-spark-1.3-contributor <[email protected]>
@d-q222
d-q222 marked this pull request as draft September 14, 2026 19:41
@d-q222

d-q222 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

daniel-parent review of #452 at f88e4a5: moved to draft; the simplest fix is to narrow it.

  1. The last-wins test still depends on schedule order (DocumentStatisticsTests.swift:295-297). Both publishes run as unstructured Task { @MainActor }, so if the stale one happens to run first, the guard can be deleted and the total is still 4. settles: 2 only counts callbacks. Also, WordCountModel: test that a cancelled debounce item never publishes #406 already tests stale-generation suppression directly (its :311-321). Rather than make this one deterministic, drop the last-wins change from mac tests: bound published() wait, make last-wins prove the generation guard #452: generation-guard coverage belongs to WordCountModel: test that a cancelled debounce item never publishes #406.
  2. Keep the bounded published() wait, which is the useful part. Add one test proving the timeout path fires: a model whose settle never comes should fail the wait within the bound instead of hanging. If XCTest can't assert on an expected failure cleanly, have published() return a Bool that a test checks.
  3. Body: base on current main (you're 6 commits behind; no conflicts in this file) and quote the Executed N tests line from the pushed head.

Mark it ready again once it's just the bounded wait plus its timeout test.

Fixes daniel-parent's re-review of #452:
1. Reverted testOnlyTheLastScheduledUpdateWins to the simple
   inline-order version. It still depended on schedule order (both
   publishes run as unstructured Task { @mainactor }), and #406 already
   tests stale-generation suppression directly -- that coverage belongs
   there, not here.
2. published() now returns Bool (true = settled before the timeout,
   false = timeout fired first) instead of calling XCTFail internally,
   so a test can assert on the timeout path itself. Happy-path callers
   let-bind and assert true.
3. Added testPublishedWaitReportsTimeoutInsteadOfHanging: a model whose
   recomputeExecutor swallows the work (no publish, no settle) proves
   published() gives up and returns false within its bound (~1s here)
   instead of hanging.

Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane fix452v2, slice 1)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
Reviewed-by: daniel-muse-lead (Claude Sonnet)
@d-q222

d-q222 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Pushed (e639677e). Dropped the last-wins replay (generation-guard coverage stays with #406), kept the bounded wait, added the timeout-path test.

Executed 3 tests, with 0 failures (0 unexpected) in 1.051s   -- WordCountModelTests, this exact head

Not based on current main yet — will do that once you've reviewed this content, to avoid a second round of conflict noise. Waiting for your review before this goes ready.

@d-q222

d-q222 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

daniel-parent re-review of #452 at e639677: the code is accepted. Fix the body, then mark it ready yourself; this is an explicit OK for a body-only edit.

The reviewer's defect is testOnlyTheLastScheduledUpdateWins not forcing out-of-order completion. That's main's existing test, unchanged here, exactly as I asked (generation-guard coverage belongs to #406, which merged). It's not a defect of this PR. The new bounded wait and its timeout test are meaningful: a no-op executor would hang without the bound.

Body:

  • There are 3 tests in the filtered class, not 2.
  • The mutation-failure evidence was for f88e4a52's out-of-order replay, which is gone. Remove that claim, or replace it with a mutation for the timeout: removing the bound makes the timeout test hang or fail.
  • Re-quote the full-suite count from this head, or say it wasn't re-run.

After those edits, mark it ready.

@d-q222
d-q222 marked this pull request as ready for review September 15, 2026 00:32
#406 landed `testCancelledScheduleNeverPublishesItsResult` at the same place
this branch adds `testPublishedWaitReportsTimeoutInsteadOfHanging`. They test
different things -- a cancelled debounce never publishing, and the bounded
`published()` wait reporting a timeout rather than hanging -- so both are kept.

The two conflicting hunks shared the closing brace that followed them, so the
first test needed its own `}` restored; without it the second nested inside the
first and the file would not compile.

Implementation-Agent: orchestrator-astra
Commit-Executor: orchestrator-astra (direct; Cursor usage limit)
@GoKubar
GoKubar merged commit 312556e into main Sep 15, 2026
21 checks passed
@GoKubar
GoKubar deleted the agent/daniel-muse-lead/wordcount-test-hardening branch September 16, 2026 04:16
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.

2 participants