Skip to content

Saved-game loader: move-history and undo-stack rejection paths never run #141

Closed

Description

@TMHSDigital

Summary

validateSavedGame reads data the app saved to localStorage, and most of its reject branches are never run by a test. In particular, the whole move-history check is unhit. The existing "bad saved value" cases are rejected earlier, by the board check, before moveHistory is ever looked at.

Where

  • js/saved-game.js:91-101 (move-history check: the return null at line 100 is never executed)
  • js/saved-game.js:31, 64, 68, 107-122, 139, 164 (other unhit branches)
  • Existing tests: tests/unit/persistence.test.js:82-110, tests/unit/no-dom.test.js:351-364

Impact

If these checks were weakened or reordered in a refactor, CI would still pass, and a damaged save could load into the live game.

Suggested fix

Add a table-driven describe('validateSavedGame rejects', ...) to tests/unit/no-dom.test.js. Start each case from a sound save (initialPosition().board, currentPlayer: 'w') and change one field:

  • moveHistory: 'x' -> null
  • moveHistory: [null], [{}], a move with to.row: 8, a move with notation: 5 -> null each
  • moveHistory omitted -> loads with moveHistory: []
  • a board row of length 7 -> null; a cell {type:'x', color:'w'} -> null
  • enPassantTarget: {row: 9, col: 0} -> null
  • positionHistory of the right length with one null entry -> loads with positionHistory: []
  • a position with no legal moves and not in check, no gameResult, last move without isCheckmate -> gameResult: '1/2-1/2'; with last.isCheckmate and currentPlayer: 'b' -> '1-0'
  • clock {running: true} on a finished game -> turnStartedAt: null; control: 5 -> control: ''
  • players: {computer: 'x', level: 'hard'} and {computer: 'w', level: 'HARD!'} -> players: null

Acceptance criteria

  • Every return null in validateSavedGame is covered
  • saved-game.js branch coverage above 95%

Getting started

  • Relevant files: js/saved-game.js, tests/unit/no-dom.test.js
  • How to run tests: npm ci && npm run coverage

Filed by repo-audit/full-audit at 73cd279. Severity: medium. Effort: S. audit-key: testing|js/saved-game.js|validateSavedGame

Activity

  1. added
    good first issue
    testing
    severity: medium
    on Nov 17, 2026
  2. TMHSDigital commented on Nov 17, 2026

    @TMHSDigital
    OwnerAuthor

    Fixed in 8b78b42: table-driven validateSavedGame cases in tests/unit/no-dom.test.js cover every return null (move history, board rows and cells, en passant square) plus the undo-stack, clock, start and players fallbacks. saved-game.js: 100% statements, 97.7% branches from that file alone. Lint and format pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueseverity: mediumtesting

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions