Reuse verified immutable plans and streamline cooperative hashing
Continue final hosted development reliability qualification.
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user