Move live background tasks into a composer badge and modal
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
// Real composer badge/modal interaction, using recorded loopback task fixtures.
|
||||
import assert from 'node:assert/strict';
|
||||
import { mkdir, mkdtemp, writeFile } from 'node:fs/promises';
|
||||
import { once } from 'node:events';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join, resolve } from 'node:path';
|
||||
import { startFixture } from './runs_probe_server.mjs';
|
||||
import { launchChrome, waitForPort, waitForPage, connect, sleep } from './pipelines_probe_cdp_lib.mjs';
|
||||
import { axNodes, enableSemantics, waitFor, capture, click } from './pipelines_probe_cdp_input.mjs';
|
||||
|
||||
const platform = process.env.PROBE_PLATFORM ?? 'material';
|
||||
const width = Number(process.env.PROBE_WIDTH ?? 1280);
|
||||
const output = resolve(process.argv[3] ?? `build/background-task-modal-${platform}`);
|
||||
await mkdir(output, { recursive: true });
|
||||
const fixture = await startFixture({ root:resolve(process.argv[2]), chatMessages: [], chatShells: [
|
||||
{ id:'a', status:'running', command:'tail -f fixture.log' },
|
||||
{ id:'b', status:'running', command:'fixture build' },
|
||||
{ id:'finished', status:'exited', command:'old finished command' },
|
||||
], chatShellOutput: Array.from({length:200},(_,i)=>`Recorded output line ${i}`).join('\n') });
|
||||
const profile = await mkdtemp(join(tmpdir(),'background-task-modal-'));
|
||||
const chrome = launchChrome('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',profile,'about:blank');
|
||||
const log = {platform,width,checks:[],captures:[]};
|
||||
let c;
|
||||
const names = async () => (await axNodes(c)).flatMap(n=>[n.name?.value??'',n.value?.value??'']);
|
||||
const node = async name => (await axNodes(c)).find(n=>n.name?.value===name&&n.backendDOMNodeId);
|
||||
const emit = body => fetch(fixture.url+'/fixture/chat-event',{method:'POST',body:JSON.stringify(body)});
|
||||
try {
|
||||
c = await connect((await waitForPage(await waitForPort(join(profile,'DevToolsActivePort')))).webSocketDebuggerUrl);
|
||||
await c.send('Page.enable');
|
||||
if(platform==='material') await c.send('Emulation.setUserAgentOverride',{
|
||||
userAgent:'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36',platform:'Win32',
|
||||
});
|
||||
await c.send('Emulation.setDeviceMetricsOverride',{width,height:844,deviceScaleFactor:1,mobile:false});
|
||||
await c.send('Page.navigate',{url:fixture.url+'/chat/ses_probechat'});
|
||||
assert.ok(await waitFor(()=>c.evaluate("Boolean(document.querySelector('flt-semantics-placeholder'))"),30000));
|
||||
await enableSemantics(c);
|
||||
const badge=await waitFor(()=>node('Background tasks, 2 tasks'),15000);
|
||||
assert.ok(badge,'live count badge');
|
||||
const send=await node('Send');assert.ok(send,'Send control');
|
||||
const {model:b}=await c.send('DOM.getBoxModel',{backendNodeId:badge.backendDOMNodeId});
|
||||
const {model:s}=await c.send('DOM.getBoxModel',{backendNodeId:send.backendDOMNodeId});
|
||||
assert.ok(b.content[5]<=s.content[1]+1,'task badge above Send');
|
||||
assert.ok(!(await names()).some(name=>name.includes('tail -f fixture.log')),'no tasks in the transcript');
|
||||
await capture(c,output,log,'01-badge-above-send');
|
||||
log.checks.push('running count above Send; task list absent from chat body');
|
||||
await click(c,'Background tasks, 2 tasks');
|
||||
assert.ok(await waitFor(async()=>(await names()).some(name=>name.includes('tail -f fixture.log')),10000));
|
||||
assert.ok(!(await names()).some(name=>name.includes('old finished command')));
|
||||
let state=await (await fetch(fixture.url+'/fixture/state')).json();
|
||||
assert.equal(state.shellOutputRequests.length,0,'no eager output read');
|
||||
await click(c,'tail -f fixture.log');
|
||||
assert.ok(await waitFor(async()=>(await names()).some(name=>name.includes('Recorded output line 0')),10000));
|
||||
state=await (await fetch(fixture.url+'/fixture/state')).json();
|
||||
assert.deepEqual(state.shellOutputRequests[0],{session_id:'ses_probechat',shell_id:'a',cursor:0,limit:65536});
|
||||
await capture(c,output,log,'02-task-output-in-modal');
|
||||
log.checks.push('native modal exposes tasks and lazy bounded output');
|
||||
await emit({kind:'shell',shell:{id:'a',status:'exited'}});
|
||||
assert.ok(await waitFor(async()=>(await names()).includes('1 running'),10000));
|
||||
assert.ok(!(await names()).some(name=>name.includes('Recorded output line 0')),'exited task output removed');
|
||||
await capture(c,output,log,'03-live-task-exit');
|
||||
await click(c,'Done');
|
||||
assert.ok(await waitFor(()=>node('Background tasks, 1 task'),10000));
|
||||
await emit({kind:'shell',shell:{id:'b',status:'exited'}});
|
||||
assert.ok(await waitFor(()=>node('Background tasks, 0 tasks'),10000));
|
||||
await click(c,'Background tasks, 0 tasks');
|
||||
assert.ok(await waitFor(async()=>(await names()).includes('No background tasks running.'),10000));
|
||||
await capture(c,output,log,'04-empty-modal');
|
||||
await click(c,'Done');
|
||||
log.checks.push('modal updates live on exits; dismissal restores chat; zero count opens honest empty state');
|
||||
console.log(JSON.stringify(log,null,2));
|
||||
} catch(error) {
|
||||
if(c) {await capture(c,output,log,'failure');await writeFile(join(output,'failure-ax.json'),JSON.stringify(await axNodes(c),null,2));}
|
||||
throw error;
|
||||
} finally {
|
||||
await writeFile(join(output,'result.json'),JSON.stringify(log,null,2));
|
||||
c?.close();const exited=once(chrome,'exit');chrome.kill();await exited;await fixture.close();
|
||||
}
|
||||
@@ -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, runDetail, files = {}, chatMessages, chatSessions, chatHistoryDelayMs = 0, onChatHistory }) {
|
||||
export async function startFixture({ root, runs = RUNS, runDetail, files = {}, chatMessages, chatSessions, chatShells = [], chatShellOutput = '', chatHistoryDelayMs = 0, onChatHistory }) {
|
||||
const base = await realpath(root);
|
||||
const connections = new Set();
|
||||
const sockets = new Set();
|
||||
@@ -327,6 +327,7 @@ export async function startFixture({ root, runs = RUNS, runDetail, files = {}, c
|
||||
let chatSubscribed = 0;
|
||||
let chatHistory = 0;
|
||||
const chatPrompts = [];
|
||||
const shellOutputRequests = [];
|
||||
const fileReads = [];
|
||||
let chatRunning = false;
|
||||
let chatInterrupts = 0;
|
||||
@@ -367,6 +368,9 @@ export async function startFixture({ root, runs = RUNS, runDetail, files = {}, c
|
||||
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';
|
||||
if (event.kind === 'shell' && event.shell?.id) {
|
||||
chatShells = [...chatShells.filter(shell => shell.id !== event.shell.id), event.shell];
|
||||
}
|
||||
broadcast({ type: 'chat_event', chat_event: {
|
||||
session_id: CHAT_SESSION.id, ...event,
|
||||
} });
|
||||
@@ -417,6 +421,7 @@ export async function startFixture({ root, runs = RUNS, runDetail, files = {}, c
|
||||
chatSubscribed,
|
||||
chatHistory,
|
||||
chatPrompts,
|
||||
shellOutputRequests,
|
||||
chatRunning,
|
||||
chatInterrupts,
|
||||
fileReads,
|
||||
@@ -580,7 +585,15 @@ export async function startFixture({ root, runs = RUNS, runDetail, files = {}, c
|
||||
return;
|
||||
}
|
||||
if (request.type === 'chat_shells') {
|
||||
client.send({ id: request.id, type: 'chat_shells', chat_shells: [] });
|
||||
client.send({ id: request.id, type: 'chat_shells', chat_shells: chatShells });
|
||||
return;
|
||||
}
|
||||
if (request.type === 'chat_shell_output') {
|
||||
const query = request.chat_shell_output_query ?? {};
|
||||
shellOutputRequests.push(query);
|
||||
const shell = chatShells.find(shell => shell.id === query.shell_id);
|
||||
client.send({ id: request.id, type: 'chat_shell_output', chat_shell_output:
|
||||
shell ? { shell, output: chatShellOutput } : { unavailable: true } });
|
||||
return;
|
||||
}
|
||||
if (request.type === 'chat_interrupt') {
|
||||
|
||||
Reference in New Issue
Block a user