fix(chat): keep tool totals neutral and count individual errors
This commit is contained in:
@@ -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);
|
||||
});
|
||||
Reference in New Issue
Block a user