Merge branch 'fix/perf-q03' into fix/perf-omo-in-tree
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { describe, expect, it, mock, afterAll } from "bun:test"
|
||||
|
||||
const startPendingCallCleanup = mock(() => {})
|
||||
const initializeCommentCheckerCli = mock(() => {})
|
||||
|
||||
mock.module("./cli-runner", () => ({
|
||||
initializeCommentCheckerCli,
|
||||
getCommentCheckerCliPathPromise: () => Promise.resolve("/tmp/fake-comment-checker"),
|
||||
isCliPathUsable: () => true,
|
||||
processWithCli: async () => {},
|
||||
processApplyPatchEditsWithCli: async () => {},
|
||||
}))
|
||||
|
||||
mock.module("./pending-calls", () => ({
|
||||
registerPendingCall: () => {},
|
||||
startPendingCallCleanup,
|
||||
stopPendingCallCleanup: () => {},
|
||||
takePendingCall: () => undefined,
|
||||
}))
|
||||
|
||||
afterAll(() => {
|
||||
mock.restore()
|
||||
})
|
||||
|
||||
const { createCommentCheckerHooks } = await import("./hook")
|
||||
|
||||
describe("comment-checker lazy initialization", () => {
|
||||
it("initializes CLI and cleanup on first tool hook call only", async () => {
|
||||
// given
|
||||
const hooks = createCommentCheckerHooks()
|
||||
const beforeHook = hooks["tool.execute.before"]
|
||||
const input = { tool: "write", sessionID: "ses_test", callID: "call_test" }
|
||||
const output = { args: { filePath: "src/a.ts" } }
|
||||
|
||||
// when
|
||||
expect(startPendingCallCleanup).toHaveBeenCalledTimes(0)
|
||||
expect(initializeCommentCheckerCli).toHaveBeenCalledTimes(0)
|
||||
|
||||
// then
|
||||
await beforeHook(input, output)
|
||||
expect(startPendingCallCleanup).toHaveBeenCalledTimes(1)
|
||||
expect(initializeCommentCheckerCli).toHaveBeenCalledTimes(1)
|
||||
|
||||
// when
|
||||
await beforeHook(input, output)
|
||||
|
||||
// then
|
||||
expect(startPendingCallCleanup).toHaveBeenCalledTimes(1)
|
||||
expect(initializeCommentCheckerCli).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
stopPendingCallCleanup,
|
||||
takePendingCall,
|
||||
} from "./pending-calls"
|
||||
import { ensureCommentCheckerInitialization } from "./initialization-gate"
|
||||
|
||||
import * as fs from "fs"
|
||||
import { tmpdir } from "os"
|
||||
@@ -48,14 +49,16 @@ function debugLog(...args: unknown[]) {
|
||||
export function createCommentCheckerHooks(config?: CommentCheckerConfig) {
|
||||
debugLog("createCommentCheckerHooks called", { config })
|
||||
|
||||
startPendingCallCleanup()
|
||||
initializeCommentCheckerCli(debugLog)
|
||||
|
||||
return {
|
||||
"tool.execute.before": async (
|
||||
input: { tool: string; sessionID: string; callID: string },
|
||||
output: { args: Record<string, unknown> },
|
||||
): Promise<void> => {
|
||||
ensureCommentCheckerInitialization(() => {
|
||||
startPendingCallCleanup()
|
||||
initializeCommentCheckerCli(debugLog)
|
||||
})
|
||||
|
||||
debugLog("tool.execute.before:", {
|
||||
tool: input.tool,
|
||||
callID: input.callID,
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
let initialized = false
|
||||
|
||||
export function ensureCommentCheckerInitialization(initializer: () => void): void {
|
||||
if (initialized) return
|
||||
initialized = true
|
||||
initializer()
|
||||
}
|
||||
Reference in New Issue
Block a user