| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | |
| 7 | "reasonix/internal/provider" |
| 8 | "reasonix/internal/tool" |
| 9 | ) |
| 10 | |
| 11 | func TestProviderVisibleResultKeepsExactRepeats(t *testing.T) { |
| 12 | a := &Agent{} |
| 13 | first, _, _ := a.boundProviderVisibleResult("hello world", "read_file", "c1") |
| 14 | second, _, _ := a.boundProviderVisibleResult("hello world", "read_file", "c2") |
| 15 | if first != "hello world" || second != "hello world" { |
| 16 | t.Fatalf("repeated results were rewritten: first=%q second=%q", first, second) |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | func TestTodoWriteResultsAreNeverPresentationDeduplicated(t *testing.T) { |
| 21 | a := &Agent{} |
| 22 | raw := `{"todos":[{"content":"ship","status":"completed"}],"counts":{"total":1,"pending":0,"in_progress":0,"completed":1}}` |
| 23 | first, _, _ := a.boundProviderVisibleResult(raw, "todo_write", "todo-1") |
| 24 | second, _, _ := a.boundProviderVisibleResult(raw, "todo_write", "todo-2") |
| 25 | if first != raw || second != raw { |
| 26 | t.Fatalf("todo result was rewritten: first=%q second=%q", first, second) |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | func TestResolvedSkipOutcomeKeepsRepeatedLocalDiscovery(t *testing.T) { |
| 31 | a := &Agent{} |
| 32 | result := `{"id":"mcp-tool:server/read","input_schema":{"type":"object"}}` |
| 33 | plan := func(id string) *toolCallPlan { |
| 34 | return &toolCallPlan{call: provider.ToolCall{ID: id, Name: "use_capability", Arguments: `{}`}} |
| 35 | } |
| 36 | resolved := tool.ResolvedCall{ProxyAction: "inspect", SkipExecute: true, ReadOnly: true, Result: result} |
| 37 | first := a.resolvedSkipOutcome(plan("c1"), resolved) |
| 38 | if first.output != result { |
| 39 | t.Fatalf("first output = %q", first.output) |
| 40 | } |
| 41 | second := a.resolvedSkipOutcome(plan("c2"), resolved) |
| 42 | if second.output != result { |
| 43 | t.Fatalf("second output = %q", second.output) |
| 44 | } |
| 45 | if second.rawOutput != "" { |
| 46 | t.Fatalf("untransformed complete output should not need a duplicate local copy: %q", second.rawOutput) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | func TestSummarizeCIOutputKeepsFailures(t *testing.T) { |
| 51 | body := "##teamcity[testFailed name='A']\n" + strings.Repeat("ok\n", 400) + "exit status 1\n" |
| 52 | got := summarizeCIOutput(body) |
| 53 | if !strings.Contains(got, "exit_code: 1") || !strings.Contains(got, "testFailed") { |
| 54 | t.Fatalf("summary = %q", got) |
| 55 | } |
| 56 | if len(got) >= len(body) { |
| 57 | t.Fatal("summary should be smaller than the raw CI log") |
| 58 | } |
| 59 | } |
| 60 |