ln-633-test-value-auditor

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Risk-Based Value Auditor (L3 Worker)

基于风险价值的审计器(L3工作组件)

Specialized worker calculating Usefulness Score for each test.
专门用于为每个测试计算效用分数的工作组件。

Purpose & Scope

目标与范围

  • Worker in ln-630 coordinator pipeline
  • Audit Risk-Based Value (Category 3: Critical Priority)
  • Calculate Usefulness Score = Impact × Probability
  • Make KEEP/REVIEW/REMOVE decisions
  • Calculate compliance score (X/10)
  • ln-630协调器流水线中的工作组件
  • 审计基于风险的价值(类别3:关键优先级)
  • 计算效用分数=影响程度×故障概率
  • 制定保留(KEEP)/复审(REVIEW)/移除(REMOVE)决策
  • 计算合规分数(X/10)

Inputs (from Coordinator)

输入(来自协调器)

Receives
contextStore
with Impact/Probability matrices, test file list.
接收包含影响程度/故障概率矩阵、测试文件列表的
contextStore

Workflow

工作流

  1. Parse context
  2. For each test: calculate Usefulness Score
  3. Classify: KEEP (≥15), REVIEW (10-14), REMOVE (<10)
  4. Collect findings
  5. Calculate score
  6. Return JSON
  1. 解析上下文
  2. 为每个测试计算效用分数
  3. 分类:保留(≥15)、复审(10-14)、移除(<10)
  4. 收集审计结果
  5. 计算分数
  6. 返回JSON格式结果

Usefulness Score Calculation

效用分数计算

Formula

公式

Usefulness Score = Business Impact (1-5) × Failure Probability (1-5)
Usefulness Score = Business Impact (1-5) × Failure Probability (1-5)

Impact Scoring (1-5)

影响程度评分(1-5)

ScoreImpactExamples
5CriticalMoney loss, security breach, data corruption
4HighCore flow breaks (checkout, login, registration)
3MediumFeature partially broken, degraded UX
2LowMinor UX issue, cosmetic bug
1TrivialCosmetic issue, no user impact
分数影响程度示例
5关键资金损失、安全漏洞、数据损坏
4核心流程中断(结账、登录、注册)
3功能部分失效、用户体验下降
2轻微用户体验问题、界面瑕疵
1极微界面瑕疵、无用户影响

Probability Scoring (1-5)

故障概率评分(1-5)

ScoreProbabilityIndicators
5Very HighComplex algorithm, new technology, many dependencies
4HighMultiple dependencies, concurrency, edge cases
3MediumStandard CRUD, framework defaults, established patterns
2LowSimple logic, well-established library, trivial operation
1Very LowTrivial assignment, framework-generated, impossible to break
分数概率指标
5极高复杂算法、新技术、多依赖项
4多个依赖项、并发场景、边缘情况
3标准CRUD操作、框架默认配置、成熟模式
2简单逻辑、成熟库、基础操作
1极低基础赋值、框架自动生成、几乎不可能失效

Decision Thresholds

决策阈值

Score RangeDecisionAction
≥15KEEPTest is valuable, maintain it
10-14REVIEWConsider if E2E already covers this
<10REMOVEDelete test, not worth maintenance cost
分数范围决策操作
≥15KEEP(保留)测试具有价值,需维护
10-14REVIEW(复审)检查是否已被端到端(E2E)测试覆盖
<10REMOVE(移除)删除测试,维护成本大于价值

Scoring Examples

评分示例

Example 1: Payment Processing Test

示例1:支付处理测试

Test: "processPayment calculates discount correctly"
Impact: 5 (Critical — money calculation)
Probability: 4 (High — complex algorithm, multiple payment gateways)
Usefulness Score = 5 × 4 = 20
Decision: KEEP
Test: "processPayment calculates discount correctly"
Impact: 5 (Critical — money calculation)
Probability: 4 (High — complex algorithm, multiple payment gateways)
Usefulness Score = 5 × 4 = 20
Decision: KEEP

Example 2: Email Validation Test

示例2:邮箱验证测试

Test: "validateEmail returns true for valid email"
Impact: 2 (Low — minor UX issue if broken)
Probability: 2 (Low — simple regex, well-tested library)
Usefulness Score = 2 × 2 = 4
Decision: REMOVE (likely already covered by E2E registration test)
Test: "validateEmail returns true for valid email"
Impact: 2 (Low — minor UX issue if broken)
Probability: 2 (Low — simple regex, well-tested library)
Usefulness Score = 2 × 2 = 4
Decision: REMOVE (likely already covered by E2E registration test)

Example 3: Login Flow Test

示例3:登录流程测试

Test: "login with valid credentials returns JWT"
Impact: 4 (High — core flow)
Probability: 3 (Medium — standard auth flow)
Usefulness Score = 4 × 3 = 12
Decision: REVIEW (if E2E covers, remove; else keep)
Test: "login with valid credentials returns JWT"
Impact: 4 (High — core flow)
Probability: 3 (Medium — standard auth flow)
Usefulness Score = 4 × 3 = 12
Decision: REVIEW (if E2E covers, remove; else keep)

Audit Rules

审计规则

1. Calculate Score for Each Test

1. 为每个测试计算分数

Process:
  • Read test file, extract test name/description
  • Analyze code under test (CUT)
  • Determine Impact (1-5)
  • Determine Probability (1-5)
  • Calculate Usefulness Score
流程:
  • 读取测试文件,提取测试名称/描述
  • 分析被测代码(CUT)
  • 确定影响程度(1-5)
  • 确定故障概率(1-5)
  • 计算效用分数

2. Classify Decisions

2. 分类决策

KEEP (≥15):
  • High-value tests (money, security, data integrity)
  • Core flows (checkout, login)
  • Complex algorithms
REVIEW (10-14):
  • Medium-value tests
  • Question: "Is this already covered by E2E?"
  • If yes → REMOVE; if no → KEEP
REMOVE (<10):
  • Low-value tests (cosmetic, trivial)
  • Framework/library tests
  • Duplicates of E2E tests
KEEP(保留,≥15):
  • 高价值测试(资金、安全、数据完整性相关)
  • 核心流程(结账、登录)
  • 复杂算法
REVIEW(复审,10-14):
  • 中等价值测试
  • 问题:“是否已被端到端(E2E)测试覆盖?”
  • 若是→移除;若否→保留
REMOVE(移除,<10):
  • 低价值测试(界面瑕疵、基础操作)
  • 框架/库相关测试
  • 端到端(E2E)测试的重复项

3. Identify Patterns

3. 识别低价值测试模式

Common low-value tests (<10):
  • Testing framework behavior
  • Testing trivial getters/setters
  • Testing constant values
  • Testing type annotations
常见低价值测试(<10):
  • 测试框架行为
  • 测试基础getter/setter方法
  • 测试常量值
  • 测试类型注解

Scoring Algorithm

评分算法

See
shared/references/audit_scoring.md
for unified formula and score interpretation.
Severity mapping by Usefulness Score:
  • Score <5 → CRITICAL (test wastes significant maintenance effort)
  • Score 5-9 → HIGH (test likely wasteful)
  • Score 10-14 → MEDIUM (review needed)
  • Score ≥15 → no issue (KEEP)
统一公式和分数解释请参见
shared/references/audit_scoring.md
按效用分数映射严重程度:
  • 分数<5→CRITICAL(严重:测试浪费大量维护精力)
  • 分数5-9→HIGH(高:测试可能无价值)
  • 分数10-14→MEDIUM(中:需要复审)
  • 分数≥15→无问题(保留)

Output Format

输出格式

Return JSON to coordinator:
json
{
  "category": "Risk-Based Value",
  "score": 7,
  "total_issues": 12,
  "critical": 2,
  "high": 5,
  "medium": 5,
  "low": 0,
  "checks": [
    {"id": "usefulness_score", "name": "Usefulness Score Analysis", "status": "warning", "details": "7 tests scored below threshold 15"},
    {"id": "remove_candidates", "name": "Remove Candidates", "status": "failed", "details": "2 tests with Score <10 should be removed"},
    {"id": "review_candidates", "name": "Review Candidates", "status": "warning", "details": "5 tests with Score 10-14 need review"}
  ],
  "findings": [
    {
      "severity": "CRITICAL",
      "location": "utils.test.ts:23-27",
      "issue": "Test 'validateEmail returns true' has Usefulness Score 4 (Impact 2 × Probability 2) — REMOVE",
      "principle": "Risk-Based Value / Low Priority Test",
      "recommendation": "Delete test — likely covered by E2E registration test",
      "effort": "S"
    },
    {
      "severity": "MEDIUM",
      "location": "auth.test.ts:12-25",
      "issue": "Test 'login with valid credentials returns JWT' has Usefulness Score 12 (Impact 4 × Probability 3) — REVIEW",
      "principle": "Risk-Based Value / Borderline Test",
      "recommendation": "If E2E login test exists → delete; otherwise keep",
      "effort": "S"
    }
  ]
}
Note: Tests with Usefulness Score ≥15 (KEEP) are NOT included in findings — only issues are reported.
向协调器返回JSON:
json
{
  "category": "Risk-Based Value",
  "score": 7,
  "total_issues": 12,
  "critical": 2,
  "high": 5,
  "medium": 5,
  "low": 0,
  "checks": [
    {"id": "usefulness_score", "name": "Usefulness Score Analysis", "status": "warning", "details": "7 tests scored below threshold 15"},
    {"id": "remove_candidates", "name": "Remove Candidates", "status": "failed", "details": "2 tests with Score <10 should be removed"},
    {"id": "review_candidates", "name": "Review Candidates", "status": "warning", "details": "5 tests with Score 10-14 need review"}
  ],
  "findings": [
    {
      "severity": "CRITICAL",
      "location": "utils.test.ts:23-27",
      "issue": "Test 'validateEmail returns true' has Usefulness Score 4 (Impact 2 × Probability 2) — REMOVE",
      "principle": "Risk-Based Value / Low Priority Test",
      "recommendation": "Delete test — likely covered by E2E registration test",
      "effort": "S"
    },
    {
      "severity": "MEDIUM",
      "location": "auth.test.ts:12-25",
      "issue": "Test 'login with valid credentials returns JWT' has Usefulness Score 12 (Impact 4 × Probability 3) — REVIEW",
      "principle": "Risk-Based Value / Borderline Test",
      "recommendation": "If E2E login test exists → delete; otherwise keep",
      "effort": "S"
    }
  ]
}
注意: 效用分数≥15的测试(保留)不会包含在结果中——仅报告问题项。

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