






















@@ -52,6 +52,16 @@ vi.mock("./tools/agent-step.js", () => ({
5252const callGatewayMock = getCallGatewayMock();
5353const RUN_TIMEOUT_SECONDS = 1;
545455+function countMatching<T>(items: readonly T[], predicate: (item: T) => boolean): number {
56+let count = 0;
57+for (const item of items) {
58+if (predicate(item)) {
59+count += 1;
60+}
61+}
62+return count;
63+}
64+5565function buildDiscordCleanupHooks(onDelete: (key: string | undefined) => void) {
5666return {
5767onAgentSubagentSpawn: (params: unknown) => {
@@ -235,7 +245,7 @@ describe("openclaw-tools: subagents (sessions_spawn lifecycle)", () => {
235245() =>
236246ctx.waitCalls.some((call) => call.runId === child.runId) &&
237247patchCalls.some((call) => call.label === "my-task") &&
238-ctx.calls.filter((call) => call.method === "agent").length >= 2,
248+countMatching(ctx.calls, (call) => call.method === "agent") >= 2,
239249);
240250if (!child.sessionKey) {
241251throw new Error("missing child sessionKey");
@@ -371,7 +381,7 @@ describe("openclaw-tools: subagents (sessions_spawn lifecycle)", () => {
371381372382await waitForSessionsSpawnEvent(
373383"lifecycle cleanup",
374-() => ctx.calls.filter((call) => call.method === "agent").length >= 2 && Boolean(deletedKey),
384+() => countMatching(ctx.calls, (call) => call.method === "agent") >= 2 && Boolean(deletedKey),
375385);
376386377387const childWait = ctx.waitCalls.find((call) => call.runId === child.runId);
@@ -437,7 +447,7 @@ describe("openclaw-tools: subagents (sessions_spawn lifecycle)", () => {
437447);
438448await waitForSessionsSpawnEvent(
439449"main agent cleanup trigger",
440-() => ctx.calls.filter((call) => call.method === "agent").length >= 2,
450+() => countMatching(ctx.calls, (call) => call.method === "agent") >= 2,
441451);
442452await waitForSessionsSpawnEvent("delete cleanup", () => Boolean(deletedKey));
443453@@ -563,7 +573,7 @@ describe("openclaw-tools: subagents (sessions_spawn lifecycle)", () => {
563573564574await waitForSessionsSpawnEvent(
565575"account-aware lifecycle announce",
566-() => ctx.calls.filter((call) => call.method === "agent").length >= 2,
576+() => countMatching(ctx.calls, (call) => call.method === "agent") >= 2,
567577);
568578await waitForRunCleanup(child.sessionKey);
569579此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。