Files
ThothII/backend/test/rpc-client.test.ts
T

27 lines
1.2 KiB
TypeScript

import { test, expect } from "vitest";
import { spawn } from "node:child_process";
import path from "node:path";
import { RpcClient } from "../src/rpc/rpc-client.js";
const FAKE = path.resolve("../harness/tests/fake_pi/fake_pi_rpc.mjs");
const SCRIPT = path.resolve("../harness/tests/fake_pi/scripts/f1_disambiguation.json");
test("request(get_available_models) correla la response", async () => {
const child = spawn("node", [FAKE, SCRIPT]);
const rpc = new RpcClient(child as any);
const res = await rpc.request({ type: "get_available_models" });
expect(res.data.models[0].provider).toBe("zai");
child.stdin.end();
});
test("prompt emette un evento extension_ui_request", async () => {
const child = spawn("node", [FAKE, SCRIPT]);
const rpc = new RpcClient(child as any);
const got = new Promise<any>((resolve) => rpc.on("event", (e) => e.type === "extension_ui_request" && resolve(e)));
rpc.send({ type: "prompt", message: "/nuova-domanda \"x\"" });
const evt = await got;
expect(evt.method).toBe("input"); // shape nativa di Pi
expect(JSON.parse(evt.title).widget).toBe("select"); // descriptor nel title
child.stdin.end();
});