技能覆盖率审核
- 作者仓库星标 3,406
- 作者仓库 claude-octopus
- 领域
- 安全
- 作者声明的智能体
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 88 / 100 · 启发式扫描,不代表运行安全
- 运行环境证据
- 未执行;当前没有隔离运行测试证据
- 作者 / 版本 / 许可证
- @nyldn · 未声明许可证
- 上下文用量评级
- 低消耗
- 接入复杂程度
- 需简单配置
- 是否需要外部接口密钥
- 不需要
- 兼容的系统
- 未声明(默认跨平台)
- 运行环境要求
- 未检出明确要求
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- 命令执行
- 网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
需要注意: 未声明工具权限范围;实际权限由运行环境决定。
确定差异范围。使用最相关的源:仅过滤源代码文件(不包括配置、文档、生成的文件)。
对于每个更改的文件,您必须跟踪: 条件 - 每个 `if/else`、`switch/case`、三元和模式匹配。每个分支都是一个单独的代码路径。错误路径——每个`catch`,`throw`,错误返回,验证失败,以及提前返回错误。为什么:错误路径是未经测试的错误的最常见来源。函数调用——从更改的代码中调用的每个函数。深入跟踪被调用者一层以确定集成边界。
生成结构化清单: 类型类别:`conditional`、`error`、`guard`、`loop-boundary`、`integration`、`async` 风险评估:`high` = 面向用户的故障或数据丢失,`medium` = 降级行为, `low` = 装饰或伐木
对于 diff 中的每个文件,在测试目录中搜索相关测试:
对于每个代码路径,使用以下标题评估现有测试覆盖率: 评级 · 含义 · 标准 ★★★ · 行为 + 测试的边缘情况 · 测试断言行为并涵盖边界条件、错误情况和边缘输入 ★★ · 测试的快乐路径 · 测试覆盖成功路径,但错过错误分支或边缘情况 ★ · 仅冒烟测试 · 测试存在,但仅检查函数运行没有错误(没有有意义的断言)
将每个代码路径映射到其测试覆盖范围:
完成地图后,生成 ASCII 覆盖范围摘要。这是主要的输出工件。按类别细分:覆盖时使用全块,未覆盖时使用浅色。 10 字符栏。始终显示精确的分数和百分比。
在生成任何测试之前,您必须检测项目的测试模式:
> **Host: Codex CLI** — This skill was designed for Claude Code and adapted for Codex.
> Cross-reference commands use installed skill names in Codex rather than `/octo:*` slash commands.
> Use the active Codex shell and subagent tools. Do not claim a provider, model, or host subagent is available until the current session exposes it.
> For host tool equivalents, see `skills/blocks/codex-host-adapter.md`.
# Test Coverage Audit
## Overview
Trace every codepath in a diff, map each path against existing tests, visualize coverage gaps, and auto-generate tests for uncovered paths.
**Core principle:** Trace codepaths in changed files -> Map against existing tests -> Score coverage quality -> Generate tests for gaps -> Report before/after counts.
## Caps and Limits
These hard limits prevent runaway analysis:
- **30 code paths max** per audit. If a diff yields more than 30, prioritize by complexity and risk (error paths, security-sensitive branches, public API surfaces first).
- **20 tests generated max** per audit. Focus on highest-impact gaps first.
- **2-minute per-test exploration cap.** If understanding a single test path takes longer than 2 minutes, mark it as "needs manual review" and move on.
## Phase 1: Codepath Tracing
### Step 1: Identify Changed Files
Determine the diff scope. Use the most relevant source:
```bash
# PR diff
git diff --name-only main...HEAD
# Staged changes
git diff --name-only --cached
# Last commit
git diff --name-only HEAD~1..HEAD
```
Filter to source code files only (exclude configs, docs, generated files).
### Step 2: Trace Data Flow Through Every Branch
For each changed file, you MUST trace:
1. **Conditionals** -- Every `if/else`, `switch/case`, ternary, and pattern match. Each branch is a separate codepath.
2. **Error paths** -- Every `catch`, `throw`, error return, validation failure, and early return with error. WHY: Error paths are the most common source of untested bugs.
3. **Function calls** -- Every function invoked from changed code. Trace one level deep into callees to identify integration boundaries.
4. **Loop boundaries** -- Empty collection, single item, and multi-item paths through loops.
5. **Guard clauses** -- Every early return, null check, and permission gate.
### Step 3: Build the Codepath Inventory
Produce a structured inventory:
```markdown
## Codepath Inventory: [filename]
| # | Path Description | Type | Risk |
|---|-----------------|------|------|
| 1 | validateUser() happy path | conditional | low |
| 2 | validateUser() missing email | error | medium |
| 3 | validateUser() invalid format | error | medium |
| 4 | processOrder() empty cart guard | guard | high |
| 5 | processOrder() payment timeout | error | high |
| 6 | processOrder() success | conditional | low |
```
**Type categories:** `conditional`, `error`, `guard`, `loop-boundary`, `integration`, `async`
**Risk assessment:** `high` = user-facing failure or data loss, `medium` = degraded behavior, `low` = cosmetic or logging
## Phase 2: Test Mapping and Quality Scoring
### Step 1: Search for Existing Tests
For each file in the diff, search the test directory for related tests:
```bash
# Find test files that reference the changed file or its exports
# Search by filename pattern
find tests/ -name "*[changed_file_stem]*" -type f
# Search by import/require of the changed module
grep -rl "import.*from.*[module_name]" tests/
grep -rl "require.*[module_name]" tests/
# Search by function name references
grep -rl "[function_name]" tests/
```
### Step 2: Score Test Quality
For each codepath, assess existing test coverage with this rubric:
| Rating | Meaning | Criteria |
|--------|---------|----------|
| ★★★ | Behavior + edge cases tested | Tests assert behavior AND cover boundary conditions, error cases, and edge inputs |
| ★★ | Happy path tested | Tests cover the success path but miss error branches or edge cases |
| ★ | Smoke test only | Test exists but only checks the function runs without error (no meaningful assertions) |
| ☆ | No test found | No test references this codepath at all |
### Step 3: Produce Coverage Map
Map each codepath to its test coverage:
```markdown
## Coverage Map: [filename]
| # | Codepath | Test File | Rating | Notes |
|---|----------|-----------|--------|-------|
| 1 | validateUser() happy path | test-user.sh:42 | ★★★ | Asserts valid + invalid inputs |
| 2 | validateUser() missing email | test-user.sh:58 | ★★ | Tests missing, not malformed |
| 3 | validateUser() invalid format | -- | ☆ | No test for format validation |
| 4 | processOrder() empty cart guard | -- | ☆ | Guard clause untested |
| 5 | processOrder() payment timeout | test-orders.sh:30 | ★ | Checks no crash, no assertions |
| 6 | processOrder() success | test-orders.sh:15 | ★★★ | Full integration test |
```
## Phase 3: Coverage Diagram
After completing the map, produce an ASCII coverage summary. This is the primary output artifact.
```
COVERAGE: 5/12 paths tested (42%)
Code paths: 3/5 (60%)
User flows: 2/7 (29%)
GAPS: 7 paths need tests
```
Break down by category:
```
BY TYPE:
conditional: 3/4 tested (75%) ████████░░
error: 1/5 tested (20%) ██░░░░░░░░
guard: 0/2 tested (0%) ░░░░░░░░░░
integration: 1/1 tested (100%) ██████████
BY RISK:
high: 1/3 tested (33%) ███░░░░░░░
medium: 2/5 tested (40%) ████░░░░░░
low: 2/4 tested (50%) █████░░░░░
```
Use full block for covered and light shade for uncovered. 10-character bar. Always show exact fractions and percentages.
## Phase 4: Auto-Generate Tests
### Step 1: Detect Project Test Conventions
Before generating any tests, you MUST detect the project's testing patterns:
```markdown
**Detected Test Conventions:**
- Framework: [jest/vitest/pytest/bash/go test/etc.]
- Location: [tests/ | __tests__/ | src/**/*.test.* | etc.]
- Naming: [test-*.sh | *.test.ts | *_test.go | etc.]
- Style: [BDD describe/it | xUnit | TAP | custom]
- Helpers: [test-utils.ts | conftest.py | helpers/ | etc.]
- Assertion library: [built-in | chai | assert | etc.]
```
### Step 2: Generate Tests for Uncovered Paths
For each no-test and smoke-only codepath, generate a test that:
1. **Follows project naming conventions** -- same directory structure, same file naming pattern
2. **Uses existing test helpers** -- import from the same test utilities the project already uses
3. **Tests behavior, not implementation** -- assert observable outcomes, not internal state
4. **Covers the specific gap** -- targets the exact branch or error path identified in Phase 1
5. **Includes edge cases** -- aim for full coverage on each generated test
### Step 3: Present Generated Tests
For each generated test, show:
```markdown
### Generated: test for [codepath description]
**Covers:** Codepath #N from [filename]
**Raises coverage:** from no-test to full coverage
[test code block]
```
### Step 4: Report Before/After
After generating all tests, show the coverage change:
```
BEFORE: 5/12 paths tested (42%)
AFTER: 11/12 paths tested (92%)
New tests generated: 6
Remaining gaps: 1 (manual review needed)
```
## Integration with Other Skills
### With flow-deliver / skill-code-review
Coverage audit runs as a complement to code review. When invoked during deliver phase:
1. Code review assesses quality and correctness
2. Coverage audit assesses test completeness
3. Both feed into the ship/no-ship decision
### With skill-tdd
If coverage audit finds gaps in new code, recommend the user adopt TDD for the next iteration. Coverage audit fixes existing gaps; TDD prevents future ones.
### With skill-verification-gate
After generating tests, use skill-verification-gate to run the test suite and confirm the new tests pass.
## Red Flags -- Do Not Do This
| Action | Why It Is Wrong |
|--------|-----------------|
| Count lines instead of paths | Line coverage misses branch coverage entirely |
| Generate tests without checking conventions | Tests that do not match project style will be rejected |
| Test implementation details | Brittle tests that break on refactoring |
| Skip error paths | Error paths are where most bugs live |
| Exceed the 30-path cap | Analysis becomes unfocused and slow |
| Generate more than 20 tests | Diminishing returns; focus on highest impact |
| Spend more than 2 min on one path | Mark as needs-manual-review and move on |
## Quick Reference
```
1. TRACE -> Identify all codepaths in the diff (max 30)
2. MAP -> Find existing tests for each path
3. SCORE -> Rate coverage quality (no-test / smoke / happy-path / full)
4. DIAGRAM -> ASCII coverage visualization
5. GENERATE -> Auto-create tests for gaps (max 20)
6. REPORT -> Before/after test counts
```
按说明文件中的顺序排列。
概述
上限和限制
第 1 步:识别已更改的文件
第 2 步:跟踪每个分支的数据流
第 3 步:构建代码路径清单
文件/命令 -> /octo:* · skills/blocks/codex-host-adapter.md · if/else · switch/case · catch · throw · conditional · error
内容校验值 -> 3c68cd0a33db
当前原文的自动摘译,尚未人工审校。
概述
跟踪差异中的每个代码路径,根据现有测试映射每个路径,可视化覆盖间隙,并自动生成未覆盖路径的测试。核心原则:跟踪更改文件中的代码路径 -> 根据现有测试进行映射 -> 对覆盖质量进行评分 -> 生成差距测试 -> 报告之前/之后的计数。
上限和限制
这些硬限制可防止失控分析:每次审核最多 30 个代码路径。如果差异产生超过 30 个,请按复杂性和风险确定优先级(错误路径、安全敏感分支、公共 API 表面优先)。每次审核最多生成 20 个测试。首先关注影响最大的差距。每次测试探索时间上限为 2 分钟。如果理解单个测试路径需要超过 2 分钟,请将其标记为“需要手动审核”并继续。
第 3 步:构建代码路径清单
生成结构化清单: 类型类别:
conditional、error、guard、loop-boundary、integration、async风险评估:high= 面向用户的故障或数据丢失、medium= 降级行为、low= 装饰性或记录