2026-01-15 14:23:15 +09:00
|
|
|
import { describe, test, expect, beforeEach, mock } from "bun:test"
|
|
|
|
|
|
|
|
|
|
describe("comment-checker CLI path resolution", () => {
|
|
|
|
|
describe("lazy initialization", () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given module is imported
|
|
|
|
|
// when COMMENT_CHECKER_CLI_PATH is accessed
|
|
|
|
|
// then findCommentCheckerPathSync should NOT have been called during import
|
2026-01-15 14:23:15 +09:00
|
|
|
|
|
|
|
|
test("getCommentCheckerPathSync should be lazy - not called on module import", async () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given a fresh module import
|
2026-01-15 14:23:15 +09:00
|
|
|
// We need to verify that importing the module doesn't immediately call findCommentCheckerPathSync
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when we import the module
|
2026-01-15 14:23:15 +09:00
|
|
|
const cliModule = await import("./cli")
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then getCommentCheckerPathSync should exist and be callable
|
2026-01-15 14:23:15 +09:00
|
|
|
expect(typeof cliModule.getCommentCheckerPathSync).toBe("function")
|
|
|
|
|
|
|
|
|
|
// The key test: calling getCommentCheckerPathSync should work
|
|
|
|
|
// (we can't easily test that it wasn't called on import without mocking,
|
|
|
|
|
// but we can verify the function exists and returns expected types)
|
|
|
|
|
const result = cliModule.getCommentCheckerPathSync()
|
|
|
|
|
expect(result === null || typeof result === "string").toBe(true)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("getCommentCheckerPathSync should cache result after first call", async () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given getCommentCheckerPathSync is called once
|
2026-01-15 14:23:15 +09:00
|
|
|
const cliModule = await import("./cli")
|
|
|
|
|
const firstResult = cliModule.getCommentCheckerPathSync()
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when called again
|
2026-01-15 14:23:15 +09:00
|
|
|
const secondResult = cliModule.getCommentCheckerPathSync()
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then should return same cached result
|
2026-01-15 14:23:15 +09:00
|
|
|
expect(secondResult).toBe(firstResult)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("COMMENT_CHECKER_CLI_PATH export should not exist (removed for lazy loading)", async () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given the cli module
|
2026-01-15 14:23:15 +09:00
|
|
|
const cliModule = await import("./cli")
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when checking for COMMENT_CHECKER_CLI_PATH
|
|
|
|
|
// then it should not exist (replaced with lazy getter)
|
2026-01-15 14:23:15 +09:00
|
|
|
expect("COMMENT_CHECKER_CLI_PATH" in cliModule).toBe(false)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe("runCommentChecker", () => {
|
|
|
|
|
test("should use getCommentCheckerPathSync for fallback path resolution", async () => {
|
2026-02-01 16:47:50 +09:00
|
|
|
// given runCommentChecker is called without explicit path
|
2026-01-15 14:23:15 +09:00
|
|
|
const { runCommentChecker } = await import("./cli")
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// when called with input containing no comments
|
2026-01-15 14:23:15 +09:00
|
|
|
const result = await runCommentChecker({
|
|
|
|
|
session_id: "test",
|
|
|
|
|
tool_name: "Write",
|
|
|
|
|
transcript_path: "",
|
|
|
|
|
cwd: "/tmp",
|
|
|
|
|
hook_event_name: "PostToolUse",
|
|
|
|
|
tool_input: { file_path: "/tmp/test.ts", content: "const x = 1" },
|
|
|
|
|
})
|
|
|
|
|
|
2026-02-01 16:47:50 +09:00
|
|
|
// then should return CheckResult type (binary may or may not exist)
|
2026-01-15 14:23:15 +09:00
|
|
|
expect(typeof result.hasComments).toBe("boolean")
|
|
|
|
|
expect(typeof result.message).toBe("string")
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|