web: add omni-search results and routing (S1/S2)
This commit is contained in:
@@ -104,3 +104,43 @@ test("validate throws when the reply has no graph", async () => {
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "validated" });
|
||||
await assert.rejects(() => repo.validate("empty"), ProtocolError);
|
||||
});
|
||||
|
||||
test("search sends exactly {type:'search',search:{query,kind:'',limit:0}} and returns search_results", async () => {
|
||||
const { repo, ws } = connected();
|
||||
const payload = { query: "release", results: [{ kind: "run" }], cap: 50, scanned_steps: 3 };
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "search_results", search_results: payload });
|
||||
|
||||
const reply = await repo.search("release");
|
||||
assert.deepEqual(lastFrame(ws), {
|
||||
type: "search",
|
||||
search: { query: "release", kind: "", limit: 0 },
|
||||
});
|
||||
assert.deepEqual(reply, payload);
|
||||
});
|
||||
|
||||
test("search sends the selected kind verbatim and never a limit above the cap", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "search_results", search_results: { results: [] } });
|
||||
|
||||
await repo.search("release", "run");
|
||||
const { search } = lastFrame(ws);
|
||||
assert.deepEqual(search, { query: "release", kind: "run", limit: 0 });
|
||||
// limit 0 asks for the server's own default (SearchDefaultLimit 50); the client
|
||||
// never asks for more than SearchMaxLimit (200), let alone sends a larger value.
|
||||
assert.ok(search.limit <= 200);
|
||||
});
|
||||
|
||||
test("search returns null when an older server replies without search_results", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "pong" });
|
||||
assert.equal(await repo.search("release"), null);
|
||||
});
|
||||
|
||||
test("search surfaces an explicit server error with the server's own text", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "error", error: "unknown command: search" });
|
||||
await assert.rejects(() => repo.search("release"), {
|
||||
name: "ProtocolError",
|
||||
message: "unknown command: search",
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user