@wildshard/dev 0.0.0-stage → 0.4.0
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/bin/wildshard.mjs +75 -0
- package/lint/host-callbacks.d.mts +6 -0
- package/lint/host-callbacks.mjs +123 -0
- package/lint/ratchet.json +3 -0
- package/package.json +101 -3
- package/scripts/audit-assets.d.mts +10 -0
- package/scripts/audit-assets.mjs +151 -0
- package/scripts/bake/coatFiles.d.mts +6 -0
- package/scripts/bake/coatFiles.mjs +37 -0
- package/scripts/bake/navmeshGround.ts +22 -0
- package/scripts/bake/near-placeholder.mjs +331 -0
- package/scripts/bake/viewmodelBytes.ts +26 -0
- package/scripts/bake/viewmodelPage.ts +11 -0
- package/scripts/bake-catalogue.mjs +44 -0
- package/scripts/bake-check.mjs +54 -0
- package/scripts/bake-chunk.mjs +124 -0
- package/scripts/bake-cloud-field.mjs +24 -0
- package/scripts/bake-coats.mjs +110 -0
- package/scripts/bake-data-maps.d.mts +24 -0
- package/scripts/bake-data-maps.mjs +78 -0
- package/scripts/bake-entry-programs.mjs +126 -0
- package/scripts/bake-geometry.mjs +106 -0
- package/scripts/bake-ktx2.mjs +477 -0
- package/scripts/bake-map-glb.mjs +127 -0
- package/scripts/bake-map-rest.d.mts +7 -0
- package/scripts/bake-map-rest.mjs +50 -0
- package/scripts/bake-maps.mjs +200 -0
- package/scripts/bake-navmesh.mjs +259 -0
- package/scripts/bake-packs.mjs +129 -0
- package/scripts/bake-pickups.mjs +102 -0
- package/scripts/bake-query-terrain.mjs +64 -0
- package/scripts/bake-textures.mjs +80 -0
- package/scripts/bake-viewmodel-sets.mjs +137 -0
- package/scripts/bake-voxel-ao.mjs +119 -0
- package/scripts/bake-water-ripples.mjs +25 -0
- package/scripts/browser-imports.d.mts +2 -0
- package/scripts/browser-imports.mjs +40 -0
- package/scripts/browser-machine-loader-proof.mjs +39 -0
- package/scripts/browser-machine-loader.d.mts +8 -0
- package/scripts/browser-machine-loader.mjs +87 -0
- package/scripts/browser-playwright.d.mts +10 -0
- package/scripts/browser-playwright.mjs +5 -0
- package/scripts/browser-test.d.mts +4 -0
- package/scripts/browser-test.mjs +18 -0
- package/scripts/build-sdk.mjs +95 -0
- package/scripts/build-shardfiles.d.mts +7 -0
- package/scripts/build-shardfiles.mjs +230 -0
- package/scripts/capture-hero.mjs +211 -0
- package/scripts/chromium-keychain.d.mts +1 -0
- package/scripts/chromium-keychain.mjs +7 -0
- package/scripts/entry-reads/crawl.ts +152 -0
- package/scripts/gen-host-catalogue.d.mts +14 -0
- package/scripts/gen-host-catalogue.mjs +108 -0
- package/scripts/gen-shards.d.mts +17 -0
- package/scripts/gen-shards.mjs +311 -0
- package/scripts/goldens/plot-inputs.d.mts +12 -0
- package/scripts/goldens/plot-inputs.mjs +46 -0
- package/scripts/gpu-texmem.mjs +98 -0
- package/scripts/ktx2-ab.mjs +111 -0
- package/scripts/map-bake-frames.d.mts +4 -0
- package/scripts/map-bake-frames.mjs +23 -0
- package/scripts/map-world.mjs +162 -0
- package/scripts/memory-product.mjs +62 -0
- package/scripts/music/export-midi.mjs +69 -0
- package/scripts/named-blob-output.d.mts +8 -0
- package/scripts/named-blob-output.mjs +48 -0
- package/scripts/practice/verify_unimate_skin.mjs +356 -0
- package/scripts/preparation-browser.mjs +25 -0
- package/scripts/preparation-seed.mjs +15 -0
- package/scripts/prepare-product.d.mts +14 -0
- package/scripts/prepare-product.mjs +133 -0
- package/scripts/prove-walk.mjs +83 -0
- package/scripts/push-tables.d.mts +1 -0
- package/scripts/push-tables.mjs +28 -0
- package/scripts/record-shard-mounts.mjs +133 -0
- package/scripts/section-inventory.ts +209 -0
- package/scripts/shard-build-pool.d.mts +4 -0
- package/scripts/shard-build-pool.mjs +53 -0
- package/scripts/shard-milestones.d.mts +15 -0
- package/scripts/shard-milestones.mjs +105 -0
- package/scripts/shard-progress.mjs +212 -0
- package/scripts/shardfile-cold-boot.mjs +79 -0
- package/scripts/shardfile-rolldown.d.mts +2 -0
- package/scripts/shardfile-rolldown.mjs +32 -0
- package/scripts/shardfile-vite.d.mts +4 -0
- package/scripts/shardfile-vite.mjs +20 -0
- package/scripts/site-facts.mjs +88 -0
- package/scripts/test-template-gate.mjs +44 -0
- package/scripts/tex-tiers.mjs +240 -0
- package/scripts/unused-assets.mjs +173 -0
- package/scripts/wildshard.d.mts +4 -0
- package/scripts/wildshard.mjs +146 -0
- package/scripts/witness-generation.d.mts +10 -0
- package/scripts/witness-generation.mjs +45 -0
- package/src/.oxlintrc.json +12 -0
- package/src/cli/bin.mjs +8 -0
- package/src/cli/content-command.ts +44 -0
- package/src/cli/content.ts +287 -0
- package/src/cli/grid/command.ts +48 -0
- package/src/cli/grid/grid.ts +155 -0
- package/src/cli/help.ts +262 -0
- package/src/cli/hero/adopt.ts +109 -0
- package/src/cli/install-home.ts +40 -0
- package/src/cli/main.ts +142 -0
- package/src/cli/version.ts +63 -0
- package/src/server/app.ts +19 -0
- package/src/server/serve.ts +49 -0
- package/src/sharddev/bake/json.mjs +84 -0
- package/src/sharddev/bake/mapRest.ts +57 -0
- package/src/sharddev/bake/nativeRaster.ts +106 -0
- package/src/sharddev/bake/source-loader.mjs +55 -0
- package/src/sharddev/bake/splatLayers.ts +29 -0
- package/src/sharddev/bootInventory.ts +132 -0
- package/src/sharddev/check.ts +125 -0
- package/src/sharddev/checkProject.ts +134 -0
- package/src/sharddev/cli.ts +207 -0
- package/src/sharddev/dev.ts +150 -0
- package/src/sharddev/devClient.ts +120 -0
- package/src/sharddev/devRoot.ts +6 -0
- package/src/sharddev/engineMusic.ts +23 -0
- package/src/sharddev/projectEntryProof.ts +32 -0
- package/src/sharddev/test/diskScriptScenario.ts +88 -0
- package/src/sharddev/test/scriptScenario.ts +254 -0
- package/src/sharddev/tsconfig.json +3 -0
- package/src/sharddev/watch/page.ts +288 -0
- package/src/sharddev/watch/pageEntry.ts +44 -0
- package/src/sharddev/watch/parity-baseline.json +22 -0
- package/src/sharddev/watch/parity.mjs +194 -0
- package/src/sharddev/watch/proof.mjs +199 -0
- package/src/sharddev/watch/socket.ts +57 -0
- package/src/sharddev/watch/watch.ts +382 -0
- package/src/shared/health.ts +10 -0
- package/src/tools/build-web.ts +59 -0
- package/src/web/app.tsx +53 -0
- package/src/web/index.html +12 -0
- package/src/web/main.tsx +10 -0
- package/tsconfig.author.json +25 -0
- package/tsconfig.json +47 -0
- package/README.md +0 -3
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { KEYCHAIN_ARGS } from './chromium-keychain.mjs';
|
|
3
|
+
// shard-progress.mjs — one progress capture of a shard (E387, Jake 2026-10-02: "progress photos and progress videos and
|
|
4
|
+
// time lapse videos of shard five and shard six being built … we definitely should").
|
|
5
|
+
//
|
|
6
|
+
// Shoots the shard's fixed progress cameras (`art/<slug>/progress/cameras.json`) on a served build, iPhone portrait
|
|
7
|
+
// (390×844 @3, phone tier, touch HUD), and records one short real-resolution clip (canvas.captureStream, the memory note
|
|
8
|
+
// "game video capture"): a slow orbit around the clip's centre. Every run writes the same frames, so
|
|
9
|
+
// `scripts/shard-timelapse.py <slug>` can line them up into time-lapses.
|
|
10
|
+
//
|
|
11
|
+
// scripts/serve-build.sh --name prog # → http://127.0.0.1:<port>/ (or serve an export of an older SHA)
|
|
12
|
+
// scripts/browser-lane.sh --max 20 node scripts/shard-progress.mjs --shard=sunscar-dunes --url=http://127.0.0.1:<port> \
|
|
13
|
+
// --sha=<sha the build is> [--label="loop 3"] [--no-clip] [--no-qa] [--qa-wait=120] [--qa-force=<shot id>]
|
|
14
|
+
//
|
|
15
|
+
// Capture QA (E394): after the shots, scripts/decide/decide.sh asks the local Clef-flash model whether each frame shows
|
|
16
|
+
// the 3D world or a loading screen, title card, menu or blank frame (~1 s a frame, under the model lock). A flagged shot is
|
|
17
|
+
// re-taken once with a longer settle and checked again; meta.json's `qa` records each shot's answer and the re-takes.
|
|
18
|
+
// The check is skipped (and says so in meta.json) when the model or its venv is missing or the lock stays busy past
|
|
19
|
+
// --qa-wait seconds. --qa-force=<id> treats one shot as flagged, to exercise the re-take path.
|
|
20
|
+
//
|
|
21
|
+
// Output: progress/<slug>/<YYYYMMDD-HHMM>-<sha8>/<shot>.jpg (780×1688, ≤ ~300 KB), clip.mp4 (540 px wide), meta.json.
|
|
22
|
+
// The stamp is the commit's date (git), so a back-filled old SHA sorts where it belongs.
|
|
23
|
+
import { execFileSync, spawnSync } from 'node:child_process';
|
|
24
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync, rmSync } from 'node:fs';
|
|
25
|
+
import { resolve as resolvePath, join } from 'node:path';
|
|
26
|
+
import { saveFixture } from '@wildshard/engine/scripts/debug-settings.mjs';
|
|
27
|
+
import { browserBakeBytes } from '@wildshard/engine/scripts/bake-output.mjs';
|
|
28
|
+
import { recordProgressClip } from '@wildshard/engine/scripts/progress-recording.mjs';
|
|
29
|
+
import { uploadRecordedClip } from '@wildshard/engine/scripts/model-spin-recording.mjs';
|
|
30
|
+
|
|
31
|
+
const { chromium } = await import("./browser-playwright.mjs");
|
|
32
|
+
const ROOT = resolvePath(new URL('..', import.meta.url).pathname);
|
|
33
|
+
const argv = process.argv.slice(2);
|
|
34
|
+
const flag = (n, d) => { const a = argv.find((x) => x.startsWith(`--${n}=`)); return a ? a.slice(n.length + 3) : d; };
|
|
35
|
+
const SLUG = flag('shard', '');
|
|
36
|
+
const URL_BASE = flag('url', '');
|
|
37
|
+
if (!SLUG || !URL_BASE) { console.error('usage: shard-progress.mjs --shard=<slug> --url=<served build> --sha=<sha> [--label=…] [--no-clip]'); process.exit(2); }
|
|
38
|
+
const SHA = execFileSync('git', ['rev-parse', flag('sha', 'HEAD')], { cwd: ROOT, encoding: 'utf8' }).trim();
|
|
39
|
+
const LABEL = flag('label', '');
|
|
40
|
+
const CLIP = !argv.includes('--no-clip');
|
|
41
|
+
const QA = !argv.includes('--no-qa');
|
|
42
|
+
const QA_WAIT = Number(flag('qa-wait', '120'));
|
|
43
|
+
const QA_FORCE = argv.filter((a) => a.startsWith('--qa-force=')).map((a) => a.slice('--qa-force='.length));
|
|
44
|
+
/** --cameras=<file>: another cameras file (a test of the harness); default the shard's committed one */
|
|
45
|
+
const CAMS = JSON.parse(readFileSync(flag('cameras', join(ROOT, 'art', SLUG, 'progress', 'cameras.json')), 'utf8'));
|
|
46
|
+
const when = execFileSync('git', ['show', '-s', '--format=%cd', '--date=format:%Y%m%d-%H%M', SHA], { cwd: ROOT, encoding: 'utf8' }).trim();
|
|
47
|
+
/** --root=<dir>: write the capture there instead of the repo's progress/ (a scratch comparison, E397) */
|
|
48
|
+
const OUT = join(flag('root', join(ROOT, 'progress')), SLUG, `${when}-${SHA.slice(0, 8)}`);
|
|
49
|
+
mkdirSync(OUT, { recursive: true });
|
|
50
|
+
// one temp folder per run: two runs of the same shard at the same SHA (the lead's and a builder's) shared one, and the
|
|
51
|
+
// first to finish deleted it under the other (two council captures stopped half-way, E399)
|
|
52
|
+
mkdirSync(join(ROOT, 'tmp'), { recursive: true });
|
|
53
|
+
const TMP = mkdtempSync(join(ROOT, 'tmp', `shard-progress-${SLUG}-${SHA.slice(0, 8)}-`));
|
|
54
|
+
const sleep = (ms) => new Promise((resolve) => { setTimeout(resolve, ms); });
|
|
55
|
+
const D = Math.PI / 180;
|
|
56
|
+
|
|
57
|
+
/** a full-res PNG → a 780 px wide JPEG in the progress folder */
|
|
58
|
+
const store = (png, name) => {
|
|
59
|
+
const src = join(TMP, `${name}.png`); writeFileSync(src, png);
|
|
60
|
+
execFileSync('sips', ['-Z', '1688', '-s', 'format', 'jpeg', '-s', 'formatOptions', '80', src, '--out', join(OUT, `${name}.jpg`)], { stdio: 'ignore' });
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Capture QA (E394): decide.sh's `qa` over the named frames. Returns per-shot answers, or a reason the check was skipped.
|
|
65
|
+
* The sidecars it writes (<shot>.qa.json) are folded into meta.json and removed, so the progress folder keeps its shape.
|
|
66
|
+
* @param {string[]} ids @param {string[]} force
|
|
67
|
+
* @returns {{ skipped: string | null, shots: Record<string, { screen: string, pWorld: number, flagged: boolean }> }}
|
|
68
|
+
*/
|
|
69
|
+
const checkFrames = (ids, force) => {
|
|
70
|
+
const decide = join(ROOT, 'scripts', 'decide', 'decide.sh');
|
|
71
|
+
const args = ['qa', ...force.flatMap((id) => ['--force-flag', id]), ...ids.map((id) => join(OUT, `${id}.jpg`))];
|
|
72
|
+
const r = spawnSync(decide, args, { encoding: 'utf8', env: { ...process.env, DECIDE_LOCK_WAIT: String(QA_WAIT) } });
|
|
73
|
+
if (r.status !== 0 && r.status !== 3) {
|
|
74
|
+
return { skipped: r.status === 75 ? `the model lock stayed busy for ${QA_WAIT} s` : `decide.sh exited ${String(r.status)}: ${r.stderr.trim().slice(0, 200)}`, shots: {} };
|
|
75
|
+
}
|
|
76
|
+
/** @type {Record<string, { screen: string, pWorld: number, flagged: boolean }>} */
|
|
77
|
+
const shots = {};
|
|
78
|
+
for (const id of ids) {
|
|
79
|
+
const side = join(OUT, `${id}.qa.json`);
|
|
80
|
+
if (!existsSync(side)) continue;
|
|
81
|
+
const q = JSON.parse(readFileSync(side, 'utf8'));
|
|
82
|
+
shots[id] = { screen: q.answers.screen.choice, pWorld: q.answers.screen.probabilities.world, flagged: q.flagged };
|
|
83
|
+
rmSync(side);
|
|
84
|
+
}
|
|
85
|
+
return { skipped: null, shots };
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/** @type {import('playwright').Browser|undefined} */
|
|
89
|
+
let browser;
|
|
90
|
+
const errors = [], shots = [];
|
|
91
|
+
try {
|
|
92
|
+
browser = await chromium.launch({ args: [...KEYCHAIN_ARGS, '--mute-audio', '--use-angle=metal', '--ignore-gpu-blocklist'] });
|
|
93
|
+
const ctx = await browser.newContext({ viewport: { width: 390, height: 844 }, deviceScaleFactor: 3, isMobile: true, hasTouch: true,
|
|
94
|
+
userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Mobile/15E148 Safari/604.1' });
|
|
95
|
+
await saveFixture(ctx, { scope: 'device', key: 'devMode', data: true }); // experimental shards enter only in developer mode
|
|
96
|
+
// the probe's `pose` control needs the harness object (as the parity runner installs it)
|
|
97
|
+
await ctx.addInitScript(() => { window.__wildshardHarness = { seed: 0x2545f491, capture: null, lane: 'local', sha: '', browser: 'chromium', errors: [], saves: { read: [], written: [] }, audioRequests: [], gpuBytes: () => ({ textures: 0, renderbuffers: 0, buffers: 0, total: 0 }) }; });
|
|
98
|
+
const page = await ctx.newPage();
|
|
99
|
+
page.on('pageerror', (e) => errors.push(e.message.slice(0, 200)));
|
|
100
|
+
const t0 = Date.now();
|
|
101
|
+
await page.goto(`${URL_BASE}/?chunk=${SLUG}&tier=phone&touch=1&mute=1&nolock=1&sw=0&skipintro=1`, { waitUntil: 'domcontentloaded' });
|
|
102
|
+
await page.waitForFunction(() => document.documentElement.dataset.wsState === 'error'
|
|
103
|
+
|| (Boolean(window.__wildshard?.world?.player && window.__wildshard?.world?.game) && document.querySelector('.ws-load') === null),
|
|
104
|
+
undefined, { timeout: 480000, polling: 1000 });
|
|
105
|
+
// the game showed its error modal (a caught boot error leaves the load screen up): stop now with its text, not at 480 s
|
|
106
|
+
if (await page.evaluate(() => document.documentElement.dataset.wsState === 'error')) {
|
|
107
|
+
const text = await page.evaluate(() => document.body.textContent.slice(0, 600));
|
|
108
|
+
throw new Error(`the game failed to load (app state 'error'):\n${text}`);
|
|
109
|
+
}
|
|
110
|
+
const loadS = Math.round((Date.now() - t0) / 1000);
|
|
111
|
+
await sleep(6000);
|
|
112
|
+
store(await page.screenshot({ type: 'png' }), 'first-frame'); shots.push('first-frame');
|
|
113
|
+
// a free camera posed last in the frame (after the player's), the viewmodel hidden; null = the player's own view
|
|
114
|
+
await page.evaluate(() => {
|
|
115
|
+
const w = window.__wildshard.world, cam = w.game.camera;
|
|
116
|
+
try { w.animals.calm = true; } catch { /* a shard without animals */ }
|
|
117
|
+
window.__prog = null;
|
|
118
|
+
// what a free-camera shot changed, put back when the player's view returns (sky-reach, E399: after an aerial the
|
|
119
|
+
// viewmodel stayed hidden and the fov stayed 72 for every later first-person shot)
|
|
120
|
+
const hidden = new Set(); let fov = null;
|
|
121
|
+
w.game.onLate(() => {
|
|
122
|
+
const v = window.__prog;
|
|
123
|
+
if (!v) {
|
|
124
|
+
if (hidden.size > 0) { for (const c of hidden) c.visible = true; hidden.clear(); }
|
|
125
|
+
if (fov !== null) { cam.fov = fov; cam.updateProjectionMatrix(); fov = null; }
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (fov === null) fov = cam.fov;
|
|
129
|
+
cam.position.set(v.pos[0], v.pos[1], v.pos[2]); cam.up.set(0, 1, 0); cam.lookAt(v.look[0], v.look[1], v.look[2]);
|
|
130
|
+
if (Math.abs(cam.fov - v.fov) > 0.01) { cam.fov = v.fov; cam.updateProjectionMatrix(); }
|
|
131
|
+
for (const c of cam.children) if (c.visible) { c.visible = false; hidden.add(c); }
|
|
132
|
+
cam.updateMatrixWorld(true);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
const hud = (on) => page.evaluate((v) => { const h = document.getElementById('hud'); if (h) h.style.visibility = v ? '' : 'hidden'; }, on);
|
|
136
|
+
const staged = {};
|
|
137
|
+
// each shot's real camera (round 4: a new knoll lifted a view 1.1 m with no cameras.json change, so the round's camera
|
|
138
|
+
// list missed it); the council's camera diff compares these, not only the requested poses
|
|
139
|
+
const camAt = {};
|
|
140
|
+
/** one progress shot: stage, pose (or a free camera), settle, check the floor, store; a re-take passes a longer settle
|
|
141
|
+
* @param {any} s @param {number} [settle] */
|
|
142
|
+
const shoot = async (s, settle) => {
|
|
143
|
+
// creatures are calmed so they don't fill the frame; a shot whose subject IS a creature in action (a boss's stalk)
|
|
144
|
+
// sets `"calm": false`, since calm cancels the behaviour (mockup council round 1, seat A)
|
|
145
|
+
await page.evaluate((calm) => { try { window.__wildshard.world.animals.calm = calm; } catch { /* no animals */ } }, s.calm !== false);
|
|
146
|
+
// E399: a shot may stage real quest state first (`stage`), through the shard's exposed handle (`expose` at the top of
|
|
147
|
+
// cameras.json): e.g. the waymarks lit, the state a player reaches. Recorded in meta.json for the council to check.
|
|
148
|
+
if (s.stage !== undefined) {
|
|
149
|
+
const ok = await page.evaluate(([name, stage]) => {
|
|
150
|
+
const h = window.__wildshard.shard?.[name];
|
|
151
|
+
if (typeof h?.stage !== 'function') return false;
|
|
152
|
+
h.stage(stage); return true;
|
|
153
|
+
}, [CAMS.expose, s.stage]);
|
|
154
|
+
if (!ok) errors.push(`shot ${s.id}: no stage() on __wildshard.shard.${String(CAMS.expose)}`);
|
|
155
|
+
staged[s.id] = s.stage;
|
|
156
|
+
}
|
|
157
|
+
if (s.god) {
|
|
158
|
+
await page.evaluate((g) => { window.__prog = g; }, { fov: 72, ...s.god }); await hud(false);
|
|
159
|
+
} else {
|
|
160
|
+
await page.evaluate(async (p) => { window.__prog = null; const pl = window.__wildshard.world.player; try { pl.health = pl.maxHealth ?? 100; } catch { /* */ } await window.__wildshard.pose(p); },
|
|
161
|
+
{ x: s.x, z: s.z, yaw: s.yaw * D, pitch: (s.pitch ?? -4) * D, ...(s.y === undefined ? {} : { y: s.y }) });
|
|
162
|
+
await hud(true);
|
|
163
|
+
}
|
|
164
|
+
await sleep(settle ?? s.settle ?? 3000);
|
|
165
|
+
if (!s.god) { // a pose with no floor under it falls and respawns: flag it rather than store a wrong frame silently
|
|
166
|
+
const at = await page.evaluate(() => { const q = window.__wildshard.world.player.position; return [q.x, q.z]; });
|
|
167
|
+
if (Math.hypot(at[0] - s.x, at[1] - s.z) > 4) errors.push(`shot ${s.id}: the player is at (${at.map((v) => v.toFixed(1)).join(', ')}), not (${s.x}, ${s.z}): no floor there?`);
|
|
168
|
+
}
|
|
169
|
+
camAt[s.id] = await page.evaluate(() => { const c = window.__wildshard.world.game.camera, d = c.getWorldDirection(c.position.clone()); return { pos: [c.position.x, c.position.y, c.position.z].map((v) => Math.round(v * 100) / 100), dir: [d.x, d.y, d.z].map((v) => Math.round(v * 1000) / 1000), fov: Math.round(c.fov * 10) / 10 }; }).catch(() => null);
|
|
170
|
+
store(await page.screenshot({ type: 'png' }), s.id);
|
|
171
|
+
};
|
|
172
|
+
for (const s of CAMS.shots) { await shoot(s); shots.push(s.id); }
|
|
173
|
+
// capture QA (E394): a frame that is not the 3D world is re-taken once, with a longer settle
|
|
174
|
+
/** @type {{ set: string, skipped: string | null, retaken: string[], shots: Record<string, any> }} */
|
|
175
|
+
const qa = { set: 'capture-status', skipped: QA ? null : '--no-qa', retaken: [], shots: {} };
|
|
176
|
+
if (QA) {
|
|
177
|
+
const first = checkFrames(shots, QA_FORCE);
|
|
178
|
+
qa.skipped = first.skipped; qa.shots = first.shots;
|
|
179
|
+
// first-frame is the spawn view before any pose, so it is recorded but not re-taken
|
|
180
|
+
const again = CAMS.shots.filter((/** @type {any} */ x) => first.shots[x.id]?.flagged);
|
|
181
|
+
for (const s of again) { await shoot(s, (s.settle ?? 3000) * 2 + 3000); qa.retaken.push(s.id); }
|
|
182
|
+
if (again.length > 0) {
|
|
183
|
+
const second = checkFrames(qa.retaken, []);
|
|
184
|
+
for (const id of qa.retaken) qa.shots[id] = { ...second.shots[id], firstTake: first.shots[id] };
|
|
185
|
+
if (second.skipped) qa.skipped = `re-take check: ${second.skipped}`;
|
|
186
|
+
}
|
|
187
|
+
const still = Object.entries(qa.shots).filter(([, v]) => v.flagged).map(([k]) => k);
|
|
188
|
+
if (still.length > 0) errors.push(`capture QA: not the 3D world after a re-take: ${still.join(', ')}`);
|
|
189
|
+
}
|
|
190
|
+
// the clip: a slow orbit, recorded from the canvas at its real resolution
|
|
191
|
+
if (CLIP && CAMS.clip) {
|
|
192
|
+
await hud(false);
|
|
193
|
+
const clip = await page.evaluate(recordProgressClip, CAMS.clip), webm = join(TMP, 'clip.webm');
|
|
194
|
+
try {
|
|
195
|
+
const sink = await browserBakeBytes(page, { maxBytes: Math.max(1, clip.bytes), maxFiles: 1 });
|
|
196
|
+
try {
|
|
197
|
+
await page.evaluate(uploadRecordedClip, { source: clip.url, destination: `${sink.url}clip` });
|
|
198
|
+
const bytes = sink.take('clip');
|
|
199
|
+
if (bytes.byteLength !== clip.bytes) throw new Error('Recorded clip byte count changed');
|
|
200
|
+
writeFileSync(webm, bytes);
|
|
201
|
+
} finally { await sink.dispose(); }
|
|
202
|
+
} finally { await page.evaluate(source => { URL.revokeObjectURL(source); }, clip.url); }
|
|
203
|
+
execFileSync('ffmpeg', ['-v', 'error', '-y', '-i', webm, '-vf', 'scale=540:-2,format=yuv420p', '-c:v', 'libx264', '-b:v', '900k', '-maxrate', '1200k', '-bufsize', '2400k', '-r', '30', '-movflags', '+faststart', join(OUT, 'clip.mp4')]);
|
|
204
|
+
}
|
|
205
|
+
// the compiled programs after every view was drawn (E397: a program-key collision shows up as a lower count)
|
|
206
|
+
const programs = await page.evaluate(() => window.__wildshard.world.game.renderer?.info?.programs?.length ?? null).catch(() => null);
|
|
207
|
+
writeFileSync(join(OUT, 'meta.json'), `${JSON.stringify({ shard: SLUG, sha: SHA, when, label: LABEL, loadSeconds: loadS, shots, clip: CLIP && Boolean(CAMS.clip), programs, staged, camAt, qa, active: CAMS.shots.filter((x) => x.calm === false).map((x) => x.id), cameras: execFileSync('git', ['hash-object', flag('cameras', join(ROOT, 'art', SLUG, 'progress', 'cameras.json'))], { encoding: 'utf8' }).trim(), pageErrors: errors }, null, 1)}\n`);
|
|
208
|
+
console.log(`progress: ${OUT.slice(ROOT.length + 1)} · ${shots.length} shots${CLIP && CAMS.clip ? ' + clip' : ''} · load ${loadS} s · qa ${qa.skipped ? `skipped (${qa.skipped})` : `${Object.values(qa.shots).filter((v) => v.flagged).length} flagged, re-taken: ${qa.retaken.join(', ') || 'none'}`}${errors.length > 0 ? ` · ${errors.length} page errors` : ''}`);
|
|
209
|
+
} finally {
|
|
210
|
+
try { await browser?.close(); }
|
|
211
|
+
finally { rmSync(TMP, { recursive: true, force: true }); }
|
|
212
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// C0 (J137): prove a real boot needs nothing shard-owned from the tree. A built output is served with its product folders
|
|
3
|
+
// and every mount answered from the shard's tarball alone; a request for any other file a shard's name owns is refused with
|
|
4
|
+
// a 404 and counted as a leak. Each shard then cold boots on the phone profile, to control, in a fresh context.
|
|
5
|
+
// scripts/browser-lane.sh node --import ./scripts/bake-loader.mjs scripts/shardfile-cold-boot.mjs \
|
|
6
|
+
// --dist=<built output> --tars=<folder of <slug>.tar> [--engine=webkit|chromium] <slug> …
|
|
7
|
+
import { KEYCHAIN_ARGS } from './chromium-keychain.mjs';
|
|
8
|
+
import { createServer } from 'node:http';
|
|
9
|
+
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
10
|
+
import { brotliDecompressSync } from 'node:zlib';
|
|
11
|
+
import { extname, join, resolve as resolvePath } from 'node:path';
|
|
12
|
+
import { chromium, devices, webkit } from "./browser-playwright.mjs";
|
|
13
|
+
import { readTar } from '@wildshard/format/tar';
|
|
14
|
+
|
|
15
|
+
const flag = name => process.argv.find(row => row.startsWith(`--${name}=`))?.slice(name.length + 3);
|
|
16
|
+
const dist = resolvePath(flag('dist') ?? 'dist'), tars = resolvePath(flag('tars') ?? 'tmp/shardfiles'), engine = flag('engine') ?? 'chromium';
|
|
17
|
+
const slugs = process.argv.slice(2).filter(row => !row.startsWith('--'));
|
|
18
|
+
const TYPES = { '.html': 'text/html', '.js': 'text/javascript', '.mjs': 'text/javascript', '.css': 'text/css', '.json': 'application/json', '.wasm': 'application/wasm', '.webmanifest': 'application/json' };
|
|
19
|
+
/** The names a shard's own files carry under /assets. A file directly in /assets is the bundle's own (thumbs, boot tables):
|
|
20
|
+
* those are the app's until C3's catalogue. */
|
|
21
|
+
const OWNED = /^\/assets\/(?:(?:gpu\/(?:baked\/)?|music\/|sfx\/|lut\/|baked\/|models\/)?(?:driftwood|far-reach|nalati|nine-dragon|pine-hollow|sunscar|open-plot))/u;
|
|
22
|
+
|
|
23
|
+
const shards = new Map();
|
|
24
|
+
for (const name of readdirSync(tars).filter(row => row.endsWith('.tar'))) {
|
|
25
|
+
const files = readTar(readFileSync(join(tars, name))), slug = name.slice(0, -4);
|
|
26
|
+
const data = files.get('cook.json'), mounts = data === undefined ? [] : JSON.parse(new TextDecoder().decode(data)).mounts;
|
|
27
|
+
shards.set(slug, { files, mounts: new Map(mounts.map(row => [row.url, row.path])) });
|
|
28
|
+
}
|
|
29
|
+
const tally = { tar: new Map(), leaks: [] };
|
|
30
|
+
const count = (slug) => { tally.tar.set(slug, (tally.tar.get(slug) ?? 0) + 1); };
|
|
31
|
+
/** The tarball that answers a path, if one does. */
|
|
32
|
+
function fromTarball(path) {
|
|
33
|
+
const product = /^\/(?:shardfiles|server-class)\/([^/]+)\/(.+)$/u.exec(path);
|
|
34
|
+
if (product !== null) {
|
|
35
|
+
const shard = shards.get(product[1] ?? ''), bytes = shard?.files.get(product[2] ?? '');
|
|
36
|
+
if (bytes !== undefined) { count(product[1]); return bytes; }
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
for (const [slug, shard] of shards) {
|
|
40
|
+
const held = shard.mounts.get(path);
|
|
41
|
+
if (held !== undefined) { count(slug); return shard.files.get(held); }
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
const server = createServer((request, response) => {
|
|
46
|
+
const path = decodeURIComponent(new URL(request.url ?? '/', 'http://localhost').pathname);
|
|
47
|
+
const held = fromTarball(path);
|
|
48
|
+
if (held !== undefined) { response.writeHead(200, { 'content-type': TYPES[extname(path)] ?? 'application/octet-stream' }).end(held); return; }
|
|
49
|
+
if (OWNED.test(path) && !/^\/assets\/[^/]+\.[a-z0-9]+$/u.test(path)) { tally.leaks.push(path); response.writeHead(404).end(); return; }
|
|
50
|
+
const file = join(dist, path === '/' ? 'index.html' : path.slice(1));
|
|
51
|
+
if (!file.startsWith(dist) || !existsSync(file) || !statSync(file).isFile()) { response.writeHead(404).end(); return; }
|
|
52
|
+
// A part is stored as its q11 body; the test browser accepts br, and a plain read keeps this server small.
|
|
53
|
+
const body = readFileSync(file), part = file.endsWith('.pack.br');
|
|
54
|
+
response.writeHead(200, { 'content-type': TYPES[extname(file)] ?? 'application/octet-stream', 'cache-control': 'no-store' }).end(part ? brotliDecompressSync(body) : body);
|
|
55
|
+
});
|
|
56
|
+
await new Promise(resolve => { server.listen(0, '127.0.0.1', resolve); });
|
|
57
|
+
const address = server.address(), origin = `http://127.0.0.1:${typeof address === 'object' && address !== null ? address.port : 0}`;
|
|
58
|
+
const browser = await (engine === 'webkit' ? webkit : chromium).launch({ headless: true, args: engine === 'webkit' ? [] : [...KEYCHAIN_ARGS, '--mute-audio'] });
|
|
59
|
+
const rows = [];
|
|
60
|
+
try {
|
|
61
|
+
for (const slug of slugs) {
|
|
62
|
+
tally.leaks.length = 0; tally.tar.delete(slug);
|
|
63
|
+
const context = await browser.newContext({ ...devices['iPhone 16 Pro'], serviceWorkers: 'block', ...(engine === 'webkit' ? {} : { isMobile: false, defaultBrowserType: 'chromium' }) });
|
|
64
|
+
const page = await context.newPage(), errors = [], started = Date.now();
|
|
65
|
+
page.on('pageerror', error => { errors.push(String(error).slice(0, 200)); });
|
|
66
|
+
page.on('response', response => { if (response.status() >= 400) errors.push(`${response.status()} ${new URL(response.url()).pathname}`); });
|
|
67
|
+
page.on('console', message => { if (message.type() === 'error') errors.push(message.text().slice(0, 200)); });
|
|
68
|
+
let control = false;
|
|
69
|
+
try {
|
|
70
|
+
await page.goto(`${origin}/?chunk=${slug}&tier=phone&skipintro=1&nolock=1&mute=1`, { waitUntil: 'load' });
|
|
71
|
+
await page.waitForFunction(() => window.__wildshard?.world?.hud?.entered === true, undefined, { timeout: Number(flag('timeout') ?? 150_000) });
|
|
72
|
+
control = true;
|
|
73
|
+
} catch (error) { errors.push(String(error).slice(0, 160)); }
|
|
74
|
+
rows.push({ slug, control, seconds: Math.round((Date.now() - started) / 1000), fromTarball: tally.tar.get(slug) ?? 0, leaks: [...new Set(tally.leaks)], errors: [...new Set(errors)].slice(0, 6) });
|
|
75
|
+
console.log(JSON.stringify(rows.at(-1)));
|
|
76
|
+
await context.close();
|
|
77
|
+
}
|
|
78
|
+
} finally { await browser.close(); server.close(); }
|
|
79
|
+
if (rows.some(row => !row.control || row.leaks.length > 0)) process.exitCode = 1;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Trusted compiler bridge: Rolldown reads source in Rust, outside Node fs hooks. Inside the author CLI, the sdk's
|
|
2
|
+
// `rolldown` import resolves here (scripts/wildshard.mjs), so every bundle the build makes records its inputs.
|
|
3
|
+
import { rolldown as bundler } from 'rolldown';
|
|
4
|
+
import { recordBundle, inputRecorderPlugin } from '@wildshard/engine/scripts/shardfile-inputs.mjs';
|
|
5
|
+
import * as v from 'valibot';
|
|
6
|
+
|
|
7
|
+
export * from 'rolldown';
|
|
8
|
+
|
|
9
|
+
// Explicit compiler intent: this bundle executes in Node and its JavaScript
|
|
10
|
+
// is never copied into a product. Ordinary runtime bundles keep exact bytes.
|
|
11
|
+
const Execution = v.object({name:v.literal('wildshard-author-execution'),api:v.object({wildshardInputIdentity:v.literal('execution')})});
|
|
12
|
+
|
|
13
|
+
/** @param {import('rolldown').InputOptions} options */
|
|
14
|
+
export async function rolldown(options) {
|
|
15
|
+
const plugins = [options.plugins ?? []].flat();
|
|
16
|
+
const execution = plugins.some(plugin => v.is(Execution, plugin));
|
|
17
|
+
const started = performance.now();
|
|
18
|
+
const built = await bundler({ ...options, plugins: [inputRecorderPlugin({ execution }), ...plugins] });
|
|
19
|
+
/** @param {import('rolldown').RolldownOutput} result */
|
|
20
|
+
const recorded = result => {
|
|
21
|
+
recordBundle(result, { execution });
|
|
22
|
+
const input = options.input;
|
|
23
|
+
if (process.env.GITHUB_ACTIONS === 'true') console.info(`author timing: ${JSON.stringify({ pid: process.pid, phase: 'project-bundle', entry: typeof input === 'string' ? input : null, execution, seconds: Number(((performance.now() - started) / 1000).toFixed(3)) })}`);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
// The bundle keeps private fields, so its methods run on the bundle itself; only generate and write also record.
|
|
27
|
+
return new Proxy(built, { get(target, key) {
|
|
28
|
+
if (key === 'generate' || key === 'write') return async (/** @type {import('rolldown').OutputOptions} */ output) => recorded(await target[key](output));
|
|
29
|
+
const value = Reflect.get(target, key);
|
|
30
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
31
|
+
} });
|
|
32
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Trusted compiler bridge: Rolldown reads source in Rust, outside Node fs hooks.
|
|
2
|
+
import { build as viteBuild } from 'vite';
|
|
3
|
+
import { recordBundle, inputRecorderPlugin } from '@wildshard/engine/scripts/shardfile-inputs.mjs';
|
|
4
|
+
import * as v from 'valibot';
|
|
5
|
+
|
|
6
|
+
// Explicit compiler intent: this bundle executes in Node and its JavaScript
|
|
7
|
+
// is never copied into a product. Ordinary runtime bundles keep exact bytes.
|
|
8
|
+
const Execution = v.object({name:v.literal('wildshard-author-execution'),api:v.object({wildshardInputIdentity:v.literal('execution')})});
|
|
9
|
+
|
|
10
|
+
export { parseSync } from 'vite';
|
|
11
|
+
/** @param {import('vite').InlineConfig} options */
|
|
12
|
+
export async function build(options) {
|
|
13
|
+
const execution=options.plugins?.some(plugin=>v.is(Execution,plugin))===true;
|
|
14
|
+
const started = performance.now();
|
|
15
|
+
const result = await viteBuild({...options,plugins:[inputRecorderPlugin({execution}),...(options.plugins ?? [])]});
|
|
16
|
+
recordBundle(result,{execution});
|
|
17
|
+
const library = options.build?.lib;
|
|
18
|
+
if (process.env.GITHUB_ACTIONS === 'true') console.info(`author timing: ${JSON.stringify({ pid: process.pid, phase: 'project-bundle', entry: library === undefined || library === false ? null : library.entry, execution, seconds: Number(((performance.now() - started) / 1000).toFixed(3)) })}`);
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The marketing site's facts (P1-W1, E506 RD14): every number and excerpt the site shows about the game, read from the
|
|
3
|
+
// game's own sources and published as one JSON, so the site reads that file and nothing else of this repo.
|
|
4
|
+
// node scripts/site-facts.mjs --out <file> writes <file> (`pnpm build` writes dist/site-facts.json)
|
|
5
|
+
// The site lives in project-wildshard/www.wildshard.io, which commits a copy as src/site/facts.json and refreshes it by
|
|
6
|
+
// hand at a release (its docs/dev.md). Nothing here checks that copy.
|
|
7
|
+
// Sources: the single-player grid (src/shared/game/grid/singleplayer.json), the cell size and memory caps
|
|
8
|
+
// (@wildshard/format/contentBounds), the road width (@wildshard/engine/core/config), the shard.json schema's path count
|
|
9
|
+
// (@wildshard/format/shardSchema through scripts/docs/schema-reference.mjs) and an excerpt of the template's built
|
|
10
|
+
// shard.json (out/_template/shard.json: run node scripts/build-shardfiles.mjs first). The site formats the numbers.
|
|
11
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
12
|
+
import { resolve } from 'node:path';
|
|
13
|
+
import { pathToFileURL } from 'node:url';
|
|
14
|
+
|
|
15
|
+
const root = resolve(import.meta.dirname, '..');
|
|
16
|
+
const FORMAT = 'wildshard-site-facts/1';
|
|
17
|
+
|
|
18
|
+
/** @param {unknown} v @param {string} what @returns {Record<string, unknown>} */
|
|
19
|
+
function record(v, what) {
|
|
20
|
+
if (typeof v !== 'object' || v === null || Array.isArray(v)) throw new Error(`site-facts: ${what} is not a JSON object`);
|
|
21
|
+
return Object.fromEntries(Object.entries(v));
|
|
22
|
+
}
|
|
23
|
+
/** @param {unknown} v @param {string} what @returns {unknown[]} */
|
|
24
|
+
function list(v, what) { if (!Array.isArray(v)) throw new Error(`site-facts: ${what} is not a JSON array`); return v; }
|
|
25
|
+
/** @param {unknown} v @param {string} what @returns {number} */
|
|
26
|
+
function number(v, what) {
|
|
27
|
+
if (typeof v !== 'number' || !Number.isFinite(v)) throw new Error(`site-facts: ${what} is not a number`);
|
|
28
|
+
return v;
|
|
29
|
+
}
|
|
30
|
+
/** @param {string} file */
|
|
31
|
+
const json = (file) => record(JSON.parse(readFileSync(resolve(root, file), 'utf8')), file);
|
|
32
|
+
|
|
33
|
+
/** the one single-player grid used by public and Developer alike (G972); a later row for a cell replaces an earlier */
|
|
34
|
+
function grid() {
|
|
35
|
+
const g = record(json('src/shared/game/grid/singleplayer.json').grid, 'grid');
|
|
36
|
+
/** @type {Map<string, {x:number, z:number, slug:string, plot:boolean}>} */
|
|
37
|
+
const at = new Map();
|
|
38
|
+
for (const row of list(g.cells, 'grid.cells')) {
|
|
39
|
+
const r = record(row, 'a grid cell'), cell = list(r.cell, 'a grid cell'), slug = String(r.slug);
|
|
40
|
+
const x = number(cell[0], 'cell x'), z = number(cell[1], 'cell z');
|
|
41
|
+
at.set(`${x},${z}`, { x, z, slug, plot: slug.startsWith('open-plot-') });
|
|
42
|
+
}
|
|
43
|
+
return { pitch: number(g.pitch, 'grid.pitch'), cells: [...at.values()] };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** the template's built shard.json, cut to the fields the site's shardfile peek shows (MS15) */
|
|
47
|
+
function shardfileExcerpt() {
|
|
48
|
+
const file = 'out/_template/shard.json';
|
|
49
|
+
if (!existsSync(resolve(root, file))) throw new Error(`site-facts: no ${file}; run node scripts/build-shardfiles.mjs first`);
|
|
50
|
+
const index = json(file), requires = record(index.requires, 'requires'), admission = record(index.admission, 'admission');
|
|
51
|
+
return {
|
|
52
|
+
version: index.version, identity: index.identity, requires: { sdk: requires.sdk },
|
|
53
|
+
authorCaps: admission.authorCaps, serverBudget: admission.serverBudget, runtime: index.runtime ?? null,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** every fact, in the published shape (numbers stay numbers; the site words them) */
|
|
58
|
+
export async function siteFacts() {
|
|
59
|
+
await import('@wildshard/engine/scripts/sim-node-loader.mjs');
|
|
60
|
+
const { CHUNK_SIZE, MEMORY_GATES } = await import('@wildshard/format/contentBounds');
|
|
61
|
+
const { ROAD_WIDTH } = await import('@wildshard/engine/core/config');
|
|
62
|
+
const { ShardfileSchema } = await import('@wildshard/format/shardSchema');
|
|
63
|
+
const { schemaInventory } = await import('@wildshard/sdk/scripts/docs/schema-reference.mjs');
|
|
64
|
+
const { pitch, cells } = grid();
|
|
65
|
+
return {
|
|
66
|
+
$doc: 'Generated by scripts/site-facts.mjs (P1-W1) from the game\'s sources; do not edit. The site reads only this.',
|
|
67
|
+
format: FORMAT,
|
|
68
|
+
grid: { cellSize: CHUNK_SIZE, pitch, road: ROAD_WIDTH, cells },
|
|
69
|
+
memory: { explorerMB: MEMORY_GATES.explorerMB, loadingMB: MEMORY_GATES.loadingMB },
|
|
70
|
+
schemaPaths: schemaInventory(ShardfileSchema).length,
|
|
71
|
+
shardfile: shardfileExcerpt(),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** @param {unknown} facts */
|
|
76
|
+
export const factsText = (facts) => `${JSON.stringify(facts, null, 2)}\n`;
|
|
77
|
+
|
|
78
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
|
|
79
|
+
const args = process.argv.slice(2);
|
|
80
|
+
const file = args[args.indexOf('--out') + 1];
|
|
81
|
+
if (!args.includes('--out') || file === undefined) {
|
|
82
|
+
console.error('usage: node scripts/site-facts.mjs --out <file>');
|
|
83
|
+
process.exit(2);
|
|
84
|
+
}
|
|
85
|
+
const out = resolve(file);
|
|
86
|
+
writeFileSync(out, factsText(await siteFacts()));
|
|
87
|
+
console.info(`site-facts: wrote ${out}`);
|
|
88
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join, resolve } from 'node:path';
|
|
6
|
+
import { capture } from '@wildshard/engine/scripts/parity.mjs';
|
|
7
|
+
import { STEPS } from '@wildshard/engine/scripts/parity/combat.mjs';
|
|
8
|
+
import { browserPool } from '@wildshard/engine/scripts/parity/pool.mjs';
|
|
9
|
+
import { assertMetal } from '@wildshard/engine/scripts/parity/fingerprint.mjs';
|
|
10
|
+
import { flatten, object, array, string } from '@wildshard/engine/scripts/parity/value.mjs';
|
|
11
|
+
|
|
12
|
+
const url = process.argv.find((arg) => arg.startsWith('--url='))?.slice(6);
|
|
13
|
+
if (!url) throw new Error('usage: node scripts/test-template-gate.mjs --url=<built preview> [--out=<directory>]');
|
|
14
|
+
const out = resolve(process.argv.find((arg) => arg.startsWith('--out='))?.slice(6) ?? 'parity-out/template');
|
|
15
|
+
mkdirSync(out, { recursive: true });
|
|
16
|
+
const fixture = mkdtempSync(join(tmpdir(), 'template-gate-'));
|
|
17
|
+
mkdirSync(join(fixture, 'scripts'));
|
|
18
|
+
writeFileSync(join(fixture, 'scripts/physics-route.json'), JSON.stringify({ _template: [{ name: 'hut', gate: true,
|
|
19
|
+
start: { x: 0, y: 1, z: 0, yaw: 0 }, waypoints: [{ x: 0, z: -4 }, { x: 0, z: -7.5 }], timeout: 30 }] }));
|
|
20
|
+
// The scripted weapon is the Template's declared whip (SF16): a declared weapon's Weapon.id is its legacySlot,
|
|
21
|
+
// which game/server/shardfile/items.ts maps from the row's `slot`, so key on that, not the row id.
|
|
22
|
+
const items = object(JSON.parse(readFileSync(resolve(import.meta.dirname, '../src/shards/_template/data/items.json'), 'utf8')));
|
|
23
|
+
const whip = string(object(array(items.rows).find((row) => object(row).context === 'template.whip')).slot);
|
|
24
|
+
if (!whip) throw new Error('Template items declare no template.whip weapon row');
|
|
25
|
+
STEPS._template = [{ step: 'swing', weapon: whip, target: 'greyBlob', near: { x: 0, z: -19 }, distance: 3, hit: 5, kill: 20, settleFrames: 30 }];
|
|
26
|
+
const pool = browserPool(resolve(import.meta.dirname, '..'), 1, 'metal');
|
|
27
|
+
try {
|
|
28
|
+
const browser = await pool.browser(0); await assertMetal(browser, 'metal');
|
|
29
|
+
const result = object(await capture(browser, url, { shard: '_template', tier: 'phone', lane: 'gh-macos15', sha: '', root: fixture,
|
|
30
|
+
out, timeout: 240, full: false, only: 'walk+combat+leak', offline: false, accelerated: true, telemetryFixture: true }));
|
|
31
|
+
writeFileSync(join(out, 'gate.json'), JSON.stringify(result, null, 2));
|
|
32
|
+
assert.deepEqual(object(result.boot).errors, [], 'template boot');
|
|
33
|
+
const walk = object(result.walk); assert.equal(walk.stuck, 0, 'hut walk'); assert.equal(array(walk.legs).length, 1, 'hut route ran');
|
|
34
|
+
const touch = object(walk.touch);
|
|
35
|
+
assert.ok(typeof touch.moved === 'number' && touch.moved >= 2, 'touch stick moves the player');
|
|
36
|
+
assert.ok(typeof touch.yawDelta === 'number' && touch.yawDelta !== 0, 'touch look changes yaw');
|
|
37
|
+
assert.equal(touch.dodged, true, 'touch dodge'); assert.equal(touch.used, true, 'touch use');
|
|
38
|
+
assert.equal(object(object(result.combat).swing).killed, true, 'custom whip killed the blob');
|
|
39
|
+
const leak = object(result.leak); assert.deepEqual(leak.disposalErrors, [], 'scope disposal');
|
|
40
|
+
const before = flatten(leak.before), after = flatten(leak.after);
|
|
41
|
+
const changes = Object.keys(before).filter((key) => before[key] !== after[key]);
|
|
42
|
+
assert.deepEqual(changes, [], 'independent resource census returns to baseline');
|
|
43
|
+
console.log('Template phone: clean boot, hut walk, blob kill, unload census');
|
|
44
|
+
} finally { await pool.close(); rmSync(fixture, { recursive: true, force: true }); }
|