import test from "node:test"; import assert from "node:assert/strict"; import { createMigrationContext, migrationObjectId } from "../dist/migration.js"; test("migration context offers restricted ports and deterministic helper identities", () => { const input = { schemaVersion: 1, executionId: "operation:transition", exportId: "migrate", ports: [ { name: "old", binding: "slot:name", view: "old", access: ["read"], states: [{ objectId: "obj:one", value: "Alice" }], }, { name: "new", binding: "slot:name", view: "new", access: ["write"] }, { name: "newRead", binding: "slot:name", view: "new", access: ["read"] }, { name: "helpers", binding: "atom:helper", view: "new", access: ["create"] }, ], }; const { context, result } = createMigrationContext(input); assert.equal(context.read("old", "obj:one"), "Alice"); assert.throws(() => context.write("old", "obj:one", "Bob"), /does not grant/); assert.throws(() => context.read("new", "obj:one"), /does not grant/); context.write("new", "obj:one", "Alice"); assert.equal(context.read("newRead", "obj:one"), "Alice"); context.write("new", "obj:one", "Bob"); assert.equal(context.read("newRead", "obj:one"), "Bob"); assert.equal(context.read("old", "obj:one"), "Alice"); const helper = context.create("helpers", "one"); assert.equal(helper, migrationObjectId(input.executionId, "helpers", "one")); assert.equal(context.create("helpers", "one"), helper); assert.equal(result().creates.length, 1); assert.deepEqual(input.ports[0].states, [{ objectId: "obj:one", value: "Alice" }]); });