1+ /// <reference types="bun-types" />
2+
13import { describe , expect , test } from "bun:test"
24import {
35 createToolCallSignature ,
@@ -19,7 +21,7 @@ function buildWindow(
1921}
2022
2123function buildWindowWithInputs (
22- calls : Array < { tool : string ; input ?: Record < string , unknown > } > ,
24+ calls : Array < { tool : string ; input ?: Record < string , unknown > | null } > ,
2325 override ?: Parameters < typeof resolveCircuitBreakerSettings > [ 0 ]
2426) {
2527 const settings = resolveCircuitBreakerSettings ( override )
@@ -148,7 +150,12 @@ describe("loop-detector", () => {
148150
149151 describe ( "#given the same tool is called consecutively" , ( ) => {
150152 test ( "#when evaluated #then it triggers" , ( ) => {
151- const window = buildWindow ( Array . from ( { length : 20 } , ( ) => "read" ) )
153+ const window = buildWindowWithInputs (
154+ Array . from ( { length : 20 } , ( ) => ( {
155+ tool : "read" ,
156+ input : { filePath : "/src/same.ts" } ,
157+ } ) )
158+ )
152159
153160 const result = detectRepetitiveToolUse ( window )
154161
@@ -176,15 +183,25 @@ describe("loop-detector", () => {
176183
177184 describe ( "#given threshold boundary" , ( ) => {
178185 test ( "#when below threshold #then it does not trigger" , ( ) => {
179- const belowThresholdWindow = buildWindow ( Array . from ( { length : 19 } , ( ) => "read" ) )
186+ const belowThresholdWindow = buildWindowWithInputs (
187+ Array . from ( { length : 19 } , ( ) => ( {
188+ tool : "read" ,
189+ input : { filePath : "/src/same.ts" } ,
190+ } ) )
191+ )
180192
181193 const result = detectRepetitiveToolUse ( belowThresholdWindow )
182194
183195 expect ( result ) . toEqual ( { triggered : false } )
184196 } )
185197
186198 test ( "#when equal to threshold #then it triggers" , ( ) => {
187- const atThresholdWindow = buildWindow ( Array . from ( { length : 20 } , ( ) => "read" ) )
199+ const atThresholdWindow = buildWindowWithInputs (
200+ Array . from ( { length : 20 } , ( ) => ( {
201+ tool : "read" ,
202+ input : { filePath : "/src/same.ts" } ,
203+ } ) )
204+ )
188205
189206 const result = detectRepetitiveToolUse ( atThresholdWindow )
190207
@@ -224,16 +241,22 @@ describe("loop-detector", () => {
224241 } )
225242 } )
226243
227- describe ( "#given tool calls with no input" , ( ) => {
228- test ( "#when evaluated #then it triggers " , ( ) => {
244+ describe ( "#given tool calls with undefined input" , ( ) => {
245+ test ( "#when evaluated #then it does not trigger " , ( ) => {
229246 const calls = Array . from ( { length : 20 } , ( ) => ( { tool : "read" } ) )
230247 const window = buildWindowWithInputs ( calls )
231248 const result = detectRepetitiveToolUse ( window )
232- expect ( result ) . toEqual ( {
233- triggered : true ,
234- toolName : "read" ,
235- repeatedCount : 20 ,
236- } )
249+ expect ( result ) . toEqual ( { triggered : false } )
250+ } )
251+ } )
252+
253+ describe ( "#given tool calls with null input" , ( ) => {
254+ test ( "#when evaluated #then it does not trigger" , ( ) => {
255+ const calls = Array . from ( { length : 20 } , ( ) => ( { tool : "read" , input : null } ) )
256+ const window = buildWindowWithInputs ( calls )
257+ const result = detectRepetitiveToolUse ( window )
258+
259+ expect ( result ) . toEqual ( { triggered : false } )
237260 } )
238261 } )
239262 } )
0 commit comments