Reuse verified immutable plans and streamline cooperative hashing

Continue final hosted development reliability qualification.
This commit is contained in:
Timothy J. Aveni
2026-10-12 20:16:56 -07:00
parent 47b316180d
commit 62a09605cf
15 changed files with 214 additions and 57 deletions
+13 -1
View File
@@ -55,10 +55,22 @@ test("hashing is canonical and rejects values outside the persisted JSON contrac
test("cooperative hashing preserves canonical identities and services the event loop", async () => {
const sparse = [1, 2, 3];
delete sparse[1];
const values = [null, false, -0, "中\\n\ud800", sparse, { z: 1, a: { omitted: undefined, b: [false, 1e100] } }];
const values: unknown[] = [
null,
false,
-0,
"中\\n\ud800",
sparse,
{ z: 1, a: { omitted: undefined, b: [false, 1e100] } },
];
const shared = { text: "中😀".repeat(22000) };
values.push({ first: shared, second: shared });
for (const value of values) assert.equal(await contentDigestAsync(value), contentDigest(value));
for (const value of [undefined, NaN, Infinity, new Date(), [undefined]])
await assert.rejects(contentDigestAsync(value));
const cyclic: { next?: unknown } = {};
cyclic.next = cyclic;
await assert.rejects(contentDigestAsync(cyclic), /cyclic JSON/);
const large = Array.from({ length: 50000 }, (_, index) => ({ z: "definition".repeat(8), a: index }));
const expected = contentDigest(large);
let serviced = false;
+51
View File
@@ -9,6 +9,9 @@ import {
implementationDigest,
clientContractCatalog,
hexDigest,
executionPlanDigest,
executionPlanDigestAsync,
sealExecutionPlan,
parsePackageArtifacts,
artifactPath,
type PackageArtifacts,
@@ -21,6 +24,54 @@ import { compileKernelProgram } from "../src/execution-world/kernel.js";
import { loadCompositeWorkspace } from "./composite-fixture.js";
import { standardNativeBackends } from "../src/execution-world/native-backends.js";
test("sealed runtime plans reuse verified integrity while mutable copies are rechecked", async () => {
const workspace = await loadReaderWorkspace();
const compiled = compileExecutionPlan(workspace);
const plan: ExecutionPlan = JSON.parse(JSON.stringify(compiled));
assert.equal(await sealExecutionPlan(plan), true);
assert.equal(executionPlanDigest(plan), compiled.digest);
assert.equal(await executionPlanDigestAsync(plan), compiled.digest);
assert.throws(() => {
plan.definition.workspace.sourceRootCommit = "f".repeat(40);
}, TypeError);
assert.throws(() => {
plan.digest = "0".repeat(64);
}, TypeError);
const stringify = JSON.stringify;
JSON.stringify = () => {
throw Error("Repeated serialization of sealed metadata");
};
try {
assert.equal(executionPlanDigest(plan), compiled.digest);
assert.equal(await executionPlanDigestAsync(plan), compiled.digest);
} finally {
JSON.stringify = stringify;
}
const changed: ExecutionPlan = structuredClone(plan);
changed.definition.workspace.sourceRootCommit = "f".repeat(40);
Object.freeze(changed);
assert.notEqual(executionPlanDigest(changed), plan.digest);
assert.notEqual(await executionPlanDigestAsync(changed), plan.digest);
assert.equal(await sealExecutionPlan(changed), false, "shallow freezing is not an integrity proof");
const resigned: ExecutionPlan = structuredClone(plan);
resigned.definition.workspace.sourceRootCommit = "e".repeat(40);
resigned.digest = executionPlanDigest(resigned);
assert.equal(await sealExecutionPlan(resigned), true);
assert.notEqual(executionPlanDigest(resigned), plan.digest);
workspace.sourceRootCommit = "d".repeat(40);
assert.equal(workspace.sourceRootCommit, "d".repeat(40), "sealing owned JSON leaves compiler inputs editable");
});
test("runtime plan sealing rejects accessor-backed metadata", async () => {
const plan: ExecutionPlan = compileExecutionPlan(await loadReaderWorkspace());
assert.equal(await sealExecutionPlan(Object.create(plan)), false, "inherited integrity fields cannot be sealed");
Object.defineProperty(plan.definition, "codec", { get: () => "camino-execution-plan-v1", enumerable: true });
await assert.rejects(sealExecutionPlan(plan), /INVALID_PLAN_JSON/);
});
test("optional targets close over calls into another package", async () => {
const workspace = await loadCompositeWorkspace();
const before = compileExecutionPlan(workspace).definition.operations.find(