cover-branches
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBranch Coverage Gap Analysis & Fix
分支覆盖率缺口分析与修复
Find branch coverage gaps in changed code and write missing tests to fill them.
找出变更代码中的分支覆盖率缺口,并编写缺失的测试用例来填补这些缺口。
Phase 1: Identify Changes
阶段1:识别变更
Ask if there is a related spec file for scenario coverage analysis.
Run (or if there are staged changes) to identify changed source and test files.
git diffgit diff HEADIf no git changes exist, fall back to files the user mentioned or edited earlier in the conversation.
询问是否有相关的需求文档文件用于场景覆盖率分析。
运行(如果有暂存的变更则运行)来识别变更的源码文件和测试文件。
git diffgit diff HEAD如果没有Git变更,则以用户在对话中提到或编辑过的文件作为备选。
Phase 2: Launch Gap Analysis Agents in Parallel
阶段2:并行启动缺口分析Agent
Use the Agent tool to launch agents concurrently. Pass each agent the full diff for complete context.
使用Agent工具同时启动多个Agent。为每个Agent传递完整的diff内容以提供完整上下文。
Agent 1: Source ↔ Test Branch Coverage (always launched)
Agent 1:源码↔测试分支覆盖率分析(始终启动)
For each changed source file:
- Read the source file and identify all logic branches — conditional branches, error handling, early returns, default/fallback values, and any other branching constructs relevant to the file's language.
- Find the corresponding test file(s) by inferring the mapping from project conventions (naming, directory structure, imports). If no test file exists, report that as a gap.
- For each branch, determine if a test exercises that path.
- Report gaps in natural language: which branches lack test coverage and what test scenarios are missing.
针对每个变更的源码文件:
- 读取源码文件并识别所有逻辑分支——条件分支、错误处理、提前返回、默认/回退值,以及与文件编程语言相关的任何其他分支结构。
- 根据项目约定(命名规则、目录结构、导入方式)推断对应的测试文件。如果不存在测试文件,则将其报告为缺口。
- 针对每个分支,判断是否有测试用例覆盖该路径。
- 用自然语言报告缺口:哪些分支缺乏测试覆盖,以及缺失哪些测试场景。
Agent 2: Spec ↔ Test Scenario Coverage (launched only when user provides a spec file)
Agent 2:需求文档↔测试场景覆盖率分析(仅当用户提供需求文档文件时启动)
- Read the spec file provided by the user.
- Extract all testable scenarios: functional requirements, boundary conditions, error handling, edge cases, acceptance criteria, user stories.
- Find the corresponding test file(s).
- For each scenario, determine: covered or gap.
- Report gaps in natural language: which scenarios lack test coverage and what is missing.
- 读取用户提供的需求文档文件。
- 提取所有可测试场景:功能需求、边界条件、错误处理、边缘情况、验收标准、用户故事。
- 找到对应的测试文件。
- 针对每个场景,判断:已覆盖或缺口。
- 用自然语言报告缺口:哪些场景缺乏测试覆盖,以及缺失的内容。
Phase 3: Fix Gaps
阶段3:修复缺口
- Wait for all agents to complete.
- Merge findings from both agents, avoiding obviously redundant test cases.
- Write all missing test cases directly. Follow existing test file conventions (framework, naming, structure). If no test file exists, create one following project conventions.
- When a spec contains contradictions, or when the correct test behavior cannot be inferred from the source code, ask the user before writing the test.
- Run the tests to verify they pass. Infer the test command from project configuration (,
package.json,Makefile, etc.); if unable to infer, ask the user.pom.xml - Summarize what was added, or confirm coverage is already complete.
- Confirm coverage layers addressed (Source ↔ Test, and Spec ↔ Test if a spec was provided).
- 等待所有Agent完成分析。
- 合并两个Agent的分析结果,避免明显冗余的测试用例。
- 直接编写所有缺失的测试用例。遵循现有测试文件的约定(测试框架、命名规则、结构)。如果不存在测试文件,则按照项目约定创建一个。
- 当需求文档存在矛盾,或无法从源码中推断正确的测试行为时,在编写测试用例前询问用户。
- 运行测试以验证用例通过。从项目配置文件(、
package.json、Makefile等)推断测试命令;如果无法推断,则询问用户。pom.xml - 总结新增的内容,或确认覆盖率已完整。
- 确认已处理的覆盖层面(源码↔测试,以及如果提供了需求文档则包含需求文档↔测试)。