@wildshard/engine 0.1.22 → 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.
Files changed (179) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/index.html +17 -4
  3. package/lint/engine-sides.json +9 -0
  4. package/lint/sim-players.json +2 -13
  5. package/package.json +36 -3
  6. package/scripts/apfs-clone.mjs +5 -2
  7. package/scripts/app-build/catalogue.ts +39 -8
  8. package/scripts/app-build/serviceWorker.ts +4 -1
  9. package/scripts/app-build/splitOutput.mjs +33 -11
  10. package/scripts/app-build/titlePreloads.mjs +8 -5
  11. package/scripts/bake-road-surfaces.entry.ts +18 -0
  12. package/scripts/bake-road-surfaces.mjs +44 -0
  13. package/scripts/changelog.mjs +2 -1
  14. package/scripts/ci-pack.mjs +3 -3
  15. package/scripts/engine-ci-shard.mjs +11 -0
  16. package/scripts/fight-page-census.mjs +131 -0
  17. package/scripts/goldens/board.py +44 -11
  18. package/scripts/goldens/capture.mjs +18 -6
  19. package/scripts/goldens/native-residency.d.mts +2 -0
  20. package/scripts/goldens/native-residency.mjs +31 -4
  21. package/scripts/grid-road-lag.mjs +209 -0
  22. package/scripts/keep-copy.mjs +172 -0
  23. package/scripts/land.d.mts +4 -1
  24. package/scripts/land.mjs +121 -9
  25. package/scripts/lane-live.mjs +136 -0
  26. package/scripts/leftovers-report.mjs +47 -0
  27. package/scripts/loading-card-proof.mjs +42 -9
  28. package/scripts/loading-flow/benchmax.mjs +59 -7
  29. package/scripts/loading-flow/stalls.d.mts +2 -0
  30. package/scripts/loading-flow/stalls.mjs +13 -0
  31. package/scripts/map-hash.mjs +1 -1
  32. package/scripts/mmo-bots.mjs +5 -3
  33. package/scripts/mmo-grid-proof.mjs +74 -0
  34. package/scripts/mmo-seat-proof.mjs +43 -0
  35. package/scripts/nightly-heads.ts +13 -13
  36. package/scripts/nightly-model.ts +26 -12
  37. package/scripts/nightly-tag.mjs +2 -4
  38. package/scripts/nightly.proof.ts +18 -5
  39. package/scripts/nightly.ts +13 -8
  40. package/scripts/no-astc-boot.mjs +77 -0
  41. package/scripts/page-release/content.mjs +19 -10
  42. package/scripts/page-release/flow.d.mts +3 -2
  43. package/scripts/page-release/flow.mjs +31 -21
  44. package/scripts/page-release/packs.d.mts +5 -0
  45. package/scripts/page-release/packs.mjs +13 -3
  46. package/scripts/page-release/preview.d.mts +2 -0
  47. package/scripts/page-release/preview.mjs +74 -0
  48. package/scripts/page-release.mjs +13 -5
  49. package/scripts/physics-route.json +6 -6
  50. package/scripts/pins-reuse.mjs +1 -0
  51. package/scripts/pins-staging.ts +54 -0
  52. package/scripts/pins.ts +5 -0
  53. package/scripts/ring3.proof.ts +71 -0
  54. package/scripts/ring3.ts +100 -0
  55. package/scripts/road-drive-proof.mjs +269 -0
  56. package/scripts/road-memory-probe.mjs +129 -0
  57. package/scripts/scratch-dir.mjs +33 -14
  58. package/scripts/scratch-sweep.mjs +15 -23
  59. package/scripts/server-release/github.mjs +59 -26
  60. package/scripts/server-release/items.d.mts +7 -0
  61. package/scripts/server-release/items.mjs +28 -0
  62. package/scripts/server-release/publish.mjs +24 -2
  63. package/scripts/server-release/sign.mjs +8 -4
  64. package/scripts/side-parity.mjs +1 -1
  65. package/scripts/test-products.json +1 -0
  66. package/scripts/test_prebuilt_output.py +3 -1
  67. package/scripts/tsconfig.json +2 -0
  68. package/scripts/turn-in-shots.mjs +83 -0
  69. package/scripts/vitest-bench-observe-proof.py +168 -0
  70. package/scripts/vitest-bench.py +122 -77
  71. package/scripts/vitest-ci-files.ts +5 -1
  72. package/scripts/vps/rebuild.sh +3 -1
  73. package/scripts/vps/wildshard-config +106 -1
  74. package/scripts/warm-native-chrome.mjs +9 -3
  75. package/scripts/worker-client-fights.mjs +9 -3
  76. package/scripts/worktree-reap.mjs +36 -140
  77. package/scripts/worktree.mjs +92 -12
  78. package/scripts/zone-gate-proof.mjs +93 -0
  79. package/src/client/engine/audio/audioLog.ts +7 -2
  80. package/src/client/engine/boot/diagnostics.ts +69 -1
  81. package/src/client/engine/boot/sw.ts +3 -1
  82. package/src/client/engine/core/ktx2.ts +33 -10
  83. package/src/client/engine/core/ktx2Zstd.ts +2 -1
  84. package/src/client/engine/models/place.ts +7 -5
  85. package/src/client/engine/pwa/sw.js +83 -10
  86. package/src/client/engine/render/dataLook.ts +14 -7
  87. package/src/client/engine/render/lookLight.ts +64 -20
  88. package/src/client/engine/render/precompile.ts +6 -0
  89. package/src/client/engine/render/tiers.ts +9 -0
  90. package/src/client/engine/ui/Loading.ts +6 -8
  91. package/src/client/engine/ui/lookLightOption.ts +1 -1
  92. package/src/client/engine/ui/playerReload.ts +5 -5
  93. package/src/client/game/audio/cueDirector.ts +2 -1
  94. package/src/client/game/boot/bytes.generated.ts +4 -1
  95. package/src/client/game/boot/versions.generated.ts +8 -5
  96. package/src/client/game/boss/arenaRoom.ts +4 -3
  97. package/src/client/game/boss/roamingProjection.ts +1 -1
  98. package/src/client/game/devScene/hook.ts +1 -1
  99. package/src/client/game/devScene/liveLook.ts +1 -1
  100. package/src/client/game/grid/cellClip.ts +70 -6
  101. package/src/client/game/grid/dataCellKit.ts +9 -1
  102. package/src/client/game/grid/gateCard.css +9 -0
  103. package/src/client/game/grid/gateCard.ts +67 -0
  104. package/src/client/game/grid/live.ts +17 -3
  105. package/src/client/game/grid/liveSession.ts +15 -5
  106. package/src/client/game/grid/neighbourLife.ts +10 -1
  107. package/src/client/game/grid/neighbourPanels.ts +29 -2
  108. package/src/client/game/grid/pageEntry.ts +21 -0
  109. package/src/client/game/grid/products.ts +21 -7
  110. package/src/client/game/grid/regionalWorld.ts +5 -0
  111. package/src/client/game/grid/roadCompressedSurfaces.ts +69 -0
  112. package/src/client/game/grid/roadLook.ts +5 -73
  113. package/src/client/game/grid/roadLookPlatform.ts +11 -6
  114. package/src/client/game/grid/roadSurfaceMaps.ts +80 -0
  115. package/src/client/game/grid/roadTilePool.ts +4 -0
  116. package/src/client/game/grid/session.ts +58 -16
  117. package/src/client/game/grid/softWallLook.ts +6 -1
  118. package/src/client/game/plugin/ui.ts +3 -0
  119. package/src/client/game/population/signals.ts +1 -1
  120. package/src/client/game/quest/chapterDirector.ts +1 -0
  121. package/src/client/game/session/play.ts +3 -0
  122. package/src/client/game/shardfile/clientBossTelegraph.ts +4 -3
  123. package/src/client/game/shardfile/clientSource.ts +5 -2
  124. package/src/client/game/shardfile/clientWorker.ts +25 -8
  125. package/src/client/game/shardfile/look.ts +1 -1
  126. package/src/client/game/shardfile/runtimeProduct.ts +9 -5
  127. package/src/client/game/shardfile/slabLibrary.ts +37 -0
  128. package/src/client/game/shardfile/slabRanges.ts +145 -0
  129. package/src/client/game/shardfile/wirePage.ts +5 -2
  130. package/src/client/game/shardfile/worldSceneTextures.ts +15 -9
  131. package/src/client/host/online/shell.ts +2 -2
  132. package/src/client/host/standalone/shell.ts +4 -1
  133. package/src/cook/game/cookWorker.ts +8 -5
  134. package/src/cook/game/tierTextures.ts +5 -3
  135. package/src/server/engine/net/simWorld.ts +3 -4
  136. package/src/server/game/grid/cellHome.ts +58 -0
  137. package/src/server/game/grid/simulation.ts +32 -8
  138. package/src/server/game/plugin/mover.ts +18 -14
  139. package/src/server/game/plugin/simulation.ts +2 -0
  140. package/src/server/game/shardfile/dataRespawn.ts +47 -0
  141. package/src/server/game/shardfile/declaredKitItems.ts +31 -7
  142. package/src/server/host/bake/headlessWorker.ts +3 -3
  143. package/src/server/host/dedicated/cellWorker.ts +4 -2
  144. package/src/server/host/dedicated/main.ts +7 -4
  145. package/src/server/host/dedicated/packReader.ts +15 -2
  146. package/src/server/host/dedicated/playerStore.ts +1 -1
  147. package/src/server/host/headlessRuntime.ts +11 -6
  148. package/src/server/host/standalone/cellWorld.ts +20 -6
  149. package/src/server/host/standalone/gridServer.ts +20 -6
  150. package/src/server/host/standalone/roadWorld.ts +36 -0
  151. package/src/server/host/standalone/serverHost.ts +2 -2
  152. package/src/shared/engine/entities/AnimalSim.ts +10 -0
  153. package/src/shared/engine/physics/gridBorders.ts +15 -1
  154. package/src/shared/engine/physics/transferWalls.ts +9 -4
  155. package/src/shared/engine/sim/snapshot.ts +5 -5
  156. package/src/shared/game/grid/allocator.ts +8 -1
  157. package/src/shared/game/grid/gateCount.ts +27 -0
  158. package/src/shared/game/grid/zoneWalls.ts +64 -0
  159. package/src/shared/game/ledger.ts +13 -4
  160. package/src/shared/game/loot/platformCatalogue.ts +14 -0
  161. package/src/shared/game/quest/ledger.ts +3 -3
  162. package/src/shared/game/shardfile/items.ts +9 -1
  163. package/src/shared/game/strings.ts +2 -0
  164. package/src/shared/host/headlessJourney.ts +3 -3
  165. package/src/shared/host/headlessTape.ts +7 -6
  166. package/src/shared/host/releaseRows.ts +4 -1
  167. package/src/shared/host/standalone/harnessPlace.ts +4 -0
  168. package/src/test/engine/simState.ts +134 -0
  169. package/src/test/game/builtProduct.ts +6 -0
  170. package/src/test/game/headless/admittedProductCache.ts +61 -0
  171. package/src/test/game/headless/checkedReplayPipeline.ts +21 -0
  172. package/src/test/game/headless/nativeBounds.ts +27 -0
  173. package/src/test/game/headless/processUsage.ts +22 -0
  174. package/src/test/game/headless/productSession.ts +39 -0
  175. package/src/test/game/headless/ropeBodies.ts +60 -0
  176. package/src/test/game/headless/worker.ts +34 -0
  177. package/src/test/game/headlessNative.ts +114 -0
  178. package/src/test/game/headlessWorker.ts +43 -0
  179. package/src/test/tsconfig.game.json +3 -0
@@ -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) => { execFileSync(file, argv, {cwd: root, env: {...process.env, ...env}, stdio: 'inherit'}); },
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),
@@ -3093,10 +3093,10 @@
3093
3093
  }
3094
3094
  ],
3095
3095
  "timeout": 40,
3096
- "notes": "BRASSCAP ENG-3: from rev 2 the blender-template slug is Brasscap Mesa (rev 3 pinned, ENG-3b). Legs follow shardfile src/tools/brasscap/canyon.ts ROUTES; each ends at its camp's edge (the camp's tent stands on the route's end) and none crosses the gate, which is shut until the camps fall."
3096
+ "notes": "BRASSCAP ENG-3: from rev 2 the blender-template slug is Brasscap Mesa (rev 6 pinned). Legs follow shardfile src/tools/brasscap/canyon.ts ROUTES; each ends at its camp's edge (the camp's tent stands on the route's end) and none crosses the gate, which is shut until the camps fall."
3097
3097
  },
3098
3098
  {
3099
- "name": "canyon branch to the ledge stair",
3099
+ "name": "canyon branch to the ledge ladder",
3100
3100
  "start": {
3101
3101
  "x": -2,
3102
3102
  "z": -22,
@@ -3108,12 +3108,12 @@
3108
3108
  "z": -25.8
3109
3109
  },
3110
3110
  {
3111
- "x": 16.9,
3112
- "z": -25.8
3111
+ "x": 8.4,
3112
+ "z": -28.4
3113
3113
  }
3114
3114
  ],
3115
3115
  "timeout": 30,
3116
- "notes": "BRASSCAP ENG-3: from rev 2 the blender-template slug is Brasscap Mesa (rev 3 pinned, ENG-3b). Legs follow shardfile src/tools/brasscap/canyon.ts ROUTES; each ends at its camp's edge (the camp's tent stands on the route's end) and none crosses the gate, which is shut until the camps fall."
3116
+ "notes": "Rev 6 (shard-brasscap edbd9bb, TEMPLATE-E2E; camps as rev 5): camp 2's ledge is a 6.5 m block (x 10 to 26, z -43 to -25) reached by a ladder on its west face at (9.55, -28.4); the leg ends at the ladder's foot. BRASSCAP ENG-3: from rev 2 the blender-template slug is Brasscap Mesa (rev 6 pinned). Legs follow shardfile src/tools/brasscap/canyon.ts ROUTES; each ends at its camp's edge (the camp's tent stands on the route's end) and none crosses the gate, which is shut until the camps fall."
3117
3117
  },
3118
3118
  {
3119
3119
  "name": "side canyon into camp 3",
@@ -3145,7 +3145,7 @@
3145
3145
  }
3146
3146
  ],
3147
3147
  "timeout": 40,
3148
- "notes": "BRASSCAP ENG-3: from rev 2 the blender-template slug is Brasscap Mesa (rev 3 pinned, ENG-3b). Legs follow shardfile src/tools/brasscap/canyon.ts ROUTES; each ends at its camp's edge (the camp's tent stands on the route's end) and none crosses the gate, which is shut until the camps fall."
3148
+ "notes": "BRASSCAP ENG-3: from rev 2 the blender-template slug is Brasscap Mesa (rev 6 pinned). Legs follow shardfile src/tools/brasscap/canyon.ts ROUTES; each ends at its camp's edge (the camp's tent stands on the route's end) and none crosses the gate, which is shut until the camps fall."
3149
3149
  }
3150
3150
  ],
3151
3151
  "open-plot-frostline-peaks": [
@@ -48,6 +48,7 @@ export const KEY_EXEMPT=Object.freeze({
48
48
  'scripts/renderer-revision.mjs':'names a printed preparation label only (J262); no byte under out/',
49
49
  'src/shared/game/shardfile/ktx2Targets.ts':'hashed already: the validation revision in the key covers src/shared/game/shardfile (S11)',
50
50
  'scripts/pins-catalogue.ts':'refresh check only (DEL9): refuses before the pins are written; no byte under out/',
51
+ 'scripts/pins-staging.ts':'refresh/export only; selection materializes shardfiles.json already hashed in the key',
51
52
  'scripts/server-release/served-slug.mjs':'refresh check only (DEL9): names a slug\'s served folder for the catalogue compare',
52
53
  });
53
54
 
@@ -0,0 +1,54 @@
1
+ // Row 23: a reviewed staging snapshot, independent of production's live pointers.
2
+ import {createHash} from 'node:crypto';
3
+ import {mkdirSync, readFileSync, writeFileSync} from 'node:fs';
4
+ import {pathToFileURL} from 'node:url';
5
+ import {catalogueSlugs, documentSlugs, unlistedMessage, unlistedSlugs} from './pins-catalogue.ts';
6
+
7
+ interface Pin {slug: string; revision: number; hash: string; bytes: number}
8
+ interface Document {shards: Omit<Pin, 'bytes'>[]; missing: unknown[]; placements: {slug: string}[]; grid: {cells: {slug: string}[]}}
9
+ export interface StagingPins {version: 1; channel: 'staging'; api: string; catalogueHash: string; releaseHash: null; catalogue: Document; shards: Pin[]}
10
+ const file = 'test/pins/staging.json';
11
+ const json = (value: unknown): string => `${JSON.stringify(value, null, 2)}\n`;
12
+ const hash = (value: unknown): string => createHash('sha256').update(JSON.stringify(value)).digest('hex');
13
+
14
+ export function checkStaging(value: StagingPins): void {
15
+ if (value.version !== 1 || value.channel !== 'staging' || value.releaseHash !== null || value.catalogueHash !== hash(value.catalogue)) throw new Error('Invalid staging snapshot identity');
16
+ const {catalogue, shards} = value;
17
+ if (!Array.isArray(catalogue.missing) || catalogue.missing.length > 0 || !Array.isArray(shards) || shards.length === 0 || new Set(shards.map(row => row.slug)).size !== shards.length) throw new Error('Incomplete staging catalogue');
18
+ if (shards.some(row => !/^[a-z0-9-]+$/u.test(row.slug) || !/^[a-f0-9]{64}$/u.test(row.hash) || !Number.isSafeInteger(row.revision) || row.revision < 1 || !Number.isSafeInteger(row.bytes) || row.bytes <= 0)) throw new Error('Invalid staging pin');
19
+ if (catalogue.shards.length !== shards.length || catalogue.shards.some(row => !shards.some(pin => pin.slug === row.slug && pin.hash === row.hash && pin.revision === row.revision))) throw new Error('Staging pins disagree with catalogue');
20
+ const unlisted = unlistedSlugs(catalogueSlugs(catalogue), {staging: documentSlugs(catalogue)});
21
+ if (unlisted.length > 0) throw new Error(unlistedMessage(unlisted));
22
+ }
23
+
24
+ export async function refreshStaging(api: string): Promise<void> {
25
+ const get = async (path: string): Promise<unknown> => {
26
+ const response = await fetch(`${api}${path}`);
27
+ if (!response.ok) throw new Error(`${path}: HTTP ${response.status}`);
28
+ return response.json();
29
+ };
30
+ const [document, listing] = await Promise.all([get('/api/catalogue.json?channel=staging'), get('/api/shardfiles')]);
31
+ const catalogue = document as Document;
32
+ const sizes = new Map((listing as {shardfiles: {hash: string; bytes: number}[]}).shardfiles.map(row => [row.hash, row.bytes]));
33
+ const snapshot: StagingPins = {version: 1, channel: 'staging', api, catalogueHash: hash(catalogue),
34
+ // AP-26 has no public release identity yet. Never call a catalogue digest a release hash.
35
+ releaseHash: null, catalogue, shards: catalogue.shards.map(row => ({slug: row.slug, revision: row.revision, hash: row.hash, bytes: sizes.get(row.hash) ?? 0}))};
36
+ checkStaging(snapshot);
37
+ mkdirSync('test/pins', {recursive: true});
38
+ writeFileSync(file, json(snapshot));
39
+ console.log(`Pinned ${snapshot.shards.length} staging heads; release-hash verification waits on api-server AP-26`);
40
+ }
41
+
42
+ /** Materialize only in an explicitly selected test checkout; installers and both rings keep one input path. */
43
+ export function selectStaging(): void {
44
+ const snapshot = JSON.parse(readFileSync(file, 'utf8')) as StagingPins;
45
+ checkStaging(snapshot);
46
+ writeFileSync('test/pins/shardfiles.json', json({api: snapshot.api, shards: snapshot.shards}));
47
+ writeFileSync('test/pins/catalogue.json', json(snapshot.catalogue));
48
+ console.log(`Selected staging catalogue ${snapshot.catalogueHash}; release hash is unverified (AP-26)`);
49
+ }
50
+
51
+ if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href) {
52
+ if (process.argv[2] === 'select') selectStaging();
53
+ else throw new Error('Use pins.ts refresh --channel staging, or pins-staging.ts select in a disposable test checkout');
54
+ }
package/scripts/pins.ts CHANGED
@@ -462,8 +462,13 @@ function status(): void {
462
462
 
463
463
  const [command = 'status', ...rest] = process.argv.slice(2);
464
464
  if (command === 'refresh') {
465
+ if (rest.length === 2 && rest[0] === '--channel' && rest[1] === 'staging') {
466
+ const {refreshStaging} = await import('./pins-staging.ts');
467
+ await refreshStaging(API);
468
+ } else {
465
469
  if (rest.some((arg, at) => arg.startsWith('-') ? arg !== '--drop' : rest[at - 1] !== '--drop')) throw new Error('usage: pins.ts refresh [--drop slug[,slug]]...');
466
470
  await refresh(rest.flatMap((arg, at) => rest[at - 1] === '--drop' ? arg.split(',') : []));
471
+ }
467
472
  }
468
473
  else if (command === 'install' && rest[0] === '--ring') await installRing(rest[1] ?? '1');
469
474
  else if (command === 'install' && rest[0] === '--from-format') await install(rest.slice(1), 'format');
@@ -0,0 +1,71 @@
1
+ // Standalone integration checks of the sender against a controlled GitHub API.
2
+ import {test} from 'node:test';
3
+ import assert from 'node:assert/strict';
4
+ import {prepare, runRing3, shardRepos, type Api} from './ring3.ts';
5
+
6
+ const candidate = 'a'.repeat(40), shard = 'b'.repeat(40);
7
+ interface Call {method: string; path: string; body?: unknown}
8
+ function fixture(options: {red?: string; malformed?: boolean; pending?: boolean; wrongRun?: boolean; denied?: string; existing?: boolean} = {}): {api: Api; calls: Call[]} {
9
+ const calls: Call[] = [];
10
+ const api: Api = (method, path, body) => Promise.resolve().then(() => {
11
+ calls.push({method, path, body});
12
+ const repo = path.split('/')[2];
13
+ if (repo === undefined || !shardRepos.includes(repo as typeof shardRepos[number])) throw new Error(`Unexpected repository: ${path}`);
14
+ const id = shardRepos.indexOf(repo as typeof shardRepos[number]) + 100;
15
+ if (method === 'POST' && path.endsWith('/dispatches')) {
16
+ if (repo === options.denied) throw new Error('HTTP 403');
17
+ assert.deepEqual(body, {ref: 'main', inputs: {engine: candidate}, return_run_details: true});
18
+ return options.malformed ? {} : {workflow_run_id: id};
19
+ }
20
+ if (method === 'GET' && path.endsWith(`/actions/runs/${id}`)) return {id: options.wrongRun ? id + 1 : id, event: 'workflow_dispatch', path: '.github/workflows/ci.yml', head_sha: shard, run_attempt: 1,
21
+ status: options.pending ? 'queued' : 'completed', conclusion: repo === options.red ? 'failure' : 'success'};
22
+ if (method === 'GET' && path.includes('/issues?')) return options.existing ? [{title: `[Ring 3] engine ${candidate}`, html_url: 'existing-issue'}] : [];
23
+ if (method === 'POST' && path.endsWith('/issues')) return {html_url: `https://github.com/project-wildshard/${repo}/issues/1`};
24
+ throw new Error(`Unexpected API call: ${method} ${path}`);
25
+ });
26
+ return {api, calls};
27
+ }
28
+
29
+ await test('all seven exact candidate dispatches must complete green on their returned run IDs', async () => {
30
+ const {api, calls} = fixture(), report = await runRing3(prepare(candidate, 'sender'), {api});
31
+ assert.equal(report.ok, true);
32
+ assert.deepEqual(report.rows.map(row => row.repo), shardRepos);
33
+ assert.equal(report.rows.every(row => row.shardSha === shard && row.status === 'success'), true);
34
+ assert.equal(calls.filter(call => call.method === 'POST').length, 7);
35
+ assert.equal(calls.some(call => call.path.includes('/runs?')), false, 'Never substitutes another candidate run');
36
+ });
37
+ await test('one red receiver holds the aggregate and files only that shard issue', async () => {
38
+ const {api, calls} = fixture({red: 'shard-dunes'}), report = await runRing3(prepare(candidate, 'sender'), {api});
39
+ assert.equal(report.ok, false);
40
+ assert.equal(report.rows.filter(row => row.status === 'success').length, 6);
41
+ assert.equal(report.rows[0].issue, 'https://github.com/project-wildshard/shard-dunes/issues/1');
42
+ assert.equal(calls.filter(call => call.method === 'POST' && call.path.endsWith('/issues')).length, 1);
43
+ });
44
+ await test('a repeat red candidate reuses its existing issue', async () => {
45
+ const {api, calls} = fixture({red: 'shard-dunes', existing: true}), report = await runRing3(prepare(candidate, 'sender'), {api});
46
+ assert.equal(report.rows[0].issue, 'existing-issue');
47
+ assert.equal(calls.filter(call => call.method === 'POST' && call.path.endsWith('/issues')).length, 0);
48
+ });
49
+ await test('a refused shard dispatch cannot prevent the other six receivers from running', async () => {
50
+ const {api} = fixture({denied: 'shard-dunes'}), report = await runRing3(prepare(candidate, 'sender'), {api});
51
+ assert.equal(report.ok, false);
52
+ assert.equal(report.rows[0].status, 'error');
53
+ assert.equal(report.rows.filter(row => row.status === 'success').length, 6);
54
+ });
55
+ await test('missing IDs and unrelated green runs can never qualify the candidate', async () => {
56
+ for (const option of [{malformed: true}, {wrongRun: true}]) {
57
+ const {api} = fixture(option), report = await runRing3(prepare(candidate, 'sender'), {api});
58
+ assert.equal(report.ok, false);
59
+ assert.equal(report.rows.every(row => row.status === 'error'), true);
60
+ }
61
+ });
62
+ await test('queued receivers hit a bounded deadline and remain red with their run links', async () => {
63
+ let now = 0;
64
+ const {api} = fixture({pending: true}), report = await runRing3(prepare(candidate, 'sender'), {api, now: () => now, sleep: ms => {now += ms; return Promise.resolve();}, deadlineMs: 100, pollMs: 20});
65
+ assert.equal(now, 100);
66
+ assert.equal(report.ok, false);
67
+ assert.equal(report.rows.every(row => row.status === 'timeout' && row.runUrl !== undefined), true);
68
+ });
69
+ await test('moving refs and shell text refuse before a dispatch can be prepared', () => {
70
+ for (const ref of ['main', 'a'.repeat(39), '$(echo injected)', 'A'.repeat(40)]) assert.throws(() => prepare(ref, 'sender'), /full engine commit/u);
71
+ });
@@ -0,0 +1,100 @@
1
+ // Ring 3: dispatch the exact candidate, then follow the returned run ID.
2
+ // workflow_dispatch reaches the same receiver as engine-candidate, and its
3
+ // return_run_details response avoids guessing which concurrent run is ours.
4
+ import {mkdirSync, readFileSync, writeFileSync} from 'node:fs';
5
+ import {join} from 'node:path';
6
+ import {pathToFileURL} from 'node:url';
7
+
8
+ export const shardRepos = ['shard-dunes', 'shard-sky-reach', 'shard-nalati', 'shard-nine-dragon', 'shard-driftwood', 'shard-pine-hollow', 'shard-open-plots'] as const;
9
+ interface Row {repo: string; status: 'pending' | 'success' | 'failure' | 'error' | 'timeout'; runId?: number; runUrl?: string; shardSha?: string; conclusion?: string | null; issue?: string; error?: string}
10
+ export interface Aggregate {version: 1; engine: string; originRun: string; ok: boolean; rows: Row[]}
11
+ export type Api = (method: 'GET' | 'POST', path: string, body?: unknown) => Promise<unknown>;
12
+ interface Options {api: Api; now?: () => number; sleep?: (ms: number) => Promise<void>; deadlineMs?: number; pollMs?: number; checkpoint?: (report: Aggregate) => void}
13
+ const errorText = (error: unknown): string => String(error).replaceAll(/[\r\n]/gu, ' ').slice(0, 1000);
14
+
15
+ export function prepare(engine: string, originRun: string): Aggregate {
16
+ if (!/^[a-f0-9]{40}$/u.test(engine)) throw new Error('Ring 3 requires the full engine commit hash');
17
+ return {version: 1, engine, originRun, ok: false, rows: shardRepos.map(repo => ({repo, status: 'pending'}))};
18
+ }
19
+
20
+ export async function runRing3(report: Aggregate, options: Options): Promise<Aggregate> {
21
+ const {api, now = Date.now, sleep = (ms: number): Promise<void> => new Promise(resolve => {setTimeout(resolve, ms);}), deadlineMs = 20 * 60_000, pollMs = 15_000, checkpoint = () => { /* Embedded callers may omit persisted receipts. */ }} = options;
22
+ const until = now() + deadlineMs;
23
+ // All seven requests are independent; a refused shard must not hide the others.
24
+ await Promise.all(report.rows.map(async row => {
25
+ try {
26
+ const response = await api('POST', `repos/project-wildshard/${row.repo}/actions/workflows/ci.yml/dispatches`,
27
+ {ref: 'main', inputs: {engine: report.engine}, return_run_details: true}) as {workflow_run_id?: number; html_url?: string};
28
+ if (!Number.isSafeInteger(response.workflow_run_id) || (response.workflow_run_id ?? 0) <= 0) throw new Error('Dispatch returned no exact run ID; refusing to guess a run');
29
+ row.runId = response.workflow_run_id;
30
+ row.runUrl = `https://github.com/project-wildshard/${row.repo}/actions/runs/${row.runId}`;
31
+ } catch (error) {row.status = 'error'; row.error = errorText(error);}
32
+ checkpoint(report);
33
+ }));
34
+ while (report.rows.some(row => row.status === 'pending') && now() < until) {
35
+ await Promise.all(report.rows.filter(row => row.status === 'pending').map(async row => {
36
+ try {
37
+ const run = await api('GET', `repos/project-wildshard/${row.repo}/actions/runs/${row.runId}`) as {id: number; event: string; path: string; head_sha: string; status: string; conclusion: string | null; run_attempt: number};
38
+ if (run.id !== row.runId || run.event !== 'workflow_dispatch' || run.path.split('@')[0] !== '.github/workflows/ci.yml' || !/^[a-f0-9]{40}$/u.test(run.head_sha) || run.run_attempt !== 1) throw new Error('Receiver run identity changed; new qualification required');
39
+ row.shardSha = run.head_sha;
40
+ if (run.status === 'completed') {row.conclusion = run.conclusion; row.status = run.conclusion === 'success' ? 'success' : 'failure';}
41
+ } catch (error) {row.status = 'error'; row.error = errorText(error);}
42
+ checkpoint(report);
43
+ }));
44
+ if (report.rows.some(row => row.status === 'pending')) await sleep(Math.max(0, Math.min(pollMs, until - now())));
45
+ }
46
+ for (const row of report.rows) if (row.status === 'pending') {row.status = 'timeout'; row.error = 'Receiver did not complete within the Ring 3 deadline';}
47
+ // Deduplicate per candidate in each shard; cancelled/skipped/incomplete is never green.
48
+ await Promise.all(report.rows.filter(row => row.status !== 'success' && row.runId !== undefined).map(async row => {
49
+ try {
50
+ const title = `[Ring 3] engine ${report.engine}`;
51
+ const existing = await api('GET', `repos/project-wildshard/${row.repo}/issues?state=all&per_page=100&sort=created&direction=desc`) as {title: string; html_url: string; pull_request?: unknown}[];
52
+ const prior = existing.find(issue => issue.pull_request === undefined && issue.title === title);
53
+ if (prior !== undefined) row.issue = prior.html_url;
54
+ else {
55
+ const issue = await api('POST', `repos/project-wildshard/${row.repo}/issues`, {title,
56
+ body: `Engine candidate: \`${report.engine}\`\n\nReceiver: ${row.runUrl}\n\nShard commit: \`${row.shardSha ?? 'unavailable'}\`\n\nVerdict: ${row.status} (${row.conclusion ?? row.error ?? 'incomplete'}).\n\nSender: ${report.originRun}\n\nFix forward (J165); this candidate is not release-qualified.`}) as {html_url: string};
57
+ row.issue = issue.html_url;
58
+ }
59
+ } catch (error) {row.error = `${row.error ?? ''} Issue creation failed: ${errorText(error)}`.trim();}
60
+ checkpoint(report);
61
+ }));
62
+ report.ok = report.rows.length === shardRepos.length && report.rows.every(row => row.status === 'success');
63
+ checkpoint(report);
64
+ return report;
65
+ }
66
+
67
+ export function markdown(report: Aggregate): string {
68
+ return [`# Ring 3: ${report.ok ? 'GREEN' : 'RED — RELEASE HELD'}`, '', `Engine: \`${report.engine}\``, '',
69
+ '| Shard | Candidate run | Shard commit | Verdict | Issue |', '| --- | --- | --- | --- | --- |',
70
+ ...report.rows.map(row => `| ${row.repo} | ${row.runUrl === undefined ? 'not dispatched' : `[${row.runId}](${row.runUrl})`} | ${row.shardSha?.slice(0, 12) ?? 'unknown'} | ${row.status} | ${row.issue === undefined ? '' : `[issue](${row.issue})`} |`),
71
+ '', ...report.rows.filter(row => row.error !== undefined).map(row => `- ${row.repo}: ${row.error?.replaceAll(/[|<>]/gu, ' ')}`),
72
+ '', 'This artifact aggregates candidate checks. It does not create a tag, release, upload or deployment.', ''].join('\n');
73
+ }
74
+
75
+ if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href) {
76
+ const [command, directory = 'tmp/ring3'] = process.argv.slice(2);
77
+ const save = (report: Aggregate): void => {mkdirSync(directory, {recursive: true}); writeFileSync(join(directory, 'verdict.json'), `${JSON.stringify(report, null, 2)}\n`); writeFileSync(join(directory, 'summary.md'), markdown(report));};
78
+ if (command === 'prepare') save(prepare(process.env.RING3_ENGINE ?? '', process.env.RING3_ORIGIN_RUN ?? 'local'));
79
+ else if (command === 'run') {
80
+ const report = JSON.parse(readFileSync(join(directory, 'verdict.json'), 'utf8')) as Aggregate;
81
+ // Revalidate the persisted candidate before any write request.
82
+ if (JSON.stringify(report) !== JSON.stringify(prepare(report.engine, report.originRun))) throw new Error('Ring 3 must start from a fresh prepared aggregate');
83
+ const token = process.env.GH_TOKEN;
84
+ if (token === undefined || token === '') throw new Error('Ring 3 needs the dedicated nightly App token');
85
+ const api: Api = async (method, path, body) => {
86
+ const response = await fetch(`https://api.github.com/${path}`, {method, signal: AbortSignal.timeout(20_000),
87
+ headers: {accept: 'application/vnd.github+json', authorization: `Bearer ${token}`, 'x-github-api-version': '2022-11-28', ...(body === undefined ? {} : {'content-type': 'application/json'})},
88
+ ...(body === undefined ? {} : {body: JSON.stringify(body)})});
89
+ if (!response.ok) throw new Error(`GitHub ${method} ${path}: HTTP ${response.status}; check nightly App installation and Actions/Issues permissions`);
90
+ return response.json();
91
+ };
92
+ await runRing3(report, {api, checkpoint: save});
93
+ console.log(markdown(report));
94
+ if (!report.ok) process.exitCode = 1;
95
+ } else if (command === 'report') {
96
+ const report = JSON.parse(readFileSync(join(directory, 'verdict.json'), 'utf8')) as Aggregate;
97
+ console.log(markdown(report));
98
+ if (!report.ok) process.exitCode = 1;
99
+ } else throw new Error('Use ring3.ts prepare|run|report [directory]');
100
+ }