Merge pull request #3348 from code-yeongyu/refactor/ulw-repo-cleanup-20260411
refactor: simplify nullish guards and remove dead no-op paths
This commit is contained in:
@@ -112,6 +112,20 @@ describe("loop-detector", () => {
|
||||
expect(result).toBe("read")
|
||||
})
|
||||
|
||||
test("#given nullish inputs #when signatures are created #then null and undefined behave the same", () => {
|
||||
// given
|
||||
const undefinedInput = undefined
|
||||
const nullInput = null
|
||||
|
||||
// when
|
||||
const undefinedResult = createToolCallSignature("read", undefinedInput)
|
||||
const nullResult = createToolCallSignature("read", nullInput)
|
||||
|
||||
// then
|
||||
expect(undefinedResult).toBe("read")
|
||||
expect(nullResult).toBe(undefinedResult)
|
||||
})
|
||||
|
||||
test("#given tool with empty object input #when signature created #then returns bare tool name", () => {
|
||||
const result = createToolCallSignature("read", {})
|
||||
|
||||
@@ -259,5 +273,24 @@ describe("loop-detector", () => {
|
||||
expect(result).toEqual({ triggered: false })
|
||||
})
|
||||
})
|
||||
|
||||
describe("#given nullish tool inputs", () => {
|
||||
test("#when recorded #then null and undefined produce the same unknown-input window", () => {
|
||||
// given
|
||||
const settings = resolveCircuitBreakerSettings()
|
||||
|
||||
// when
|
||||
const undefinedWindow = recordToolCall(undefined, "read", settings, undefined)
|
||||
const nullWindow = recordToolCall(undefined, "read", settings, null)
|
||||
|
||||
// then
|
||||
expect(undefinedWindow).toEqual(nullWindow)
|
||||
expect(undefinedWindow).toEqual({
|
||||
lastSignature: "read::__unknown-input__",
|
||||
consecutiveCount: 1,
|
||||
threshold: settings.consecutiveThreshold,
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -36,7 +36,7 @@ export function recordToolCall(
|
||||
settings: CircuitBreakerSettings,
|
||||
toolInput?: Record<string, unknown> | null
|
||||
): ToolCallWindow {
|
||||
if (toolInput === undefined || toolInput === null) {
|
||||
if (toolInput == null) {
|
||||
return {
|
||||
lastSignature: `${toolName}::__unknown-input__`,
|
||||
consecutiveCount: 1,
|
||||
@@ -62,7 +62,7 @@ export function recordToolCall(
|
||||
}
|
||||
|
||||
function sortObject(obj: unknown): unknown {
|
||||
if (obj === null || obj === undefined) return obj
|
||||
if (obj == null) return obj
|
||||
if (typeof obj !== "object") return obj
|
||||
if (Array.isArray(obj)) return obj.map(sortObject)
|
||||
|
||||
@@ -78,7 +78,7 @@ export function createToolCallSignature(
|
||||
toolName: string,
|
||||
toolInput?: Record<string, unknown> | null
|
||||
): string {
|
||||
if (toolInput === undefined || toolInput === null) {
|
||||
if (toolInput == null) {
|
||||
return toolName
|
||||
}
|
||||
if (Object.keys(toolInput).length === 0) {
|
||||
|
||||
Reference in New Issue
Block a user