improved tool debugging

This commit is contained in:
Luxferre
2026-03-22 12:01:29 +02:00
parent 77d0d17c89
commit cd2de78c2c
16 changed files with 986 additions and 592 deletions
+26 -11
View File
@@ -9,18 +9,32 @@ import (
func TestShellExecHandler(t *testing.T) {
// Success
got, err := shellExecHandler(map[string]interface{}{"command": "echo hello"})
if err != nil { t.Fatal(err) }
if strings.TrimSpace(got) != "hello" { t.Errorf("expected hello, got %s", got) }
if err != nil {
t.Fatal(err)
}
if strings.TrimSpace(got) != "hello" {
t.Errorf("expected hello, got %s", got)
}
// Failure
got, err = shellExecHandler(map[string]interface{}{"command": "ls /nonexistent-file-path-that-should-not-exist"})
if err != nil { t.Fatal(err) }
if !strings.Contains(got, "Error:") { t.Errorf("expected error in output, got %s", got) }
got, err = shellExecHandler(map[string]interface{}{
"command": "ls /nonexistent-file-path-that-should-not-exist",
})
if err != nil {
t.Fatal(err)
}
if !strings.Contains(got, "Error:") {
t.Errorf("expected error in output, got %s", got)
}
// Empty
got, err = shellExecHandler(map[string]interface{}{"command": "true"})
if err != nil { t.Fatal(err) }
if got != "(empty output)" { t.Errorf("expected empty output, got %s", got) }
if err != nil {
t.Fatal(err)
}
if got != "(empty output)" {
t.Errorf("expected empty output, got %s", got)
}
}
func TestHashLine(t *testing.T) {
@@ -33,7 +47,7 @@ func TestHashLine(t *testing.T) {
if len(h1) != 4 {
t.Errorf("hashLine output length is not 4: %d", len(h1))
}
h3 := hashLine("hello worle")
if h1 == h3 {
t.Errorf("hashLine collision for similar strings: %s == %s", h1, h3)
@@ -45,7 +59,7 @@ func TestStripHashlines(t *testing.T) {
// ghij is not valid hex, so it should NOT be stripped if we follow the code strictly
// Wait, my code checks for hex: (c >= 'a' && c <= 'f')
// So 'ghij' should not be stripped.
expected := "line 1\nline 2\nnot a hashline\n3:ghij:line 3"
got := stripHashlines(input)
if got != expected {
@@ -82,7 +96,8 @@ func TestEditFileHandler_ExactHashlines(t *testing.T) {
got, _ := os.ReadFile(tmpFile)
expected := "line one\nreplaced two\nreplaced three\nline four"
if string(got) != expected {
t.Errorf("editFileHandler did not precisely replace using hashlines.\nGot: %s\nExpected: %s", string(got), expected)
t.Errorf("editFileHandler did not precisely replace using hashlines. Got: %s Expected: %s",
string(got), expected)
}
}
@@ -188,7 +203,7 @@ func TestGrepFileHandler_HashlineAnchors(t *testing.T) {
// 5:<hash>:fifth needle
lines := strings.Split(got, "\n")
findLine := func(prefix string) bool {
for _, l := range lines {
if strings.HasPrefix(l, prefix) {