diff --git a/test/emit-portable-reader.ts b/test/emit-portable-reader.ts index c3dff3b..90a413f 100644 --- a/test/emit-portable-reader.ts +++ b/test/emit-portable-reader.ts @@ -89,6 +89,11 @@ void negative; ); const { asyncObjectPlan } = await import("./async-fixture.js"); +const { treePlan } = await import("./tree-fixture.js"); +const tree = await treePlan(); +await mkdir("dist/portable-reader/tree", { recursive: true }); +await writeFile("dist/portable-reader/tree/plan.json", JSON.stringify(tree)); +await writeFile("dist/portable-reader/tree/kernel.json", JSON.stringify(compileKernelProgram(tree))); const { compile: compileAcceptance } = await import("./acceptance-fixture.js"); const acceptance = compileAcceptance(); if (!acceptance.ok) throw Error(JSON.stringify(acceptance.diagnostics)); diff --git a/test/fixtures/tree/TreeData.qx b/test/fixtures/tree/TreeData.qx new file mode 100644 index 0000000..701ad50 --- /dev/null +++ b/test/fixtures/tree/TreeData.qx @@ -0,0 +1,11 @@ +interface TreeData id "tree:data" revision "tree:data@1" { + operation reparent id "tree:reparent" : optional> -> unit { + call id "tree:reparent:call" execution transaction targets [browser, server]; + } + queryable relation parent id "tree:parent" : optional-one interface TreeData { + resolve id "tree:parent:resolve" execution snapshot targets [browser, server]; + } + queryable relation children id "tree:children" : many interface TreeData { + resolve id "tree:children:resolve" execution snapshot targets [browser, server]; + } +} diff --git a/test/fixtures/tree/TreeRuntime.qx b/test/fixtures/tree/TreeRuntime.qx new file mode 100644 index 0000000..0e2a489 --- /dev/null +++ b/test/fixtures/tree/TreeRuntime.qx @@ -0,0 +1,13 @@ +external atom Node id "tree:node"; +import interface TreeData; +package TreeRuntime id "tree:runtime" revision "tree:runtime@1" { + operation reparent id "tree:runtime:reparent" : optional> -> unit + mode call execution transaction targets [browser, server] receiver atom Node requires { + edge parent id "tree:move:parent" : optional-one interface TreeData [resolve, connect, disconnect]; + } accept using check; + operation check id "tree:runtime:check" : optional> -> unit + mode call execution snapshot targets [server] receiver atom Node requires { + edge current id "tree:check:current" : optional-one interface TreeData [resolve]; + interface ancestors id "tree:check:ancestors" : TreeData using [parent.resolve] from input; + }; +} diff --git a/test/fixtures/tree/workspace.qx b/test/fixtures/tree/workspace.qx new file mode 100644 index 0000000..f7c41b9 --- /dev/null +++ b/test/fixtures/tree/workspace.qx @@ -0,0 +1,19 @@ +workspace Tree id "workspace:tree" revision "workspace:tree@1" commit "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" { + import interface TreeData; + import package TreeRuntime; + atom Node id "tree:node"; + conform Node as TreeData id "tree:node:data" { + private edge Parent id "tree:parent-edge" { + atom Node projection parent id "tree:parent-projection" optional-one; + interface TreeData projection children id "tree:children-projection" many; + } + bind parent.resolve to edge Parent.parent.resolve; + bind children.resolve to edge Parent.children.resolve; + bind reparent.call to package TreeRuntime.reparent with { + parent to edge Parent.parent; + } accept with { + current to edge Parent.parent; + ancestors to interface TreeData from input; + }; + } +} diff --git a/test/tree-fixture.ts b/test/tree-fixture.ts new file mode 100644 index 0000000..11d30c4 --- /dev/null +++ b/test/tree-fixture.ts @@ -0,0 +1,23 @@ +import assert from "node:assert/strict"; +import { readFile } from "node:fs/promises"; +import { compileCapabilityResourceSource, compileCapabilitySource } from "../src/capability-language/parser.js"; +import { compileExecutionPlan } from "../src/execution-world/plan.js"; +import type { InterfaceRevision } from "../src/capability-model/types.js"; +export async function treePlan() { + const read = (name: string) => readFile(`test/fixtures/tree/${name}.qx`, "utf8"); + const source = { repository: "https://example.test/tree.git", commit: "a".repeat(40) }; + const interfaces = new Map(); + for (const name of ["TreeData"]) { + const result = compileCapabilityResourceSource(await read(name), { source, environment: { interfaces } }); + assert.ok(result.ok && result.resource.kind === "interface", JSON.stringify(result.diagnostics)); + interfaces.set(name, result.resource.revision); + } + const pkg = compileCapabilityResourceSource(await read("TreeRuntime"), { source, environment: { interfaces } }); + assert.ok(pkg.ok && pkg.resource.kind === "package", JSON.stringify(pkg.diagnostics)); + const result = compileCapabilitySource(await read("workspace"), "workspace.qx", { + interfaces, + packages: new Map([["TreeRuntime", pkg.resource.revision]]), + }); + assert.ok(result.ok, JSON.stringify(result.diagnostics)); + return compileExecutionPlan(result.workspace); +}