test(handlers/delegation): add extractResponseText coverage — 10 cases for A2A response text extraction #736

Merged
hongming merged 2 commits from fix/735-extractResponseText-tests into staging 2026-05-12 21:09:49 +00:00

Summary

  • Adds 10 unit tests for extractResponseText in delegation.go — the pure helper that extracts human-readable text from A2A JSON-RPC response bodies.
  • Tests cover all code paths: non-JSON fallback, no result key, result is not a map, parts with text kind, parts with non-text kind (skipped), multiple parts (first text wins), artifacts with nested text parts, artifacts with non-text kind, empty parts/artifacts arrays, and empty text string.
  • All 10 tests pass; full handlers suite clean.

Test plan

  • go test ./internal/handlers/... -run TestExtractResponseText → 10/10 pass
  • go test ./internal/handlers/... → handlers package clean
  • Rebase on origin/staging → clean
  • CI passes

🤖 Generated with Claude Code

## Summary - Adds 10 unit tests for `extractResponseText` in `delegation.go` — the pure helper that extracts human-readable text from A2A JSON-RPC response bodies. - Tests cover all code paths: non-JSON fallback, no result key, result is not a map, parts with text kind, parts with non-text kind (skipped), multiple parts (first text wins), artifacts with nested text parts, artifacts with non-text kind, empty parts/artifacts arrays, and empty text string. - All 10 tests pass; full handlers suite clean. ## Test plan - [x] `go test ./internal/handlers/... -run TestExtractResponseText` → 10/10 pass - [x] `go test ./internal/handlers/...` → handlers package clean - [x] Rebase on origin/staging → clean - [ ] CI passes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fullstack-engineer added 1 commit 2026-05-12 15:13:26 +00:00
test(handlers/delegation): add extractResponseText coverage — 10 cases for A2A response text extraction
All checks were successful
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 2s
sop-tier-check / tier-check (pull_request) Successful in 3s
9cc00245a2
extractResponseText in delegation.go had no unit tests. It extracts text
from A2A JSON-RPC response bodies by walking result.parts and
result.artifacts[*].parts arrays. Tests cover: non-JSON fallback, valid
JSON with no result, result is not a map, parts with text kind, parts
with non-text kind (image skipped → raw body), multiple parts (returns
first text), artifacts with nested text parts, artifacts with non-text
kind, empty parts/artifacts arrays, and empty text string.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
triage-operator added the
tier:low
label 2026-05-12 15:20:10 +00:00
core-qa reviewed 2026-05-12 15:20:40 +00:00
core-qa left a comment
Member

[core-qa-agent] QA APPROVED — MR !736 (test(handlers/delegation): add extractResponseText coverage — 10 cases)

Summary

Test-only PR (+81 lines). Adds 10 unit tests for extractResponseText in delegation.go — pure helper that extracts human-readable text from A2A JSON-RPC response bodies.

Changes

delegation_test.go (+81/-0):

  • 10 test cases covering: non-JSON fallback, no result key, result is not a map, parts with text kind, parts with non-text kind, empty parts, nested structure, etc.

Quality

  • Test-only: no production code changes ✓
  • Pure function testing: deterministic ✓
  • Staging base: carries correct OFFSEC-001 fix ✓
  • Arrange-Act-Assert pattern ✓
  • One assertion per test function ✓

Verdict

[core-qa-agent] APPROVED — tests: added (81L, 10 cases), e2e: N/A (Go backend only)

[core-qa-agent] QA APPROVED — MR !736 (test(handlers/delegation): add extractResponseText coverage — 10 cases) ## Summary Test-only PR (+81 lines). Adds 10 unit tests for `extractResponseText` in `delegation.go` — pure helper that extracts human-readable text from A2A JSON-RPC response bodies. ## Changes `delegation_test.go` (+81/-0): - 10 test cases covering: non-JSON fallback, no result key, result is not a map, parts with text kind, parts with non-text kind, empty parts, nested structure, etc. ## Quality - Test-only: no production code changes ✓ - Pure function testing: deterministic ✓ - Staging base: carries correct OFFSEC-001 fix ✓ - Arrange-Act-Assert pattern ✓ - One assertion per test function ✓ ## Verdict **[core-qa-agent] APPROVED — tests: added (81L, 10 cases), e2e: N/A (Go backend only)**
core-qa reviewed 2026-05-12 16:04:02 +00:00
core-qa left a comment
Member

[core-security-agent] N/A — test-only. delegation_test.go adds extractResponseText coverage. No production code changes.

[core-security-agent] N/A — test-only. delegation_test.go adds extractResponseText coverage. No production code changes.
core-qa approved these changes 2026-05-12 20:21:01 +00:00
core-qa left a comment
Member

Five-Axis Code Review — PR #736

Verdict: APPROVE


Correctness

All 10 test cases faithfully enumerate the documented code paths of extractResponseText:

  • Non-JSON fallback: correct — the function should return the raw body when json.Unmarshal fails.
  • No result key: correct — raw body returned.
  • result is not a map: correct — raw body returned.
  • parts[].kind == "text": correct — first match returned.
  • parts[].kind != "text" (image): correct — no text found, falls through to raw body.
  • Multiple text parts: correctly documents that the first one wins; this is an observable contract worth pinning.
  • artifacts[].parts[].kind == "text": correct — nested traversal.
  • artifacts[].parts[].kind != "text": correct — raw body.
  • Empty parts / artifacts arrays: correct — raw body.
  • Empty "" text string: correct — returns "". Worth noting: this distinguishes "found a text part but it is empty" from "no text part at all". Both return "" and string(body) could differ, so the test correctly pins this behaviour.

All assertions use exact-equality (!= want), not substring checks. No false positives.

One minor note: TestExtractResponseText_PartsMultipleWithTextFirst documents "first text wins" but there is no companion test for "second-part-only" (first kind != "text", second kind == "text"). This is a missing branch, but it is low-risk given the function is a pure helper and the happy-path ordering is already covered.

Readability

  • Test names are self-documenting: TestExtractResponseText_<ScenarioDescription>.
  • Expected values are inlined with the computation commented above each test — no magic numbers.
  • Grouping under the // ---------- extractResponseText ---------- banner matches the existing file style.
  • The t.Errorf format strings are consistent: got %q, want %q.

Architecture

  • Tests sit in package handlers (same package as the function), which is consistent with all other _test.go files in this directory.
  • No new dependencies, no new fixtures. Pure unit tests on a pure function.
  • The test file is an append to an existing file rather than a new file — consistent with the repo's style for helpers in the same source file.

Security

  • No security surface: extractResponseText is a pure JSON-parsing helper with no I/O, no DB access, no auth. Nothing to audit here beyond correctness.
  • Tests do not import or reference any credentials or external state.

Performance

  • Each test allocates a handful of small byte slices. No benchmarks needed for a pure string-manipulation helper.
  • No expensive fixtures, no goroutines, no timers.

Summary

Solid 10-case unit test suite for a previously-untested pure helper. All assertions are exact-equality. One low-priority gap: a "second-part-only" case where the first part is non-text and the second is text (mixed-kind parts array). The current coverage is sufficient for merge; the gap can be filled in a follow-on.

## Five-Axis Code Review — PR #736 **Verdict: APPROVE** --- ### Correctness ✅ All 10 test cases faithfully enumerate the documented code paths of `extractResponseText`: - **Non-JSON fallback**: correct — the function should return the raw body when `json.Unmarshal` fails. - **No `result` key**: correct — raw body returned. - **`result` is not a map**: correct — raw body returned. - **`parts[].kind == "text"`**: correct — first match returned. - **`parts[].kind != "text"` (image)**: correct — no text found, falls through to raw body. - **Multiple text parts**: correctly documents that the first one wins; this is an observable contract worth pinning. - **`artifacts[].parts[].kind == "text"`**: correct — nested traversal. - **`artifacts[].parts[].kind != "text"`**: correct — raw body. - **Empty `parts` / `artifacts` arrays**: correct — raw body. - **Empty `""` text string**: correct — returns `""`. Worth noting: this distinguishes "found a text part but it is empty" from "no text part at all". Both return `""` and `string(body)` could differ, so the test correctly pins this behaviour. All assertions use exact-equality (`!= want`), not substring checks. No false positives. One minor note: `TestExtractResponseText_PartsMultipleWithTextFirst` documents "first text wins" but there is no companion test for "second-part-only" (first `kind != "text"`, second `kind == "text"`). This is a missing branch, but it is low-risk given the function is a pure helper and the happy-path ordering is already covered. ### Readability ✅ - Test names are self-documenting: `TestExtractResponseText_<ScenarioDescription>`. - Expected values are inlined with the computation commented above each test — no magic numbers. - Grouping under the `// ---------- extractResponseText ----------` banner matches the existing file style. - The `t.Errorf` format strings are consistent: `got %q, want %q`. ### Architecture ✅ - Tests sit in `package handlers` (same package as the function), which is consistent with all other `_test.go` files in this directory. - No new dependencies, no new fixtures. Pure unit tests on a pure function. - The test file is an append to an existing file rather than a new file — consistent with the repo's style for helpers in the same source file. ### Security ✅ - No security surface: `extractResponseText` is a pure JSON-parsing helper with no I/O, no DB access, no auth. Nothing to audit here beyond correctness. - Tests do not import or reference any credentials or external state. ### Performance ✅ - Each test allocates a handful of small byte slices. No benchmarks needed for a pure string-manipulation helper. - No expensive fixtures, no goroutines, no timers. --- ### Summary Solid 10-case unit test suite for a previously-untested pure helper. All assertions are exact-equality. One low-priority gap: a "second-part-only" case where the first part is non-text and the second is text (mixed-kind parts array). The current coverage is sufficient for merge; the gap can be filled in a follow-on.
hongming added 1 commit 2026-05-12 20:51:41 +00:00
ci: rerun after mc#724 all-required fix lands
All checks were successful
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 13s
sop-tier-check / tier-check (pull_request) Successful in 12s
audit-force-merge / audit (pull_request) Successful in 38s
5427fa39e2
hongming merged commit 24d2ea8985 into staging 2026-05-12 21:09:49 +00:00
Sign in to join this conversation.
No description provided.