1import test from 'node:test';2import assert from 'node:assert/strict';3import { winHandoffIsCurrent } from '../src/app/level-identity.js';45function game(won = true, moves = 0) {6 return { getState: () => ({ won, moves }) };7}89test('delayed win remains valid for the game and stable level that created it', () => {10 const expectedGame = game(true, 4);11 assert.equal(winHandoffIsCurrent({12 currentGame: expectedGame,13 expectedGame,14 expectedLevelId: 'pack:proof',15 activeLevel: { id: 'pack:proof' },16 }), true);17});1819test('same stable id after pack replacement cannot promote the old game', () => {20 const expectedGame = game(true, 4);21 const replacementGame = game(true, 0);22 assert.equal(winHandoffIsCurrent({23 currentGame: replacementGame,24 expectedGame,25 expectedLevelId: 'pack:proof',26 activeLevel: { id: 'pack:proof' },27 }), false);28});2930test('removing the active pack and falling back cannot promote its delayed win', () => {31 const expectedGame = game(true, 4);32 assert.equal(winHandoffIsCurrent({33 currentGame: expectedGame,34 expectedGame,35 expectedLevelId: 'pack:proof',36 activeLevel: { id: 'core:intro' },37 }), false);38});3940test('a game that has been undone out of a win cannot promote', () => {41 const expectedGame = game(false, 5);42 assert.equal(winHandoffIsCurrent({43 currentGame: expectedGame,44 expectedGame,45 expectedLevelId: 'pack:proof',46 activeLevel: { id: 'pack:proof' },47 }), false);48});