feat(backend): spawnFor new/resume prompt mode; resume sends /riprendi-sessione
This commit is contained in:
@@ -2,6 +2,7 @@ import { test, expect } from "vitest";
|
||||
import { spawn } from "node:child_process";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { EventEmitter } from "node:events";
|
||||
import { PiProcessManager } from "../src/pi/pi-process-manager.js";
|
||||
import { loadConfig } from "../src/config.js";
|
||||
|
||||
@@ -68,3 +69,32 @@ test("oltre maxPiProcesses solleva errore", async () => {
|
||||
await expect(mgr.spawnFor("b", {})).rejects.toThrow(/max/i);
|
||||
mgr.teardown("a");
|
||||
});
|
||||
|
||||
function recordingChild() {
|
||||
const ch: any = new EventEmitter();
|
||||
ch.stdout = new EventEmitter();
|
||||
ch.stderr = new EventEmitter();
|
||||
ch._writes = [] as string[];
|
||||
ch.stdin = { write: (d: any) => { ch._writes.push(String(d)); return true; } };
|
||||
ch.kill = () => {};
|
||||
return ch;
|
||||
}
|
||||
|
||||
test("spawnFor resume mode sends /riprendi-sessione <id>", async () => {
|
||||
const cfg = loadConfig({}); // no provider/model/thinking -> no rpc.request handshakes
|
||||
const child = recordingChild();
|
||||
const mgr = new PiProcessManager(cfg, { spawnFn: () => child as any });
|
||||
await mgr.spawnFor("sid-9", { mode: "resume" });
|
||||
expect(child._writes.join("")).toContain("/riprendi-sessione sid-9");
|
||||
expect(child._writes.join("")).not.toContain("/nuova-domanda");
|
||||
mgr.teardown("sid-9");
|
||||
});
|
||||
|
||||
test("spawnFor default (new) mode sends /nuova-domanda", async () => {
|
||||
const cfg = loadConfig({});
|
||||
const child = recordingChild();
|
||||
const mgr = new PiProcessManager(cfg, { spawnFn: () => child as any });
|
||||
await mgr.spawnFor("sid-10", {});
|
||||
expect(child._writes.join("")).toContain("/nuova-domanda");
|
||||
mgr.teardown("sid-10");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user