ln-634-test-coverage-auditor
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCoverage Gaps Auditor (L3 Worker)
测试覆盖缺口审计器(L3工作器)
Specialized worker identifying missing tests for critical business logic.
一款专门用于识别关键业务逻辑中缺失测试的工作器。
Purpose & Scope
目标与范围
- Worker in ln-630 coordinator pipeline
- Audit Coverage Gaps (Category 4: High Priority)
- Identify untested critical paths
- Classify by category (Money, Security, Data, Core Flows)
- Calculate compliance score (X/10)
- ln-630协调器流水线中的工作器
- 审计测试覆盖缺口(4类:高优先级)
- 识别未测试的关键路径
- 按类别分类(资金、安全、数据、核心流程)
- 计算合规评分(X/10)
Inputs (from Coordinator)
输入(来自协调器)
MANDATORY READ: Load for contextStore structure.
shared/references/task_delegation_pattern.md#audit-coordinator--worker-contractReceives with: , , .
contextStoretech_stacktestFilesMetadatacodebase_rootDomain-aware: Supports + (see ).
domain_modecurrent_domainaudit_output_schema.md#domain-aware-worker-output必读提示: 加载以了解contextStore结构。
shared/references/task_delegation_pattern.md#audit-coordinator--worker-contract接收包含以下内容的:、、。
contextStoretech_stacktestFilesMetadatacodebase_root领域感知: 支持 + (详见)。
domain_modecurrent_domainaudit_output_schema.md#domain-aware-worker-outputWorkflow
工作流程
-
Parse context — extract fields, determine(domain-aware if specified) ELSE: scan_path = codebase_root domain_name = null
scan_pathundefined -
Identify critical paths in scan_path (not entire codebase)
- Scan production code in for money/security/data keywords
scan_path - All Grep/Glob patterns use (not codebase_root)
scan_path - Example:
Grep(pattern="payment|refund|discount", path=scan_path)
- Scan production code in
-
Check test coverage for each critical path
- Search ALL test files for coverage (tests may be in different location than production code)
- Match by function name, module name, or test description
-
Collect missing tests
- Tag each finding with (if domain-aware)
domain: domain_name
- Tag each finding with
-
Calculate score
-
Return JSON with domain metadata
- Include and
domainfields (if domain-aware)scan_path
- Include
-
解析上下文 — 提取字段,确定(若指定则启用领域感知) 否则: scan_path = codebase_root domain_name = null
scan_pathundefined -
识别scan_path中的关键路径(而非整个代码库)
- 扫描中的生产代码,查找与资金/安全/数据相关的关键词
scan_path - 所有Grep/Glob模式均使用(而非codebase_root)
scan_path - 示例:
Grep(pattern="payment|refund|discount", path=scan_path)
- 扫描
-
检查每个关键路径的测试覆盖情况
- 搜索所有测试文件以确认覆盖情况(测试文件可能与生产代码位于不同位置)
- 通过函数名、模块名或测试描述进行匹配
-
收集缺失的测试
- 若启用领域感知,为每个检测结果标记
domain: domain_name
- 若启用领域感知,为每个检测结果标记
-
计算评分
-
返回包含领域元数据的JSON
- 若启用领域感知,需包含和
domain字段scan_path
- 若启用领域感知,需包含
Critical Paths Classification
关键路径分类
1. Money Flows (Priority 20+)
1. 资金流(优先级20+)
What: Any code handling financial transactions
Examples:
- Payment processing (,
/payment)processPayment() - Discounts/promotions (,
calculateDiscount())applyPromoCode() - Tax calculations (,
calculateTax())getTaxRate() - Refunds (,
processRefund())/refund - Invoices/billing (,
generateInvoice())createBill() - Currency conversion ()
convertCurrency()
Min Priority: 20
Why Critical: Money loss, fraud, legal compliance
定义: 任何处理金融交易的代码
示例:
- 支付处理(、
/payment)processPayment() - 折扣/促销(、
calculateDiscount())applyPromoCode() - 税费计算(、
calculateTax())getTaxRate() - 退款处理(、
processRefund())/refund - 发票/账单(、
generateInvoice())createBill() - 货币转换()
convertCurrency()
最低优先级: 20
关键原因: 资金损失、欺诈、合规风险
2. Security Flows (Priority 20+)
2. 安全流(优先级20+)
What: Authentication, authorization, encryption
Examples:
- Login/logout (,
/login)authenticate() - Token refresh (,
/refresh-token)refreshAccessToken() - Password reset (,
/forgot-password)resetPassword() - Permissions/RBAC (,
checkPermission())hasRole() - Encryption/hashing (custom crypto logic, NOT bcrypt/argon2)
- API key validation ()
validateApiKey()
Min Priority: 20
Why Critical: Security breach, data leak, unauthorized access
定义: 身份验证、授权、加密相关代码
示例:
- 登录/登出(、
/login)authenticate() - Token刷新(、
/refresh-token)refreshAccessToken() - 密码重置(、
/forgot-password)resetPassword() - 权限/RBAC(、
checkPermission())hasRole() - 加密/哈希(自定义加密逻辑,不含bcrypt/argon2)
- API密钥验证()
validateApiKey()
最低优先级: 20
关键原因: 安全漏洞、数据泄露、未授权访问
3. Data Integrity (Priority 15+)
3. 数据完整性(优先级15+)
What: CRUD operations, transactions, validation
Examples:
- Critical CRUD (,
createUser(),deleteOrder())updateProduct() - Database transactions ()
withTransaction() - Data validation (custom validators, NOT framework defaults)
- Data migrations ()
runMigration() - Unique constraints ()
checkDuplicateEmail()
Min Priority: 15
Why Critical: Data corruption, lost data, inconsistent state
定义: CRUD操作、事务、验证相关代码
示例:
- 核心CRUD操作(、
createUser()、deleteOrder())updateProduct() - 数据库事务()
withTransaction() - 数据验证(自定义验证器,不含框架默认验证)
- 数据迁移()
runMigration() - 唯一约束()
checkDuplicateEmail()
最低优先级: 15
关键原因: 数据损坏、数据丢失、状态不一致
4. Core User Journeys (Priority 15+)
4. 核心用户旅程(优先级15+)
What: Multi-step flows critical to business
Examples:
- Registration → Email verification → Onboarding
- Search → Product details → Add to cart → Checkout
- Upload file → Process → Download result
- Submit form → Approval workflow → Notification
Min Priority: 15
Why Critical: Broken user flow = lost customers
定义: 对业务至关重要的多步骤流程
示例:
- 注册 → 邮箱验证 → 新手引导
- 搜索 → 商品详情 → 加入购物车 → 结账
- 文件上传 → 处理 → 结果下载
- 表单提交 → 审批流程 → 通知
最低优先级: 15
关键原因: 用户流程断裂会导致客户流失
Audit Rules
审计规则
1. Identify Critical Paths
1. 识别关键路径
Process:
- Scan codebase for money-related keywords: ,
payment,refund,discount,tax,pricecurrency - Scan for security keywords: ,
auth,login,password,token,permissionencrypt - Scan for data keywords: ,
transaction,validation,migrationconstraint - Scan for user journeys: multi-step flows in routes/controllers
流程:
- 扫描代码库中的资金相关关键词:、
payment、refund、discount、tax、pricecurrency - 扫描安全相关关键词:、
auth、login、password、token、permissionencrypt - 扫描数据相关关键词:、
transaction、validation、migrationconstraint - 扫描用户旅程:路由/控制器中的多步骤流程
2. Check Test Coverage
2. 检查测试覆盖情况
For each critical path:
- Search test files for matching test name/description
- If NO test found → add to missing tests list
- If test found but inadequate (only positive, no edge cases) → add to gaps list
针对每个关键路径:
- 在测试文件中搜索匹配的测试名称/描述
- 若未找到测试 → 添加至缺失测试列表
- 若找到测试但覆盖不足(仅正向用例,无边缘场景)→ 添加至覆盖缺口列表
3. Categorize Gaps
3. 对缺口进行分类
Severity by Priority:
- CRITICAL: Priority 20+ (Money, Security)
- HIGH: Priority 15-19 (Data, Core Flows)
- MEDIUM: Priority 10-14 (Important but not critical)
按优先级划分严重程度:
- CRITICAL(严重): 优先级20+(资金、安全类)
- HIGH(高): 优先级15-19(数据、核心流程类)
- MEDIUM(中): 优先级10-14(重要但非核心)
4. Provide Justification
4. 提供说明
For each missing test:
- Explain WHY it's critical (money loss, security breach, etc.)
- Suggest test type (E2E, Integration, Unit)
- Estimate effort (S/M/L)
针对每个缺失测试:
- 解释其关键原因(资金损失、安全漏洞等)
- 建议测试类型(E2E、集成测试、单元测试)
- 估算工作量(S/M/L)
Scoring Algorithm
评分算法
See for unified formula and score interpretation.
shared/references/audit_scoring.mdSeverity mapping by Priority:
- Priority 20+ (Money, Security) missing test → CRITICAL
- Priority 15-19 (Data Integrity, Core Flows) missing test → HIGH
- Priority 10-14 (Important) missing test → MEDIUM
- Priority <10 (Nice-to-have) → LOW
统一公式及评分解读请参阅。
shared/references/audit_scoring.md按优先级映射严重程度:
- 优先级20+(资金、安全类)缺失测试 → CRITICAL
- 优先级15-19(数据完整性、核心流程类)缺失测试 → HIGH
- 优先级10-14(重要类)缺失测试 → MEDIUM
- 优先级<10(锦上添花类)→ LOW
Output Format
输出格式
Return JSON to coordinator:
json
{
"category": "Coverage Gaps",
"score": 6,
"total_issues": 10,
"critical": 3,
"high": 4,
"medium": 2,
"low": 1,
"checks": [
{"id": "line_coverage", "name": "Line Coverage", "status": "passed", "details": "85% coverage (threshold: 80%)"},
{"id": "branch_coverage", "name": "Branch Coverage", "status": "warning", "details": "72% coverage (threshold: 75%)"},
{"id": "function_coverage", "name": "Function Coverage", "status": "passed", "details": "90% coverage (threshold: 80%)"},
{"id": "critical_gaps", "name": "Critical Gaps", "status": "failed", "details": "3 Money flows, 2 Security flows untested"}
],
"domain": "orders",
"scan_path": "src/orders",
"findings": [
{
"severity": "CRITICAL",
"location": "src/orders/services/order.ts:45",
"issue": "Missing E2E test for applyDiscount() (Priority 25, Money flow)",
"principle": "Coverage Gaps / Money Flow",
"recommendation": "Add E2E test: applyDiscount() with edge cases (negative discount, max discount, currency rounding)",
"effort": "M"
},
{
"severity": "HIGH",
"location": "src/orders/repositories/order.ts:78",
"issue": "Missing Integration test for orderTransaction() rollback (Priority 18, Data Integrity)",
"principle": "Coverage Gaps / Data Integrity",
"recommendation": "Add Integration test verifying transaction rollback on failure",
"effort": "M"
}
]
}Note: and fields included only when .
domainscan_pathdomain_mode="domain-aware"向协调器返回JSON:
json
{
"category": "Coverage Gaps",
"score": 6,
"total_issues": 10,
"critical": 3,
"high": 4,
"medium": 2,
"low": 1,
"checks": [
{"id": "line_coverage", "name": "Line Coverage", "status": "passed", "details": "85% coverage (threshold: 80%)"},
{"id": "branch_coverage", "name": "Branch Coverage", "status": "warning", "details": "72% coverage (threshold: 75%)"},
{"id": "function_coverage", "name": "Function Coverage", "status": "passed", "details": "90% coverage (threshold: 80%)"},
{"id": "critical_gaps", "name": "Critical Gaps", "status": "failed", "details": "3 Money flows, 2 Security flows untested"}
],
"domain": "orders",
"scan_path": "src/orders",
"findings": [
{
"severity": "CRITICAL",
"location": "src/orders/services/order.ts:45",
"issue": "Missing E2E test for applyDiscount() (Priority 25, Money flow)",
"principle": "Coverage Gaps / Money Flow",
"recommendation": "Add E2E test: applyDiscount() with edge cases (negative discount, max discount, currency rounding)",
"effort": "M"
},
{
"severity": "HIGH",
"location": "src/orders/repositories/order.ts:78",
"issue": "Missing Integration test for orderTransaction() rollback (Priority 18, Data Integrity)",
"principle": "Coverage Gaps / Data Integrity",
"recommendation": "Add Integration test verifying transaction rollback on failure",
"effort": "M"
}
]
}注意: 仅当时,才包含和字段。
domain_mode="domain-aware"domainscan_pathCritical Rules
核心规则
- Domain-aware scanning: If , scan ONLY
domain_mode="domain-aware"production code (not entire codebase)scan_path - Tag findings: Include field in each finding when domain-aware
domain - Test search scope: Search ALL test files for coverage (tests may be in different location than production code)
- Match by name: Use function name, module name, or test description to match tests to production code
- 领域感知扫描: 若,仅扫描
domain_mode="domain-aware"中的生产代码(而非整个代码库)scan_path - 标记检测结果: 启用领域感知时,需在每个检测结果中包含字段
domain - 测试搜索范围: 搜索所有测试文件以确认覆盖情况(测试文件可能与生产代码位于不同位置)
- 按名称匹配: 通过函数名、模块名或测试描述将测试与生产代码进行匹配
Definition of Done
完成标准
- contextStore parsed (including domain_mode and current_domain)
- scan_path determined (domain path or codebase root)
- Critical paths identified in scan_path (Money, Security, Data, Core Flows)
- Test coverage checked for each critical path
- Missing tests collected with severity, priority, justification, domain
- Score calculated
- JSON returned to coordinator with domain metadata
- 已解析contextStore(包括domain_mode和current_domain)
- 已确定scan_path(领域路径或代码库根目录)
- 已识别scan_path中的关键路径(资金、安全、数据、核心流程类)
- 已检查每个关键路径的测试覆盖情况
- 已收集包含严重程度、优先级、说明、领域信息的缺失测试列表
- 已计算评分
- 已向协调器返回包含领域元数据的JSON
Reference Files
参考文件
- Audit scoring formula:
shared/references/audit_scoring.md - Audit output schema:
shared/references/audit_output_schema.md
Version: 3.0.0
Last Updated: 2025-12-23
- 审计评分公式:
shared/references/audit_scoring.md - 审计输出 schema:
shared/references/audit_output_schema.md
版本: 3.0.0
最后更新: 2025-12-23