7e69e675ba
Add authorized exact-contract lookup, revision-fenced views, generated typed package/browser descriptors, and lifecycle-safe React discovery. Preserve closed generic contracts without competing-conformance policies or new authority grants. Document supported workarounds and privacy boundaries for agent feedback. Publish matching protocol/SDK exports and update scaffold/starter pins; leave the deployed template unchanged.
73 lines
2.5 KiB
JavaScript
73 lines
2.5 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { bindQxHandler, createRuntimeContext, defineQxInterfaceContract, jsToProtoValue } from "../dist/index.js";
|
|
import { referenceFromWire } from "../dist/references.js";
|
|
|
|
const unit = { kind: "builtin", name: "unit" };
|
|
test("generated conformance views use checked codecs and retain their fence on invocation", async () => {
|
|
const contract = defineQxInterfaceContract("Named", {
|
|
"name.get": { id: "get", inputType: unit, outputType: { kind: "scalar", name: "string" } },
|
|
});
|
|
const object = referenceFromWire("object");
|
|
const witness = {
|
|
objectId: "object",
|
|
interfaceRevisionId: "Named",
|
|
workspaceEpoch: "1",
|
|
workspaceRevisionId: "w",
|
|
conformanceId: "named",
|
|
};
|
|
const requests = [];
|
|
const raw = createRuntimeContext(
|
|
{},
|
|
{
|
|
async tryConform(request) {
|
|
requests.push(request);
|
|
return { conformance: witness };
|
|
},
|
|
async invokeCapability(request) {
|
|
for (const key of Object.keys(witness)) assert.equal(request.capability.conformance[key], witness[key]);
|
|
assert.deepEqual(request.input, {});
|
|
return { ok: true, result: jsToProtoValue("Hello"), dependencies: [] };
|
|
},
|
|
},
|
|
{ objectId: "object", input: {}, dependencies: [] },
|
|
);
|
|
const handler = bindQxHandler(
|
|
{ inputType: unit, outputType: unit, ports: {} },
|
|
async (context) => {
|
|
const view = await context.conform.tryConform(object, contract);
|
|
assert.ok(view.objectId.equals(object));
|
|
assert.equal(view.contract, contract);
|
|
assert.equal(await view["name.get"](), "Hello");
|
|
},
|
|
{},
|
|
);
|
|
await handler(raw);
|
|
assert.deepEqual(requests, [{ objectId: "object", interfaceRevisionId: "Named" }]);
|
|
});
|
|
|
|
test("package discovery preserves absence and denied errors and refuses raw IDs", async () => {
|
|
const request = { objectId: "object", input: {}, dependencies: [] };
|
|
const raw = createRuntimeContext(
|
|
{},
|
|
{
|
|
async tryConform() {
|
|
return {};
|
|
},
|
|
},
|
|
request,
|
|
);
|
|
assert.equal(await raw.tryConform(referenceFromWire("object"), "Missing"), undefined);
|
|
await assert.rejects(raw.tryConform("object", "Named"), /opaque object reference/);
|
|
const denied = createRuntimeContext(
|
|
{},
|
|
{
|
|
async tryConform() {
|
|
throw Error("permission denied");
|
|
},
|
|
},
|
|
request,
|
|
);
|
|
await assert.rejects(denied.tryConform(referenceFromWire("object"), "Named"), /permission denied/);
|
|
});
|