MCPcopy Create free account
hub / github.com/cli/cli / TestRenderEscapesToolCallArguments

Function TestRenderEscapesToolCallArguments

pkg/cmd/agent-task/shared/log_test.go:99–151  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

97}
98
99func TestRenderEscapesToolCallArguments(t *testing.T) {
100 const seq = "\x1b]0;x\a"
101
102 tests := []struct {
103 name string
104 tool string
105 args map[string]string
106 }{
107 {name: "setup step name", tool: "run_setup", args: map[string]string{"name": seq}},
108 {name: "bash description and command", tool: "bash", args: map[string]string{"description": seq, "command": seq}},
109 {name: "view path", tool: "view", args: map[string]string{"path": "/home/runner/work/o/r/" + seq}},
110 {name: "thought", tool: "think", args: map[string]string{"thought": seq}},
111 {name: "progress commit message and description", tool: "report_progress", args: map[string]string{"commitMessage": seq, "prDescription": seq}},
112 {name: "created file path and text", tool: "create", args: map[string]string{"path": "/home/runner/work/o/r/" + seq, "file_text": seq}},
113 {name: "edited file path", tool: "str_replace", args: map[string]string{"path": "/home/runner/work/o/r/" + seq}},
114 {name: "unknown tool name", tool: "tool" + seq, args: map[string]string{}},
115 }
116
117 for _, tt := range tests {
118 for _, tty := range []bool{false, true} {
119 t.Run(fmt.Sprintf("%s tty=%t", tt.name, tty), func(t *testing.T) {
120 args, err := json.Marshal(tt.args)
121 require.NoError(t, err)
122
123 entry := map[string]any{
124 "object": "chat.completion.chunk",
125 "choices": []any{map[string]any{
126 "delta": map[string]any{
127 "role": "assistant",
128 "content": "done",
129 "tool_calls": []any{map[string]any{
130 "function": map[string]any{"name": tt.tool, "arguments": string(args)},
131 }},
132 },
133 }},
134 }
135 line, err := json.Marshal(entry)
136 require.NoError(t, err)
137
138 ios, _, stdout, stderr := iostreams.Test()
139 ios.SetStdoutTTY(tty)
140
141 _, err = NewLogRenderer().Render([]byte("data: "+string(line)), stdout, ios)
142 require.NoError(t, err)
143
144 assert.Contains(t, stdout.String(), "^[]0;x^G")
145 assert.NotContains(t, stdout.String(), "\a")
146 assert.NotContains(t, stdout.String(), "\x1b]")
147 assert.NotContains(t, stderr.String(), "\x1b")
148 })
149 }
150 }
151}

Callers

nothing calls this directly

Calls 7

TestFunction · 0.92
NewLogRendererFunction · 0.85
SetStdoutTTYMethod · 0.80
ContainsMethod · 0.80
RunMethod · 0.65
RenderMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected