fix(tests): serialize AffordanceRegistry tests to remove flake - #20
Conversation
`booted simulator apiLinks include plugin stream when registered` and `booted simulator affordances include plugin stream when registered` failed intermittently under parallel scheduling. AffordanceRegistry is process-global mutable state. AffordanceRegistryTests is `@Suite(.serialized)` and resets the registry in `init()`, while SimulatorTests is a plain parallel `@Suite` whose plugin tests register a provider and then read the result. `.serialized` only orders tests *within* a suite — separate suites still run concurrently, so the reset lands between another suite's `register()` and its assertion and the affordance reads back nil. The `.serialized` trait on the individual test functions does not help: it scopes parameterized cases, not cross-test isolation, so the three Simulator plugin tests were also racing each other. Move the three registry-touching Simulator tests into the serialized AffordanceRegistryTests suite so every test that mutates the global registry shares one serial scope. Assertions are unchanged; the redundant inline `reset()` calls are dropped since the suite's `init()` already resets. Measured with `swift test --filter "SimulatorTests|AffordanceRegistryTests"`, 20 runs each: 15/20 failed before, 0/20 after. Full suite 5/5 green, 2383 tests unchanged. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe changes move simulator plugin affordance tests to ChangesSimulator affordance registry coverage
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #20 +/- ##
=======================================
Coverage 81.54% 81.54%
=======================================
Files 453 453
Lines 13441 13441
=======================================
Hits 10960 10960
Misses 2481 2481 🚀 New features to boost your workflow:
|
Problem
Two tests fail intermittently under parallel scheduling:
booted simulator apiLinks include plugin stream when registeredbooted simulator affordances include plugin stream when registeredRoot cause
AffordanceRegistry(Sources/Domain/Shared/AffordanceRegistry.swift) is process-global mutable state. Two suites inDomainTeststouch it:AffordanceRegistryTests—@Suite(.serialized), callsAffordanceRegistry.reset()ininit()before every testSimulatorTests— plain parallel@Suite; three testsregister()a provider and then assert on the merged affordance.serializedonly orders tests within a suite — separate suites still run concurrently. SoAffordanceRegistryTests.init()'sreset()lands betweenSimulatorTests'register()and its assertion, and the affordance reads backnil.The
.serializedtrait on the individual test functions does not help here: it scopes parameterized cases, not cross-test isolation. That's why the three Simulator plugin tests were also racing each other — both affected tests register a provider forSimulatorand reset at entry.Fix
Move the three registry-touching Simulator tests into the serialized
AffordanceRegistryTestssuite, so every test that mutates the global registry shares one serial scope.reset()calls are dropped; the suite'sinit()already resets.Test-only change; no production code touched.
Tests/ASCCommandTests/.../SimulatorsListTests.swiftalso callsreset(), but it never registers a provider and nothing else in that target does either, so it is unaffected and left alone.Verification
swift test --filter "SimulatorTests|AffordanceRegistryTests", 20 runs each:Full suite: 5/5 green, 2383 tests — unchanged count.
🤖 Generated with Claude Code
Summary by CodeRabbit