test(app): verify streaming chat and stage debugging in the browser

This commit is contained in:
2026-10-24 02:08:26 +01:00
parent 8e980564cb
commit d915f69226
5 changed files with 252 additions and 10 deletions
+37 -2
View File
@@ -310,7 +310,7 @@ async function staticFile(base, pathname, req, res) {
* It serves the built probe bundle and upgrades /connect on the same origin, so
* the normal web composition infers this server from Uri.base.
*/
export async function startFixture({ root, runs = RUNS }) {
export async function startFixture({ root, runs = RUNS, runDetail, files = {} }) {
const base = await realpath(root);
const connections = new Set();
const sockets = new Set();
@@ -327,6 +327,9 @@ export async function startFixture({ root, runs = RUNS }) {
let chatSubscribed = 0;
let chatHistory = 0;
const chatPrompts = [];
const fileReads = [];
let chatRunning = false;
let chatInterrupts = 0;
const searchRequests = [];
const CHAT_SESSION = {
id: 'ses_probechat',
@@ -348,6 +351,22 @@ export async function startFixture({ root, runs = RUNS }) {
const server = createServer(async (req, res) => {
const pathname = new URL(req.url, 'http://fixture').pathname;
if (pathname === '/fixture/chat-event' && req.method === 'POST') {
const chunks = [];
for await (const chunk of req) chunks.push(chunk);
const event = JSON.parse(Buffer.concat(chunks).toString('utf8'));
if (event.kind === 'step') chatRunning = event.step?.status !== 'ended';
broadcast({ type: 'chat_event', chat_event: {
session_id: CHAT_SESSION.id, ...event,
} });
res.writeHead(200, { 'content-type': 'application/json' }).end('{"ok":true}');
return;
}
if (Object.hasOwn(files, pathname)) {
fileReads.push(pathname);
res.writeHead(200, { 'content-type': 'text/plain; charset=utf-8' }).end(files[pathname]);
return;
}
if (pathname === '/fixture/live' && req.method === 'POST') {
live = true;
broadcast(LIVE_EVENT);
@@ -386,6 +405,9 @@ export async function startFixture({ root, runs = RUNS }) {
chatSubscribed,
chatHistory,
chatPrompts,
chatRunning,
chatInterrupts,
fileReads,
searchRequests,
}));
return;
@@ -443,6 +465,10 @@ export async function startFixture({ root, runs = RUNS }) {
}
if (request.type === 'get_run') {
getRun++;
if (runDetail) {
client.send({ id: request.id, type: 'run', run_detail: runDetail });
return;
}
const id = request.run_id;
if (id === 2) {
// Deliberately slow so the browser sees the pending/Back state;
@@ -521,7 +547,16 @@ export async function startFixture({ root, runs = RUNS }) {
const body = request.chat_prompt ?? {};
chatPrompts.push({ session_id: body.session_id, text: body.text,
operation_id: body.operation_id, native_message_id: body.native_message_id });
setTimeout(() => client.send({ id: request.id, type: 'chat_prompt' }), 300);
setTimeout(() => client.send({ id: request.id, type: 'chat_prompt', chat_queued: chatRunning }), 300);
return;
}
if (request.type === 'chat_shells') {
client.send({ id: request.id, type: 'chat_shells', chat_shells: [] });
return;
}
if (request.type === 'chat_interrupt') {
chatInterrupts++;
client.send({ id: request.id, type: 'chat_interrupt' });
return;
}
if (request.type === 'chat_messages') {