test(auto-reply): centralize subagent command test reset setup

This commit is contained in:
Peter Steinberger
2026-02-22 07:39:05 +00:00
parent b56c07e991
commit 8acf5ffca7

View File

@@ -871,9 +871,12 @@ describe("handleCommands context", () => {
}); });
describe("handleCommands subagents", () => { describe("handleCommands subagents", () => {
it("lists subagents when none exist", async () => { beforeEach(() => {
resetSubagentRegistryForTests(); resetSubagentRegistryForTests();
callGatewayMock.mockReset(); callGatewayMock.mockReset();
});
it("lists subagents when none exist", async () => {
const cfg = { const cfg = {
commands: { text: true }, commands: { text: true },
channels: { whatsapp: { allowFrom: ["*"] } }, channels: { whatsapp: { allowFrom: ["*"] } },
@@ -889,8 +892,6 @@ describe("handleCommands subagents", () => {
}); });
it("truncates long subagent task text in /subagents list", async () => { it("truncates long subagent task text in /subagents list", async () => {
resetSubagentRegistryForTests();
callGatewayMock.mockReset();
addSubagentRunForTests({ addSubagentRunForTests({
runId: "run-long-task", runId: "run-long-task",
childSessionKey: "agent:main:subagent:long-task", childSessionKey: "agent:main:subagent:long-task",
@@ -916,8 +917,6 @@ describe("handleCommands subagents", () => {
}); });
it("lists subagents for the current command session over the target session", async () => { it("lists subagents for the current command session over the target session", async () => {
resetSubagentRegistryForTests();
callGatewayMock.mockReset();
addSubagentRunForTests({ addSubagentRunForTests({
runId: "run-1", runId: "run-1",
childSessionKey: "agent:main:subagent:abc", childSessionKey: "agent:main:subagent:abc",
@@ -955,8 +954,6 @@ describe("handleCommands subagents", () => {
}); });
it("formats subagent usage with io and prompt/cache breakdown", async () => { it("formats subagent usage with io and prompt/cache breakdown", async () => {
resetSubagentRegistryForTests();
callGatewayMock.mockReset();
addSubagentRunForTests({ addSubagentRunForTests({
runId: "run-usage", runId: "run-usage",
childSessionKey: "agent:main:subagent:usage", childSessionKey: "agent:main:subagent:usage",
@@ -992,7 +989,6 @@ describe("handleCommands subagents", () => {
}); });
it("omits subagent status line when none exist", async () => { it("omits subagent status line when none exist", async () => {
resetSubagentRegistryForTests();
const cfg = { const cfg = {
commands: { text: true }, commands: { text: true },
channels: { whatsapp: { allowFrom: ["*"] } }, channels: { whatsapp: { allowFrom: ["*"] } },
@@ -1006,8 +1002,6 @@ describe("handleCommands subagents", () => {
}); });
it("returns help/usage for invalid or incomplete subagents commands", async () => { it("returns help/usage for invalid or incomplete subagents commands", async () => {
resetSubagentRegistryForTests();
callGatewayMock.mockReset();
const cfg = { const cfg = {
commands: { text: true }, commands: { text: true },
channels: { whatsapp: { allowFrom: ["*"] } }, channels: { whatsapp: { allowFrom: ["*"] } },
@@ -1025,8 +1019,6 @@ describe("handleCommands subagents", () => {
}); });
it("includes subagent count in /status when active", async () => { it("includes subagent count in /status when active", async () => {
resetSubagentRegistryForTests();
callGatewayMock.mockReset();
addSubagentRunForTests({ addSubagentRunForTests({
runId: "run-1", runId: "run-1",
childSessionKey: "agent:main:subagent:abc", childSessionKey: "agent:main:subagent:abc",
@@ -1049,8 +1041,6 @@ describe("handleCommands subagents", () => {
}); });
it("includes subagent details in /status when verbose", async () => { it("includes subagent details in /status when verbose", async () => {
resetSubagentRegistryForTests();
callGatewayMock.mockReset();
addSubagentRunForTests({ addSubagentRunForTests({
runId: "run-1", runId: "run-1",
childSessionKey: "agent:main:subagent:abc", childSessionKey: "agent:main:subagent:abc",
@@ -1087,8 +1077,6 @@ describe("handleCommands subagents", () => {
}); });
it("returns info for a subagent", async () => { it("returns info for a subagent", async () => {
resetSubagentRegistryForTests();
callGatewayMock.mockReset();
const now = Date.now(); const now = Date.now();
addSubagentRunForTests({ addSubagentRunForTests({
runId: "run-1", runId: "run-1",
@@ -1116,8 +1104,6 @@ describe("handleCommands subagents", () => {
}); });
it("kills subagents via /kill alias without a confirmation reply", async () => { it("kills subagents via /kill alias without a confirmation reply", async () => {
resetSubagentRegistryForTests();
callGatewayMock.mockReset();
addSubagentRunForTests({ addSubagentRunForTests({
runId: "run-1", runId: "run-1",
childSessionKey: "agent:main:subagent:abc", childSessionKey: "agent:main:subagent:abc",
@@ -1139,8 +1125,6 @@ describe("handleCommands subagents", () => {
}); });
it("resolves numeric aliases in active-first display order", async () => { it("resolves numeric aliases in active-first display order", async () => {
resetSubagentRegistryForTests();
callGatewayMock.mockReset();
const now = Date.now(); const now = Date.now();
addSubagentRunForTests({ addSubagentRunForTests({
runId: "run-active", runId: "run-active",
@@ -1175,8 +1159,6 @@ describe("handleCommands subagents", () => {
}); });
it("sends follow-up messages to finished subagents", async () => { it("sends follow-up messages to finished subagents", async () => {
resetSubagentRegistryForTests();
callGatewayMock.mockReset();
callGatewayMock.mockImplementation(async (opts: unknown) => { callGatewayMock.mockImplementation(async (opts: unknown) => {
const request = opts as { method?: string; params?: { runId?: string } }; const request = opts as { method?: string; params?: { runId?: string } };
if (request.method === "agent") { if (request.method === "agent") {
@@ -1234,8 +1216,6 @@ describe("handleCommands subagents", () => {
}); });
it("steers subagents via /steer alias", async () => { it("steers subagents via /steer alias", async () => {
resetSubagentRegistryForTests();
callGatewayMock.mockReset();
callGatewayMock.mockImplementation(async (opts: unknown) => { callGatewayMock.mockImplementation(async (opts: unknown) => {
const request = opts as { method?: string }; const request = opts as { method?: string };
if (request.method === "agent") { if (request.method === "agent") {
@@ -1300,8 +1280,6 @@ describe("handleCommands subagents", () => {
}); });
it("restores announce behavior when /steer replacement dispatch fails", async () => { it("restores announce behavior when /steer replacement dispatch fails", async () => {
resetSubagentRegistryForTests();
callGatewayMock.mockReset();
callGatewayMock.mockImplementation(async (opts: unknown) => { callGatewayMock.mockImplementation(async (opts: unknown) => {
const request = opts as { method?: string }; const request = opts as { method?: string };
if (request.method === "agent.wait") { if (request.method === "agent.wait") {