ec9433d783
Brings the project to a clean `make lint` baseline (0 issues). Mechanical: - Wrap deferred resp.Body.Close() in closures (router/discovery.go, router/probe.go) so the unchecked return surfaces as `_ = ...`. - Apply `_ = ...` (single or multi-return blank) to test-file calls that intentionally ignore errors: os.MkdirAll / os.WriteFile / os.Chdir in setup paths, Close / Shutdown in teardown, Submit / Spawn / Send / LoadDir in tests that assert on side effects. Structural: - engine.handleRequestTooLarge drops the unused req parameter and rebuilds the request from compacted history (SA4009 — argument was overwritten before first use). - provider.ClassifyHTTPStatus and google.applyCapabilityOverrides switch to tagged switches over the discriminator (QF1002). - tui.app.go MouseWheel + inputMode and cmd/gnoma main slm-status use tagged switches in place of equality chains (QF1003). - cmd/gnoma main.go merges a var decl with its immediate assignment (S1021). - Three empty-branch sites (dispatcher_test, loader_test, coordinator_test) become real assertions or get the dead `if` removed (SA9003).
104 lines
3.0 KiB
Go
104 lines
3.0 KiB
Go
package agent_test
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"somegit.dev/Owlibou/gnoma/internal/tool/agent"
|
|
"somegit.dev/Owlibou/gnoma/internal/tool/persist"
|
|
)
|
|
|
|
func makeTestStore(t *testing.T) *persist.Store {
|
|
t.Helper()
|
|
s := persist.New("test-coord-" + t.Name())
|
|
t.Cleanup(func() { _ = os.RemoveAll(s.Dir()) })
|
|
return s
|
|
}
|
|
|
|
func TestListResultsTool_EmptyStore(t *testing.T) {
|
|
s := makeTestStore(t)
|
|
tool := agent.NewListResultsTool(s)
|
|
args, _ := json.Marshal(map[string]string{})
|
|
result, err := tool.Execute(context.Background(), args)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// Empty store: either a "no results" message or empty output is acceptable;
|
|
// verify only that we don't surface a hard error.
|
|
if strings.Contains(result.Output, "error") {
|
|
t.Errorf("unexpected error output for empty store: %s", result.Output)
|
|
}
|
|
}
|
|
|
|
func TestListResultsTool_ListsFiles(t *testing.T) {
|
|
s := makeTestStore(t)
|
|
big := strings.Repeat("x", 1024)
|
|
s.Save("bash", "toolu_aaa", big)
|
|
s.Save("fs.grep", "toolu_bbb", big)
|
|
|
|
tool := agent.NewListResultsTool(s)
|
|
args, _ := json.Marshal(map[string]string{})
|
|
result, err := tool.Execute(context.Background(), args)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(result.Output, "bash") {
|
|
t.Errorf("expected bash in output, got: %s", result.Output)
|
|
}
|
|
if !strings.Contains(result.Output, "fs") {
|
|
t.Errorf("expected fs in output, got: %s", result.Output)
|
|
}
|
|
}
|
|
|
|
func TestListResultsTool_FilterByToolName(t *testing.T) {
|
|
s := makeTestStore(t)
|
|
big := strings.Repeat("x", 1024)
|
|
s.Save("bash", "toolu_c1", big)
|
|
s.Save("fs.read", "toolu_c2", big)
|
|
|
|
tool := agent.NewListResultsTool(s)
|
|
args, _ := json.Marshal(map[string]string{"filter": "bash"})
|
|
result, err := tool.Execute(context.Background(), args)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(result.Output, "bash") {
|
|
t.Errorf("filter should include bash, got: %s", result.Output)
|
|
}
|
|
if strings.Contains(result.Output, "fs") {
|
|
t.Errorf("filter should exclude fs.read, got: %s", result.Output)
|
|
}
|
|
}
|
|
|
|
func TestReadResultTool_ReadsFile(t *testing.T) {
|
|
s := makeTestStore(t)
|
|
big := strings.Repeat("hello\n", 200)
|
|
path, _ := s.Save("bash", "toolu_read1", big)
|
|
|
|
tool := agent.NewReadResultTool(s)
|
|
args, _ := json.Marshal(map[string]string{"path": path})
|
|
result, err := tool.Execute(context.Background(), args)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(result.Output, "hello") {
|
|
t.Errorf("expected file content in output, got: %s", result.Output)
|
|
}
|
|
}
|
|
|
|
func TestReadResultTool_RejectsPathTraversal(t *testing.T) {
|
|
s := makeTestStore(t)
|
|
tool := agent.NewReadResultTool(s)
|
|
args, _ := json.Marshal(map[string]string{"path": "/etc/passwd"})
|
|
result, err := tool.Execute(context.Background(), args)
|
|
if err != nil {
|
|
t.Fatalf("Execute must not return a hard error; soft rejection in Output expected, got: %v", err)
|
|
}
|
|
if !strings.Contains(result.Output, "outside") {
|
|
t.Errorf("expected 'outside session directory' rejection, got: %s", result.Output)
|
|
}
|
|
}
|