Implementation: How to write comprehensive A2A protocol tests for the existi...
Documentation for Sessions
⚙️ Implementation: How to write comprehensive A2A protocol tests for the existi...
Date: 2026-02-26
Time: 16:54:31 UTC
Session: gspace1-144.8
Agent: testing
Confidence: 96%
Status: ✅ Documented
📋 Decision Context
Question:
How to write comprehensive A2A protocol tests for the existing implementation without modifying production code?
Task: Write A2A protocol integration tests (Gap 12)
🎯 Decision Made
Chosen:
5 test suites (59 tests) using @nestjs/testing Test.createTestingModule with mocked VittoEngineService. Covers discovery, lifecycle, error handling, all 9 status mappings, and SSE event building. Fixed pre-existing TS error in vitto.types.ts to unblock compilation.
Options Considered:
- Unit tests only on A2AService methods — rejected: misses controller routing and SSE stream behavior
- E2E tests with running Vitto server — rejected: requires MongoDB and full backend stack, too heavy for unit test suite
- Service-level tests with mocked dependencies via NestJS testing module — chosen: tests real service logic, mocks external deps, fast execution, covers all public methods
💭 Reasoning
ROOT CAUSE: A2A module had zero test coverage despite being a public protocol interface. Any breaking change to status mapping or agent card would go undetected. SOLUTION: 5 focused test files covering all A2A service public methods: (1) Discovery — verifies AgentCard structure, required fields, URL construction from VITTO_PUBLIC_URL env var; (2) Task lifecycle — full submit→status→complete flow with artifact extraction from PhaseResult; (3) Error handling — NotFoundException on invalid taskId, cancel flow, non-blocking MongoDB persistence failure, cache miss with DB fallback; (4) Status mapping — all 9 Vitto→A2A status mappings via it.each (queued→submitted, analyzing/planning/executing/verifying/delegating→working, completed→completed, failed→failed, cancelled→canceled), unknown status fallback; (5) SSE events — buildTaskEvent shape, ISO timestamp, terminal status detection. PRE-EXISTING BUG FIXED: phase-executor.service.ts:197 referenced _transient.simulationWarning which didn't exist on the type definition in vitto.types.ts — added the optional property to unblock all test compilation. WHAT WOULD MAKE THIS WRONG: If A2A protocol spec changes (Google is still iterating). If VittoEngineService.submitTask() return shape changes, lifecycle tests break. EARLY WARNING: Watch for new Vitto task statuses that aren't mapped in TASK_STATUS_MAP — they'll default to 'working' which may be wrong.
📁 Files Involved
APIs/backend-vitto-api/src/app/a2a/__tests__/a2a-discovery.spec.tsAPIs/backend-vitto-api/src/app/a2a/__tests__/a2a-task-lifecycle.spec.tsAPIs/backend-vitto-api/src/app/a2a/__tests__/a2a-error-handling.spec.tsAPIs/backend-vitto-api/src/app/a2a/__tests__/a2a-status-mapping.spec.tsAPIs/backend-vitto-api/src/app/a2a/__tests__/a2a-sse-events.spec.tsAPIs/backend-vitto-api/src/app/types/vitto.types.ts
🔗 Related
- Decision ID:
dev_1772124871291_djz5cvg - Session: 144
- Workspace: gspace1
Auto-generated by MCP Smart Consolidation