@wildshard/engine 0.1.20 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/lint/engine-sides.json +4 -0
- package/lint/shardfile-boundaries.mjs +4 -2
- package/lint/wildshard-plugin.js +1 -1
- package/package.json +3 -1
- package/scripts/audio-download-proof.mjs +1 -1
- package/scripts/chaos-proxy-core.mjs +14 -1
- package/scripts/chaos-proxy-proof.mjs +22 -0
- package/scripts/check-spelled-paths.mjs +6 -3
- package/scripts/committed-fast-checks.mjs +2 -2
- package/scripts/failmode-cases.d.mts +8 -0
- package/scripts/failmode-cases.mjs +97 -0
- package/scripts/failmode-proof.mjs +556 -0
- package/scripts/grid-crossing-nightly.mjs +5 -4
- package/scripts/grid-crossing-report.mjs +5 -2
- package/scripts/grid-crossing-tour.mjs +25 -8
- package/scripts/grid-crossing-walk-proof.mjs +3 -3
- package/scripts/hover-speed-probe.mjs +136 -0
- package/scripts/mmo-bots.mjs +7 -3
- package/scripts/net-lag-proof.mjs +4 -3
- package/scripts/online-rig.mjs +11 -9
- package/scripts/parity/boot-smoke.mjs +1 -1
- package/scripts/release-cook.mjs +113 -0
- package/scripts/test-products.json +0 -21
- package/scripts/vps/cook-follow.d.mts +6 -0
- package/scripts/vps/cook-follow.mjs +45 -0
- package/scripts/vps/harden-apply.sh +10 -1
- package/scripts/vps/rebuild.sh +120 -26
- package/scripts/vps/wildshard-apply.mjs +5 -1
- package/scripts/vps/wildshard-config +117 -3
- package/src/client/app/entry.ts +2 -3
- package/src/client/engine/boot/contentRead.ts +78 -9
- package/src/client/engine/boot/downloadGiveUp.ts +34 -0
- package/src/client/engine/boot/gpuFiles.ts +3 -3
- package/src/client/engine/boot/leaveAfterPaint.ts +4 -1
- package/src/client/engine/combat/EquipmentService.ts +2 -0
- package/src/client/engine/core/Game.ts +6 -2
- package/src/client/engine/core/shadowLayer.ts +18 -0
- package/src/client/engine/explore/pick.ts +13 -1
- package/src/client/engine/net/predictor.ts +12 -4
- package/src/client/engine/player/TouchControls.ts +3 -2
- package/src/client/engine/render/families/sceneSurface.ts +3 -1
- package/src/client/engine/telemetry/browserErrors.ts +3 -1
- package/src/client/engine/ui/ErrorModal.ts +1 -1
- package/src/client/engine/ui/Loading.ts +14 -2
- package/src/client/engine/ui/downloadFailed.ts +54 -0
- package/src/client/engine/ui/errorScreen.ts +51 -9
- package/src/client/engine/ui/hoverBoost.ts +31 -4
- package/src/client/engine/ui/styles/touch.css +6 -0
- package/src/client/game/boot/spawnDownload.ts +56 -7
- package/src/client/game/grid/copyPrompts.ts +3 -4
- package/src/client/game/grid/dataCellKit.ts +91 -0
- package/src/client/game/grid/enteredEquipment.ts +11 -2
- package/src/client/game/grid/live.ts +11 -301
- package/src/client/game/grid/liveSession.ts +33 -10
- package/src/client/game/grid/neighbourLife.ts +50 -32
- package/src/client/game/grid/reveal.ts +7 -2
- package/src/client/game/grid/session.ts +6 -70
- package/src/client/game/grid/shardfileFar.ts +13 -2
- package/src/client/game/plugin/weaponFamily.ts +6 -0
- package/src/client/game/shardfile/clientSource.ts +7 -3
- package/src/client/game/shardfile/clientWorker.ts +17 -7
- package/src/client/game/shardfile/groundMerge.ts +5 -3
- package/src/client/host/online/linkScreens.ts +12 -6
- package/src/client/host/online/reconnectStrip.ts +3 -2
- package/src/client/host/online/release.ts +87 -16
- package/src/client/host/online/releaseScreens.ts +108 -0
- package/src/client/host/online/shell.ts +46 -12
- package/src/client/host/online/voice.ts +45 -1
- package/src/client/host/online/voiceUi.ts +24 -6
- package/src/server/engine/sim/playerSim.ts +1 -1
- package/src/server/game/grid/room.ts +2 -38
- package/src/server/game/grid/simulation.ts +12 -6
- package/src/server/game/shardfile/declaredKitItems.ts +8 -2
- package/src/server/host/dedicated/cellHost.ts +9 -2
- package/src/server/host/dedicated/cellProtocol.ts +1 -1
- package/src/server/host/dedicated/cellWorker.ts +2 -2
- package/src/server/host/dedicated/dedicatedRoom.ts +22 -4
- package/src/server/host/dedicated/gridCells.ts +5 -3
- package/src/server/host/dedicated/main.ts +6 -4
- package/src/server/host/dedicated/roadRoom.ts +3 -0
- package/src/server/host/dedicated/workerTable.ts +0 -10
- package/src/server/host/dedicated/world.ts +39 -5
- package/src/server/host/standalone/cellWorld.ts +1 -1
- package/src/server/host/standalone/gridServer.ts +1 -1
- package/src/shared/engine/boot/loadingWaits.ts +10 -2
- package/src/shared/engine/core/config.ts +3 -0
- package/src/shared/engine/player/hoverSpeed.ts +3 -3
- package/src/shared/engine/saves/shape.ts +17 -2
- package/src/shared/engine/strings.ts +22 -1
- package/src/shared/game/grid/placementRows.ts +4 -3
- package/src/shared/game/grid/rules.ts +12 -0
- package/src/client/game/grid/cellLoading.ts +0 -110
- package/src/client/game/grid/cellScreens.ts +0 -48
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
// on preview or a loopback page) and the online walks (`grid-crossing-qa.mjs`'s `rows.json` on staging: the pairs a walker can reach by
|
|
4
4
|
// input), writes report.html (pairs × the goal's measures, worst first, and thumbnails of the failed or walled crossings in shots/) and checks every
|
|
5
5
|
// crossing against the ratchet `test/grid-crossing-ratchet.json`: a pair worse than its ratchet makes the run exit 1.
|
|
6
|
-
// node scripts/grid-crossing-report.mjs <out dir> --runs=<tour dir or rows.json>,… [--tighten]
|
|
6
|
+
// node scripts/grid-crossing-report.mjs <out dir> --runs=<tour dir or rows.json>,… [--tighten] [--ratchet=<file>]
|
|
7
|
+
// --ratchet reads another ratchet file (GC17's seeded break proves a worse pair turns the run red)
|
|
7
8
|
// --tighten writes the ratchet after the run (new pairs join, numbers only go down); without it the ratchet is read only.
|
|
8
9
|
import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
9
10
|
import { basename, dirname, join, resolve as absolute } from 'node:path';
|
|
@@ -15,7 +16,7 @@ const flag = (name, fallback) => process.argv.find(arg => arg.startsWith(`--${na
|
|
|
15
16
|
const out = absolute(process.argv.slice(2).find(arg => !arg.startsWith('--')) ?? '');
|
|
16
17
|
const sources = flag('runs', '').split(',').filter(Boolean).map(path => absolute(path));
|
|
17
18
|
if (out === absolute('') || sources.length === 0) throw new Error('usage: grid-crossing-report.mjs <out dir> --runs=<tour dir or rows.json>,… [--tighten]');
|
|
18
|
-
const RATCHET = join(import.meta.dirname, '../test/grid-crossing-ratchet.json');
|
|
19
|
+
const RATCHET = absolute(flag('ratchet', join(import.meta.dirname, '../test/grid-crossing-ratchet.json')));
|
|
19
20
|
|
|
20
21
|
/** @typedef {{ site: string, run: string, from: string, to: string, boost: boolean, repeat: boolean, ok: boolean, why: string, borderToControlMs: number | null, freezeMs: number | null, wallMs: number | null, over50: number | null, over33: number | null, build: string, shot: string | null }} Row */
|
|
21
22
|
/** @type {Row[]} */
|
|
@@ -47,6 +48,8 @@ for (const source of sources) {
|
|
|
47
48
|
const scored = new Map();
|
|
48
49
|
for (const row of rows) { const key = pairKey(row.site, row.run, row.from, row.to), had = scored.get(key); if (had === undefined || (had.repeat && !row.repeat)) scored.set(key, row); }
|
|
49
50
|
const now = Object.fromEntries([...scored].map(([key, row]) => [key, { ok: row.ok, borderToControlMs: row.borderToControlMs, freezeMs: row.freezeMs, wallMs: row.wallMs, over50: row.over50 }]));
|
|
51
|
+
// a named --ratchet that is missing would read as {} and pass everything (GC17's seeded break must not go green by a typo)
|
|
52
|
+
if (!existsSync(RATCHET) && process.argv.some(arg => arg.startsWith('--ratchet='))) throw new Error(`No ratchet file at ${RATCHET}`);
|
|
50
53
|
const ratchet = existsSync(RATCHET) ? JSON.parse(readFileSync(RATCHET, 'utf8')) : {};
|
|
51
54
|
const worsened = worse(ratchet, now);
|
|
52
55
|
if (process.argv.includes('--tighten')) writeFileSync(RATCHET, `${JSON.stringify(tighten(ratchet, now), null, 2)}\n`);
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
// picks another; when a cell has no arc left it goes back over crossings that worked (scored too, marked `repeat`), and when none
|
|
8
8
|
// leads anywhere (a cell it can't leave) it enters again by the title.
|
|
9
9
|
// Per crossing, from the in-page samples (every 100 ms) and every frame: border to control, the longest run under 90 % of the
|
|
10
|
-
// approach speed (slow) and under 0.1 m per 100 ms with the key held (freeze), the time held at an unready neighbour (wall: phase
|
|
11
|
-
//
|
|
10
|
+
// approach speed (slow) and under 0.1 m per 100 ms with the key held (freeze), the time held at an unready neighbour (wall: phase preparing, blocked or ready, the last a world built whose entry still prepares, GC6;
|
|
11
|
+
// while frozen), the time the cell step screen shows, and frames over 33 and 50 ms within 3 s of the border.
|
|
12
12
|
// Not measured: grey stand-ins within 60 m (no reader yet).
|
|
13
13
|
// scripts/browser-lane.sh node scripts/grid-crossing-tour.mjs --base=https://preview.wildshard.io --out=<dir> [--engine=chromium|webkit]
|
|
14
14
|
// [--layout=phone] [--arcs=<from>:<to>,…] [--limit=<n crossings>] [--cold] [--lane=<name>] [--hold=<ms>] [--laps=<n>]
|
|
@@ -34,6 +34,7 @@ const limit = Number(flag('limit', '400')), only = flag('arcs', '').split(',').f
|
|
|
34
34
|
// --viewport=<w>x<h>@<dpr> (desktop): Jake's window is 2992x1434@2 (QA 11-14 row 6)
|
|
35
35
|
const desk = (/^(\d+)x(\d+)@([\d.]+)$/u.exec(flag('viewport', '1440x900@1')) ?? [0, '1440', '900', '1']).slice(1).map(Number);
|
|
36
36
|
let currentLap = 1;
|
|
37
|
+
const profileFirst = process.argv.includes('--profile'), latency = Number(flag('latency', '0'));
|
|
37
38
|
mkdirSync(out, { recursive: true });
|
|
38
39
|
const sleep = (/** @type {number} */ ms) => new Promise(resolve => { setTimeout(resolve, ms); });
|
|
39
40
|
|
|
@@ -79,6 +80,8 @@ try {
|
|
|
79
80
|
await saveFixture(context, { scope: 'global', key: 'settings', merge: true, data: phone ? { tier: 'phone', volume: 0 } : { volume: 0 } });
|
|
80
81
|
page = await context.newPage();
|
|
81
82
|
if (cold && engineName === 'chromium') await (await context.newCDPSession(page)).send('Network.setCacheDisabled', { cacheDisabled: true });
|
|
83
|
+
// --latency=<ms> (GC6): a CDN's round trip on every request of a loopback page (Chromium), so a local build's fetches cost what a site's do
|
|
84
|
+
if (latency > 0 && engineName === 'chromium') { const cdp = await context.newCDPSession(page); await cdp.send('Network.enable'); await cdp.send('Network.emulateNetworkConditions', { offline: false, latency, downloadThroughput: 25e6, uploadThroughput: 5e6 }); }
|
|
82
85
|
const opened = page;
|
|
83
86
|
page.on('pageerror', error => { if (result.errors.length < 20) result.errors.push(error.message.slice(0, 240)); });
|
|
84
87
|
// GC6: the page's own warnings name a stuck entry preparation (`[grid] <cell>: entry preparation on the road`)
|
|
@@ -147,6 +150,9 @@ try {
|
|
|
147
150
|
const { at_: placed, ok: placedOk } = await place(EDGE_IN);
|
|
148
151
|
row.placed = { x: placed.x, y: placed.y, z: placed.z, inside: placed.inside };
|
|
149
152
|
if (!placedOk) { row.why = `not placed on ${arc.from}'s entryway (inside ${String(placed.inside)})`; return row; }
|
|
153
|
+
// --profile (GC6): a CPU profile of the first crossing (Chromium), for what its preparation spends
|
|
154
|
+
const profiler = profileFirst && crossings.length === 1 && engineName === 'chromium' ? await page.context().newCDPSession(page) : null;
|
|
155
|
+
if (profiler !== null) { await profiler.send('Profiler.enable'); await profiler.send('Profiler.setSamplingInterval', { interval: 500 }); await profiler.send('Profiler.start'); row.profileStartPageMs = await page.evaluate(() => performance.now()); }
|
|
150
156
|
await face(yaw);
|
|
151
157
|
const t1 = Date.now(), tFrom = (await sample()).t;
|
|
152
158
|
await page.keyboard.down('KeyW'); if (arc.boost) await page.keyboard.down('ShiftLeft');
|
|
@@ -164,13 +170,18 @@ try {
|
|
|
164
170
|
controlAt = now; controlT = s.t;
|
|
165
171
|
// GC14: the page's memory at each control, so the tour doubles as the long-walk soak
|
|
166
172
|
row.memory = await page.evaluate(() => { const W = /** @type {any} */ (window); let st = null; try { st = W.__wildshard.shard.grid.state(); } catch { /* no grid yet */ }
|
|
167
|
-
|
|
173
|
+
// GC13: what the playing cost is made of (the allocator's input per category, MB) and the biggest owners' claims
|
|
174
|
+
let parts = null, owners = null; try { const r = W.__wildshard.shard.grid.residency(); parts = Object.fromEntries(Object.entries(r.cost.input).map(([k, v]) => [k, typeof v === 'number' ? Math.round(v / 1e5) / 10 : v]));
|
|
175
|
+
/** @type {Record<string, number>} */ const by = {}; for (const c of r.claims) { const key = `${String(c.owner)}:${String(c.category)}`; by[key] = (by[key] ?? 0) + (c.accountedBytes ?? c.bytes) / 1e6; }
|
|
176
|
+
owners = Object.fromEntries(Object.entries(by).sort((a, b) => b[1] - a[1]).slice(0, 16).map(([k, v]) => [k, Math.round(v * 10) / 10])); } catch { /* no residency probe */ }
|
|
177
|
+
const perf = /** @type {any} */ (performance); return { playingMB: st?.playingMB ?? null, residentMB: st?.residentMB ?? null, heapMB: perf.memory ? Math.round(perf.memory.usedJSHeapSize / 1048576) : null, parts, owners }; }).catch(() => null);
|
|
168
178
|
}
|
|
169
179
|
} else if (now - controlAt > 2500) break;
|
|
170
180
|
last = s;
|
|
171
181
|
if (jumps >= 4 && stuckSince !== 0 && now - stuckSince > 10_000) break;
|
|
172
182
|
}
|
|
173
183
|
await page.keyboard.up('KeyW'); if (arc.boost) await page.keyboard.up('ShiftLeft');
|
|
184
|
+
if (profiler !== null) { const stopped = await profiler.send('Profiler.stop'); writeFileSync(join(out, `${engineName}-${arc.from}-${arc.to}.cpuprofile`), JSON.stringify(stopped.profile)); await profiler.detach(); }
|
|
174
185
|
// GC13 `--hold`: stand in the cell reached, so the page can let the cell behind go
|
|
175
186
|
await sleep(controlAt === 0 ? 400 : Math.max(400, hold));
|
|
176
187
|
const rows =/** @type {any[]} */ (await page.evaluate(t => /** @type {any} */ (window).__gc3.samples.filter((/** @type {any} */ r) => r.err === undefined && r.t >= t), tFrom));
|
|
@@ -196,7 +207,7 @@ try {
|
|
|
196
207
|
const border = entered?.t ?? Infinity, near = frames.filter(f => Math.abs((f[0] ?? 0) - border) <= 3000).map(f => f[1] ?? 0);
|
|
197
208
|
Object.assign(row, { ok: controlAt !== 0, why: controlAt !== 0 ? '' : fell ? `fell off ${arc.from}'s entryway (no ground there)` : entered === undefined ? (roadAt === undefined ? `never left ${arc.from}` : `held on the road (${String(last.phase)})`) : 'in the cell, no control',
|
|
198
209
|
borderToControlMs: entered === undefined || controlAt === 0 ? null : controlT - entered.t, controlMs: controlAt === 0 ? null : controlAt, approachMps: Number(approach.toFixed(2)),
|
|
199
|
-
slowMs: approach > 0 ? longest(s => s.v < approach * 0.9) : null, freezeMs: longest(s => s.v * 0.1 < 0.1), wallMs: sum(s => (s.r.phase === 'preparing' || s.r.phase === 'blocked') && s.v * 0.1 < 0.1),
|
|
210
|
+
slowMs: approach > 0 ? longest(s => s.v < approach * 0.9) : null, freezeMs: longest(s => s.v * 0.1 < 0.1), wallMs: sum(s => (s.r.phase === 'preparing' || s.r.phase === 'blocked' || s.r.phase === 'ready') && s.v * 0.1 < 0.1),
|
|
200
211
|
stepScreenMs: sum(s => s.r.loading !== null && s.r.loading !== undefined && s.r.loading !== false), over33: near.filter(ms => ms > 33).length, over50: near.filter(ms => ms > 50).length,
|
|
201
212
|
// GC8: how long each `cell` step stood on the loading screen in this crossing (samples every 100 ms; a build before GC8 reads none)
|
|
202
213
|
steps: speeds.reduce((/** @type {Record<string, number>} */ onScreen, x) => { if (x.t <= untilT && typeof x.r.step === 'string' && x.r.step !== '') onScreen[x.r.step] = (onScreen[x.r.step] ?? 0) + 100; return onScreen; }, {}),
|
|
@@ -213,15 +224,21 @@ try {
|
|
|
213
224
|
// GC8: what preparing the target cost in this window: its `wildshard.prepare:<slug>:<step>` spans (wall ms, developer pages
|
|
214
225
|
// only), the main thread's long tasks, and the bytes fetched under its shardfile folder (resource timing transfer sizes)
|
|
215
226
|
const slug = cells.find(cell => cell.instance === arc.to)?.slug ?? arc.to;
|
|
216
|
-
Object.assign(row, await page.evaluate(([from, name]) => {
|
|
227
|
+
Object.assign(row, await page.evaluate(([from, name, target]) => {
|
|
217
228
|
const W = /** @type {any} */ (window), end = performance.now();
|
|
218
229
|
const spans = performance.getEntriesByType('measure').filter(entry => entry.name.startsWith(`wildshard.prepare:${name}:`) && entry.startTime >= from)
|
|
219
230
|
.map(entry => [entry.name.slice(`wildshard.prepare:${name}:`.length), Math.round(entry.startTime - from), Math.round(entry.duration)]);
|
|
220
231
|
const tasks = /** @type {number[][]} */ (W.__gc3.longTasks ?? []).filter(task => (task[0] ?? 0) >= from && (task[0] ?? 0) <= end);
|
|
221
232
|
const files = /** @type {PerformanceResourceTiming[]} */ (performance.getEntriesByType('resource')).filter(entry => entry.startTime >= from && entry.name.includes(`/${name}/`));
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
233
|
+
// GC6: the hybrid hooks run for this cell in the window ([hook, start, ms, outcome]; the grid probe's `hookTimings`, the last 32)
|
|
234
|
+
let hooks = /** @type {unknown[]} */ ([]);
|
|
235
|
+
try { hooks = (W.__wildshard.shard.grid.hookTimings?.()?.completed ?? []).filter((/** @type {any} */ h) => h.start >= from && h.instance === target).map((/** @type {any} */ h) => [h.hook, Math.round(h.start - from), Math.round(h.end - h.start), h.outcome]); } catch { /* no live session */ }
|
|
236
|
+
return { prepare: { windowMs: Math.round(end - from), hooks, spans: spans.slice(0, 200), longTasks: tasks.length, longTaskMs: tasks.reduce((total, task) => total + (task[1] ?? 0), 0),
|
|
237
|
+
files: files.length, bytes: files.reduce((total, entry) => total + (entry.transferSize || 0), 0), decodedBytes: files.reduce((total, entry) => total + (entry.decodedBodySize || 0), 0),
|
|
238
|
+
// GC6: every fetch in the window (at most 3000), as [the path's last folders and its name's first 8, start, ms, transfer bytes, initiator], to see what a preparation waits on
|
|
239
|
+
fetches: (/** @type {PerformanceResourceTiming[]} */ (performance.getEntriesByType('resource'))).filter(entry => entry.startTime >= from)
|
|
240
|
+
.slice(-3000).map(entry => { const parts = new URL(entry.name).pathname.split('/'); return [`${parts.slice(-4, -1).join('/')}/${(parts.at(-1) ?? '').slice(0, 8)}`, Math.round(entry.startTime - from), Math.round(entry.duration), entry.transferSize || 0, entry.initiatorType]; }) }, windowEnd: end };
|
|
241
|
+
}, /** @type {[number, string, string]} */ ([windowStart, slug, arc.to])).then(({ prepare, windowEnd }) => { lastWindowEnd = windowEnd; return { prepare }; }).catch(() => ({})));
|
|
225
242
|
if (!row.ok || row.wallMs > 0) await page.screenshot({ path: join(out, `${engineName}-${arc.from}-${arc.to}.png`) }).catch(() => undefined);
|
|
226
243
|
console.log(`${row.ok ? 'ok ' : 'FAIL'} ${arc.from} -> ${arc.to}${arc.boost ? ' boost' : ''}${repeat ? ' (repeat)' : ''} ${JSON.stringify({ why: row.why, b2c: row.borderToControlMs, wall: row.wallMs, freeze: row.freezeMs, over50: row.over50 })}`);
|
|
227
244
|
return row;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// GC15 (GRID-CROSSING): the first page walk across a cell border online, on this Mac. The rig's server runs WORLD_CELLS=grid with
|
|
3
|
-
//
|
|
3
|
+
// the always-on road on staging's two workers (Nalati alone; Driftwood, Pine Hollow, Sunscar and Far Reach and their road on the other), its origin carries the grid pack, and a real browser enters Driftwood
|
|
4
4
|
// from the deck's card, then walks into a same-worker neighbour (Sunscar, or Pine Hollow), boosts back into Driftwood and boosts out again, by
|
|
5
5
|
// real input. Each leg passes with no stop (no 1.5 s under 0.15 m a sample while the key is held), no page reload, and control in the
|
|
6
6
|
// target cell (the page inside it, gameplay ready, the player moving). It writes time-to-control per leg beside GC1's baseline.
|
|
@@ -69,10 +69,10 @@ if (served !== '' && !/^https:\/\/(staging|preview)\.wildshard\.io\/?$|^http:\/\
|
|
|
69
69
|
const workers = Number(process.argv.find(arg => arg.startsWith('--workers='))?.slice(10) ?? 2);
|
|
70
70
|
if (!Number.isInteger(workers) || workers < 1) throw new Error('--workers takes a whole number from 1');
|
|
71
71
|
const rig = served !== '' ? { base: served.replace(/\/$/, ''), close: () => Promise.resolve() }
|
|
72
|
-
: await openRig({ dist, work, keyFile, pgBin: 'memory:', pgData: '', shard: HOME, more: ['pine-hollow', 'far-reach', 'sunscar-dunes', 'nalati-grasslands'], cells: 'grid',
|
|
72
|
+
: await openRig({ dist, work, keyFile, pgBin: 'memory:', pgData: '', shard: HOME, more: ['pine-hollow', 'far-reach', 'sunscar-dunes', 'nalati-grasslands'], cells: 'grid', workers });
|
|
73
73
|
let code = 1, browser = /** @type {import('playwright').Browser | null} */ (null);
|
|
74
74
|
/** @type {Record<string, unknown>} */
|
|
75
|
-
const result = { lane: 'opus-gc15c', engine: engineName, layout: phone ? 'phone 402x874 touch' : `desktop ${String(desk[0])}x${String(desk[1])}@${String(desk[2])}`, site: served !== '' ? served : 'local rig, WORLD_CELLS=grid,
|
|
75
|
+
const result = { lane: 'opus-gc15c', engine: engineName, layout: phone ? 'phone 402x874 touch' : `desktop ${String(desk[0])}x${String(desk[1])}@${String(desk[2])}`, site: served !== '' ? served : 'local rig, WORLD_CELLS=grid, WORLD_WORKERS=2 (staging: Nalati alone, Driftwood with Pine Hollow, Sunscar and Far Reach)' };
|
|
76
76
|
try {
|
|
77
77
|
let open = served !== '' ? { cells: 25 } : null;
|
|
78
78
|
for (let tries = 0; tries < 300 && open === null; tries++) { open = await fetch(`http://127.0.0.1:${String(WORLD_PORT)}/health`).then(found => found.ok ? found.json() : null).catch(() => null); if (open === null) await sleep(200); }
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// QA 11-15 row 8 (Jake: "what speed is the hoverboard inside the [zone], what speed is it on the road, what speed is it with boost,
|
|
3
|
+
// what speed is it with boost off … We had agreed upon speeds"): a headless page enters Driftwood, steps on the board (H), and
|
|
4
|
+
// drives straight by real input in the four cases, boost off and on (a double tap of H), inside the shard (its west water, x -235)
|
|
5
|
+
// and on the road's deck west of it (x -281.25). Each case prints the page's measured ground speed (median over its last 1.5 s,
|
|
6
|
+
// from the world feet every 50 ms), the page's own board cap (`hoverCap`), and the corrections the server sent meanwhile (a
|
|
7
|
+
// server that caps lower than the page predicts pulls it back: corrections, and a measured speed under the cap).
|
|
8
|
+
// QA 11-15 row 9: `--shots` also shoots the left edge riding with boost off and on (the HOVER tab on a phone, the tag on desktop).
|
|
9
|
+
// scripts/browser-lane.sh node scripts/hover-speed-probe.mjs --base=<staging, preview or loopback url> --out=<dir> [--layout=phone] [--shots]
|
|
10
|
+
// scripts/browser-lane.sh node scripts/hover-speed-probe.mjs --rig=<app dist>,<work dir>,<key.json> --out=<dir> (engine's loopback
|
|
11
|
+
// world, online-rig.mjs: the built dedicated server and 2 workers; the dist stamped for its release file)
|
|
12
|
+
// J205: staging, preview or a loopback page only, never production. Chromium runs headless and muted; the page is closed at the end.
|
|
13
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
14
|
+
import { join, resolve as absolute } from 'node:path';
|
|
15
|
+
import { chromium } from 'playwright';
|
|
16
|
+
import { KEYCHAIN_ARGS } from './chromium-keychain.mjs';
|
|
17
|
+
import { saveFixture } from './debug-settings.mjs';
|
|
18
|
+
|
|
19
|
+
/** @param {string} name @param {string} fallback */
|
|
20
|
+
const flag = (name, fallback) => process.argv.find(arg => arg.startsWith(`--${name}=`))?.slice(name.length + 3) ?? fallback;
|
|
21
|
+
const rigArg = flag('rig', ''), out = absolute(flag('out', 'tmp/hover-speed-probe')), phone = flag('layout', 'desktop') === 'phone', shots = process.argv.includes('--shots');
|
|
22
|
+
let base = flag('base', '').replace(/\/$/u, '');
|
|
23
|
+
if (rigArg === '' && !/^https:\/\/(staging|preview)\.wildshard\.io$|^http:\/\/127\.0\.0\.1:\d+$/u.test(base)) throw new Error('--base takes staging, preview or a loopback page only: never production (J205)');
|
|
24
|
+
const sleep = (/** @type {number} */ ms) => new Promise(resolve => { setTimeout(resolve, ms); });
|
|
25
|
+
mkdirSync(out, { recursive: true });
|
|
26
|
+
|
|
27
|
+
/** Driftwood is cell [0, 0], so its own metres are the world's. The road's deck is the middle 15 m of the 62.5 m between cells. */
|
|
28
|
+
const ZONE_X = -235, DECK_X = -281.25;
|
|
29
|
+
|
|
30
|
+
let rig = /** @type {{ base: string, close: () => Promise<unknown> } | null} */ (null);
|
|
31
|
+
if (rigArg !== '') {
|
|
32
|
+
const [dist = '', work = '', keyFile = ''] = rigArg.split(',');
|
|
33
|
+
const { openRig, WORLD_PORT } = await import('./online-rig.mjs');
|
|
34
|
+
rig = await openRig({ dist, work: absolute(work), keyFile, pgBin: 'memory:', pgData: '', shard: 'driftwood-isle', more: ['pine-hollow', 'far-reach', 'sunscar-dunes', 'nalati-grasslands'], cells: 'grid', workers: 2 });
|
|
35
|
+
for (let tries = 0; tries < 300 && !(await fetch(`http://127.0.0.1:${String(WORLD_PORT)}/health`).then(found => found.ok).catch(() => false)); tries++) await sleep(200);
|
|
36
|
+
base = rig.base;
|
|
37
|
+
}
|
|
38
|
+
const result = { base, rig: rigArg !== '', layout: phone ? 'phone 402x874@3 touch' : 'desktop 1440x900@1', at: new Date().toISOString(), build: '', cases: /** @type {Record<string, unknown>[]} */ ([]), shots: /** @type {string[]} */ ([]), errors: /** @type {string[]} */ ([]), notes: /** @type {string[]} */ ([]) };
|
|
39
|
+
const browser = await chromium.launch({ headless: true, args: [...KEYCHAIN_ARGS, '--mute-audio', '--use-angle=metal', '--ignore-gpu-blocklist'] });
|
|
40
|
+
let code = 1, shown = /** @type {import('playwright').Page | null} */ (null);
|
|
41
|
+
try {
|
|
42
|
+
result.build = await fetch(`${base}/version.json`).then(async found => String((await found.json()).build)).catch(() => '');
|
|
43
|
+
const context = await browser.newContext(phone ? { viewport: { width: 402, height: 874 }, deviceScaleFactor: 3, isMobile: true, hasTouch: true } : { viewport: { width: 1440, height: 900 }, deviceScaleFactor: 1 });
|
|
44
|
+
const page = await context.newPage(); shown = page;
|
|
45
|
+
page.on('pageerror', error => { result.errors.push(error.message.slice(0, 240)); });
|
|
46
|
+
await saveFixture(context, { scope: 'device', key: 'firstPlayDone', data: true });
|
|
47
|
+
await saveFixture(context, { scope: 'device', key: 'devMode', data: true });
|
|
48
|
+
await saveFixture(context, { scope: 'global', key: 'settings', merge: true, data: phone ? { tier: 'phone', volume: 0 } : { volume: 0 } });
|
|
49
|
+
await page.goto(`${base}/?mute=1&nolock=1`, { waitUntil: 'load' });
|
|
50
|
+
await page.locator('.ws-main-select').click({ timeout: 120_000 });
|
|
51
|
+
if (await page.locator('#ws-name-box input').waitFor({ timeout: 30_000 }).then(() => true).catch(() => false)) { await page.locator('#ws-name-box input').fill('hoverspeed'); await page.locator('#ws-name-box button[type=submit]').click(); }
|
|
52
|
+
await page.locator('.ws-menu-card').first().waitFor({ state: 'visible', timeout: 30_000 });
|
|
53
|
+
const index = await page.evaluate(() => [...document.querySelectorAll('.ws-menu-card')].findIndex(row => (row.textContent ?? '').includes('Driftwood Isle')));
|
|
54
|
+
if (index < 0) throw new Error('No Driftwood Isle card');
|
|
55
|
+
await page.locator('.ws-menu-dots i').nth(index).click();
|
|
56
|
+
await page.locator('.ws-menu-play').click();
|
|
57
|
+
await page.waitForFunction(() => /** @type {any} */ (window).__wildshard?.shard?.grid?.state?.().live?.live?.gameplayReady === true, undefined, { timeout: 180_000, polling: 100 });
|
|
58
|
+
await sleep(2000);
|
|
59
|
+
await page.getByText('DONE', { exact: true }).click({ timeout: 2000 }).catch(() => undefined);
|
|
60
|
+
await page.evaluate(() => {
|
|
61
|
+
const W = /** @type {any} */ (window), q = W.__hoverSpeed = { samples: /** @type {any[]} */ ([]) };
|
|
62
|
+
setInterval(() => { try {
|
|
63
|
+
const st = W.__wildshard.shard.grid.state(), p = W.__wildshard.world.player, wf = st.live?.live?.worldFeet ?? p.position, wire = W.__workerClient?.();
|
|
64
|
+
q.samples.push({ t: Math.round(performance.now()), x: wf.x, y: wf.y, z: wf.z, inside: st.inside ?? null, cap: typeof p.hoverSpeedLimit === 'function' ? Number(p.hoverSpeedLimit().toFixed(2)) : null, hover: p.hover, boost: p.hoverBoost, corrections: wire?.corrections ?? null });
|
|
65
|
+
} catch (error) { q.samples.push({ err: String(error).slice(0, 160) }); } }, 50);
|
|
66
|
+
});
|
|
67
|
+
const sample = () => page.evaluate(() => { const rows = /** @type {any[]} */ (/** @type {any} */ (window).__hoverSpeed.samples); for (let at = rows.length - 1; at >= 0; at--) if (rows[at].err === undefined) return rows[at]; return undefined; });
|
|
68
|
+
const now = () => page.evaluate(() => Math.round(performance.now()));
|
|
69
|
+
const face = (/** @type {number} */ yaw) => page.evaluate(wanted => { /** @type {any} */ (window).__wildshard.world.player.yaw = wanted; }, yaw);
|
|
70
|
+
/** Steer to (x, z) with W held, turning toward it every 100 ms; true when within 3 m. */
|
|
71
|
+
const driveTo = async (/** @type {number} */ x, /** @type {number} */ z, ms = 60_000) => {
|
|
72
|
+
let near = Infinity;
|
|
73
|
+
await page.keyboard.down('KeyW');
|
|
74
|
+
for (const ends = Date.now() + ms; Date.now() < ends && near > 3; await sleep(100)) { const at = await sample(); near = Math.hypot(at.x - x, at.z - z); await face(Math.atan2(at.x - x, at.z - z)); }
|
|
75
|
+
await page.keyboard.up('KeyW'); await sleep(800);
|
|
76
|
+
return near <= 3;
|
|
77
|
+
};
|
|
78
|
+
// The board and its boost through the player's own toggles (what H and a double tap of H call), each checked before it counts.
|
|
79
|
+
const board = async () => {
|
|
80
|
+
for (let tries = 0; tries < 5 && !(await sample())?.hover; tries++) { await page.evaluate(() => { const p = /** @type {any} */ (window).__wildshard.world.player; if (!p.hover) p.setHover(true); }); await sleep(800); }
|
|
81
|
+
};
|
|
82
|
+
const boost = async (/** @type {boolean} */ on) => {
|
|
83
|
+
await board();
|
|
84
|
+
await page.evaluate(wanted => { /** @type {any} */ (window).__wildshard.world.player.setBoost(wanted); }, on); await sleep(300);
|
|
85
|
+
const at = await sample(); if (!at?.hover || Boolean(at?.boost) !== on) result.notes.push(`boost ${String(on)} did not take: ${JSON.stringify(at)}`);
|
|
86
|
+
};
|
|
87
|
+
/** Hold W facing `yaw` for `ms` and read the case: the median speed over the last 1.5 s (0.25 s steps), the page's cap, corrections. */
|
|
88
|
+
const drive = async (/** @type {string} */ name, /** @type {number} */ x, /** @type {number} */ ms) => {
|
|
89
|
+
const from = await now(), before = await sample();
|
|
90
|
+
// north along the line x, turning back onto it every 100 ms (a board drifts off a held yaw over 200 m)
|
|
91
|
+
await page.keyboard.down('KeyW');
|
|
92
|
+
for (const ends = Date.now() + ms; Date.now() < ends; await sleep(100)) { const at = await sample(); await face(Math.atan2(at.x - x, -40)); }
|
|
93
|
+
await page.keyboard.up('KeyW');
|
|
94
|
+
const rows = /** @type {any[]} */ (await page.evaluate(t => /** @type {any} */ (window).__hoverSpeed.samples.filter((/** @type {any} */ row) => row.err === undefined && row.t >= t), from));
|
|
95
|
+
const last = rows.at(-1), tail = rows.filter(row => row.t >= last.t - 1500), speeds = [];
|
|
96
|
+
for (let i = 0; i < tail.length; i++) { const later = tail.find(row => row.t >= tail[i].t + 250); if (later !== undefined) speeds.push(Math.hypot(later.x - tail[i].x, later.z - tail[i].z) / ((later.t - tail[i].t) / 1000)); }
|
|
97
|
+
speeds.sort((a, b) => a - b);
|
|
98
|
+
const row = { name, speed: Number((speeds[Math.floor(speeds.length / 2)] ?? 0).toFixed(2)), top: Number((speeds.at(-1) ?? 0).toFixed(2)), cap: last.cap, hover: last.hover, boost: last.boost,
|
|
99
|
+
inside: last.inside, at: { x: Number(last.x.toFixed(1)), y: Number(last.y.toFixed(2)), z: Number(last.z.toFixed(1)) }, corrections: last.corrections === null || before.corrections === null ? null : last.corrections - before.corrections };
|
|
100
|
+
result.cases.push(row); console.log(JSON.stringify(row));
|
|
101
|
+
await sleep(1200);
|
|
102
|
+
return row;
|
|
103
|
+
};
|
|
104
|
+
const shoot = async (/** @type {string} */ name) => {
|
|
105
|
+
const file = join(out, `${phone ? 'phone' : 'desktop'}-${name}.png`);
|
|
106
|
+
await page.screenshot({ path: file }); result.shots.push(file);
|
|
107
|
+
const edge = join(out, `${phone ? 'phone' : 'desktop'}-${name}-edge.png`), size = page.viewportSize() ?? { width: 1440, height: 900 };
|
|
108
|
+
await page.screenshot({ path: edge, clip: { x: 0, y: Math.round(size.height * 0.46 - 90), width: Math.min(220, size.width), height: 180 } }); result.shots.push(edge);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// The approach (not scored): on the board to Driftwood's west water.
|
|
112
|
+
await board();
|
|
113
|
+
if (!await driveTo(ZONE_X, -194)) result.notes.push('the approach to (-235, -194) fell short');
|
|
114
|
+
if (shots) { await boost(false); await shoot('boost-off'); await boost(true); await shoot('boost-on'); }
|
|
115
|
+
await boost(false);
|
|
116
|
+
await drive('zone, boost off', ZONE_X, 7000);
|
|
117
|
+
await boost(false); await driveTo(ZONE_X, -194);
|
|
118
|
+
await boost(true);
|
|
119
|
+
await drive('zone, boost on', ZONE_X, 6500);
|
|
120
|
+
// Onto the road: back to the west entryway's line (z 0), out through it, and onto the deck's middle.
|
|
121
|
+
await boost(false);
|
|
122
|
+
if (!await driveTo(ZONE_X, 0)) result.notes.push('the way to the west entryway fell short');
|
|
123
|
+
if (!await driveTo(DECK_X, 0, 40_000)) result.notes.push('the deck (-281, 0) was not reached');
|
|
124
|
+
await drive('road, boost off', DECK_X, 8000);
|
|
125
|
+
await boost(true);
|
|
126
|
+
await drive('road, boost on', DECK_X, 10_500); // 12 m/s² takes 30 to 120 in 7.5 s
|
|
127
|
+
code = 0;
|
|
128
|
+
} catch (error) {
|
|
129
|
+
result.errors.push(String(error).slice(0, 400)); console.error(error);
|
|
130
|
+
await shown?.screenshot({ path: join(out, `${phone ? 'phone' : 'desktop'}-failed.png`) }).catch(() => undefined);
|
|
131
|
+
} finally {
|
|
132
|
+
writeFileSync(join(out, `hover-speed-${phone ? 'phone' : 'desktop'}.json`), `${JSON.stringify(result, null, 2)}\n`);
|
|
133
|
+
await browser.close();
|
|
134
|
+
await rig?.close();
|
|
135
|
+
}
|
|
136
|
+
process.exit(code);
|
package/scripts/mmo-bots.mjs
CHANGED
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
// code, built here under the release's build name, so the release's packs still match it. The bots are built from the same
|
|
26
26
|
// commit, so their code and wire are the server's exactly. It must descend from the release's build; the report names it
|
|
27
27
|
// (`serverFrom`). Every value that reaches the host's shell is a checked slug, number, hex or fixed path.
|
|
28
|
-
// Everything goes in tmp/mmo-bots/<stamp
|
|
28
|
+
// Everything goes in tmp/mmo-bots/<stamp>/ by default, or in the bounded `--work-dir tmp/<lane>/...` path; the release tree is
|
|
29
|
+
// removed after the run and the report stays.
|
|
29
30
|
import { execFileSync, spawn } from 'node:child_process';
|
|
30
31
|
import { createHash, createPublicKey, generateKeyPairSync, randomBytes, sign, verify } from 'node:crypto';
|
|
31
32
|
import { copyFileSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
@@ -47,7 +48,8 @@ const [mode = '', ...rest] = process.argv.slice(2);
|
|
|
47
48
|
const { values } = parseArgs({ args: rest, options: { bots: { type: 'string' }, seconds: { type: 'string' }, seats: { type: 'string', default: '32' }, workers: { type: 'string', default: '4' },
|
|
48
49
|
cells: { type: 'string', default: 'driftwood-isle' }, database: { type: 'string', default: 'memory:' }, keep: { type: 'boolean', default: false },
|
|
49
50
|
remote: { type: 'string' }, cpus: { type: 'string', default: '9-13' }, 'server-from': { type: 'string' },
|
|
50
|
-
'bots-on-host': { type: 'boolean', default: false }, 'bot-cpus': { type: 'string', default: '14-15' }, tailnet: { type: 'boolean', default: false }
|
|
51
|
+
'bots-on-host': { type: 'boolean', default: false }, 'bot-cpus': { type: 'string', default: '14-15' }, tailnet: { type: 'boolean', default: false },
|
|
52
|
+
'work-dir': { type: 'string' } } });
|
|
51
53
|
const serverFrom = values['server-from'];
|
|
52
54
|
if (serverFrom !== undefined && (mode !== 'replica' || !/^[0-9a-f]{40}$/u.test(serverFrom))) throw new Error('--server-from is a full commit, for a replica');
|
|
53
55
|
// These reach the host's shell inside the replica's env line: only slugs and whole numbers.
|
|
@@ -60,7 +62,9 @@ if (botsOnHost && remote === undefined) throw new Error('--bots-on-host needs --
|
|
|
60
62
|
if (mode !== 'replica' && mode !== 'staging') { console.error('usage: mmo-bots.mjs replica|staging [--bots N] [--seconds S]'); process.exit(2); }
|
|
61
63
|
const bots = Number(values.bots ?? (mode === 'replica' ? 32 : 2)), seconds = Number(values.seconds ?? (mode === 'replica' ? 120 : 60));
|
|
62
64
|
if (!Number.isInteger(bots) || bots < 1 || bots > 64 || !Number.isFinite(seconds) || seconds < 5 || seconds > 3600) throw new Error('--bots 1..64, --seconds 5..3600');
|
|
63
|
-
const
|
|
65
|
+
const workRoot = absolute(ROOT, 'tmp'), workBase = absolute(ROOT, values['work-dir'] ?? 'tmp/mmo-bots');
|
|
66
|
+
if (workBase !== workRoot && !workBase.startsWith(`${workRoot}/`)) throw new Error('--work-dir stays under tmp/');
|
|
67
|
+
const stamp = new Date().toISOString().replaceAll(/[-:]/gu, '').replace(/\..*/u, 'Z'), work = join(workBase, stamp), tag = `${mode === 'replica' ? 'r' : 's'}${stamp.slice(9, 15)}`;
|
|
64
68
|
mkdirSync(work, { recursive: true });
|
|
65
69
|
/** @param {Record<string, unknown>} line */
|
|
66
70
|
const note = line => { const text = JSON.stringify({ at: 'mmo-bots', ...line }); console.info(text); writeFileSync(join(work, 'run.log'), `${text}\n`, { flag: 'a' }); };
|
|
@@ -107,7 +107,7 @@ async function runOne(browser, engineName, layout, slug, site, socket) {
|
|
|
107
107
|
if (await page.evaluate(() => /** @type {any} */ (window).__wildshard?.world?.game.app.clock.paused === true)) await page.getByRole('button', { name: /^resume$/iu }).click().catch(() => undefined);
|
|
108
108
|
row.enterMs = Date.now() - t0;
|
|
109
109
|
const entered = Date.now(), delays = /** @type {{ t: number, delay: number }[]} */ ([]), heldFrom = await page.evaluate(() => window.__workerClient?.().interpHeld ?? 0);
|
|
110
|
-
const report = () => page.evaluate(() => { const w = window.__workerClient?.(); return w === undefined ? null : { corrections: w.corrections, worst: w.worstOffset, delay: w.delayMs, held: w.interpHeld, falls: w.falls, missed: { ...w.missed } }; });
|
|
110
|
+
const report = () => page.evaluate(() => { const w = window.__workerClient?.(); return w === undefined ? null : { corrections: w.corrections, worst: w.worstOffset, delay: w.delayMs, held: w.interpHeld, falls: w.falls, missed: { ...w.missed }, authoritative: { ...w.authoritative } }; });
|
|
111
111
|
sampler = setInterval(() => { void report().then(r => { if (r !== null) delays.push({ t: Date.now() - entered, delay: r.delay }); return undefined; }).catch(() => undefined); }, 250);
|
|
112
112
|
await sleep(2000);
|
|
113
113
|
// the budget: the drawn rate standing still, against the display's 60 Hz (headless)
|
|
@@ -131,7 +131,8 @@ async function runOne(browser, engineName, layout, slug, site, socket) {
|
|
|
131
131
|
const drawn = await page.evaluate(() => /** @type {any} */ (window).__netLag.drawn.slice()), to = await report();
|
|
132
132
|
// what this phase's corrections disagreed on (position, grounded, board, swim, ride), for the row a miss becomes
|
|
133
133
|
const missed = Object.fromEntries(Object.entries(to?.missed ?? {}).filter(([key]) => key !== 'gap').map(([key, value]) => [key, value - (/** @type {Record<string, number> | undefined} */ (from?.missed)?.[key] ?? 0)]).filter(([, value]) => value !== 0));
|
|
134
|
-
|
|
134
|
+
const authoritative = Object.fromEntries(Object.entries(to?.authoritative ?? {}).map(([key, value]) => [key, value - (/** @type {Record<string, number> | undefined} */ (from?.authoritative)?.[key] ?? 0)]).filter(([, value]) => value !== 0));
|
|
135
|
+
return { name, corrections: (to?.corrections ?? 0) - (from?.corrections ?? 0), missed, authoritative, frames: drawn.length, p50: at(drawn, 0.5), p99: at(drawn, 0.99), max: at(drawn, 1), over2x: drawn.filter((/** @type {number} */ ms) => ms > 2 * row.budgetMs).length, over50: drawn.filter((/** @type {number} */ ms) => ms > 50).length };
|
|
135
136
|
};
|
|
136
137
|
row.walk = await phase('walk', ['KeyW']);
|
|
137
138
|
row.sprint = await phase('sprint', ['KeyW', 'ShiftLeft']);
|
|
@@ -199,7 +200,7 @@ for (const engineName of engines) {
|
|
|
199
200
|
let site = { base, close: () => Promise.resolve() }, socket = /^https:\/\/(staging|preview)\./u.test(base) ? arg('socket', 'wss://rooms-staging.wildshard.io') : arg('socket', '');
|
|
200
201
|
if (rigArg !== '') {
|
|
201
202
|
const [dist = '', work = '', keyFile = ''] = rigArg.split(','), { openRig, WORLD_PORT } = await import('./online-rig.mjs');
|
|
202
|
-
site = await openRig({ dist: absolute(dist), work: absolute(work, slug), keyFile, pgBin: 'memory:', pgData: '', shard: slug
|
|
203
|
+
site = await openRig({ dist: absolute(dist), work: absolute(work, slug), keyFile, pgBin: 'memory:', pgData: '', shard: slug });
|
|
203
204
|
socket = `ws://127.0.0.1:${String(WORLD_PORT)}`;
|
|
204
205
|
}
|
|
205
206
|
try {
|
package/scripts/online-rig.mjs
CHANGED
|
@@ -46,11 +46,13 @@ export async function intoWorld(page) {
|
|
|
46
46
|
|
|
47
47
|
/** `pgBin` 'memory:' keeps the saves in the server's memory, for a proof that never reads them back (voice-proof.mjs): no Postgres.
|
|
48
48
|
* `more` are other shards the release names, `cells` the server's `WORLD_CELLS` (default `shard`), and `socket` the address the
|
|
49
|
-
* release names when a proof puts its own front door before the server (grid-gate-proof.mjs).
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
|
|
49
|
+
* release names when a proof puts its own front door before the server (grid-gate-proof.mjs). Every rig has the road;
|
|
50
|
+
* J353 removed the continuous-crossing switch. `workers` sets `WORLD_WORKERS` (the rig's release is production's,
|
|
51
|
+
* 4 by default; staging runs 2). FM3: `origins` are loopback page origins the server also lets in, and `channel`
|
|
52
|
+
* is the release file's channel (`production`).
|
|
53
|
+
* @param {{ dist: string, nextDist?: string, work: string, keyFile: string, pgBin: string, pgData: string, shard?: string, seats?: number, more?: string[], cells?: string, socket?: string, workers?: number, origins?: string[], channel?: string }} options */
|
|
54
|
+
export async function openRig({ dist, nextDist = '', work, keyFile, pgBin, pgData, shard = 'driftwood-isle', seats, more = [], cells = shard, socket = `ws://127.0.0.1:${String(WORLD_PORT)}/`, workers, origins = [], channel = 'production' }) {
|
|
55
|
+
if (origins.some(origin => new URL(origin).origin !== origin || new URL(origin).hostname !== '127.0.0.1')) throw new Error('A rig lets in loopback page origins only');
|
|
54
56
|
const memory = pgBin === 'memory:';
|
|
55
57
|
const key = JSON.parse(readFileSync(keyFile, 'utf8')), build = buildOf(dist), nextBuild = nextDist === '' ? '' : buildOf(nextDist), DATABASE = memory ? 'memory:' : database('saves_online');
|
|
56
58
|
mkdirSync(work, { recursive: true });
|
|
@@ -62,9 +64,9 @@ export async function openRig({ dist, nextDist = '', work, keyFile, pgBin, pgDat
|
|
|
62
64
|
run(['scripts/build-server.mjs', '--build', build, '--out', server], 'the server build');
|
|
63
65
|
|
|
64
66
|
let signed = '';
|
|
65
|
-
/** @param {number} serial @param {string} engineBuild */
|
|
66
|
-
const publish = (serial, engineBuild) => {
|
|
67
|
-
const body = JSON.stringify({ channel:
|
|
67
|
+
/** @param {number} serial @param {string} engineBuild @param {string} [signedChannel] */
|
|
68
|
+
const publish = (serial, engineBuild, signedChannel = channel) => {
|
|
69
|
+
const body = JSON.stringify({ channel: signedChannel, serial, engineBuild, saveEpoch: 1, shards: slugs.map(slug => ({ slug, revision: 1 })), socket });
|
|
68
70
|
signed = JSON.stringify({ body, signature: sign(null, Buffer.from(body), key.private).toString('hex') });
|
|
69
71
|
};
|
|
70
72
|
publish(1, build);
|
|
@@ -81,7 +83,7 @@ export async function openRig({ dist, nextDist = '', work, keyFile, pgBin, pgDat
|
|
|
81
83
|
|
|
82
84
|
const world = (running = build) => {
|
|
83
85
|
const room = spawn(process.execPath, [join(server, 'main.mjs')], { cwd: ROOT, stdio: ['ignore', 'pipe', 'pipe'],
|
|
84
|
-
env: { ...process.env, RELEASE_URL: `http://127.0.0.1:${String(RELEASE_PORT)}/release.json`, RELEASE_PUBLIC_KEY: key.public, PACK_ORIGIN: `file://${origin}/`, PACK_CACHE: join(work, 'packs'), DATABASE_URL: DATABASE, SEAT_SECRET: 'online-proof', HOST: '127.0.0.1', PORT: String(WORLD_PORT), ALLOWED_ORIGINS: `http://127.0.0.1:${String(PAGE_PORT)}`, WILDSHARD_BUILD: running, WORLD_CELLS: cells, RELEASE_POLL_MS: '500', GRACE_MS: '6000', ...seats === undefined ? {} : { WORLD_SEATS: String(seats) },
|
|
86
|
+
env: { ...process.env, RELEASE_URL: `http://127.0.0.1:${String(RELEASE_PORT)}/release.json`, RELEASE_PUBLIC_KEY: key.public, PACK_ORIGIN: `file://${origin}/`, PACK_CACHE: join(work, 'packs'), DATABASE_URL: DATABASE, SEAT_SECRET: 'online-proof', HOST: '127.0.0.1', PORT: String(WORLD_PORT), ALLOWED_ORIGINS: [`http://127.0.0.1:${String(PAGE_PORT)}`, ...origins].join(','), WILDSHARD_BUILD: running, WORLD_CELLS: cells, RELEASE_POLL_MS: '500', GRACE_MS: '6000', ...seats === undefined ? {} : { WORLD_SEATS: String(seats) }, ...workers === undefined ? {} : { WORLD_WORKERS: String(workers) } } });
|
|
85
87
|
room.stdout.pipe(log, { end: false }); room.stderr.pipe(log, { end: false });
|
|
86
88
|
return room;
|
|
87
89
|
};
|
|
@@ -273,7 +273,7 @@ export function bootRoadCompletionState() {
|
|
|
273
273
|
return {at, timeOrigin: performance.timeOrigin, stop: stop ?? null,
|
|
274
274
|
compact: compact === null ? null : {inside: field(compact, 'inside'), current: field(live, 'current'), ready: field(live, 'gameplayReady'),
|
|
275
275
|
pendingCount: Array.isArray(pending) ? pending.length : null, phase: field(crossing, 'phase')},
|
|
276
|
-
observer: ids === null ? null : {present: ids.
|
|
276
|
+
observer: ids === null ? null : {present: ids.some((id) => id.startsWith('harness.walk')), systems: ids.length},
|
|
277
277
|
owner: scope === undefined ? null : {name: scope.name, disposed: scope.disposed, disposing: scope.disposing},
|
|
278
278
|
view: {coverage: ui?.presentation, still: ui?.still, blocking: ui?.blocking, top: ui?.top,
|
|
279
279
|
visibility: typeof document === 'undefined' ? null : document.visibilityState,
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// AUTO-RELEASE AR5 (meta docs/plans/AUTO-RELEASE-PLAN.md, J355): the last step of an engine release, with no Jake command.
|
|
3
|
+
// Moves the box's cook worker to the tag production now serves, through the agents' own account (J266).
|
|
4
|
+
// node scripts/release-cook.mjs vX.Y.Z [--dry-run]
|
|
5
|
+
// 1. Production's signed release must name vX.Y.Z (read from packs.wildshard.io, public; the box checks the signature).
|
|
6
|
+
// 2. If the box's wildshard-config has no `cook` verb yet, it is installed from a signed tag that carries it, by the
|
|
7
|
+
// allowlisted `wildshard-apply <tag> harden` (which refreshes /usr/local/sbin and /opt/wildshard-vps). Only after
|
|
8
|
+
// `wildshard-harden --check` shows no `fail` row outside OFF_SSH_ROWS, so the apply changes no sshd, ufw or Tailscale
|
|
9
|
+
// setting. An OFF_SSH_ROWS fail is one the apply fixes away from them (v0.1.21: SC2, Prometheus down on a root-only
|
|
10
|
+
// /etc/prometheus, fixed by the tag's harden).
|
|
11
|
+
// 3. `sudo -n wildshard-config cook vX.Y.Z`: the box verifies the tag, writes cook.settings, rebuilds the cook step alone,
|
|
12
|
+
// waits for its /health and rolls back if it does not come up. Then `show cook` and the worker's /health.
|
|
13
|
+
// --dry-run reads the box and says what it would do; it writes nothing. Output never carries an address or a secret.
|
|
14
|
+
import { spawnSync } from 'node:child_process';
|
|
15
|
+
|
|
16
|
+
const HOST = 'wildshard-agent';
|
|
17
|
+
const RELEASES = 'https://packs.wildshard.io/releases';
|
|
18
|
+
const TAG = /^v\d{1,4}\.\d{1,4}\.\d{1,4}$/u;
|
|
19
|
+
const SIGNED_TAG = /^(?:v\d{1,4}\.\d{1,4}\.\d{1,4}|server-(?:staging|production)-[0-9a-f]{40})$/u, COMMIT = /^[0-9a-f]{40}$/u;
|
|
20
|
+
const MARK = 'cook <tag>';
|
|
21
|
+
// harden --check rows whose fix never touches sshd, ufw or Tailscale: SC2 is the box-local Prometheus on loopback.
|
|
22
|
+
const OFF_SSH_ROWS = new Set(['SC2']);
|
|
23
|
+
|
|
24
|
+
/** @param {string} what @param {string} message */
|
|
25
|
+
function say(what, message) { console.info(`${what.padEnd(7)} ${redact(message)}`); }
|
|
26
|
+
/** @param {string} message @returns {never} */
|
|
27
|
+
function stop(message) { console.error(`stop ${redact(message)}`); process.exit(1); }
|
|
28
|
+
/** Never print an address: IPv4 and tailnet hosts are blanked. @param {string} text */
|
|
29
|
+
function redact(text) { return text.replaceAll(/\b(?:\d{1,3}\.){3}\d{1,3}\b/gu, '<address>').replaceAll(/\b[\w-]+\.tail[\w-]+\.ts\.net\b/gu, '<tailnet>'); }
|
|
30
|
+
|
|
31
|
+
/** One command on the box as the agents' account. @param {string} command */
|
|
32
|
+
function box(command) {
|
|
33
|
+
const run = spawnSync('ssh', ['-o', 'ConnectTimeout=20', '-o', 'BatchMode=yes', HOST, command], { encoding: 'utf8', timeout: 20 * 60_000 });
|
|
34
|
+
return { status: run.status ?? 1, out: `${run.stdout ?? ''}${run.stderr ?? ''}` };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The tag and build a channel's release file names (unverified here; the box verifies). @param {'production' | 'staging'} channel */
|
|
38
|
+
async function served(channel) {
|
|
39
|
+
const answer = await fetch(`${RELEASES}/${channel}.json`, { signal: AbortSignal.timeout(20_000), cache: 'no-store' });
|
|
40
|
+
if (!answer.ok) stop(`${channel}'s release file answered ${String(answer.status)}`);
|
|
41
|
+
const body = JSON.parse(/** @type {{ body: string }} */ (await answer.json()).body);
|
|
42
|
+
const tag = String(body.bundle?.name ?? '').split('/')[0] ?? '', build = String(body.engineBuild ?? '');
|
|
43
|
+
// The file is unverified here and both values reach a shell on the box: only a release tag and a full commit pass.
|
|
44
|
+
if (!SIGNED_TAG.test(tag) || !COMMIT.test(build)) stop(`${channel}'s release file names an unexpected tag or build`);
|
|
45
|
+
return { tag, build };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** True when engine `commit` ships the cook verb. @param {string} commit */
|
|
49
|
+
function carries(commit) {
|
|
50
|
+
spawnSync('git', ['fetch', '--quiet', 'origin', commit], { encoding: 'utf8' });
|
|
51
|
+
const shown = spawnSync('git', ['show', `${commit}:scripts/vps/wildshard-config`], { encoding: 'utf8', maxBuffer: 1 << 24 });
|
|
52
|
+
return shown.status === 0 && shown.stdout.includes(MARK);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function main() {
|
|
56
|
+
const args = process.argv.slice(2), dry = args.includes('--dry-run');
|
|
57
|
+
const tag = args.find(arg => arg !== '--dry-run');
|
|
58
|
+
if (tag === undefined || !TAG.test(tag) || args.length > (dry ? 2 : 1)) stop('usage: node scripts/release-cook.mjs vX.Y.Z [--dry-run]');
|
|
59
|
+
const production = await served('production');
|
|
60
|
+
if (production.tag !== tag) stop(`production serves ${production.tag || 'nothing'}, not ${tag}: the cook follows production`);
|
|
61
|
+
say('ok', `production serves ${tag} (${production.build.slice(0, 8)})`);
|
|
62
|
+
|
|
63
|
+
const shown = box('sudo -n /usr/local/sbin/wildshard-config show cook');
|
|
64
|
+
say('now', shown.status === 0 ? shown.out.trim().replaceAll('\n', ', ') : 'the box has no cook verb yet');
|
|
65
|
+
if (shown.status === 0 && shown.out.includes(`COOK_ENGINE_REF=${tag}\n`) && shown.out.includes(`WILDSHARD_BUILD=${production.build}`)) {
|
|
66
|
+
const health = box('curl -fsS --max-time 5 http://127.0.0.1:8792/health >/dev/null && echo up');
|
|
67
|
+
if (health.out.includes('up')) { say('ok', `the cook worker already runs ${tag} and answers /health`); return; }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (box(`grep -qF '${MARK}' /usr/local/sbin/wildshard-config`).status !== 0) {
|
|
71
|
+
// The helper comes from a signed tag that carries it: production's if it does, else staging's.
|
|
72
|
+
const staging = await served('staging');
|
|
73
|
+
const source = carries(production.build) ? production : carries(staging.build) ? staging : null;
|
|
74
|
+
if (source === null) stop('no signed release carries `wildshard-config cook` yet: it rides the next staging serial (AUTO-RELEASE AR8)');
|
|
75
|
+
const check = box('sudo -n /usr/local/sbin/wildshard-harden --check');
|
|
76
|
+
const fails = check.out.split('\n').filter(line => line.startsWith('fail') && !OFF_SSH_ROWS.has(line.split(/\s+/u)[1] ?? ''));
|
|
77
|
+
if (fails.length > 0) stop(`harden --check has ${String(fails.length)} fail row(s) (${fails.map(line => line.split(/\s+/u)[1]).join(', ')}): applying would change the box, so no auto-install`);
|
|
78
|
+
if (dry) { say('would', `install the cook verb by: sudo -n wildshard-apply ${source.tag} harden`); }
|
|
79
|
+
else {
|
|
80
|
+
say('doing', `sudo -n wildshard-apply ${source.tag} harden (detached; it may restart sshd)`);
|
|
81
|
+
box(`nohup sudo -n /usr/local/sbin/wildshard-apply ${source.tag} harden > ~/release-cook-harden.log 2>&1 < /dev/null &`);
|
|
82
|
+
// [w]: pgrep must not match the remote shell that runs it.
|
|
83
|
+
const deadline = Date.now() + 20 * 60_000, running = `pgrep -f '[w]ildshard-apply ${source.tag}' >/dev/null`;
|
|
84
|
+
// pgrep's 1 is "finished"; ssh's 255 (harden restarting sshd) is "ask again".
|
|
85
|
+
let status;
|
|
86
|
+
do {
|
|
87
|
+
await new Promise(resolve => { setTimeout(resolve, 15_000); });
|
|
88
|
+
if (Date.now() > deadline) stop('wildshard-apply harden did not finish in 20 minutes; see ~/release-cook-harden.log on the box');
|
|
89
|
+
status = box(running).status;
|
|
90
|
+
} while (status !== 1);
|
|
91
|
+
if (box(`grep -qF '${MARK}' /usr/local/sbin/wildshard-config`).status !== 0) stop('harden ran but the cook verb is not installed; see ~/release-cook-harden.log on the box');
|
|
92
|
+
// A step that could cut SSH arms a 10-minute dead-man; this new session proves the way in, so stop it as harden asks.
|
|
93
|
+
if (box('systemctl is-active --quiet wildshard-harden-deadman.timer').status === 0) {
|
|
94
|
+
say('note', 'harden armed its dead-man, so it changed an SSH-side setting; this session got in, stopping the timer');
|
|
95
|
+
const stopped = box('sudo -n /usr/bin/systemctl stop wildshard-harden-deadman.timer');
|
|
96
|
+
if (stopped.status !== 0 || box('systemctl is-active --quiet wildshard-harden-deadman.timer').status === 0) {
|
|
97
|
+
stop('the harden dead-man timer is still armed: run `sudo -n systemctl stop wildshard-harden-deadman.timer` as wildshard-agent within 10 minutes');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
say('ok', `the cook verb is installed from ${source.tag}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (dry) { say('would', `sudo -n wildshard-config cook ${tag}`); return; }
|
|
105
|
+
const moved = box(`sudo -n /usr/local/sbin/wildshard-config cook ${tag}`);
|
|
106
|
+
for (const line of moved.out.trim().split('\n').filter(row => /^(ok|doing|undo|stop|note|wait|warn|done)\s/u.test(row))) console.info(redact(line));
|
|
107
|
+
if (moved.status !== 0) stop(`wildshard-config cook ${tag} exited ${String(moved.status)}`);
|
|
108
|
+
const after = box('sudo -n /usr/local/sbin/wildshard-config show cook; curl -fsS --max-time 5 http://127.0.0.1:8792/health >/dev/null && echo health-up');
|
|
109
|
+
if (!after.out.includes(`COOK_ENGINE_REF=${tag}\n`) || !after.out.includes(`WILDSHARD_BUILD=${production.build}`) || !after.out.includes('health-up')) stop('the cook did not settle on the new tag; see journalctl -u wildshard-cook');
|
|
110
|
+
say('done', `the cook worker runs ${tag} (${production.build.slice(0, 8)}) and answers /health`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
await main();
|
|
@@ -139,10 +139,6 @@
|
|
|
139
139
|
"test/sdk-rigged-hull-files.test.ts": [],
|
|
140
140
|
"test/frame-floor-output-entry.test.ts": [],
|
|
141
141
|
"test/texture-scope-lifetime.test.ts": [],
|
|
142
|
-
"test/chapter-director-product.test.ts": [
|
|
143
|
-
"pine-hollow",
|
|
144
|
-
"driftwood-isle"
|
|
145
|
-
],
|
|
146
142
|
"test/director-shipping-product.test.ts": [
|
|
147
143
|
"pine-hollow",
|
|
148
144
|
"driftwood-isle"
|
|
@@ -221,9 +217,6 @@
|
|
|
221
217
|
"sunscar-dunes",
|
|
222
218
|
"far-reach"
|
|
223
219
|
],
|
|
224
|
-
"test/pine-npc-figure-product.test.ts": [
|
|
225
|
-
"pine-hollow"
|
|
226
|
-
],
|
|
227
220
|
"test/scripts/_template-boss.test.ts": [
|
|
228
221
|
"_template"
|
|
229
222
|
],
|
|
@@ -272,10 +265,6 @@
|
|
|
272
265
|
"test/keyed-sky-platform.test.ts": [],
|
|
273
266
|
"test/streamed-cover-platform.test.ts": [],
|
|
274
267
|
"test/toon-look-platform.test.ts": [],
|
|
275
|
-
"test/pine-quest-actions-product.test.ts": [
|
|
276
|
-
"pine-hollow",
|
|
277
|
-
"driftwood-isle"
|
|
278
|
-
],
|
|
279
268
|
"test/world-scene-batch.test.ts": [],
|
|
280
269
|
"test/pine-crag-scenes.test.ts": [
|
|
281
270
|
"pine-hollow"
|
|
@@ -285,9 +274,6 @@
|
|
|
285
274
|
"driftwood-isle"
|
|
286
275
|
],
|
|
287
276
|
"test/world-scene-baked-model.test.ts": [],
|
|
288
|
-
"test/pine-prop-product.test.ts": [
|
|
289
|
-
"pine-hollow"
|
|
290
|
-
],
|
|
291
277
|
"test/driftwood-foliage-scenes.test.ts": [],
|
|
292
278
|
"test/quest-catalogue-sites.test.ts": [
|
|
293
279
|
"pine-hollow",
|
|
@@ -332,10 +318,6 @@
|
|
|
332
318
|
"test/quest-page-refs.test.ts": [],
|
|
333
319
|
"test/scene-motion-refs.test.ts": [],
|
|
334
320
|
"test/scene-buffers.test.ts": [],
|
|
335
|
-
"test/native-runtime-plan.test.ts": [
|
|
336
|
-
"far-reach",
|
|
337
|
-
"sunscar-dunes"
|
|
338
|
-
],
|
|
339
321
|
"test/native-runtime-observation.test.ts": [
|
|
340
322
|
"far-reach"
|
|
341
323
|
],
|
|
@@ -356,9 +338,6 @@
|
|
|
356
338
|
"test/boss-arena-room.test.ts": [],
|
|
357
339
|
"test/grapple-platform.test.ts": [],
|
|
358
340
|
"test/nalati-layout-bake.test.ts": [],
|
|
359
|
-
"test/template-map-generation.test.ts": [
|
|
360
|
-
"_template"
|
|
361
|
-
],
|
|
362
341
|
"test/stealth-detection.test.ts": [],
|
|
363
342
|
"test/held-weapon-laws.test.ts": [],
|
|
364
343
|
"test/nalati-riding-rules.test.ts": ["pine-hollow", "nalati-grasslands"],
|