@wildshard/engine 0.1.23 → 0.1.24
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 +7 -0
- package/index.html +17 -4
- package/lint/engine-sides.json +7 -0
- package/package.json +29 -3
- package/scripts/app-build/titlePreloads.mjs +8 -5
- package/scripts/bake-road-surfaces.entry.ts +18 -0
- package/scripts/bake-road-surfaces.mjs +44 -0
- package/scripts/changelog.mjs +2 -1
- package/scripts/goldens/capture.mjs +18 -6
- package/scripts/goldens/native-residency.d.mts +1 -0
- package/scripts/goldens/native-residency.mjs +14 -1
- package/scripts/grid-road-lag.mjs +209 -0
- package/scripts/keep-copy.mjs +64 -12
- package/scripts/land.d.mts +4 -1
- package/scripts/land.mjs +85 -3
- package/scripts/loading-flow/benchmax.mjs +2 -0
- package/scripts/map-hash.mjs +1 -1
- package/scripts/nightly-tag.mjs +2 -4
- package/scripts/page-release/content.mjs +19 -10
- package/scripts/page-release/flow.d.mts +3 -2
- package/scripts/page-release/flow.mjs +31 -21
- package/scripts/page-release/packs.d.mts +5 -0
- package/scripts/page-release/packs.mjs +13 -3
- package/scripts/page-release/preview.d.mts +2 -0
- package/scripts/page-release/preview.mjs +74 -0
- package/scripts/page-release.mjs +13 -5
- package/scripts/road-drive-proof.mjs +269 -0
- package/scripts/road-memory-probe.mjs +129 -0
- package/scripts/scratch-dir.mjs +4 -4
- package/scripts/server-release/github.mjs +59 -26
- package/scripts/server-release/publish.mjs +15 -1
- package/scripts/server-release/sign.mjs +8 -4
- package/scripts/test_prebuilt_output.py +3 -1
- package/scripts/turn-in-shots.mjs +83 -0
- package/scripts/vitest-bench-observe-proof.py +168 -0
- package/scripts/vitest-bench.py +122 -77
- package/scripts/vps/rebuild.sh +3 -1
- package/scripts/worktree-reap.mjs +21 -9
- package/scripts/worktree.mjs +1 -1
- package/scripts/zone-gate-proof.mjs +93 -0
- package/src/client/engine/boot/sw.ts +3 -1
- package/src/client/engine/core/ktx2.ts +30 -9
- package/src/client/engine/models/place.ts +7 -5
- package/src/client/engine/pwa/sw.js +57 -2
- package/src/client/engine/render/precompile.ts +6 -0
- package/src/client/engine/render/tiers.ts +9 -0
- package/src/client/engine/ui/playerReload.ts +5 -5
- package/src/client/game/boot/bytes.generated.ts +4 -1
- package/src/client/game/boot/versions.generated.ts +8 -5
- package/src/client/game/grid/cellClip.ts +70 -6
- package/src/client/game/grid/gateCard.css +9 -0
- package/src/client/game/grid/gateCard.ts +67 -0
- package/src/client/game/grid/live.ts +17 -3
- package/src/client/game/grid/liveSession.ts +15 -5
- package/src/client/game/grid/neighbourLife.ts +10 -1
- package/src/client/game/grid/neighbourPanels.ts +29 -2
- package/src/client/game/grid/pageEntry.ts +21 -0
- package/src/client/game/grid/regionalWorld.ts +5 -0
- package/src/client/game/grid/roadCompressedSurfaces.ts +69 -0
- package/src/client/game/grid/roadLook.ts +5 -73
- package/src/client/game/grid/roadLookPlatform.ts +11 -6
- package/src/client/game/grid/roadSurfaceMaps.ts +80 -0
- package/src/client/game/grid/roadTilePool.ts +4 -0
- package/src/client/game/grid/session.ts +52 -12
- package/src/client/game/grid/softWallLook.ts +6 -1
- package/src/client/game/plugin/ui.ts +3 -0
- package/src/client/game/session/play.ts +3 -0
- package/src/client/game/shardfile/clientSource.ts +5 -2
- package/src/client/game/shardfile/clientWorker.ts +3 -2
- package/src/client/game/shardfile/slabLibrary.ts +37 -0
- package/src/client/game/shardfile/slabRanges.ts +145 -0
- package/src/client/host/online/shell.ts +2 -2
- package/src/client/host/standalone/shell.ts +4 -1
- package/src/server/game/grid/simulation.ts +27 -4
- package/src/server/game/plugin/simulation.ts +2 -0
- package/src/server/game/shardfile/dataRespawn.ts +47 -0
- package/src/server/host/standalone/cellWorld.ts +1 -1
- package/src/server/host/standalone/gridServer.ts +18 -6
- package/src/server/host/standalone/roadWorld.ts +30 -0
- package/src/server/host/standalone/serverHost.ts +2 -2
- package/src/shared/engine/entities/AnimalSim.ts +10 -0
- package/src/shared/engine/physics/transferWalls.ts +9 -4
- package/src/shared/game/grid/allocator.ts +8 -1
- package/src/shared/game/grid/gateCount.ts +27 -0
- package/src/shared/game/grid/zoneWalls.ts +64 -0
- package/src/shared/game/strings.ts +2 -0
- package/src/shared/host/standalone/harnessPlace.ts +4 -0
- package/src/test/engine/simState.ts +134 -0
- package/src/test/game/builtProduct.ts +6 -0
- package/src/test/game/headless/admittedProductCache.ts +61 -0
- package/src/test/game/headless/checkedReplayPipeline.ts +21 -0
- package/src/test/game/headless/nativeBounds.ts +27 -0
- package/src/test/game/headless/processUsage.ts +22 -0
- package/src/test/game/headless/productSession.ts +39 -0
- package/src/test/game/headless/ropeBodies.ts +60 -0
- package/src/test/game/headless/worker.ts +34 -0
- package/src/test/game/headlessNative.ts +114 -0
- package/src/test/game/headlessWorker.ts +43 -0
- package/src/test/tsconfig.game.json +3 -0
|
@@ -123,8 +123,17 @@ const mb = bytes => (bytes / 1e6).toFixed(1);
|
|
|
123
123
|
|
|
124
124
|
/** @template T @param {readonly T[]} items @param {number} width @param {(item: T) => Promise<void>} each */
|
|
125
125
|
async function pool(items, width, each) {
|
|
126
|
-
let next = 0;
|
|
127
|
-
|
|
126
|
+
let next = 0, failed = false;
|
|
127
|
+
/** @type {unknown} */ let failure;
|
|
128
|
+
await Promise.all(Array.from({length: Math.min(width, items.length)}, async () => {
|
|
129
|
+
while (!failed && next < items.length) {
|
|
130
|
+
const item = items[next++];
|
|
131
|
+
try { if (item !== undefined) await each(item); }
|
|
132
|
+
catch (error) { failed = true; failure = error; }
|
|
133
|
+
}
|
|
134
|
+
}));
|
|
135
|
+
// Drain every already-started request before a retry can create another pool.
|
|
136
|
+
if (failed) throw failure;
|
|
128
137
|
}
|
|
129
138
|
|
|
130
139
|
/** A key read back: 200, the game's CORS, the decoded bytes. A 404 right after upload is retried (the CDN caches 404s
|
|
@@ -170,7 +179,7 @@ export async function publishContent({dir, store, scratch, origin = GAME_ORIGIN,
|
|
|
170
179
|
let wrong = 0;
|
|
171
180
|
// A present key is held only when it reads back with this file's bytes and the game's CORS; anything else (a wrong or
|
|
172
181
|
// short object left by an earlier run, say) is uploaded again over it. Set keys are content-named, so that is safe.
|
|
173
|
-
await pool(files,
|
|
182
|
+
await pool(files, 8, async file => {
|
|
174
183
|
const key = contentKey(set, file.path);
|
|
175
184
|
if (!await store.exists(key)) { missing.push(file); return; }
|
|
176
185
|
const read = await store.read(key, origin);
|
|
@@ -196,7 +205,7 @@ export async function publishContent({dir, store, scratch, origin = GAME_ORIGIN,
|
|
|
196
205
|
} catch (error) {
|
|
197
206
|
if (round >= 6) throw error;
|
|
198
207
|
/** @type {ContentFile[]} */ const still = [];
|
|
199
|
-
await pool(left,
|
|
208
|
+
await pool(left, 8, async file => { if (!await store.exists(contentKey(set, file.path))) still.push(file); });
|
|
200
209
|
log(`content ${set}: put failed (${error instanceof Error ? error.message : String(error)}); ${still.length} still missing, retrying`);
|
|
201
210
|
left = still.sort((a, b) => (a.path < b.path ? -1 : 1));
|
|
202
211
|
// The API answers 429 under load (seen on the first real run): back off longer each round.
|
|
@@ -204,7 +213,7 @@ export async function publishContent({dir, store, scratch, origin = GAME_ORIGIN,
|
|
|
204
213
|
}
|
|
205
214
|
}
|
|
206
215
|
let read = 0;
|
|
207
|
-
await pool(missing,
|
|
216
|
+
await pool(missing, 4, async file => {
|
|
208
217
|
await readBack(store, contentKey(set, file.path), file.decoded, origin, sleep);
|
|
209
218
|
if (++read % 1000 === 0) log(`content ${set}: ${read}/${missing.length} read back`);
|
|
210
219
|
});
|
|
@@ -244,7 +253,7 @@ export async function copyFromSets({set, missing, store, origin, log, sleep}) {
|
|
|
244
253
|
}
|
|
245
254
|
/** @type {ContentFile[]} */ const copied = [];
|
|
246
255
|
let failed = 0;
|
|
247
|
-
await pool(missing.filter(file => held.has(`${file.sha256}:${file.bytes}`)),
|
|
256
|
+
await pool(missing.filter(file => held.has(`${file.sha256}:${file.bytes}`)), 8, async file => {
|
|
248
257
|
const from = held.get(`${file.sha256}:${file.bytes}`) ?? '';
|
|
249
258
|
try { await copy(from, contentKey(set, file.path), contentHeaders(file.path), file.bytes); copied.push(file); }
|
|
250
259
|
catch (error) { failed++; log(`content ${set}: copy ${from} failed (${error instanceof Error ? error.message : String(error)}); uploading it`); }
|
|
@@ -262,14 +271,14 @@ export async function copyFromSets({set, missing, store, origin, log, sleep}) {
|
|
|
262
271
|
* PZ6: R2's S3 API on the packs bucket, for the store's `sets` and `copy`. Credentials from the environment
|
|
263
272
|
* (R2_ACCOUNT_ID, R2_PACKS_ACCESS_KEY_ID, R2_PACKS_SECRET_ACCESS_KEY: server-release's bucket-scoped keys), else none.
|
|
264
273
|
* @param {NodeJS.ProcessEnv} env
|
|
265
|
-
* With them the store also puts through S3 (
|
|
274
|
+
* With them the store also puts through S3 (4 at a time), not `wrangler r2 bulk put`, so a CI token needs no R2 write.
|
|
266
275
|
* @returns {{sets: () => Promise<string[]>, copy: (from: string, to: string, headers: Headers, bytes: number) => Promise<void>, put: (puts: readonly Put[]) => Promise<void>, secrets: string[], close: () => void} | undefined}
|
|
267
276
|
*/
|
|
268
277
|
export function r2Copies(env) {
|
|
269
278
|
const account = env.R2_ACCOUNT_ID?.trim(), accessKeyId = env.R2_PACKS_ACCESS_KEY_ID?.trim(), secretAccessKey = env.R2_PACKS_SECRET_ACCESS_KEY?.trim();
|
|
270
279
|
if (account === undefined || accessKeyId === undefined || secretAccessKey === undefined || account === '' || accessKeyId === '' || secretAccessKey === '') return undefined;
|
|
271
280
|
if (!/^[0-9a-f]{32}$/u.test(account)) throw new Error('Invalid R2_ACCOUNT_ID');
|
|
272
|
-
const client = new S3Client({region: 'auto', endpoint: `https://${account}.r2.cloudflarestorage.com`, credentials: {accessKeyId, secretAccessKey}});
|
|
281
|
+
const client = new S3Client({region: 'auto', maxAttempts: 6, endpoint: `https://${account}.r2.cloudflarestorage.com`, credentials: {accessKeyId, secretAccessKey}});
|
|
273
282
|
return {
|
|
274
283
|
secrets: [accessKeyId, secretAccessKey],
|
|
275
284
|
close: () => client.destroy(),
|
|
@@ -293,7 +302,7 @@ export function r2Copies(env) {
|
|
|
293
302
|
return complete.sort((a, b) => b.at - a.at).map(row => row.set);
|
|
294
303
|
},
|
|
295
304
|
async put(puts) {
|
|
296
|
-
await pool(puts,
|
|
305
|
+
await pool(puts, 4, async item => {
|
|
297
306
|
await client.send(new PutObjectCommand({Bucket: BUCKET, Key: item.key, Body: readFileSync(item.file),
|
|
298
307
|
ContentType: item.headers.type, CacheControl: item.headers.cache, ...(item.headers.encoding === undefined ? {} : {ContentEncoding: item.headers.encoding})}));
|
|
299
308
|
});
|
|
@@ -366,7 +375,7 @@ export function r2Content({root, scratch, token, fetch: get = fetch, exec = runR
|
|
|
366
375
|
/** @type {Headers} */ const headers = JSON.parse(id);
|
|
367
376
|
const list = join(scratch, `bulk-${createHash('sha256').update(id).digest('hex').slice(0, 8)}.json`);
|
|
368
377
|
writeFileSync(list, JSON.stringify(items.map(item => ({key: item.key, file: item.file}))));
|
|
369
|
-
const args = ['r2', 'bulk', 'put', BUCKET, '--remote', '--filename', list, '--content-type', headers.type, '--cache-control', headers.cache, '--concurrency', '
|
|
378
|
+
const args = ['r2', 'bulk', 'put', BUCKET, '--remote', '--filename', list, '--content-type', headers.type, '--cache-control', headers.cache, '--concurrency', '2', '--force'];
|
|
370
379
|
if (headers.encoding !== undefined) args.push('--content-encoding', headers.encoding);
|
|
371
380
|
try {
|
|
372
381
|
exec(join(root, 'node_modules/.bin/wrangler'), args, {cwd: root, env: {...process.env, CLOUDFLARE_ACCOUNT_ID: CLOUDFLARE_ACCOUNT}, timeout: 3 * 60 * 60_000}, secrets);
|
|
@@ -2,7 +2,7 @@ export type WorldChannel = 'staging' | 'production';
|
|
|
2
2
|
export type Channel = WorldChannel | 'preview';
|
|
3
3
|
export type Phase = 'build' | 'upload' | 'check' | 'go-live';
|
|
4
4
|
export interface WorldChannelConfig { channel: WorldChannel; solo: false; other: WorldChannel; origin: string; release: string; socket: string; health: string }
|
|
5
|
-
export interface SoloChannelConfig { channel: 'preview'; solo: true; origin: string }
|
|
5
|
+
export interface SoloChannelConfig { channel: 'preview'; solo: true; origin: string; release: string }
|
|
6
6
|
export type ChannelConfig = WorldChannelConfig | SoloChannelConfig;
|
|
7
7
|
export interface Deployment { id: string; url: string }
|
|
8
8
|
export interface HostContext { root: string; channel: ChannelConfig; build: string; saveEpoch: number; version: string; deployment?: Deployment }
|
|
@@ -52,10 +52,11 @@ export interface Deps {
|
|
|
52
52
|
}
|
|
53
53
|
export const PACKS_ORIGIN: string;
|
|
54
54
|
export const RELEASE_PUBLIC_KEY: string;
|
|
55
|
+
export function pinnedReleaseKey(configured?: string): string;
|
|
55
56
|
export const PHASES: readonly Phase[];
|
|
56
57
|
export const CHECKED_DOCUMENTS: readonly ['version.json', 'index.html', 'sw.js', 'deploy-chunks.json'];
|
|
57
58
|
export const CHANNELS: { staging: WorldChannelConfig; production: WorldChannelConfig; preview: SoloChannelConfig };
|
|
58
59
|
export class RefusedError extends Error { constructor(message: string) }
|
|
59
60
|
export function runPhase(phase: Phase, deps: Deps): Promise<{ refusals: string[] }>;
|
|
60
61
|
export function buildEnv(channel: ChannelConfig, deps: Deps): Record<string, string>;
|
|
61
|
-
export function readGate(channel:
|
|
62
|
+
export function readGate(channel: ChannelConfig, deps: Deps): Promise<{ serial?: number; problem?: string }>;
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
// the producer's signed serial to name this build and the channel's /health to show that build and serial.
|
|
9
9
|
// go-live the alias move, LAST: refused without a fresh signed-release and /health match.
|
|
10
10
|
//
|
|
11
|
-
// Preview (the solo build of green main, J274
|
|
12
|
-
//
|
|
11
|
+
// Preview (the solo build of green main, J274) signs releases/preview.json as a deployment gate (PZ6 D2).
|
|
12
|
+
// Its document has no world stamp or release URL: the offline page still runs its server in a worker.
|
|
13
13
|
//
|
|
14
14
|
// The flow owns order and gates; the host (hosts/workers.mjs, page-release.mjs --host) owns how a
|
|
15
15
|
// page is packaged, uploaded, read back and aliased. Every dependency comes in through `deps`, so the tests drive a fake host.
|
|
@@ -30,13 +30,13 @@ export const CHECKED_DOCUMENTS = /** @type {const} */ (['version.json', 'index.h
|
|
|
30
30
|
/** @typedef {WorldChannel|'preview'} Channel */
|
|
31
31
|
/** @typedef {typeof PHASES[number]} Phase */
|
|
32
32
|
/** @typedef {{channel: WorldChannel, solo: false, other: WorldChannel, origin: string, release: string, socket: string, health: string}} WorldChannelConfig */
|
|
33
|
-
/** @typedef {{channel: 'preview', solo: true, origin: string}} SoloChannelConfig */
|
|
33
|
+
/** @typedef {{channel: 'preview', solo: true, origin: string, release: string}} SoloChannelConfig */
|
|
34
34
|
/** @typedef {WorldChannelConfig|SoloChannelConfig} ChannelConfig */
|
|
35
35
|
|
|
36
36
|
/** @type {{staging: WorldChannelConfig, production: WorldChannelConfig, preview: SoloChannelConfig}} */
|
|
37
37
|
export const CHANNELS = {
|
|
38
38
|
// SHELL-CUTOVER SC1: the solo build of the newest green main, no world stamp, so the in-page server runs.
|
|
39
|
-
preview: {channel: 'preview', solo: true, origin: 'https://preview.wildshard.io'},
|
|
39
|
+
preview: {channel: 'preview', solo: true, origin: 'https://preview.wildshard.io', release: `${PACKS_ORIGIN}/releases/preview.json`},
|
|
40
40
|
staging: {
|
|
41
41
|
channel: 'staging', solo: false, other: 'production', origin: 'https://staging.wildshard.io',
|
|
42
42
|
release: `${PACKS_ORIGIN}/releases/staging.json`, socket: 'wss://rooms-staging.wildshard.io',
|
|
@@ -55,6 +55,14 @@ export class RefusedError extends Error {
|
|
|
55
55
|
constructor(message) { super(message); this.name = 'RefusedError'; }
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
/** Configuration may confirm the reviewed trust root, never replace it.
|
|
59
|
+
* @param {string|undefined} configured @returns {string} */
|
|
60
|
+
export function pinnedReleaseKey(configured) {
|
|
61
|
+
const value = configured?.trim();
|
|
62
|
+
if (value !== undefined && value !== '' && value !== RELEASE_PUBLIC_KEY) throw new RefusedError('E7_RELEASE_PUBLIC_KEY differs from the pinned release key');
|
|
63
|
+
return RELEASE_PUBLIC_KEY;
|
|
64
|
+
}
|
|
65
|
+
|
|
58
66
|
/**
|
|
59
67
|
* @typedef {{id: string, url: string}} Deployment
|
|
60
68
|
* @typedef {{algorithm: 'sha1'|'sha256', digest: string}} Digest
|
|
@@ -221,19 +229,17 @@ export async function runPhase(phase, deps) {
|
|
|
221
229
|
for (const line of deps.host.describe('deployedDigests', deployed)) plan(line);
|
|
222
230
|
if (!dry) await checkDeployed(deps, deployed, refuse);
|
|
223
231
|
if (channel.solo) {
|
|
224
|
-
|
|
225
|
-
if (dry)
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
232
|
+
plan(`sign ${channel.release} after the page and its content are uploaded (no socket or server bundle)`);
|
|
233
|
+
if (!dry) deps.run('node', ['--import', './scripts/bake-loader.mjs', 'scripts/page-release/preview.mjs', `--build=${deps.build}`], {});
|
|
234
|
+
} else {
|
|
235
|
+
plan(`verify the server book and parts on ${PACKS_ORIGIN} answer with CORS ${channel.origin}`);
|
|
236
|
+
if (!dry) await deps.packs.verify({root: deps.root, build: deps.build, cors: channel.origin});
|
|
229
237
|
}
|
|
230
|
-
plan(`
|
|
231
|
-
if (!dry) await deps.packs.verify({root: deps.root, build: deps.build, cors: channel.origin});
|
|
232
|
-
plan(`wait for ${channel.release} to sign ${deps.build} and ${channel.health} to match its serial`);
|
|
238
|
+
plan(`wait for ${channel.release} to sign ${deps.build}${channel.solo ? ' (solo deployment gate)' : ` and ${channel.health} to match its serial`}`);
|
|
233
239
|
const gate = await waitForGate(channel, deps, refuse);
|
|
234
240
|
if (dry) return {refusals};
|
|
235
241
|
deps.state.write('check', {build: deps.build, channel: channel.channel, deployment, serial: gate.serial});
|
|
236
|
-
deps.log(`PASS ${channel.channel} check ${deployment.id}: deployed bytes equal,
|
|
242
|
+
deps.log(`PASS ${channel.channel} check ${deployment.id}: deployed bytes equal, serial ${gate.serial} signed${channel.solo ? ', solo deployment gate' : ', packs public and healthy'}; alias not moved`);
|
|
237
243
|
return {refusals};
|
|
238
244
|
}
|
|
239
245
|
|
|
@@ -244,8 +250,8 @@ export async function runPhase(phase, deps) {
|
|
|
244
250
|
if (!dry) await checkDeployed(deps, deployed, refuse);
|
|
245
251
|
/** @type {{serial?: number, problem?: string}} */
|
|
246
252
|
let gate = {};
|
|
247
|
-
|
|
248
|
-
plan(`re-read ${channel.release} and ${channel.health}:
|
|
253
|
+
{
|
|
254
|
+
plan(`re-read ${channel.release}${channel.solo ? '' : ` and ${channel.health}`}: must name ${deps.build} and one serial`);
|
|
249
255
|
gate = await readGate(channel, deps);
|
|
250
256
|
if (gate.problem !== undefined) refuse(gate.problem);
|
|
251
257
|
else if (checked !== undefined && gate.serial !== checked.serial) deps.log(`note: serial moved ${checked.serial} -> ${gate.serial} since check, still ${deps.build}`);
|
|
@@ -256,7 +262,7 @@ export async function runPhase(phase, deps) {
|
|
|
256
262
|
deps.log(`ALIAS MOVED ${channel.origin} -> ${deployment.id}; checking the domain`);
|
|
257
263
|
await waitForDomain(channel, deps, refuse);
|
|
258
264
|
deps.state.write('go-live', {build: deps.build, channel: channel.channel, deployment, ...(gate.serial === undefined ? {} : {serial: gate.serial})});
|
|
259
|
-
deps.log(`PASS ${channel.origin} -> ${deps.build} ${deployment.id} ${channel.solo ? 'solo
|
|
265
|
+
deps.log(`PASS ${channel.origin} -> ${deps.build} ${deployment.id} after matching serial ${gate.serial}${channel.solo ? ' (solo)' : ''} (alias last)`);
|
|
260
266
|
deps.log(channel.solo ? `next: node scripts/e7-doctor-proof.mjs ${channel.origin} ${deps.build} --human-static`
|
|
261
267
|
: channel.channel === 'staging'
|
|
262
268
|
? `next: strict staging proofs, then production. node scripts/e7-doctor-proof.mjs ${channel.origin} ${deps.build} ${RELEASE_PUBLIC_KEY}; node scripts/e7-live-staging-proof.mjs ${channel.origin} ${deps.build} ${RELEASE_PUBLIC_KEY} chromium|webkit`
|
|
@@ -271,7 +277,7 @@ export function buildEnv(channel, deps) {
|
|
|
271
277
|
WS_BUILD_ID: deps.build, WILDSHARD_CATALOGUE: (channel.solo ? deps.catalogue : undefined) ?? 'test/pins/catalogue.json',
|
|
272
278
|
WS_PREVIOUS_DEPLOY_ORIGIN: channel.origin, WS_RELEASE: '1', WS_CHANNEL: channel.channel,
|
|
273
279
|
// API-CLOUDFLARE AC11: errors, telemetry and the inbox go to the api-server Worker on every channel.
|
|
274
|
-
VITE_API_ORIGIN: API_ORIGIN,
|
|
280
|
+
VITE_API_ORIGIN: API_ORIGIN, WILDSHARD_RELEASE_KEY: deps.releaseKey ?? RELEASE_PUBLIC_KEY,
|
|
275
281
|
};
|
|
276
282
|
// Preview is the solo game: no release file, so the build stamps no world (app-build-pipeline.mjs E7.2d).
|
|
277
283
|
return channel.solo ? common
|
|
@@ -340,8 +346,8 @@ async function productionGates(phase, deps, refuse) {
|
|
|
340
346
|
}
|
|
341
347
|
|
|
342
348
|
/**
|
|
343
|
-
* The signed
|
|
344
|
-
* @param {
|
|
349
|
+
* The signed file names this build. Online channels also require matching /health; preview forbids a socket.
|
|
350
|
+
* @param {ChannelConfig} channel @param {Deps} deps
|
|
345
351
|
* @returns {Promise<{serial?: number, problem?: string}>}
|
|
346
352
|
*/
|
|
347
353
|
export async function readGate(channel, deps) {
|
|
@@ -354,10 +360,14 @@ export async function readGate(channel, deps) {
|
|
|
354
360
|
createPublicKey({key: Buffer.from(deps.releaseKey ?? RELEASE_PUBLIC_KEY, 'hex'), format: 'der', type: 'spki'}), Buffer.from(signed.signature, 'hex'));
|
|
355
361
|
} catch { valid = false; }
|
|
356
362
|
if (!valid) return {problem: `${channel.release} signature does not verify`};
|
|
357
|
-
|
|
363
|
+
let release;
|
|
364
|
+
try { release = JSON.parse(signed.body); } catch { return {problem: `${channel.release} body is not JSON`}; }
|
|
365
|
+
if (release === null || typeof release !== 'object' || !Number.isSafeInteger(release.serial) || release.serial < 1) return {problem: `${channel.release} has an invalid serial`};
|
|
358
366
|
if (release.channel !== channel.channel) return {problem: `${channel.release} is channel ${release.channel}`};
|
|
359
367
|
if (release.engineBuild !== deps.build) return {problem: `${channel.release} serial ${release.serial} signs ${release.engineBuild}, not ${deps.build}`};
|
|
360
368
|
if (release.saveEpoch !== deps.manifest.saveEpoch) return {problem: `${channel.release} save epoch ${release.saveEpoch} is not ${deps.manifest.saveEpoch}`};
|
|
369
|
+
if (channel.solo) return release.socket === undefined && release.bundle === undefined
|
|
370
|
+
? {serial: release.serial} : {problem: `${channel.release} must be solo (no socket or server bundle)`};
|
|
361
371
|
if (String(release.socket).replace(/\/$/u, '') !== channel.socket) return {problem: `${channel.release} socket ${release.socket} is not ${channel.socket}`};
|
|
362
372
|
/** @type {any} */
|
|
363
373
|
let health;
|
|
@@ -366,7 +376,7 @@ export async function readGate(channel, deps) {
|
|
|
366
376
|
return {serial: release.serial};
|
|
367
377
|
}
|
|
368
378
|
|
|
369
|
-
/** @param {
|
|
379
|
+
/** @param {ChannelConfig} channel @param {Deps} deps @param {(message: string) => void} refuse */
|
|
370
380
|
async function waitForGate(channel, deps, refuse) {
|
|
371
381
|
const deadline = deps.now() + (deps.dryRun ? 0 : deps.waitMs ?? 45 * 60_000);
|
|
372
382
|
for (let last = '';;) {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type {execFileSync} from 'node:child_process';
|
|
2
|
+
import type {PackStore} from './flow.mjs';
|
|
3
|
+
|
|
4
|
+
export function serverPackOutputRoot(root: string, bookPath: string): string;
|
|
5
|
+
export function r2Packs(options: {log: (line: string) => void; exec?: typeof execFileSync; fetch?: typeof fetch; sleep?: (ms: number) => Promise<void>}): PackStore;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import {execFileSync} from 'node:child_process';
|
|
8
8
|
import {setTimeout as delay} from 'node:timers/promises';
|
|
9
9
|
import {createHash} from 'node:crypto';
|
|
10
|
-
import {readFileSync} from 'node:fs';
|
|
10
|
+
import {existsSync, readFileSync} from 'node:fs';
|
|
11
11
|
import {join, resolve} from 'node:path';
|
|
12
12
|
import {pathToFileURL} from 'node:url';
|
|
13
13
|
import {brotliDecompressSync} from 'node:zlib';
|
|
@@ -17,6 +17,16 @@ export const BUCKET = 'wildshard-packs';
|
|
|
17
17
|
export const CLOUDFLARE_ACCOUNT = '0a870ffdd1b0bca67f7fedad77f67957';
|
|
18
18
|
const sha256 = (/** @type {Uint8Array} */ bytes) => createHash('sha256').update(bytes).digest('hex');
|
|
19
19
|
|
|
20
|
+
/** Server books/parts move together into dist-content/ on a split page release.
|
|
21
|
+
* @param {string} root @param {string} bookPath */
|
|
22
|
+
export function serverPackOutputRoot(root, bookPath) {
|
|
23
|
+
for (const name of ['dist', 'dist-content']) {
|
|
24
|
+
const dir = join(root, name);
|
|
25
|
+
if (existsSync(join(dir, bookPath))) return dir;
|
|
26
|
+
}
|
|
27
|
+
throw new Error(`Server book ${bookPath} is missing from dist/ and dist-content/`);
|
|
28
|
+
}
|
|
29
|
+
|
|
20
30
|
/**
|
|
21
31
|
* @param {{log: (line: string) => void, exec?: typeof execFileSync, fetch?: typeof fetch, sleep?: (ms: number) => Promise<void>}} options
|
|
22
32
|
* @returns {import('./flow.mjs').PackStore}
|
|
@@ -54,9 +64,9 @@ export function r2Packs({log, exec = execFileSync, fetch: get = fetch, sleep = d
|
|
|
54
64
|
}
|
|
55
65
|
/** @param {{root: string, build: string}} context */
|
|
56
66
|
async function load({root, build}) {
|
|
57
|
-
const dist = join(root, 'dist');
|
|
58
67
|
const {readServerPackBook, serverPackBookPath} = await import(pathToFileURL(join(root, 'src/shared/game/shardfile/serverPack.ts')).href);
|
|
59
|
-
const bookPath = serverPackBookPath(build),
|
|
68
|
+
const bookPath = serverPackBookPath(build), dist = serverPackOutputRoot(root, bookPath);
|
|
69
|
+
const bookBytes = readFileSync(join(dist, bookPath)), book = readServerPackBook(JSON.parse(bookBytes.toString('utf8')));
|
|
60
70
|
if (book.build !== build) throw new Error(`${bookPath} names ${book.build}`);
|
|
61
71
|
/** @type {Map<string, {url: string, bytes: number, hash: string, wireBytes: number, files: readonly (readonly [string, number, number])[]}>} */
|
|
62
72
|
const parts = new Map();
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// PZ6 D2: a deployment-only signed preview release. The solo page never reads it.
|
|
2
|
+
import {execFileSync, spawnSync} from 'node:child_process';
|
|
3
|
+
import {readFileSync} from 'node:fs';
|
|
4
|
+
import {parseArgs} from 'node:util';
|
|
5
|
+
import {resolve} from 'node:path';
|
|
6
|
+
import * as v from 'valibot';
|
|
7
|
+
import {HeadObjectCommand, S3Client} from '@aws-sdk/client-s3';
|
|
8
|
+
import {publishChannel} from '../server-release/publish.mjs';
|
|
9
|
+
import {COMMIT, releaseShards} from '../server-release/sign.mjs';
|
|
10
|
+
import {pinnedReleaseKey} from './flow.mjs';
|
|
11
|
+
|
|
12
|
+
const UploadState = v.object({
|
|
13
|
+
build: v.object({build: v.string(), contentBase: v.optional(v.string())}),
|
|
14
|
+
upload: v.object({build: v.string(), channel: v.literal('preview'),
|
|
15
|
+
deployment: v.object({id: v.pipe(v.string(), v.minLength(1))}), content: v.optional(v.object({base: v.string()}))}),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
/** Validate the completed page upload before granting the signer any work.
|
|
19
|
+
* @param {unknown} state @param {string} build @param {boolean} onMain @returns {string|undefined} */
|
|
20
|
+
export function previewUpload(state, build, onMain) {
|
|
21
|
+
if (!COMMIT.test(build) || !onMain) throw new Error('Preview build must be a full commit on origin/main');
|
|
22
|
+
const row = v.parse(UploadState, state);
|
|
23
|
+
if (row.build.build !== build || row.upload.build !== build) throw new Error('Preview must upload this page before signing');
|
|
24
|
+
const base = row.build.contentBase;
|
|
25
|
+
if (base !== undefined && (!/^https:\/\/packs\.wildshard\.io\/content\/[0-9a-f]{16}\/$/u.test(base)
|
|
26
|
+
|| row.upload.content?.base !== base)) throw new Error('Preview content upload does not match the built page');
|
|
27
|
+
return base;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function main() {
|
|
31
|
+
const {values} = parseArgs({options: {build: {type: 'string'}}});
|
|
32
|
+
const build = values.build;
|
|
33
|
+
if (build === undefined || !COMMIT.test(build)) throw new Error('Preview needs --build=<full SHA>');
|
|
34
|
+
if (execFileSync('git', ['rev-parse', 'HEAD'], {encoding: 'utf8'}).trim() !== build) throw new Error('Preview build must be HEAD');
|
|
35
|
+
const onMain = spawnSync('git', ['merge-base', '--is-ancestor', build, 'origin/main'], {stdio: 'ignore'}).status === 0;
|
|
36
|
+
const base = previewUpload(JSON.parse(readFileSync(`tmp/page-release/preview-${build}.json`, 'utf8')), build, onMain);
|
|
37
|
+
const need = (/** @type {string} */ name) => {
|
|
38
|
+
const value = process.env[name]?.trim();
|
|
39
|
+
if (value === undefined || value === '') throw new Error(`Missing ${name}`);
|
|
40
|
+
return value;
|
|
41
|
+
};
|
|
42
|
+
const account = need('R2_ACCOUNT_ID');
|
|
43
|
+
if (!/^[0-9a-f]{32}$/u.test(account)) throw new Error('Invalid R2_ACCOUNT_ID');
|
|
44
|
+
const privateKey = need('E7_RELEASE_SIGNING_KEY');
|
|
45
|
+
const publicKey = pinnedReleaseKey(process.env.E7_RELEASE_PUBLIC_KEY);
|
|
46
|
+
const client = new S3Client({region: 'auto', endpoint: `https://${account}.r2.cloudflarestorage.com`,
|
|
47
|
+
credentials: {accessKeyId: need('R2_PACKS_ACCESS_KEY_ID'), secretAccessKey: need('R2_PACKS_SECRET_ACCESS_KEY')}});
|
|
48
|
+
const pins = JSON.parse(readFileSync('test/pins/shardfiles.json', 'utf8'));
|
|
49
|
+
try {
|
|
50
|
+
const result = await publishChannel({client, bucket: 'wildshard-packs', privateKey, publicKey,
|
|
51
|
+
candidate: {channel: 'preview', serial: 1, engineBuild: build,
|
|
52
|
+
saveEpoch: JSON.parse(readFileSync('save-epoch.json', 'utf8')).saveEpoch,
|
|
53
|
+
shards: releaseShards(pins, pins.shards.map((/** @type {{slug: string}} */ row) => row.slug).join(','))},
|
|
54
|
+
isAncestor: (older, newer) => {
|
|
55
|
+
const check = spawnSync('git', ['merge-base', '--is-ancestor', older, newer], {stdio: 'ignore'});
|
|
56
|
+
if (check.status !== 0 && check.status !== 1) throw new Error('Cannot read preview commit history');
|
|
57
|
+
return check.status === 0;
|
|
58
|
+
},
|
|
59
|
+
packsReady: async () => {
|
|
60
|
+
// The index is the publisher's completion marker, written after every content file is verified.
|
|
61
|
+
if (base !== undefined) await client.send(new HeadObjectCommand({Bucket: 'wildshard-packs', Key: `${new URL(base).pathname.slice(1)}content.json`}));
|
|
62
|
+
return null;
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
if (!['published', 'unchanged'].includes(result.status) || result.release.engineBuild !== build) throw new Error('Preview publication is stale; alias stays unchanged');
|
|
66
|
+
console.log(`preview ${result.status}: ${build} signed at serial ${result.release.serial}, no socket`);
|
|
67
|
+
} finally { client.destroy(); }
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (process.argv[1] !== undefined && resolve(process.argv[1]) === import.meta.filename) {
|
|
72
|
+
try { await main(); }
|
|
73
|
+
catch (error) { console.error(error instanceof Error ? error.message : 'Preview publication failed'); process.exitCode = 1; }
|
|
74
|
+
}
|
package/scripts/page-release.mjs
CHANGED
|
@@ -27,11 +27,15 @@ import {execFileSync} from 'node:child_process';
|
|
|
27
27
|
import {setTimeout as delay} from 'node:timers/promises';
|
|
28
28
|
import {existsSync, mkdirSync, readFileSync, writeFileSync} from 'node:fs';
|
|
29
29
|
import {join, resolve} from 'node:path';
|
|
30
|
-
import {CHANNELS, RefusedError, buildEnv, runPhase} from './page-release/flow.mjs';
|
|
30
|
+
import {CHANNELS, pinnedReleaseKey, RefusedError, buildEnv, runPhase} from './page-release/flow.mjs';
|
|
31
31
|
import {workersHost} from './page-release/hosts/workers.mjs';
|
|
32
32
|
import {r2Packs} from './page-release/packs.mjs';
|
|
33
33
|
import {publishContent, r2Content, r2Copies} from './page-release/content.mjs';
|
|
34
34
|
|
|
35
|
+
// The world-signing key reaches only the deployment publisher, never build tools or the host.
|
|
36
|
+
const signingKey = process.env.E7_RELEASE_SIGNING_KEY;
|
|
37
|
+
delete process.env.E7_RELEASE_SIGNING_KEY;
|
|
38
|
+
const releaseKey = pinnedReleaseKey(process.env.E7_RELEASE_PUBLIC_KEY);
|
|
35
39
|
const args = process.argv.slice(2);
|
|
36
40
|
const flag = (/** @type {string} */ name) => args.find(arg => arg === `--${name}` || arg.startsWith(`--${name}=`));
|
|
37
41
|
const value = (/** @type {string} */ name) => flag(name)?.split('=').slice(1).join('=');
|
|
@@ -47,7 +51,7 @@ if (flag('print-env') !== undefined) {
|
|
|
47
51
|
}
|
|
48
52
|
const cwd = resolve(value('root') ?? '.');
|
|
49
53
|
const head = execFileSync('git', ['rev-parse', 'HEAD'], {cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe']}).trim();
|
|
50
|
-
const env = buildEnv(config, /** @type {any} */ ({build: head, ...(catalogue === undefined ? {} : {catalogue: resolve(catalogue)})}));
|
|
54
|
+
const env = buildEnv(config, /** @type {any} */ ({build: head, releaseKey, ...(catalogue === undefined ? {} : {catalogue: resolve(catalogue)})}));
|
|
51
55
|
for (const name of Object.keys(env).sort()) console.log(`${name}=${env[name]}`);
|
|
52
56
|
process.exit(0);
|
|
53
57
|
}
|
|
@@ -59,7 +63,7 @@ const git = (/** @type {string[]} */ argv, /** @type {string} */ cwd) => execFil
|
|
|
59
63
|
const root = resolve(value('root') ?? git(['rev-parse', '--show-toplevel'], process.cwd()));
|
|
60
64
|
const build = git(['rev-parse', 'HEAD'], root);
|
|
61
65
|
/** @type {string[]} */
|
|
62
|
-
const secrets = [];
|
|
66
|
+
const secrets = signingKey === undefined || signingKey === '' ? [] : [signingKey];
|
|
63
67
|
/** Cloudflare's token comes only from CLOUDFLARE_API_TOKEN (else wrangler's login). */
|
|
64
68
|
const cloudflareToken = process.env.CLOUDFLARE_API_TOKEN;
|
|
65
69
|
if (cloudflareToken !== undefined && cloudflareToken !== '') secrets.push(cloudflareToken);
|
|
@@ -83,13 +87,17 @@ let phase = '';
|
|
|
83
87
|
try {
|
|
84
88
|
for (phase of phaseList.split(',')) {
|
|
85
89
|
const {refusals} = await runPhase(/** @type {any} */ (phase), {
|
|
86
|
-
root, channel: /** @type {any} */ (channel), build, host,
|
|
90
|
+
root, channel: /** @type {any} */ (channel), build, host, releaseKey,
|
|
87
91
|
packs: r2Packs({log}),
|
|
88
92
|
...(flag('content') === undefined ? {} : {content: {
|
|
89
93
|
publish: ({dir, cors, dryRun}) => publishContent({dir, origin: cors, dryRun, log,
|
|
90
94
|
scratch: join(root, 'tmp/page-release/content'), store: r2Content({root, scratch: join(root, 'tmp/page-release/content'), token: cloudflareToken, copies: contentCopies})}),
|
|
91
95
|
}}),
|
|
92
|
-
run: (file, argv, env) => {
|
|
96
|
+
run: (file, argv, env) => {
|
|
97
|
+
const signing = file === 'node' && argv[2] === 'scripts/page-release/preview.mjs' && signingKey !== undefined
|
|
98
|
+
? {E7_RELEASE_SIGNING_KEY: signingKey} : {};
|
|
99
|
+
execFileSync(file, argv, {cwd: root, env: {...process.env, ...env, ...signing}, stdio: 'inherit'});
|
|
100
|
+
},
|
|
93
101
|
fetchJSON: async url => (await fetch200(url)).json(),
|
|
94
102
|
fetchText: async url => (await fetch200(url)).text(),
|
|
95
103
|
readFile: path => readFileSync(path),
|