MCPcopy Create free account
hub / github.com/codehamr/codehamr / TestToolResultFailed

Function TestToolResultFailed

internal/tui/tui_test.go:1765–1801  ·  view source on GitHub ↗

TestToolResultFailed pins the failure classifier the nudge keys on: a "(cancelled)" result (user Ctrl+C) is never a failure; write/edit fail iff the trimmed result opens with "(" (their error convention); read_file returns raw content on success, which can start with "(", so it fails only on its two

(t *testing.T)

Source from the content-addressed store, hash-verified

1763 Name: tools.EditFileName, Arguments: map[string]any{"path": "/a/b.go", "old_string": "x", "new_string": "y"},
1764 }, tools.EditFileName + "|/a/b.go"},
1765 {"read_file keys on path", chmctx.ToolCall{
1766 Name: tools.ReadFileName, Arguments: map[string]any{"path": "/a/b.go"},
1767 }, tools.ReadFileName + "|/a/b.go"},
1768 {"bash keys on first line of cmd", chmctx.ToolCall{
1769 Name: tools.BashName, Arguments: map[string]any{"cmd": "go test ./...\necho done"},
1770 }, tools.BashName + "|go test ./..."},
1771 {"bash trims surrounding whitespace", chmctx.ToolCall{
1772 Name: tools.BashName, Arguments: map[string]any{"cmd": " ls -la \nmore"},
1773 }, tools.BashName + "|ls -la"},
1774 {"unknown tool keys on name", chmctx.ToolCall{
1775 Name: "context7", Arguments: map[string]any{"query": "x"},
1776 }, "context7"},
1777 }
1778 for _, c := range cases {
1779 if got := toolTargetKey(c.call); got != c.want {
1780 t.Errorf("%s: toolTargetKey = %q, want %q", c.name, got, c.want)
1781 }
1782 }
1783}
1784
1785// TestToolResultFailed pins the failure classifier the nudge keys on: a
1786// "(cancelled)" result (user Ctrl+C) is never a failure; write/edit fail iff the
1787// trimmed result opens with "(" (their error convention); read_file returns raw
1788// content on success, which can start with "(", so it fails only on its two
1789// real error outputs; bash fails iff it carries "\n(exit: " or "(timeout after "
1790// or is exactly "(empty command)"; a clean result is not a failure.
1791func TestToolResultFailed(t *testing.T) {
1792 cases := []struct {
1793 name string
1794 tool string
1795 result string
1796 want bool
1797 }{
1798 {"cancelled is never a failure", tools.BashName, "partial\n(cancelled)", false},
1799 {"cancelled file op is not a failure", tools.WriteFileName, "(cancelled)", false},
1800 {"bash non-zero exit fails", tools.BashName, "boom\n(exit: exit status 1)", true},
1801 {"bash timeout fails", tools.BashName, "slow\n(timeout after 2s)", true},
1802 {"bash empty-command fails", tools.BashName, "(empty command)", true},
1803 {"bash clean success", tools.BashName, "all green\n", false},
1804 {"bash leading-paren output is not a failure", tools.BashName, "(3 rows affected)\n", false},

Callers

nothing calls this directly

Calls 1

toolResultFailedFunction · 0.85

Tested by

no test coverage detected