2026-09-20 21:51:43 -07:00
|
|
|
import assert from "node:assert/strict";
|
|
|
|
|
import { compileCapabilityResourceSource, compileCapabilitySource } from "../src/capability-language/parser.js";
|
|
|
|
|
const contract = `interface Limit id "limit" revision "limit@1" {
|
|
|
|
|
operation change id "change" : int32 -> unit {
|
2026-09-28 20:29:21 -07:00
|
|
|
call id "change:call" execution transaction;
|
2026-09-20 21:51:43 -07:00
|
|
|
}
|
|
|
|
|
}`;
|
2026-09-28 20:29:21 -07:00
|
|
|
export const runtime = `symbol JavaScript id "target:org.quixos.execution.javascript@1";
|
|
|
|
|
external atom Item id "item";
|
2026-09-20 21:51:43 -07:00
|
|
|
package Runtime id "runtime" revision "runtime@1" {
|
2026-09-28 20:29:21 -07:00
|
|
|
operation change id "runtime:change" : int32 -> unit mode call execution transaction targets [JavaScript, server]
|
2026-09-20 21:51:43 -07:00
|
|
|
receiver atom Item requires { state level id "write:value" : int32 [write]; } accept using check;
|
|
|
|
|
operation check id "runtime:check" : int32 -> unit mode call execution snapshot targets [server]
|
|
|
|
|
receiver atom Item requires {
|
|
|
|
|
state level id "read:value" : int32 [read];
|
|
|
|
|
state ceiling id "read:ceiling" : int32 [read];
|
|
|
|
|
};
|
|
|
|
|
}`;
|
|
|
|
|
export const workspace = `workspace LimitTest id "workspace:limit" revision "workspace:limit@1" commit "${"a".repeat(40)}" {
|
|
|
|
|
import interface Limit;
|
|
|
|
|
import package Runtime;
|
|
|
|
|
atom Item id "item";
|
|
|
|
|
conform Item as Limit id "item:limit" {
|
|
|
|
|
private state Value id "value" on Item : int32 policy register default 0;
|
|
|
|
|
private state Ceiling id "ceiling" on Item : int32 policy register default 100;
|
|
|
|
|
bind change.call to package Runtime.change with { level to state Value; }
|
|
|
|
|
accept with { level to state Value; ceiling to state Ceiling; };
|
|
|
|
|
}
|
|
|
|
|
}`;
|
|
|
|
|
export function compile(packageSource = runtime, workspaceSource = workspace) {
|
|
|
|
|
const source = { repository: "https://example.test/limit.git", commit: "a".repeat(40) };
|
|
|
|
|
const iface = compileCapabilityResourceSource(contract, { source });
|
|
|
|
|
assert.ok(iface.ok && iface.resource.kind === "interface", JSON.stringify(iface.diagnostics));
|
|
|
|
|
const pkg = compileCapabilityResourceSource(packageSource, { source });
|
|
|
|
|
if (!pkg.ok) return pkg;
|
|
|
|
|
assert.equal(pkg.resource.kind, "package");
|
|
|
|
|
if (pkg.resource.kind !== "package") throw Error("Expected package");
|
|
|
|
|
return compileCapabilitySource(workspaceSource, "workspace.qx", {
|
|
|
|
|
interfaces: new Map([["Limit", iface.resource.revision]]),
|
|
|
|
|
packages: new Map([["Runtime", pkg.resource.revision]]),
|
|
|
|
|
});
|
|
|
|
|
}
|