oh-my-opencode/src/hooks/comment-checker/hook.output-guard.test.ts
YeonGyu-Kim 8b44d3b7b5 fix: add null guards for output.output in tool.execute.after hooks
Three hooks crashed with TypeError when MCP tools returned results where
output.output is undefined. Added type guards to all affected hooks:

- comment-checker/hook.ts: guard before toLowerCase()
- edit-error-recovery/hook.ts: guard before toLowerCase()
- task-resume-info/hook.ts: guard before startsWith()/includes()/trimEnd()
- Added test for undefined output.output in edit-error-recovery

Fixes #1746
2026-02-11 15:39:15 +09:00

25 lines
949 B
TypeScript

import { describe, it, expect, mock } from "bun:test"
mock.module("./cli-runner", () => ({
initializeCommentCheckerCli: () => {},
getCommentCheckerCliPathPromise: () => Promise.resolve("/tmp/fake-comment-checker"),
isCliPathUsable: () => true,
processWithCli: async () => {},
processApplyPatchEditsWithCli: async () => {},
}))
const { createCommentCheckerHooks } = await import("./hook")
describe("comment-checker output guard", () => {
//#given output.output is undefined
//#when tool.execute.after is called
//#then should return without throwing
it("should not throw when output.output is undefined", async () => {
const hooks = createCommentCheckerHooks()
const input = { tool: "Write", sessionID: "ses_test", callID: "call_test" }
const output = { title: "ok", output: undefined as unknown as string, metadata: {} }
await expect(hooks["tool.execute.after"](input, output)).resolves.toBeUndefined()
})
})