feat(backend): PiProcessManager (one Pi per session, cap, set_model/thinking)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { test, expect } from "vitest";
|
||||
import { spawn } from "node:child_process";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { PiProcessManager } from "../src/pi/pi-process-manager.js";
|
||||
import { loadConfig } from "../src/config.js";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const FAKE = path.resolve(__dirname, "../../harness/tests/fake_pi/fake_pi_rpc.mjs");
|
||||
const SCRIPT = path.resolve(__dirname, "../../harness/tests/fake_pi/scripts/f1_disambiguation.json");
|
||||
|
||||
test("spawnFor avvia un runtime e il bridge emette il widget F1", async () => {
|
||||
const cfg = loadConfig({ THT_HARNESS_DIR: "../harness" });
|
||||
const mgr = new PiProcessManager(cfg, { spawnFn: () => spawn("node", [FAKE, SCRIPT]) as any });
|
||||
const rt = await mgr.spawnFor("2026-06-27-100000-x", {});
|
||||
const widget = await new Promise<any>((res) => rt.bridge.onClientEvent((e) => e.type === "ui_request" && res(e)));
|
||||
expect(widget.ui_request.widget).toBe("select");
|
||||
mgr.teardown("2026-06-27-100000-x");
|
||||
expect(mgr.count()).toBe(0);
|
||||
});
|
||||
|
||||
test("oltre maxPiProcesses solleva errore", async () => {
|
||||
const cfg = { ...loadConfig({}), maxPiProcesses: 1 };
|
||||
const mgr = new PiProcessManager(cfg, { spawnFn: () => spawn("node", [FAKE, SCRIPT]) as any });
|
||||
await mgr.spawnFor("a", {});
|
||||
await expect(mgr.spawnFor("b", {})).rejects.toThrow(/max/i);
|
||||
mgr.teardown("a");
|
||||
});
|
||||
Reference in New Issue
Block a user