Fix duplicate Famine food-loss badges; release viewer 0.1.218

This commit is contained in:
coyotte508 2026-11-14 17:35:40 +00:00
commit 3f818d5b24
8 changed files with 186 additions and 9 deletions

View file

@ -1411,3 +1411,33 @@ protocol, split-WASM bundle and combat journal checks also pass. Existing Clippy
warnings and expected rejected-move WASM diagnostics remain. The first native
random-actions run hit the existing Tributes eligibility rejection; a complete
workspace rerun passed. No Tributes rules or unrelated snapshots were changed.
# Viewer 0.1.218 / engine unchanged (0.4.152)
Famine and Drought show one food-loss badge when the engine records a structured
food-only loss immediately followed by its identical “Lost N food” explanation.
Suppression is limited to that adjacent explanation within the same action,
incident, player and amount. Resource records are never deduplicated; legacy
prose, separate actions/effects, other players, gains and mixed losses remain.
Rules and protection details stay available in the expanded event journal.
After fetching main, production was already on achievement engine 0.4.152 (not
the earlier 0.4.149). Preserve that exact engine URL/package with a viewer-only
publication; do not pass `--engine`. No engine source or gameplay changes, live
moves, history repairs or Fossil refresh are included. Preserve all gallery,
achievement and unrelated metadata, including game-length labels/order and
Standard defaults.
Verified: 1,079 frontend tests, four gallery tests, 19 achievement publication
checks (two existing artifact-dependent skips), locale validation and extraction,
Svelte with zero errors/warnings, and a production build from the current bridge.
The built-viewer offline famine regression runs at 1400px and 390px, asserting
one food badge and complete expanded rules/protection text. Journal, combat,
event-explanation, piece-loss and split-WASM bundle browser checks also pass.
Engine-backed tests cover Drought 52 and Famine 7 reducing food from one to zero
without presentation mutating history. Expected rejected-move diagnostics remain.
Integration also repairs the stale revision-2 achievement test on main to check
the already-shipped revision-3 catalog and both artwork sets. The artwork input
lockfile hash is refreshed solely for the viewer version bump; dependencies and
artwork bytes are unchanged. No achievement publication is performed.

View file

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

View file

@ -1,6 +1,6 @@
{
"name": "@boardgamers/clash-web-client",
"version": "0.1.217",
"version": "0.1.218",
"private": true,
"type": "module",
"scripts": {

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": "5c2509542ca8802914b81bf6bc777537c1b95a69f913f6f99aaeae1ae3d5cd6b",
"web-client/package-lock.json": "b0e8fd2588eb68322b9f06345b95f3ee0c5f6549cee0caee0d2c97dc622d84e5",
"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

@ -0,0 +1,76 @@
// Offline built-viewer regression; no BGS connections or live moves.
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { createRequire } from 'node:module';
import { chromium } from 'playwright';
const engine = createRequire(import.meta.url)('../.engine/server.js');
const raw = JSON.parse(
await readFile(
new URL('../../server/tests/test_games/incidents/pandemics/drought.json', import.meta.url),
'utf8',
),
);
raw.players[0].resources.food = 1;
const after = engine.tryMove(
JSON.stringify(raw),
JSON.stringify({ Playing: { Advance: { advance: 'Storage', payment: { gold: 2 } } } }),
0,
);
assert.equal(JSON.parse(after).players[0].resources.food ?? 0, 0);
const browser = await chromium.launch({
headless: true,
args: ['--use-gl=angle', '--use-angle=swiftshader'],
});
try {
for (const [width, height] of [
[1400, 900],
[390, 740],
]) {
const page = await browser.newPage({ viewport: { width, height } }),
errors = [];
page.on('pageerror', (e) => errors.push(e.message));
await page.route('**/*', async (route) => {
const path = new URL(route.request().url()).pathname;
if (path === '/')
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(path)) return route.abort();
return route.fulfill({
contentType: path.endsWith('.wasm') ? 'application/wasm' : 'text/javascript',
body: await readFile(new URL('../dist' + path, import.meta.url)),
});
});
await page.goto('http://clash.test');
await page.evaluate(
(state) => {
window.host = clash3d.launch('#app');
host.emit('player', { index: 0 });
host.emit('theme', { dark: true });
host.emit('preferences', { sound: false });
host.emit('state', state);
},
engine.stripSecret(after, 0),
);
await page.getByRole('button', { name: 'Open journal', exact: true }).click();
const event = page.locator('.journal-event').filter({ hasText: /Drought|Draught/ });
await event.waitFor();
console.log(width, await event.innerText());
const food = event.locator('.journal-delta').filter({ has: page.locator('b', { hasText: '−1' }) });
assert.equal(await food.count(), 1);
assert.match(await food.getAttribute('aria-label'), /food/i);
await event.locator('.event-rules summary').click();
const rules = JSON.parse(engine.webView(engine.stripSecret(after))).eventCatalog.find(
(e) => e.id === 52,
).rules;
const renderedRules = (await event.locator('.event-rules').innerText()).replace(/\s+/g, ' ');
for (const rule of rules) assert.ok(renderedRules.includes(rule), rule);
console.log('Expanded rules verified:', rules);
await page.screenshot({ path: `/tmp/famine-journal-${width}.png` });
assert.deepEqual(errors, []);
await page.close();
}
} finally {
await browser.close();
}

View file

@ -20,7 +20,7 @@ const finish = () => engine.tryMove(fixture, JSON.stringify({ Playing: 'EndTurn'
test('WASM achievement catalog follows official protocol 0.11.0', () => {
const manifest = achievementManifestSchema.parse(hooks.achievementDefinitions());
assert.equal(manifest.revision, 2);
assert.equal(manifest.revision, 3);
assert.equal(manifest.achievements.length, 41);
assert.ok(!manifest.achievements.some((a) => a.id === 'four-cities'));
assert.ok(manifest.achievements.some((a) => a.id === 'seven-cities'));
@ -32,13 +32,17 @@ test('WASM achievement catalog follows official protocol 0.11.0', () => {
const art = JSON.parse(
readFileSync(new URL('../release/achievement-assets.json', import.meta.url), 'utf8'),
);
assert.equal(art.revision, manifest.revision);
const nonfactionArt = JSON.parse(
readFileSync(new URL('../release/achievement-assets-nonfaction.json', import.meta.url), 'utf8'),
);
assert.equal(nonfactionArt.revision, manifest.revision);
assert.equal(art.revision, 2, 'revision 3 preserves the existing faction artwork');
assert.deepEqual(
manifest.achievements
.filter((a) => a.icon?.type === 'asset')
.map((a) => (a.icon!.type === 'asset' ? a.icon!.key : ''))
.sort(),
art.assets.map((a: { key: string }) => a.key).sort(),
[...art.assets, ...nonfactionArt.assets].map((a: { key: string }) => a.key).sort(),
);
for (const length of ['shorter', 'standard', 'roll-to-end', 'wonderful-ending', 'epic']) {
for (const verb of ['complete', 'win'])

View file

@ -3,6 +3,7 @@ import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import { readFileSync, readdirSync } from 'node:fs';
import { journal } from './journal.ts';
import { readableHistory } from './structured-log.ts';
import { journalParts } from './model.ts';
import { localizedParts } from './localized-parts.ts';
import { createTranslator } from './localization/runtime.js';
@ -455,3 +456,56 @@ test('Earthquake never labels a non-target player as below its city threshold',
assert.deepEqual(event.explanations.map(e => e.player), [0]);
assert.match(event.explanations[0].text, /requires 3/);
});
for (const [name, id] of [['pandemics/drought', 52], ['famine/famine', 7]] as const) {
test(`${name}: an engine food loss and its explanation produce one badge`, () => {
const raw = JSON.parse(fixture(name));
raw.players[0].resources.food = 1;
const state = run(JSON.stringify(raw), advance);
assert.equal(JSON.parse(state).players[0].resources.food ?? 0, 0);
const game = JSON.parse(engine.stripSecret(state));
const before = JSON.stringify(game);
const items = game.log.flatMap((a: any) => a.rounds.flatMap((r: any) =>
r.turns.flatMap((t: any) => t.actions.flatMap((a: LoggedAction) => a.items ?? []))));
assert.ok(items.some((i: any) => i.origin?.Incident === id && i.Resources?.resources.food === 1));
assert.ok(items.some((i: any) => i.origin?.Incident === id && i.Text === 'Lost 1 food'));
const event = journal(game, view(state)).find(e => e.event)!;
assert.deepEqual(event.event!.outcomes.flatMap(e => e.tokens).filter(t => t.icon === 'food')
.map(t => t.value), ['−1']);
assert.equal(JSON.stringify(game), before, 'presentation must not change engine state or records');
});
}
test('food explanations are suppressed only beside their matching incident resource record', () => {
const famine = { ...info, id: 52, name: 'Famine: Draught' };
const loss = { player: 0, origin: { Incident: 52 }, Resources: { balance: 'Loss' as const, resources: { food: 1 } } };
const text = { player: 0, origin: { Incident: 52 }, Text: 'Lost 1 food' };
const count = (actions: LoggedAction[]) => {
const game = history(actions);
game.players.push({ ...game.players[0], id: 1, civilization: 'Phoenicia' });
return journal(game, publicView([famine]))
.flatMap(e => e.event ? e.event.outcomes : [e]).flatMap(e => e.tokens).filter(t => t.icon === 'food').length;
};
assert.equal(count([{ items: [loss] }]), 1);
assert.equal(count([{ items: [text] }]), 1);
assert.equal(count([{ log: ['Player1: Famine: Draught: Lost 1 food'] }]), 1);
assert.equal(count([{ items: [loss, text] }]), 1);
assert.equal(count([{ items: [loss, loss] }]), 2);
assert.equal(count([{ items: [loss, text, loss, text] }]), 2);
assert.equal(count([{ items: [loss, text, text] }]), 2);
assert.equal(count([{ items: [loss] }, { items: [text] }]), 2);
assert.equal(count([{ items: [loss, { ...text, origin: { Incident: 7 } }] }]), 2);
assert.equal(count([{ items: [loss, { ...text, player: 1 }] }]), 2);
assert.equal(count([{ items: [loss, { ...text, Text: 'Lost 2 food' }] }]), 2);
assert.equal(count([{ items: [loss, { ...text, Text: 'A separate effect' }, text] }]), 2);
assert.equal(count([{ items: [text, loss] }]), 2, 'prose before a loss is not its trailing explanation');
assert.equal(count([{ items: [{ ...loss, origin: { Advance: 'Storage' } }, { ...text, origin: { Advance: 'Storage' } }] }]), 2);
assert.equal(count([{ items: [{ ...loss, Resources: { balance: 'Gain', resources: { food: 1 } } }, text] }]), 2);
assert.equal(count([{ items: [{ ...loss, Resources: { balance: 'Loss', resources: { food: 1, wood: 1 } } }, text] }]), 2);
for (const origin of [undefined, { Incident: 52 }]) {
const game = readableHistory(history([{ items: [
{ ...loss, origin }, { ...text, origin, Text: 'Lost 1 food and became angry' },
] }]));
assert.ok(game.log![0].rounds[0].turns[0].actions![0].log!.some(line => line.endsWith('Lost 1 food and became angry')));
}
});

View file

@ -69,13 +69,26 @@ function lines(game: Game, action: LoggedAction, context?: Context): string[] {
result.push(`${actor(game, player)}: ${origin}: ${text}`);
if (collect && action.items?.length)
add(action.player ?? action.items[0].player, 'Collect', `Use city ${collect.city_position}`);
for (const item of action.items ?? []) {
const items = action.items ?? [];
for (const [index, item] of items.entries()) {
const played = playedCardId(action, item);
const origin = typeof played === 'number'
? source({ ...item, origin: { CivilCard: played } }, context)
: source(item, context);
const write = (text: string) => add(item.player, origin, text);
if (item.Text !== undefined && !offeredDiscount(item.Text)) {
// Famine's listener logs the loss, then repeats it as "Lost N food".
// Only suppress that adjacent explanation for the same incident and player;
// never deduplicate resource records (equal losses can be separate effects).
const previous = items[index - 1];
const foodLoss = item.Text?.match(/^Lost (\d+) food$/);
const repeatedFoodLoss = foodLoss &&
item.origin?.Incident !== undefined &&
previous?.origin?.Incident === item.origin.Incident &&
previous.player === item.player &&
previous.Resources?.balance === 'Loss' &&
previous.Resources.resources.food === Number(foodLoss[1]) &&
Object.entries(previous.Resources.resources).every(([resource, amount]) => resource === 'food' || !amount);
if (item.Text !== undefined && !offeredDiscount(item.Text) && !repeatedFoodLoss) {
const event = item.Text.match(/^triggers the event (.+)$/);
if (event) result.push(`A new game event has been triggered: ${event[1]}`);
else if (item.Text === 'wins the battle')