import assert from "node:assert/strict"; import { compileCapabilityResourceSource, compileCapabilitySource } from "../src/capability-language/parser.js"; import { compileExecutionPlan } from "../src/execution-world/plan.js"; /** Independently versioned generic interface and implementation, closed by a workspace. */ export function portableGenericPlan() { const source = { repository: "https://example.test/portable-generics.git", commit: "a".repeat(40) }; const iface = compileCapabilityResourceSource( ` interface Echo id "echo-interface" revision "echo-interface@2" { operation echo id "echo-member" : T -> T { call id "echo-call" execution snapshot targets [browser, server]; } }`, { source }, ); assert.ok(iface.ok && iface.resource.kind === "interface", JSON.stringify(iface.diagnostics)); const pkg = compileCapabilityResourceSource( ` package Generic id "generic" revision "generic@3" { operation echo id "echo" : T -> T mode call execution snapshot targets [browser, server] receiver any; }`, { source: { ...source, commit: "b".repeat(40) } }, ); assert.ok(pkg.ok && pkg.resource.kind === "package", JSON.stringify(pkg.diagnostics)); const workspace = compileCapabilitySource( ` workspace W id "w" revision "w@1" commit "${source.commit}" { import interface Echo; import package Generic; atom Thing id "thing"; conform Thing as Echo id "string-echo" { bind echo.call to package Generic.echo; } conform Thing as Echo> id "list-echo" { bind echo.call to package Generic.echo>; } }`, "workspace.qx", { interfaces: new Map([["Echo", iface.resource.revision]]), packages: new Map([["Generic", pkg.resource.revision]]), }, ); assert.ok(workspace.ok, JSON.stringify(workspace.diagnostics)); return compileExecutionPlan(workspace.workspace); }