Separate graph execution identity from installation provenance
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import { loadReaderWorkspace } from "./reader-fixture.js";
|
||||
import { buildArtifactFixture } from "./artifact-fixture.js";
|
||||
import {
|
||||
generatePortableClientBindings,
|
||||
compileExecutionPlan,
|
||||
compileKernelProgram,
|
||||
compileQueryProgram,
|
||||
graphExecutionRepresentation,
|
||||
hexDigest,
|
||||
type ExecutionPlan,
|
||||
type ExecutionInstallation,
|
||||
} from "../src/execution-world/index.js";
|
||||
|
||||
function prepare(plan: ExecutionPlan) {
|
||||
const installation: ExecutionInstallation = {
|
||||
codec: "camino-execution-installation-v1",
|
||||
plan: plan.digest,
|
||||
world: "0".repeat(64),
|
||||
routes: {},
|
||||
components: [],
|
||||
packages: plan.definition.packages.map((pkg) => {
|
||||
const { manifest } = buildArtifactFixture(plan, pkg.revision);
|
||||
return {
|
||||
revision: pkg.revision,
|
||||
root: "/build/provenance",
|
||||
service: manifest.implementations[0]!,
|
||||
browserImplementation: manifest.implementations[2]!,
|
||||
};
|
||||
}),
|
||||
};
|
||||
const kernel = compileKernelProgram(plan) as any,
|
||||
queries = compileQueryProgram(plan) as any;
|
||||
return {
|
||||
installation,
|
||||
kernel,
|
||||
queries,
|
||||
graph: () => graphExecutionRepresentation(plan, installation, kernel, queries),
|
||||
};
|
||||
}
|
||||
|
||||
test("actual interpreter inputs and creation recipes exclude source provenance", async () => {
|
||||
const workspace = await loadReaderWorkspace();
|
||||
const originalPlan = compileExecutionPlan(workspace);
|
||||
const before = prepare(originalPlan);
|
||||
workspace.sourceRootCommit = "f".repeat(40);
|
||||
for (const pkg of workspace.packageImports) pkg.source.commit = "e".repeat(40);
|
||||
const nextPlan = compileExecutionPlan(workspace);
|
||||
const after = prepare(nextPlan);
|
||||
assert.equal(
|
||||
generatePortableClientBindings(originalPlan, { target: "browser" }),
|
||||
generatePortableClientBindings(nextPlan, { target: "browser" }),
|
||||
);
|
||||
assert.notEqual(before.installation.plan, after.installation.plan);
|
||||
assert.deepEqual(before.kernel, after.kernel);
|
||||
assert.deepEqual(before.queries, after.queries);
|
||||
assert.deepEqual(before.graph(), after.graph());
|
||||
assert.ok(JSON.stringify(before.kernel).includes('"recipe"'));
|
||||
});
|
||||
|
||||
test("graph identity covers executable closures, query semantics and real interpreter input", async () => {
|
||||
const plan = compileExecutionPlan(await loadReaderWorkspace());
|
||||
const fixture = prepare(plan),
|
||||
baseline = hexDigest(fixture.graph());
|
||||
fixture.installation.packages[0]!.service!.files[0]!.digest = "c".repeat(64);
|
||||
assert.notEqual(hexDigest(fixture.graph()), baseline);
|
||||
const query = prepare(plan);
|
||||
query.queries.queries[0].budgets.rows++;
|
||||
assert.notEqual(hexDigest(query.graph()), baseline);
|
||||
query.kernel.operations[0].output = { kind: "scalar", name: "string" };
|
||||
assert.throws(() => query.graph(), /GRAPH_PROGRAM_MISMATCH/);
|
||||
const shared = prepare(plan);
|
||||
(shared.installation as any).engineURL = "/changed-engine.mjs";
|
||||
assert.notEqual(hexDigest(shared.graph()), baseline);
|
||||
const future = prepare(plan);
|
||||
future.kernel.codec = "future-kernel";
|
||||
assert.throws(() => future.graph(), /GRAPH_PROGRAM_MISMATCH/);
|
||||
});
|
||||
|
||||
test("initialization, storage, nominal contracts and bound ports affect executed kernel identity", async () => {
|
||||
const workspace = await loadReaderWorkspace(),
|
||||
plan = compileExecutionPlan(workspace);
|
||||
const original = prepare(plan);
|
||||
for (const change of [
|
||||
(p: ExecutionPlan) => {
|
||||
(p.definition.owners[0]!.initialization as any[]).push({
|
||||
input: "extra",
|
||||
binding: { kind: "state", slotId: "extra" },
|
||||
});
|
||||
},
|
||||
(p: ExecutionPlan) => {
|
||||
p.definition.owners[0]!.id += ":different";
|
||||
},
|
||||
(p: ExecutionPlan) => {
|
||||
p.definition.operations[0]!.operationId += ":different";
|
||||
},
|
||||
(p: ExecutionPlan) => {
|
||||
p.definition.versions.crdt = "future-genesis" as any;
|
||||
},
|
||||
]) {
|
||||
const changed = structuredClone(plan);
|
||||
change(changed);
|
||||
changed.digest = hexDigest(changed.definition);
|
||||
assert.notEqual((compileKernelProgram(changed) as any).plan, original.kernel.plan);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user