1package agent
2
3import (
4 "encoding/json"
5 "testing"
6
7 "github.com/bnema/zut/packages/agent/tools"
8 "github.com/bnema/zut/packages/core"
9)
10
11// TestConfirmationKeyFor pins the confirmation grant key resolved at the tool
12// call site: a multiplexed tool keys per action, a plain built-in keeps its
13// name, and an unknown tool falls back to its raw name.
14func TestConfirmationKeyFor(t *testing.T) {
15 reg := core.Registry{
16 tools.SubagentToolName: &tools.SubagentTool{},
17 "read": &tools.GrepTool{},
18 }
19 cases := []struct {
20 name string
21 tool string
22 args string
23 want string
24 }{
25 {name: "facade action", tool: tools.SubagentToolName, args: `{"action":"spawn","task":"t"}`, want: "subagent:spawn"},
26 {name: "facade plain action", tool: tools.SubagentToolName, args: `{"action":"resume","agent_id":"x","prompt":"p"}`, want: "subagent:resume"},
27 {name: "built-in tool", tool: "read", args: `{"pattern":"x"}`, want: "read"},
28 {name: "unknown tool", tool: "missing", args: `{}`, want: "missing"},
29 }
30 for _, tc := range cases {
31 t.Run(tc.name, func(t *testing.T) {
32 if got := confirmationKeyFor(reg, tc.tool, json.RawMessage(tc.args)); got != tc.want {
33 t.Fatalf("confirmationKeyFor(%q, %s) = %q, want %q", tc.tool, tc.args, got, tc.want)
34 }
35 })
36 }
37}