fix(comment-checker): improve pending calls handling and add tests
🤖 Generated with assistance of OhMyOpenCode
This commit is contained in:
@@ -22,7 +22,12 @@ import {
|
|||||||
processWithCli,
|
processWithCli,
|
||||||
processApplyPatchEditsWithCli,
|
processApplyPatchEditsWithCli,
|
||||||
} from "./cli-runner"
|
} from "./cli-runner"
|
||||||
import { registerPendingCall, startPendingCallCleanup, takePendingCall } from "./pending-calls"
|
import {
|
||||||
|
registerPendingCall,
|
||||||
|
startPendingCallCleanup,
|
||||||
|
stopPendingCallCleanup,
|
||||||
|
takePendingCall,
|
||||||
|
} from "./pending-calls"
|
||||||
|
|
||||||
import * as fs from "fs"
|
import * as fs from "fs"
|
||||||
import { tmpdir } from "os"
|
import { tmpdir } from "os"
|
||||||
@@ -180,5 +185,8 @@ export function createCommentCheckerHooks(config?: CommentCheckerConfig) {
|
|||||||
debugLog("tool.execute.after failed:", err)
|
debugLog("tool.execute.after failed:", err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
dispose: (): void => {
|
||||||
|
stopPendingCallCleanup()
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,4 +35,43 @@ describe("pending-calls cleanup interval", () => {
|
|||||||
globalThis.setInterval = originalSetInterval
|
globalThis.setInterval = originalSetInterval
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("#given cleanup timer already started #when stop cleanup runs #then interval state resets for future reuse", async () => {
|
||||||
|
//#given
|
||||||
|
const originalSetInterval = globalThis.setInterval
|
||||||
|
const originalClearInterval = globalThis.clearInterval
|
||||||
|
let intervalHandle: ReturnType<typeof setInterval> | undefined
|
||||||
|
let clearCalls = 0
|
||||||
|
|
||||||
|
globalThis.setInterval = ((
|
||||||
|
_handler: TimerHandler,
|
||||||
|
_timeout?: number,
|
||||||
|
..._args: any[]
|
||||||
|
) => {
|
||||||
|
intervalHandle = { unref: () => {} } as unknown as ReturnType<typeof setInterval>
|
||||||
|
return intervalHandle
|
||||||
|
}) as unknown as typeof setInterval
|
||||||
|
|
||||||
|
globalThis.clearInterval = ((handle?: ReturnType<typeof setInterval>) => {
|
||||||
|
if (handle === intervalHandle) {
|
||||||
|
clearCalls += 1
|
||||||
|
}
|
||||||
|
}) as unknown as typeof clearInterval
|
||||||
|
|
||||||
|
try {
|
||||||
|
const modulePath = new URL("./pending-calls.ts", import.meta.url).pathname
|
||||||
|
const pendingCallsModule = await import(`${modulePath}?pending-calls-test-stop`)
|
||||||
|
pendingCallsModule.startPendingCallCleanup()
|
||||||
|
|
||||||
|
//#when
|
||||||
|
pendingCallsModule.stopPendingCallCleanup()
|
||||||
|
pendingCallsModule.startPendingCallCleanup()
|
||||||
|
|
||||||
|
//#then
|
||||||
|
expect(clearCalls).toBe(1)
|
||||||
|
} finally {
|
||||||
|
globalThis.setInterval = originalSetInterval
|
||||||
|
globalThis.clearInterval = originalClearInterval
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -24,6 +24,15 @@ export function startPendingCallCleanup(): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function stopPendingCallCleanup(): void {
|
||||||
|
pendingCalls.clear()
|
||||||
|
if (cleanupInterval) {
|
||||||
|
clearInterval(cleanupInterval)
|
||||||
|
cleanupInterval = undefined
|
||||||
|
}
|
||||||
|
cleanupIntervalStarted = false
|
||||||
|
}
|
||||||
|
|
||||||
export function registerPendingCall(callID: string, pendingCall: PendingCall): void {
|
export function registerPendingCall(callID: string, pendingCall: PendingCall): void {
|
||||||
pendingCalls.set(callID, pendingCall)
|
pendingCalls.set(callID, pendingCall)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user