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
16 changes: 14 additions & 2 deletions sdk/npm/prism-code/scripts/check-package.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
// Validate npm's pack manifest against the reviewed distribution inventory.
// Run after npm pack --dry-run --json > pack.json, as npm-prism-code.yml does.
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { readdirSync, readFileSync } from 'node:fs';
import { pathToFileURL } from 'node:url';

export const PACKAGE_LIMIT = 1622016; // 1584 KiB: 1088 KiB plus 72 KiB for setup, open and the bundled prism skill (about 63 KiB), plus 48 KiB for the machine half of setup, the build tiers, axioms and init's next steps (about 44 KiB), plus 112 KiB for prism-code mcp, the guided journey (about 110 KiB), plus 4 KiB for closure v2 provenance verification and the Hologram studio stylesheet (about 2.7 KiB), plus 24 KiB for the hosted tiers: hosted.mjs, the routing of build --check and verify --lean, and their docs (about 24.6 KiB), plus 4 KiB for the journey's hosted proof (about 6.7 KiB, with the 0.9 KiB left before it), plus 40 KiB for build --remote github: the GitHub client, the artifact reader and the checks of what comes back, with its docs and skill section (about 37.8 KiB), plus 4 KiB for the first-run fixes: the lockfile found above app/, per-verb --help, located hosted diagnostics and their docs (about 5.0 KiB, with the 2.2 KiB left before them), plus 20 KiB for the first run without Docker: setup's next steps and --local, the journey choosing GitHub Actions, the approved repository and the pinned template files (about 16.5 KiB), plus 28 KiB for template instances: the files that make a journey app an instance of UOR-Foundation/template, the canonical LexLean layout, the repository made from the template and the live check (about 24 KiB), plus 12 KiB for specs drafted from one sentence: the input schema of prism_spec, reasons, meanings and limits, and SPEC.md in the OpenSpec format (about 14 KiB, with the 4 KiB left before it), plus 20 KiB for gap telemetry: gaps.mjs, the rule each refusal names, the round-trip check, delivery in a hosted call's _meta, and their docs (about 16.5 KiB), plus 4 KiB for the verifier refusing what the Wire codec refuses (about 2.4 KiB), plus 4 KiB for refusing an altered holo in load (#583, about 2 KiB), plus 56 KiB for the nine modules on one client: prism.images (#442, about 26 KiB), prism.system with its event bus (#446, about 12 KiB), and the client of #441 with containers.list and prune (about 12 KiB), plus 20 KiB for generate --lang rust: the Rust writer (about 19.2 KiB), plus 20 KiB for generate --lang python: the Python writer and its docs (about 18.5 KiB), plus 4 KiB for attest --unsigned and --statement, which sign what prismpm wrote (about 4 KiB). This is the one place the cap is written.
// The cap is the sum of the reviewed allowances in scripts/package-allowances/, one file per
// change that grew the package: { "kib": n, "reason": "what the bytes are for (about x KiB)" }.
// A change that needs room adds its own file, so parallel changes never edit the same line.
const ALLOWANCES = new URL('./package-allowances/', import.meta.url);
export const PACKAGE_ALLOWANCES = readdirSync(ALLOWANCES).filter((name) => name.endsWith('.json')).sort()
.map((name) => {
const allowance = JSON.parse(readFileSync(new URL(name, ALLOWANCES), 'utf8'));
assert.deepEqual(Object.keys(allowance).sort(), ['kib', 'reason'], `${name} holds exactly kib and reason`);
assert.ok(Number.isInteger(allowance.kib) && allowance.kib > 0, `${name} grants a whole, positive number of KiB`);
assert.ok(typeof allowance.reason === 'string' && allowance.reason.trim() !== '', `${name} says what the bytes are for`);
return { name, ...allowance };
});
export const PACKAGE_LIMIT = PACKAGE_ALLOWANCES.reduce((sum, { kib }) => sum + kib, 0) * 1024;
export const PACKAGE_FILES = JSON.parse(readFileSync(new URL('../test/fixtures/package-files.json', import.meta.url), 'utf8'));

export function checkPackage(pack) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"kib": 4,
"reason": "Attest --unsigned and --statement, which sign what prismpm wrote (about 4 KiB)."
}
4 changes: 4 additions & 0 deletions sdk/npm/prism-code/scripts/package-allowances/base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"kib": 1088,
"reason": "The package before allowances were recorded one by one."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"kib": 40,
"reason": "Build --remote github: the GitHub client, the artifact reader and the checks of what comes back, with its docs and skill section (about 37.8 KiB)."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"kib": 4,
"reason": "Closure v2 provenance verification and the Hologram studio stylesheet (about 2.7 KiB)."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"kib": 4,
"reason": "The first-run fixes: the lockfile found above app/, per-verb --help, located hosted diagnostics and their docs (about 5.0 KiB, with the 2.2 KiB left before them)."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"kib": 20,
"reason": "The first run without Docker: setup's next steps and --local, the journey choosing GitHub Actions, the approved repository and the pinned template files (about 16.5 KiB)."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"kib": 20,
"reason": "Gap telemetry: gaps.mjs, the rule each refusal names, the round-trip check, delivery in a hosted call's _meta, and their docs (about 16.5 KiB)."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"kib": 20,
"reason": "Generate --lang python: the Python writer and its docs (about 18.5 KiB)."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"kib": 20,
"reason": "Generate --lang rust: the Rust writer (about 19.2 KiB)."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"kib": 24,
"reason": "The hosted tiers: hosted.mjs, the routing of build --check and verify --lean, and their docs (about 24.6 KiB)."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"kib": 4,
"reason": "The journey's hosted proof (about 6.7 KiB, with the 0.9 KiB left before it)."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"kib": 4,
"reason": "Refusing an altered holo in load (#583, about 2 KiB)."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"kib": 112,
"reason": "Prism-code mcp, the guided journey (about 110 KiB)."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"kib": 56,
"reason": "The nine modules on one client: prism.images (#442, about 26 KiB), prism.system with its event bus (#446, about 12 KiB), and the client of #441 with containers.list and prune (about 12 KiB)."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"kib": 48,
"reason": "The machine half of setup, the build tiers, axioms and init's next steps (about 44 KiB)."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"kib": 72,
"reason": "Setup, open and the bundled prism skill (about 63 KiB)."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"kib": 12,
"reason": "Specs drafted from one sentence: the input schema of prism_spec, reasons, meanings and limits, and SPEC.md in the OpenSpec format (about 14 KiB, with the 4 KiB left before it)."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"kib": 28,
"reason": "Template instances: the files that make a journey app an instance of UOR-Foundation/template, the canonical LexLean layout, the repository made from the template and the live check (about 24 KiB)."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"kib": 4,
"reason": "The verifier refusing what the Wire codec refuses (about 2.4 KiB)."
}
4 changes: 2 additions & 2 deletions sdk/npm/prism-code/test/package.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ assert.equal(result.status, 0, result.stderr);
const [pack] = JSON.parse(result.stdout);
const { files } = pack;

test('all required distributed files fit the 1584 KiB package budget', () => {
test('all required distributed files fit the package budget, the sum of the reviewed allowances', () => {
checkPackage(pack);
});

Expand All @@ -25,7 +25,7 @@ test('one byte over budget is refused, and the exact boundary is accepted', () =
files: files.map((file, i) => i === 0 ? { ...file, size: file.size + unpackedSize - pack.unpackedSize } : file),
});
checkPackage(atSize(PACKAGE_LIMIT));
assert.throws(() => checkPackage(atSize(PACKAGE_LIMIT + 1)), /cap is 1622016/);
assert.throws(() => checkPackage(atSize(PACKAGE_LIMIT + 1)), new RegExp(`cap is ${PACKAGE_LIMIT}$`));
});

test('a smaller package cannot pass by omitting a required file or changing its inventory', () => {
Expand Down
Loading