Add live subagent dashboard and default to 16 workers
This commit is contained in:
1 parent
7b3686f55d
commit
b8e5c7eab5
17 files changed
+1079
-104
No files matched your search
+58
-1
@@ -1,7 +1,9 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import type { Message } from "@earendil-works/pi-ai";
|
||||
import { SubagentManager } from "../src/manager.ts";
|
||||
import { FakeRunner, invocation } from "./helpers.ts";
|
||||
import type { JobSnapshot } from "../src/types.ts";
|
||||
import { FakeRunner, invocation, result as makeResult } from "./helpers.ts";
|
||||
|
||||
test("async single returns an ID before completion and later exposes its result", async () => {
|
||||
const runner = new FakeRunner();
|
||||
@@ -20,6 +22,44 @@ test("async single returns an ID before completion and later exposes its result"
|
||||
assert.equal(terminal.results[0].status, "succeeded");
|
||||
});
|
||||
|
||||
test("async progress exposes bounded activity without persisting every message", async () => {
|
||||
const persisted: JobSnapshot[] = [];
|
||||
const progress: JobSnapshot[] = [];
|
||||
const runner = new FakeRunner();
|
||||
const manager = new SubagentManager(runner, {
|
||||
onJobChange: (job) => persisted.push(job),
|
||||
onJobActivity: (job) => progress.push(job),
|
||||
});
|
||||
const job = manager.startAsync(invocation());
|
||||
const persistedBeforeProgress = persisted.length;
|
||||
const pending = runner.calls[0];
|
||||
const messages = [{
|
||||
role: "assistant",
|
||||
content: [{ type: "toolCall", id: "call-1", name: "bash", arguments: { command: "npm test" } }],
|
||||
timestamp: 100,
|
||||
}] as unknown as Message[];
|
||||
|
||||
pending.options.onUpdate?.({
|
||||
...makeResult(pending.task, "working"),
|
||||
status: "running",
|
||||
exitCode: null,
|
||||
messages,
|
||||
});
|
||||
|
||||
const current = manager.get(job.id);
|
||||
assert.equal(current.results[0].output, "working");
|
||||
assert.deepEqual(current.results[0].activity, [
|
||||
{ kind: "toolCall", summary: "$ npm test", timestamp: 100 },
|
||||
]);
|
||||
assert.equal(progress.length, 1);
|
||||
assert.equal(persisted.length, persistedBeforeProgress);
|
||||
|
||||
runner.complete("task 1", "finished");
|
||||
const terminal = await manager.wait(job.id, 1);
|
||||
assert.equal(terminal.results[0].activity?.[0].summary, "$ npm test");
|
||||
assert.equal(persisted.at(-1)?.results[0].activity?.[0].summary, "$ npm test");
|
||||
});
|
||||
|
||||
test("parallel preserves partial results and does not finish while another task can run", async () => {
|
||||
const runner = new FakeRunner();
|
||||
const manager = new SubagentManager(runner, { maxWorkers: 1 });
|
||||
@@ -78,6 +118,23 @@ test("cancel drains queued tasks, aborts running tasks, and is idempotent", asyn
|
||||
assert.equal(manager.cancel(job.id).status, "cancelled");
|
||||
});
|
||||
|
||||
test("the manager defaults to sixteen shared workers", async () => {
|
||||
const runner = new FakeRunner();
|
||||
const manager = new SubagentManager(runner);
|
||||
const request = invocation("parallel");
|
||||
request.tasks = Array.from({ length: 17 }, (_, index) => ({ ...request.tasks[0], task: `task ${index + 1}` }));
|
||||
|
||||
const job = manager.startAsync(request);
|
||||
assert.equal(runner.calls.length, 16);
|
||||
assert.equal(manager.get(job.id).results.filter((task) => task.status === "queued").length, 1);
|
||||
|
||||
for (const pending of [...runner.calls]) runner.complete(pending.task.task);
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
assert.equal(runner.calls.length, 17);
|
||||
runner.complete("task 17");
|
||||
assert.equal((await manager.wait(job.id, 1)).status, "succeeded");
|
||||
});
|
||||
|
||||
test("synchronous and async work share the global worker limit", async () => {
|
||||
const runner = new FakeRunner();
|
||||
const manager = new SubagentManager(runner, { maxWorkers: 1 });
|
||||
|
||||
Reference in new issue
Block a user