Fix Viking leader cargo logging; prepare viewer 0.1.239 and engine 0.4.170

This commit is contained in:
coyotte508 2026-11-23 19:43:42 +00:00
commit 7858f477a0
10 changed files with 322 additions and 9 deletions

View file

@ -1,7 +1,7 @@
name: Web viewer
on:
pull_request:
paths: ['web-client/**', 'server/**', 'scripts/status-phase-battle.test.cjs', 'scripts/postcombat-queue*.cjs', 'scripts/tributes.test.cjs', 'scripts/withdrawal.test.cjs', 'Cargo.*', '.github/workflows/web-viewer.yml']
paths: ['web-client/**', 'server/**', 'scripts/status-phase-battle.test.cjs', 'scripts/postcombat-queue*.cjs', 'scripts/tributes.test.cjs', 'scripts/withdrawal.test.cjs', 'scripts/viking-cargo.test.cjs', 'Cargo.*', '.github/workflows/web-viewer.yml']
push:
branches: [main, feat/3d-web-viewer]
jobs:
@ -28,7 +28,7 @@ jobs:
working-directory: web-client
- run: npm run test:boarding && node scripts/embark-smoke.mjs && node scripts/ship-landing-smoke.mjs
working-directory: web-client
- run: node scripts/withdrawal-smoke.mjs && node scripts/horse-master-smoke.mjs && node scripts/carthage-recruit-smoke.mjs && node scripts/payment-defaults-smoke.mjs && node scripts/wonder-payment-perf.mjs
- run: node scripts/viking-cargo-smoke.mjs && node scripts/withdrawal-smoke.mjs && node scripts/horse-master-smoke.mjs && node scripts/carthage-recruit-smoke.mjs && node scripts/payment-defaults-smoke.mjs && node scripts/wonder-payment-perf.mjs
working-directory: web-client
- run: node scripts/map-guide-smoke.mjs && node scripts/trade-routes-smoke.mjs && node scripts/raiders-smoke.mjs
working-directory: web-client

View file

@ -0,0 +1,81 @@
// Synthetic public fixture; exercise the actual JSON/WASM move and save boundaries.
const assert = require("node:assert/strict");
const { test } = require("node:test");
const { readFileSync } = require("node:fs");
const { resolve } = require("node:path");
const engine = require(process.env.CLASH_WASM || "../server/pkg/server.js");
const move = (g, action) =>
JSON.parse(engine.move(JSON.stringify(g), JSON.stringify(action), 1));
function fixture(mixed) {
const g = JSON.parse(
readFileSync(
resolve(
__dirname,
"../server/tests/test_games/civilizations/vikings/ship_construction.json",
),
),
);
[g.players[0], g.players[1]] = [g.players[1], g.players[0]];
g.players.forEach((p, i) => (p.id = i));
g.current_player_index = g.starting_player_index = 1;
g.log[0].rounds[0].turns[0].turn_type.Player = 1;
g.players[1].recruited_leaders = ["Ragnar"];
g.players[1].units = [
{ id: 3, position: "D2", unit_type: "Ship" },
{ id: 4, position: "D2", unit_type: { Leader: "Ragnar" }, carrier_id: 3 },
];
if (mixed)
g.players[1].units.push({
id: 5,
position: "D2",
unit_type: "Infantry",
carrier_id: 3,
});
return g;
}
for (const mixed of [false, true])
for (const settler of [false, true]) {
test(`Ship Construction unloads ${mixed ? "mixed" : "leader-only"} cargo as ${settler ? "settler" : "infantry"} at seat 1 after save/resume`, () => {
let g = fixture(mixed);
const opponent = structuredClone(g.players[0]);
g = move(g, {
Movement: { Move: { units: [3], destination: "C2", payment: {} } },
});
assert.equal(engine.currentPlayer(JSON.stringify(g)), 1);
assert.deepEqual(
g.players[1].units[0].carried_units.map((u) => u.id),
mixed ? [4, 5] : [4],
);
const pending = JSON.stringify(g);
assert.match(pending, /Select units to convert to settlers/);
// Restore the pending state, rather than reissuing movement or repairing cargo.
g = move(JSON.parse(pending), {
Response: { SelectUnits: settler ? [3] : [] },
});
const units = g.players[1].units;
assert.deepEqual(
units.map((u) => u.id),
mixed ? [3, 4, 5] : [3, 4],
);
assert.equal(units[0].unit_type, settler ? "Settler" : "Infantry");
assert.deepEqual(units[1].unit_type, { Leader: "Ragnar" });
if (mixed) assert.equal(units[2].unit_type, "Infantry");
assert.ok(
units.every((u) => u.position === "C2" && u.carrier_id == null),
);
assert.deepEqual(g.players[0].units, opponent.units);
assert.equal(g.state.Movement.movement_actions_left, 2);
assert.deepEqual(g.state.Movement.moved_units, [3]);
const log = JSON.stringify(g.log);
const expected = `Unloaded ${mixed ? "1 infantry and " : ""}Ragnar Lodbrok from ships`;
assert.equal(log.split(expected).length - 1, 1);
assert.equal(
log.split(
`Converted 1 ship and to 1 ${settler ? "settler" : "infantry"}`,
).length - 1,
1,
);
assert.ok(!(g.events || []).length, "conversion prompt resolved");
assert.doesNotThrow(() => engine.webView(JSON.stringify(g), 1));
});
}

View file

@ -99,7 +99,7 @@ fn ship_construction() -> SpecialAdvanceInfo {
if !unload_units.is_empty() {
s.log(
game,
&format!("Unloaded {} from ships", unload_units.to_string(None)),
&format!("Unloaded {} from ships", unload_units.to_string(Some(game))),
);
}
s.log(

View file

@ -151,3 +151,101 @@ fn converting_ship_carries_army_passengers_in_one_group_move() {
panic!("expected movement");
}
}
// Synthetic legal cargo, not a historical save. Exercise both the live callback
// and a suspended conversion restored across the ordinary save boundary.
#[test]
fn converting_ship_unloads_leader_cargo() {
use serde_json::json;
use server::{
cache::Cache,
game::{Game, GameContext},
game_data::GameData,
leader::Leader,
unit::UnitType,
};
fn load(value: serde_json::Value) -> Game {
let data: GameData = serde_json::from_value(value).unwrap();
let cache = Cache::new(&data.options);
Game::from_data(data, cache, GameContext::Play)
}
for mixed in [false, true] {
for settler in [false, true] {
for resume in [false, true] {
let mut value: serde_json::Value = serde_json::from_str(include_str!(
"test_games/civilizations/vikings/ship_construction.json"
))
.unwrap();
value["players"].as_array_mut().unwrap().swap(0, 1);
value["players"][0]["id"] = json!(0);
value["players"][1]["id"] = json!(1);
value["current_player_index"] = json!(1);
value["starting_player_index"] = json!(1);
value["log"][0]["rounds"][0]["turns"][0]["turn_type"]["Player"] = json!(1);
let p = &mut value["players"][1];
p["recruited_leaders"] = json!(["Ragnar"]);
p["units"] = json!([
{"id":3,"position":"D2","unit_type":"Ship"},
{"id":4,"position":"D2","unit_type":{"Leader":"Ragnar"},"carrier_id":3}
]);
if mixed {
p["units"].as_array_mut().unwrap().push(
json!({"id":5,"position":"D2","unit_type":"Infantry","carrier_id":3}),
);
}
let mut game = server::game_api::execute(
load(value),
move_action(vec![3], Position::from_offset("C2")),
1,
);
assert_eq!(game.player(1).get_unit(4).carrier_id, Some(3));
if resume {
game = load(serde_json::to_value(game.cloned_data()).unwrap());
}
game = server::game_api::execute(
game,
Action::Response(EventResponse::SelectUnits(if settler {
vec![3]
} else {
vec![]
})),
1,
);
let p = game.player(1);
assert_eq!(p.units.len(), if mixed { 3 } else { 2 });
assert_eq!(
p.get_unit(3).unit_type,
if settler {
UnitType::Settler
} else {
UnitType::Infantry
}
);
assert_eq!(p.get_unit(4).unit_type, UnitType::Leader(Leader::Ragnar));
if mixed {
assert_eq!(p.get_unit(5).unit_type, UnitType::Infantry);
}
assert!(
p.units
.iter()
.all(|u| u.position == Position::from_offset("C2")
&& u.carrier_id.is_none()
&& u.player_index == 1)
);
if let server::game::GameState::Movement(m) = &game.state {
assert_eq!(m.movement_actions_left, 2);
assert_eq!(m.moved_units, vec![3]);
} else {
panic!("expected movement");
}
let log = serde_json::to_value(game.cloned_data()).unwrap()["log"].to_string();
let expected = if mixed {
"Unloaded 1 infantry and Ragnar Lodbrok from ships"
} else {
"Unloaded Ragnar Lodbrok from ships"
};
assert_eq!(log.matches(expected).count(), 1);
}
}
}
}

View file

@ -1817,3 +1817,20 @@ remain unchanged. The artwork lockfile pin changes only for the viewer version.
This code release cannot repair BGS responder metadata on already-blocked games;
no production save reconciliation, batch replay, forced moves or clock edits are
authorized or performed.
# Viewer 0.1.239 / engine 0.4.170 — Viking leader cargo logging
Ship Construction supplies game context when printing unloaded cargo, so Ragnar
and other leaders have readable names instead of panicking after conversion.
This is a logging-only fix: unit IDs, cargo unloading, Infantry/Settler choices,
movement accounting and rules are unchanged. Fresh moves and saved pending
conversion prompts use the same corrected callback; no historical save is rewritten.
Native tests cover leader-only/mixed cargo, both choices, live/resumed prompts at
seat 1; four actual WASM regressions and desktop/mobile normal-viewer clicks cover
both responses and readable, exactly-once unload logging.
Require exact-commit Check and Web viewer CI green before publishing the frozen
viewer and engine together. Preserve catalog 8 / 46 definitions, artwork 4, all
60 named assets, gallery, Standard options, settings and preferences. Only the
artwork manifest's lockfile integrity pin changes; no artwork is republished and
no production game edits, repairs, backfills or history rewrites are performed.

View file

@ -1,12 +1,12 @@
{
"name": "@boardgamers/clash-web-client",
"version": "0.1.238",
"version": "0.1.239",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@boardgamers/clash-web-client",
"version": "0.1.238",
"version": "0.1.239",
"dependencies": {
"@boardgamers/protocol": "0.11.0",
"lucide-svelte": "^0.577.0",

View file

@ -1,13 +1,13 @@
{
"name": "@boardgamers/clash-web-client",
"version": "0.1.238",
"version": "0.1.239",
"private": true,
"type": "module",
"scripts": {
"dev": "vite --host 127.0.0.1 --port 8643",
"build": "vite build",
"check": "svelte-check --tsconfig ./tsconfig.json",
"test": "node --experimental-strip-types --test src/*.test.ts && node --test scripts/publish-gallery.test.mjs scripts/boarding.test.mjs scripts/raiders.test.mjs && npm run test:achievement-assets && npm run test:locales && node scripts/exhausted-movement-check.mjs && CLASH_WASM=\"$PWD/.engine/server.js\" node --test ../scripts/status-phase-battle.test.cjs ../scripts/postcombat-queue.test.cjs ../scripts/tributes.test.cjs ../scripts/withdrawal.test.cjs",
"test": "node --experimental-strip-types --test src/*.test.ts && node --test scripts/publish-gallery.test.mjs scripts/boarding.test.mjs scripts/raiders.test.mjs && npm run test:achievement-assets && npm run test:locales && node scripts/exhausted-movement-check.mjs && CLASH_WASM=\"$PWD/.engine/server.js\" node --test ../scripts/status-phase-battle.test.cjs ../scripts/postcombat-queue.test.cjs ../scripts/tributes.test.cjs ../scripts/withdrawal.test.cjs ../scripts/viking-cargo.test.cjs",
"test:boarding": "npm run build:bridge && npm run build && node --test scripts/boarding.test.mjs && node scripts/boarding-smoke.mjs",
"test:home-orientation": "npm run build && node scripts/home-orientation-smoke.mjs",
"build:achievement-assets": "node scripts/build-achievement-assets.mjs",

View file

@ -13,7 +13,7 @@
"web-client/src/civilization-emblems.ts": "01b0cbf3fa77a8466532ccd73d63c1a3ddc9bbc79fc06ce7224b425322a9c9f0",
"web-client/src/civilization-flags.ts": "cd176076bfe05b3059093b80c88596b7ae46b77898695c6c7406cbe1a3a0f78b",
"server/src/content/civilizations.rs": "73602f3db506f3dc2dbc6de43d01179440fd3bb034c997ff209336faaef2a332",
"web-client/package-lock.json": "18e8eb271d15adbf54933db2dee15ce50e6ffc3f60bdec0dee7c1373243424d3",
"web-client/package-lock.json": "4e6b5fb67d993f97e8d2faef7943aa29ae78787f62930d97879cc6ac30415434",
"web-client/node_modules/lucide-svelte/dist/Icon.svelte": "f7b49ab842c143fa680fa8bd9a54a9efdc48c2e2d49fa574bd5ccf8f6cfca5be",
"web-client/node_modules/lucide-svelte/dist/defaultAttributes.js": "5b8981c6e3434ae6538716af9e0403554e7708c4087f18d060950a7bef00d96a",
"web-client/node_modules/lucide-svelte/LICENSE": "668dcc52803480e0a026b31140a4cae668772663cd764e5991d252eef03f98db"

View file

@ -1,6 +1,6 @@
{
"name": "@boardgamers/clash-server",
"version": "0.4.169",
"version": "0.4.170",
"description": "Clash of Cultures: Monumental edition engine for Boardgamers Space",
"license": "MIT",
"type": "commonjs",

View file

@ -0,0 +1,117 @@
// Synthetic legal cargo only. Production viewer/controller and actual WASM;
// no production saves, forced clicks, or private state repairs.
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { createRequire } from 'node:module';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { chromium } from 'playwright';
const root = fileURLToPath(new URL('..', import.meta.url));
const engine = createRequire(import.meta.url)(process.env.CLASH_WASM || '../.engine/server.js');
const viewer = process.env.CLASH_VIEWER_DIR || path.join(root, 'dist');
function pending(template) {
const game = structuredClone(template);
[game.players[0], game.players[1]] = [game.players[1], game.players[0]];
game.players.forEach((p, i) => (p.id = i));
game.current_player_index = game.starting_player_index = 1;
game.log[0].rounds[0].turns[0].turn_type.Player = 1;
game.players[1].recruited_leaders = ['Ragnar'];
game.players[1].units = [
{ id: 3, position: 'D2', unit_type: 'Ship' },
{ id: 4, position: 'D2', unit_type: { Leader: 'Ragnar' }, carrier_id: 3 },
{ id: 5, position: 'D2', unit_type: 'Infantry', carrier_id: 3 },
];
return engine.move(
JSON.stringify(game),
JSON.stringify({ Movement: { Move: { units: [3], destination: 'C2', payment: {} } } }),
1,
);
}
const template = JSON.parse(
await readFile(
new URL('../../server/tests/test_games/civilizations/vikings/ship_construction.json', import.meta.url),
),
);
const browser = await chromium.launch({
headless: true,
args: ['--use-gl=angle', '--use-angle=swiftshader'],
});
try {
for (const width of [1400, 390])
for (const settler of [false, true]) {
const page = await browser.newPage({ viewport: { width, height: 900 } });
const errors = [],
sent = [];
let raw = pending(template);
page.on('pageerror', (error) => errors.push(error.message));
const emit = () => page.evaluate((state) => host.emit('state', state), engine.stripSecret(raw, 1));
await page.exposeFunction('applyMove', async (action) => {
sent.push(JSON.parse(action));
raw = engine.move(raw, action, 1);
await emit();
});
await page.route('**/*', async (route) => {
const name = new URL(route.request().url()).pathname;
if (name === '/')
return route.fulfill({
contentType: 'text/html',
body: '<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><div id="app"></div><script src="/viewer.js"></script>',
});
if (!['/viewer.js', '/server_bg.wasm'].includes(name)) return route.abort();
return route.fulfill({
contentType: name.endsWith('.wasm') ? 'application/wasm' : 'text/javascript',
body: await readFile(path.join(viewer, name)),
});
});
await page.goto('http://clash.test/');
await page.waitForFunction(() => typeof window.clash3d !== 'undefined');
await page.evaluate(() => {
window.host = clash3d.launch('#app');
host.on('move', (action) => window.applyMove(action));
host.emit('player', { index: 1 });
host.emit('preferences', { sound: false, reducedMotion: true });
});
await emit();
await page
.getByText('Select units to convert to settlers (instead of infantry)', { exact: true })
.waitFor();
if (settler) {
await page.getByRole('button', { name: 'Ship', exact: true }).click();
await page.getByRole('button', { name: 'Confirm', exact: true }).click();
} else {
await page.getByRole('button', { name: 'Skip', exact: true }).click();
}
await page.waitForFunction(
() => !document.body.textContent.includes('Select units to convert to settlers'),
);
assert.deepEqual(sent, [{ Response: { SelectUnits: settler ? [3] : [] } }]);
const state = JSON.parse(raw);
assert.deepEqual(
state.players[1].units.map((u) => u.id),
[3, 4, 5],
);
assert.equal(state.players[1].units[0].unit_type, settler ? 'Settler' : 'Infantry');
assert.deepEqual(state.players[1].units[1].unit_type, { Leader: 'Ragnar' });
assert.ok(state.players[1].units.every((u) => u.position === 'C2' && u.carrier_id == null));
assert.equal(
JSON.stringify(state.log).split('Unloaded 1 infantry and Ragnar Lodbrok from ships').length - 1,
1,
);
assert.equal(state.state.Movement.movement_actions_left, 2);
assert.deepEqual(state.state.Movement.moved_units, [3]);
assert.ok(!(state.events || []).length);
assert.doesNotThrow(() => engine.webView(raw, 1));
assert.doesNotMatch(
(await page.locator('.toast').allTextContents()).join(' '),
/error|panic|invalid|failed/i,
);
assert.deepEqual(errors, []);
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth));
await page.close();
console.log(
`${width}px: normal Ship Construction ${settler ? 'Ship / Confirm → Settler' : 'Skip → Infantry'}, leader cargo unloaded once; valid resumed state, no error toast.`,
);
}
} finally {
await browser.close();
}