test(extension): cover background completion notifications
This commit is contained in:
@@ -14,7 +14,16 @@ test("status tool shows active runs by default and can query single run", async
|
||||
// default should show only active (running) runs
|
||||
assert.equal(resDefault.details.runs.length, 1);
|
||||
assert.equal(resDefault.details.runs[0].runId, "r1");
|
||||
assert.deepEqual(resDefault.details.counts, {
|
||||
running: 1,
|
||||
completed: 1,
|
||||
failed: 0,
|
||||
aborted: 0,
|
||||
total: 2,
|
||||
});
|
||||
assert.match(resDefault.content[0].text, /Active runs: 1/);
|
||||
assert.match(resDefault.content[0].text, /running=1/);
|
||||
assert.match(resDefault.content[0].text, /total=2/);
|
||||
// assert counts appear in details and text
|
||||
assert.deepEqual(resDefault.details.counts, { running: 1, completed: 1, failed: 0, aborted: 0, total: 2 });
|
||||
assert.match(resDefault.content[0].text, /running=1\s+completed=1\s+failed=0\s+aborted=0\s+total=2/);
|
||||
@@ -22,6 +31,7 @@ test("status tool shows active runs by default and can query single run", async
|
||||
const resSingle: any = await tool.execute("id", { runId: "r2" }, undefined, undefined, undefined);
|
||||
assert.equal(resSingle.details.runs.length, 1);
|
||||
assert.equal(resSingle.details.runs[0].runId, "r2");
|
||||
assert.equal(resSingle.details.counts.completed, 1);
|
||||
assert.match(resSingle.content[0].text, /status=completed/);
|
||||
assert.deepEqual(resSingle.details.counts, { running: 1, completed: 1, failed: 0, aborted: 0, total: 2 });
|
||||
|
||||
|
||||
@@ -429,3 +429,109 @@ test("empty model list should NOT register the tool, but a later non-empty list
|
||||
else process.env.PI_SUBAGENTS_CHILD = original;
|
||||
}
|
||||
});
|
||||
|
||||
test("background completion updates footer status, appends session updates, notifies UI, and sends a non-triggering session message", async () => {
|
||||
const original = process.env.PI_SUBAGENTS_CHILD;
|
||||
if (original !== undefined) delete process.env.PI_SUBAGENTS_CHILD;
|
||||
|
||||
try {
|
||||
const handlers: any = {};
|
||||
const registeredTools: any[] = [];
|
||||
const appendedEntries: Array<{ type: string; data: any }> = [];
|
||||
const sentMessages: Array<{ message: any; options: any }> = [];
|
||||
const notifications: Array<{ message: string; type: string | undefined }> = [];
|
||||
const statuses: Array<{ key: string; text: string | undefined }> = [];
|
||||
|
||||
subagentsExtension(
|
||||
{
|
||||
on(event: string, handler: (event: any, ctx: any) => Promise<void> | void) {
|
||||
handlers[event] = handler;
|
||||
},
|
||||
registerTool(tool: any) {
|
||||
registeredTools.push(tool);
|
||||
},
|
||||
registerProvider() {},
|
||||
appendEntry(type: string, data: any) {
|
||||
appendedEntries.push({ type, data });
|
||||
},
|
||||
sendMessage(message: any, options: any) {
|
||||
sentMessages.push({ message, options });
|
||||
},
|
||||
} as any,
|
||||
{
|
||||
monitorRun: async () => ({
|
||||
runId: "run-1",
|
||||
exitCode: 0,
|
||||
finalText: "done",
|
||||
stopReason: "stop",
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
await handlers.session_start?.(
|
||||
{ reason: "startup" },
|
||||
{
|
||||
modelRegistry: {
|
||||
getAvailable: () => [{ provider: "openai", id: "gpt-5" }],
|
||||
},
|
||||
ui: {
|
||||
notify(message: string, type?: string) {
|
||||
notifications.push({ message, type });
|
||||
},
|
||||
setStatus(key: string, text: string | undefined) {
|
||||
statuses.push({ key, text });
|
||||
},
|
||||
},
|
||||
sessionManager: {
|
||||
getEntries: () => [
|
||||
{
|
||||
type: "pi-subagents:bg-run",
|
||||
data: {
|
||||
run: {
|
||||
runId: "run-1",
|
||||
preset: "repo-scout",
|
||||
task: "inspect auth",
|
||||
status: "running",
|
||||
startTime: Date.now(),
|
||||
paths: {
|
||||
eventsPath: "/tmp/run-1/events.jsonl",
|
||||
resultPath: "/tmp/run-1/result.json",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
assert.equal(registeredTools.length, 3);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
||||
assert.deepEqual(appendedEntries, [
|
||||
{
|
||||
type: "pi-subagents:bg-update",
|
||||
data: { runId: "run-1", status: "completed", finalText: "done", exitCode: 0 },
|
||||
},
|
||||
]);
|
||||
assert.deepEqual(notifications, [
|
||||
{ message: "Background agent repo-scout finished: done", type: "info" },
|
||||
]);
|
||||
assert.deepEqual(sentMessages, [
|
||||
{
|
||||
message: {
|
||||
customType: "pi-subagents:bg-complete",
|
||||
content: "Background agent repo-scout completed (run-1): done",
|
||||
display: true,
|
||||
details: { runId: "run-1", status: "completed" },
|
||||
},
|
||||
options: { triggerTurn: false },
|
||||
},
|
||||
]);
|
||||
assert.deepEqual(statuses.at(-1), { key: "pi-subagents", text: "bg: 0 running / 1 total" });
|
||||
} finally {
|
||||
if (original === undefined) delete process.env.PI_SUBAGENTS_CHILD;
|
||||
else process.env.PI_SUBAGENTS_CHILD = original;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user