Implement query execution, scoped RPC enrichment, live collections, and scaffold integration
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
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";
|
||||
|
||||
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");
|
||||
assert.equal(seen.objectId, "obj:collection");
|
||||
assert.equal(seen.queryId, "pkg@1:upcoming");
|
||||
assert.equal(protoValueToJs(seen.variables.first), 30);
|
||||
assert.throws(() => context.query("not-injected"), /Missing/);
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
Reference in New Issue
Block a user