2026-09-17 14:34:16 -07:00
|
|
|
import assert from "node:assert/strict";
|
|
|
|
|
import test from "node:test";
|
|
|
|
|
import { create } from "@bufbuild/protobuf";
|
|
|
|
|
import { QueryResponseSchema } from "../dist/camino/api_pb.js";
|
|
|
|
|
import { InjectedDependencySchema } from "../dist/quixos/refs_pb.js";
|
|
|
|
|
import { createRuntimeContext, decodeQuerySnapshot, jsToProtoValue, protoValueToJs } from "../dist/index.js";
|
|
|
|
|
|
2026-09-17 18:23:16 -07:00
|
|
|
test("private relational captures cannot be decoded as a completed public query", () => {
|
|
|
|
|
const response = create(QueryResponseSchema, { relationalCaptures: [{ rootObjectId: "obj:private" }] });
|
|
|
|
|
assert.throws(
|
|
|
|
|
() => decodeQuerySnapshot(response, { kind: "record", fields: {} }, "run", 1n),
|
|
|
|
|
/QUERY_RESULT_UNFINISHED/,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-17 14:34:16 -07:00
|
|
|
test("query ports carry only an injected query identity and root", async () => {
|
|
|
|
|
let seen;
|
|
|
|
|
const context = createRuntimeContext(
|
|
|
|
|
{},
|
|
|
|
|
{
|
|
|
|
|
executeQuery: async (request) => {
|
|
|
|
|
seen = request;
|
|
|
|
|
return create(QueryResponseSchema);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
objectId: "obj:receiver",
|
|
|
|
|
input: {},
|
|
|
|
|
dependencies: [
|
|
|
|
|
create(InjectedDependencySchema, {
|
|
|
|
|
portId: "list",
|
|
|
|
|
objectId: "obj:collection",
|
|
|
|
|
binding: { case: "queryId", value: "pkg@1:upcoming" },
|
|
|
|
|
}),
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
await context.query("list").execute({ first: jsToProtoValue(30) }, "checked-definition");
|
|
|
|
|
assert.equal(seen.expectedDefinitionDigest, "checked-definition");
|
2026-09-18 14:55:12 -07:00
|
|
|
assert.deepEqual(seen.root, { case: "objectId", value: "obj:collection" });
|
2026-09-17 14:34:16 -07:00
|
|
|
assert.equal(seen.queryId, "pkg@1:upcoming");
|
|
|
|
|
assert.equal(protoValueToJs(seen.variables.first), 30);
|
|
|
|
|
assert.throws(() => context.query("not-injected"), /Missing/);
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-18 14:55:12 -07:00
|
|
|
test("workspace query ports carry explicit scoped evidence, never their receiver", async () => {
|
|
|
|
|
let seen;
|
|
|
|
|
const dependency = create(InjectedDependencySchema, {
|
|
|
|
|
portId: "search",
|
|
|
|
|
binding: {
|
|
|
|
|
case: "workspaceQuery",
|
|
|
|
|
value: {
|
|
|
|
|
queryId: "pkg@1:search",
|
|
|
|
|
scope: {
|
|
|
|
|
workspaceId: "ws",
|
|
|
|
|
workspaceRevisionId: "ws@1",
|
|
|
|
|
workspaceEpoch: "1",
|
|
|
|
|
interfaceRevisionId: "searchable",
|
|
|
|
|
bindingDigest: "digest",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
const context = createRuntimeContext(
|
|
|
|
|
{},
|
|
|
|
|
{
|
|
|
|
|
executeQuery: async (request) => {
|
|
|
|
|
seen = request;
|
|
|
|
|
return create(QueryResponseSchema);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{ objectId: "obj:receiver", input: {}, dependencies: [dependency] },
|
|
|
|
|
);
|
|
|
|
|
await context.query("search").execute({});
|
|
|
|
|
assert.equal(seen.root.case, "workspaceScope");
|
|
|
|
|
assert.equal(seen.root.value.workspaceId, "ws");
|
|
|
|
|
assert.equal(seen.objectId, undefined);
|
|
|
|
|
dependency.binding.value.scope = undefined;
|
|
|
|
|
assert.throws(
|
|
|
|
|
() => createRuntimeContext({}, {}, { objectId: "obj:receiver", input: {}, dependencies: [dependency] }),
|
|
|
|
|
/has no scope/,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2026-09-17 14:34:16 -07:00
|
|
|
test("query snapshots distinguish an unavailable scalar from a successful null", () => {
|
|
|
|
|
const output = {
|
|
|
|
|
kind: "record",
|
|
|
|
|
fields: { title: { kind: "scalar", name: "string" }, score: { kind: "scalar", name: "int64" } },
|
|
|
|
|
};
|
|
|
|
|
const response = create(QueryResponseSchema, {
|
|
|
|
|
value: jsToProtoValue({ title: "Native title", score: null }),
|
|
|
|
|
pending: [{ path: [{ part: { case: "field", value: "score" } }] }],
|
|
|
|
|
});
|
|
|
|
|
const snapshot = decodeQuerySnapshot(response, output, "run1", 1n);
|
|
|
|
|
assert.equal(snapshot.status, "partial");
|
|
|
|
|
assert.deepEqual(snapshot.data, { title: "Native title" });
|
|
|
|
|
assert.deepEqual(snapshot.fields, [{ path: ["score"], status: "pending" }]);
|
|
|
|
|
assert.equal(output.fields.score.kind, "scalar");
|
|
|
|
|
response.pending = [];
|
|
|
|
|
response.value = jsToProtoValue({ title: "Native title", score: 9007199254740993n });
|
|
|
|
|
assert.equal(decodeQuerySnapshot(response, output, "run1", 2n).data.score, 9007199254740993n);
|
|
|
|
|
});
|