62 lines
2.7 KiB
TypeScript
62 lines
2.7 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { test } from "node:test";
|
|
import { compileQuery } from "../src/query/compile.js";
|
|
import { linkQueries } from "../src/query/link.js";
|
|
import { loadReaderWorkspace as load, readReaderFixture as read } from "./reader-fixture.js";
|
|
test("complete reader contracts compose factories, portable selectors, CRDT edits, and bounded query scopes", async () => {
|
|
const workspace = await load();
|
|
assert.equal(workspace.constructors.length, 0);
|
|
assert.equal(workspace.atoms.length, 3);
|
|
const linked = linkQueries(workspace);
|
|
assert.equal(linked.length, 8);
|
|
assert.equal(linked.filter((q) => q.checked.declaration.placement?.kind === "local").length, 4);
|
|
const screen = linked.find((q) => q.checked.declaration.displayName === "ReaderScreen")!;
|
|
assert.ok(screen.fields.some((f) => f.memberId === "highlight:excerpt" && f.binding.kind === "package"));
|
|
assert.ok(screen.fields.some((f) => f.memberId === "comment:content" && f.binding.kind === "state"));
|
|
assert.equal(
|
|
linked.find((q) => q.checked.declaration.displayName === "HighlightEditorInputs")!.checked.declaration.root.kind,
|
|
"object",
|
|
);
|
|
assert.equal(
|
|
linked.find((q) => q.checked.declaration.displayName === "HighlightScope")!.checked.declaration.root.kind,
|
|
"workspace-interface",
|
|
);
|
|
});
|
|
|
|
test("reader composition reports the dependency that weakens a portable promise", async () => {
|
|
await assert.rejects(
|
|
load((name, text) =>
|
|
name === "ReaderRuntime.qx"
|
|
? text.replace(/(operation excerpt[\s\S]*?targets )\[browser, server\]/, "$1[server]")
|
|
: text,
|
|
),
|
|
/does not provide execution target browser/,
|
|
);
|
|
await assert.rejects(
|
|
load((name, text) =>
|
|
name === "ReaderRuntime.qx"
|
|
? text.replace(
|
|
"using [sourceRevision.get, content.get];",
|
|
"using [sourceRevision.get, content.get, highlights.connect];",
|
|
)
|
|
: text,
|
|
),
|
|
/Snapshot execution cannot perform a transaction/,
|
|
);
|
|
});
|
|
|
|
test("a field can remain server-queryable while failing local query placement", async () => {
|
|
const workspace = await load();
|
|
const pkg = workspace.packageImports[0]!;
|
|
const highlight = workspace.interfaceImports.find((i) => i.displayName === "HighlightData")!;
|
|
const field = highlight.members.find((m) => m.displayName === "color")!;
|
|
delete field.operations[0]!.execution;
|
|
const admission = pkg.queries!.find((q) => q.displayName === "HighlightScope")!;
|
|
const local = pkg.queries!.find((q) => q.displayName === "HighlightList")!;
|
|
await compileQuery(admission, workspace.interfaceImports, read);
|
|
await assert.rejects(
|
|
compileQuery(local, workspace.interfaceImports, read),
|
|
/browser snapshot getter for HighlightData.color/,
|
|
);
|
|
});
|