Skip to content

armgit / kiln

Public Imported from GitHub
0

Build and revise procedural 3D assets with your coding agent. Local MCP server, CLI and TypeScript engine with rendered review, editable source and GLB export.

Restage a Holodeck pack without its store, and keep one release ID per staged state (#274, #275) (#300)

Matthew Kissingerb5cd386bc73a
diff --git a/packs/holodeck/README.md b/packs/holodeck/README.md
index 101cad71..78c713d7 100644
--- a/packs/holodeck/README.md
+++ b/packs/holodeck/README.md
@@ -40,14 +40,20 @@ Kiln and Holodeck software keep their own licences.
- `selection.json` freezes each pack's exact collection, asset and revision IDs and the
SHA-256 of every saved manifest, source program and canonical GLB. Every placed scene GLB is
byte-identical to the canonical `asset.glb` of the revision its world names.
-- `sources/project/<asset>/<revision>/` keeps each source program and saved manifest.
+- `sources/project/<asset>/<revision>/` keeps each source program and saved manifest. With the
+ published editable bundles these are enough to restage a pack whose Kiln store is gone, and to
+ rebuild that store; see [Restage without a store](#restage-without-a-store).
- `HOLODECK_APPROVAL` in `site/scripts/holodeck-spec.mjs` records owner approval by slug and
exact revision: on 2026-10-23 the 47 Tidemark, Courtyard and Cove cards, then Crescent Cove's
41 new cards. A pack is available only when every asset it lists is approved, so a new card
or revision makes its pack wait for review again.
- `site/src/data/holodeck.json` is the gallery catalog. Downloads and posters are pinned in
`site/src/data/mirror-manifest.json`; posters are rendered under the `review-neutral-v1` rig
- and recorded in `site/src/data/rig-posters.json`.
+ and recorded in `site/src/data/rig-posters.json`, which keeps one record per poster run and
+ names the run on every poster it made.
+- `releases.json` records every release ID the packs have spent and the selection it staged, so
+ a branch cannot reuse an ID another branch already spent; see
+ [Choose a release ID](#choose-a-release-id).
## Regenerate
@@ -77,12 +83,80 @@ Keys are immutable, so different bytes at an existing key are refused.
`published.json` records every object the asset host has served back. The upload list leaves
those out and names only new objects; one recorded with different bytes is refused.
+### Where stores live
+
+Keep every authoring workspace a release selects under one durable directory, one workspace per
+store name in `selection.json` — never in a session temp folder, and never only on the machine
+that authored it. A store named in the selection but kept nowhere else is a store that will be
+lost, and the names are the only thing a later release has to go on.
+
+Losing one is recoverable but not free: the published editable bundle is a fallback for
+restaging, not a substitute for the authoring workspace it came from.
+
+### Restage without a store
+
+A revision whose store is gone, or whose store no longer holds it, is read back from the
+editable bundle its release published. The bundle is a standard Kiln revision bundle, so its
+sealed members are the stored files byte for byte; the saved `manifest.json` comes from the
+`sources/` record here, because a bundle re-serialises it without the trailing newline a store
+writes. Both are verified against `selection.json`, the bundle must name the selected revision,
+and it must rebuild byte for byte into the very object it was read from — a content-addressed
+key would otherwise move silently rather than fail. Staging names every revision it read that
+way under `recovered`.
+
+The bytes come from `--mirror` when a previous staging run still has them, and from the asset
+host otherwise, but only for an object `published.json` records the host serving back. A
+revision never published, such as a brand-new one, still needs its store.
+
+### Recover a lost store
+
+Materialise the selected revisions as a Kiln store again, from the same published bundles:
+
+```sh
+node scripts/stage-holodeck.mjs --recover-store STORE_DIR --mirror .localdata/holodeck-delivery
+```
+
+`--only slug,slug` limits it to some assets. Each revision is written to
+`STORE_DIR/<assetId>/revisions/<revisionId>` exactly as its store held it, so one recovered
+directory can serve several store names; an existing file must already hold those bytes. The
+result is a store for restaging, not the authoring workspace: it holds the selected revisions
+only, with no history and no workspace state.
+
+### Choose a release ID
+
+A release ID names one staged state. `releases.json` records every ID spent and the SHA-256 of
+the `selection.json` it staged; staging refuses an ID already spent on different content and
+suggests the next free one. Restaging the same selection under the same ID is the normal release
+loop and records nothing new.
+
+Seven IDs were spent before this ledger existed, and only the current one is recorded with its
+selection: the rest were recovered from the release folders in the Holodeck poster paths, which
+show the ID was used but not what it staged. None of those can be claimed again.
+
+### Rebase a pack onto main
+
+`published.json`, `mirror-manifest.json`, `commons-build.json`, `holodeck.json` and
+`holodeck-shots.json` are generated. Merging two branches' copies line by line produces a state
+no staging run would produce — `holodeck-20261025-02` was spent twice and five files had to be
+reconciled entry by entry. Regenerate them instead:
+
+1. Take `main`'s copies of every generated file (`git checkout main -- <file>`), and `main`'s
+ `releases.json`.
+2. Give the pack a release ID that `releases.json` leaves free.
+3. Rerun the selection, staging and upload-list commands above. Staging rewrites the catalog,
+ the pins and the image plan from `selection.json`, so the result is one coherent state.
+
+`rig-posters.json` is the exception: its images need the GPU rig, so keep both branches' records
+and both runs, and re-render only the posters whose revision or model changed (`--only`).
+`refreshCatalog` then rewrites the catalog's posters from the record.
+
### Add a new committed example
For a new scene, keep the published selection as the baseline instead of reselecting
older worlds. First add its real pack metadata, exact asset count and per-asset
-presentation to `holodeck-spec.mjs`, choose a new `HOLODECK_RELEASE`, and add its
-scene URL to `src/data/holodeck-worlds.json`. Do this only after the example and its
+presentation to `holodeck-spec.mjs`, choose a new `HOLODECK_RELEASE` that
+[`releases.json` leaves free](#choose-a-release-id), and add its scene URL to
+`src/data/holodeck-worlds.json`. Do this only after the example and its
final assets exist. A selection does not approve an asset or publish its gallery page.
From `site/`, append the committed example with its saved Kiln store:
@@ -113,7 +187,8 @@ revision approval records, and record any new asset review separately and honest
### Repoint a committed example
When a selected example moves to a newer source revision, choose a new `HOLODECK_RELEASE`
-and repoint only that pack, from `site/`:
+that [`releases.json` leaves free](#choose-a-release-id) and repoint only that pack, from
+`site/`:
```sh
node scripts/select-holodeck.mjs --repoint-example crescent-cove \
diff --git a/packs/holodeck/releases.json b/packs/holodeck/releases.json
new file mode 100644
index 00000000..22caf718
--- /dev/null
+++ b/packs/holodeck/releases.json
@@ -0,0 +1,30 @@
+{
+ "schemaVersion": 1,
+ "releases": [
+ {
+ "release": "gallery-20261026-01"
+ },
+ {
+ "release": "holodeck-20261022-01"
+ },
+ {
+ "release": "holodeck-20261023-01"
+ },
+ {
+ "release": "holodeck-20261024-01"
+ },
+ {
+ "release": "holodeck-20261025-01"
+ },
+ {
+ "release": "holodeck-20261025-02"
+ },
+ {
+ "release": "holodeck-20261026-01",
+ "selection": {
+ "bytes": 190798,
+ "sha256": "4565733e436796d7e319e22ebf3ca86997e880f44eaa07274fbd0d57a860c14f"
+ }
+ }
+ ]
+}
diff --git a/site/scripts/holodeck.test.ts b/site/scripts/holodeck.test.ts
index 1b34f213..be28ab7e 100644
--- a/site/scripts/holodeck.test.ts
+++ b/site/scripts/holodeck.test.ts
@@ -2,6 +2,7 @@ import { expect, test } from 'bun:test';
import { createHash } from 'node:crypto';
import { readFile } from 'node:fs/promises';
import { join, resolve } from 'node:path';
+import releases from '../../packs/holodeck/releases.json';
import selection from '../../packs/holodeck/selection.json';
import catalog from '../src/data/holodeck.json';
import worlds from '../src/data/holodeck-worlds.json';
@@ -13,7 +14,7 @@ import { HOLODECK_SITE } from '../src/lib/config';
import { buildGallery } from '../src/lib/gallery';
import { holodeckScenes, holodeckWorldUrl } from '../src/lib/holodeck';
import { HOLODECK_APPROVAL, HOLODECK_ASSETS, HOLODECK_PACKS, HOLODECK_SHOT_SIZE, HOLODECK_SHOTS, holodeckApproved, holodeckSlug } from './holodeck-spec.mjs';
-import { HOLODECK_OBJECTS, HOLODECK_SHOTS_DIR } from './stage-holodeck.mjs';
+import { HOLODECK_OBJECTS, HOLODECK_SHOTS_DIR, claimHolodeckRelease } from './stage-holodeck.mjs';
import { ASSET_BASE } from './mirror-core.mjs';
import { applyRigPosters } from './rig-posters-core.mjs';
@@ -158,3 +159,19 @@ test('every pack shows its two scene shots, wide view first, captured from its w
}
}
});
+
+test('every release ID the packs have spent is recorded once, and the current one describes this selection', async () => {
+ const ids = releases.releases.map((record) => record.release);
+ expect(ids).toEqual([...new Set(ids)]);
+ expect(ids).toEqual([...ids].sort((a, b) => a.localeCompare(b, 'en')));
+ // Every release a Holodeck poster was rendered under was spent, whether or not its selection was kept.
+ const rendered = new Set(Object.entries(rigPosters.posters).filter(([key]) => key.startsWith('holodeck:')).map(([, poster]) => poster.path.split('/')[4]));
+ for (const release of rendered) expect(ids, release).toContain(release);
+ expect(ids).toContain(catalog.release);
+ // Restaging this selection under its own ID is the release loop and claims nothing new; reusing the ID for other
+ // content is refused with the next free one.
+ const bytes = await readFile(join(ROOT, 'packs/holodeck/selection.json'));
+ expect(claimHolodeckRelease({ release: selection.release, selection: bytes, recorded: releases })).toEqual(releases);
+ expect(() => claimHolodeckRelease({ release: selection.release, selection: Buffer.from('other'), recorded: releases })).toThrow('choose a new HOLODECK_RELEASE');
+ expect(() => claimHolodeckRelease({ release: 'holodeck-20261025-02', selection: bytes, recorded: releases })).toThrow('holodeck-20261025-03');
+});
diff --git a/site/scripts/rig-posters.mjs b/site/scripts/rig-posters.mjs
index ede364fa..d70c869e 100644
--- a/site/scripts/rig-posters.mjs
+++ b/site/scripts/rig-posters.mjs
@@ -238,10 +238,31 @@ export async function renderTarget(rig, target) {
const recordKey = (target) => target.key ?? rigPosterKey(target.pack, target.slug);
+/**
+ * A poster run's identity: its pack, the day it rendered, and a digest of the engine and render service it used.
+ * Re-rendering under the same engine and service on the same day is the same run; anything else is another one, so
+ * a later run can never be mistaken for the one that made an earlier image.
+ */
+export const rigRunId = ({ pack, renderedOn, engine, service }) => `${pack}-${renderedOn}-${sha256Of(Buffer.from(JSON.stringify([engine, service]))).slice(0, 8)}`;
+const rigRun = ({ pack, renderedOn, engine, service }) => ({ id: rigRunId({ pack, renderedOn, engine, service }), pack, renderedOn, engine, service });
+
+/**
+ * Every run recorded so far, one record each. Earlier files kept a single run per pack, and the one before that a
+ * single run for the whole file, so a second run of a pack overwrote the first run's engine, service and date --
+ * seven winter posters ended up pointing at the run that rendered a different pack. Those headers are migrated
+ * here; the posters they covered keep no run, because which run made them was lost before this record existed.
+ */
+export function rigRuns(previous) {
+ const rig = previous?.rig ?? {};
+ if (Array.isArray(rig.runs)) return rig.runs.map((run) => (run.id ? run : rigRun(run)));
+ const legacy = rig.runs ?? (rig.engine ? { farm: { renderedOn: rig.renderedOn, engine: rig.engine, service: rig.service } } : {});
+ return Object.entries(legacy).map(([pack, run]) => rigRun({ pack, ...run }));
+}
+
/**
* Write the record, and (Farm) pin the PNGs and extend the image plan. `pin: false` writes the PNGs into the
* mirror without pinning them: the bridge update pins a revision's whole directory itself and would replace
- * any earlier pin under it.
+ * any earlier pin under it. Each poster names the run that rendered it, and each run keeps its own record.
*/
export async function recordPosters({ rig, rendered, mirror, data = DATA, renderedOn = new Date().toISOString().slice(0, 10), pin = true }) {
const manifestFile = join(data, 'mirror-manifest.json');
@@ -249,8 +270,8 @@ export async function recordPosters({ rig, rendered, mirror, data = DATA, render
const recordFile = join(data, 'rig-posters.json');
const previous = await readJson(recordFile).catch(() => ({ schemaVersion: 1, rig: {}, posters: {} }));
const posters = { ...previous.posters };
- // The header keeps one run per pack: the engine and service each image set came from.
- const runs = { ...(previous.rig?.runs ?? (previous.rig?.engine ? { farm: { renderedOn: previous.rig.renderedOn, engine: previous.rig.engine, service: previous.rig.service } } : {})) };
+ // One record per run: the engine and service that image set came from.
+ const runs = rigRuns(previous);
let plan = pin ? await readJson(planFile) : undefined;
for (const { png, record, target } of rendered) {
if (pin) await pinMirrorFile({ mirror, manifestFile, path: record.path, bytes: png });
@@ -258,13 +279,15 @@ export async function recordPosters({ rig, rendered, mirror, data = DATA, render
await mkdir(dirname(join(mirror, record.path)), { recursive: true });
await writeFile(join(mirror, record.path), png);
}
- posters[recordKey(target)] = record;
if (pin) plan = { ...plan, images: upsertBy(plan.images, 'inputPath', rigPosterImage(record, target.alt)) };
- runs[target.pack] = {
+ const run = rigRun({
+ pack: target.pack,
renderedOn,
engine: { commit: rig.engine.provenance.commit, subject: rig.engine.provenance.subject, dirty: rig.engine.provenance.dirty },
service: rig.service,
- };
+ });
+ if (!runs.some((prior) => prior.id === run.id)) runs.push(run);
+ posters[recordKey(target)] = { ...record, run: run.id };
}
if (pin) await writeJson(planFile, plan);
await writeJson(recordFile, { schemaVersion: 1, rig: { id: RIG_ID, backdrop: 'neutral', runs }, posters });
diff --git a/site/scripts/rig-posters.test.ts b/site/scripts/rig-posters.test.ts
index 3f410769..e8cca90d 100644
--- a/site/scripts/rig-posters.test.ts
+++ b/site/scripts/rig-posters.test.ts
@@ -4,11 +4,12 @@ import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { RIG_ID, resolveRigEngine, fitCamera, orbitDirection } from './rig-render.mjs';
import { applyRigPoster, applyRigPosters, rigPosterImage, rigPosterKey, rigPosterPath } from './rig-posters-core.mjs';
-import { VEHICLE_POSTER, holodeckPosterView, pruneImagePlan, vehicleTargets } from './rig-posters.mjs';
+import { VEHICLE_POSTER, holodeckPosterView, pruneImagePlan, recordPosters, vehicleTargets } from './rig-posters.mjs';
import { hashBytes } from './mirror-core.mjs';
const DATA = resolve(import.meta.dir, '../src/data');
const json = async (file: string) => JSON.parse(await readFile(join(DATA, file), 'utf8'));
+const runFor = (recorded: { rig: { runs: { pack: string }[] } }, pack: string) => recorded.rig.runs.find((run) => run.pack === pack) as any;
const record = {
path: 'media/rig/review-neutral-v1/farm/r34/barn.png',
@@ -108,7 +109,9 @@ describe('the checked-in Farm posters', () => {
const [farm, recorded, manifest, plan] = await Promise.all([json('packs/farm.json'), json('rig-posters.json'), json('mirror-manifest.json'), json('commons-build.json')]);
expect(recorded.rig.id).toBe(RIG_ID);
expect(recorded.rig.backdrop).toBe('neutral');
- expect(recorded.rig.runs.farm.engine.commit).toMatch(/^[0-9a-f]{40}$/);
+ expect(runFor(recorded, 'farm').engine.commit).toMatch(/^[0-9a-f]{40}$/);
+ // One record per run, each with its own id: a later run of a pack no longer overwrites an earlier one.
+ expect(recorded.rig.runs.map((run: { id: string }) => run.id)).toEqual([...new Set(recorded.rig.runs.map((run: { id: string }) => run.id))]);
const pins = new Map<string, { path: string; bytes: number; sha256: string }>(manifest.files.map((file: { path: string; bytes: number; sha256: string }) => [file.path, file]));
const planned = new Set(plan.images.map((image: { inputPath: string }) => image.inputPath));
expect(farm.assets).toHaveLength(23);
@@ -130,10 +133,10 @@ describe('the checked-in Farm posters', () => {
test('every vehicle has a rig poster from the same place, rendered from its own delivered GLB, pinned and planned', async () => {
const [vehicles, recorded, manifest, plan] = await Promise.all([json('packs/vehicles.json'), json('rig-posters.json'), json('mirror-manifest.json'), json('commons-build.json')]);
- expect(recorded.rig.runs.vehicles.engine.commit).toBe(recorded.rig.runs.farm.engine.commit);
+ expect(runFor(recorded, 'vehicles').engine.commit).toBe(runFor(recorded, 'farm').engine.commit);
// All six final posters must bind the newly delivered runtime, independently of saved-preview canonical bytes.
- expect(recorded.rig.runs.vehicles.engine).toMatchObject({ commit: 'ac6d9eb492b4891a54dbf563cfef14af5633254a', dirty: true });
- expect(recorded.rig.runs.vehicles.service).toMatchObject({
+ expect(runFor(recorded, 'vehicles').engine).toMatchObject({ commit: 'ac6d9eb492b4891a54dbf563cfef14af5633254a', dirty: true });
+ expect(runFor(recorded, 'vehicles').service).toMatchObject({
protocol: 'kiln.render-service.v2',
sourceFingerprint: 'sha256:ea13cf0d48a53734132568066d5a94121c8dd3b088ea8606b1c4dbe14b896ef6',
buildFingerprint: 'sha256:56d89e736bb03575c9131be509f3411c9b764750d354f82d8a601188e723b576',
@@ -192,3 +195,59 @@ describe('the checked-in Farm posters', () => {
expect(() => resolveRigEngine({ site, env: {}, exists: () => false })).toThrow('KILN_RIG_ENGINE_DIR');
});
});
+
+describe('poster run provenance', () => {
+ const rigFor = (commit: string, instance: string) => ({
+ engine: { provenance: { commit, subject: `engine at ${commit.slice(0, 7)}`, dirty: false } },
+ service: { url: 'http://127.0.0.1:8000', protocol: 'kiln.render-service.v2', captureIdentity: ['kiln.capture-producer.v1', instance] },
+ });
+ const png = Buffer.from('png');
+ const rendered = (pack: string, release: string, slug: string) => [{
+ png,
+ target: { pack, slug, alt: `A ${slug}.` },
+ record: { path: rigPosterPath(pack, release, slug), width: 8, height: 8, bytes: png.length, sha256: hashBytes(png), revisionId: `r_${slug}` },
+ }];
+
+ /** A data directory as the pipeline keeps it, plus a mirror to pin into. */
+ async function workspace(seed: object = { schemaVersion: 1, rig: {}, posters: {} }) {
+ const root = await mkdtemp(join(tmpdir(), 'kiln-rig-runs-'));
+ const data = join(root, 'data');
+ await mkdir(data, { recursive: true });
+ await writeFile(join(data, 'mirror-manifest.json'), JSON.stringify({ files: [] }));
+ await writeFile(join(data, 'commons-build.json'), JSON.stringify({ images: [] }));
+ await writeFile(join(data, 'rig-posters.json'), JSON.stringify(seed));
+ return { root, data, mirror: join(root, 'mirror'), read: async () => JSON.parse(await readFile(join(data, 'rig-posters.json'), 'utf8')) };
+ }
+
+ test('each run keeps its own record and every poster names the run that made it', async () => {
+ const w = await workspace();
+ try {
+ await recordPosters({ rig: rigFor('a'.repeat(40), 'one'), rendered: rendered('holodeck', 'rel-01', 'shell'), mirror: w.mirror, data: w.data, renderedOn: '2026-10-25' });
+ await recordPosters({ rig: rigFor('b'.repeat(40), 'two'), rendered: rendered('holodeck', 'rel-02', 'palm'), mirror: w.mirror, data: w.data, renderedOn: '2026-10-26' });
+ const recorded = await w.read();
+ expect(recorded.rig.runs).toHaveLength(2);
+ // The earlier run's provenance survives the later one: this is what a single per-pack record overwrote.
+ expect(recorded.rig.runs[0]).toMatchObject({ pack: 'holodeck', renderedOn: '2026-10-25', engine: { commit: 'a'.repeat(40) } });
+ expect(recorded.rig.runs[1]).toMatchObject({ pack: 'holodeck', renderedOn: '2026-10-26', engine: { commit: 'b'.repeat(40) } });
+ expect(recorded.posters['holodeck:shell'].run).toBe(recorded.rig.runs[0].id);
+ expect(recorded.posters['holodeck:palm'].run).toBe(recorded.rig.runs[1].id);
+ // Re-rendering under the same engine, service and day is the same run, not another record.
+ await recordPosters({ rig: rigFor('b'.repeat(40), 'two'), rendered: rendered('holodeck', 'rel-02', 'shell'), mirror: w.mirror, data: w.data, renderedOn: '2026-10-26' });
+ const again = await w.read();
+ expect(again.rig.runs.map((run: { id: string }) => run.id)).toEqual(recorded.rig.runs.map((run: { id: string }) => run.id));
+ expect(again.posters['holodeck:shell'].run).toBe(again.rig.runs[1].id);
+ } finally { await rm(w.root, { recursive: true, force: true }); }
+ });
+
+ test('a one-record-per-pack header migrates to one record per run', async () => {
+ const legacy = { schemaVersion: 1, rig: { id: RIG_ID, backdrop: 'neutral', runs: { farm: { renderedOn: '2026-10-01', engine: { commit: 'c'.repeat(40), subject: 'farm', dirty: true }, service: { url: 'http://127.0.0.1:8000' } } } }, posters: {} };
+ const w = await workspace(legacy);
+ try {
+ await recordPosters({ rig: rigFor('d'.repeat(40), 'three'), rendered: rendered('holodeck', 'rel-01', 'shell'), mirror: w.mirror, data: w.data, renderedOn: '2026-10-26' });
+ const recorded = await w.read();
+ expect(recorded.rig.runs.map((run: { pack: string }) => run.pack)).toEqual(['farm', 'holodeck']);
+ expect(recorded.rig.runs[0]).toMatchObject({ renderedOn: '2026-10-01', engine: { commit: 'c'.repeat(40) } });
+ for (const run of recorded.rig.runs) expect(run.id).toMatch(/^[a-z-]+-2026-10-\d\d-[0-9a-f]{8}$/);
+ } finally { await rm(w.root, { recursive: true, force: true }); }
+ });
+});
diff --git a/site/scripts/stage-holodeck.mjs b/site/scripts/stage-holodeck.mjs
index 47656f66..563a0d24 100644
--- a/site/scripts/stage-holodeck.mjs
+++ b/site/scripts/stage-holodeck.mjs
@@ -1,4 +1,5 @@
import { execFileSync } from 'node:child_process';
+import { existsSync } from 'node:fs';
import { cp, mkdir, mkdtemp, readFile, realpath, rm, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { dirname, join, resolve } from 'node:path';
@@ -22,6 +23,11 @@ import { materialClosure, metricsOf, verifyRuntimeProfile } from './stage-cabin-
* node scripts/stage-holodeck.mjs --shots --captures CAPTURE_DIR --mirror .localdata/holodeck-delivery
* node scripts/stage-holodeck.mjs --upload-list --mirror .localdata/holodeck-delivery
* node scripts/stage-holodeck.mjs --record-published .localdata/holodeck-delivery/holodeck-upload-list.json.published.json
+ * node scripts/stage-holodeck.mjs --recover-store DIR --mirror .localdata/holodeck-delivery [--only slug,slug]
+ *
+ * A revision whose store is gone is read back from the editable bundle this release already published, verified
+ * against every hash the selection freezes; the result names every revision taken that way. `--recover-store`
+ * materialises those bundles as a Kiln store again, so a lost store is rebuilt rather than mourned.
*
* Generated downloads go to the ignored mirror at content-addressed keys, `packs/holodeck/objects/<sha256>/<file>`,
* shared by every release that keeps their bytes, and are pinned in `src/data/mirror-manifest.json` for the asset
@@ -92,13 +98,143 @@ async function writeImmutable(root, path, bytes) {
await writeFile(target, bytes);
}
-export async function stageHolodeck({ kiln, mirror, stores, selectionFile = join(PACKS_ROOT, 'selection.json'), site = SITE, packsRoot = PACKS_ROOT, exporter = runtimeExport, packs: packSpecs = HOLODECK_PACKS, presentations = HOLODECK_ASSETS, approved = holodeckApproved }) {
- if (!kiln || !mirror || !stores || !Object.keys(stores).length) throw new Error('Explicit Kiln package, mirror and stores are required');
+/** Fetch a published object from the asset host. */
+const fetchAssetObject = async (url) => {
+ const response = await fetch(url, { signal: AbortSignal.timeout(120_000) });
+ if (!response.ok) throw new Error(`${url} answered ${response.status}`);
+ return Buffer.from(await response.arrayBuffer());
+};
+
+/**
+ * The one object pinned as an asset's editable revision bundle. Object keys are content-addressed, so the pin is the
+ * current revision's bundle whichever release first published it.
+ */
+export function holodeckBundlePin(pins, slug) {
+ const name = `/${slug}-editable.zip`;
+ const found = pins.filter((record) => record.path.startsWith(HOLODECK_OBJECTS) && record.path.endsWith(name));
+ if (found.length > 1) throw new Error(`More than one object is pinned as ${slug}-editable.zip`);
+ return found[0];
+}
+
+/** Read a pinned object: from the mirror, else from the asset host once the ledger records it serving the object back. */
+async function readPinnedObject(pin, { mirror, published, fetchObject }) {
+ if (mirror) {
+ try { return verifyBytes(await readFile(join(mirror, assetPath(pin.path))), pin, pin.path); }
+ catch (error) { if (error.code !== 'ENOENT') throw error; }
+ }
+ const served = published.get(pin.path);
+ if (!served) throw new Error(`${pin.path} is not in the mirror and published.json does not record the asset host serving it back`);
+ if (!sameObject(served, pin)) throw new Error(`The asset host holds different bytes at ${pin.path}`);
+ return verifyBytes(await fetchObject(ASSET_BASE + pin.path), pin, pin.path);
+}
+
+/**
+ * One selected revision read back out of its published editable bundle, as its Kiln store held it. The bundle is a
+ * standard Kiln revision bundle, so every sealed member is the stored file byte for byte; only its own
+ * `manifest.json` is re-serialised without the trailing newline a store writes, so the manifest comes from the
+ * `sources/` record this repository keeps. Both are verified against the selection, and the bundle must name the
+ * selected revision.
+ */
+export function holodeckRevisionFromBundle({ slug, chosen, bundle, manifestBytes }) {
+ const stored = json(verifyBytes(manifestBytes, chosen.manifest, `${slug} manifest`));
+ const { files, manifest, prefix } = verifyArchive(bundle, 'editable');
+ if (manifest.assetId !== chosen.assetId || manifest.revisionId !== chosen.revisionId) throw new Error(`${slug}: the published bundle holds ${manifest.assetId}/${manifest.revisionId}, not the selected revision`);
+ if (JSON.stringify(manifest) !== JSON.stringify(stored)) throw new Error(`${slug}: the kept manifest and the published bundle describe different revisions`);
+ const members = { 'manifest.json': Buffer.from(manifestBytes) };
+ for (const name of Object.keys(manifest.files)) members[name] = Buffer.from(files[prefix + name]);
+ const materials = files[`${prefix}materials.kiln.json`];
+ if (materials) members['materials.kiln.json'] = Buffer.from(materials);
+ return members;
+}
+
+/** A selected revision's store files, read back from the bundle pinned for it. */
+async function revisionFromPublished({ slug, chosen, pins, published, mirror, fetchObject, packsRoot }) {
+ const pin = holodeckBundlePin(pins, slug);
+ if (!pin) throw new Error(`No editable bundle is pinned for ${slug}: its Kiln store is its only copy`);
+ const bundle = await readPinnedObject(pin, { mirror, published, fetchObject });
+ const manifestBytes = await readFile(join(packsRoot, `sources/${chosen.collection}/${chosen.assetId}/${chosen.revisionId}/manifest.json`));
+ return { pin, members: holodeckRevisionFromBundle({ slug, chosen, bundle, manifestBytes }) };
+}
+
+/**
+ * Materialise a Kiln store from the published editable bundles, so a lost store can be rebuilt. Each revision is
+ * written to `<out>/<assetId>/revisions/<revisionId>` exactly as its store held it; an existing file must already
+ * hold those bytes.
+ */
+export async function recoverHolodeckStore({ out, only, mirror, selectionFile = join(PACKS_ROOT, 'selection.json'), site = SITE, packsRoot = PACKS_ROOT, fetchObject = fetchAssetObject }) {
+ if (!out) throw new Error('An explicit output store directory is required');
const selection = json(await readFile(selectionFile));
+ const pins = (await readJson(join(site, 'src/data/mirror-manifest.json'))).files;
+ const published = await readLedger(join(packsRoot, 'published.json'));
+ const revisions = [];
+ for (const [slug, chosen] of Object.entries(selection.assets)) {
+ if (only && !only.includes(slug)) continue;
+ const { pin, members } = await revisionFromPublished({ slug, chosen, pins, published, mirror, fetchObject, packsRoot });
+ for (const [name, bytes] of Object.entries(members)) await writeImmutable(out, `${chosen.assetId}/revisions/${chosen.revisionId}/${name}`, bytes);
+ revisions.push({ slug, store: chosen.store, assetId: chosen.assetId, revisionId: chosen.revisionId, bundle: pin.path });
+ }
+ const unknown = (only ?? []).filter((slug) => !revisions.some((record) => record.slug === slug));
+ if (unknown.length) throw new Error(`Not selected: ${unknown.join(', ')}`);
+ return { store: out, revisions };
+}
+
+/**
+ * Suggest the next free `<stem>-<NN>` after a release ID that is already spent, keeping the counter's width.
+ */
+export function nextHolodeckRelease(release, taken) {
+ const match = /^(.*)-(\d+)$/.exec(release);
+ if (!match) return undefined;
+ const [, stem, counter] = match;
+ for (let next = Number(counter) + 1; next < Number(counter) + 100; next++) {
+ const candidate = `${stem}-${String(next).padStart(counter.length, '0')}`;
+ if (!taken.has(candidate)) return candidate;
+ }
+ return undefined;
+}
+
+/**
+ * A release ID names one staged state. `releases.json` records every ID a release has spent and the selection it
+ * staged, so a branch cannot quietly reuse an ID another branch already spent on different content: #272 and #273
+ * both did, and five generated files had to be merged entry by entry afterwards. Restaging the same selection under
+ * the same ID is the normal release loop and changes nothing. An ID recorded without its selection was used before
+ * this ledger existed and cannot be reclaimed, because nothing can show it described the same content.
+ */
+export function claimHolodeckRelease({ release, selection, recorded }) {
+ const releases = new Map((recorded?.releases ?? []).map((record) => [record.release, record]));
+ const seal = { bytes: selection.length, sha256: hashBytes(selection) };
+ const prior = releases.get(release);
+ if (prior && !(prior.selection && sameObject(prior.selection, seal))) {
+ const free = nextHolodeckRelease(release, new Set(releases.keys()));
+ const held = prior.selection ? `a different selection (${prior.selection.sha256.slice(0, 12)})` : 'content this ledger did not record';
+ throw new Error(`Release ${release} already staged ${held}: choose a new HOLODECK_RELEASE${free ? `, such as ${free}` : ''}`);
+ }
+ releases.set(release, { release, selection: seal });
+ return { schemaVersion: 1, releases: [...releases.values()].sort((a, b) => a.release.localeCompare(b.release, 'en')) };
+}
+
+/**
+ * Stage the selection, recovering any revision whose store is gone from its published bundle. The recovery workspace
+ * is a throwaway copy of those revisions; the stores themselves stay read-only.
+ */
+export async function stageHolodeck(options) {
+ const recovery = { revisions: [], bundles: new Map() };
+ try { return await stageSelection(options, recovery); }
+ finally { if (recovery.root) await rm(recovery.root, { recursive: true, force: true }); }
+}
+
+async function stageSelection({ kiln, mirror, stores, selectionFile = join(PACKS_ROOT, 'selection.json'), site = SITE, packsRoot = PACKS_ROOT, exporter = runtimeExport, packs: packSpecs = HOLODECK_PACKS, presentations = HOLODECK_ASSETS, approved = holodeckApproved, fetchObject = fetchAssetObject }, recovery) {
+ if (!kiln || !mirror || !stores) throw new Error('An explicit Kiln package, mirror and store set are required');
+ const selectionBytes = await readFile(selectionFile), selection = json(selectionBytes);
if (selection.schemaVersion !== 1 || selection.licence !== 'CC0-1.0' || !/^[a-z0-9-]+$/.test(selection.release)) throw new Error('Invalid Holodeck selection');
+ const releaseFile = join(packsRoot, 'releases.json');
+ let recordedReleases;
+ try { recordedReleases = await readJson(releaseFile); } catch (error) { if (error.code !== 'ENOENT') throw error; }
+ const releases = claimHolodeckRelease({ release: selection.release, selection: selectionBytes, recorded: recordedReleases });
const kilnVersion = json(await readFile(join(kiln, 'package.json'))).version;
const release = selection.release;
const licence = holodeckLicence(), cc0 = await readFile(join(packsRoot, 'LICENSES/CC0-1.0.txt'));
+ const manifestFile = join(site, 'src/data/mirror-manifest.json'), planFile = join(site, 'src/data/commons-build.json');
+ const pins = await readJson(manifestFile), published = await readLedger(join(packsRoot, 'published.json'));
const output = new Map(), names = new Set(), lightweight = new Map(), staged = {};
const add = (name, bytes) => {
if (names.has(name)) throw new Error(`Duplicate staged output: ${name}`);
@@ -111,8 +247,16 @@ export async function stageHolodeck({ kiln, mirror, stores, selectionFile = join
for (const [slug, chosen] of Object.entries(selection.assets)) {
const presentation = presentations[slug];
if (!presentation) throw new Error(`No gallery presentation for ${slug}`);
- if (!stores[chosen.store]) throw new Error(`No --store given for ${chosen.store}`);
- const revisionDir = join(stores[chosen.store], chosen.assetId, 'revisions', chosen.revisionId);
+ let revisionDir = stores[chosen.store] && join(stores[chosen.store], chosen.assetId, 'revisions', chosen.revisionId);
+ if (!revisionDir || !existsSync(revisionDir)) {
+ // The store is gone or no longer holds this revision: read it back from the bundle the release published.
+ const { pin, members } = await revisionFromPublished({ slug, chosen, pins: pins.files, published, mirror, fetchObject, packsRoot });
+ recovery.root ??= await mkdtemp(join(tmpdir(), 'kiln-holodeck-recovered-'));
+ revisionDir = join(recovery.root, chosen.assetId, 'revisions', chosen.revisionId);
+ for (const [name, bytes] of Object.entries(members)) await writeImmutable(recovery.root, `${chosen.assetId}/revisions/${chosen.revisionId}/${name}`, bytes);
+ recovery.revisions.push({ slug, store: chosen.store, assetId: chosen.assetId, revisionId: chosen.revisionId, bundle: pin.path });
+ recovery.bundles.set(slug, pin.path);
+ }
const manifestBytes = verifyBytes(await readFile(join(revisionDir, 'manifest.json')), chosen.manifest, `${slug} manifest`);
const manifest = json(manifestBytes);
if (manifest.assetId !== chosen.assetId || manifest.revisionId !== chosen.revisionId || !manifest.editable) throw new Error(`${slug}: saved revision identity differs from the selection`);
@@ -144,6 +288,10 @@ export async function stageHolodeck({ kiln, mirror, stores, selectionFile = join
};
const editable = revisionBundle({ manifest, files, ...(materialResources ? { materialResources } : {}) });
verifyArchive(editable, 'editable');
+ // Object keys are content addresses, so a wrong input would quietly land at a new key rather than fail. A
+ // recovered revision must rebuild the very bundle it was read from.
+ const recoveredFrom = recovery.bundles.get(slug);
+ if (recoveredFrom && holodeckObjectPath(`${slug}-editable.zip`, editable) !== recoveredFrom) throw new Error(`${slug}: rebuilding from ${recoveredFrom} did not reproduce it byte for byte`);
const runtimeFiles = { [`models/${slug}.glb`]: runtime, [`models/${slug}.kiln-metadata.json`]: metadata, 'LICENSE.txt': licence, 'LICENSES/CC0-1.0.txt': cc0 };
const identity = `${chosen.collection}/${manifest.assetId}/${manifest.revisionId}`;
lightweight.set(`sources/${identity}/source.kiln.js`, source);
@@ -201,8 +349,6 @@ export async function stageHolodeck({ kiln, mirror, stores, selectionFile = join
try { if (!(await readFile(join(packsRoot, path))).equals(bytes)) throw new Error(`Existing source record conflict: ${path}`); }
catch (error) { if (error.code !== 'ENOENT') throw error; }
}
- const manifestFile = join(site, 'src/data/mirror-manifest.json'), planFile = join(site, 'src/data/commons-build.json');
- const pins = await readJson(manifestFile);
for (const [path, bytes] of output) {
const prior = pins.files.find((record) => record.path === path);
if (prior && (prior.sha256 !== hashBytes(bytes) || prior.bytes !== bytes.length)) throw new Error(`A different file is already pinned at ${path}; use a new release`);
@@ -227,7 +373,8 @@ export async function stageHolodeck({ kiln, mirror, stores, selectionFile = join
packs, planned: HOLODECK_PLANNED, assets,
};
await writeJson(join(site, 'src/data/holodeck.json'), catalog);
- return { catalog, files: output.size, bytes: [...output.values()].reduce((sum, bytes) => sum + bytes.length, 0) };
+ await writeJson(releaseFile, releases);
+ return { catalog, files: output.size, bytes: [...output.values()].reduce((sum, bytes) => sum + bytes.length, 0), recovered: recovery.revisions };
}
export const HOLODECK_SHOTS_DIR = `media/${HOLODECK_ID}/scenes/`;
@@ -346,9 +493,13 @@ if (process.argv[1] && pathToFileURL(resolve(process.argv[1])).href === import.m
if (flag === '--store') { const [name, dir] = value.split(/=(.*)/s); options.stores[name] = await realpath(dir); }
else if (['--kiln', '--mirror', '--captures'].includes(flag)) options[flag.slice(2)] = resolve(value);
else if (flag === '--record-published') options.receipt = resolve(value);
+ else if (flag === '--recover-store') options.out = resolve(value);
+ else if (flag === '--only') options.only = value.split(',');
else throw new Error(`Unknown option ${flag}`);
}
- if (shots) {
+ if (options.out) {
+ console.log(JSON.stringify(await recoverHolodeckStore(options), null, 2));
+ } else if (shots) {
const record = await stageHolodeckShots(options);
console.log(JSON.stringify({ shots: Object.fromEntries(Object.entries(record.packs).map(([id, images]) => [id, images.map((image) => image.inputPath)])) }, null, 2));
} else if (options.receipt) {
@@ -359,7 +510,7 @@ if (process.argv[1] && pathToFileURL(resolve(process.argv[1])).href === import.m
await writeFile(file, JSON.stringify(records, null, 2) + '\n');
console.log(JSON.stringify({ file, files: records.length, bytes: records.reduce((sum, record) => sum + record.bytes, 0) }, null, 2));
} else {
- const { catalog, files, bytes } = await stageHolodeck(options);
- console.log(JSON.stringify({ release: catalog.release, files, bytes, packs: catalog.packs.map((pack) => ({ id: pack.id, assets: pack.assetCount, downloads: pack.downloads.map((d) => ({ profile: d.profile, bytes: d.bytes, sha256: d.sha256 })) })) }, null, 2));
+ const { catalog, files, bytes, recovered } = await stageHolodeck(options);
+ console.log(JSON.stringify({ release: catalog.release, files, bytes, recovered, packs: catalog.packs.map((pack) => ({ id: pack.id, assets: pack.assetCount, downloads: pack.downloads.map((d) => ({ profile: d.profile, bytes: d.bytes, sha256: d.sha256 })) })) }, null, 2));
}
}
diff --git a/site/scripts/stage-holodeck.test.ts b/site/scripts/stage-holodeck.test.ts
index 43b19ba8..7819f1d4 100644
--- a/site/scripts/stage-holodeck.test.ts
+++ b/site/scripts/stage-holodeck.test.ts
@@ -1,9 +1,10 @@
import { afterEach, expect, test } from 'bun:test';
+import { unzipSync, zipSync } from 'fflate';
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { dirname, join } from 'node:path';
import { hashBytes, verifyArchive } from './mirror-core.mjs';
-import { holodeckObjectPath, holodeckUploadList, recordHolodeckPublished, stageHolodeck } from './stage-holodeck.mjs';
+import { holodeckObjectPath, holodeckUploadList, recordHolodeckPublished, recoverHolodeckStore, stageHolodeck } from './stage-holodeck.mjs';
const directories: string[] = [];
afterEach(async () => { for (const d of directories.splice(0)) await rm(d, { recursive: true, force: true }); });
@@ -52,14 +53,16 @@ async function fixture() {
type Fixture = Awaited<ReturnType<typeof fixture>>;
const PACK = (id: string, expectedAssets: number) => ({ id, scene: id, name: id, description: `The ${id} pack.`, expectedAssets });
+const selectionPath = (f: Fixture, release: string) => join(f.root, `selection-${release}.json`);
+
/** Stage one release: each pack lists its slugs, and every slug records the packs that place it. */
-async function stageRelease(f: Fixture, release: string, packs: Record<string, string[]>) {
+async function stageRelease(f: Fixture, release: string, packs: Record<string, string[]>, overrides: Record<string, unknown> = {}) {
const assets = JSON.parse(JSON.stringify(f.assets));
for (const [pack, slugs] of Object.entries(packs)) for (const slug of slugs) assets[slug].placements.push({ pack });
const used = Object.fromEntries(Object.entries(assets).filter(([, record]: [string, any]) => record.placements.length));
- const selectionFile = join(f.root, `selection-${release}.json`);
+ const selectionFile = selectionPath(f, release);
await put(selectionFile, JSON.stringify({ schemaVersion: 1, release, licence: 'CC0-1.0', versions: 'final-only', packs: Object.fromEntries(Object.entries(packs).map(([id, slugs]) => [id, { assets: slugs, source: { kind: 'fixture' } }])), assets: used }));
- return stageHolodeck({ kiln: f.kiln, mirror: f.mirror, stores: { fixture: f.store }, selectionFile, site: f.site, packsRoot: f.packsRoot, exporter: f.exporter, packs: Object.entries(packs).map(([id, slugs]) => PACK(id, slugs.length)), presentations, approved: () => true });
+ return stageHolodeck({ kiln: f.kiln, mirror: f.mirror, stores: { fixture: f.store }, selectionFile, site: f.site, packsRoot: f.packsRoot, exporter: f.exporter, packs: Object.entries(packs).map(([id, slugs]) => PACK(id, slugs.length)), presentations, approved: () => true, ...overrides });
}
/** Record a poster per staged model, as scripts/rig-posters.mjs does, then stage again so the catalog shows them. */
@@ -152,3 +155,117 @@ test('immutable keys refuse different bytes in the mirror, the ledger and the re
await writeFile(join(f.mirror, model.path), Buffer.from('tampered'));
await expect(stageRelease(f, 'holodeck-fixture-02', { 'holodeck-cove': ['shell'] })).rejects.toThrow('differs');
});
+
+const COVE = { 'holodeck-cove': ['shell', 'palm'] };
+const bundlePath = (catalog: any, slug: string) => catalog.assets.find((asset: any) => asset.slug === slug).editableDownload.path;
+
+test('a lost store restages byte-identical packs from the published editable bundles and says which', async () => {
+ const f = await fixture();
+ const first = (await stageRelease(f, 'holodeck-fixture-01', COVE)).catalog;
+ // The store is gone. Every revision is read back from the editable bundle the release published, which the
+ // mirror still holds at its content-addressed key.
+ const again = await stageRelease(f, 'holodeck-fixture-01', COVE, { stores: {} });
+ expect(again.recovered).toEqual([
+ { slug: 'shell', store: 'fixture', assetId: ids('shell').assetId, revisionId: ids('shell').revisionId, bundle: bundlePath(first, 'shell') },
+ { slug: 'palm', store: 'fixture', assetId: ids('palm').assetId, revisionId: ids('palm').revisionId, bundle: bundlePath(first, 'palm') },
+ ]);
+ expect(downloads(again.catalog)).toEqual(downloads(first));
+ expect(again.catalog).toEqual(first);
+});
+
+test('a named store that lacks the selected revision falls back for that revision alone', async () => {
+ const f = await fixture();
+ const first = (await stageRelease(f, 'holodeck-fixture-01', COVE)).catalog;
+ await rm(join(f.store, ids('palm').assetId), { recursive: true });
+ const again = await stageRelease(f, 'holodeck-fixture-01', COVE);
+ expect(again.recovered.map((record: any) => record.slug)).toEqual(['palm']);
+ expect(again.catalog).toEqual(first);
+});
+
+test('a published bundle whose bytes differ from its pin is refused', async () => {
+ const f = await fixture();
+ const first = (await stageRelease(f, 'holodeck-fixture-01', COVE)).catalog;
+ await writeFile(join(f.mirror, bundlePath(first, 'shell')), Buffer.from('tampered'));
+ await expect(stageRelease(f, 'holodeck-fixture-01', COVE, { stores: {} })).rejects.toThrow('SHA-256');
+});
+
+/** Pin `bytes` as `<slug>-editable.zip`, optionally in place of the object already pinned under that name. */
+async function pinAsBundle(f: Fixture, slug: string, bytes: Buffer, { replace = true } = {}) {
+ const path = holodeckObjectPath(`${slug}-editable.zip`, bytes);
+ await put(join(f.mirror, path), bytes);
+ const pins = JSON.parse(await readFile(join(f.site, 'src/data/mirror-manifest.json'), 'utf8'));
+ const kept = replace ? pins.files.filter((pin: { path: string }) => !pin.path.endsWith(`/${slug}-editable.zip`)) : pins.files;
+ await put(join(f.site, 'src/data/mirror-manifest.json'), JSON.stringify({ ...pins, files: [...kept, { path, ...seal(bytes) }] }));
+}
+
+test('a bundle pinned under one asset name that holds another revision is refused', async () => {
+ const f = await fixture();
+ const first = (await stageRelease(f, 'holodeck-fixture-01', COVE)).catalog;
+ // An object that verifies against its pin but carries the palm revision under the shell's readable name.
+ const palm = await readFile(join(f.mirror, bundlePath(first, 'palm')));
+ await pinAsBundle(f, 'shell', palm, { replace: false });
+ await expect(stageRelease(f, 'holodeck-fixture-01', COVE, { stores: {} })).rejects.toThrow('More than one object is pinned');
+ await pinAsBundle(f, 'shell', palm);
+ await expect(stageRelease(f, 'holodeck-fixture-01', COVE, { stores: {} })).rejects.toThrow('not the selected revision');
+});
+
+test('a bundle that no longer rebuilds byte for byte is refused rather than landing at a new key', async () => {
+ const f = await fixture();
+ const first = (await stageRelease(f, 'holodeck-fixture-01', COVE)).catalog;
+ // The same revision, sealed members and all, packed with different ZIP settings: every hash the selection freezes
+ // still verifies, so only rebuilding the object catches it.
+ const members = unzipSync(await readFile(join(f.mirror, bundlePath(first, 'shell'))));
+ const repacked = Buffer.from(zipSync(Object.fromEntries(Object.keys(members).sort().map((name) => [name, [members[name]!, { level: 0, mtime: new Date(1980, 0, 1) }] as const]))));
+ await pinAsBundle(f, 'shell', repacked);
+ await expect(stageRelease(f, 'holodeck-fixture-01', COVE, { stores: {} })).rejects.toThrow('did not reproduce it byte for byte');
+});
+
+test('a bundle missing from the mirror comes from the asset host, and only once it served it back', async () => {
+ const f = await fixture();
+ const first = (await stageRelease(f, 'holodeck-fixture-01', COVE)).catalog;
+ const shell = bundlePath(first, 'shell');
+ const served = await readFile(join(f.mirror, shell));
+ await rm(join(f.mirror, shell));
+ const asked: string[] = [];
+ const fetchObject = async (url: string) => { asked.push(url); return served; };
+ // Nothing in the ledger: the host has never served this object, so staging says so rather than guessing a URL.
+ await expect(stageRelease(f, 'holodeck-fixture-01', COVE, { stores: {}, fetchObject })).rejects.toThrow('published.json');
+ await put(join(f.packsRoot, 'published.json'), JSON.stringify({ schemaVersion: 1, objects: [{ path: shell, bytes: served.length, sha256: hashBytes(served) }] }));
+ const again = await stageRelease(f, 'holodeck-fixture-01', COVE, { stores: {}, fetchObject });
+ expect(asked).toEqual([`https://assets.kilnstudio.tools/${shell}`]);
+ expect(again.catalog).toEqual(first);
+});
+
+test('the recovery command rebuilds a store whose revisions are the stored bytes', async () => {
+ const f = await fixture();
+ await stageRelease(f, 'holodeck-fixture-01', COVE);
+ const out = join(f.root, 'recovered');
+ const recovered = await recoverHolodeckStore({ out, mirror: f.mirror, selectionFile: selectionPath(f, 'holodeck-fixture-01'), site: f.site, packsRoot: f.packsRoot });
+ expect(recovered.revisions.map((record: any) => record.slug)).toEqual(['shell', 'palm']);
+ for (const slug of ['shell', 'palm']) {
+ const { assetId, revisionId } = ids(slug);
+ for (const name of ['manifest.json', 'asset.glb', 'source.kiln.js', 'preview.png']) {
+ const where = join(assetId, 'revisions', revisionId, name);
+ expect(await readFile(join(out, where))).toEqual(await readFile(join(f.store, where)));
+ }
+ }
+ // A store rebuilt this way stages on its own: nothing falls back to a bundle.
+ const again = await stageRelease(f, 'holodeck-fixture-01', COVE, { stores: { fixture: out } });
+ expect(again.recovered).toEqual([]);
+});
+
+test('a release ID that already staged other content is refused, with the next free one', async () => {
+ const f = await fixture();
+ const ledger = join(f.packsRoot, 'releases.json');
+ await stageRelease(f, 'holodeck-fixture-01', COVE);
+ expect(JSON.parse(await readFile(ledger, 'utf8')).releases.map((record: any) => record.release)).toEqual(['holodeck-fixture-01']);
+ // Two packs staged in parallel both saw the same previous release and both chose the same next ID.
+ await expect(stageRelease(f, 'holodeck-fixture-01', { 'holodeck-cove': ['shell'] })).rejects.toThrow('holodeck-fixture-02');
+ // Restaging the same selection under the same ID is the normal release loop and adds nothing.
+ expect((await stageRelease(f, 'holodeck-fixture-01', COVE)).catalog.release).toBe('holodeck-fixture-01');
+ await stageRelease(f, 'holodeck-fixture-02', { 'holodeck-cove': ['shell'] });
+ expect(JSON.parse(await readFile(ledger, 'utf8')).releases.map((record: any) => record.release)).toEqual(['holodeck-fixture-01', 'holodeck-fixture-02']);
+ // An ID recorded as used but whose selection is unknown cannot be claimed either.
+ await put(ledger, JSON.stringify({ schemaVersion: 1, releases: [{ release: 'holodeck-fixture-03' }] }));
+ await expect(stageRelease(f, 'holodeck-fixture-03', COVE)).rejects.toThrow('holodeck-fixture-04');
+});
diff --git a/site/src/data/rig-posters.json b/site/src/data/rig-posters.json
index 88095cd1..e8ec9753 100644
--- a/site/src/data/rig-posters.json
+++ b/site/src/data/rig-posters.json
@@ -3,8 +3,10 @@
"rig": {
"id": "review-neutral-v1",
"backdrop": "neutral",
- "runs": {
- "farm": {
+ "runs": [
+ {
+ "id": "farm-2026-10-01-a2452dec",
+ "pack": "farm",
"renderedOn": "2026-10-01",
"engine": {
"commit": "ac6d9eb492b4891a54dbf563cfef14af5633254a",
@@ -38,7 +40,9 @@
]
}
},
- "bridge": {
+ {
+ "id": "bridge-2026-09-30-c5055c42",
+ "pack": "bridge",
"renderedOn": "2026-09-30",
"engine": {
"commit": "5af4341e65a1c5131a9ad5bb5110046be925f29e",
@@ -72,7 +76,9 @@
]
}
},
- "vehicles": {
+ {
+ "id": "vehicles-2026-10-01-784df044",
+ "pack": "vehicles",
"renderedOn": "2026-10-01",
"engine": {
"commit": "ac6d9eb492b4891a54dbf563cfef14af5633254a",
@@ -106,7 +112,9 @@
]
}
},
- "foundry-floor": {
+ {
+ "id": "foundry-floor-2026-09-30-d94dcc68",
+ "pack": "foundry-floor",
"renderedOn": "2026-09-30",
"engine": {
"commit": "ac6d9eb492b4891a54dbf563cfef14af5633254a",
@@ -140,7 +148,9 @@
]
}
},
- "hero": {
+ {
+ "id": "hero-2026-09-30-c5055c42",
+ "pack": "hero",
"renderedOn": "2026-09-30",
"engine": {
"commit": "5af4341e65a1c5131a9ad5bb5110046be925f29e",
@@ -174,7 +184,9 @@
]
}
},
- "cabin-woods-psx-horror": {
+ {
+ "id": "cabin-woods-psx-horror-2026-10-17-544b2fcc",
+ "pack": "cabin-woods-psx-horror",
"renderedOn": "2026-10-17",
"engine": {
"commit": "2d359d8b006288beb77f7eea6581a1b8c376eedf",
@@ -208,7 +220,9 @@
]
}
},
- "holodeck": {
+ {
+ "id": "holodeck-2026-10-26-a5c7f75c",
+ "pack": "holodeck",
"renderedOn": "2026-10-26",
"engine": {
"commit": "6ff8f8ab89cdb7e31ec46613fea601d9ab55f95a",
@@ -242,7 +256,7 @@
]
}
}
- }
+ ]
},
"posters": {
"farm:farmhouse": {