test(agent): keep image_model regression compatible
This commit is contained in:
parent
d8b4f088cb
commit
c686aac187
1 changed files with 0 additions and 86 deletions
|
|
@ -1,14 +1,10 @@
|
||||||
package agent
|
package agent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/sipeed/picoclaw/pkg/config"
|
"github.com/sipeed/picoclaw/pkg/config"
|
||||||
"github.com/sipeed/picoclaw/pkg/media"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewAgentInstance_UsesDefaultsTemperatureAndMaxTokens(t *testing.T) {
|
func TestNewAgentInstance_UsesDefaultsTemperatureAndMaxTokens(t *testing.T) {
|
||||||
|
|
@ -207,85 +203,3 @@ func TestNewAgentInstance_ResolveImageCandidatesFromModelListAlias(t *testing.T)
|
||||||
t.Fatalf("second image candidate = %+v, want anthropic/claude-3-7-sonnet", agent.ImageCandidates[1])
|
t.Fatalf("second image candidate = %+v, want anthropic/claude-3-7-sonnet", agent.ImageCandidates[1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewAgentInstance_AllowsMediaTempDirForReadListAndExec(t *testing.T) {
|
|
||||||
workspace := t.TempDir()
|
|
||||||
mediaDir := media.TempDir()
|
|
||||||
if err := os.MkdirAll(mediaDir, 0o700); err != nil {
|
|
||||||
t.Fatalf("MkdirAll(mediaDir) error = %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
mediaFile, err := os.CreateTemp(mediaDir, "instance-tool-*.txt")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("CreateTemp(mediaDir) error = %v", err)
|
|
||||||
}
|
|
||||||
mediaPath := mediaFile.Name()
|
|
||||||
if _, err := mediaFile.WriteString("attachment content"); err != nil {
|
|
||||||
mediaFile.Close()
|
|
||||||
t.Fatalf("WriteString(mediaFile) error = %v", err)
|
|
||||||
}
|
|
||||||
if err := mediaFile.Close(); err != nil {
|
|
||||||
t.Fatalf("Close(mediaFile) error = %v", err)
|
|
||||||
}
|
|
||||||
t.Cleanup(func() { _ = os.Remove(mediaPath) })
|
|
||||||
|
|
||||||
cfg := &config.Config{
|
|
||||||
Agents: config.AgentsConfig{
|
|
||||||
Defaults: config.AgentDefaults{
|
|
||||||
Workspace: workspace,
|
|
||||||
Model: "test-model",
|
|
||||||
RestrictToWorkspace: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Tools: config.ToolsConfig{
|
|
||||||
ReadFile: config.ReadFileToolConfig{Enabled: true},
|
|
||||||
ListDir: config.ToolConfig{Enabled: true},
|
|
||||||
Exec: config.ExecConfig{
|
|
||||||
ToolConfig: config.ToolConfig{Enabled: true},
|
|
||||||
EnableDenyPatterns: true,
|
|
||||||
AllowRemote: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
agent := NewAgentInstance(nil, &cfg.Agents.Defaults, cfg, &mockProvider{})
|
|
||||||
|
|
||||||
readTool, ok := agent.Tools.Get("read_file")
|
|
||||||
if !ok {
|
|
||||||
t.Fatal("read_file tool not registered")
|
|
||||||
}
|
|
||||||
readResult := readTool.Execute(context.Background(), map[string]any{"path": mediaPath})
|
|
||||||
if readResult.IsError {
|
|
||||||
t.Fatalf("read_file should allow media temp dir, got: %s", readResult.ForLLM)
|
|
||||||
}
|
|
||||||
if !strings.Contains(readResult.ForLLM, "attachment content") {
|
|
||||||
t.Fatalf("read_file output missing media content: %s", readResult.ForLLM)
|
|
||||||
}
|
|
||||||
|
|
||||||
listTool, ok := agent.Tools.Get("list_dir")
|
|
||||||
if !ok {
|
|
||||||
t.Fatal("list_dir tool not registered")
|
|
||||||
}
|
|
||||||
listResult := listTool.Execute(context.Background(), map[string]any{"path": mediaDir})
|
|
||||||
if listResult.IsError {
|
|
||||||
t.Fatalf("list_dir should allow media temp dir, got: %s", listResult.ForLLM)
|
|
||||||
}
|
|
||||||
if !strings.Contains(listResult.ForLLM, filepath.Base(mediaPath)) {
|
|
||||||
t.Fatalf("list_dir output missing media file: %s", listResult.ForLLM)
|
|
||||||
}
|
|
||||||
|
|
||||||
execTool, ok := agent.Tools.Get("exec")
|
|
||||||
if !ok {
|
|
||||||
t.Fatal("exec tool not registered")
|
|
||||||
}
|
|
||||||
execResult := execTool.Execute(context.Background(), map[string]any{
|
|
||||||
"command": "cat " + filepath.Base(mediaPath),
|
|
||||||
"working_dir": mediaDir,
|
|
||||||
})
|
|
||||||
if execResult.IsError {
|
|
||||||
t.Fatalf("exec should allow media temp dir, got: %s", execResult.ForLLM)
|
|
||||||
}
|
|
||||||
if !strings.Contains(execResult.ForLLM, "attachment content") {
|
|
||||||
t.Fatalf("exec output missing media content: %s", execResult.ForLLM)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue