feat(backend): resume + venv PATH + end-to-end F1 smoke (fake-pi-rpc)
- Add PiProcessManager.resume(sessionId, tht): reads provider/model/thinking from tht.sessionShow() and calls spawnFor with those values - Add POST /sessions/:id/resume route: calls mgr.resume then re-wires bridge.onClientEvent → hub.publish - Confirm venv PATH already present in real spawn (no change needed) - Add e2e test: POST /sessions → SSE receives ui_request via pendingWidget re-emit → POST /sessions/s1/response → 204 (all over real HTTP against fake-pi-rpc) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import { test, expect } from "vitest";
|
||||
import { spawn } from "node:child_process";
|
||||
import path from "node:path";
|
||||
import { buildApp } from "../src/app.js";
|
||||
import { loadConfig } from "../src/config.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("loop F1: crea sessione → SSE riceve il widget → risponde → 204", async () => {
|
||||
const app = buildApp(loadConfig({ THT_HARNESS_DIR: "../harness" }), {
|
||||
thtRunner: {
|
||||
sessionNew: async () => ({ id: "s1" }),
|
||||
sessionShow: async (_id: string) => ({ id: "s1", provider: undefined, model: undefined, thinking: undefined }),
|
||||
sessionList: async () => [],
|
||||
} as any,
|
||||
spawnFn: () => spawn("node", [FAKE, SCRIPT]) as any,
|
||||
});
|
||||
await app.listen({ port: 0, host: "127.0.0.1" });
|
||||
const base = `http://127.0.0.1:${(app.server.address() as any).port}`;
|
||||
|
||||
// 1. Create session — spawns fake-pi, sends prompt, fake-pi emits widget
|
||||
await fetch(`${base}/sessions`, {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({ workspace: "w", question: "q" }),
|
||||
});
|
||||
|
||||
// 2. Small delay to let fake-pi process the prompt and fill pendingWidget
|
||||
await new Promise((r) => setTimeout(r, 50));
|
||||
|
||||
// 3. SSE: read the first event (pendingWidget re-emit via subscribe)
|
||||
const es = await fetch(`${base}/sessions/s1/events`);
|
||||
const reader = es.body!.getReader();
|
||||
const chunk = await reader.read();
|
||||
const text = new TextDecoder().decode(chunk.value);
|
||||
expect(text).toContain("ui_request");
|
||||
await reader.cancel();
|
||||
|
||||
// 4. POST response — widget id is "u1" from f1_disambiguation.json
|
||||
const resp = await fetch(`${base}/sessions/s1/response`, {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({ ui_response: { id: "u1", choices: ["a"] } }),
|
||||
});
|
||||
expect(resp.status).toBe(204);
|
||||
|
||||
await app.close();
|
||||
}, 10000);
|
||||
Reference in New Issue
Block a user