Fix Rome Provinces mandatory Neutral capture benefit

This commit is contained in:
coyotte508 2026-11-24 10:15:48 +00:00
commit c135dea227
23 changed files with 468 additions and 12 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', 'scripts/viking-cargo.test.cjs', 'scripts/aggressor.test.cjs', 'scripts/great-architect.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', 'scripts/aggressor.test.cjs', 'scripts/great-architect.test.cjs', 'scripts/provinces*.cjs', 'Cargo.*', '.github/workflows/web-viewer.yml']
push:
branches: [main, feat/3d-web-viewer]
jobs:
@ -24,7 +24,7 @@ jobs:
working-directory: web-client
- run: npx playwright install --with-deps chromium
working-directory: web-client
- run: node scripts/resource-journal-smoke.mjs && node scripts/famine-journal-smoke.mjs && node scripts/construction-smoke.mjs && node scripts/great-architect-smoke.mjs && node scripts/research-card-smoke.mjs
- run: node scripts/resource-journal-smoke.mjs && node scripts/famine-journal-smoke.mjs && node scripts/construction-smoke.mjs && node scripts/great-architect-smoke.mjs && node scripts/provinces-smoke.mjs && node scripts/research-card-smoke.mjs
working-directory: web-client
- run: npm run test:boarding && node scripts/embark-smoke.mjs && node scripts/ship-landing-smoke.mjs
working-directory: web-client

60
docs/rome-provinces.md Normal file
View file

@ -0,0 +1,60 @@
# Rome: Provinces (viewer 0.1.241 / engine 0.4.172)
The primary [Rome board, image 9488277](https://boardgamegeek.com/image/9488277)
was visually verified during investigation:
> After you capture a city, make it [Neutral] as a last step (or [Happy] if you pay 1 [Culture]).
Both benefits previously lived in the optional-payment response. The shared
payment helper suppresses unaffordable requests, so a player without a legal
one-culture payment never received the mandatory Neutral benefit. Leadership
25 correctly spends one culture for one action; it only exposed this bug.
Provinces now sets a retained captured city Neutral at combat-end priority 21,
before offering its optional Happy upgrade. Proconsul remains 22 and Captivi 20.
No global payment semantics changed. PaymentOptions still permits Great Arena's
mood conversion; zero available culture and mood does not create a prompt.
Affordable pending prompts already show the Neutral city. Declining leaves it
Neutral; paying upgrades it Happy exactly once. Legacy pending prompts still
resolve, without downgrading an already Happy city on decline. Missing or
no-longer-owned cities receive no mood mutation and any submitted payment is
refunded. Automatically razed captures generate no Provinces request.
## History compatibility
Correcting historical Angry captures could change later happiness costs and
legal actions. A separate `provinces_from` action boundary therefore follows the
existing independent rule-boundary pattern. New games use zero; old live saves
record their first new action. Historical replay without the field uses old
capture behavior throughout its retained history, then enables the correction
for new actions. Partial replay and branches clamp to the retained cursor plus
one; undo/redo and client prediction preserve the boundary. All save/replay
serialization paths carry it. Existing completed Angry cities are **not** repaired
on load, including the reported C4. This is a code correction, not a live-save edit.
## Coverage and scope
Native tests cover zero-culture capture, old behavior, pending accept/decline,
legacy resume, ownership loss/refund, Happy decline, automatic city-limit razing,
upgrade/undo/redo/branch, and independent full/partial replay serialization using
the existing frozen Architect history. The historical fixture tests boundary
plumbing, not a from-initialization Rome replay. Public-WASM synthetic captures
cover Leadership spending its last culture before China's last/nonlast city,
ordinary zero-culture captures, optional culture payment and Great Arena mood
conversion. No private production fixture is included.
The zero-culture native regression was run against the original Rome listener:
it failed with actual Angry / expected Neutral, then passed with this fix.
Combat-end mood-mutator inspection found later Happy effects for Huns (Attila,
priority -35) and Phoenicia (Deliverance, -20), not a later Roman downgrade.
These civilization-specific effects were left unchanged. The optional-payment
listener API itself is unchanged; other callers were not broadly rewritten.
The shared-helper caller audit also found optional decline logging (Trojan Horse,
Great Artist/temple and warfare) and Celts' selected-army cleanup in response
callbacks. These are not Provinces' mandatory capture benefit; no global change
or speculative fixes were made. Desktop (1400px) and mobile (390px) normal-viewer
smokes verify zero-token absence of a payment prompt, decline, and paid Happy.
The WASM drop-player regression checks deterministic optional decline and leaves
the mandatory Neutral mood and culture balance intact.

View file

@ -0,0 +1,23 @@
// Synthetic public-engine Rome capture fixtures.
const engine = require(process.env.CLASH_WASM || '../web-client/.engine/server.js');
const move = (g, a) => JSON.parse(engine.tryMove(JSON.stringify(g), JSON.stringify(a), 0));
const capture = g => move(g, { Movement: { Move: { units: [0], destination: 'C1', payment: {} } } });
const city = g => g.players[0].cities.find(c => c.position === 'C1');
async function setup(culture = 0, mood = 0, arena = false, last = true) {
const g = JSON.parse(await engine.init(2, [], {}, 'provinces-printed-rule', null));
g.current_player_index = 0;
g.starting_player_index = 0;
g.map = { tiles: [['C2', 'Fertile'], ['C1', 'Fertile'], ['D1', 'Fertile']], unexplored_blocks: [] };
g.players.forEach((p, i) => {
p.civilization = ['Rome', 'China', 'Barbarians', 'Pirates'][i];
p.objective_cards = []; p.action_cards = []; p.units = [];
p.cities = i === 0 ? [{position: 'C2', mood_state: 'Happy'}] : i === 1 ? [{position: 'C1', mood_state: 'Happy'}, ...(!last ? [{position: 'D1', mood_state: 'Happy'}] : [])] : [];
p.advances = ['Farming', 'Mining', 'Tactics', ...(i === 0 ? ['Nationalism'] : [])];
});
g.players[0].resources = {culture_tokens: culture, mood_tokens: mood};
if (arena) g.players[0].cities[0].city_pieces = {wonders: ['Colosseum']};
g.players[0].units = [{id: 0, position: 'C2', unit_type: 'Infantry'}];
g.players[0].next_unit_id = 1;
return g;
}
module.exports = {engine, move, capture, city, setup};

View file

@ -0,0 +1,40 @@
// Synthetic public WASM captures; no production saves.
const assert = require('node:assert/strict');
const { test } = require('node:test');
const {engine, move, capture, city, setup} = require('./provinces-fixture.cjs');
for (const last of [false, true]) {
test(`Leadership spends last culture; capture ${last ? 'last' : 'nonlast'} city is Neutral`, async () => {
let g = await setup(1, 0, false, last);
g.players[0].action_cards = [25];
const actions = g.actions_left;
g = move(g, {Playing: {ActionCard: 25}});
g = move(g, {Response: {Payment: [{culture_tokens: 1}]}});
assert.equal(g.players[0].resources?.culture_tokens || 0, 0);
assert.equal(g.actions_left, actions + 1);
g = capture(g);
assert.equal(city(g).mood_state, 'Neutral');
assert.equal((g.events || []).length, 0);
});
}
for (const [culture, mood, arena] of [[0, 0, false], [0, 0, true], [1, 0, false], [0, 1, true]]) {
for (const accept of culture || mood ? [false, true] : [false]) {
test(`capture culture=${culture} mood=${mood} Arena=${arena} accept=${accept}`, async () => {
let g = capture(await setup(culture, mood, arena));
assert.equal(city(g).mood_state, 'Neutral');
if (culture || mood) {
assert.ok(g.events.length > 0);
g = move(g, {Response: {Payment: [accept ? culture ? {culture_tokens: 1} : {mood_tokens: 1} : {}]}});
}
assert.equal(city(g).mood_state, accept ? 'Happy' : 'Neutral');
assert.equal((g.players[0].resources?.culture_tokens || 0) + (g.players[0].resources?.mood_tokens || 0), culture + mood - Number(accept));
});
}
}
test('withdrawn Provinces owner deterministically declines optional Happy payment', async () => {
const pending = capture(await setup(1, 0, false, false));
const g = JSON.parse(await engine.dropPlayer(JSON.stringify(pending), 0));
assert.equal(city(g).mood_state, 'Neutral');
assert.equal(g.players[0].resources?.culture_tokens, 1);
assert.deepEqual(JSON.parse(await engine.dropPlayer(JSON.stringify(pending), 0)), g);
});

View file

@ -122,9 +122,17 @@ fn provinces() -> SpecialAdvanceInfo {
|event| &mut event.combat_end,
21,
|game, player, s| {
(s.captured_city(player.index).is_some()
&& player.get(game).try_get_city(s.defender.position).is_some())
.then_some(vec![PaymentRequest::optional(
if s.captured_city(player.index).is_none()
|| player.get(game).try_get_city(s.defender.position).is_none()
{
return None;
}
// The mandatory benefit must run before the optional-payment helper
// filters unaffordable requests. Preserve historical captures on replay.
if game.provinces_from.is_some_and(|from| crate::game_api::log_length(game) >= from) {
set_city_mood(game, s.defender.position, &player.origin, MoodState::Neutral);
}
Some(vec![PaymentRequest::optional(
player
.payment_options()
.resources(player.get(game), ResourcePile::culture_tokens(1)),
@ -139,6 +147,13 @@ fn provinces() -> SpecialAdvanceInfo {
c.player().gain_resources(game, c.choice[0].clone());
return;
}
// A legacy pending prompt can still need its Neutral fallback, but
// declining an outdated prompt must not downgrade an already Happy city.
if c.choice[0].is_empty()
&& game.player(c.player_index).get_city(s.defender.position).mood_state == MoodState::Happy
{
return;
}
set_city_mood(
game,
s.defender.position,

View file

@ -159,6 +159,7 @@ pub struct Game {
pub finalized_combat_from: Option<usize>,
pub great_architect_action_cost_from: Option<usize>,
pub aggressor_eligibility_from: Option<usize>,
pub provinces_from: Option<usize>,
pub home_layout: crate::map::HomeLayout,
pub version: u16, // JSON schema version
pub state: GameState,

View file

@ -45,6 +45,8 @@ pub struct GameData {
great_architect_action_cost_from: Option<usize>,
#[serde(default, skip_serializing_if = "Option::is_none")]
aggressor_eligibility_from: Option<usize>,
#[serde(default, skip_serializing_if = "Option::is_none")]
provinces_from: Option<usize>,
#[serde(default, skip_serializing_if = "crate::map::HomeLayout::is_legacy")]
home_layout: crate::map::HomeLayout,
#[serde(default)]
@ -171,6 +173,7 @@ pub fn from_data(data: GameData, mut cache: Cache, context: GameContext) -> Game
finalized_combat_from: data.finalized_combat_from,
great_architect_action_cost_from: data.great_architect_action_cost_from,
aggressor_eligibility_from: data.aggressor_eligibility_from,
provinces_from: data.provinces_from,
home_layout: data.home_layout,
state: data.state,
players: Vec::new(),
@ -237,6 +240,7 @@ pub fn data(game: Game) -> GameData {
finalized_combat_from: game.finalized_combat_from,
great_architect_action_cost_from: game.great_architect_action_cost_from,
aggressor_eligibility_from: game.aggressor_eligibility_from,
provinces_from: game.provinces_from,
home_layout: game.home_layout,
state: game.state,
events: game.events,
@ -289,6 +293,7 @@ pub fn cloned_data(game: &Game) -> GameData {
finalized_combat_from: game.finalized_combat_from,
great_architect_action_cost_from: game.great_architect_action_cost_from,
aggressor_eligibility_from: game.aggressor_eligibility_from,
provinces_from: game.provinces_from,
home_layout: game.home_layout,
state: game.state.clone(),
events: game.events.clone(),

View file

@ -209,6 +209,7 @@ pub fn setup_game_with_cache(setup: &GameSetup, cache: Cache) -> Game {
finalized_combat_from: Some(0),
great_architect_action_cost_from: Some(0),
aggressor_eligibility_from: Some(0),
provinces_from: Some(0),
version: JSON_SCHEMA_VERSION,
options: GameOptions {
legacy_undo: None,

View file

@ -456,6 +456,7 @@ pub(crate) fn add_log_action(game: &mut Game, item: Action) {
game.great_architect_action_cost_from.get_or_insert(next);
}
game.aggressor_eligibility_from.get_or_insert(next);
game.provinces_from.get_or_insert(next);
let active_events = game.events.len();
let player = game.active_player();
let origin = action_origin(&item, game.player(player)).clone();
@ -471,6 +472,7 @@ pub(crate) fn add_log_action(game: &mut Game, item: Action) {
.map(|from| from.min(next));
game.aggressor_eligibility_from =
game.aggressor_eligibility_from.map(|from| from.min(next));
game.provinces_from = game.provinces_from.map(|from| from.min(next));
}
let l = &mut current_turn_log_mut(game).actions;
remove_redo_actions(l, i);

View file

@ -20,6 +20,8 @@ pub struct ReplayGameData {
great_architect_action_cost_from: Option<usize>,
#[serde(default, skip_serializing_if = "Option::is_none")]
aggressor_eligibility_from: Option<usize>,
#[serde(default, skip_serializing_if = "Option::is_none")]
provinces_from: Option<usize>,
#[serde(default, skip_serializing_if = "crate::map::HomeLayout::is_legacy")]
home_layout: crate::map::HomeLayout,
log: Vec<ActionLogAge>,
@ -146,6 +148,10 @@ pub fn replay(data: ReplayGameData, to: Option<usize>) -> Result<Game, String> {
data.aggressor_eligibility_from
.unwrap_or(actions.len().saturating_add(1)),
);
game.provinces_from = Some(
data.provinces_from
.unwrap_or(actions.len().saturating_add(1)),
);
if data.options.civilization == CivSetupOption::DraftThree {
// Draft locks are private and absent from the action log; setup turns
// record their final choices. Re-deal before locking to preserve the RNG.
@ -218,6 +224,9 @@ pub fn replay(data: ReplayGameData, to: Option<usize>) -> Result<Game, String> {
game.aggressor_eligibility_from = game
.aggressor_eligibility_from
.map(|from| from.min(to.saturating_add(1)));
game.provinces_from = game
.provinces_from
.map(|from| from.min(to.saturating_add(1)));
for player in data.players {
game.players[player.id].settings = player.settings;
}

View file

@ -5,7 +5,7 @@ use crate::movement::execute_movement_action;
use json_patch::{PatchOperation, patch};
use serde_json::Value;
const IGNORE_PATHS: [&str; 11] = [
const IGNORE_PATHS: [&str; 12] = [
"/calendar_knowledge",
"/log/",
"/log_index",
@ -20,6 +20,7 @@ const IGNORE_PATHS: [&str; 11] = [
"/finalized_combat_from",
"/great_architect_action_cost_from",
"/aggressor_eligibility_from",
"/provinces_from",
];
pub(crate) fn clean_patch(mut patch: Vec<PatchOperation>) -> Vec<PatchOperation> {

View file

@ -111,6 +111,27 @@ fn independent_aggressor_boundary_survives_full_partial_and_new_history_replay()
}
}
#[test]
fn independent_provinces_boundary_survives_full_partial_and_new_history_replay() {
let fixture = fixture();
let before = fixture["before"].as_u64().unwrap() as usize;
for boundary in [0, before, before + 4] {
let mut history = fixture["history"].clone();
history["provinces_from"] = json!(boundary);
let partial = replay(
serde_json::from_value(history.clone()).unwrap(),
Some(before),
)
.unwrap();
assert_eq!(partial.provinces_from, Some(boundary.min(before + 1)));
let full = replay(serde_json::from_value(history).unwrap(), None).unwrap();
assert_eq!(full.provinces_from, Some(boundary));
let saved = serde_json::to_value(full.cloned_data()).unwrap();
let replayed = replay(serde_json::from_value(saved).unwrap(), None).unwrap();
assert_eq!(replayed.provinces_from, Some(boundary));
}
}
#[test]
fn architect_redo_keeps_recorded_cost_policy_but_replacing_future_charges() {
let fixture = fixture();

View file

@ -142,3 +142,189 @@ fn civilizer() {
)],
);
}
fn provinces_capture(culture: u8, corrected: bool) -> server::game::Game {
let mut game = JSON.load_game("provinces");
game.provinces_from = Some(if corrected { 0 } else { usize::MAX });
game = server::game_api::execute(
game,
advance_action(Advance::Voting, ResourcePile::food(2)),
0,
);
game.players[0].resources.culture_tokens = culture;
server::game_api::execute(game, move_action(vec![0], Position::from_offset("B2")), 0)
}
#[test]
fn provinces_zero_culture_is_neutral_without_a_prompt() {
let game = provinces_capture(0, true);
assert_eq!(
game.player(0)
.get_city(Position::from_offset("B2"))
.mood_state,
server::city::MoodState::Neutral
);
assert!(game.events.is_empty());
}
#[test]
fn provinces_legacy_capture_retains_angry() {
let game = provinces_capture(0, false);
assert_eq!(
game.player(0)
.get_city(Position::from_offset("B2"))
.mood_state,
server::city::MoodState::Angry
);
}
#[test]
fn provinces_optional_payment_accept_decline_and_legacy_resume() {
for corrected in [false, true] {
for accept in [false, true] {
let game = provinces_capture(1, corrected);
assert_eq!(
game.player(0)
.get_city(Position::from_offset("B2"))
.mood_state,
if corrected {
server::city::MoodState::Neutral
} else {
server::city::MoodState::Angry
}
);
let mut game = server::game::Game::from_data(
game.cloned_data(),
server::cache::Cache::new(&game.options),
server::game::GameContext::Play,
);
// Existing pending choices remain valid when an old save is upgraded.
game.provinces_from = None;
let game = server::game_api::execute(
game,
payment_response(if accept {
ResourcePile::culture_tokens(1)
} else {
ResourcePile::empty()
}),
0,
);
assert_eq!(
game.player(0)
.get_city(Position::from_offset("B2"))
.mood_state,
if accept {
server::city::MoodState::Happy
} else {
server::city::MoodState::Neutral
}
);
assert_eq!(game.player(0).resources.culture_tokens, u8::from(!accept));
}
}
}
#[test]
fn provinces_obsolete_prompt_refunds_and_does_not_touch_another_owner() {
for accept in [false, true] {
let mut game = provinces_capture(1, false);
let position = Position::from_offset("B2");
let index = game.players[0]
.cities
.iter()
.position(|c| c.position == position)
.unwrap();
let city = game.players[0].cities.remove(index);
game.players[1].cities.push(city);
let game = server::game_api::execute(
game,
payment_response(if accept {
ResourcePile::culture_tokens(1)
} else {
ResourcePile::empty()
}),
0,
);
assert_eq!(game.player(0).resources.culture_tokens, 1);
assert_eq!(
game.player(1).get_city(position).mood_state,
server::city::MoodState::Angry
);
}
let mut game = provinces_capture(1, false);
game.players[0]
.cities
.iter_mut()
.find(|c| c.position == Position::from_offset("B2"))
.unwrap()
.mood_state = server::city::MoodState::Happy;
let game = server::game_api::execute(game, payment_response(ResourcePile::empty()), 0);
assert_eq!(
game.player(0)
.get_city(Position::from_offset("B2"))
.mood_state,
server::city::MoodState::Happy
);
}
#[test]
fn provinces_boundary_upgrade_undo_redo_and_branch() {
let mut game = JSON.load_game("provinces");
game = server::game_api::execute(
game,
advance_action(Advance::Voting, ResourcePile::food(2)),
0,
);
game.players[0].resources.culture_tokens = 0;
game.provinces_from = None;
let boundary = server::game_api::log_length(&game) + 1;
let action = move_action(vec![0], Position::from_offset("B2"));
game = server::game_api::execute(game, action.clone(), 0);
assert_eq!(game.provinces_from, Some(boundary));
game = server::game_api::execute(game, Action::Undo, 0);
assert_eq!(game.provinces_from, Some(boundary));
game = server::game_api::execute(game, Action::Redo, 0);
assert_eq!(
game.player(0)
.get_city(Position::from_offset("B2"))
.mood_state,
server::city::MoodState::Neutral
);
game = server::game_api::execute(game, Action::Undo, 0);
game.provinces_from = Some(usize::MAX);
game = server::game_api::execute(game, action, 0);
assert_eq!(game.provinces_from, Some(boundary));
assert_eq!(
game.player(0)
.get_city(Position::from_offset("B2"))
.mood_state,
server::city::MoodState::Neutral
);
}
#[test]
fn provinces_at_city_limit_automatically_razes_without_prompt() {
let mut game = JSON.load_game("provinces");
game.provinces_from = Some(0);
game = server::game_api::execute(
game,
advance_action(Advance::Voting, ResourcePile::food(2)),
0,
);
// Use spare cities solely to exhaust the city pieces; capture remains real.
while game.players[0].cities.len() < 7 {
let city = server::city::City::new(
0,
Position::from_offset(&format!("G{}", game.players[0].cities.len())),
);
game.players[0].cities.push(city);
}
let game =
server::game_api::execute(game, move_action(vec![0], Position::from_offset("B2")), 0);
assert!(
game.player(0)
.try_get_city(Position::from_offset("B2"))
.is_none()
);
assert!(game.events.is_empty());
}

View file

@ -158,6 +158,9 @@ fn clean_json(expected: &str) -> String {
.unwrap()
.remove("aggressor_eligibility_from");
}
if value["provinces_from"] == serde_json::json!(usize::MAX) {
value.as_object_mut().unwrap().remove("provinces_from");
}
// Only public action-log items qualify, never arbitrary arrays or game state.
if let Some(ages) = value
.get_mut("log")
@ -493,6 +496,9 @@ pub fn load_game(path: &GamePath) -> Game {
if game.aggressor_eligibility_from.is_none() {
game.aggressor_eligibility_from = Some(usize::MAX);
}
if game.provinces_from.is_none() {
game.provinces_from = Some(usize::MAX);
}
if update_expected() {
write_result(&to_json(&game), path);
}

View file

@ -7,6 +7,7 @@
"finalized_combat_from": 0,
"great_architect_action_cost_from": 0,
"aggressor_eligibility_from": 0,
"provinces_from": 0,
"home_layout": "ClockwiseV1",
"state": "ChooseCivilization",
"players": [

View file

@ -1854,3 +1854,10 @@ frozen artifacts. Verify 39 viewer files and engine bytes, catalog 8 / 46 entrie
artwork 4, all 60 named assets and unchanged gallery, Standard options, preferences
and settings. Only the artwork manifest's lockfile pin changes. No production
moves, repairs, backfills, point changes or historical save writes are performed.
# Viewer 0.1.241 / engine 0.4.172 — Rome Provinces
Provinces makes retained captured cities Neutral even with no culture available;
optional Happy payment still supports Great Arena. Historical captures retain
legacy replay behavior through an independent action boundary; existing Angry
cities are not repaired. See `docs/rome-provinces.md` for scope and regressions.

View file

@ -1,12 +1,12 @@
{
"name": "@boardgamers/clash-web-client",
"version": "0.1.240",
"version": "0.1.241",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@boardgamers/clash-web-client",
"version": "0.1.240",
"version": "0.1.241",
"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.240",
"version": "0.1.241",
"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 ../scripts/viking-cargo.test.cjs ../scripts/aggressor.test.cjs ../scripts/great-architect.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 ../scripts/aggressor.test.cjs ../scripts/great-architect.test.cjs ../scripts/provinces.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": "ecba98cab2766ff0ecf4278b50ee5aa9a78e2d63edf31e0f6c9bc20a060b3fe6",
"web-client/package-lock.json": "7ae29c256b48c313b79c1de9abc90fcb9b70603dea9ec5915a81ede5003a7203",
"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.171",
"version": "0.4.172",
"description": "Clash of Cultures: Monumental edition engine for Boardgamers Space",
"license": "MIT",
"type": "commonjs",

View file

@ -0,0 +1,76 @@
// Real engine and ordinary viewer payment controls, synthetic Rome captures.
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { createRequire } from 'node:module';
import path from 'node:path';
import { chromium } from 'playwright';
const {engine, setup, capture, city} = createRequire(import.meta.url)('../../scripts/provinces-fixture.cjs');
const dist = process.env.CLASH_VIEWER_DIR || new URL('../dist/', import.meta.url).pathname;
const browser = await chromium.launch({
headless: true,
args: ['--use-gl=angle', '--use-angle=swiftshader'],
});
try {
for (const width of [1400, 390]) {
for (const choice of ['unaffordable', 'decline', 'pay']) {
let state = capture(await setup(choice === 'unaffordable' ? 0 : 1));
assert.equal(city(state).mood_state, 'Neutral');
const page = await browser.newPage({ viewport: { width, height: 900 } });
const errors = [],
moves = [];
page.on('pageerror', (error) => errors.push(error.message));
await page.exposeFunction('applyMove', async (action) => {
const parsed = typeof action === 'string' ? JSON.parse(action) : action;
state = JSON.parse(engine.tryMove(JSON.stringify(state), JSON.stringify(parsed), 0));
moves.push(parsed);
await page.evaluate((raw) => host.emit('state', raw), engine.stripSecret(JSON.stringify(state), 0));
});
await page.route('**/*', async (route) => {
const url = new URL(route.request().url());
if (url.hostname !== 'clash.test') return route.abort();
if (url.pathname === '/')
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>',
});
return route.fulfill({
contentType: url.pathname.endsWith('.wasm') ? 'application/wasm' : 'text/javascript',
body: await readFile(path.join(dist, url.pathname)),
});
});
await page.goto('http://clash.test/');
await page.evaluate(
(raw) => {
window.host = clash3d.launch('#app');
host.on('move', (action) => window.applyMove(action));
host.emit('player', { index: 0 });
host.emit('preferences', { sound: false });
host.emit('state', raw);
},
engine.stripSecret(JSON.stringify(state), 0),
);
await page.waitForTimeout(500);
if (choice !== 'unaffordable') {
const panel = page.locator('.decision-panel');
await panel.waitFor();
assert.match(await panel.innerText(), /Provinces/);
await page.screenshot({path: `/tmp/clash-provinces-pending-${choice}-${width}.png`});
if (choice === 'pay') await panel.getByRole('button', {name: /^Pay /}).click();
else await panel.getByRole('button', {name: /Skip|Decline|No thanks|^No$|Continue/}).click();
await page.waitForFunction(() => !document.querySelector('.decision-panel'));
assert.equal(moves.length, 1);
} else {
assert.equal(await page.locator('.decision-panel').count(), 0);
assert.equal(moves.length, 0);
}
assert.equal(city(state).mood_state, choice === 'pay' ? 'Happy' : 'Neutral');
assert.equal(await page.getByRole('alert').count(), 0);
assert.deepEqual(errors, []);
await page.screenshot({path: `/tmp/clash-provinces-${choice}-${width}.png`});
console.log(`${width}px Provinces ${choice}: real viewer and engine verified`);
await page.close();
}
}
} finally {
await browser.close();
}

View file

@ -955,6 +955,7 @@ test('predicted undo preserves all independent persisted rule boundaries', () =>
finalized_combat_from: 4,
great_architect_action_cost_from: 5,
aggressor_eligibility_from: 1,
provinces_from: 1,
};
const current = {
...previous,

View file

@ -200,6 +200,7 @@ export function predictUndo(previous: string, current: string): string | null {
'finalized_combat_from',
'great_architect_action_cost_from',
'aggressor_eligibility_from',
'provinces_from',
]) {
if (after[field] !== undefined) before[field] = after[field];
else delete before[field];