Add one-use consent for a named player to start seat AI

Let a human owner authorize another human in the started room to start a fixed difficulty once within 24 hours. The owner retains the seat, cookie, private hand, recovery setup and takeback control. Consent is explicit even while online; neither host status nor inactivity authorizes a takeover. Activation enters the existing paced private-view AI path without strategic changes.

Add additive migration 0006, both exact session fences, owner/delegate-only metadata in the authenticated room snapshot, atomic CAS activation and consumption, expiry and terminal retry receipts. Replacement hides older consent; own AI changes invalidate unused consent. Recovery or handover of either bound seat invalidates the grant. Future-version guards prevent stale computed state from overwriting a racing action. Exact browser retry records retain the original operation/version across refresh and cannot rearm old consent. Shared HTTP continuation preserves coalescing across ordinary and control routes.

Independent review found no material remaining issue. Revoke messaging accurately handles activation winning the race. Browser QA exercised grant/revoke, preserved consent after refresh, reciprocal fixed-profile activation, consumed receipts, keyboard takeback and private ownership. The panel now remains expanded after success and action buttons are at least 44px. Responsive screenshot acceptance remains open because the browser viewport override targeted a failed secondary-origin tab; desktop controls and no-overflow width were verified. The QA room is stopped at a genuine human setup decision with both seats taken back.

Types, lint, all 4906 offline tests, production build and all 45 HTTP tests pass on the stable source fingerprint. Seven new offline cases cover client consent/retry validation and real SQLite privacy, restart, one-use races, future versions, takeback, expiry and both-seat recovery/handover; two new HTTP cases cover authentication, injection, fixed-profile continuation and takeback. The first broad run exposed 68 legacy VM fixtures missing the new production dependency; their mappings were updated and the real shared continuation remains exercised. The historical 0005 migration test verifies backfill before applying 0006 for current code.

All 1174 original rooms, 2456 seats and every prior recovery/entry/handover/migration row remain unchanged. SQLite integrity and foreign keys pass; migration and QA added 88 rooms and 188 seats. No reset, server restart, usage check or automation was performed.

The current Sites integration has no supported durable Cron/DO provisioning path. Document this platform blocker rather than adding an inert scheduled export; unattended resumption and broader network-failure acceptance remain unfinished. Full rules, component, AI strength and publication gates remain closed.

Verified source tree: 2d86fc611e9ef4f5a10db10f96687a31db1ec238908ecf1e9333c50fac9ccaa8
This commit is contained in:
Quintine committed 2026-09-20 16:30:37 +10:00
1 parent e13ad454e2
commit b21b2bc378
93 files changed
+2996 -72

No files matched your search

@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import type * as Rooms from '../db/rooms';
@@ -80,6 +81,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,8 +7,10 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import type * as Rooms from '../db/rooms';
import { loadRoomContinuation } from './fixture-room-continuation';
/** Execute the production room module and SQL, with a hook immediately before its CAS. */
function unitStore(runBots = bots.runBots) {
@@ -81,6 +83,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -262,6 +265,10 @@ function route(
run: (code: string) => Promise<void>,
) {
const pending: Promise<void>[] = [];
const continuation = loadRoomContinuation({
continueRoomAutomatic: automatic,
continueRoomBots: run,
});
const exports: {
GET?: (req: Request) => Promise<Response>;
POST?: (req: Request) => Promise<Response>;
@@ -291,6 +298,7 @@ function route(
continueRoomAutomatic: automatic,
continueRoomBots: run,
};
if (name === '@/db/room-continuation') return continuation;
if (name === '@/game/engine') return engine;
if (name === 'cloudflare:workers')
return { waitUntil: (work: Promise<void>) => pending.push(work) };
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import type { FactionId } from '../game/catalog';
import type * as Rooms from '../db/rooms';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import type * as Rooms from '../db/rooms';
@@ -80,6 +81,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import type * as Rooms from '../db/rooms';
import { createRequire } from 'node:module';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import { richeseCards } from '../game/richese-cards';
import type * as Rooms from '../db/rooms';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import { richeseCards } from '../game/richese-cards';
import type * as Rooms from '../db/rooms';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
import { homeworldGameIntegrity } from '../game/homeworld-game';
@@ -80,6 +81,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
/** Execute the production room module and SQL, with a hook immediately before its CAS. */
@@ -80,6 +81,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+9
View File
@@ -7,7 +7,9 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
import { loadRoomContinuation } from './fixture-room-continuation';
/** Execute the production room module and SQL, with a hook immediately before its CAS. */
function unitStore(runBots = bots.runBots) {
@@ -80,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -323,6 +326,11 @@ void test('authenticated GET schedules the persisted queue after reconnect while
const f = await fixture();
try {
const pending: Promise<unknown>[] = [];
const continuation = loadRoomContinuation({
continueRoomAutomatic: async () => {},
continueRoomBots: (code: string) =>
f.rooms.continueRoomBots(code, 1, f.clock),
});
const exports: { GET?: (req: Request) => Promise<Response> } = {};
runInNewContext(
ts.transpileModule(
@@ -349,6 +357,7 @@ void test('authenticated GET schedules the persisted queue after reconnect while
continueRoomBots: (code: string) =>
f.rooms.continueRoomBots(code, 1, f.clock),
};
if (name === '@/db/room-continuation') return continuation;
if (name === '@/game/engine') return engine;
if (name === 'cloudflare:workers')
return {
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import type * as Rooms from '../db/rooms';
import { createRequire } from 'node:module';
@@ -82,6 +83,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck, createAuditorLeader } from '../game/cards';
import type * as Rooms from '../db/rooms';
@@ -80,6 +81,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import { newRevivalRules } from '../game/revival';
import type * as Rooms from '../db/rooms';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import type * as Rooms from '../db/rooms';
@@ -80,6 +81,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import type * as Rooms from '../db/rooms';
@@ -80,6 +81,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import { richeseCards } from '../game/richese-cards';
import type * as Rooms from '../db/rooms';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import { createAmbassadors, placeAmbassador } from '../game/ecaz-ambassadors';
import { createDukeVidal } from '../game/duke-vidal';
@@ -82,6 +83,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import type * as Rooms from '../db/rooms';
@@ -80,6 +81,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import {
createAmbassadors,
@@ -86,6 +87,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import {
createAmbassadors,
@@ -86,6 +87,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import type * as Rooms from '../db/rooms';
@@ -80,6 +81,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import { createStrongholdCards } from '../game/stronghold-cards';
import type * as Rooms from '../db/rooms';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -5,6 +5,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
/** Execute the production room module and SQL, with a hook immediately before its CAS. */
@@ -82,6 +83,7 @@ export function unitStore(runBots = bots.runBots, migrationThrough?: string) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+37
View File
@@ -0,0 +1,37 @@
import { readFileSync } from 'node:fs';
import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import type * as Rooms from '../db/rooms';
import type * as RoomContinuation from '../db/room-continuation';
/** Load the production isolate-local continuation gate with fixture room calls. */
export function loadRoomContinuation(
rooms: Pick<
typeof Rooms,
'continueRoomAutomatic' | 'continueRoomBots'
>,
) {
const exports = {};
runInNewContext(
ts.transpileModule(
readFileSync(
new URL('../db/room-continuation.ts', import.meta.url),
'utf8',
),
{
compilerOptions: {
module: ts.ModuleKind.CommonJS,
target: ts.ScriptTarget.ES2022,
},
},
).outputText,
{
exports,
require: (name: string) => {
if (name === './rooms') return rooms;
throw new Error('Unexpected continuation dependency ' + name);
},
},
);
return exports as typeof RoomContinuation;
}
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import {
createAmbassadors,
@@ -86,6 +87,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import { TERRITORIES, gameDistance, location } from '../game/board';
import type * as Rooms from '../db/rooms';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import { createDukeVidal, DUKE_VIDAL_ID } from '../game/duke-vidal';
import type * as Rooms from '../db/rooms';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
import { homeworldGameIntegrity } from '../game/homeworld-game';
@@ -80,6 +81,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import {
createAmbassadors,
@@ -85,6 +86,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
import { homeworldGameIntegrity } from '../game/homeworld-game';
import { richeseCards } from '../game/richese-cards';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import type * as Rooms from '../db/rooms';
@@ -80,6 +81,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
import {
homeworldContext,
@@ -87,6 +88,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
import type { FactionId } from '../game/catalog';
import { homeworldGameIntegrity } from '../game/homeworld-game';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
import { homeworldGameIntegrity } from '../game/homeworld-game';
@@ -80,6 +81,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
import { homeworldGameIntegrity } from '../game/homeworld-game';
@@ -80,6 +81,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
import { MOBILE_LOCATION, mobileRoutes } from '../game/board';
import { homeworldGameIntegrity } from '../game/homeworld-game';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
import { homeworldGameIntegrity } from '../game/homeworld-game';
@@ -80,6 +81,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
/** Execute the production room module and SQL, with a hook immediately before its CAS. */
@@ -79,6 +80,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
import { homeworldGameIntegrity } from '../game/homeworld-game';
@@ -80,6 +81,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
import { homeworldGameIntegrity } from '../game/homeworld-game';
@@ -80,6 +81,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
import { homeworldGameIntegrity } from '../game/homeworld-game';
import { richeseCards } from '../game/richese-cards';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
import { homeworldGameIntegrity } from '../game/homeworld-game';
@@ -80,6 +81,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
import { homeworldGameIntegrity } from '../game/homeworld-game';
@@ -80,6 +81,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
import { homeworldGameIntegrity } from '../game/homeworld-game';
import { homeworldVictoryObligationSignature } from '../game/homeworld-victory-return';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import { richeseCards } from '../game/richese-cards';
import type * as Rooms from '../db/rooms';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
import { homeworldGameIntegrity } from '../game/homeworld-game';
@@ -80,6 +81,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import type * as Rooms from '../db/rooms';
import { createAmbassadors } from '../game/ecaz-ambassadors';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import { richeseCards } from '../game/richese-cards';
import type * as Rooms from '../db/rooms';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { treacheryDeck } from '../game/cards';
import { createTechTokens } from '../game/tech-tokens';
import type * as Rooms from '../db/rooms';
@@ -82,6 +83,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import { richeseCards } from '../game/richese-cards';
import {
@@ -87,6 +88,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import { richeseCards } from '../game/richese-cards';
import {
@@ -85,6 +86,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
/** Execute the production room module and SQL, with a hook immediately before its CAS. */
@@ -80,6 +81,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import type * as Rooms from '../db/rooms';
@@ -80,6 +81,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import { createAmbassadors } from '../game/ecaz-ambassadors';
import { createTerrorState } from '../game/moritani-terror';
@@ -83,6 +84,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import { richeseCards } from '../game/richese-cards';
import type * as Rooms from '../db/rooms';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import { richeseCards } from '../game/richese-cards';
import type * as Rooms from '../db/rooms';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import { richeseCards } from '../game/richese-cards';
import type * as Rooms from '../db/rooms';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import {
createRicheseNoField,
@@ -84,6 +85,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import { richeseCards } from '../game/richese-cards';
import type * as Rooms from '../db/rooms';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import { richeseCards } from '../game/richese-cards';
import type * as Rooms from '../db/rooms';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import { createRicheseNoField } from '../game/richese-no-field';
import type * as Rooms from '../db/rooms';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -8,6 +8,7 @@ import { DatabaseSync } from 'node:sqlite';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
const base = process.env.DUNE_TEST_URL ?? 'http://localhost:3000';
@@ -439,6 +440,7 @@ function unitStore() {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return bots;
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
});
+142
View File
@@ -0,0 +1,142 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {
parseSeatAiDelegateRequest,
seatAiDelegateStorageKey,
storeSeatAiDelegateRequest,
validSeatAiDelegateRequest,
type SeatAiDelegateRequest,
} from '../lib/seat-ai-delegation';
const ownerId = crypto.randomUUID(),
delegateId = crypto.randomUUID(),
grantId = crypto.randomUUID();
const request: SeatAiDelegateRequest = {
type: 'setSeatAiDelegate',
version: 12,
grantId,
delegateId,
difficulty: 'Hard',
};
function storage() {
const values = new Map<string, string>();
return {
getItem: (key: string) => values.get(key) ?? null,
setItem: (key: string, value: string) => {
values.set(key, value);
},
removeItem: (key: string) => {
values.delete(key);
},
};
}
void test('AI permission retry preserves exact consent and original version across refresh; cannot replace an uncertain request', () => {
const tab = storage(),
key = seatAiDelegateStorageKey('ABCDEFGH', ownerId);
storeSeatAiDelegateRequest(tab, key, request);
const restored = parseSeatAiDelegateRequest(tab.getItem(key)!);
assert.deepEqual(restored, request);
assert.equal(Object.isFrozen(restored), true);
storeSeatAiDelegateRequest(tab, key, restored);
for (const replacement of [
{ ...request, version: 13 },
{ ...request, grantId: crypto.randomUUID() },
{ ...request, delegateId: ownerId },
])
assert.throws(
() => storeSeatAiDelegateRequest(tab, key, replacement),
/Resolve the saved/,
);
assert.equal(
tab.getItem(seatAiDelegateStorageKey('ABCDEFGH', delegateId)),
null,
);
assert.equal(
tab.getItem(seatAiDelegateStorageKey('BCDEFGHJ', ownerId)),
null,
);
storeSeatAiDelegateRequest(tab, key, null);
assert.equal(tab.getItem(key), null);
storeSeatAiDelegateRequest(tab, key, {
...request,
grantId: crypto.randomUUID(),
});
});
void test('AI permission request validation rejects alternate profiles, target injection, credentials, malformed versions and stored extras', () => {
const use: SeatAiDelegateRequest = {
type: 'useSeatAiDelegate',
version: 13,
grantId,
ownerId,
};
const revoke: SeatAiDelegateRequest = {
type: 'revokeSeatAiDelegate',
version: 13,
grantId,
};
for (const good of [request, use, revoke])
assert.equal(validSeatAiDelegateRequest(good), true);
for (const bad of [
{ ...request, ownerId },
{ ...request, sessionToken: 'secret' },
{ ...request, difficulty: 'Impossible' },
{ ...request, version: -1 },
{ ...request, version: 2.5 },
{ ...request, version: '12' },
{ ...request, grantId: '' },
{ ...request, delegateId: 'another player' },
{ ...use, difficulty: 'Brutal' },
{ ...use, delegateId },
{ ...revoke, ownerId },
{ ...request, type: 'setAutopilot' },
null,
[],
]) {
assert.equal(validSeatAiDelegateRequest(bad), false);
assert.throws(() => parseSeatAiDelegateRequest(JSON.stringify(bad)));
}
assert.throws(() => parseSeatAiDelegateRequest(' '.repeat(2001)));
});
void test('AI permission storage must persist exactly before a request can be dispatched', () => {
const key = seatAiDelegateStorageKey('ABCDEFGH', ownerId);
assert.throws(
() =>
storeSeatAiDelegateRequest(
{ getItem: () => null, setItem: () => {}, removeItem: () => {} },
key,
request,
),
/could not be saved/,
);
assert.throws(
() =>
storeSeatAiDelegateRequest(
{
getItem: () => JSON.stringify(request),
setItem: () => {},
removeItem: () => {},
},
key,
null,
),
/could not be saved/,
);
assert.throws(
() =>
storeSeatAiDelegateRequest(
{
getItem: () => {
throw new Error('blocked');
},
setItem: () => {},
removeItem: () => {},
},
key,
request,
),
/blocked/,
);
});
+233
View File
@@ -0,0 +1,233 @@
// @dune-suite integration
import test from 'node:test';
import assert from 'node:assert/strict';
import { setTimeout as pause } from 'node:timers/promises';
import type { GameView } from '../game/engine';
const base = process.env.DUNE_TEST_URL ?? 'http://localhost:3000';
async function request(
path: string,
body?: unknown,
cookie?: string,
origin?: string,
) {
const response = await fetch(base + path, {
method: body === undefined ? 'GET' : 'POST',
signal: AbortSignal.timeout(15_000),
headers: {
...(body === undefined ? {} : { 'Content-Type': 'application/json' }),
...(cookie ? { cookie } : {}),
...(origin ? { origin } : {}),
},
...(body === undefined ? {} : { body: JSON.stringify(body) }),
});
const raw = await response.text();
let data: unknown;
try {
data = JSON.parse(raw);
} catch {
data = { error: 'Non-JSON response' };
}
return {
status: response.status,
data: data as GameView & {
view: GameView;
replayed?: boolean;
error?: string;
},
cookie: response.headers.get('set-cookie')?.split(';')[0],
cache: response.headers.get('cache-control'),
};
}
async function fixture() {
const a = await request('/api/rooms', {
name: 'AI permission owner',
faction: 'atreides',
advanced: false,
expansions: [],
});
assert.equal(a.status, 201);
assert.ok(a.cookie);
const path = `/api/rooms/${a.data.code}`;
const b = await request(path, {
type: 'join',
name: 'AI permission delegate',
faction: 'emperor',
});
const c = await request(path, {
type: 'join',
name: 'AI permission observer',
faction: 'guild',
});
assert.equal(b.status, 200);
assert.ok(b.cookie);
assert.equal(c.status, 200);
assert.ok(c.cookie);
let view = c.data;
for (const player of [a, b, c]) {
const ready = await request(
path,
{ version: view.version, action: { type: 'ready' } },
player.cookie,
);
assert.equal(ready.status, 200);
view = ready.data;
}
const started = await request(
path,
{ version: view.version, action: { type: 'start' } },
a.cookie,
);
assert.equal(started.status, 200);
assert.equal(started.data.status, 'setup');
return { a, b, c, path, view: started.data };
}
function privateView(view: GameView, ownId: string) {
assert.equal(view.me, ownId);
assert.ok(view.players.find((player) => player.id === ownId)?.traitorChoices);
for (const player of view.players.filter((player) => player.id !== ownId))
for (const key of ['hand', 'traitors', 'traitorChoices', 'spice'])
assert.equal(key in player, false, `Other seat exposed ${key}`);
for (const secret of [
'ownerSessionHash',
'delegateSessionHash',
'owner_session_hash',
'delegate_session_hash',
'tokenHash',
])
assert.equal(JSON.stringify(view).includes(secret), false);
}
void test('AI permission HTTP restricts creation/use/revoke to consented identities and rejects injection without mutation', async () => {
const f = await fixture(),
control = f.path + '/control';
const grant = {
type: 'setSeatAiDelegate',
version: f.view.version,
grantId: crypto.randomUUID(),
delegateId: f.b.data.me,
difficulty: 'Hard',
};
assert.equal((await request(control, grant)).status, 409);
assert.equal(
(await request(control, grant, f.a.cookie, 'https://other.invalid')).status,
403,
);
for (const body of [
{ ...grant, ownerId: f.c.data.me },
{ ...grant, delegateId: f.a.data.me },
{ ...grant, difficulty: 'Invalid' },
])
assert.ok((await request(control, body, f.a.cookie)).status >= 400);
assert.equal(
(await request(f.path, undefined, f.a.cookie)).data.version,
f.view.version,
);
const made = await request(control, grant, f.a.cookie);
assert.equal(made.status, 200);
assert.equal(made.cache, 'no-store');
assert.equal(made.data.view.seatAiDelegations?.[0].grantId, grant.grantId);
const replay = await request(control, grant, f.a.cookie);
assert.equal(replay.status, 200);
assert.equal(replay.data.replayed, true);
const other = await request(f.path, undefined, f.c.cookie);
assert.equal(other.data.seatAiDelegations, undefined);
const read = await request(f.path, undefined, f.b.cookie);
assert.equal(read.data.seatAiDelegations?.[0].grantId, grant.grantId);
privateView(read.data, f.b.data.me);
const activate = {
type: 'useSeatAiDelegate',
version: read.data.version,
ownerId: f.a.data.me,
grantId: grant.grantId,
};
for (const [body, cookie] of [
[activate, f.c.cookie],
[{ ...activate, difficulty: 'Brutal' }, f.b.cookie],
[
{
type: 'revokeSeatAiDelegate',
version: read.data.version,
grantId: grant.grantId,
},
f.b.cookie,
],
] as const)
assert.ok((await request(control, body, cookie)).status >= 400);
assert.equal(
(await request(f.path, undefined, f.a.cookie)).data.version,
read.data.version,
);
});
void test('AI permission HTTP starts only the chosen profile, resumes paced work, preserves ownership and cannot reactivate after takeback', async () => {
const f = await fixture(),
control = f.path + '/control';
const grant = {
type: 'setSeatAiDelegate',
version: f.view.version,
grantId: crypto.randomUUID(),
delegateId: f.b.data.me,
difficulty: 'Medium',
};
const made = await request(control, grant, f.a.cookie);
assert.equal(made.status, 200);
const activate = {
type: 'useSeatAiDelegate',
version: made.data.view.version,
ownerId: f.a.data.me,
grantId: grant.grantId,
};
const used = await request(control, activate, f.b.cookie);
assert.equal(used.status, 200);
assert.equal(used.cookie, undefined);
assert.equal(used.cache, 'no-store');
privateView(used.data.view, f.b.data.me);
assert.equal(
used.data.view.players.find((player) => player.id === f.a.data.me)
?.autopilot,
'Medium',
);
assert.ok(
used.data.view.seatAiDelegations?.find(
(entry) => entry.grantId === grant.grantId,
)?.usedAt,
);
const deadline = Date.now() + 10_000;
let own = await request(f.path, undefined, f.a.cookie);
while (own.data.botsPending && Date.now() < deadline) {
await pause(150);
own = await request(f.path, undefined, f.a.cookie);
}
assert.equal(own.status, 200);
assert.equal(own.data.me, f.a.data.me);
assert.equal(own.data.botsPending, false);
assert.ok(
own.data.version > used.data.view.version,
'Server continuation should advance the AI setup choice.',
);
const back = await request(
f.path,
{
version: own.data.version,
action: { type: 'setAutopilot', difficulty: null },
},
f.a.cookie,
);
assert.equal(back.status, 200);
assert.equal(
back.data.players.find((player) => player.id === f.a.data.me)?.autopilot,
undefined,
);
// Both exact lost-response retry and newly versioned reuse must remain harmless.
for (const version of [activate.version, back.data.version]) {
const retry = await request(control, { ...activate, version }, f.b.cookie);
assert.ok([200, 409].includes(retry.status));
const current = await request(f.path, undefined, f.a.cookie);
assert.equal(current.data.version, back.data.version);
assert.equal(
current.data.players.find((player) => player.id === f.a.data.me)
?.autopilot,
undefined,
);
}
});
+527
View File
@@ -0,0 +1,527 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { DatabaseSync } from 'node:sqlite';
import type { Game } from '../game/engine';
import { unitStore } from './fixture-nexus-room-store';
const UUID = {
ownerEntry: '71000000-0000-4000-8000-000000000001',
delegateEntry: '71000000-0000-4000-8000-000000000002',
observerEntry: '71000000-0000-4000-8000-000000000003',
grant1: '71000000-0000-4000-8000-000000000011',
grant2: '71000000-0000-4000-8000-000000000012',
grant3: '71000000-0000-4000-8000-000000000013',
grant4: '71000000-0000-4000-8000-000000000014',
recovery: '71000000-0000-4000-8000-000000000021',
offer: '71000000-0000-4000-8000-000000000022',
claim: '71000000-0000-4000-8000-000000000023',
};
const secret = (pair: string) => pair.repeat(32);
const clock = (now: number) => ({
now: () => now,
sleep: async () => {},
});
async function fixture() {
const store = unitStore();
assert.ok(store.sqlite instanceof DatabaseSync);
const owner = await store.rooms.createRoom('Owner', 'atreides', false, [], {
operationId: UUID.ownerEntry,
sessionToken: secret('11'),
});
const code = owner.view.code;
const delegate = await store.rooms.joinRoom(code, 'Delegate', 'emperor', {
operationId: UUID.delegateEntry,
sessionToken: secret('22'),
});
const observer = await store.rooms.joinRoom(code, 'Observer', 'fremen', {
operationId: UUID.observerEntry,
sessionToken: secret('33'),
});
assert.ok(delegate.token);
assert.ok(observer.token);
const auths = {
owner: await store.rooms.authenticate(code, owner.token),
delegate: await store.rooms.authenticate(code, delegate.token),
observer: await store.rooms.authenticate(code, observer.token),
};
for (const auth of Object.values(auths)) {
const current = await store.rooms.readRoom(code);
await store.rooms.act(code, auth, current.version, { type: 'ready' });
}
const beforeStart = await store.rooms.readRoom(code);
await store.rooms.act(code, auths.owner, beforeStart.version, {
type: 'start',
});
return {
...store,
code,
owner,
delegate,
observer,
ownerId: auths.owner.playerId,
delegateId: auths.delegate.playerId,
observerId: auths.observer.playerId,
auths,
};
}
const delegation = (
f: Awaited<ReturnType<typeof fixture>>,
grantId: string,
) => ({
grantId,
delegateId: f.delegateId,
difficulty: 'Hard' as const,
});
function storedState(f: Awaited<ReturnType<typeof fixture>>) {
return f.sqlite.prepare('SELECT state FROM rooms WHERE code = ?').get(f.code)!
.state as string;
}
function withoutDelegationActivation(game: Game) {
const copy = structuredClone(game);
delete copy.botsPending;
delete copy.botNextActionAt;
copy.version = 0;
copy.log = [];
for (const player of copy.players) delete player.autopilot;
return copy;
}
void test('delegation is private, survives restart, activates once and preserves sealed setup state', async () => {
const f = await fixture();
try {
const beforeState = storedState(f);
const before = JSON.parse(beforeState) as Game;
const version = (await f.rooms.readRoom(f.code)).version;
const saved = await f.rooms.setSeatAiDelegate(
f.code,
f.auths.owner,
version,
delegation(f, UUID.grant1),
clock(1000),
);
assert.equal(saved.replayed, false);
assert.equal(storedState(f), beforeState);
assert.deepEqual(saved.view.seatAiDelegations, [
{
grantId: UUID.grant1,
ownerId: f.ownerId,
delegateId: f.delegateId,
difficulty: 'Hard',
expiresAt: 1000 + f.rooms.SEAT_AI_DELEGATION_TTL_MS,
usedAt: null,
},
]);
assert.deepEqual(
(await f.restart().readSeatView(f.code, f.auths.delegate))
.seatAiDelegations,
saved.view.seatAiDelegations,
);
const observer = await f.rooms.readSeatView(f.code, f.auths.observer);
assert.equal(Object.hasOwn(observer, 'seatAiDelegations'), false);
for (const view of [saved.view, observer]) {
const text = JSON.stringify(view);
assert.equal(text.includes('session_hash'), false);
assert.equal(text.includes(secret('11')), false);
assert.equal(text.includes(secret('22')), false);
}
let reachedBatch = false;
f.hooks.beforeBatch = async () => {
reachedBatch = true;
};
const beforeFutureVersion = storedState(f);
await assert.rejects(
f.rooms.useSeatAiDelegate(
f.code,
f.auths.delegate,
saved.view.version + 1,
{ ownerId: f.ownerId, grantId: UUID.grant1 },
clock(1750),
),
/table changed/i,
);
assert.equal(reachedBatch, false);
delete f.hooks.beforeBatch;
assert.equal(storedState(f), beforeFutureVersion);
let entered!: () => void;
let release!: () => void;
const waiting = new Promise<void>((resolve) => (entered = resolve));
const gate = new Promise<void>((resolve) => (release = resolve));
f.hooks.beforeBatch = async () => {
delete f.hooks.beforeBatch;
entered();
await gate;
};
const pending = f.rooms.useSeatAiDelegate(
f.code,
f.auths.delegate,
saved.view.version,
{ ownerId: f.ownerId, grantId: UUID.grant1 },
clock(2000),
);
await waiting;
const duplicate = await f
.restart()
.useSeatAiDelegate(
f.code,
f.auths.delegate,
saved.view.version,
{ ownerId: f.ownerId, grantId: UUID.grant1 },
clock(2000),
);
release();
const first = await pending;
assert.deepEqual(
[first.replayed, duplicate.replayed].sort(
(a, b) => Number(a) - Number(b),
),
[false, true],
);
const after = await f.rooms.readRoom(f.code);
assert.equal(after.version, saved.view.version + 1);
assert.equal(
after.players.find((player) => player.id === f.ownerId)?.autopilot,
'Hard',
);
assert.equal(after.botsPending, true);
assert.equal(after.botNextActionAt, 3500);
assert.match(
after.log.at(-1)!.text,
/Delegate activated Hard AI for Owner/,
);
assert.equal(
after.log.filter((entry) => entry.text.includes('one-use delegation'))
.length,
1,
);
assert.deepEqual(
withoutDelegationActivation(after),
withoutDelegationActivation(before),
);
assert.deepEqual(
(await f.rooms.readSeatView(f.code, f.auths.owner)).seatAiDelegations,
[
{
grantId: UUID.grant1,
ownerId: f.ownerId,
delegateId: f.delegateId,
difficulty: 'Hard',
expiresAt: 1000 + f.rooms.SEAT_AI_DELEGATION_TTL_MS,
usedAt: 2000,
},
],
);
} finally {
f.sqlite.close();
}
});
void test('replacement, revoke, expiry and owner control cannot be bypassed by stale consent', async () => {
const f = await fixture();
try {
const view = await f.rooms.readSeatView(f.code, f.auths.owner);
let reachedBatch = false;
f.hooks.beforeBatch = async () => {
reachedBatch = true;
};
await assert.rejects(
f.rooms.setSeatAiDelegate(
f.code,
f.auths.owner,
view.version + 1,
delegation(f, UUID.grant1),
clock(500),
),
/table changed/i,
);
assert.equal(reachedBatch, false);
delete f.hooks.beforeBatch;
const first = await f.rooms.setSeatAiDelegate(
f.code,
f.auths.owner,
view.version,
delegation(f, UUID.grant1),
clock(1000),
);
const replay = await f.rooms.setSeatAiDelegate(
f.code,
f.auths.owner,
first.view.version,
delegation(f, UUID.grant1),
clock(1500),
);
assert.equal(replay.replayed, true);
assert.equal(replay.view.version, first.view.version);
const replaced = await f.rooms.setSeatAiDelegate(
f.code,
f.auths.owner,
first.view.version,
delegation(f, UUID.grant2),
clock(2000),
);
assert.deepEqual(
replaced.view.seatAiDelegations?.map((item) => item.grantId),
[UUID.grant2],
);
const rejectedState = storedState(f);
await assert.rejects(
f.rooms.useSeatAiDelegate(
f.code,
f.auths.delegate,
replaced.view.version,
{ ownerId: f.ownerId, grantId: UUID.grant1 },
clock(2500),
),
/revoked|replaced/,
);
assert.equal(storedState(f), rejectedState);
const revoked = await f.rooms.revokeSeatAiDelegate(
f.code,
f.auths.owner,
replaced.view.version,
UUID.grant2,
clock(3000),
);
assert.equal(revoked.replayed, false);
assert.equal(Object.hasOwn(revoked.view, 'seatAiDelegations'), false);
const revokeReplay = await f.rooms.revokeSeatAiDelegate(
f.code,
f.auths.owner,
replaced.view.version,
UUID.grant2,
clock(3500),
);
assert.equal(revokeReplay.replayed, true);
assert.equal(revokeReplay.view.version, revoked.view.version);
const expiring = await f.rooms.setSeatAiDelegate(
f.code,
f.auths.owner,
revoked.view.version,
delegation(f, UUID.grant3),
clock(4000),
);
const beforeExpiry = storedState(f);
await assert.rejects(
f.rooms.useSeatAiDelegate(
f.code,
f.auths.delegate,
expiring.view.version,
{ ownerId: f.ownerId, grantId: UUID.grant3 },
clock(4000 + f.rooms.SEAT_AI_DELEGATION_TTL_MS),
),
/expired/,
);
assert.equal(storedState(f), beforeExpiry);
const current = await f.rooms.readRoom(f.code);
const ownAi = await f.rooms.act(
f.code,
f.auths.owner,
current.version,
{ type: 'setAutopilot', difficulty: 'Easy' },
clock(5000),
);
assert.equal(Object.hasOwn(ownAi, 'seatAiDelegations'), false);
await assert.rejects(
f.rooms.useSeatAiDelegate(
f.code,
f.auths.delegate,
ownAi.version,
{ ownerId: f.ownerId, grantId: UUID.grant3 },
clock(5500),
),
/revoked|replaced/,
);
} finally {
f.sqlite.close();
}
});
void test('owner control and delegated activation serialize without stale takeback or double enable', async () => {
for (const winner of ['owner', 'delegate'] as const) {
const f = await fixture();
try {
const initial = await f.rooms.readSeatView(f.code, f.auths.owner);
const granted = await f.rooms.setSeatAiDelegate(
f.code,
f.auths.owner,
initial.version,
delegation(f, UUID.grant1),
clock(1000),
);
let entered!: () => void;
let release!: () => void;
const waiting = new Promise<void>((resolve) => (entered = resolve));
const gate = new Promise<void>((resolve) => (release = resolve));
f.hooks.beforeBatch = async () => {
delete f.hooks.beforeBatch;
entered();
await gate;
};
if (winner === 'owner') {
const pendingUse = f.rooms.useSeatAiDelegate(
f.code,
f.auths.delegate,
granted.view.version,
{ ownerId: f.ownerId, grantId: UUID.grant1 },
clock(2000),
);
await waiting;
const controlled = await f
.restart()
.act(
f.code,
f.auths.owner,
granted.view.version,
{ type: 'setAutopilot', difficulty: null },
clock(2000),
);
release();
await assert.rejects(
pendingUse,
/table, owner, delegate or consent changed/i,
);
assert.equal(
controlled.players.find((player) => player.id === f.ownerId)
?.autopilot,
undefined,
);
} else {
const pendingControl = f.rooms.act(
f.code,
f.auths.owner,
granted.view.version,
{ type: 'setAutopilot', difficulty: null },
clock(2000),
);
await waiting;
const used = await f
.restart()
.useSeatAiDelegate(
f.code,
f.auths.delegate,
granted.view.version,
{ ownerId: f.ownerId, grantId: UUID.grant1 },
clock(2000),
);
assert.equal(used.replayed, false);
release();
await assert.rejects(pendingControl, /Another action arrived first/);
const current = await f.rooms.readSeatView(f.code, f.auths.owner);
const takenBack = await f.rooms.act(
f.code,
f.auths.owner,
current.version,
{ type: 'setAutopilot', difficulty: null },
clock(3000),
);
assert.equal(
takenBack.players.find((player) => player.id === f.ownerId)
?.autopilot,
undefined,
);
}
const after = await f.rooms.readRoom(f.code);
assert.ok(after.version >= granted.view.version + 1);
assert.ok(
after.log.filter((entry) => entry.text.includes('one-use delegation'))
.length <= 1,
);
} finally {
f.sqlite.close();
}
}
});
void test('recovery or handover of either bound seat invalidates delegation consent', async () => {
for (const mode of ['recovery', 'handover'] as const) {
for (const target of ['owner', 'delegate'] as const) {
const f = await fixture();
try {
let targetAuth = f.auths[target];
let version = (await f.rooms.readRoom(f.code)).version;
const recoverySecret = secret(target === 'owner' ? '44' : '55');
if (mode === 'recovery') {
const configured = await f.rooms.setRecoveryKey(
f.code,
targetAuth,
version,
recoverySecret,
);
version = configured.view.version;
}
const granted = await f.rooms.setSeatAiDelegate(
f.code,
f.auths.owner,
version,
delegation(f, UUID.grant4),
clock(1000),
);
let newToken: string;
if (mode === 'recovery') {
newToken = secret(target === 'owner' ? '66' : '77');
await f.rooms.recoverSeat(f.code, {
playerId: targetAuth.playerId,
recoverySecret,
operationId: UUID.recovery,
newSessionToken: newToken,
});
} else {
const offer = {
offerId: UUID.offer,
handoverSecret: secret(target === 'owner' ? '88' : '99'),
};
await f.rooms.createSeatHandover(
f.code,
targetAuth,
granted.view.version,
offer,
clock(1500),
);
newToken = secret(target === 'owner' ? 'aa' : 'bb');
await f.rooms.claimSeatHandover(
f.code,
{
playerId: targetAuth.playerId,
...offer,
operationId: UUID.claim,
newSessionToken: newToken,
},
clock(2000),
);
}
targetAuth = await f.rooms.authenticate(f.code, newToken);
const delegateAuth =
target === 'delegate' ? targetAuth : f.auths.delegate;
const current = await f.rooms.readRoom(f.code);
const before = storedState(f);
await assert.rejects(
f.rooms.useSeatAiDelegate(
f.code,
delegateAuth,
current.version,
{ ownerId: f.ownerId, grantId: UUID.grant4 },
clock(3000),
),
/credential changed|not available/,
`${mode} of ${target}`,
);
assert.equal(storedState(f), before);
assert.equal(
Object.hasOwn(
await f.rooms.readSeatView(f.code, targetAuth),
'seatAiDelegations',
),
false,
);
} finally {
f.sqlite.close();
}
}
}
});
+50 -20
View File
@@ -4,6 +4,7 @@ import { createHash } from 'node:crypto';
import { readFileSync } from 'node:fs';
import type { DatabaseSync } from 'node:sqlite';
import { baseDeck } from '../game/cards';
import { createGame, newPlayer } from '../game/engine';
import { unitStore } from './fixture-nexus-room-store';
const UUID = {
@@ -301,16 +302,43 @@ void test('claim invalidates the issuer entry receipt that still controlled the
});
void test('0005 backfills an active 0004 claim for exact replay after upgrade', async () => {
const f = await fixture(false, '0004_flippant_archangel.sql');
const f = unitStore(undefined, '0004_flippant_archangel.sql');
try {
const body = claim(f.created.view.me);
const offered = await f.rooms.createSeatHandover(
f.code,
f.auth,
f.view.version,
offer(),
clock(1000),
const code = 'LEGACY05';
const playerId = UUID.rival;
const oldSessionHash = digest(secret('10'));
const handover = offer();
const body = claim(playerId);
const game = createGame(
code,
newPlayer(playerId, 'Original owner', 'atreides'),
false,
[],
);
game.players[0].hand = [baseDeck()[0]];
game.players[0].traitors = ['emperor-0'];
f.sqlite
.prepare(
'INSERT INTO rooms(code,state,version,updated_at) VALUES(?,?,1,?)',
)
.run(code, JSON.stringify(game), 1000);
f.sqlite
.prepare(
'INSERT INTO seats(token_hash,room_code,player_id) VALUES(?,?,?)',
)
.run(oldSessionHash, code, playerId);
f.sqlite
.prepare(
'INSERT INTO seat_handover_offers(room_code,player_id,offer_hash,secret_hash,issuer_session_hash,expires_at,claim_operation_hash,session_hash,claimed_at) VALUES(?,?,?,?,?,?,NULL,NULL,NULL)',
)
.run(
code,
playerId,
digest(handover.offerId),
digest(handover.handoverSecret),
oldSessionHash,
301000,
);
const operationHash = digest(body.operationId);
const sessionHash = digest(body.newSessionToken);
f.sqlite.exec('BEGIN');
@@ -319,22 +347,22 @@ void test('0005 backfills an active 0004 claim for exact replay after upgrade',
.prepare(
'UPDATE rooms SET version = version + 1, updated_at = ? WHERE code = ? AND version = ?',
)
.run(2000, f.code, offered.view.version);
.run(2000, code, 1);
f.sqlite
.prepare(
'UPDATE seat_handover_offers SET claim_operation_hash = ?, session_hash = ?, claimed_at = ? WHERE room_code = ? AND player_id = ?',
)
.run(operationHash, sessionHash, 2000, f.code, f.created.view.me);
.run(operationHash, sessionHash, 2000, code, playerId);
f.sqlite
.prepare(
'UPDATE seats SET revoked = 1 WHERE room_code = ? AND player_id = ? AND revoked = 0',
)
.run(f.code, f.created.view.me);
.run(code, playerId);
f.sqlite
.prepare(
'INSERT INTO seats(token_hash,room_code,player_id) VALUES (?,?,?)',
)
.run(sessionHash, f.code, f.created.view.me);
.run(sessionHash, code, playerId);
f.sqlite.exec('COMMIT');
} catch (error) {
f.sqlite.exec('ROLLBACK');
@@ -342,7 +370,7 @@ void test('0005 backfills an active 0004 claim for exact replay after upgrade',
}
const stateBeforeUpgrade = f.sqlite
.prepare('SELECT state FROM rooms WHERE code = ?')
.get(f.code)!.state;
.get(code)!.state;
f.sqlite.exec(
readFileSync(
new URL('../drizzle/0005_salty_alice.sql', import.meta.url),
@@ -353,7 +381,7 @@ void test('0005 backfills an active 0004 claim for exact replay after upgrade',
.prepare(
'SELECT operation_hash,session_hash,claim_fence FROM seat_handover_claim_receipts WHERE room_code = ? AND player_id = ?',
)
.get(f.code, f.created.view.me)!;
.get(code, playerId)!;
assert.equal(receipt.operation_hash, operationHash);
assert.equal(receipt.session_hash, sessionHash);
assert.match(receipt.claim_fence as string, /^legacy:/);
@@ -361,17 +389,19 @@ void test('0005 backfills an active 0004 claim for exact replay after upgrade',
(receipt.claim_fence as string).includes(body.newSessionToken),
false,
);
const replay = await f.restart().claimSeatHandover(
f.code,
body,
clock(3000),
f.sqlite.exec(
readFileSync(
new URL('../drizzle/0006_thick_imperial_guard.sql', import.meta.url),
'utf8',
),
);
const replay = await f.restart().claimSeatHandover(code, body, clock(3000));
assert.equal(replay.replayed, true);
assert.equal(replay.token, body.newSessionToken);
assert.equal(replay.view.me, f.created.view.me);
assert.equal(replay.view.me, playerId);
assert.equal(replay.view.players[0].hand![0].id, baseDeck()[0].id);
assert.equal(
f.sqlite.prepare('SELECT state FROM rooms WHERE code = ?').get(f.code)!
f.sqlite.prepare('SELECT state FROM rooms WHERE code = ?').get(code)!
.state,
stateBeforeUpgrade,
);
+2
View File
@@ -8,6 +8,7 @@ import { DatabaseSync } from 'node:sqlite';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
const base = process.env.DUNE_TEST_URL ?? 'http://localhost:3000';
@@ -350,6 +351,7 @@ function unitStore() {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return bots;
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
});
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import type * as Rooms from '../db/rooms';
@@ -80,6 +81,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import { richeseCards } from '../game/richese-cards';
import type * as Rooms from '../db/rooms';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import {
createStrongholdCards,
@@ -85,6 +86,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import type * as Rooms from '../db/rooms';
import { createRequire } from 'node:module';
@@ -82,6 +83,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import type { TruthQuestion } from '../game/truthtrance';
import { createRequire } from 'node:module';
@@ -82,6 +83,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
+2
View File
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import { baseDeck } from '../game/cards';
import type { TruthFact } from '../game/truthtrance';
import type * as Rooms from '../db/rooms';
@@ -81,6 +82,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},
@@ -7,6 +7,7 @@ import { runInNewContext } from 'node:vm';
import ts from 'typescript';
import * as engine from '../game/engine';
import * as bots from '../game/bots';
import * as seatAiDelegation from '../lib/seat-ai-delegation';
import type * as Rooms from '../db/rooms';
import { homeworldGameIntegrity } from '../game/homeworld-game';
import { homeworldContext } from '../game/homeworld-game';
@@ -89,6 +90,7 @@ function unitStore(runBots = bots.runBots) {
if (name === 'cloudflare:workers') return { env: { DB: database } };
if (name === '@/game/engine') return engine;
if (name === '@/game/bots') return { ...bots, runBots };
if (name === '@/lib/seat-ai-delegation') return seatAiDelegation;
throw new Error('Unexpected module ' + name);
},
},