| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | // A single-agent arm must say so rather than render nothing: an empty section |
| 9 | // reads as "not measured" when it actually means "no delegation happened". |
| 10 | func TestRenderDelegationNamesTheSingleAgentArm(t *testing.T) { |
| 11 | got := renderDelegation([]result{ |
| 12 | {Passed: true, runMetrics: runMetrics{ToolCalls: 9}}, |
| 13 | {Passed: false, runMetrics: runMetrics{ToolCalls: 4}}, |
| 14 | }) |
| 15 | if !strings.Contains(got, "none") || !strings.Contains(got, "1/2") { |
| 16 | t.Fatalf("single-agent arm rendered as %q", got) |
| 17 | } |
| 18 | if renderDelegation(nil) != "" { |
| 19 | t.Fatal("no runs at all must render nothing") |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | // The delegated arm has to expose the cost side, not just the outcome. |
| 24 | func TestRenderDelegationExposesWhatDelegationCost(t *testing.T) { |
| 25 | got := renderDelegation([]result{{ |
| 26 | Passed: true, |
| 27 | runMetrics: runMetrics{ |
| 28 | ToolCalls: 30, SubagentToolCalls: 24, |
| 29 | SubagentRuns: 3, SubagentNestedRuns: 1, SubagentMutations: 5, |
| 30 | DuplicateWorkPaths: 2, |
| 31 | CompletionReports: 2, CompletionsProsedOnly: 1, |
| 32 | FalseCompletions: 1, CriterionDowngrades: 3, |
| 33 | WriteScopeViolations: 1, |
| 34 | }, |
| 35 | }}) |
| 36 | for _, want := range []string{ |
| 37 | "3** child runs (1 nested)", |
| 38 | "parent **6** tool calls", |
| 39 | "children **24**", |
| 40 | "duplicate work**: 2", |
| 41 | "checkable claim: **2/3**", |
| 42 | "false completions**: 1 run(s), 3 criterion", |
| 43 | "write-scope violations**: 1", |
| 44 | } { |
| 45 | if !strings.Contains(got, want) { |
| 46 | t.Errorf("delegation section missing %q:\n%s", want, got) |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | // The section has to price independence as well as cost: how much of what the |
| 52 | // children read they had to find, and how much the parent's own text handed |
| 53 | // them. The hand-over stays an absolute count so its size cannot be hidden. |
| 54 | func TestRenderDelegationReportsEvidenceOrigin(t *testing.T) { |
| 55 | got := renderDelegation([]result{{ |
| 56 | Passed: true, |
| 57 | runMetrics: runMetrics{ |
| 58 | ToolCalls: 30, SubagentToolCalls: 24, SubagentRuns: 2, |
| 59 | ParentScopeHints: 2, ParentNamedFiles: 4, |
| 60 | ChildEvidencePaths: 25, ChildDiscoveredPaths: 23, |
| 61 | }, |
| 62 | }}) |
| 63 | for _, want := range []string{"evidence origin", "**92%**", "(23/25 paths)", "**2** scope hint(s)", "**4** file(s) named"} { |
| 64 | if !strings.Contains(got, want) { |
| 65 | t.Errorf("delegation section missing %q:\n%s", want, got) |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // Children that never touched a path leave the rate undefined. Printing 0% |
| 71 | // would read as "found nothing itself" instead of "nothing was measured". |
| 72 | func TestRenderDelegationSaysWhenEvidenceOriginIsUnscored(t *testing.T) { |
| 73 | got := renderDelegation([]result{{ |
| 74 | Passed: true, |
| 75 | runMetrics: runMetrics{ToolCalls: 6, SubagentToolCalls: 3, SubagentRuns: 1}, |
| 76 | }}) |
| 77 | line := "" |
| 78 | for l := range strings.SplitSeq(got, "\n") { |
| 79 | if strings.Contains(l, "evidence origin") { |
| 80 | line = l |
| 81 | } |
| 82 | } |
| 83 | if !strings.Contains(line, "not scored") { |
| 84 | t.Errorf("unscored origin rendered as %q", line) |
| 85 | } |
| 86 | if strings.Contains(line, "%") { |
| 87 | t.Errorf("unscored origin printed a rate: %q", line) |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // A clean delegated arm must not print alarm lines it has no evidence for. |
| 92 | func TestRenderDelegationStaysQuietWhenNothingWentWrong(t *testing.T) { |
| 93 | got := renderDelegation([]result{{ |
| 94 | Passed: true, |
| 95 | runMetrics: runMetrics{ToolCalls: 12, SubagentToolCalls: 8, SubagentRuns: 2, CompletionReports: 2}, |
| 96 | }}) |
| 97 | for _, unwanted := range []string{"duplicate work", "false completions", "write-scope violations"} { |
| 98 | if strings.Contains(got, unwanted) { |
| 99 | t.Errorf("clean run reported %q:\n%s", unwanted, got) |
| 100 | } |
| 101 | } |
| 102 | if !strings.Contains(got, "checkable claim: **2/2**") { |
| 103 | t.Errorf("clean run lost its completion coverage:\n%s", got) |
| 104 | } |
| 105 | } |
| 106 |