test: avoid agent count filter allocations · openclaw/openclaw@cd7f733
steipete
·
2026-05-09
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -437,7 +437,7 @@ describe("writeCliImages", () => {
|
437 | 437 | useResume: false, |
438 | 438 | }); |
439 | 439 | |
440 | | -expect(argv.filter((arg) => arg === "--image")).toHaveLength(1); |
| 440 | +expect(argv.reduce((count, arg) => count + (arg === "--image" ? 1 : 0), 0)).toBe(1); |
441 | 441 | expect(argv[argv.indexOf("--image") + 1]).toContain("openclaw-cli-images"); |
442 | 442 | await expect(fs.readFile(prepared.imagePaths?.[0] ?? "")).resolves.toEqual( |
443 | 443 | Buffer.from(explicitImage.data, "base64"), |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1301,7 +1301,9 @@ describe("openai transport stream", () => {
|
1301 | 1301 | }>; |
1302 | 1302 | }; |
1303 | 1303 | |
1304 | | -expect(params.input?.filter((item) => item.type === "reasoning")).toHaveLength(1); |
| 1304 | +expect( |
| 1305 | +params.input?.reduce((count, item) => count + (item.type === "reasoning" ? 1 : 0), 0), |
| 1306 | +).toBe(1); |
1305 | 1307 | const assistantMessage = params.input?.find( |
1306 | 1308 | (item) => item.type === "message" && item.role === "assistant", |
1307 | 1309 | ); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -179,9 +179,11 @@ describe("rotateTranscriptAfterCompaction", () => {
|
179 | 179 | expect(entries.find((entry) => entry.id === staleModelId)).toBeUndefined(); |
180 | 180 | expect(entries.find((entry) => entry.id === staleThinkingId)).toBeUndefined(); |
181 | 181 | expect(entries.find((entry) => entry.id === staleSessionInfoId)).toBeUndefined(); |
182 | | -expect(entries.filter((entry) => entry.type === "model_change")).toHaveLength(1); |
183 | | -expect(entries.filter((entry) => entry.type === "thinking_level_change")).toHaveLength(1); |
184 | | -expect(entries.filter((entry) => entry.type === "session_info")).toHaveLength(1); |
| 182 | +const countEntryType = (type: (typeof entries)[number]["type"]) => |
| 183 | +entries.reduce((count, entry) => count + (entry.type === type ? 1 : 0), 0); |
| 184 | +expect(countEntryType("model_change")).toBe(1); |
| 185 | +expect(countEntryType("thinking_level_change")).toBe(1); |
| 186 | +expect(countEntryType("session_info")).toBe(1); |
185 | 187 | expect(entries.find((entry) => entry.type === "model_change")).toMatchObject({ |
186 | 188 | provider: "openai", |
187 | 189 | modelId: "gpt-5.2", |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -899,7 +899,9 @@ describe("compaction-safeguard recent-turn preservation", () => {
|
899 | 899 | const identifiers = extractOpaqueIdentifiers( |
900 | 900 | "Track id a1b2c3d4e5f6 plus A1B2C3D4E5F6 and again a1b2c3d4e5f6", |
901 | 901 | ); |
902 | | -expect(identifiers.filter((id) => id === "A1B2C3D4E5F6")).toHaveLength(1); // pragma: allowlist secret |
| 902 | +expect( |
| 903 | +identifiers.reduce((count, id) => count + (id === "A1B2C3D4E5F6" ? 1 : 0), 0), // pragma: allowlist secret |
| 904 | +).toBe(1); |
903 | 905 | }); |
904 | 906 | |
905 | 907 | it("dedupes identifiers before applying the result cap", () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -175,7 +175,7 @@ describe("sanitizeToolUseResultPairing", () => {
|
175 | 175 | ]); |
176 | 176 | |
177 | 177 | const out = sanitizeToolUseResultPairing(input); |
178 | | -expect(out.filter((m) => m.role === "toolResult")).toHaveLength(1); |
| 178 | +expect(out.reduce((count, m) => count + (m.role === "toolResult" ? 1 : 0), 0)).toBe(1); |
179 | 179 | }); |
180 | 180 | |
181 | 181 | it("drops duplicate tool results for the same id across the transcript", () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -561,7 +561,9 @@ describe("loadWorkspaceSkillEntries", () => {
|
561 | 561 | }, |
562 | 562 | }).map((entry) => entry.skill.name); |
563 | 563 | |
564 | | -expect(names.filter((name) => name.startsWith("nested-skill-"))).toHaveLength(2); |
| 564 | +expect( |
| 565 | +names.reduce((count, name) => count + (name.startsWith("nested-skill-") ? 1 : 0), 0), |
| 566 | +).toBe(2); |
565 | 567 | expect( |
566 | 568 | warn.mock.calls |
567 | 569 | .map(([line]) => String(line)) |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。