test: dedupe and optimize test suites

This commit is contained in:
Peter Steinberger
2026-02-19 15:18:50 +00:00
parent b0e55283d5
commit a1cb700a05
80 changed files with 2627 additions and 2962 deletions

View File

@@ -1,4 +1,4 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
import "./subagent-registry.mocks.shared.js";
vi.mock("../config/config.js", () => ({
@@ -17,15 +17,19 @@ vi.mock("./subagent-registry.store.js", () => ({
saveSubagentRegistryToDisk: vi.fn(() => {}),
}));
let subagentRegistry: typeof import("./subagent-registry.js");
describe("subagent registry nested agent tracking", () => {
afterEach(async () => {
const mod = await import("./subagent-registry.js");
mod.resetSubagentRegistryForTests({ persist: false });
beforeAll(async () => {
subagentRegistry = await import("./subagent-registry.js");
});
afterEach(() => {
subagentRegistry.resetSubagentRegistryForTests({ persist: false });
});
it("listSubagentRunsForRequester returns children of the requesting session", async () => {
const { registerSubagentRun, listSubagentRunsForRequester } =
await import("./subagent-registry.js");
const { registerSubagentRun, listSubagentRunsForRequester } = subagentRegistry;
// Main agent spawns a depth-1 orchestrator
registerSubagentRun({
@@ -67,7 +71,7 @@ describe("subagent registry nested agent tracking", () => {
});
it("announce uses requesterSessionKey to route to the correct parent", async () => {
const { registerSubagentRun } = await import("./subagent-registry.js");
const { registerSubagentRun } = subagentRegistry;
// Register a sub-sub-agent whose parent is a sub-agent
registerSubagentRun({
runId: "run-subsub",
@@ -82,7 +86,7 @@ describe("subagent registry nested agent tracking", () => {
// When announce fires for the sub-sub-agent, it should target the sub-agent (depth-1),
// NOT the main session. The registry entry's requesterSessionKey ensures this.
// We verify the registry entry has the correct requesterSessionKey.
const { listSubagentRunsForRequester } = await import("./subagent-registry.js");
const { listSubagentRunsForRequester } = subagentRegistry;
const orchRuns = listSubagentRunsForRequester("agent:main:subagent:orch");
expect(orchRuns).toHaveLength(1);
expect(orchRuns[0].requesterSessionKey).toBe("agent:main:subagent:orch");
@@ -90,8 +94,7 @@ describe("subagent registry nested agent tracking", () => {
});
it("countActiveRunsForSession only counts active children of the specific session", async () => {
const { registerSubagentRun, countActiveRunsForSession } =
await import("./subagent-registry.js");
const { registerSubagentRun, countActiveRunsForSession } = subagentRegistry;
// Main spawns orchestrator (active)
registerSubagentRun({
@@ -130,8 +133,7 @@ describe("subagent registry nested agent tracking", () => {
});
it("countActiveDescendantRuns traverses through ended parents", async () => {
const { addSubagentRunForTests, countActiveDescendantRuns } =
await import("./subagent-registry.js");
const { addSubagentRunForTests, countActiveDescendantRuns } = subagentRegistry;
addSubagentRunForTests({
runId: "run-parent-ended",