|
| 1 | +import { describe, it, expect, mock } from "bun:test" |
| 2 | + |
| 3 | +mock.module("./cli-runner", () => ({ |
| 4 | + initializeCommentCheckerCli: () => {}, |
| 5 | + getCommentCheckerCliPathPromise: () => Promise.resolve("/tmp/fake-comment-checker"), |
| 6 | + isCliPathUsable: () => true, |
| 7 | + processWithCli: async () => {}, |
| 8 | + processApplyPatchEditsWithCli: async () => {}, |
| 9 | +})) |
| 10 | + |
| 11 | +const { createCommentCheckerHooks } = await import("./hook") |
| 12 | + |
| 13 | +describe("comment-checker null output guard", () => { |
| 14 | + it("does not throw when output.output is undefined", async () => { |
| 15 | + const hooks = createCommentCheckerHooks() |
| 16 | + const input = { tool: "Edit", sessionID: "ses_test", callID: "call_test" } |
| 17 | + const output = { title: "Edit", output: undefined as unknown as string, metadata: {} } |
| 18 | + |
| 19 | + await hooks["tool.execute.after"](input, output) |
| 20 | + |
| 21 | + expect(output.output).toBeUndefined() |
| 22 | + }) |
| 23 | + |
| 24 | + it("does not throw when output.output is null", async () => { |
| 25 | + const hooks = createCommentCheckerHooks() |
| 26 | + const input = { tool: "Edit", sessionID: "ses_test", callID: "call_test" } |
| 27 | + const output = { title: "Edit", output: null as unknown as string, metadata: {} } |
| 28 | + |
| 29 | + await hooks["tool.execute.after"](input, output) |
| 30 | + |
| 31 | + expect(output.output).toBeNull() |
| 32 | + }) |
| 33 | + |
| 34 | + it("still processes valid string output", async () => { |
| 35 | + const hooks = createCommentCheckerHooks() |
| 36 | + const input = { tool: "Edit", sessionID: "ses_test", callID: "call_test" } |
| 37 | + const output = { title: "Edit", output: "File edited successfully", metadata: {} } |
| 38 | + |
| 39 | + await hooks["tool.execute.after"](input, output) |
| 40 | + |
| 41 | + expect(typeof output.output).toBe("string") |
| 42 | + }) |
| 43 | + |
| 44 | + it("skips tool failure output without crashing", async () => { |
| 45 | + const hooks = createCommentCheckerHooks() |
| 46 | + const input = { tool: "Edit", sessionID: "ses_test", callID: "call_test" } |
| 47 | + const output = { title: "Edit", output: "Error: something went wrong", metadata: {} } |
| 48 | + |
| 49 | + await hooks["tool.execute.after"](input, output) |
| 50 | + |
| 51 | + expect(output.output).toBe("Error: something went wrong") |
| 52 | + }) |
| 53 | +}) |
0 commit comments