55ac653eaa
Override TodoWrite description via tool.definition hook to require WHERE/WHY/HOW/RESULT in each todo title and enforce 1-3 tool call granularity.
41 lines
1.6 KiB
TypeScript
41 lines
1.6 KiB
TypeScript
import { describe, it, expect } from "bun:test"
|
|
import { createTodoDescriptionOverrideHook } from "./hook"
|
|
import { TODOWRITE_DESCRIPTION } from "./description"
|
|
|
|
describe("createTodoDescriptionOverrideHook", () => {
|
|
describe("#given hook is created", () => {
|
|
describe("#when tool.definition is called with todowrite", () => {
|
|
it("#then should override the description", async () => {
|
|
const hook = createTodoDescriptionOverrideHook()
|
|
const output = { description: "original description", parameters: {} }
|
|
|
|
await hook["tool.definition"]({ toolID: "todowrite" }, output)
|
|
|
|
expect(output.description).toBe(TODOWRITE_DESCRIPTION)
|
|
})
|
|
})
|
|
|
|
describe("#when tool.definition is called with non-todowrite tool", () => {
|
|
it("#then should not modify the description", async () => {
|
|
const hook = createTodoDescriptionOverrideHook()
|
|
const output = { description: "original description", parameters: {} }
|
|
|
|
await hook["tool.definition"]({ toolID: "bash" }, output)
|
|
|
|
expect(output.description).toBe("original description")
|
|
})
|
|
})
|
|
|
|
describe("#when tool.definition is called with TodoWrite (case-insensitive)", () => {
|
|
it("#then should not override for different casing since OpenCode sends lowercase", async () => {
|
|
const hook = createTodoDescriptionOverrideHook()
|
|
const output = { description: "original description", parameters: {} }
|
|
|
|
await hook["tool.definition"]({ toolID: "TodoWrite" }, output)
|
|
|
|
expect(output.description).toBe("original description")
|
|
})
|
|
})
|
|
})
|
|
})
|