test-architect
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTest Architect
测试架构师
Design test strategies, analyze coverage gaps, identify edge cases, diagnose flaky tests, and audit test suite architecture.
Scope: Test design and analysis only. NOT for running tests or CI/CD (devops-engineer), code review (review), or TDD workflow.
设计测试策略、分析覆盖率缺口、识别边缘用例、诊断不稳定测试,并审核测试套件架构。
适用范围: 仅用于测试设计与分析。不适用于执行测试或CI/CD(devops-engineer)、代码评审(review)或TDD工作流。
Dispatch
命令调度
| $ARGUMENTS | Action |
|---|---|
| Design test strategy and pyramid for a feature or module |
| Generate test cases (strategy text or actual test code based on context) |
| Analyze coverage gaps from coverage reports |
| Systematic edge case identification for a function |
| Diagnose flaky tests from logs and code |
| Audit test suite architecture |
| Empty | Show mode menu with examples |
| 参数 | 操作 |
|---|---|
| 为功能/模块设计测试策略和测试金字塔 |
| 生成测试用例(根据上下文生成策略文本或实际测试代码) |
| 从覆盖率报告分析覆盖率缺口 |
| 系统性识别函数的边缘用例 |
| 从日志和代码诊断不稳定测试 |
| 审核测试套件架构 |
| 无参数 | 显示包含示例的模式菜单 |
Canonical Vocabulary
标准术语
Use these terms exactly throughout all modes:
| Term | Definition |
|---|---|
| test pyramid | Layered test distribution: unit (base), integration (middle), e2e (top) |
| coverage gap | Code path with no test coverage, weighted by complexity risk |
| edge case | Input at boundary conditions, null/empty, type coercion, overflow, unicode, concurrent |
| flaky test | Test with non-deterministic pass/fail behavior across identical runs |
| mutation score | Percentage of injected mutations detected by the test suite |
| test strategy | Document defining what to test, how, at what layer, with what tools |
| property-based test | Test asserting invariants over generated inputs (Hypothesis/fast-check) |
| test isolation | Guarantee that tests do not share mutable state or execution order dependencies |
| fixture | Reusable test setup/teardown providing controlled state |
| test surface | Set of public interfaces, code paths, and states requiring test coverage |
所有模式中需严格使用以下术语:
| 术语 | 定义 |
|---|---|
| test pyramid | 分层测试分布:单元测试(底层)、集成测试(中层)、端到端测试(顶层) |
| coverage gap | 无测试覆盖的代码路径,按复杂度风险加权 |
| edge case | 边界条件、空值/空输入、类型转换、溢出、Unicode、并发场景下的输入 |
| flaky test | 在相同运行环境下结果不稳定(时而通过时而失败)的测试 |
| mutation score | 测试套件检测到注入突变的百分比 |
| test strategy | 定义测试对象、测试方式、测试层级及测试工具的文档 |
| property-based test | 针对生成输入断言不变量的测试(Hypothesis/fast-check) |
| test isolation | 确保测试之间不共享可变状态或执行顺序依赖 |
| fixture | 可复用的测试前置/后置操作,提供可控状态 |
| test surface | 需要测试覆盖的公开接口、代码路径和状态集合 |
Mode 1: Design
模式1:设计
/test-architect design <feature/module>/test-architect design <feature/module>Surface Analysis
测试面分析
- Read the feature/module code. Map the test surface: public API, internal paths, state transitions, error conditions.
- Classify complexity: simple (pure functions), moderate (I/O, state), complex (distributed, concurrent, multi-service).
- 阅读功能/模块代码,梳理测试面:公开API、内部路径、状态转换、错误场景。
- 复杂度分类:简单(纯函数)、中等(I/O、状态相关)、复杂(分布式、并发、多服务)。
Pyramid Design
测试金字塔设计
- Design test pyramid:
- Unit layer: Pure logic, transformations, validators. Target: 70-80% of tests.
- Integration layer: Database, API, file I/O, service boundaries. Target: 15-25%.
- E2E layer: Critical user flows only. Target: 5-10%.
- For each layer, list specific test cases with: description, input, expected output, rationale.
- Recommend framework and tooling based on language/ecosystem.
- Output: structured strategy document with pyramid diagram, case list, and priority order.
Reference: read references/test-pyramid.md for layer guidance.
- 设计测试金字塔:
- 单元测试层: 纯逻辑、转换操作、验证器。目标占比:70-80%。
- 集成测试层: 数据库、API、文件I/O、服务边界。目标占比:15-25%。
- 端到端测试层: 仅覆盖关键用户流程。目标占比:5-10%。
- 为每个层级列出具体测试用例,包含:描述、输入、预期输出、设计理由。
- 根据语言/技术栈推荐框架和工具。
- 输出:包含金字塔示意图、用例列表及优先级排序的结构化策略文档。
参考:阅读references/test-pyramid.md获取层级指导。
Mode 2: Generate
模式2:生成
/test-architect generate <file/function>- Read the target file/function. Identify signature, dependencies, side effects.
- Determine output format:
- If test file exists for target: generate actual test code matching existing patterns.
- If no test file exists: generate test strategy text with case descriptions.
- If user specifies : always generate test code.
--code
- Generate test cases covering:
- Happy path (expected inputs and outputs)
- Error path (invalid inputs, exceptions, timeouts)
- Edge cases (run edge-case-generator.py if function has typed parameters)
- Boundary conditions (min/max values, empty collections, null)
- Follow framework conventions: read references/framework-patterns.md for pytest/jest/vitest patterns.
- Output: test cases or test code with clear section headers per category.
/test-architect generate <file/function>- 读取目标文件/函数,识别签名、依赖项、副作用。
- 确定输出格式:
- 若目标已有测试文件:生成匹配现有模式的实际测试代码。
- 若目标无测试文件:生成包含用例描述的测试策略文本。
- 若用户指定:始终生成测试代码。
--code
- 生成覆盖以下场景的测试用例:
- 正常路径(预期输入与输出)
- 错误路径(无效输入、异常、超时)
- 边缘用例(若函数有类型化参数,运行edge-case-generator.py)
- 边界条件(最小/最大值、空集合、空值)
- 遵循框架约定:阅读references/framework-patterns.md获取pytest/jest/vitest模式。
- 输出:按类别划分、带有清晰章节标题的测试用例或测试代码。
Mode 3: Gaps
模式3:覆盖率缺口
/test-architect gaps- Locate coverage reports. Search for:
- ,
coverage.json,coverage.xml(Python/coverage.py).coverage - ,
lcov.info(JS/lcov)coverage/lcov.info - ,
htmlcov/directoriescoverage/
- Run coverage analyzer:
uv run python skills/test-architect/scripts/coverage-analyzer.py <report-path> - Parse JSON output. Rank gaps by complexity-weighted risk.
- For each gap, assess:
- What code is untested and why it matters
- Complexity score (cyclomatic complexity proxy)
- Recommended test type (unit/integration/e2e)
- Priority (P0: security/auth, P1: core logic, P2: utilities, P3: cosmetic)
- Render dashboard if 10+ gaps:
Copy templates/dashboard.html to a temporary file Inject gap data JSON into <script id="data"> tag Open in browser - Output: prioritized gap list with recommended actions.
Reference: read references/coverage-analysis.md for interpretation guidance.
/test-architect gaps- 定位覆盖率报告,搜索以下文件/目录:
- ,
coverage.json,coverage.xml(Python/coverage.py).coverage - ,
lcov.info(JS/lcov)coverage/lcov.info - ,
htmlcov/目录coverage/
- 运行覆盖率分析器:
uv run python skills/test-architect/scripts/coverage-analyzer.py <report-path> - 解析JSON输出,按复杂度加权风险对缺口排序。
- 针对每个缺口评估:
- 未测试的代码内容及其重要性
- 复杂度得分(圈复杂度代理值)
- 推荐测试类型(单元/集成/端到端)
- 优先级(P0:安全/认证,P1:核心逻辑,P2:工具类,P3:界面美化)
- 若缺口数量≥10,生成可视化仪表盘:
将templates/dashboard.html复制到临时文件 将缺口数据JSON注入<script id="data">标签 在浏览器中打开 - 输出:带有推荐操作的优先级缺口列表。
参考:阅读references/coverage-analysis.md获取解读指导。
Mode 4: Edge Cases
模式4:边缘用例
/test-architect edge-cases <function>- Read the function. Extract parameter types, return types, and constraints.
- Run edge case generator:
uv run python skills/test-architect/scripts/edge-case-generator.py --name "<function_name>" --params "<param1:type,param2:type>" - Parse JSON output. Review generated categories:
- Null/empty: None, "", [], {}, 0, False
- Boundary: min/max int, float limits, string length limits
- Type coercion: "123" vs 123, True vs 1, None vs "null"
- Overflow: large numbers, deep nesting, long strings
- Unicode: emoji, RTL text, zero-width chars, combining marks
- Concurrent: race conditions, deadlocks, stale reads
- For each edge case, provide: input value, expected behavior, rationale.
- Flag cases where current code would likely fail (no guard, no validation).
Reference: read references/edge-case-heuristics.md for category details.
/test-architect edge-cases <function>- 读取函数,提取参数类型、返回类型及约束条件。
- 运行边缘用例生成器:
uv run python skills/test-architect/scripts/edge-case-generator.py --name "<function_name>" --params "<param1:type,param2:type>" - 解析JSON输出,审核生成的类别:
- 空值/空输入: None、""、[]、{}、0、False
- 边界值: 整数最小/最大值、浮点数限制、字符串长度限制
- 类型转换: "123" vs 123、True vs 1、None vs "null"
- 溢出: 大数、深层嵌套、长字符串
- Unicode: 表情符号、RTL文本、零宽字符、组合标记
- 并发: 竞态条件、死锁、脏读
- 为每个边缘用例提供:输入值、预期行为、设计理由。
- 标记当前代码可能失败的场景(无防护、无验证)。
参考:阅读references/edge-case-heuristics.md获取类别详情。
Mode 5: Flaky
模式5:不稳定测试诊断
/test-architect flaky/test-architect flakyLog Collection
日志收集
- Locate test result logs. Search for:
- CI logs, pytest output, jest output
- ,
.pytest_cache/test-results/ - Ask user for log path if not found
- Run flaky test analyzer:
uv run python skills/test-architect/scripts/flaky-test-analyzer.py <log-path>
- 定位测试结果日志,搜索以下内容:
- CI日志、pytest输出、jest输出
- ,
.pytest_cache/目录test-results/ - 若未找到,询问用户日志路径
- 运行不稳定测试分析器:
uv run python skills/test-architect/scripts/flaky-test-analyzer.py <log-path>
Root Cause Classification
根因分类
- Parse JSON output. For each flaky test:
- Failure count vs pass count
- Failure pattern (timing, ordering, resource, state)
- Likely root cause classification:
- Timing: sleep/timeout dependencies, race conditions
- Ordering: test execution order dependencies
- Resource: external service, database, file system
- State: shared mutable state between tests
- Environment: platform-specific, timezone, locale
- Recommend fix strategy per root cause.
- Prioritize by failure frequency and blast radius.
Reference: read references/flaky-diagnosis.md for root cause patterns.
- 解析JSON输出,针对每个不稳定测试:
- 失败次数vs通过次数
- 失败模式(时序、执行顺序、资源、状态)
- 可能的根因分类:
- 时序问题: 依赖sleep/超时、竞态条件
- 执行顺序问题: 测试执行顺序依赖
- 资源问题: 外部服务、数据库、文件系统
- 状态问题: 测试间共享可变状态
- 环境问题: 平台特定、时区、区域设置
- 针对每个根因推荐修复策略。
- 按失败频率和影响范围排序优先级。
参考:阅读references/flaky-diagnosis.md获取根因模式。
Mode 6: Review
模式6:架构审核
/test-architect review- Scan the test suite. Map: test file count, framework(s), directory structure.
- Assess architecture dimensions:
- Pyramid balance: ratio of unit:integration:e2e tests
- Isolation: shared state, global fixtures, test ordering dependencies
- Naming: consistency, descriptiveness, convention adherence
- Coverage distribution: even vs clustered coverage
- Fixture health: duplication, complexity, setup/teardown balance
- Assertion quality: specific assertions vs generic assertTrue
- Speed: identify slow tests (>1s unit, >10s integration)
- Determinism: potential flakiness indicators
- Run coverage analyzer if reports exist.
- Cross-reference with source code:
- Untested public APIs
- Tests for deleted/renamed code (orphaned tests)
- Missing negative test cases
- Output: architecture audit report with scores per dimension, findings, and recommendations.
Reference: read references/test-suite-audit.md for scoring criteria.
/test-architect review- 扫描测试套件,梳理:测试文件数量、框架、目录结构。
- 评估架构维度:
- 金字塔平衡: 单元:集成:端到端测试的比例
- 隔离性: 共享状态、全局fixture、测试执行顺序依赖
- 命名规范: 一致性、描述性、约定遵循度
- 覆盖率分布: 均匀覆盖vs集中覆盖
- Fixture健康度: 重复度、复杂度、前置/后置操作平衡
- 断言质量: 特定断言vs通用assertTrue
- 速度: 识别慢测试(单元测试>1s,集成测试>10s)
- 确定性: 潜在不稳定测试指标
- 若存在覆盖率报告,运行覆盖率分析器。
- 与源代码交叉验证:
- 未测试的公开API
- 针对已删除/重命名代码的测试(孤立测试)
- 缺失的负向测试用例
- 输出:包含各维度得分、发现问题及改进建议的架构审核报告。
参考:阅读references/test-suite-audit.md获取评分标准。
Reference Files
参考文件
Load ONE reference at a time. Do not preload all references into context.
| File | Content | Read When |
|---|---|---|
| references/test-pyramid.md | Test pyramid layers, distribution targets, anti-patterns | Mode 1 (Design) |
| references/framework-patterns.md | pytest, jest, vitest patterns and conventions | Mode 2 (Generate), Mode 6 (Review) |
| references/coverage-analysis.md | Coverage report interpretation, complexity weighting | Mode 3 (Gaps) |
| references/edge-case-heuristics.md | Edge case categories by data type, generation strategies | Mode 4 (Edge Cases) |
| references/flaky-diagnosis.md | Flaky test root causes, fix strategies, prevention patterns | Mode 5 (Flaky) |
| references/test-suite-audit.md | Test architecture scoring rubric, quality dimensions | Mode 6 (Review) |
| references/property-testing.md | Property-based testing with Hypothesis and fast-check | Mode 1 (Design), Mode 2 (Generate) |
| references/mutation-testing.md | Mutation testing plan design, tool integration | Mode 1 (Design), Mode 6 (Review) |
| Script | When to Run |
|---|---|
| scripts/coverage-analyzer.py | Mode 3 (Gaps) -- parse coverage reports |
| scripts/edge-case-generator.py | Mode 4 (Edge Cases) -- generate edge cases from function signature |
| scripts/flaky-test-analyzer.py | Mode 5 (Flaky) -- parse test logs for flaky indicators |
| Template | When to Render |
|---|---|
| templates/dashboard.html | Mode 3 (Gaps) with 10+ gaps -- coverage gap visualization |
每次仅加载一个参考文件,不要预加载所有参考文件到上下文。
| 文件 | 内容 | 读取时机 |
|---|---|---|
| references/test-pyramid.md | 测试金字塔层级、分布目标、反模式 | 模式1(设计) |
| references/framework-patterns.md | pytest、jest、vitest模式与约定 | 模式2(生成)、模式6(审核) |
| references/coverage-analysis.md | 覆盖率报告解读、复杂度加权 | 模式3(覆盖率缺口) |
| references/edge-case-heuristics.md | 按数据类型划分的边缘用例类别、生成策略 | 模式4(边缘用例) |
| references/flaky-diagnosis.md | 不稳定测试根因、修复策略、预防模式 | 模式5(不稳定测试诊断) |
| references/test-suite-audit.md | 测试架构评分规则、质量维度 | 模式6(架构审核) |
| references/property-testing.md | 使用Hypothesis和fast-check的属性测试 | 模式1(设计)、模式2(生成) |
| references/mutation-testing.md | 突变测试计划设计、工具集成 | 模式1(设计)、模式6(审核) |
| 脚本 | 运行时机 |
|---|---|
| scripts/coverage-analyzer.py | 模式3(覆盖率缺口)-- 解析覆盖率报告 |
| scripts/edge-case-generator.py | 模式4(边缘用例)-- 根据函数签名生成边缘用例 |
| scripts/flaky-test-analyzer.py | 模式5(不稳定测试诊断)-- 解析测试日志中的不稳定指标 |
| 模板 | 渲染时机 |
|---|---|
| templates/dashboard.html | 模式3(覆盖率缺口)且缺口≥10个时 -- 覆盖率缺口可视化 |
Critical Rules
核心规则
- Never run tests -- design and analyze only. Suggest commands but do not execute.
- Never modify source code -- test architecture is advisory, not implementation.
- Always recommend the correct test layer (unit/integration/e2e) for each test case.
- Edge cases must include rationale -- "why this matters" not just "try this input."
- Coverage gaps must be prioritized by risk, not by line count.
- Flaky test diagnosis must identify root cause category before recommending fixes.
- Framework recommendations must match the project's existing stack.
- Property-based testing is recommended only when invariants are identifiable.
- Load ONE reference file at a time -- do not preload all references.
- Every finding must cite the specific file and function it applies to.
- Test generation must follow existing test patterns in the project when present.
- Dashboard rendering requires 10+ gaps -- do not render for small gap sets.
- 绝不执行测试 -- 仅做设计与分析。可建议命令但不要执行。
- 绝不修改源代码 -- 测试架构仅提供建议,不负责实现。
- 始终为每个测试用例推荐正确的测试层级(单元/集成/端到端)。
- 边缘用例必须包含理由 -- 不仅要说明“尝试此输入”,还要说明“为何重要”。
- 覆盖率缺口必须按风险优先级排序,而非按代码行数。
- 不稳定测试诊断必须先确定根因类别,再推荐修复方案。
- 框架推荐必须匹配项目现有技术栈。
- 仅当可识别不变量时,才推荐属性测试。
- 每次仅加载一个参考文件 -- 不要预加载所有参考文件。
- 每个发现必须注明对应的具体文件和函数。
- 测试生成必须遵循项目中已有的测试模式(若存在)。
- 仅当缺口≥10个时才渲染仪表盘 -- 缺口数量较少时不渲染。