package hooks import "testing" func TestDenyBeatsAllow(t *testing.T) { b := New() b.On(func(Call) Outcome { return Outcome{Decision: Allow} }) b.On(func(c Call) Outcome { if c.Event == PreToolUse { return Outcome{Decision: Deny, Reason: "no"} } return Outcome{} }) out := b.Emit(Call{Event: PreToolUse, Tool: "write_file"}) if out.Decision != Deny || out.Reason != "no" { t.Fatalf("%+v", out) } } func TestAdaptBefore(t *testing.T) { h := AdaptBefore(func(name, args string) error { if name == "write_file" { return errString("blocked") } return nil }) if h(Call{Event: PreToolUse, Tool: "read_file"}).Decision != Allow { t.Fatal("read") } if h(Call{Event: PreToolUse, Tool: "write_file"}).Decision != Deny { t.Fatal("write") } if h(Call{Event: Stop}).Decision != "" { t.Fatal("stop should be ignored") } } type errString string func (e errString) Error() string { return string(e) }