Files
quixos-protocol/test/projection-compatibility.test.ts

30 lines
1.4 KiB
TypeScript

import assert from "node:assert/strict";
import { test } from "node:test";
import { loadReaderWorkspace } from "./reader-fixture.js";
import { compileExecutionPlan, checkResultProjection, publicOperationKey } from "../src/execution-world/index.js";
test("factory result observation checks direct replica roots against the result contract", async () => {
const plan = compileExecutionPlan(await loadReaderWorkspace());
const query = (id: string) => JSON.stringify(["package:reader-runtime@1", id]);
const create = publicOperationKey(
"atom:reader:document",
"interface:reader:document-factory@1",
"document:create:call",
);
const annotate = publicOperationKey(
"atom:reader:document",
"interface:reader:document-actions@1",
"document:annotate:call",
);
assert.equal(checkResultProjection(plan, create, query("reader:replica-inputs")).id, query("reader:replica-inputs"));
assert.equal(checkResultProjection(plan, annotate, query("reader:editor-inputs")).id, query("reader:editor-inputs"));
assert.throws(() => checkResultProjection(plan, create, query("reader:editor-inputs")), {
code: "RESULT_PROJECTION_MISMATCH",
});
assert.throws(() => checkResultProjection(plan, annotate, query("reader:highlight-scope")), {
code: "INVALID_RESULT_PROJECTION",
});
assert.throws(() => checkResultProjection(plan, annotate, query("reader:editor-view")), {
code: "INVALID_RESULT_PROJECTION",
});
});