Skip to content

refactor(game): extract undo.ts + drop undo as-any casts (Phase 2 of #132)#137

Merged
nodots merged 2 commits into
refactor/game-decomp-phase1-guardsfrom
refactor/game-decomp-phase2-undo
Jul 15, 2026
Merged

refactor(game): extract undo.ts + drop undo as-any casts (Phase 2 of #132)#137
nodots merged 2 commits into
refactor/game-decomp-phase1-guardsfrom
refactor/game-decomp-phase2-undo

Conversation

@nodots

@nodots nodots commented Jul 15, 2026

Copy link
Copy Markdown
Owner

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

Stacked on #136 (Phase 1). Base is refactor/game-decomp-phase1-guards; retarget to development once #135 and #136 merge.

Depends on backgammon-types PR nodots/backgammon-types#68 — the undo.frames typing must land (and publish) for the cast removal to typecheck against the released types package.

What changed

  1. Characterization tests first (test: expand core coverage, starting with Game/index.ts extraction targets #134) — 10 tests locking current behavior of Game.canUndoActivePlay / Game.undoLastInActivePlay (defensive/guard branches + a real-move push→pop happy path).
  2. New src/Game/undo.tsundoLastInActivePlay and canUndoActivePlay as free functions.
  3. as any removal (chore: Eliminate as any casts in Game/index.ts with proper type definitions #96) — with undo.frames now typed BackgammonGameMoving[] on BasePlay, the functions read game.activePlay.undo.frames directly; 5 casts removed from the undo slice.
  4. Public Game.* statics remain thin delegating wrappers. canUndoActivePlay (deferred from the guards phase) lands here with its concern.

Verification

  • tsc -b --force clean
  • npx jest: 458 passed / 12 skipped (448 baseline + 10 new)
  • No behavior change; public Game.* surface unchanged

Refs #132, #96, #134

nodots added 2 commits July 15, 2026 09:10
Lock in current behavior of Game.canUndoActivePlay and
Game.undoLastInActivePlay before refactoring: defensive/guard branches
and the real-move happy path (snapshot push -> undo pop). 10 tests.

Refs #132, #134
Move undoLastInActivePlay and canUndoActivePlay into src/Game/undo.ts as
free functions. Now that types promotes undo.frames to a typed
BackgammonGameMoving[] on BasePlay, the functions read
game.activePlay.undo.frames directly with no 'as any' casts (removes 5
casts from the undo slice of #96). The public Game.* statics remain as
thin delegating wrappers; canUndoActivePlay (deferred from guards) lands
here with its concern.

Depends on backgammon-types refactor/undo-frames-typed.
Characterization tests (10) added in the prior commit stay green.

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

Refs #132, #96
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