Repository navigation
Closed
Labels
good first issueGood for newcomersseverity: mediumEdge-case bugs or meaningful maintainability costtestingTest coverage and test quality
Description
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: thereturn nullat 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 withto.row: 8, a move withnotation: 5-> null each -
moveHistoryomitted -> loads withmoveHistory: [] - a board row of length 7 -> null; a cell
{type:'x', color:'w'}-> null -
enPassantTarget: {row: 9, col: 0}-> null -
positionHistoryof the right length with onenullentry -> loads withpositionHistory: [] - a position with no legal moves and not in check, no
gameResult, last move withoutisCheckmate->gameResult: '1/2-1/2'; withlast.isCheckmateandcurrentPlayer: '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 nullinvalidateSavedGameis 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
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersseverity: mediumEdge-case bugs or meaningful maintainability costtestingTest coverage and test quality
Activity
TMHSDigital commentedon Nov 17, 2026
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.Test every rejection path of the saved-game loader (TMHSDigital#141)