Summary
The doAnalyze function in internal/copilot/client.go (line 591) has only 6.9% test coverage. This function performs AI-powered completion analysis by creating a Copilot SDK session, sending plan content, handling tool calls, and parsing structured JSON responses. It is the most complex function in the copilot package and the least tested.
Details
doAnalyze is responsible for:
- Acquiring a mutex lock and checking SDK availability
- Creating a non-streaming SDK session with tool definitions
- Sending a structured analysis prompt with plan content
- Handling a multi-turn tool-call loop (up to 10 iterations)
- Parsing the final response as JSON into a CompletionAnalysis struct
- Applying a longer timeout (analysisOperationTimeout) than search operations
The existing test hook (c.hooks.doAnalyze) is the only tested path (the early return at line 593-595), meaning the actual SDK interaction, tool-call loop, JSON parsing, and error handling are all untested.
Impact
The copilot package overall is at 76.2% coverage, and doAnalyze is the primary gap. Since this function orchestrates external SDK calls, JSON parsing, and a retry loop, it has multiple failure modes:
- SDK session creation failure
- Tool-call loop exceeding the 10-iteration cap
- Malformed JSON in the final response
- Timeout during analysis
Recommendation
- Add unit tests using the existing hooks.doAnalyze injection point to verify the caller's retry logic and error propagation in AnalyzeCompletion
- Add integration-style tests with a mock SDK client that exercises the tool-call loop (return tool calls for N iterations, then a final response)
- Test JSON parsing with malformed responses to verify graceful degradation
- Test the timeout path by injecting a slow hook
Summary
The doAnalyze function in internal/copilot/client.go (line 591) has only 6.9% test coverage. This function performs AI-powered completion analysis by creating a Copilot SDK session, sending plan content, handling tool calls, and parsing structured JSON responses. It is the most complex function in the copilot package and the least tested.
Details
doAnalyze is responsible for:
The existing test hook (c.hooks.doAnalyze) is the only tested path (the early return at line 593-595), meaning the actual SDK interaction, tool-call loop, JSON parsing, and error handling are all untested.
Impact
The copilot package overall is at 76.2% coverage, and doAnalyze is the primary gap. Since this function orchestrates external SDK calls, JSON parsing, and a retry loop, it has multiple failure modes:
Recommendation