Add tool binary file detection
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package llm
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"os/exec"
|
||||
"strings"
|
||||
@@ -221,24 +222,54 @@ func TestToolResult_FormatResult(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "success with stdout",
|
||||
result: ToolResult{Stdout: "hello\n", Stderr: "", ProcessState: cmdOK.ProcessState},
|
||||
result: ToolResult{Stdout: []byte("hello\n"), Stderr: nil, ProcessState: cmdOK.ProcessState},
|
||||
wantContains: []string{"▸ stdout:", "hello", "▸ stderr:", "┗ exit: 0"},
|
||||
},
|
||||
{
|
||||
name: "failure with stderr",
|
||||
result: ToolResult{Stdout: "", Stderr: "error occurred\n", ProcessState: cmdFail.ProcessState},
|
||||
result: ToolResult{Stdout: nil, Stderr: []byte("error occurred\n"), ProcessState: cmdFail.ProcessState},
|
||||
wantContains: []string{"▸ stdout:", "▸ stderr:", "error occurred", "┗ exit: 3"},
|
||||
},
|
||||
{
|
||||
name: "both stdout and stderr",
|
||||
result: ToolResult{Stdout: "output", Stderr: "warning", ProcessState: cmdOK.ProcessState},
|
||||
result: ToolResult{Stdout: []byte("output"), Stderr: []byte("warning"), ProcessState: cmdOK.ProcessState},
|
||||
wantContains: []string{"▸ stdout:", "output", "▸ stderr:", "warning", "┗ exit: 0"},
|
||||
},
|
||||
{
|
||||
name: "empty output",
|
||||
result: ToolResult{Stdout: "", Stderr: "", ProcessState: cmdOK.ProcessState},
|
||||
result: ToolResult{Stdout: nil, Stderr: nil, ProcessState: cmdOK.ProcessState},
|
||||
wantContains: []string{"▸ stdout:", "▸ stderr:", "┗ exit: 0"},
|
||||
},
|
||||
{
|
||||
name: "binary stdout (PNG)",
|
||||
result: ToolResult{Stdout: []byte("\x89PNG\r\n\x1a\n"), Stderr: nil, ProcessState: cmdOK.ProcessState},
|
||||
wantContains: []string{"▸ stdout:", binaryOutputPrefix, "image/png", "▸ stderr:", "┗ exit: 0"},
|
||||
},
|
||||
{
|
||||
name: "binary stderr",
|
||||
result: ToolResult{Stdout: nil, Stderr: []byte("\x89PNG\r\n\x1a\n"), ProcessState: cmdOK.ProcessState},
|
||||
wantContains: []string{"▸ stdout:", "▸ stderr:", binaryOutputPrefix, "image/png", "┗ exit: 0"},
|
||||
},
|
||||
{
|
||||
name: "HTML",
|
||||
result: ToolResult{Stdout: []byte("<HTML><BODY>Hello</BODY></HTML>\n"), Stderr: nil, ProcessState: cmdOK.ProcessState},
|
||||
wantContains: []string{"▸ stdout:", "<HTML>", "▸ stderr:", "┗ exit: 0"},
|
||||
},
|
||||
{
|
||||
name: "XML",
|
||||
result: ToolResult{Stdout: []byte("<?xml version=\"1.0\"?><root/>\n"), Stderr: nil, ProcessState: cmdOK.ProcessState},
|
||||
wantContains: []string{"▸ stdout:", "<?xml", "▸ stderr:", "┗ exit: 0"},
|
||||
},
|
||||
{
|
||||
name: "Go source",
|
||||
result: ToolResult{Stdout: []byte("package main\n\nfunc main() {}\n"), Stderr: nil, ProcessState: cmdOK.ProcessState},
|
||||
wantContains: []string{"▸ stdout:", "package main", "▸ stderr:", "┗ exit: 0"},
|
||||
},
|
||||
{
|
||||
name: "JSON",
|
||||
result: ToolResult{Stdout: []byte(`{"key":"value"}`), Stderr: nil, ProcessState: cmdOK.ProcessState},
|
||||
wantContains: []string{"▸ stdout:", `{"key":"value"}`, "▸ stderr:", "┗ exit: 0"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -268,7 +299,7 @@ func TestRegistry_Execute_Success(t *testing.T) {
|
||||
if result.ProcessState.ExitCode() != 0 {
|
||||
t.Errorf("ExitCode = %d, want 0", result.ProcessState.ExitCode())
|
||||
}
|
||||
if !strings.Contains(result.Stdout, "hello") {
|
||||
if !bytes.Contains(result.Stdout, []byte("hello")) {
|
||||
t.Errorf("Stdout = %q, want to contain hello", result.Stdout)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user