@wildshard/engine 0.1.20 → 0.1.21
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 +8 -0
- package/lint/engine-sides.json +1 -0
- package/package.json +2 -1
- package/scripts/chaos-proxy-core.mjs +14 -1
- package/scripts/chaos-proxy-proof.mjs +22 -0
- package/scripts/failmode-cases.d.mts +8 -0
- package/scripts/failmode-cases.mjs +97 -0
- package/scripts/failmode-proof.mjs +532 -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/hover-speed-probe.mjs +136 -0
- package/scripts/net-lag-proof.mjs +3 -2
- package/scripts/online-rig.mjs +9 -7
- package/scripts/release-cook.mjs +109 -0
- package/scripts/vps/rebuild.sh +35 -9
- package/scripts/vps/wildshard-apply.mjs +5 -1
- package/scripts/vps/wildshard-config +117 -1
- package/src/client/engine/boot/contentRead.ts +54 -5
- package/src/client/engine/boot/gpuFiles.ts +3 -3
- package/src/client/engine/boot/leaveAfterPaint.ts +4 -1
- 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/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 +44 -6
- package/src/client/game/grid/live.ts +2 -2
- package/src/client/game/grid/liveSession.ts +2 -2
- package/src/client/game/grid/session.ts +2 -0
- package/src/client/game/grid/shardfileFar.ts +13 -2
- package/src/client/game/shardfile/clientSource.ts +7 -3
- package/src/client/game/shardfile/clientWorker.ts +4 -4
- 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 +11 -1
- 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/simulation.ts +12 -6
- package/src/server/host/dedicated/cellHost.ts +7 -0
- package/src/server/host/dedicated/cellWorker.ts +1 -1
- package/src/server/host/dedicated/dedicatedRoom.ts +14 -1
- package/src/server/host/dedicated/roadRoom.ts +3 -0
- 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/strings.ts +12 -1
- package/src/shared/game/grid/rules.ts +12 -0
|
@@ -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;
|
|
@@ -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, 2 workers, crossing on; 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', crossing: true, 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);
|
|
@@ -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']);
|
package/scripts/online-rig.mjs
CHANGED
|
@@ -48,9 +48,11 @@ export async function intoWorld(page) {
|
|
|
48
48
|
* `more` are other shards the release names, `cells` the server's `WORLD_CELLS` (default `shard`), and `socket` the address the
|
|
49
49
|
* release names when a proof puts its own front door before the server (grid-gate-proof.mjs). `crossing` (on by default, GC35 / J322; false sets
|
|
50
50
|
* `WORLD_CROSSING=off`, a bench's lone cells) is `WORLD_CROSSING=worker` (GC15): each worker hosts the road between its cells from the grid pack the bake left in this checkout (grid-crossing-walk-proof.mjs),
|
|
51
|
-
* and `workers` sets `WORLD_WORKERS` (the rig's release is production's, 4 by default; staging runs 2).
|
|
52
|
-
*
|
|
53
|
-
|
|
51
|
+
* and `workers` sets `WORLD_WORKERS` (the rig's release is production's, 4 by default; staging runs 2). FM3: `origins` are page origins the
|
|
52
|
+
* server also lets in (a loopback proxy before the page server, failmode-proof.mjs), and `channel` 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, crossing?: boolean, 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)}/`, crossing = true, 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) }, WORLD_CROSSING: crossing ? 'worker' : 'off', ...workers === undefined ? {} : { WORLD_WORKERS: String(workers) } } });
|
|
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) }, WORLD_CROSSING: crossing ? 'worker' : 'off', ...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
|
};
|
|
@@ -0,0 +1,109 @@
|
|
|
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, so the apply changes no sshd, ufw or Tailscale setting.
|
|
9
|
+
// 3. `sudo -n wildshard-config cook vX.Y.Z`: the box verifies the tag, writes cook.settings, rebuilds the cook step alone,
|
|
10
|
+
// waits for its /health and rolls back if it does not come up. Then `show cook` and the worker's /health.
|
|
11
|
+
// --dry-run reads the box and says what it would do; it writes nothing. Output never carries an address or a secret.
|
|
12
|
+
import { spawnSync } from 'node:child_process';
|
|
13
|
+
|
|
14
|
+
const HOST = 'wildshard-agent';
|
|
15
|
+
const RELEASES = 'https://packs.wildshard.io/releases';
|
|
16
|
+
const TAG = /^v\d{1,4}\.\d{1,4}\.\d{1,4}$/u;
|
|
17
|
+
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;
|
|
18
|
+
const MARK = 'cook <tag>';
|
|
19
|
+
|
|
20
|
+
/** @param {string} what @param {string} message */
|
|
21
|
+
function say(what, message) { console.info(`${what.padEnd(7)} ${redact(message)}`); }
|
|
22
|
+
/** @param {string} message @returns {never} */
|
|
23
|
+
function stop(message) { console.error(`stop ${redact(message)}`); process.exit(1); }
|
|
24
|
+
/** Never print an address: IPv4 and tailnet hosts are blanked. @param {string} text */
|
|
25
|
+
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>'); }
|
|
26
|
+
|
|
27
|
+
/** One command on the box as the agents' account. @param {string} command */
|
|
28
|
+
function box(command) {
|
|
29
|
+
const run = spawnSync('ssh', ['-o', 'ConnectTimeout=20', '-o', 'BatchMode=yes', HOST, command], { encoding: 'utf8', timeout: 20 * 60_000 });
|
|
30
|
+
return { status: run.status ?? 1, out: `${run.stdout ?? ''}${run.stderr ?? ''}` };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The tag and build a channel's release file names (unverified here; the box verifies). @param {'production' | 'staging'} channel */
|
|
34
|
+
async function served(channel) {
|
|
35
|
+
const answer = await fetch(`${RELEASES}/${channel}.json`, { signal: AbortSignal.timeout(20_000), cache: 'no-store' });
|
|
36
|
+
if (!answer.ok) stop(`${channel}'s release file answered ${String(answer.status)}`);
|
|
37
|
+
const body = JSON.parse(/** @type {{ body: string }} */ (await answer.json()).body);
|
|
38
|
+
const tag = String(body.bundle?.name ?? '').split('/')[0] ?? '', build = String(body.engineBuild ?? '');
|
|
39
|
+
// The file is unverified here and both values reach a shell on the box: only a release tag and a full commit pass.
|
|
40
|
+
if (!SIGNED_TAG.test(tag) || !COMMIT.test(build)) stop(`${channel}'s release file names an unexpected tag or build`);
|
|
41
|
+
return { tag, build };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** True when engine `commit` ships the cook verb. @param {string} commit */
|
|
45
|
+
function carries(commit) {
|
|
46
|
+
spawnSync('git', ['fetch', '--quiet', 'origin', commit], { encoding: 'utf8' });
|
|
47
|
+
const shown = spawnSync('git', ['show', `${commit}:scripts/vps/wildshard-config`], { encoding: 'utf8', maxBuffer: 1 << 24 });
|
|
48
|
+
return shown.status === 0 && shown.stdout.includes(MARK);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function main() {
|
|
52
|
+
const args = process.argv.slice(2), dry = args.includes('--dry-run');
|
|
53
|
+
const tag = args.find(arg => arg !== '--dry-run');
|
|
54
|
+
if (tag === undefined || !TAG.test(tag) || args.length > (dry ? 2 : 1)) stop('usage: node scripts/release-cook.mjs vX.Y.Z [--dry-run]');
|
|
55
|
+
const production = await served('production');
|
|
56
|
+
if (production.tag !== tag) stop(`production serves ${production.tag || 'nothing'}, not ${tag}: the cook follows production`);
|
|
57
|
+
say('ok', `production serves ${tag} (${production.build.slice(0, 8)})`);
|
|
58
|
+
|
|
59
|
+
const shown = box('sudo -n /usr/local/sbin/wildshard-config show cook');
|
|
60
|
+
say('now', shown.status === 0 ? shown.out.trim().replaceAll('\n', ', ') : 'the box has no cook verb yet');
|
|
61
|
+
if (shown.status === 0 && shown.out.includes(`COOK_ENGINE_REF=${tag}\n`) && shown.out.includes(`WILDSHARD_BUILD=${production.build}`)) {
|
|
62
|
+
const health = box('curl -fsS --max-time 5 http://127.0.0.1:8792/health >/dev/null && echo up');
|
|
63
|
+
if (health.out.includes('up')) { say('ok', `the cook worker already runs ${tag} and answers /health`); return; }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (box(`grep -qF '${MARK}' /usr/local/sbin/wildshard-config`).status !== 0) {
|
|
67
|
+
// The helper comes from a signed tag that carries it: production's if it does, else staging's.
|
|
68
|
+
const staging = await served('staging');
|
|
69
|
+
const source = carries(production.build) ? production : carries(staging.build) ? staging : null;
|
|
70
|
+
if (source === null) stop('no signed release carries `wildshard-config cook` yet: it rides the next staging serial (AUTO-RELEASE AR8)');
|
|
71
|
+
const check = box('sudo -n /usr/local/sbin/wildshard-harden --check');
|
|
72
|
+
const fails = check.out.split('\n').filter(line => line.startsWith('fail'));
|
|
73
|
+
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`);
|
|
74
|
+
if (dry) { say('would', `install the cook verb by: sudo -n wildshard-apply ${source.tag} harden`); }
|
|
75
|
+
else {
|
|
76
|
+
say('doing', `sudo -n wildshard-apply ${source.tag} harden (detached; it may restart sshd)`);
|
|
77
|
+
box(`nohup sudo -n /usr/local/sbin/wildshard-apply ${source.tag} harden > ~/release-cook-harden.log 2>&1 < /dev/null &`);
|
|
78
|
+
// [w]: pgrep must not match the remote shell that runs it.
|
|
79
|
+
const deadline = Date.now() + 20 * 60_000, running = `pgrep -f '[w]ildshard-apply ${source.tag}' >/dev/null`;
|
|
80
|
+
// pgrep's 1 is "finished"; ssh's 255 (harden restarting sshd) is "ask again".
|
|
81
|
+
let status;
|
|
82
|
+
do {
|
|
83
|
+
await new Promise(resolve => { setTimeout(resolve, 15_000); });
|
|
84
|
+
if (Date.now() > deadline) stop('wildshard-apply harden did not finish in 20 minutes; see ~/release-cook-harden.log on the box');
|
|
85
|
+
status = box(running).status;
|
|
86
|
+
} while (status !== 1);
|
|
87
|
+
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');
|
|
88
|
+
// 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.
|
|
89
|
+
if (box('systemctl is-active --quiet wildshard-harden-deadman.timer').status === 0) {
|
|
90
|
+
say('note', 'harden armed its dead-man, so it changed an SSH-side setting; this session got in, stopping the timer');
|
|
91
|
+
const stopped = box('sudo -n /usr/bin/systemctl stop wildshard-harden-deadman.timer');
|
|
92
|
+
if (stopped.status !== 0 || box('systemctl is-active --quiet wildshard-harden-deadman.timer').status === 0) {
|
|
93
|
+
stop('the harden dead-man timer is still armed: run `sudo -n systemctl stop wildshard-harden-deadman.timer` as wildshard-agent within 10 minutes');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
say('ok', `the cook verb is installed from ${source.tag}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (dry) { say('would', `sudo -n wildshard-config cook ${tag}`); return; }
|
|
101
|
+
const moved = box(`sudo -n /usr/local/sbin/wildshard-config cook ${tag}`);
|
|
102
|
+
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));
|
|
103
|
+
if (moved.status !== 0) stop(`wildshard-config cook ${tag} exited ${String(moved.status)}`);
|
|
104
|
+
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');
|
|
105
|
+
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');
|
|
106
|
+
say('done', `the cook worker runs ${tag} (${production.build.slice(0, 8)}) and answers /health`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
await main();
|
package/scripts/vps/rebuild.sh
CHANGED
|
@@ -7,20 +7,24 @@
|
|
|
7
7
|
# 4. The cook worker (C4): an engine checkout at a tag, its user, its AppArmor allowance and its unit. It needs cook.env.
|
|
8
8
|
# sudo bash rebuild.sh do what is missing. Exit 0 is done; exit 2 is waiting for one of Jake's inputs
|
|
9
9
|
# bash rebuild.sh --check change nothing and say what it would do; protected state says `cannot verify`
|
|
10
|
+
# sudo bash rebuild.sh --cook step 4 alone (AUTO-RELEASE AR3): `wildshard-config cook <tag>` runs it as root after
|
|
11
|
+
# writing cook.settings, whose COOK_ENGINE_REF and WILDSHARD_BUILD win over cook.env's
|
|
10
12
|
# Keep this beside the other scripts/vps files. docs/vps-setup.md, "Rebuild from nothing", has the steps around it.
|
|
11
13
|
# HARD STOP (Jake, 2026-11-09): this never runs on the old VPS. Nothing there is rebuilt until OPENCLAW-EXTRACT's OX10
|
|
12
14
|
# is signed, so a host that still holds OpenClaw, Coolify, clawdbot or Ollama state is refused in both modes.
|
|
13
15
|
# Port 443 and `rooms.wildshard.io` are Jake's, after VPS-HARDENING VH16 (J179): Caddy is installed and left off.
|
|
14
16
|
set -euo pipefail
|
|
15
|
-
CHECK=0
|
|
16
|
-
if [ "$
|
|
17
|
-
elif [ "$#"
|
|
17
|
+
CHECK=0 COOK_ONLY=0
|
|
18
|
+
if [ "$#" = 1 ] && [ "$1" = --check ]; then CHECK=1
|
|
19
|
+
elif [ "$#" = 1 ] && [ "$1" = --cook ]; then COOK_ONLY=1
|
|
20
|
+
elif [ "$#" != 0 ]; then printf 'stop Expected no arguments, --check or --cook\n'; exit 1; fi
|
|
18
21
|
HERE=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
|
|
19
22
|
ETC=/etc/wildshard HOME_DIR=/var/lib/wildshard SYSTEMD=/etc/systemd/system
|
|
20
23
|
PG_VERSION=16 NODE=/usr/bin/node NODE_MAJOR=24 PNPM=pnpm@10.34.9
|
|
21
24
|
KEY_DIR=/home/raynos/wildshard-e7 KEY_FILE=/home/raynos/wildshard-e7/release-public-key.hex
|
|
22
25
|
COOK_ENV=/etc/wildshard/cook.env COOK_HOME=/var/lib/wildshard-cook COOK_SRC=/opt/wildshard/engine COOK_LIB=/usr/local/lib/wildshard-cook
|
|
23
26
|
COOK_GROUP=wildshard-cook
|
|
27
|
+
COOK_SETTINGS=/etc/wildshard/cook.settings
|
|
24
28
|
# 8790 and 8791 are the game's loopback ports; the cook worker's own default was 8791 too.
|
|
25
29
|
COOK_PORT=8792
|
|
26
30
|
ENGINE_GIT=https://github.com/project-wildshard/engine.git
|
|
@@ -80,9 +84,15 @@ env_value() { sed -n "s/^$2=//p" "$1" 2>/dev/null | tail -n 1; }
|
|
|
80
84
|
# The cook worker starts only once its env file names a build, an API, a token and one store (R2's four rows or a folder).
|
|
81
85
|
cook_env_complete() {
|
|
82
86
|
local file=$1 name
|
|
83
|
-
for name in COOK_ENGINE_REF WILDSHARD_BUILD WILDSHARD_API_URL COOK_NOTIFY_TOKEN; do [ -n "$(
|
|
84
|
-
if [ -n "$(
|
|
85
|
-
for name in R2_ACCOUNT_ID R2_BUCKET_PACKS R2_PACKS_ACCESS_KEY_ID R2_PACKS_SECRET_ACCESS_KEY; do [ -n "$(
|
|
87
|
+
for name in COOK_ENGINE_REF WILDSHARD_BUILD WILDSHARD_API_URL COOK_NOTIFY_TOKEN; do [ -n "$(cook_value "$file" "$name")" ] || return 1; done
|
|
88
|
+
if [ -n "$(cook_value "$file" COOK_STORE_DIR)" ]; then return 0; fi
|
|
89
|
+
for name in R2_ACCOUNT_ID R2_BUCKET_PACKS R2_PACKS_ACCESS_KEY_ID R2_PACKS_SECRET_ACCESS_KEY; do [ -n "$(cook_value "$file" "$name")" ] || return 1; done
|
|
90
|
+
}
|
|
91
|
+
# AUTO-RELEASE AR3 (J355): `wildshard-config cook <tag>` writes COOK_ENGINE_REF and WILDSHARD_BUILD to cook.settings, which
|
|
92
|
+
# the unit reads after cook.env. A key there wins, blank too, exactly as systemd reads the two files; otherwise cook.env's.
|
|
93
|
+
cook_value() {
|
|
94
|
+
if [ -n "${COOK_SETTINGS:-}" ] && [ -r "$COOK_SETTINGS" ] && grep -q "^$2=" "$COOK_SETTINGS"; then env_value "$COOK_SETTINGS" "$2"
|
|
95
|
+
else env_value "$1" "$2"; fi
|
|
86
96
|
}
|
|
87
97
|
# Caddy's package ships a page on port 80. Only that file, byte for byte as dpkg recorded it, or this script's own
|
|
88
98
|
# placeholder is replaced; any other file is VH9's and is never touched.
|
|
@@ -106,6 +116,9 @@ wait_http() {
|
|
|
106
116
|
|
|
107
117
|
# --- Before anything
|
|
108
118
|
if [ "$CHECK" = 0 ] && [ "$(id -u)" != 0 ]; then say stop 'Run with sudo, or pass --check'; exit 1; fi
|
|
119
|
+
# AUTO-RELEASE AR3: one rebuild at a time, whichever way it was started (a full run, --cook from wildshard-config cook,
|
|
120
|
+
# wildshard-apply <tag> rebuild), so two never move the cook's checkout or install into it at once.
|
|
121
|
+
if [ "$CHECK" = 0 ]; then exec 9>/run/wildshard-rebuild.lock; flock 9; fi
|
|
109
122
|
for name in setup.sh setup-state.mjs pull.mjs dump.sh restore-check.sh uptime.sh health-stub.mjs wildshard-config wildshard-apply.mjs wildshard-agent.pub; do
|
|
110
123
|
if [ ! -f "$HERE/$name" ]; then say stop "$name must sit beside rebuild.sh"; exit 1; fi
|
|
111
124
|
done
|
|
@@ -121,6 +134,9 @@ if [ "$(uname -m)" != x86_64 ]; then say warn "The VPS is x86_64, and this is $(
|
|
|
121
134
|
CPUS=$(nproc) SHARED_CPUS='AllowedCPUs=13-15'
|
|
122
135
|
if [ "$CPUS" -lt 16 ]; then say warn "The units' AllowedCPUs assume 16 cores, and this has $CPUS"; SHARED_CPUS="# AllowedCPUs=13-15 needs 16 cores; this box has $CPUS"; fi
|
|
123
136
|
|
|
137
|
+
# AUTO-RELEASE AR3: --cook is step 4 alone; the box already has what steps 1 to 3 make.
|
|
138
|
+
PHASE2=0
|
|
139
|
+
if [ "$COOK_ONLY" = 0 ]; then
|
|
124
140
|
# --- 1. Packages
|
|
125
141
|
APT_UPDATED=0
|
|
126
142
|
apt_update() { if [ "$APT_UPDATED" = 0 ]; then apt-get update -qq; APT_UPDATED=1; fi; }
|
|
@@ -375,6 +391,7 @@ else
|
|
|
375
391
|
bash "$HERE/setup.sh"
|
|
376
392
|
PHASE2=1
|
|
377
393
|
fi
|
|
394
|
+
fi # COOK_ONLY: --cook skips steps 1 to 3
|
|
378
395
|
|
|
379
396
|
# --- 4. The cook worker (C4, J28): its own user, an engine checkout it can read and not write, and its unit.
|
|
380
397
|
have_cook_user() { id wildshard-cook >/dev/null 2>&1 && getent group wildshard-cook >/dev/null; }
|
|
@@ -426,7 +443,7 @@ EOF
|
|
|
426
443
|
else say ok 'unprivileged user namespaces are not restricted here; no AppArmor profile needed'; fi
|
|
427
444
|
|
|
428
445
|
COOK_REF='' COOK_READY=0
|
|
429
|
-
if [ -r "$COOK_ENV" ] && cook_env_complete "$COOK_ENV"; then COOK_READY=1; COOK_REF=$(
|
|
446
|
+
if [ -r "$COOK_ENV" ] && cook_env_complete "$COOK_ENV"; then COOK_READY=1; COOK_REF=$(cook_value "$COOK_ENV" COOK_ENGINE_REF); fi
|
|
430
447
|
if [ "$COOK_READY" = 0 ]; then
|
|
431
448
|
if [ -r "$COOK_ENV" ] || [ "$CHECK" = 0 ]; then wait_for "Fill $COOK_ENV (engine tag, build, notify token, and R2 or a folder), then run rebuild.sh again"
|
|
432
449
|
elif [ "$(id -u)" = 0 ]; then say would "wait for $COOK_ENV to be filled"
|
|
@@ -450,6 +467,10 @@ make_cook_source() {
|
|
|
450
467
|
fi
|
|
451
468
|
git -c safe.directory="$COOK_SRC" -C "$COOK_SRC" fetch --quiet --tags origin
|
|
452
469
|
git -c safe.directory="$COOK_SRC" -C "$COOK_SRC" checkout --quiet --force --detach "$COOK_REF^{commit}"
|
|
470
|
+
# --cook (AR3): the tag must still be the build wildshard-config verified, or the worker would run other code than it reports.
|
|
471
|
+
if [ "$COOK_ONLY" = 1 ] && [ "$(cook_commit)" != "$(cook_value "$COOK_ENV" WILDSHARD_BUILD)" ]; then
|
|
472
|
+
say stop "$COOK_REF is $(cook_commit) on GitHub now, not the verified WILDSHARD_BUILD"; exit 1
|
|
473
|
+
fi
|
|
453
474
|
rm -f "$COOK_SRC/.wildshard-installed"
|
|
454
475
|
(cd "$COOK_SRC" && org_git env CI=1 HOME=/root COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack "$PNPM" install --frozen-lockfile --ignore-scripts --config.confirmModulesPurge=false)
|
|
455
476
|
printf '%s %s\n' "$COOK_REF" "$(cook_commit)" > "$COOK_SRC/.wildshard-installed"
|
|
@@ -474,8 +495,11 @@ if [ "$COOK_READY" = 1 ]; then
|
|
|
474
495
|
if [ "$CHECK" = 0 ] && ! have_cook_read; then COOK_SOURCE_CHANGED=1; fi
|
|
475
496
|
step "cook source readable by $COOK_GROUP" have_cook_read make_cook_read
|
|
476
497
|
fi
|
|
477
|
-
# What the running worker last read of cook.env, as a hash in its root-owned checkout: a changed file
|
|
478
|
-
|
|
498
|
+
# What the running worker last read of cook.env and cook.settings, as a hash in its root-owned checkout: a changed file
|
|
499
|
+
# restarts it. With no cook.settings the hash is cook.env's alone, as it was before AR3.
|
|
500
|
+
cook_env_hash() {
|
|
501
|
+
{ cat "$COOK_ENV"; cat "$COOK_SETTINGS" 2>/dev/null || true; } | sha256sum | cut -d' ' -f1
|
|
502
|
+
}
|
|
479
503
|
|
|
480
504
|
if put "$SYSTEMD/wildshard-cook.service" 644 root:root <<EOF
|
|
481
505
|
[Unit]
|
|
@@ -490,6 +514,8 @@ User=wildshard-cook
|
|
|
490
514
|
Group=wildshard-cook
|
|
491
515
|
WorkingDirectory=$COOK_SRC
|
|
492
516
|
EnvironmentFile=$COOK_ENV
|
|
517
|
+
# AUTO-RELEASE AR3: the engine tag and build wildshard-config cook sets, read after the secrets so they win. Optional.
|
|
518
|
+
EnvironmentFile=-$COOK_SETTINGS
|
|
493
519
|
# MS2.4b: the checkout is root's and the worker runs git in it as wildshard-cook, which git refuses ("dubious ownership")
|
|
494
520
|
# unless the path is a safe.directory. Set here, not in a gitconfig the worker's home would have to hold.
|
|
495
521
|
Environment=GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=safe.directory GIT_CONFIG_VALUE_0=$COOK_SRC
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/node
|
|
2
2
|
// MMO-SERVER-PLAN MS3.5 (J266): the agents' way to rerun harden.sh or setup.sh as root, from a signed, landed release only.
|
|
3
3
|
// wildshard-apply <tag> harden|setup|rebuild
|
|
4
|
+
// wildshard-apply <tag> verify AUTO-RELEASE AR2 (J355): print `commit <sha>` for a signed tag GitHub agrees on; runs nothing
|
|
4
5
|
// <tag> is a release tag a signed channel file names: `vX.Y.Z` (production) or `server-staging-<sha>` (staging). The file is
|
|
5
6
|
// checked exactly as pull.mjs checks it (Ed25519 over `body`, the release public key embedded below and in setup.sh), and its
|
|
6
7
|
// `bundle.name` must sit under that tag. Its `engineBuild` commit is fetched from GitHub by hash, the tag must point at the
|
|
@@ -89,7 +90,7 @@ async function main() {
|
|
|
89
90
|
{ stdio: 'inherit', env: { PATH: '/usr/sbin:/usr/bin:/sbin:/bin', HOME: '/root', LANG: 'C.UTF-8', WILDSHARD_APPLY_LOCKED: '1' } });
|
|
90
91
|
process.exit(locked.status ?? 1);
|
|
91
92
|
}
|
|
92
|
-
if (tag === undefined || which === undefined || rest.length > 0 || !(which
|
|
93
|
+
if (tag === undefined || which === undefined || rest.length > 0 || !(Object.hasOwn(SCRIPTS, which) || which === 'verify')) stop('usage: wildshard-apply <tag> harden|setup|rebuild|verify');
|
|
93
94
|
if (!TAG.test(tag)) stop(`${tag} is not a release tag (vX.Y.Z or server-staging-<sha>)`);
|
|
94
95
|
const key = test !== undefined ? process.env.WILDSHARD_APPLY_TEST_KEY ?? '' : RELEASE_PUBLIC_KEY;
|
|
95
96
|
const commits = new Set((await signedFiles()).map(text => signedCommit(text, tag, key)).filter(commit => commit !== null));
|
|
@@ -97,12 +98,15 @@ async function main() {
|
|
|
97
98
|
if (commits.size > 1) stop(`signed releases name ${tag} with different commits`);
|
|
98
99
|
const [commit] = commits;
|
|
99
100
|
say('ok', `${tag} is signed: engine ${commit}`);
|
|
101
|
+
if (test !== undefined && which === 'verify') { say('commit', commit); return; }
|
|
100
102
|
if (test !== undefined) { say('would', `fetch ${commit} and run scripts/vps/${SCRIPTS[/** @type {'harden' | 'setup' | 'rebuild'} */ (which)]}`); return; }
|
|
101
103
|
|
|
102
104
|
// The tag on GitHub must point at the signed commit (a peeled annotated tag, or a lightweight one).
|
|
103
105
|
const refs = git(['ls-remote', ENGINE_GIT, `refs/tags/${tag}`, `refs/tags/${tag}^{}`]).trim().split('\n').filter(Boolean).map(row => row.split('\t'));
|
|
104
106
|
const pointed = (refs.find(([, ref]) => ref === `refs/tags/${tag}^{}`) ?? refs.find(([, ref]) => ref === `refs/tags/${tag}`))?.[0];
|
|
105
107
|
if (pointed !== commit) stop(`GitHub's ${tag} points at ${pointed ?? 'nothing'}, not the signed ${commit}`);
|
|
108
|
+
// verify: wildshard-config's cook verb reads this line and moves the cook to exactly this commit (AUTO-RELEASE AR4).
|
|
109
|
+
if (which === 'verify') { say('commit', commit); return; }
|
|
106
110
|
|
|
107
111
|
// A fresh root-only folder for this commit: fetched by hash, unpacked from git's own objects, never a working copy.
|
|
108
112
|
mkdirSync(WORK, { recursive: true, mode: 0o700 });
|