// Loads the game page in jsdom with the animation loop disabled, so tests can drive the simulation // directly through the game's globals (ACT, S, R, dayTick…). The page is assembled from src/ once per // test process (scripts/lib/page.js), so tests always run what is in src/, never a stale build. // It is the page players get; {agent: true} loads the development page instead, with the agent facade // (src/agent/) the MCP server drives. Only the tests of that facade ask for it, so core code that leans on // it fails here rather than in production. const fs = require('node:fs'); const path = require('node:path'); const vm = require('node:vm'); const { JSDOM, VirtualConsole } = require('jsdom'); const { assemble, simId } = require('../scripts/lib/page'); const PAGE = {}; const page = (dev, mp) => PAGE[dev + '|' + mp] || (PAGE[dev + '|' + mp] = assemble({ dev, mp }).html); // The build id an MP page carries (scripts/lib/page.js simId()), worked out once per test process. let SIM; const simOf = () => SIM || (SIM = simId(assemble({ mp: true }).html)); // The page's inline scripts, taken out of the HTML once per process and compiled once. jsdom's HTML parser is slow // on 2 MB of script text (it was more than half of every load()), so the DOM is built from the rest of the page and // the scripts then run in its window, in order, the same way jsdom runs them (vm.Script.runInContext). Only plain // '; }); // With scripting on, the parser keeps a