Skip to content

refactor(game): extract lifecycle.ts standalone transitions (Phase 4 of #132)#139

Merged
nodots merged 2 commits into
refactor/game-decomp-phase2-undofrom
refactor/game-decomp-phase4-lifecycle
Jul 15, 2026
Merged

refactor(game): extract lifecycle.ts standalone transitions (Phase 4 of #132)#139
nodots merged 2 commits into
refactor/game-decomp-phase2-undofrom
refactor/game-decomp-phase4-lifecycle

Conversation

@nodots

@nodots nodots commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Phase 4 of the Game/index.ts decomposition epic (#133)

Stacked on #138 (Phase 3). Base is refactor/game-decomp-phase3-cube; retarget to development as parents merge.

Scope decision

Game.initialize and Game.createNewGame stay on the class — they drive the new Game() constructor path (PositionReconstructor, the gnuPositionId getter consumed in ai/api) and the overloaded initialize signature. This phase extracts only the clearly-standalone lifecycle transitions.

What changed

  1. Characterization tests first (test: expand core coverage, starting with Game/index.ts extraction targets #134) — restoreState had zero coverage; added 7 tests locking every validation guard branch + the valid-state passthrough. rollForStart is already well-covered by existing suites.
  2. New src/Game/lifecycle.tsrollForStart and restoreState as free functions. rollForStart self-recurses on a tie via the module-local function (Rule A).
  3. Public Game.* statics remain thin delegating wrappers.
  4. Removed two now-dead imports from index.ts (RESTORABLE_GAME_STATE_KINDS, BackgammonPlayerRollingForStart).

Verification

  • tsc -b --force clean
  • npx jest: 475 passed / 12 skipped (468 baseline + 7 new)
  • No behavior change; public API unchanged

Refs #132, #134

nodots added 2 commits July 15, 2026 09:27
restoreState had no coverage. Lock in all validation guard branches
(null state, missing stateKind/board/cube, wrong player count,
non-restorable stateKind) and the valid-state passthrough. 7 tests.
rollForStart is already well-covered by existing suites.

Refs #132, #134
#132)

Move the standalone lifecycle transitions rollForStart and restoreState
into src/Game/lifecycle.ts as free functions. Public Game.* statics
remain thin delegating wrappers (external ai/api/client callers
unchanged). rollForStart self-recurses on a tie via the module-local
function (Rule A). Removed two now-dead imports from index.ts
(RESTORABLE_GAME_STATE_KINDS, BackgammonPlayerRollingForStart).

Game.initialize and Game.createNewGame stay on the class: they drive the
new Game() constructor path (PositionReconstructor, gnuPositionId getter)
and the overloaded initialize signature.

Faithful move; pre-existing casts preserved. Characterization tests for
restoreState (7) added in the prior commit stay green.

No behavior change. Core: 475 passed / 12 skipped, tsc -b clean.

Refs #132, #134
Base automatically changed from refactor/game-decomp-phase3-cube to refactor/game-decomp-phase2-undo July 15, 2026 18:34
@nodots
nodots merged commit e5e7df0 into refactor/game-decomp-phase2-undo Jul 15, 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