Skip to content

tests: pin _enableExperimentalOptimizations = true via subclass of ModelStateLayoutTests#161

Open
tsushanth wants to merge 1 commit into
airbnb:masterfrom
tsushanth:tests/experimental-optimizations-parity
Open

tests: pin _enableExperimentalOptimizations = true via subclass of ModelStateLayoutTests#161
tsushanth wants to merge 1 commit into
airbnb:masterfrom
tsushanth:tests/experimental-optimizations-parity

Conversation

@tsushanth

Copy link
Copy Markdown

Why

MagazineLayout._enableExperimentalOptimizations is documented in MagazineLayout.swift as "A temporary flag to enable safely testing some optimizations" (added in #156). The flag now gates 35+ branches across MagazineLayout.swift, SectionModel.swift, and ModelState.swift, but no existing test exercises it.

Without automated coverage of the optimized code paths, flipping the default to true is risky — any divergence between the optimized and legacy paths can land silently.

What

Adds ModelStateLayoutTestsWithExperimentalOptimizations, a subclass of ModelStateLayoutTests that flips the flag in setUp and restores it in tearDown. XCTest reruns every inherited test method against the optimized path, so any divergence between the two paths now fails a test.

Verified locally on iOS Simulator (iPhone 17 Pro, iOS 26.4): ModelStateLayoutTests (11 tests, flag = false) + ModelStateLayoutTestsWithExperimentalOptimizations (11 tests, flag = true) = 22 tests, 0 failures.

Mechanical changes:

  • Drop final from ModelStateLayoutTests so it can be subclassed (test-only file; production code untouched).
  • Add a 47-line subclass that overrides setUp / tearDown.
  • Wire the new file into the Xcode test target.

Scope

Intentionally narrow — this is the smallest wedge that validates the approach. If you're happy with the pattern, the same subclass-and-flip approach extends naturally to:

  • ModelStateUpdateTests
  • ElementLocationFramePairsTests
  • LayoutStateTargetContentOffsetTests
  • ModelStateEmptySectionLayoutTests
  • ModelStateInitiallSetUpTests

Happy to push a follow-up PR with those once you confirm the direction. I kept this one small so it's easy to review and so any feedback on the pattern lands once, not five times.

What this enables

Once test coverage of the optimized path exists, flipping the default of _enableExperimentalOptimizations to true becomes a one-line PR that you can confidently land. Eventually the flag can be removed entirely.

…delStateLayoutTests

`MagazineLayout._enableExperimentalOptimizations` is documented in
`MagazineLayout.swift` as "A temporary flag to enable safely testing some
optimizations" (added in airbnb#156). The flag gates 35+ branches across
`MagazineLayout.swift`, `SectionModel.swift`, and `ModelState.swift`, but
no existing test exercises it. Flipping the default is risky without
automated coverage of the optimized code paths.

This change adds `ModelStateLayoutTestsWithExperimentalOptimizations`,
which subclasses `ModelStateLayoutTests` and flips the flag in `setUp`
(restoring `false` in `tearDown`). XCTest reruns every inherited test
method against the optimized path. Any divergence between the optimized
and legacy paths now fails a test.

Mechanically:
- Drop `final` from `ModelStateLayoutTests` so it can be subclassed
  (test-only change; production code unaffected)
- Add a single 47-line subclass file that overrides `setUp` / `tearDown`
- Wire the new file into the Xcode test target

Verified locally: ModelStateLayoutTests (11 tests, flag=false) +
ModelStateLayoutTestsWithExperimentalOptimizations (11 tests, flag=true)
= 22 tests, 0 failures.

This is a starting wedge — if accepted, the same pattern can extend to
`ModelStateUpdateTests`, `ElementLocationFramePairsTests`,
`LayoutStateTargetContentOffsetTests`, etc. Happy to follow up with
those in a separate PR once you confirm the approach.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tsushanth

Copy link
Copy Markdown
Author

Filed a broader proposal at #162 that frames this PR as Phase 1 of a path to flipping the flag and eventually removing it. Cross-linking so the PR and the proposal sit in each other's context.

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