// What counts as a running subagent, and the menu badge's wording. Run by // `npm test`, which Node runs with its built-in test runner and type // stripping, so the `.ts` module is imported as it is. import assert from "node:assert/strict"; import { test } from "node:test"; import { STALE_S, byRecency, isRunning, runningLabel, splitRunning, } from "../src/agent/terminal/subagent-list.ts"; const NOW = 1_000_000; const sub = (name, ago) => ({ name, last_row_unix: ago === null ? null : NOW - ago, }); test("a subagent with a recent row is running, a quiet one is not", () => { assert.equal(isRunning(sub("a", 5), NOW), true); assert.equal(isRunning(sub("a", STALE_S), NOW), true); assert.equal(isRunning(sub("a", STALE_S + 1), NOW), false); }); test("a subagent whose time could not be read is not counted as running", () => { assert.equal(isRunning(sub("a", null), NOW), false); }); test("newest first, unreadable last, ties by name", () => { const list = [sub("c", 50), sub("z", null), sub("b", 10), sub("a", 10)]; assert.deepEqual( [...list].sort(byRecency).map((s) => s.name), ["a", "b", "c", "z"], ); }); test("the list splits into running and quiet, each newest first", () => { const { running, quiet } = splitRunning( [ sub("old", STALE_S + 100), sub("new", 1), sub("mid", 60), sub("none", null), ], NOW, ); assert.deepEqual( running.map((s) => s.name), ["new", "mid"], ); assert.deepEqual( quiet.map((s) => s.name), ["old", "none"], ); }); test("the badge counts in words", () => { assert.equal(runningLabel(1), "1 running subagent"); assert.equal(runningLabel(4), "4 running subagents"); });