TestShowRecentHandoffSummary verifies the handoff output and its MaxHandoffCompactBytes guard against context bloat.
(t *testing.T)
| 1182 | // TestShowRecentHandoffSummary verifies the handoff output and its |
| 1183 | // MaxHandoffCompactBytes guard against context bloat. |
| 1184 | func TestShowRecentHandoffSummary(t *testing.T) { |
| 1185 | t.Run("nil artifact produces no output", func(t *testing.T) { |
| 1186 | out := captureOutput(func() { showRecentHandoffSummary(nil) }) |
| 1187 | if out != "" { |
| 1188 | t.Errorf("expected no output for nil artifact, got %q", out) |
| 1189 | } |
| 1190 | }) |
| 1191 | |
| 1192 | t.Run("artifact with changed files shows header and file", func(t *testing.T) { |
| 1193 | a := &handoff.Artifact{ |
| 1194 | Branch: "feature/test", |
| 1195 | BaseRef: "main", |
| 1196 | Delta: handoff.DeltaSnapshot{ |
| 1197 | Changed: []handoff.FileStub{ |
| 1198 | {Path: "cmd/hooks.go", Status: "modified"}, |
| 1199 | }, |
| 1200 | }, |
| 1201 | } |
| 1202 | out := captureOutput(func() { showRecentHandoffSummary(a) }) |
| 1203 | if !strings.Contains(out, "Recent handoff") { |
| 1204 | t.Errorf("expected 'Recent handoff' header, got %q", out) |
| 1205 | } |
| 1206 | if !strings.Contains(out, "feature/test") { |
| 1207 | t.Errorf("expected branch name, got %q", out) |
| 1208 | } |
| 1209 | }) |
| 1210 | |
| 1211 | t.Run("large summary is truncated to MaxHandoffCompactBytes (context bloat protection)", func(t *testing.T) { |
| 1212 | // Build a NextSteps list large enough to overflow MaxHandoffCompactBytes (3000 bytes). |
| 1213 | var nextSteps []string |
| 1214 | for i := 0; i < 200; i++ { |
| 1215 | nextSteps = append(nextSteps, fmt.Sprintf("Step %03d: do the thing with the long description that adds bytes %s", i, strings.Repeat("x", 30))) |
| 1216 | } |
| 1217 | a := &handoff.Artifact{ |
| 1218 | Branch: "feature/huge", |
| 1219 | BaseRef: "main", |
| 1220 | Delta: handoff.DeltaSnapshot{ |
| 1221 | NextSteps: nextSteps, |
| 1222 | }, |
| 1223 | } |
| 1224 | |
| 1225 | // Confirm the raw compact render is actually over budget before asserting truncation. |
| 1226 | raw := handoff.RenderCompact(a, 200) |
| 1227 | if len(raw) <= limits.MaxHandoffCompactBytes { |
| 1228 | t.Skipf("test precondition not met: raw compact render is only %d bytes (need >%d)", len(raw), limits.MaxHandoffCompactBytes) |
| 1229 | } |
| 1230 | |
| 1231 | out := captureOutput(func() { showRecentHandoffSummary(a) }) |
| 1232 | if !strings.Contains(out, "truncated") { |
| 1233 | t.Errorf("expected truncation indicator in oversized output, got %d bytes", len(out)) |
| 1234 | } |
| 1235 | }) |
| 1236 | |
| 1237 | t.Run("artifact with risk files includes them in summary", func(t *testing.T) { |
| 1238 | a := &handoff.Artifact{ |
| 1239 | Branch: "feature/risky", |
| 1240 | BaseRef: "main", |
| 1241 | Delta: handoff.DeltaSnapshot{ |
nothing calls this directly
no test coverage detected