Players can select a non-allied recipient and explicitly pay a whole-spice bribe outside Mentat and open decision/response windows. The server derives private payment limits from uncommitted spice and existing joint Truthtrance completion checks on isolated copies. Target-specific Bureaucrat guards preserve supported redirect/allow continuations. Reserved bids, sealed spending and incoming escrow cannot be spent twice. No strategic AI negotiation or mode/publication changes. The panel separates deferred incoming bribes from spendable supply, disables stale/invalid selections and uses existing request/version fencing. The chronicle now describes actual payment and next-Mentat spendability rather than a promise. Internal guidance and the implementation checklist record this boundary. The separate Emperor gift/Bureaucrat source ambiguity remains explicitly pending. Independent review found no material issue. Focused tests cover out-of-turn payment, JSON escrow/collection, private budgets, invalid targets/amounts, phase/response gates, reserved bids, joint promises, supported redirection and rendered controls. Existing Bureaucrat SQLite/all-four legal response tests pass. The new HTTP test races duplicate submissions and verifies one debit, refreshed private balances and stale/over-budget rejection. Types, lint, all 4968 offline tests, production build and 49 HTTP tests pass on stable source. Preliminary checks caught a typed fixture opener and semantic-status/internal-link/template lint requirements and the new SSR test needed the existing Vinext Link alias. All were corrected before the final4 run. Browser QA used genuine fresh Basic setup with a human payer and Easy AI recipient: 11 rejected by controls, 4 paid from10 leaving6, one public payment entry and unchanged recipient spendable10 with4 in escrow after refresh. Keyboard selection and amount access passed. At390px the panel fits with16px text and44px-or-larger controls; linked rules and back navigation work. Screenshot capture timed out; full visual/assistive and all-configuration acceptance remain open. Browser transport loss was not injected; HTTP concurrency is separately covered. This is playability evidence, not difficulty calibration. All 1418 original rooms, 2991 seats and auxiliary rows are unchanged. SQLite integrity and foreign keys pass. The healthy server was reused without restart, migration, reset or recurring maintenance. Private evidence: 20260921-bribe-controls. Verified source tree: b9a8594c5dcd85f78974c9647f24f5f6eba60a38c9dcd2badcf4529d1e825ae1
62 lines
3.1 KiB
TypeScript
62 lines
3.1 KiB
TypeScript
// @dune-suite integration
|
|
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import type { GameView } from '../game/engine';
|
|
|
|
const base = process.env.DUNE_TEST_URL ?? 'http://localhost:3000';
|
|
async function request(path: string, cookie?: string, body?: unknown) {
|
|
const response = await fetch(base + path, {
|
|
method: body === undefined ? 'GET' : 'POST',
|
|
signal: AbortSignal.timeout(15_000),
|
|
headers: { ...(cookie ? { cookie } : {}), ...(body ? { 'Content-Type': 'application/json' } : {}) },
|
|
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
});
|
|
return { status: response.status, cookie: response.headers.get('set-cookie')?.split(';')[0],
|
|
data: await response.json() as GameView };
|
|
}
|
|
|
|
void test('bribe HTTP payment is atomic, rejects duplicate/stale writes and restores owner-only budgets', async () => {
|
|
const host = await request('/api/rooms', undefined, {
|
|
name: 'Bribe HTTP payer', faction: 'atreides', advanced: false, expansions: [],
|
|
});
|
|
assert.equal(host.status, 201); assert.ok(host.cookie);
|
|
const path = `/api/rooms/${host.data.code}`;
|
|
const peer = await request(path, undefined, { type: 'join', name: 'Bribe HTTP recipient', faction: 'harkonnen' });
|
|
assert.equal(peer.status, 200); assert.ok(peer.cookie);
|
|
let view = peer.data;
|
|
async function act(cookie: string, action: object) {
|
|
const next = await request(path, cookie, { version: view.version, action });
|
|
assert.equal(next.status, 200); view = next.data;
|
|
}
|
|
await act(host.cookie, { type: 'ready' });
|
|
await act(peer.cookie, { type: 'ready' });
|
|
await act(host.cookie, { type: 'start' });
|
|
const own = view.players.find(p => p.id === host.data.me)!;
|
|
await act(host.cookie, { type: 'traitor', leader: own.traitorChoices![0] });
|
|
assert.equal(view.status, 'playing');
|
|
assert.equal(view.bribeOptions.available, 10);
|
|
const version = view.version;
|
|
const action = { type: 'bribe', target: peer.data.me, amount: 4 };
|
|
const replies = await Promise.all([
|
|
request(path, host.cookie, { version, action }), request(path, host.cookie, { version, action }),
|
|
]);
|
|
assert.equal(replies.filter(reply => reply.status === 200).length, 1);
|
|
assert.equal(replies.filter(reply => reply.status >= 400).length, 1);
|
|
for (const [cookie, id, available, incoming] of [
|
|
[host.cookie, host.data.me, 6, 0], [peer.cookie, peer.data.me, 10, 4],
|
|
] as const) {
|
|
const restored = await request(path, cookie);
|
|
assert.equal(restored.status, 200);
|
|
assert.equal(restored.data.version, version + 1);
|
|
assert.equal(restored.data.me, id);
|
|
assert.equal(restored.data.bribeOptions.available, available);
|
|
assert.equal(restored.data.bribeOptions.incoming, incoming);
|
|
for (const rival of restored.data.players.filter(p => p.id !== id)) {
|
|
assert.equal(rival.spice, undefined); assert.equal(rival.bribes, undefined);
|
|
assert.equal(rival.hand, undefined); assert.equal(rival.traitors, undefined);
|
|
}
|
|
}
|
|
assert.ok((await request(path, host.cookie, { version: version + 1, action: { ...action, amount: 7 } })).status >= 400);
|
|
assert.equal((await request(path, host.cookie)).data.version, version + 1);
|
|
});
|