mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 09:30:43 +00:00
test: avoid agent count filter allocations
This commit is contained in:
@@ -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"),
|
||||
|
||||
@@ -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",
|
||||
);
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user