From cd7f733a99254ebdc7e561a13eb3671e0824180e Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 8 May 2026 22:02:06 +0100 Subject: [PATCH] test: avoid agent count filter allocations --- src/agents/cli-runner.helpers.test.ts | 2 +- src/agents/openai-transport-stream.test.ts | 4 +++- .../compaction-successor-transcript.test.ts | 8 +++++--- src/agents/pi-hooks/compaction-safeguard.test.ts | 4 +++- src/agents/session-transcript-repair.test.ts | 2 +- src/agents/skills.loadworkspaceskillentries.test.ts | 4 +++- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/agents/cli-runner.helpers.test.ts b/src/agents/cli-runner.helpers.test.ts index 07c917cb96d..8f5b99b4fd9 100644 --- a/src/agents/cli-runner.helpers.test.ts +++ b/src/agents/cli-runner.helpers.test.ts @@ -437,7 +437,7 @@ describe("writeCliImages", () => { useResume: false, }); - expect(argv.filter((arg) => arg === "--image")).toHaveLength(1); + expect(argv.reduce((count, arg) => count + (arg === "--image" ? 1 : 0), 0)).toBe(1); expect(argv[argv.indexOf("--image") + 1]).toContain("openclaw-cli-images"); await expect(fs.readFile(prepared.imagePaths?.[0] ?? "")).resolves.toEqual( Buffer.from(explicitImage.data, "base64"), diff --git a/src/agents/openai-transport-stream.test.ts b/src/agents/openai-transport-stream.test.ts index a5eb59e49a7..eedfcf25fce 100644 --- a/src/agents/openai-transport-stream.test.ts +++ b/src/agents/openai-transport-stream.test.ts @@ -1301,7 +1301,9 @@ describe("openai transport stream", () => { }>; }; - expect(params.input?.filter((item) => item.type === "reasoning")).toHaveLength(1); + expect( + params.input?.reduce((count, item) => count + (item.type === "reasoning" ? 1 : 0), 0), + ).toBe(1); const assistantMessage = params.input?.find( (item) => item.type === "message" && item.role === "assistant", ); diff --git a/src/agents/pi-embedded-runner/compaction-successor-transcript.test.ts b/src/agents/pi-embedded-runner/compaction-successor-transcript.test.ts index b2ffbd0ce83..c385b5bb53f 100644 --- a/src/agents/pi-embedded-runner/compaction-successor-transcript.test.ts +++ b/src/agents/pi-embedded-runner/compaction-successor-transcript.test.ts @@ -179,9 +179,11 @@ describe("rotateTranscriptAfterCompaction", () => { expect(entries.find((entry) => entry.id === staleModelId)).toBeUndefined(); expect(entries.find((entry) => entry.id === staleThinkingId)).toBeUndefined(); expect(entries.find((entry) => entry.id === staleSessionInfoId)).toBeUndefined(); - expect(entries.filter((entry) => entry.type === "model_change")).toHaveLength(1); - expect(entries.filter((entry) => entry.type === "thinking_level_change")).toHaveLength(1); - expect(entries.filter((entry) => entry.type === "session_info")).toHaveLength(1); + const countEntryType = (type: (typeof entries)[number]["type"]) => + entries.reduce((count, entry) => count + (entry.type === type ? 1 : 0), 0); + expect(countEntryType("model_change")).toBe(1); + expect(countEntryType("thinking_level_change")).toBe(1); + expect(countEntryType("session_info")).toBe(1); expect(entries.find((entry) => entry.type === "model_change")).toMatchObject({ provider: "openai", modelId: "gpt-5.2", diff --git a/src/agents/pi-hooks/compaction-safeguard.test.ts b/src/agents/pi-hooks/compaction-safeguard.test.ts index 0354707ec11..931531423aa 100644 --- a/src/agents/pi-hooks/compaction-safeguard.test.ts +++ b/src/agents/pi-hooks/compaction-safeguard.test.ts @@ -899,7 +899,9 @@ describe("compaction-safeguard recent-turn preservation", () => { const identifiers = extractOpaqueIdentifiers( "Track id a1b2c3d4e5f6 plus A1B2C3D4E5F6 and again a1b2c3d4e5f6", ); - expect(identifiers.filter((id) => id === "A1B2C3D4E5F6")).toHaveLength(1); // pragma: allowlist secret + expect( + identifiers.reduce((count, id) => count + (id === "A1B2C3D4E5F6" ? 1 : 0), 0), // pragma: allowlist secret + ).toBe(1); }); it("dedupes identifiers before applying the result cap", () => { diff --git a/src/agents/session-transcript-repair.test.ts b/src/agents/session-transcript-repair.test.ts index d3635036d6f..0e74006559e 100644 --- a/src/agents/session-transcript-repair.test.ts +++ b/src/agents/session-transcript-repair.test.ts @@ -175,7 +175,7 @@ describe("sanitizeToolUseResultPairing", () => { ]); const out = sanitizeToolUseResultPairing(input); - expect(out.filter((m) => m.role === "toolResult")).toHaveLength(1); + expect(out.reduce((count, m) => count + (m.role === "toolResult" ? 1 : 0), 0)).toBe(1); }); it("drops duplicate tool results for the same id across the transcript", () => { diff --git a/src/agents/skills.loadworkspaceskillentries.test.ts b/src/agents/skills.loadworkspaceskillentries.test.ts index 5f0ba4a3347..3b585b1ced9 100644 --- a/src/agents/skills.loadworkspaceskillentries.test.ts +++ b/src/agents/skills.loadworkspaceskillentries.test.ts @@ -561,7 +561,9 @@ describe("loadWorkspaceSkillEntries", () => { }, }).map((entry) => entry.skill.name); - expect(names.filter((name) => name.startsWith("nested-skill-"))).toHaveLength(2); + expect( + names.reduce((count, name) => count + (name.startsWith("nested-skill-") ? 1 : 0), 0), + ).toBe(2); expect( warn.mock.calls .map(([line]) => String(line))