Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions website/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public/assets/demo/
public/assets/product.css
public/assets/fonts.css
public/demo/transport.js
public/demo/library.json
public/demo/api/
test-results/
.impeccable/*
Expand Down
2 changes: 1 addition & 1 deletion website/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ receipts, recipe fingerprints and asset hashes are recorded in the public
build manifest and export provenance. This is a tagged-source rebuild, not a
measurement of installed npm tarballs.

Every publishing run regenerates the demo bundle, product CSS, all PNG/PDF
Every publishing run regenerates the demo bundle and its library file, product CSS, all PNG/PDF
share exports and four fallback screenshots from the selected product UI. It then typechecks integration and runs real Chromium smoke checks of
all four embedded views, plus end-to-end ranking/submission, scenario switching,
allow/deny, dictation/edit/send, file navigation/frontmatter, wiki links,
Expand Down
1 change: 0 additions & 1 deletion website/public/demo/library.json

This file was deleted.

17 changes: 14 additions & 3 deletions website/scripts/check-publication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import assert from 'node:assert/strict';
import { mkdtemp, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { resolve } from 'node:path';
import { sourceInputHash, snapshotName } from './publication-source.ts';
import { sourceInputDigests, sourceInputHash, snapshotName } from './publication-source.ts';

const built = await Bun.file(resolve(import.meta.dir, '../dist/build-manifest.json')).json();
assert(Object.keys(built.files).length > 0, 'The artifact fixture must have emitted files');
const root = await mkdtemp(resolve(tmpdir(), 'brain-kit-pages-proof-'));
await Bun.write(resolve(root, 'source.txt'), 'unchanged build input\n');
const clean = { ...built, dirty: false, base: '/brain-kit/' };
const snapshot = { sourceSha: built.sourceSha, sourceDirty: false, brainKit: built.brainKit, inputHash: await sourceInputHash(root) };
const snapshot = { sourceSha: built.sourceSha, sourceDirty: false, brainKit: built.brainKit, inputHash: await sourceInputHash(root), inputFiles: await sourceInputDigests(root) };
const shares = { sourceSha: built.sourceSha, recipeHash: built.exportRecipeHash, brainKit: built.brainKit };
const previews = await Bun.file(resolve(import.meta.dir, '../dist/assets/previews/provenance.json')).json();
async function check(manifest = clean, source = snapshot, exports = shares, failure?: string) {
Expand All @@ -35,11 +35,22 @@ try {
await check(clean, snapshot, { ...shares, recipeHash: 'stale' }, 'Exports were not regenerated');
await check(clean, snapshot, { ...shares, brainKit: { ...shares.brainKit, version: '0.0.0' } }, 'Exports belong to another product build');
await Bun.write(resolve(root, 'source.txt'), 'unexpected source mutation\n');
await check(clean, snapshot, shares, 'Publication source inputs changed during the build');
await check(clean, snapshot, shares, 'Publication source inputs changed during the build: modified source.txt');
await Bun.write(resolve(root, 'source.txt'), 'unchanged build input\n');
await check();
// The product build takes the workspace output lease (scripts/workspace-lease.mjs).
await Bun.write(resolve(root, 'tmp/workspace-operation/output.lock'), '');
await check();
// ...and leaves its receipt beside it (scripts/build-receipt.ts).
await Bun.write(resolve(root, 'tmp/build-4242-00000000-0000-0000-0000-000000000000-probe.json'), '{}');
await check();
// The demo build regenerates the worker's library file (website/scripts/build.ts).
await Bun.write(resolve(root, 'website/public/demo/library.json'), '{}');
await check();
// Anything else under tmp/ is still a source input.
await Bun.write(resolve(root, 'tmp/notes.json'), '{}');
await check(clean, snapshot, shares, 'Publication source inputs changed during the build: added tmp/notes.json');
await rm(resolve(root, 'tmp/notes.json'));
await check();
console.log('Publication proof passed: matching artifact accepted; dirty/changed source, wrong website/product/base and stale or mismatched exports refused by the actual publication command.');
} finally { await rm(root, { recursive: true, force: true }); }
4 changes: 2 additions & 2 deletions website/scripts/prepare-publication.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { cp, mkdir, rm } from 'node:fs/promises';
import { resolve } from 'node:path';
import { sourceInputHash, snapshotName } from './publication-source.ts';
import { sourceInputDigests, sourceInputHash, snapshotName } from './publication-source.ts';

const repository = resolve(import.meta.dir, '../..');
const output = process.env.PUBLICATION_WORKSPACE;
Expand Down Expand Up @@ -44,6 +44,6 @@ if (tag) {
}
}
const brainKit = { mode: tag ? 'release' : 'workspace', version: product.version, sourceSha: productSha, tag: tag || null, registry };
await Bun.write(resolve(output, snapshotName), JSON.stringify({ schemaVersion: 1, sourceSha, sourceDirty, brainKit, editorialRoot: repository, editorialInputHash: await sourceInputHash(repository), inputHash: await sourceInputHash(output) }, null, 2) + '\n');
await Bun.write(resolve(output, snapshotName), JSON.stringify({ schemaVersion: 1, sourceSha, sourceDirty, brainKit, editorialRoot: repository, editorialInputHash: await sourceInputHash(repository), inputHash: await sourceInputHash(output), inputFiles: await sourceInputDigests(output) }, null, 2) + '\n');
if (process.env.GITHUB_ENV) await Bun.write(process.env.GITHUB_ENV, (await Bun.file(process.env.GITHUB_ENV).text()) + `PAGES_WORKSPACE=${output}\nWEBSITE_SOURCE_SHA=${sourceSha}\nWEBSITE_CONTENT_ROOT=${repository}\nEXPECTED_BRAIN_KIT_SHA=${productSha}\nEXPECTED_BRAIN_KIT_TAG=${tag}\n`);
console.log(JSON.stringify({ website: sourceSha, brainKit, workspace: output }, null, 2));
25 changes: 21 additions & 4 deletions website/scripts/publication-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import { resolve } from 'node:path';
import { readdir } from 'node:fs/promises';

export const snapshotName = '.website-source.json';
// Only build outputs may change in the isolated publication workspace.
const generated = [snapshotName, '**/node_modules/**', '**/dist/**', '**/.astro/**', '**/.git/**', 'website/.impeccable/review/**', 'website/test-results/**', 'website/public/assets/demo/**', 'website/public/assets/shares/**', 'website/public/assets/previews/**', 'website/public/assets/product.css', 'website/public/assets/fonts.css', 'website/public/demo/transport.js', 'website/public/demo/api/**', 'tmp/workspace-operation/**'];
export async function sourceInputHash(root: string) {
// Only build outputs may change in the isolated publication workspace. The
// product build adds its lease and a per-build receipt under tmp/
// (scripts/workspace-lease.mjs, scripts/build-receipt.ts); website/scripts/build.ts
// writes the demo bundle, its transport, its library file and its HTML route.
const generated = [snapshotName, '**/node_modules/**', '**/dist/**', '**/.astro/**', '**/.git/**', 'website/.impeccable/review/**', 'website/test-results/**', 'website/public/assets/demo/**', 'website/public/assets/shares/**', 'website/public/assets/previews/**', 'website/public/assets/product.css', 'website/public/assets/fonts.css', 'website/public/demo/transport.js', 'website/public/demo/library.json', 'website/public/demo/api/**', 'tmp/workspace-operation/**', 'tmp/build-*-probe.json', 'tmp/build-*-probe.json.writing'];
async function sourceInputPaths(root: string) {
const paths: string[] = [];
async function walk(directory = '') {
for (const entry of await readdir(resolve(root, directory), { withFileTypes: true })) {
Expand All @@ -16,7 +19,21 @@ export async function sourceInputHash(root: string) {
}
}
await walk();
return paths.sort();
}
export async function sourceInputHash(root: string) {
const hash = createHash('sha256');
for (const path of paths.sort()) { hash.update(path); hash.update('\0'); hash.update(new Uint8Array(await Bun.file(resolve(root, path)).arrayBuffer())); }
for (const path of await sourceInputPaths(root)) { hash.update(path); hash.update('\0'); hash.update(new Uint8Array(await Bun.file(resolve(root, path)).arrayBuffer())); }
return hash.digest('hex');
}
// Per-file digests let a changed input be named instead of only detected.
export async function sourceInputDigests(root: string) {
const digests: Record<string, string> = {};
for (const path of await sourceInputPaths(root)) digests[path] = createHash('sha256').update(new Uint8Array(await Bun.file(resolve(root, path)).arrayBuffer())).digest('hex');
return digests;
}
export function describeInputChanges(before: Record<string, string> | undefined, after: Record<string, string>) {
if (!before) return '';
const changed = [...new Set([...Object.keys(before), ...Object.keys(after)])].sort().flatMap(path => !(path in after) ? [`removed ${path}`] : !(path in before) ? [`added ${path}`] : before[path] !== after[path] ? [`modified ${path}`] : []);
return changed.length ? `: ${changed.slice(0, 20).join(', ')}${changed.length > 20 ? ` and ${changed.length - 20} more` : ''}` : '';
}
5 changes: 3 additions & 2 deletions website/scripts/verify-publication.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import assert from 'node:assert/strict';
import { resolve } from 'node:path';
import { createHash } from 'node:crypto';
import { sourceInputHash, snapshotName } from './publication-source.ts';
import { describeInputChanges, sourceInputDigests, sourceInputHash, snapshotName } from './publication-source.ts';

const root = process.argv[2] ? resolve(process.argv[2]) : resolve(import.meta.dir, '../..');
const snapshot = await Bun.file(resolve(root, snapshotName)).json();
const file = Bun.file(resolve(root, 'website/dist/build-manifest.json'));
const manifest = await file.json();
assert.equal(snapshot.sourceDirty, false, 'Website checkout was dirty');
assert.equal(await sourceInputHash(root), snapshot.inputHash, 'Publication source inputs changed during the build');
const inputHash = await sourceInputHash(root);
assert.equal(inputHash, snapshot.inputHash, inputHash === snapshot.inputHash ? '' : `Publication source inputs changed during the build${describeInputChanges(snapshot.inputFiles, await sourceInputDigests(root))}`);
if (snapshot.editorialRoot) assert.equal(await sourceInputHash(snapshot.editorialRoot), snapshot.editorialInputHash, 'Canonical editorial inputs changed during the build');
assert.equal(manifest.sourceSha, process.env.WEBSITE_SOURCE_SHA, 'Website source does not match the selected commit');
assert.equal(manifest.dirty, false, 'Artifact has changed source inputs');
Expand Down
Loading