diff --git a/viewer/scripts/tutorial-smoke.mjs b/viewer/scripts/tutorial-smoke.mjs index fd7594e..ca1dba6 100644 --- a/viewer/scripts/tutorial-smoke.mjs +++ b/viewer/scripts/tutorial-smoke.mjs @@ -372,10 +372,17 @@ try { fullPage: true, }); } - await page.waitForFunction( - (previous) => document.querySelector('.bgs-tutorial-heading strong')?.textContent !== previous, - heading - ); + if (chapter === 'offshore-cargo' && state.game.players[0].ship.containers.length === 1) { + // The pickup step remains open until both real board pieces are loaded. + await page.waitForFunction( + () => document.querySelectorAll('.bank-holding[data-owner="0"] [data-piece-id]').length === 1 + ); + } else { + await page.waitForFunction( + (previous) => document.querySelector('.bgs-tutorial-heading strong')?.textContent !== previous, + heading + ); + } if (chapter === 'bidding' && heading.includes('Submit a sealed')) { assert.match(await page.locator('.tutorial-auction').innerText(), /Leo: Sealed/); await page.reload(); diff --git a/viewer/src/tutorial/offshore-lessons.ts b/viewer/src/tutorial/offshore-lessons.ts index ebe9796..79b304e 100644 --- a/viewer/src/tutorial/offshore-lessons.ts +++ b/viewer/src/tutorial/offshore-lessons.ts @@ -39,6 +39,7 @@ type Stage = { text: string; move?: (g: GameState) => Move; script?: (g: GameState, apply: (m: Move, seat: number) => void) => void; + complete?: (g: GameState) => boolean; }; const endRound = (_g: GameState, apply: (m: Move, seat: number) => void) => { apply(pass, 1); @@ -60,7 +61,7 @@ function make(id: string, title: string, description: string, stages: Stage[], c return { game: 'container', id, - version: 1, + version: id === 'offshore-cargo' ? 2 : 1, title, description, initialState: fixture, @@ -81,11 +82,14 @@ function make(id: string, title: string, description: string, stages: Stage[], c // Container IDs identify physical pieces; display metadata and object key order are irrelevant. const data = expected.data as any; const got = actual.data as any; - const matches = data?.id - ? got?.id === data.id - : data?.type - ? got?.type === data.type && got?.lot === data.lot - : equal(got, data); + const matches = + expected.name === MoveName.LoadBankContainer + ? state.game.players[0].bankHolding?.some((piece) => piece.id === got?.id) + : data?.id + ? got?.id === data.id + : data?.type + ? got?.type === data.type && got?.lot === data.lot + : equal(got, data); const extra = (expected as any).extraData as any; const supplied = (actual as any).extraData as any; const extras = @@ -107,7 +111,8 @@ function make(id: string, title: string, description: string, stages: Stage[], c }; if (action.kind === 'move') apply(action.move, 0); else if (action.kind === 'watch') stages[index].script!(game, apply); - return { game, answer: String(index + 1) }; + const complete = stages[index].complete?.(game) ?? true; + return { game, answer: String(index + (complete ? 1 : 0)) }; }, choices(state, step) { const stage = stages.find((s) => s.id === step); @@ -143,8 +148,9 @@ export const offshoreLessons: Lesson[] = [ { id: 'load-bank', title: 'Choose a container to load', - text: 'Click the first container in your holding to load it. Loading is free only just after arrival (or another pickup), up to five aboard. The remaining holding is safe; it scores $3 per container at game end.', + text: 'Click a container in your holding to load it, then load the other one. Both pickups are free after sailing to the bank.', move: (g) => ({ name: MoveName.LoadBankContainer, data: g.players[0].bankHolding![0] }), + complete: (g) => g.players[0].bankHolding!.length === 0, }, ], 'Public bank auctions do not replace sealed ship auctions. Your cargo is now aboard; containers left in your holding remain yours.' diff --git a/viewer/tests/tutorial/lessons.cjs b/viewer/tests/tutorial/lessons.cjs index 0d8d6b3..566c55b 100644 --- a/viewer/tests/tutorial/lessons.cjs +++ b/viewer/tests/tutorial/lessons.cjs @@ -175,8 +175,16 @@ for (const lesson of lessons.filter((l) => l.id.startsWith('offshore-'))) { false ); assert.deepEqual(controller.snapshot.state, checkpoint, 'invalid actions never mutate bank state'); - await controller.restartStep(); - assert.deepEqual(controller.snapshot.state, checkpoint, 'replay restores escrow, decisions and holding'); + // A loading step now has two actions; restarting it intentionally undoes + // the first pickup. Mid-step persistence is covered by the dedicated test. + if (!(lesson.steps[step].id === 'load-bank' && checkpoint.game.players[0].bankHolding.length === 1)) { + await controller.restartStep(); + assert.deepEqual( + controller.snapshot.state, + checkpoint, + 'replay restores escrow, decisions and holding' + ); + } controller.destroy(); controller = await createTutorial({ ...lesson, storage }); assert.equal(controller.snapshot.step, step); @@ -214,6 +222,37 @@ for (const lesson of lessons.filter((l) => l.id.startsWith('offshore-'))) { }); } +test('Offshore cargo loads both pieces in either order, resumes and retries the whole pickup step', async () => { + const lesson = lessons.find((l) => l.id === 'offshore-cargo'); + assert.equal(lesson.version, 2); + for (const first of [0, 1]) { + const storage = memory(); + let controller = await createTutorial({ ...lesson, storage }); + while (lesson.steps[controller.snapshot.step].id !== 'load-bank') + assert.equal(await controller.play(actionFor(lesson, controller.snapshot)), true); + const arrival = structuredClone(controller.snapshot.state); + const load = (piece) => ({ kind: 'move', move: { name: 'loadBankContainer', data: piece } }); + assert.equal(await controller.play(load(arrival.game.players[0].bankHolding[first])), true); + assert.equal(controller.snapshot.completed, false); + assert.equal(controller.snapshot.canContinue, false); + assert.equal(controller.snapshot.state.game.players[0].ship.containers.length, 1); + controller.destroy(); + controller = await createTutorial({ ...lesson, storage }); + assert.equal(controller.snapshot.state.game.players[0].bankHolding.length, 1); + await controller.restartStep(); + assert.deepEqual(controller.snapshot.state, arrival); + assert.equal(await controller.play(load(arrival.game.players[0].bankHolding[first])), true); + assert.equal(await controller.play(actionFor(lesson, controller.snapshot)), true); + assert.equal(controller.snapshot.completed, true); + const player = controller.snapshot.state.game.players[0]; + assert.equal(player.ship.containers.length, 2); + assert.equal(player.bankHolding.length, 0); + assert.equal(player.actions, arrival.game.players[0].actions); + assert.equal(player.money, arrival.game.players[0].money); + controller.destroy(); + } +}); + test('Offshore lesson prose is translated in every supported catalogue', () => { const fs = require('node:fs'); const path = require('node:path');