/** Protocol/process qualification only; no application fixture enters runtime code. */ import assert from "node:assert/strict"; import { mkdir, writeFile } from "node:fs/promises"; import { compileCapabilityResourceSource, compileCapabilitySource } from "../src/capability-language/index.js"; import { compileExecutionPlan } from "../src/execution-world/plan.js"; import { compileKernelProgram } from "../src/execution-world/kernel.js"; import { compileQueryProgram } from "../src/execution-world/queries.js"; const source = { repository: "https://example.test/device-owner.git", commit: "a".repeat(40) }; const factory = compileCapabilityResourceSource( `external atom Entry id "atom:entry"; interface EntryFactory id "interface:entry-factory" revision "interface:entry-factory@1" { static operation create id "entry:create" : unit -> atom-ref { call id "entry:create:call" execution transaction targets [server]; } }`, { source }, ); assert.ok(factory.ok && factory.resource.kind === "interface", JSON.stringify(factory.diagnostics)); for (const variant of ["base", "added", "gateway", "gateway-next"]) { const gateway = variant.startsWith("gateway"), commit = { base: "a", added: "b", gateway: "c", "gateway-next": "d" }[variant]!.repeat(40); const pkg = compileCapabilityResourceSource( `${gateway ? 'external atom Entry id "atom:entry";' : ""} package Owner id "package:owner" revision "package:owner@1" { function identity id "identity" : int32 -> record { pid: int32; child: int32; } execution remote; ${gateway ? 'function create id "create" : unit -> atom-ref execution transaction targets [server] requires { creation entry id "entry:birth" : Entry input unit; };' : ""} }`, { source }, ); assert.ok(pkg.ok && pkg.resource.kind === "package", JSON.stringify(pkg.diagnostics)); const result = compileCapabilitySource( `workspace Managed id "workspace:managed-process" revision "workspace:managed-process@${variant}" commit "${commit}" { import package Owner; ${variant !== "base" ? 'atom Independent id "atom:independent";' : ""} ${ gateway ? `import interface EntryFactory; atom Entry id "atom:entry"; conform Entry as EntryFactory id "owner:entry-factory" { bind create.call to package Owner.create with { entry to creation Entry with {}; }; }` : "" } }`, "workspace.qx", { packages: new Map([["Owner", pkg.resource.revision]]), packageClosure: [pkg.resource.revision], ...(gateway ? { interfaces: new Map([["EntryFactory", factory.resource.revision]]), interfaceClosure: [factory.resource.revision], } : {}), }, ); assert.ok(result.ok, JSON.stringify(result.diagnostics)); const plan = compileExecutionPlan(result.workspace), root = `dist/managed/${variant}`; await mkdir(root, { recursive: true }); for (const [file, value] of Object.entries({ "candidate.json": result.workspace, "entry.json": gateway ? { atom: "atom:entry", interface: "interface:entry-factory@1", operation: "entry:create:call" } : null, "execution-plan.json": plan, "kernel.json": compileKernelProgram(plan), "queries.json": compileQueryProgram(plan), "source.json": { kind: "workspace", repository: "https://example.test/managed.git", commit }, })) await writeFile(`${root}/${file}`, JSON.stringify(value)); }