73 lines
1.7 KiB
Go
73 lines
1.7 KiB
Go
package format
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestRenderBlock_SurfacesToolsAndBypass(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
block Block
|
|
contains []string
|
|
empty bool
|
|
}{
|
|
{
|
|
name: "call shows name and args",
|
|
block: Block{Role: "call", Name: "shell", Content: `{"cmd":"ls"}`},
|
|
contains: []string{"shell", "cmd"},
|
|
},
|
|
{
|
|
name: "call without args shows name",
|
|
block: Block{Role: "call", Name: "memory_wake"},
|
|
contains: []string{"memory_wake"},
|
|
},
|
|
{
|
|
name: "tool output rendered",
|
|
block: Block{Role: "tool", Content: "total 0\nfile.txt"},
|
|
contains: []string{"file.txt"},
|
|
},
|
|
{
|
|
name: "bypass request flagged for approval",
|
|
block: Block{Role: "bypass", Content: "rm -rf /tmp/x"},
|
|
contains: []string{"approval", "rm -rf /tmp/x"},
|
|
},
|
|
{
|
|
name: "bypass resolution rendered",
|
|
block: Block{Role: "bypass-resolved", Content: "approved"},
|
|
contains: []string{"approved"},
|
|
},
|
|
{
|
|
name: "reasoning hidden",
|
|
block: Block{Role: "reasoning", Content: "secret thoughts"},
|
|
empty: true,
|
|
},
|
|
{
|
|
name: "context hidden",
|
|
block: Block{Role: "context", Content: "system context"},
|
|
empty: true,
|
|
},
|
|
{
|
|
name: "partial skipped",
|
|
block: Block{Role: "assistant", Content: "streaming", Partial: true},
|
|
empty: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := RenderBlock(tt.block)
|
|
if tt.empty {
|
|
if got != "" {
|
|
t.Errorf("expected empty, got %q", got)
|
|
}
|
|
return
|
|
}
|
|
for _, want := range tt.contains {
|
|
if !strings.Contains(got, want) {
|
|
t.Errorf("RenderBlock = %q, want substring %q", got, want)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|