Files
quixos-protocol/test/remote-bindings.test.ts
T

30 lines
1.4 KiB
TypeScript

import assert from "node:assert/strict";
import { test } from "node:test";
import { asyncObjectPlan } from "./async-fixture.js";
import { generateRemoteTypeScriptBindings, generatePortableTypeScriptBindings } from "../src/bindings/portable.js";
test("remote adapters expose selected typed calls, lifetimes and explicit transaction identities", async () => {
const plan = await asyncObjectPlan();
const schema = plan.definition.bindingSchema;
const source = generateRemoteTypeScriptBindings(schema, "async:controller-runtime@1");
assert.match(source, /readonly signal: AbortSignal/);
assert.match(source, /readonly "summary.set":.*options: ServerMutationOptions/);
assert.match(source, /readonly "summarize.call": \(input: string\) => Promise<string>/);
assert.doesNotMatch(source, /readonly "summary.get"|context\.conform|readonly snapshot:/);
assert.doesNotMatch(
generatePortableTypeScriptBindings(schema, "async:controller-runtime@1", { target: "browser" }),
/readonly "refresh"/,
);
const entry = schema.packages
.find((p) => p.revisionId === "async:controller-runtime@1")!
.exports.find((entry) => entry.id === "async:controller:refresh")!;
entry.dependencyPorts[0]!.requirement = {
kind: "state",
valueType: { kind: "scalar", name: "string" },
primitives: ["write"],
};
assert.throws(
() => generateRemoteTypeScriptBindings(schema, "async:controller-runtime@1"),
/named transaction capability/,
);
});