fix(chat): keep tool totals neutral and count individual errors

This commit is contained in:
2026-10-20 22:05:21 +01:00
parent e29be1181f
commit aa57fe8a04
8 changed files with 123 additions and 10 deletions
+17
View File
@@ -0,0 +1,17 @@
import test from "node:test";
import assert from "node:assert/strict";
import { toolFailureCount, toolCallCount } from "../src/chat.js";
test("one error among 82 calls is one failed call, not an entirely failed tool group", () => {
const parts = Array.from({ length: 82 }, (_, i) => ({type:"tool",state:{status:i===17?"error":"completed"}}));
assert.equal(toolCallCount(parts),82);
assert.equal(toolFailureCount(parts),1);
parts.push({type:"text",state:{status:"error"}});
assert.equal(toolFailureCount(parts),1);
});
test("error counts ignore running and missing states and keep multiple failures", () => {
assert.equal(toolFailureCount(null),0);
assert.equal(toolFailureCount([{type:"tool"},{type:"tool",state:{status:"running"}}]),0);
assert.equal(toolFailureCount([{type:"tool",state:{status:"error"}},{type:"tool",state:{status:"error"}}]),2);
});