-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdecision_test.go
More file actions
54 lines (50 loc) · 2.02 KB
/
Copy pathdecision_test.go
File metadata and controls
54 lines (50 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package agenthooks
import "testing"
func TestWithBlockReasonFirstNonEmptyWins(t *testing.T) {
tests := []struct {
name string
candidates []string
want string
}{
{"first candidate wins", []string{"custom message", "audit reason"}, "custom message"},
{"empty first falls through", []string{"", "audit reason"}, "audit reason"},
{"single candidate", []string{"only"}, "only"},
{"whitespace counts as present", []string{" ", "audit reason"}, " "},
{"later empties ignored", []string{"", "", "third"}, "third"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Deny("audit").WithBlockReason(tt.candidates...).SystemMessage(); got != tt.want {
t.Errorf("ToolPreDecision.WithBlockReason(%q).SystemMessage() = %q, want %q", tt.candidates, got, tt.want)
}
if got := BlockPrompt("audit").WithBlockReason(tt.candidates...).SystemMessage(); got != tt.want {
t.Errorf("PromptDecision.WithBlockReason(%q).SystemMessage() = %q, want %q", tt.candidates, got, tt.want)
}
})
}
}
func TestWithBlockReasonAllEmptyLeavesDecisionUnchanged(t *testing.T) {
d := Deny("audit").WithSystemMessage("existing")
if got := d.WithBlockReason("", "").SystemMessage(); got != "existing" {
t.Errorf("all-empty candidates: SystemMessage() = %q, want existing message preserved", got)
}
if got := d.WithBlockReason().SystemMessage(); got != "existing" {
t.Errorf("no candidates: SystemMessage() = %q, want existing message preserved", got)
}
p := BlockPrompt("audit").WithBlockReason("", "")
if got := p.SystemMessage(); got != "" {
t.Errorf("all-empty candidates on fresh decision: SystemMessage() = %q, want empty", got)
}
}
func TestWithBlockReasonDoesNotTouchOtherFields(t *testing.T) {
d := Deny("audit").WithBlockReason("user message")
if d.Kind() != DecisionDeny {
t.Errorf("Kind() = %v, want DecisionDeny", d.Kind())
}
if d.Reason() != "audit" {
t.Errorf("Reason() = %q, want audit reason untouched", d.Reason())
}
if !d.Blocks() {
t.Error("Blocks() = false, want true for Deny")
}
}