mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-28 09:23:08 +08:00
Refactor code structure for improved readability and maintainability
This commit is contained in:
427
.claude/skills/team-quality-assurance/SKILL.md
Normal file
427
.claude/skills/team-quality-assurance/SKILL.md
Normal file
@@ -0,0 +1,427 @@
|
||||
---
|
||||
name: team-quality-assurance
|
||||
description: Unified team skill for quality assurance team. All roles invoke this skill with --role arg for role-specific execution. Triggers on "team quality-assurance", "team qa".
|
||||
allowed-tools: TeamCreate(*), TeamDelete(*), SendMessage(*), TaskCreate(*), TaskUpdate(*), TaskList(*), TaskGet(*), Task(*), AskUserQuestion(*), Read(*), Write(*), Edit(*), Bash(*), Glob(*), Grep(*)
|
||||
---
|
||||
|
||||
# Team Quality Assurance
|
||||
|
||||
质量保障团队技能。融合"问题发现"和"软件测试"两大能力域,形成"发现→策略→测试→分析"闭环。通过 Scout 多视角扫描、Generator-Executor 循环、共享缺陷模式数据库,实现渐进式质量保障。所有成员通过 `--role=xxx` 路由到角色执行逻辑。
|
||||
|
||||
## Architecture Overview
|
||||
|
||||
```
|
||||
┌──────────────────────────────────────────────────────────┐
|
||||
│ Skill(skill="team-quality-assurance", args="--role=xxx") │
|
||||
└────────────────────────┬─────────────────────────────────┘
|
||||
│ Role Router
|
||||
┌────────┬───────────┼───────────┬──────────┬──────────┐
|
||||
↓ ↓ ↓ ↓ ↓ ↓
|
||||
┌────────┐┌───────┐┌──────────┐┌─────────┐┌────────┐┌────────┐
|
||||
│coordi- ││scout ││strategist││generator││executor││analyst │
|
||||
│nator ││SCOUT-*││QASTRAT-* ││QAGEN-* ││QARUN-* ││QAANA-* │
|
||||
│ roles/ ││ roles/││ roles/ ││ roles/ ││ roles/ ││ roles/ │
|
||||
└────────┘└───────┘└──────────┘└─────────┘└────────┘└────────┘
|
||||
```
|
||||
|
||||
## Command Architecture
|
||||
|
||||
```
|
||||
roles/
|
||||
├── coordinator/
|
||||
│ ├── role.md # Pipeline 编排(模式选择、任务分发、监控)
|
||||
│ └── commands/
|
||||
│ ├── dispatch.md # 任务链创建
|
||||
│ └── monitor.md # 进度监控
|
||||
├── scout/
|
||||
│ ├── role.md # 多视角问题扫描
|
||||
│ └── commands/
|
||||
│ └── scan.md # 多视角 CLI Fan-out 扫描
|
||||
├── strategist/
|
||||
│ ├── role.md # 测试策略制定
|
||||
│ └── commands/
|
||||
│ └── analyze-scope.md # 变更范围分析
|
||||
├── generator/
|
||||
│ ├── role.md # 测试用例生成
|
||||
│ └── commands/
|
||||
│ └── generate-tests.md # 按层级生成测试代码
|
||||
├── executor/
|
||||
│ ├── role.md # 测试执行与修复
|
||||
│ └── commands/
|
||||
│ └── run-fix-cycle.md # 迭代测试修复循环
|
||||
└── analyst/
|
||||
├── role.md # 质量分析报告
|
||||
└── commands/
|
||||
└── quality-report.md # 缺陷模式 + 覆盖率分析
|
||||
```
|
||||
|
||||
**设计原则**: role.md 保留 Phase 1(Task Discovery)和 Phase 5(Report)内联。Phase 2-4 根据复杂度决定内联或委派到 `commands/*.md`。
|
||||
|
||||
## Role Router
|
||||
|
||||
### Input Parsing
|
||||
|
||||
Parse `$ARGUMENTS` to extract `--role`:
|
||||
|
||||
```javascript
|
||||
const args = "$ARGUMENTS"
|
||||
const roleMatch = args.match(/--role[=\s]+(\w+)/)
|
||||
|
||||
if (!roleMatch) {
|
||||
throw new Error("Missing --role argument. Available roles: coordinator, scout, strategist, generator, executor, analyst")
|
||||
}
|
||||
|
||||
const role = roleMatch[1]
|
||||
const teamName = args.match(/--team[=\s]+([\w-]+)/)?.[1] || "quality-assurance"
|
||||
```
|
||||
|
||||
### Role Dispatch
|
||||
|
||||
```javascript
|
||||
const VALID_ROLES = {
|
||||
"coordinator": { file: "roles/coordinator/role.md", prefix: null },
|
||||
"scout": { file: "roles/scout/role.md", prefix: "SCOUT" },
|
||||
"strategist": { file: "roles/strategist/role.md", prefix: "QASTRAT" },
|
||||
"generator": { file: "roles/generator/role.md", prefix: "QAGEN" },
|
||||
"executor": { file: "roles/executor/role.md", prefix: "QARUN" },
|
||||
"analyst": { file: "roles/analyst/role.md", prefix: "QAANA" }
|
||||
}
|
||||
|
||||
if (!VALID_ROLES[role]) {
|
||||
throw new Error(`Unknown role: ${role}. Available: ${Object.keys(VALID_ROLES).join(', ')}`)
|
||||
}
|
||||
|
||||
// Read and execute role-specific logic
|
||||
Read(VALID_ROLES[role].file)
|
||||
// → Execute the 5-phase process defined in that file
|
||||
```
|
||||
|
||||
### Available Roles
|
||||
|
||||
| Role | Task Prefix | Responsibility | Role File |
|
||||
|------|-------------|----------------|-----------|
|
||||
| `coordinator` | N/A | QA pipeline 编排、模式选择、质量门控 | [roles/coordinator/role.md](roles/coordinator/role.md) |
|
||||
| `scout` | SCOUT-* | 多视角问题扫描、主动发现潜在缺陷 | [roles/scout/role.md](roles/scout/role.md) |
|
||||
| `strategist` | QASTRAT-* | 变更范围分析、测试层级选择、覆盖率目标 | [roles/strategist/role.md](roles/strategist/role.md) |
|
||||
| `generator` | QAGEN-* | 按层级生成测试用例(unit/integration/E2E) | [roles/generator/role.md](roles/generator/role.md) |
|
||||
| `executor` | QARUN-* | 执行测试、收集覆盖率、自动修复循环 | [roles/executor/role.md](roles/executor/role.md) |
|
||||
| `analyst` | QAANA-* | 缺陷模式分析、覆盖率差距、质量报告 | [roles/analyst/role.md](roles/analyst/role.md) |
|
||||
|
||||
## Shared Infrastructure
|
||||
|
||||
### Role Isolation Rules
|
||||
|
||||
**核心原则**: 每个角色仅能执行自己职责范围内的工作。
|
||||
|
||||
#### Output Tagging(强制)
|
||||
|
||||
所有角色的输出必须带 `[role_name]` 标识前缀:
|
||||
|
||||
```javascript
|
||||
SendMessage({ content: `## [${role}] ...`, summary: `[${role}] ...` })
|
||||
mcp__ccw-tools__team_msg({ summary: `[${role}] ...` })
|
||||
```
|
||||
|
||||
#### Coordinator 隔离
|
||||
|
||||
| 允许 | 禁止 |
|
||||
|------|------|
|
||||
| 需求澄清 (AskUserQuestion) | ❌ 直接编写测试 |
|
||||
| 创建任务链 (TaskCreate) | ❌ 直接执行测试或扫描 |
|
||||
| 模式选择 + 质量门控 | ❌ 直接分析覆盖率 |
|
||||
| 监控进度 (消息总线) | ❌ 绕过 worker 自行完成 |
|
||||
|
||||
#### Worker 隔离
|
||||
|
||||
| 允许 | 禁止 |
|
||||
|------|------|
|
||||
| 处理自己前缀的任务 | ❌ 处理其他角色前缀的任务 |
|
||||
| 读写 shared-memory.json (自己的字段) | ❌ 为其他角色创建任务 |
|
||||
| SendMessage 给 coordinator | ❌ 直接与其他 worker 通信 |
|
||||
|
||||
### Team Configuration
|
||||
|
||||
```javascript
|
||||
const TEAM_CONFIG = {
|
||||
name: "quality-assurance",
|
||||
sessionDir: ".workflow/.team/QA-{slug}-{date}/",
|
||||
msgDir: ".workflow/.team-msg/quality-assurance/",
|
||||
sharedMemory: "shared-memory.json",
|
||||
testLayers: {
|
||||
L1: { name: "Unit Tests", coverage_target: 80 },
|
||||
L2: { name: "Integration Tests", coverage_target: 60 },
|
||||
L3: { name: "E2E Tests", coverage_target: 40 }
|
||||
},
|
||||
scanPerspectives: ["bug", "security", "ux", "test-coverage", "code-quality"]
|
||||
}
|
||||
```
|
||||
|
||||
### Shared Memory(核心创新)
|
||||
|
||||
```javascript
|
||||
// 各角色读取共享记忆
|
||||
const memoryPath = `${sessionFolder}/shared-memory.json`
|
||||
let sharedMemory = {}
|
||||
try { sharedMemory = JSON.parse(Read(memoryPath)) } catch {}
|
||||
|
||||
// 各角色写入自己负责的字段:
|
||||
// scout → sharedMemory.discovered_issues
|
||||
// strategist → sharedMemory.test_strategy
|
||||
// generator → sharedMemory.generated_tests
|
||||
// executor → sharedMemory.execution_results
|
||||
// analyst → sharedMemory.defect_patterns + quality_score + coverage_history
|
||||
Write(memoryPath, JSON.stringify(sharedMemory, null, 2))
|
||||
```
|
||||
|
||||
### Message Bus (All Roles)
|
||||
|
||||
```javascript
|
||||
mcp__ccw-tools__team_msg({
|
||||
operation: "log",
|
||||
team: teamName,
|
||||
from: role,
|
||||
to: "coordinator",
|
||||
type: "<type>",
|
||||
summary: `[${role}] <summary>`,
|
||||
ref: "<file_path>"
|
||||
})
|
||||
```
|
||||
|
||||
| Role | Types |
|
||||
|------|-------|
|
||||
| coordinator | `mode_selected`, `gc_loop_trigger`, `quality_gate`, `task_unblocked`, `error`, `shutdown` |
|
||||
| scout | `scan_ready`, `issues_found`, `error` |
|
||||
| strategist | `strategy_ready`, `error` |
|
||||
| generator | `tests_generated`, `tests_revised`, `error` |
|
||||
| executor | `tests_passed`, `tests_failed`, `coverage_report`, `error` |
|
||||
| analyst | `analysis_ready`, `quality_report`, `error` |
|
||||
|
||||
### CLI 回退
|
||||
|
||||
```javascript
|
||||
Bash(`ccw team log --team "${teamName}" --from "${role}" --to "coordinator" --type "<type>" --summary "<摘要>" --json`)
|
||||
```
|
||||
|
||||
### Task Lifecycle (All Worker Roles)
|
||||
|
||||
```javascript
|
||||
const tasks = TaskList()
|
||||
const myTasks = tasks.filter(t =>
|
||||
t.subject.startsWith(`${VALID_ROLES[role].prefix}-`) &&
|
||||
t.owner === role &&
|
||||
t.status === 'pending' &&
|
||||
t.blockedBy.length === 0
|
||||
)
|
||||
if (myTasks.length === 0) return
|
||||
const task = TaskGet({ taskId: myTasks[0].id })
|
||||
TaskUpdate({ taskId: task.id, status: 'in_progress' })
|
||||
|
||||
// Phase 2-4: Role-specific
|
||||
// Phase 5: Report + Loop
|
||||
mcp__ccw-tools__team_msg({ operation: "log", team: teamName, from: role, to: "coordinator", type: "...", summary: `[${role}] ...` })
|
||||
SendMessage({ type: "message", recipient: "coordinator", content: `## [${role}] ...`, summary: `[${role}] ...` })
|
||||
TaskUpdate({ taskId: task.id, status: 'completed' })
|
||||
```
|
||||
|
||||
## Three-Mode Pipeline Architecture
|
||||
|
||||
```
|
||||
Discovery Mode (问题发现优先):
|
||||
SCOUT-001(多视角扫描) → QASTRAT-001 → QAGEN-001 → QARUN-001 → QAANA-001
|
||||
|
||||
Testing Mode (测试优先,跳过 scout):
|
||||
QASTRAT-001(变更分析) → QAGEN-001(L1) → QARUN-001(L1) → QAGEN-002(L2) → QARUN-002(L2) → QAANA-001
|
||||
|
||||
Full QA Mode (完整闭环):
|
||||
SCOUT-001(扫描) → QASTRAT-001(策略) → [QAGEN-001(L1) + QAGEN-002(L2)](parallel) → [QARUN-001 + QARUN-002](parallel) → QAANA-001(分析) → SCOUT-002(回归扫描)
|
||||
```
|
||||
|
||||
### Mode Auto-Detection
|
||||
|
||||
```javascript
|
||||
function detectQAMode(args, taskDescription) {
|
||||
if (/--mode[=\s]+(discovery|testing|full)/.test(args)) {
|
||||
return args.match(/--mode[=\s]+(\w+)/)[1]
|
||||
}
|
||||
// 自动检测
|
||||
if (/发现|扫描|scan|discover|issue|问题/.test(taskDescription)) return 'discovery'
|
||||
if (/测试|test|覆盖|coverage|TDD/.test(taskDescription)) return 'testing'
|
||||
return 'full'
|
||||
}
|
||||
```
|
||||
|
||||
### Generator-Executor Loop (GC 循环)
|
||||
|
||||
```
|
||||
QAGEN → QARUN → (if coverage < target) → QAGEN-fix → QARUN-2
|
||||
(if coverage >= target) → next layer or QAANA
|
||||
```
|
||||
|
||||
## Unified Session Directory
|
||||
|
||||
```
|
||||
.workflow/.team/QA-{slug}-{YYYY-MM-DD}/
|
||||
├── team-session.json
|
||||
├── shared-memory.json # 发现的问题 / 测试策略 / 缺陷模式 / 覆盖率历史
|
||||
├── scan/ # Scout output
|
||||
│ └── scan-results.json
|
||||
├── strategy/ # Strategist output
|
||||
│ └── test-strategy.md
|
||||
├── tests/ # Generator output
|
||||
│ ├── L1-unit/
|
||||
│ ├── L2-integration/
|
||||
│ └── L3-e2e/
|
||||
├── results/ # Executor output
|
||||
│ ├── run-001.json
|
||||
│ └── coverage-001.json
|
||||
└── analysis/ # Analyst output
|
||||
└── quality-report.md
|
||||
```
|
||||
|
||||
## Coordinator Spawn Template
|
||||
|
||||
```javascript
|
||||
TeamCreate({ team_name: teamName })
|
||||
|
||||
// Scout
|
||||
Task({
|
||||
subagent_type: "general-purpose",
|
||||
team_name: teamName,
|
||||
name: "scout",
|
||||
prompt: `你是 team "${teamName}" 的 SCOUT。
|
||||
|
||||
当你收到 SCOUT-* 任务时,调用 Skill(skill="team-quality-assurance", args="--role=scout") 执行。
|
||||
|
||||
当前需求: ${taskDescription}
|
||||
约束: ${constraints}
|
||||
|
||||
## 角色准则(强制)
|
||||
- 你只能处理 SCOUT-* 前缀的任务,不得执行其他角色的工作
|
||||
- 所有输出(SendMessage、team_msg)必须带 [scout] 标识前缀
|
||||
- 仅与 coordinator 通信,不得直接联系其他 worker
|
||||
- 不得使用 TaskCreate 为其他角色创建任务
|
||||
|
||||
## 消息总线(必须)
|
||||
每次 SendMessage 前,先调用 mcp__ccw-tools__team_msg 记录。
|
||||
|
||||
工作流程:
|
||||
1. TaskList → 找到 SCOUT-* 任务
|
||||
2. Skill(skill="team-quality-assurance", args="--role=scout") 执行
|
||||
3. team_msg log + SendMessage 结果给 coordinator(带 [scout] 标识)
|
||||
4. TaskUpdate completed → 检查下一个任务`
|
||||
})
|
||||
|
||||
// Strategist
|
||||
Task({
|
||||
subagent_type: "general-purpose",
|
||||
team_name: teamName,
|
||||
name: "strategist",
|
||||
prompt: `你是 team "${teamName}" 的 STRATEGIST。
|
||||
|
||||
当你收到 QASTRAT-* 任务时,调用 Skill(skill="team-quality-assurance", args="--role=strategist") 执行。
|
||||
|
||||
当前需求: ${taskDescription}
|
||||
约束: ${constraints}
|
||||
|
||||
## 角色准则(强制)
|
||||
- 你只能处理 QASTRAT-* 前缀的任务
|
||||
- 所有输出必须带 [strategist] 标识前缀
|
||||
- 仅与 coordinator 通信
|
||||
|
||||
## 消息总线(必须)
|
||||
每次 SendMessage 前,先调用 mcp__ccw-tools__team_msg 记录。
|
||||
|
||||
工作流程:
|
||||
1. TaskList → 找到 QASTRAT-* 任务
|
||||
2. Skill(skill="team-quality-assurance", args="--role=strategist") 执行
|
||||
3. team_msg log + SendMessage 结果给 coordinator
|
||||
4. TaskUpdate completed → 检查下一个任务`
|
||||
})
|
||||
|
||||
// Generator
|
||||
Task({
|
||||
subagent_type: "general-purpose",
|
||||
team_name: teamName,
|
||||
name: "generator",
|
||||
prompt: `你是 team "${teamName}" 的 GENERATOR。
|
||||
|
||||
当你收到 QAGEN-* 任务时,调用 Skill(skill="team-quality-assurance", args="--role=generator") 执行。
|
||||
|
||||
当前需求: ${taskDescription}
|
||||
|
||||
## 角色准则(强制)
|
||||
- 你只能处理 QAGEN-* 前缀的任务
|
||||
- 所有输出必须带 [generator] 标识前缀
|
||||
|
||||
## 消息总线(必须)
|
||||
每次 SendMessage 前,先调用 mcp__ccw-tools__team_msg 记录。
|
||||
|
||||
工作流程:
|
||||
1. TaskList → 找到 QAGEN-* 任务
|
||||
2. Skill(skill="team-quality-assurance", args="--role=generator") 执行
|
||||
3. team_msg log + SendMessage
|
||||
4. TaskUpdate completed → 检查下一个任务`
|
||||
})
|
||||
|
||||
// Executor
|
||||
Task({
|
||||
subagent_type: "general-purpose",
|
||||
team_name: teamName,
|
||||
name: "executor",
|
||||
prompt: `你是 team "${teamName}" 的 EXECUTOR。
|
||||
|
||||
当你收到 QARUN-* 任务时,调用 Skill(skill="team-quality-assurance", args="--role=executor") 执行。
|
||||
|
||||
当前需求: ${taskDescription}
|
||||
|
||||
## 角色准则(强制)
|
||||
- 你只能处理 QARUN-* 前缀的任务
|
||||
- 所有输出必须带 [executor] 标识前缀
|
||||
|
||||
## 消息总线(必须)
|
||||
每次 SendMessage 前,先调用 mcp__ccw-tools__team_msg 记录。
|
||||
|
||||
工作流程:
|
||||
1. TaskList → 找到 QARUN-* 任务
|
||||
2. Skill(skill="team-quality-assurance", args="--role=executor") 执行
|
||||
3. team_msg log + SendMessage
|
||||
4. TaskUpdate completed → 检查下一个任务`
|
||||
})
|
||||
|
||||
// Analyst
|
||||
Task({
|
||||
subagent_type: "general-purpose",
|
||||
team_name: teamName,
|
||||
name: "analyst",
|
||||
prompt: `你是 team "${teamName}" 的 ANALYST。
|
||||
|
||||
当你收到 QAANA-* 任务时,调用 Skill(skill="team-quality-assurance", args="--role=analyst") 执行。
|
||||
|
||||
当前需求: ${taskDescription}
|
||||
|
||||
## 角色准则(强制)
|
||||
- 你只能处理 QAANA-* 前缀的任务
|
||||
- 所有输出必须带 [analyst] 标识前缀
|
||||
|
||||
## 消息总线(必须)
|
||||
每次 SendMessage 前,先调用 mcp__ccw-tools__team_msg 记录。
|
||||
|
||||
工作流程:
|
||||
1. TaskList → 找到 QAANA-* 任务
|
||||
2. Skill(skill="team-quality-assurance", args="--role=analyst") 执行
|
||||
3. team_msg log + SendMessage
|
||||
4. TaskUpdate completed → 检查下一个任务`
|
||||
})
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Scenario | Resolution |
|
||||
|----------|------------|
|
||||
| Unknown --role value | Error with available role list |
|
||||
| Missing --role arg | Error with usage hint |
|
||||
| Role file not found | Error with expected path (roles/{name}/role.md) |
|
||||
| Task prefix conflict | Log warning, proceed |
|
||||
| Coverage never reaches target | After 3 GC loops, accept current with warning |
|
||||
| Scout finds no issues | Report clean scan, skip to testing mode |
|
||||
| Test environment broken | Notify user, suggest manual fix |
|
||||
@@ -0,0 +1,360 @@
|
||||
# Command: quality-report
|
||||
|
||||
> 缺陷模式分析 + 覆盖率分析 + 综合质量报告。多维度分析 QA 数据,生成质量评分和改进建议。
|
||||
|
||||
## When to Use
|
||||
|
||||
- Phase 3 of Analyst
|
||||
- 测试执行完成,需要分析结果
|
||||
- 需要识别缺陷模式和覆盖率趋势
|
||||
|
||||
**Trigger conditions**:
|
||||
- QAANA-* 任务进入执行阶段
|
||||
- 所有 QARUN 任务已完成
|
||||
- Coordinator 请求质量报告
|
||||
|
||||
## Strategy
|
||||
|
||||
### Delegation Mode
|
||||
|
||||
**Mode**: CLI Fan-out(深度分析)/ Direct(基础分析)
|
||||
**CLI Tool**: `gemini` (primary)
|
||||
**CLI Mode**: `analysis`
|
||||
|
||||
### Decision Logic
|
||||
|
||||
```javascript
|
||||
const dataPoints = discoveredIssues.length + Object.keys(executionResults).length
|
||||
if (dataPoints <= 5) {
|
||||
// 基础内联分析
|
||||
mode = 'direct'
|
||||
} else {
|
||||
// CLI 辅助深度分析
|
||||
mode = 'cli-assisted'
|
||||
}
|
||||
```
|
||||
|
||||
## Execution Steps
|
||||
|
||||
### Step 1: Context Preparation
|
||||
|
||||
```javascript
|
||||
// 从 shared memory 加载所有 QA 数据
|
||||
const discoveredIssues = sharedMemory.discovered_issues || []
|
||||
const strategy = sharedMemory.test_strategy || {}
|
||||
const generatedTests = sharedMemory.generated_tests || {}
|
||||
const executionResults = sharedMemory.execution_results || {}
|
||||
const historicalPatterns = sharedMemory.defect_patterns || []
|
||||
const coverageHistory = sharedMemory.coverage_history || []
|
||||
|
||||
// 读取覆盖率详细数据
|
||||
let coverageData = null
|
||||
try {
|
||||
coverageData = JSON.parse(Read('coverage/coverage-summary.json'))
|
||||
} catch {}
|
||||
|
||||
// 读取各层级执行结果
|
||||
const layerResults = {}
|
||||
try {
|
||||
const resultFiles = Glob(`${sessionFolder}/results/run-*.json`)
|
||||
for (const f of resultFiles) {
|
||||
const data = JSON.parse(Read(f))
|
||||
layerResults[data.layer] = data
|
||||
}
|
||||
} catch {}
|
||||
```
|
||||
|
||||
### Step 2: Execute Strategy
|
||||
|
||||
```javascript
|
||||
if (mode === 'direct') {
|
||||
// 基础内联分析
|
||||
analysis = performDirectAnalysis()
|
||||
} else {
|
||||
// CLI 辅助深度分析
|
||||
const analysisContext = JSON.stringify({
|
||||
issues: discoveredIssues.slice(0, 20),
|
||||
execution: layerResults,
|
||||
coverage: coverageData?.total || {},
|
||||
strategy: { layers: strategy.layers?.map(l => ({ level: l.level, target: l.target_coverage })) }
|
||||
}, null, 2)
|
||||
|
||||
Bash(`ccw cli -p "PURPOSE: Perform deep quality analysis on QA results to identify defect patterns, coverage trends, and improvement opportunities
|
||||
TASK: • Classify defects by root cause pattern (logic errors, integration issues, missing validation, etc.) • Identify files with highest defect density • Analyze coverage gaps vs risk levels • Compare actual coverage to targets • Generate actionable improvement recommendations
|
||||
MODE: analysis
|
||||
CONTEXT: @${sessionFolder}/shared-memory.json @${sessionFolder}/results/**/*
|
||||
EXPECTED: Structured analysis with: defect pattern taxonomy, risk-coverage matrix, quality score rationale, top 5 improvement recommendations with expected impact
|
||||
CONSTRAINTS: Be data-driven, avoid speculation without evidence" --tool gemini --mode analysis --rule analysis-analyze-code-patterns`, {
|
||||
run_in_background: true
|
||||
})
|
||||
// 等待 CLI 完成
|
||||
}
|
||||
|
||||
// ===== 分析维度 =====
|
||||
|
||||
// 1. 缺陷模式分析
|
||||
function analyzeDefectPatterns(issues, results) {
|
||||
const byType = {}
|
||||
for (const issue of issues) {
|
||||
const type = issue.perspective || 'unknown'
|
||||
if (!byType[type]) byType[type] = []
|
||||
byType[type].push(issue)
|
||||
}
|
||||
|
||||
// 识别重复模式
|
||||
const patterns = []
|
||||
for (const [type, typeIssues] of Object.entries(byType)) {
|
||||
if (typeIssues.length >= 2) {
|
||||
// 分析共同特征
|
||||
const commonFiles = findCommonPatterns(typeIssues.map(i => i.file))
|
||||
patterns.push({
|
||||
type,
|
||||
count: typeIssues.length,
|
||||
files: [...new Set(typeIssues.map(i => i.file))],
|
||||
common_pattern: commonFiles,
|
||||
description: `${type} 类问题在 ${typeIssues.length} 处重复出现`,
|
||||
recommendation: generateRecommendation(type, typeIssues)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return { by_type: byType, patterns, total: issues.length }
|
||||
}
|
||||
|
||||
// 2. 覆盖率差距分析
|
||||
function analyzeCoverageGaps(coverage, strategy) {
|
||||
if (!coverage) return { status: 'no_data', gaps: [] }
|
||||
|
||||
const totalCoverage = coverage.total?.lines?.pct || 0
|
||||
const gaps = []
|
||||
|
||||
for (const layer of (strategy.layers || [])) {
|
||||
if (totalCoverage < layer.target_coverage) {
|
||||
gaps.push({
|
||||
layer: layer.level,
|
||||
target: layer.target_coverage,
|
||||
actual: totalCoverage,
|
||||
gap: Math.round(layer.target_coverage - totalCoverage),
|
||||
severity: (layer.target_coverage - totalCoverage) > 20 ? 'high' : 'medium'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 按文件分析覆盖率
|
||||
const fileGaps = []
|
||||
if (coverage && typeof coverage === 'object') {
|
||||
for (const [file, data] of Object.entries(coverage)) {
|
||||
if (file === 'total') continue
|
||||
const linePct = data?.lines?.pct || 0
|
||||
if (linePct < 50) {
|
||||
fileGaps.push({ file, coverage: linePct, severity: linePct < 20 ? 'critical' : 'high' })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { total_coverage: totalCoverage, gaps, file_gaps: fileGaps.slice(0, 10) }
|
||||
}
|
||||
|
||||
// 3. 测试有效性分析
|
||||
function analyzeTestEffectiveness(generated, results) {
|
||||
const effectiveness = {}
|
||||
for (const [layer, data] of Object.entries(generated)) {
|
||||
const result = results[layer] || {}
|
||||
effectiveness[layer] = {
|
||||
files_generated: data.files?.length || 0,
|
||||
pass_rate: result.pass_rate || 0,
|
||||
iterations_needed: result.iterations || 0,
|
||||
coverage_achieved: result.coverage || 0,
|
||||
effective: (result.pass_rate || 0) >= 95 && (result.iterations || 0) <= 2
|
||||
}
|
||||
}
|
||||
return effectiveness
|
||||
}
|
||||
|
||||
// 4. 质量趋势分析
|
||||
function analyzeQualityTrend(history) {
|
||||
if (history.length < 2) return { trend: 'insufficient_data', confidence: 'low' }
|
||||
|
||||
const latest = history[history.length - 1]
|
||||
const previous = history[history.length - 2]
|
||||
const delta = (latest?.coverage || 0) - (previous?.coverage || 0)
|
||||
|
||||
return {
|
||||
trend: delta > 5 ? 'improving' : delta < -5 ? 'declining' : 'stable',
|
||||
delta: Math.round(delta * 10) / 10,
|
||||
data_points: history.length,
|
||||
confidence: history.length >= 5 ? 'high' : history.length >= 3 ? 'medium' : 'low'
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 综合质量评分
|
||||
function calculateQualityScore(analysis) {
|
||||
let score = 100
|
||||
|
||||
// 扣分: 安全问题
|
||||
const securityIssues = (analysis.defect_patterns.by_type?.security || []).length
|
||||
score -= securityIssues * 10
|
||||
|
||||
// 扣分: Bug
|
||||
const bugIssues = (analysis.defect_patterns.by_type?.bug || []).length
|
||||
score -= bugIssues * 5
|
||||
|
||||
// 扣分: 覆盖率差距
|
||||
for (const gap of (analysis.coverage_gaps.gaps || [])) {
|
||||
score -= gap.gap * 0.5
|
||||
}
|
||||
|
||||
// 扣分: 测试失败
|
||||
for (const [layer, eff] of Object.entries(analysis.test_effectiveness)) {
|
||||
if (eff.pass_rate < 100) score -= (100 - eff.pass_rate) * 0.3
|
||||
}
|
||||
|
||||
// 加分: 有效测试层
|
||||
const effectiveLayers = Object.values(analysis.test_effectiveness)
|
||||
.filter(e => e.effective).length
|
||||
score += effectiveLayers * 5
|
||||
|
||||
// 加分: 改善趋势
|
||||
if (analysis.quality_trend.trend === 'improving') score += 3
|
||||
|
||||
return Math.max(0, Math.min(100, Math.round(score)))
|
||||
}
|
||||
|
||||
// 辅助函数
|
||||
function findCommonPatterns(files) {
|
||||
const dirs = files.map(f => f.split('/').slice(0, -1).join('/'))
|
||||
const commonDir = dirs.reduce((a, b) => {
|
||||
const partsA = a.split('/')
|
||||
const partsB = b.split('/')
|
||||
const common = []
|
||||
for (let i = 0; i < Math.min(partsA.length, partsB.length); i++) {
|
||||
if (partsA[i] === partsB[i]) common.push(partsA[i])
|
||||
else break
|
||||
}
|
||||
return common.join('/')
|
||||
})
|
||||
return commonDir || 'scattered'
|
||||
}
|
||||
|
||||
function generateRecommendation(type, issues) {
|
||||
const recommendations = {
|
||||
'security': '加强输入验证和安全审计,考虑引入 SAST 工具',
|
||||
'bug': '改进错误处理和边界检查,增加防御性编程',
|
||||
'test-coverage': '补充缺失的测试用例,聚焦未覆盖的分支',
|
||||
'code-quality': '重构复杂函数,消除代码重复',
|
||||
'ux': '统一错误提示和加载状态处理'
|
||||
}
|
||||
return recommendations[type] || '进一步分析并制定改进计划'
|
||||
}
|
||||
```
|
||||
|
||||
### Step 3: Result Processing
|
||||
|
||||
```javascript
|
||||
// 组装分析结果
|
||||
const analysis = {
|
||||
defect_patterns: analyzeDefectPatterns(discoveredIssues, layerResults),
|
||||
coverage_gaps: analyzeCoverageGaps(coverageData, strategy),
|
||||
test_effectiveness: analyzeTestEffectiveness(generatedTests, layerResults),
|
||||
quality_trend: analyzeQualityTrend(coverageHistory),
|
||||
quality_score: 0
|
||||
}
|
||||
|
||||
analysis.quality_score = calculateQualityScore(analysis)
|
||||
|
||||
// 生成报告文件
|
||||
const reportContent = generateReportMarkdown(analysis)
|
||||
Bash(`mkdir -p "${sessionFolder}/analysis"`)
|
||||
Write(`${sessionFolder}/analysis/quality-report.md`, reportContent)
|
||||
|
||||
// 更新 shared memory
|
||||
sharedMemory.defect_patterns = analysis.defect_patterns.patterns
|
||||
sharedMemory.quality_score = analysis.quality_score
|
||||
sharedMemory.coverage_history = sharedMemory.coverage_history || []
|
||||
sharedMemory.coverage_history.push({
|
||||
date: new Date().toISOString(),
|
||||
coverage: analysis.coverage_gaps.total_coverage || 0,
|
||||
quality_score: analysis.quality_score,
|
||||
issues: analysis.defect_patterns.total
|
||||
})
|
||||
Write(`${sessionFolder}/shared-memory.json`, JSON.stringify(sharedMemory, null, 2))
|
||||
|
||||
function generateReportMarkdown(analysis) {
|
||||
return `# Quality Assurance Report
|
||||
|
||||
## Quality Score: ${analysis.quality_score}/100
|
||||
|
||||
---
|
||||
|
||||
## 1. Defect Pattern Analysis
|
||||
- Total issues found: ${analysis.defect_patterns.total}
|
||||
- Recurring patterns: ${analysis.defect_patterns.patterns.length}
|
||||
|
||||
${analysis.defect_patterns.patterns.map(p =>
|
||||
`### Pattern: ${p.type} (${p.count} occurrences)
|
||||
- Files: ${p.files.join(', ')}
|
||||
- Common location: ${p.common_pattern}
|
||||
- Recommendation: ${p.recommendation}`
|
||||
).join('\n\n')}
|
||||
|
||||
## 2. Coverage Analysis
|
||||
- Overall coverage: ${analysis.coverage_gaps.total_coverage || 'N/A'}%
|
||||
- Coverage gaps: ${(analysis.coverage_gaps.gaps || []).length}
|
||||
|
||||
${(analysis.coverage_gaps.gaps || []).map(g =>
|
||||
`- **${g.layer}**: target ${g.target}% vs actual ${g.actual}% (gap: ${g.gap}%, severity: ${g.severity})`
|
||||
).join('\n')}
|
||||
|
||||
### Low Coverage Files
|
||||
${(analysis.coverage_gaps.file_gaps || []).map(f =>
|
||||
`- ${f.file}: ${f.coverage}% [${f.severity}]`
|
||||
).join('\n')}
|
||||
|
||||
## 3. Test Effectiveness
|
||||
${Object.entries(analysis.test_effectiveness).map(([layer, data]) =>
|
||||
`- **${layer}**: ${data.files_generated} files, pass rate ${data.pass_rate}%, ${data.iterations_needed} fix iterations, ${data.effective ? 'EFFECTIVE' : 'NEEDS IMPROVEMENT'}`
|
||||
).join('\n')}
|
||||
|
||||
## 4. Quality Trend
|
||||
- Trend: ${analysis.quality_trend.trend}
|
||||
${analysis.quality_trend.delta !== undefined ? `- Coverage delta: ${analysis.quality_trend.delta > 0 ? '+' : ''}${analysis.quality_trend.delta}%` : ''}
|
||||
- Confidence: ${analysis.quality_trend.confidence}
|
||||
|
||||
## 5. Recommendations
|
||||
${analysis.quality_score >= 80 ? '- Quality is **GOOD**. Maintain current testing practices.' : ''}
|
||||
${analysis.quality_score >= 60 && analysis.quality_score < 80 ? '- Quality needs **IMPROVEMENT**. Focus on coverage gaps and recurring patterns.' : ''}
|
||||
${analysis.quality_score < 60 ? '- Quality is **CONCERNING**. Recommend comprehensive review and testing effort.' : ''}
|
||||
${analysis.defect_patterns.patterns.map(p => `- [${p.type}] ${p.recommendation}`).join('\n')}
|
||||
${(analysis.coverage_gaps.gaps || []).map(g => `- Close ${g.layer} coverage gap: +${g.gap}% needed`).join('\n')}
|
||||
`
|
||||
}
|
||||
```
|
||||
|
||||
## Output Format
|
||||
|
||||
```
|
||||
## Quality Analysis Results
|
||||
|
||||
### Quality Score: [score]/100
|
||||
|
||||
### Dimensions
|
||||
1. Defect Patterns: [count] recurring
|
||||
2. Coverage Gaps: [count] layers below target
|
||||
3. Test Effectiveness: [effective_count]/[total_layers] effective
|
||||
4. Quality Trend: [improving|stable|declining]
|
||||
|
||||
### Report Location
|
||||
[session]/analysis/quality-report.md
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Scenario | Resolution |
|
||||
|----------|------------|
|
||||
| No coverage data available | Score based on other dimensions only |
|
||||
| No execution results | Analyze only scout findings and strategy |
|
||||
| Shared memory empty/corrupt | Generate minimal report with available data |
|
||||
| CLI analysis fails | Fall back to direct inline analysis |
|
||||
| Insufficient history for trend | Report 'insufficient_data', skip trend scoring |
|
||||
| Agent/CLI failure | Retry once, then fallback to inline execution |
|
||||
| Timeout (>5 min) | Report partial results, notify coordinator |
|
||||
326
.claude/skills/team-quality-assurance/roles/analyst/role.md
Normal file
326
.claude/skills/team-quality-assurance/roles/analyst/role.md
Normal file
@@ -0,0 +1,326 @@
|
||||
# Role: analyst
|
||||
|
||||
质量分析师。分析缺陷模式、覆盖率差距、测试有效性,生成综合质量报告。维护缺陷模式数据库,为 scout 和 strategist 提供反馈数据。
|
||||
|
||||
## Role Identity
|
||||
|
||||
- **Name**: `analyst`
|
||||
- **Task Prefix**: `QAANA-*`
|
||||
- **Responsibility**: Read-only analysis(质量分析)
|
||||
- **Communication**: SendMessage to coordinator only
|
||||
- **Output Tag**: `[analyst]`
|
||||
|
||||
## Role Boundaries
|
||||
|
||||
### MUST
|
||||
|
||||
- 仅处理 `QAANA-*` 前缀的任务
|
||||
- 所有输出必须带 `[analyst]` 标识
|
||||
- 基于数据生成分析报告
|
||||
- 更新 shared memory 中的缺陷模式和质量分数
|
||||
|
||||
### MUST NOT
|
||||
|
||||
- ❌ 修改源代码或测试代码
|
||||
- ❌ 执行测试
|
||||
- ❌ 为其他角色创建任务
|
||||
- ❌ 直接与其他 worker 通信
|
||||
|
||||
## Message Types
|
||||
|
||||
| Type | Direction | Trigger | Description |
|
||||
|------|-----------|---------|-------------|
|
||||
| `analysis_ready` | analyst → coordinator | 分析完成 | 包含质量评分 |
|
||||
| `quality_report` | analyst → coordinator | 报告生成 | 包含详细分析 |
|
||||
| `error` | analyst → coordinator | 分析失败 | 阻塞性错误 |
|
||||
|
||||
## Toolbox
|
||||
|
||||
### Available Commands
|
||||
|
||||
| Command | File | Phase | Description |
|
||||
|---------|------|-------|-------------|
|
||||
| `quality-report` | [commands/quality-report.md](commands/quality-report.md) | Phase 3 | 缺陷模式分析 + 覆盖率分析 |
|
||||
|
||||
### CLI Capabilities
|
||||
|
||||
| CLI Tool | Mode | Used By | Purpose |
|
||||
|----------|------|---------|---------|
|
||||
| `gemini` | analysis | quality-report.md | 缺陷模式识别和趋势分析 |
|
||||
|
||||
## Execution (5-Phase)
|
||||
|
||||
### Phase 1: Task Discovery
|
||||
|
||||
```javascript
|
||||
const tasks = TaskList()
|
||||
const myTasks = tasks.filter(t =>
|
||||
t.subject.startsWith('QAANA-') &&
|
||||
t.owner === 'analyst' &&
|
||||
t.status === 'pending' &&
|
||||
t.blockedBy.length === 0
|
||||
)
|
||||
|
||||
if (myTasks.length === 0) return
|
||||
const task = TaskGet({ taskId: myTasks[0].id })
|
||||
TaskUpdate({ taskId: task.id, status: 'in_progress' })
|
||||
```
|
||||
|
||||
### Phase 2: Context Loading
|
||||
|
||||
```javascript
|
||||
// 读取 shared memory 获取所有数据
|
||||
const sessionFolder = task.description.match(/session:\s*(.+)/)?.[1] || '.'
|
||||
let sharedMemory = {}
|
||||
try { sharedMemory = JSON.parse(Read(`${sessionFolder}/shared-memory.json`)) } catch {}
|
||||
|
||||
const discoveredIssues = sharedMemory.discovered_issues || []
|
||||
const strategy = sharedMemory.test_strategy || {}
|
||||
const generatedTests = sharedMemory.generated_tests || {}
|
||||
const executionResults = sharedMemory.execution_results || {}
|
||||
const historicalPatterns = sharedMemory.defect_patterns || []
|
||||
|
||||
// 读取覆盖率数据
|
||||
let coverageData = null
|
||||
try {
|
||||
coverageData = JSON.parse(Read('coverage/coverage-summary.json'))
|
||||
} catch {}
|
||||
|
||||
// 读取测试执行日志
|
||||
const runResults = {}
|
||||
try {
|
||||
const resultFiles = Glob(`${sessionFolder}/results/run-*.json`)
|
||||
for (const f of resultFiles) {
|
||||
const data = JSON.parse(Read(f))
|
||||
runResults[data.layer] = data
|
||||
}
|
||||
} catch {}
|
||||
```
|
||||
|
||||
### Phase 3: Multi-Dimensional Analysis
|
||||
|
||||
```javascript
|
||||
// Read commands/quality-report.md for full implementation
|
||||
Read("commands/quality-report.md")
|
||||
```
|
||||
|
||||
**分析维度**:
|
||||
|
||||
```javascript
|
||||
const analysis = {
|
||||
// 1. 缺陷模式分析
|
||||
defect_patterns: analyzeDefectPatterns(discoveredIssues, executionResults),
|
||||
|
||||
// 2. 覆盖率差距分析
|
||||
coverage_gaps: analyzeCoverageGaps(coverageData, strategy),
|
||||
|
||||
// 3. 测试有效性分析
|
||||
test_effectiveness: analyzeTestEffectiveness(generatedTests, executionResults),
|
||||
|
||||
// 4. 质量趋势
|
||||
quality_trend: analyzeQualityTrend(sharedMemory.coverage_history || []),
|
||||
|
||||
// 5. 综合质量评分
|
||||
quality_score: 0
|
||||
}
|
||||
|
||||
function analyzeDefectPatterns(issues, results) {
|
||||
// 按类型分组
|
||||
const byType = {}
|
||||
for (const issue of issues) {
|
||||
const type = issue.perspective || 'unknown'
|
||||
if (!byType[type]) byType[type] = []
|
||||
byType[type].push(issue)
|
||||
}
|
||||
|
||||
// 识别重复模式
|
||||
const patterns = []
|
||||
for (const [type, typeIssues] of Object.entries(byType)) {
|
||||
if (typeIssues.length >= 2) {
|
||||
patterns.push({
|
||||
type,
|
||||
count: typeIssues.length,
|
||||
files: [...new Set(typeIssues.map(i => i.file))],
|
||||
description: `${type} 类问题在 ${typeIssues.length} 处重复出现`
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return { by_type: byType, patterns, total: issues.length }
|
||||
}
|
||||
|
||||
function analyzeCoverageGaps(coverage, strategy) {
|
||||
if (!coverage) return { status: 'no_data' }
|
||||
|
||||
const gaps = []
|
||||
const totalCoverage = coverage.total?.lines?.pct || 0
|
||||
|
||||
// 对比策略目标
|
||||
for (const layer of (strategy.layers || [])) {
|
||||
const actual = totalCoverage
|
||||
if (actual < layer.target_coverage) {
|
||||
gaps.push({
|
||||
layer: layer.level,
|
||||
target: layer.target_coverage,
|
||||
actual,
|
||||
gap: layer.target_coverage - actual,
|
||||
files_below_target: [] // 可以进一步分析
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return { total_coverage: totalCoverage, gaps }
|
||||
}
|
||||
|
||||
function analyzeTestEffectiveness(generated, results) {
|
||||
const effectiveness = {}
|
||||
for (const [layer, data] of Object.entries(generated)) {
|
||||
const result = results[layer] || {}
|
||||
effectiveness[layer] = {
|
||||
files_generated: data.files?.length || 0,
|
||||
pass_rate: result.pass_rate || 0,
|
||||
iterations_needed: result.iterations || 0,
|
||||
effective: (result.pass_rate || 0) >= 95
|
||||
}
|
||||
}
|
||||
return effectiveness
|
||||
}
|
||||
|
||||
function analyzeQualityTrend(history) {
|
||||
if (history.length < 2) return { trend: 'insufficient_data' }
|
||||
const latest = history[history.length - 1]
|
||||
const previous = history[history.length - 2]
|
||||
const delta = (latest?.coverage || 0) - (previous?.coverage || 0)
|
||||
return {
|
||||
trend: delta > 0 ? 'improving' : delta < 0 ? 'declining' : 'stable',
|
||||
delta,
|
||||
data_points: history.length
|
||||
}
|
||||
}
|
||||
|
||||
// 综合质量评分 (0-100)
|
||||
function calculateQualityScore(analysis) {
|
||||
let score = 100
|
||||
|
||||
// 扣分项
|
||||
const criticalIssues = (analysis.defect_patterns.by_type?.security || []).length
|
||||
score -= criticalIssues * 10
|
||||
|
||||
const highIssues = (analysis.defect_patterns.by_type?.bug || []).length
|
||||
score -= highIssues * 5
|
||||
|
||||
// 覆盖率不达标扣分
|
||||
for (const gap of (analysis.coverage_gaps.gaps || [])) {
|
||||
score -= gap.gap * 0.5
|
||||
}
|
||||
|
||||
// 测试有效性加分
|
||||
const effectiveLayers = Object.values(analysis.test_effectiveness)
|
||||
.filter(e => e.effective).length
|
||||
score += effectiveLayers * 5
|
||||
|
||||
return Math.max(0, Math.min(100, Math.round(score)))
|
||||
}
|
||||
|
||||
analysis.quality_score = calculateQualityScore(analysis)
|
||||
```
|
||||
|
||||
### Phase 4: Report Generation
|
||||
|
||||
```javascript
|
||||
// 生成质量报告
|
||||
const reportContent = `# Quality Assurance Report
|
||||
|
||||
## Quality Score: ${analysis.quality_score}/100
|
||||
|
||||
## 1. Defect Pattern Analysis
|
||||
- Total issues found: ${analysis.defect_patterns.total}
|
||||
- Recurring patterns: ${analysis.defect_patterns.patterns.length}
|
||||
${analysis.defect_patterns.patterns.map(p => ` - **${p.type}**: ${p.count} occurrences across ${p.files.length} files`).join('\n')}
|
||||
|
||||
## 2. Coverage Analysis
|
||||
- Overall coverage: ${analysis.coverage_gaps.total_coverage || 'N/A'}%
|
||||
- Coverage gaps: ${(analysis.coverage_gaps.gaps || []).length}
|
||||
${(analysis.coverage_gaps.gaps || []).map(g => ` - **${g.layer}**: target ${g.target}% vs actual ${g.actual}% (gap: ${g.gap}%)`).join('\n')}
|
||||
|
||||
## 3. Test Effectiveness
|
||||
${Object.entries(analysis.test_effectiveness).map(([layer, data]) =>
|
||||
`- **${layer}**: ${data.files_generated} files, pass rate ${data.pass_rate}%, ${data.iterations_needed} fix iterations`
|
||||
).join('\n')}
|
||||
|
||||
## 4. Quality Trend
|
||||
- Trend: ${analysis.quality_trend.trend}
|
||||
${analysis.quality_trend.delta !== undefined ? `- Coverage change: ${analysis.quality_trend.delta > 0 ? '+' : ''}${analysis.quality_trend.delta}%` : ''}
|
||||
|
||||
## 5. Recommendations
|
||||
${analysis.quality_score >= 80 ? '- Quality is GOOD. Continue with current testing strategy.' : ''}
|
||||
${analysis.quality_score >= 60 && analysis.quality_score < 80 ? '- Quality needs IMPROVEMENT. Focus on coverage gaps and recurring patterns.' : ''}
|
||||
${analysis.quality_score < 60 ? '- Quality is CONCERNING. Recommend deep scan and comprehensive test generation.' : ''}
|
||||
${analysis.defect_patterns.patterns.length > 0 ? `- Address ${analysis.defect_patterns.patterns.length} recurring defect patterns` : ''}
|
||||
${(analysis.coverage_gaps.gaps || []).length > 0 ? `- Close ${analysis.coverage_gaps.gaps.length} coverage gaps` : ''}
|
||||
`
|
||||
|
||||
Bash(`mkdir -p "${sessionFolder}/analysis"`)
|
||||
Write(`${sessionFolder}/analysis/quality-report.md`, reportContent)
|
||||
|
||||
// 更新 shared memory
|
||||
sharedMemory.defect_patterns = analysis.defect_patterns.patterns
|
||||
sharedMemory.quality_score = analysis.quality_score
|
||||
sharedMemory.coverage_history = sharedMemory.coverage_history || []
|
||||
sharedMemory.coverage_history.push({
|
||||
date: new Date().toISOString(),
|
||||
coverage: analysis.coverage_gaps.total_coverage || 0,
|
||||
quality_score: analysis.quality_score,
|
||||
issues: analysis.defect_patterns.total
|
||||
})
|
||||
Write(`${sessionFolder}/shared-memory.json`, JSON.stringify(sharedMemory, null, 2))
|
||||
```
|
||||
|
||||
### Phase 5: Report to Coordinator
|
||||
|
||||
```javascript
|
||||
mcp__ccw-tools__team_msg({
|
||||
operation: "log",
|
||||
team: teamName,
|
||||
from: "analyst",
|
||||
to: "coordinator",
|
||||
type: "quality_report",
|
||||
summary: `[analyst] 质量评分: ${analysis.quality_score}/100, 缺陷模式: ${analysis.defect_patterns.patterns.length}, 覆盖率: ${analysis.coverage_gaps.total_coverage || 'N/A'}%`,
|
||||
ref: `${sessionFolder}/analysis/quality-report.md`
|
||||
})
|
||||
|
||||
SendMessage({
|
||||
type: "message",
|
||||
recipient: "coordinator",
|
||||
content: `## [analyst] Quality Analysis Results
|
||||
|
||||
**Task**: ${task.subject}
|
||||
**Quality Score**: ${analysis.quality_score}/100
|
||||
**Defect Patterns**: ${analysis.defect_patterns.patterns.length} recurring
|
||||
**Coverage**: ${analysis.coverage_gaps.total_coverage || 'N/A'}%
|
||||
**Trend**: ${analysis.quality_trend.trend}
|
||||
|
||||
### Report
|
||||
${sessionFolder}/analysis/quality-report.md`,
|
||||
summary: `[analyst] QAANA complete: score ${analysis.quality_score}/100`
|
||||
})
|
||||
|
||||
TaskUpdate({ taskId: task.id, status: 'completed' })
|
||||
|
||||
const nextTasks = TaskList().filter(t =>
|
||||
t.subject.startsWith('QAANA-') && t.owner === 'analyst' &&
|
||||
t.status === 'pending' && t.blockedBy.length === 0
|
||||
)
|
||||
if (nextTasks.length > 0) { /* back to Phase 1 */ }
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Scenario | Resolution |
|
||||
|----------|------------|
|
||||
| No QAANA-* tasks available | Idle, wait for coordinator |
|
||||
| Coverage data not found | Report quality score based on other dimensions |
|
||||
| Shared memory empty | Generate minimal report with available data |
|
||||
| No execution results | Analyze only scout findings and strategy coverage |
|
||||
| CLI analysis fails | Fall back to inline pattern analysis |
|
||||
| Critical issue beyond scope | SendMessage error to coordinator |
|
||||
@@ -0,0 +1,167 @@
|
||||
# Command: dispatch
|
||||
|
||||
> 任务链创建与依赖管理。根据 QA 模式创建 pipeline 任务链并分配给 worker 角色。
|
||||
|
||||
## When to Use
|
||||
|
||||
- Phase 3 of Coordinator
|
||||
- QA 模式已确定,需要创建任务链
|
||||
- 团队已创建,worker 已 spawn
|
||||
|
||||
**Trigger conditions**:
|
||||
- Coordinator Phase 2 完成后
|
||||
- 模式切换需要重建任务链
|
||||
- GC 循环需要创建修复任务
|
||||
|
||||
## Strategy
|
||||
|
||||
### Delegation Mode
|
||||
|
||||
**Mode**: Direct(coordinator 直接操作 TaskCreate/TaskUpdate)
|
||||
|
||||
### Decision Logic
|
||||
|
||||
```javascript
|
||||
// 根据 qaMode 选择 pipeline
|
||||
function buildPipeline(qaMode, sessionFolder, taskDescription) {
|
||||
const pipelines = {
|
||||
'discovery': [
|
||||
{ prefix: 'SCOUT', owner: 'scout', desc: '多视角问题扫描', blockedBy: [] },
|
||||
{ prefix: 'QASTRAT', owner: 'strategist', desc: '测试策略制定', blockedBy: ['SCOUT'] },
|
||||
{ prefix: 'QAGEN', owner: 'generator', desc: '测试代码生成 (L1)', meta: 'layer: L1', blockedBy: ['QASTRAT'] },
|
||||
{ prefix: 'QARUN', owner: 'executor', desc: '测试执行 (L1)', meta: 'layer: L1', blockedBy: ['QAGEN'] },
|
||||
{ prefix: 'QAANA', owner: 'analyst', desc: '质量分析报告', blockedBy: ['QARUN'] }
|
||||
],
|
||||
'testing': [
|
||||
{ prefix: 'QASTRAT', owner: 'strategist', desc: '测试策略制定', blockedBy: [] },
|
||||
{ prefix: 'QAGEN-L1', owner: 'generator', desc: '测试代码生成 (L1)', meta: 'layer: L1', blockedBy: ['QASTRAT'] },
|
||||
{ prefix: 'QARUN-L1', owner: 'executor', desc: '测试执行 (L1)', meta: 'layer: L1', blockedBy: ['QAGEN-L1'] },
|
||||
{ prefix: 'QAGEN-L2', owner: 'generator', desc: '测试代码生成 (L2)', meta: 'layer: L2', blockedBy: ['QARUN-L1'] },
|
||||
{ prefix: 'QARUN-L2', owner: 'executor', desc: '测试执行 (L2)', meta: 'layer: L2', blockedBy: ['QAGEN-L2'] },
|
||||
{ prefix: 'QAANA', owner: 'analyst', desc: '质量分析报告', blockedBy: ['QARUN-L2'] }
|
||||
],
|
||||
'full': [
|
||||
{ prefix: 'SCOUT', owner: 'scout', desc: '多视角问题扫描', blockedBy: [] },
|
||||
{ prefix: 'QASTRAT', owner: 'strategist', desc: '测试策略制定', blockedBy: ['SCOUT'] },
|
||||
{ prefix: 'QAGEN-L1', owner: 'generator', desc: '测试代码生成 (L1)', meta: 'layer: L1', blockedBy: ['QASTRAT'] },
|
||||
{ prefix: 'QAGEN-L2', owner: 'generator', desc: '测试代码生成 (L2)', meta: 'layer: L2', blockedBy: ['QASTRAT'] },
|
||||
{ prefix: 'QARUN-L1', owner: 'executor', desc: '测试执行 (L1)', meta: 'layer: L1', blockedBy: ['QAGEN-L1'] },
|
||||
{ prefix: 'QARUN-L2', owner: 'executor', desc: '测试执行 (L2)', meta: 'layer: L2', blockedBy: ['QAGEN-L2'] },
|
||||
{ prefix: 'QAANA', owner: 'analyst', desc: '质量分析报告', blockedBy: ['QARUN-L1', 'QARUN-L2'] },
|
||||
{ prefix: 'SCOUT-REG', owner: 'scout', desc: '回归扫描', blockedBy: ['QAANA'] }
|
||||
]
|
||||
}
|
||||
return pipelines[qaMode] || pipelines['discovery']
|
||||
}
|
||||
```
|
||||
|
||||
## Execution Steps
|
||||
|
||||
### Step 1: Context Preparation
|
||||
|
||||
```javascript
|
||||
const pipeline = buildPipeline(qaMode, sessionFolder, taskDescription)
|
||||
```
|
||||
|
||||
### Step 2: Execute Strategy
|
||||
|
||||
```javascript
|
||||
const taskIds = {}
|
||||
|
||||
for (const stage of pipeline) {
|
||||
// 构建任务描述(包含 session 和层级信息)
|
||||
const fullDesc = [
|
||||
stage.desc,
|
||||
`\nsession: ${sessionFolder}`,
|
||||
stage.meta ? `\n${stage.meta}` : '',
|
||||
`\n\n目标: ${taskDescription}`
|
||||
].join('')
|
||||
|
||||
// 创建任务
|
||||
TaskCreate({
|
||||
subject: `${stage.prefix}-001: ${stage.desc}`,
|
||||
description: fullDesc,
|
||||
activeForm: `${stage.desc}进行中`
|
||||
})
|
||||
|
||||
// 记录任务 ID(假设 TaskCreate 返回 ID)
|
||||
const allTasks = TaskList()
|
||||
const newTask = allTasks.find(t => t.subject.startsWith(`${stage.prefix}-001`))
|
||||
taskIds[stage.prefix] = newTask.id
|
||||
|
||||
// 设置 owner 和依赖
|
||||
const blockedByIds = stage.blockedBy
|
||||
.map(dep => taskIds[dep])
|
||||
.filter(Boolean)
|
||||
|
||||
TaskUpdate({
|
||||
taskId: newTask.id,
|
||||
owner: stage.owner,
|
||||
addBlockedBy: blockedByIds
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
### Step 3: Result Processing
|
||||
|
||||
```javascript
|
||||
// 验证任务链
|
||||
const allTasks = TaskList()
|
||||
const chainTasks = pipeline.map(s => taskIds[s.prefix]).filter(Boolean)
|
||||
const chainValid = chainTasks.length === pipeline.length
|
||||
|
||||
if (!chainValid) {
|
||||
mcp__ccw-tools__team_msg({
|
||||
operation: "log", team: teamName, from: "coordinator",
|
||||
to: "user", type: "error",
|
||||
summary: `[coordinator] 任务链创建不完整: ${chainTasks.length}/${pipeline.length}`
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
## GC Loop Task Creation
|
||||
|
||||
当 executor 报告覆盖率不达标时,coordinator 调用此逻辑追加任务:
|
||||
|
||||
```javascript
|
||||
function createGCLoopTasks(gcIteration, targetLayer, sessionFolder) {
|
||||
// 创建修复任务
|
||||
TaskCreate({
|
||||
subject: `QAGEN-fix-${gcIteration}: 修复 ${targetLayer} 测试 (GC #${gcIteration})`,
|
||||
description: `修复未通过测试并补充覆盖\nsession: ${sessionFolder}\nlayer: ${targetLayer}\ntype: gc-fix`,
|
||||
activeForm: `GC循环 #${gcIteration} 修复中`
|
||||
})
|
||||
|
||||
// 创建重新执行任务
|
||||
TaskCreate({
|
||||
subject: `QARUN-gc-${gcIteration}: 重新执行 ${targetLayer} (GC #${gcIteration})`,
|
||||
description: `重新执行测试验证修复\nsession: ${sessionFolder}\nlayer: ${targetLayer}`,
|
||||
activeForm: `GC循环 #${gcIteration} 执行中`
|
||||
})
|
||||
|
||||
// 设置依赖: QARUN-gc 依赖 QAGEN-fix
|
||||
// ... TaskUpdate addBlockedBy
|
||||
}
|
||||
```
|
||||
|
||||
## Output Format
|
||||
|
||||
```
|
||||
## Task Chain Created
|
||||
|
||||
### Mode: [discovery|testing|full]
|
||||
### Pipeline Stages: [count]
|
||||
- [prefix]-001: [description] (owner: [role], blocked by: [deps])
|
||||
|
||||
### Verification: PASS/FAIL
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Scenario | Resolution |
|
||||
|----------|------------|
|
||||
| Task creation fails | Retry once, then report to user |
|
||||
| Dependency cycle detected | Flatten dependencies, warn coordinator |
|
||||
| Invalid qaMode | Default to 'discovery' mode |
|
||||
| Agent/CLI failure | Retry once, then fallback to inline execution |
|
||||
| Timeout (>5 min) | Report partial results, notify coordinator |
|
||||
@@ -0,0 +1,247 @@
|
||||
# Command: monitor
|
||||
|
||||
> 消息总线轮询与协调循环。持续监控 worker 进度,路由消息,触发 GC 循环,执行质量门控。
|
||||
|
||||
## When to Use
|
||||
|
||||
- Phase 4 of Coordinator
|
||||
- 任务链已创建并分发
|
||||
- 需要持续监控直到所有任务完成
|
||||
|
||||
**Trigger conditions**:
|
||||
- dispatch 完成后立即启动
|
||||
- GC 循环创建新任务后重新进入
|
||||
|
||||
## Strategy
|
||||
|
||||
### Delegation Mode
|
||||
|
||||
**Mode**: Direct(coordinator 直接轮询和路由)
|
||||
|
||||
### Decision Logic
|
||||
|
||||
```javascript
|
||||
// 消息路由表
|
||||
const routingTable = {
|
||||
// Scout 完成
|
||||
'scan_ready': {
|
||||
action: 'Mark SCOUT complete, unblock QASTRAT',
|
||||
next: 'strategist'
|
||||
},
|
||||
'issues_found': {
|
||||
action: 'Mark SCOUT complete with issues, unblock QASTRAT',
|
||||
next: 'strategist'
|
||||
},
|
||||
|
||||
// Strategist 完成
|
||||
'strategy_ready': {
|
||||
action: 'Mark QASTRAT complete, unblock QAGEN',
|
||||
next: 'generator'
|
||||
},
|
||||
|
||||
// Generator 完成
|
||||
'tests_generated': {
|
||||
action: 'Mark QAGEN complete, unblock QARUN',
|
||||
next: 'executor'
|
||||
},
|
||||
'tests_revised': {
|
||||
action: 'Mark QAGEN-fix complete, unblock QARUN-gc',
|
||||
next: 'executor'
|
||||
},
|
||||
|
||||
// Executor 完成
|
||||
'tests_passed': {
|
||||
action: 'Mark QARUN complete, check coverage, unblock next',
|
||||
next: 'check_coverage'
|
||||
},
|
||||
'tests_failed': {
|
||||
action: 'Evaluate failures, decide GC loop or continue',
|
||||
next: 'gc_decision'
|
||||
},
|
||||
|
||||
// Analyst 完成
|
||||
'analysis_ready': {
|
||||
action: 'Mark QAANA complete, evaluate quality gate',
|
||||
next: 'quality_gate'
|
||||
},
|
||||
'quality_report': {
|
||||
action: 'Quality report received, prepare final report',
|
||||
next: 'finalize'
|
||||
},
|
||||
|
||||
// 错误
|
||||
'error': {
|
||||
action: 'Assess severity, retry or escalate',
|
||||
next: 'error_handler'
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Execution Steps
|
||||
|
||||
### Step 1: Context Preparation
|
||||
|
||||
```javascript
|
||||
// 从 shared memory 获取覆盖率目标
|
||||
const sharedMemory = JSON.parse(Read(`${sessionFolder}/shared-memory.json`))
|
||||
const strategy = sharedMemory.test_strategy || {}
|
||||
const coverageTargets = {}
|
||||
for (const layer of (strategy.layers || [])) {
|
||||
coverageTargets[layer.level] = layer.target_coverage
|
||||
}
|
||||
|
||||
let gcIteration = 0
|
||||
const MAX_GC_ITERATIONS = 3
|
||||
```
|
||||
|
||||
### Step 2: Execute Strategy
|
||||
|
||||
```javascript
|
||||
let allComplete = false
|
||||
|
||||
while (!allComplete) {
|
||||
// 1. Poll message bus
|
||||
const messages = mcp__ccw-tools__team_msg({
|
||||
operation: "list",
|
||||
team: teamName,
|
||||
last: 10
|
||||
})
|
||||
|
||||
// 2. Route each unprocessed message
|
||||
for (const msg of messages) {
|
||||
const handler = routingTable[msg.type]
|
||||
if (!handler) continue
|
||||
|
||||
switch (handler.next) {
|
||||
case 'check_coverage': {
|
||||
// 读取执行结果
|
||||
const coverage = msg.data?.coverage || 0
|
||||
const targetLayer = msg.data?.layer || 'L1'
|
||||
const target = coverageTargets[targetLayer] || 80
|
||||
|
||||
if (coverage >= target) {
|
||||
// 覆盖率达标,继续流水线
|
||||
// 解锁下一个任务(QAANA 或下一层级)
|
||||
} else {
|
||||
// 转入 GC 决策
|
||||
handler.next = 'gc_decision'
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
case 'gc_decision': {
|
||||
const coverage = msg.data?.coverage || 0
|
||||
const targetLayer = msg.data?.layer || 'L1'
|
||||
|
||||
if (gcIteration < MAX_GC_ITERATIONS) {
|
||||
gcIteration++
|
||||
// 触发 GC 循环
|
||||
mcp__ccw-tools__team_msg({
|
||||
operation: "log", team: teamName, from: "coordinator",
|
||||
to: "generator", type: "gc_loop_trigger",
|
||||
summary: `[coordinator] GC循环 #${gcIteration}: 覆盖率 ${coverage}% 未达标,请修复`,
|
||||
data: { iteration: gcIteration, layer: targetLayer, coverage }
|
||||
})
|
||||
|
||||
// 创建 GC 修复任务(参见 dispatch.md createGCLoopTasks)
|
||||
// createGCLoopTasks(gcIteration, targetLayer, sessionFolder)
|
||||
} else {
|
||||
// 超过最大迭代次数,接受当前覆盖率
|
||||
mcp__ccw-tools__team_msg({
|
||||
operation: "log", team: teamName, from: "coordinator",
|
||||
to: "user", type: "quality_gate",
|
||||
summary: `[coordinator] GC循环已达上限(${MAX_GC_ITERATIONS}),接受当前覆盖率 ${coverage}%`
|
||||
})
|
||||
// 继续流水线,解锁 QAANA
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
case 'quality_gate': {
|
||||
const qualityScore = sharedMemory.quality_score || 0
|
||||
let status = 'PASS'
|
||||
if (qualityScore < 60) status = 'FAIL'
|
||||
else if (qualityScore < 80) status = 'CONDITIONAL'
|
||||
|
||||
mcp__ccw-tools__team_msg({
|
||||
operation: "log", team: teamName, from: "coordinator",
|
||||
to: "user", type: "quality_gate",
|
||||
summary: `[coordinator] 质量门控: ${status} (score: ${qualityScore})`
|
||||
})
|
||||
break
|
||||
}
|
||||
|
||||
case 'error_handler': {
|
||||
const fromRole = msg.from
|
||||
const severity = msg.data?.severity || 'medium'
|
||||
|
||||
if (severity === 'critical') {
|
||||
// 通知用户
|
||||
SendMessage({
|
||||
content: `## [coordinator] Critical Error from ${fromRole}\n\n${msg.summary}`,
|
||||
summary: `[coordinator] Critical error: ${msg.summary}`
|
||||
})
|
||||
} else {
|
||||
// 标记任务失败,尝试重试
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Check TaskList for overall completion
|
||||
const tasks = TaskList()
|
||||
const pendingWorkerTasks = tasks.filter(t =>
|
||||
t.owner !== 'coordinator' &&
|
||||
t.status !== 'completed' &&
|
||||
t.status !== 'deleted'
|
||||
)
|
||||
|
||||
allComplete = pendingWorkerTasks.length === 0
|
||||
|
||||
// 4. 如果没有完成,等待片刻再轮询
|
||||
if (!allComplete) {
|
||||
// 短暂等待(在实际执行中 coordinator 会在 subagent 返回后继续)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Step 3: Result Processing
|
||||
|
||||
```javascript
|
||||
// 汇总所有结果
|
||||
const finalSharedMemory = JSON.parse(Read(`${sessionFolder}/shared-memory.json`))
|
||||
const summary = {
|
||||
total_tasks: TaskList().filter(t => t.owner !== 'coordinator').length,
|
||||
completed_tasks: TaskList().filter(t => t.status === 'completed' && t.owner !== 'coordinator').length,
|
||||
gc_iterations: gcIteration,
|
||||
quality_score: finalSharedMemory.quality_score,
|
||||
coverage: finalSharedMemory.execution_results?.coverage
|
||||
}
|
||||
```
|
||||
|
||||
## Output Format
|
||||
|
||||
```
|
||||
## Coordination Summary
|
||||
|
||||
### Pipeline Status: COMPLETE
|
||||
### Tasks: [completed]/[total]
|
||||
### GC Iterations: [count]
|
||||
### Quality Score: [score]/100
|
||||
### Coverage: [percent]%
|
||||
|
||||
### Message Log (last 10)
|
||||
- [timestamp] [from] → [to]: [type] - [summary]
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Scenario | Resolution |
|
||||
|----------|------------|
|
||||
| Message bus unavailable | Fall back to TaskList polling only |
|
||||
| Teammate unresponsive (2x no response) | Respawn teammate with same task |
|
||||
| Deadlock detected (tasks blocked indefinitely) | Identify cycle, manually unblock |
|
||||
| Quality gate FAIL | Report to user, suggest targeted re-run |
|
||||
| Agent/CLI failure | Retry once, then fallback to inline execution |
|
||||
| Timeout (>5 min) | Report partial results, notify coordinator |
|
||||
228
.claude/skills/team-quality-assurance/roles/coordinator/role.md
Normal file
228
.claude/skills/team-quality-assurance/roles/coordinator/role.md
Normal file
@@ -0,0 +1,228 @@
|
||||
# Role: coordinator
|
||||
|
||||
QA 团队协调者。编排 pipeline:需求澄清 → 模式选择 → 团队创建 → 任务分发 → 监控协调 → 质量门控 → 结果汇报。
|
||||
|
||||
## Role Identity
|
||||
|
||||
- **Name**: `coordinator`
|
||||
- **Task Prefix**: N/A (coordinator creates tasks, doesn't receive them)
|
||||
- **Responsibility**: Orchestration
|
||||
- **Communication**: SendMessage to all teammates
|
||||
- **Output Tag**: `[coordinator]`
|
||||
|
||||
## Role Boundaries
|
||||
|
||||
### MUST
|
||||
|
||||
- 所有输出(SendMessage、team_msg、日志)必须带 `[coordinator]` 标识
|
||||
- 仅负责需求澄清、模式选择、任务创建/分发、进度监控、质量门控、结果汇报
|
||||
- 通过 TaskCreate 创建任务并分配给 worker 角色
|
||||
- 通过消息总线监控 worker 进度并路由消息
|
||||
|
||||
### MUST NOT
|
||||
|
||||
- ❌ **直接执行任何业务任务**(扫描、测试、分析等)
|
||||
- ❌ 直接调用 cli-explore-agent、code-developer 等实现类 subagent
|
||||
- ❌ 直接修改源代码或生成产物文件
|
||||
- ❌ 绕过 worker 角色自行完成应委派的工作
|
||||
- ❌ 在输出中省略 `[coordinator]` 标识
|
||||
|
||||
> **核心原则**: coordinator 是指挥者,不是执行者。所有实际工作必须通过 TaskCreate 委派给 worker 角色。
|
||||
|
||||
## Message Types
|
||||
|
||||
| Type | Direction | Trigger | Description |
|
||||
|------|-----------|---------|-------------|
|
||||
| `mode_selected` | coordinator → all | QA 模式确定 | Discovery/Testing/Full |
|
||||
| `gc_loop_trigger` | coordinator → generator | 覆盖率不达标 | 触发 Generator-Executor 循环 |
|
||||
| `quality_gate` | coordinator → user | 质量评估 | 通过/不通过/有条件通过 |
|
||||
| `task_unblocked` | coordinator → worker | 依赖解除 | 任务可执行 |
|
||||
| `error` | coordinator → user | 协调错误 | 阻塞性问题 |
|
||||
| `shutdown` | coordinator → all | 团队关闭 | 清理资源 |
|
||||
|
||||
## Toolbox
|
||||
|
||||
### Available Commands
|
||||
|
||||
| Command | File | Phase | Description |
|
||||
|---------|------|-------|-------------|
|
||||
| `dispatch` | [commands/dispatch.md](commands/dispatch.md) | Phase 3 | 任务链创建与依赖管理 |
|
||||
| `monitor` | [commands/monitor.md](commands/monitor.md) | Phase 4 | 消息总线轮询与协调循环 |
|
||||
|
||||
### Subagent Capabilities
|
||||
|
||||
> Coordinator 不直接使用 subagent(通过 worker 角色间接使用)
|
||||
|
||||
### CLI Capabilities
|
||||
|
||||
> Coordinator 不直接使用 CLI 分析工具
|
||||
|
||||
## Execution
|
||||
|
||||
### Phase 1: Requirement Clarification
|
||||
|
||||
```javascript
|
||||
const args = "$ARGUMENTS"
|
||||
|
||||
// 提取任务描述
|
||||
const taskDescription = args.replace(/--role[=\s]+\w+/, '').replace(/--team[=\s]+[\w-]+/, '').replace(/--mode[=\s]+\w+/, '').trim()
|
||||
|
||||
// QA 模式选择
|
||||
function detectQAMode(args, desc) {
|
||||
const modeMatch = args.match(/--mode[=\s]+(discovery|testing|full)/)
|
||||
if (modeMatch) return modeMatch[1]
|
||||
if (/发现|扫描|scan|discover|issue|问题/.test(desc)) return 'discovery'
|
||||
if (/测试|test|覆盖|coverage|TDD/.test(desc)) return 'testing'
|
||||
return 'full'
|
||||
}
|
||||
|
||||
let qaMode = detectQAMode(args, taskDescription)
|
||||
|
||||
// 简单任务可跳过确认
|
||||
if (!taskDescription || taskDescription.length < 10) {
|
||||
const clarification = AskUserQuestion({
|
||||
questions: [{
|
||||
question: "请描述 QA 目标(哪些模块需要质量保障?关注哪些方面?)",
|
||||
header: "QA Target",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{ label: "自定义", description: "输入具体描述" },
|
||||
{ label: "全项目扫描", description: "对整个项目进行多视角质量扫描" },
|
||||
{ label: "变更测试", description: "针对最近代码变更生成和执行测试" },
|
||||
{ label: "完整QA流程", description: "扫描+测试+分析的完整闭环" }
|
||||
]
|
||||
}]
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
### Phase 2: Create Team + Spawn Teammates
|
||||
|
||||
```javascript
|
||||
const teamName = "quality-assurance"
|
||||
const sessionSlug = taskDescription.slice(0, 30).replace(/[^a-zA-Z0-9\u4e00-\u9fa5]/g, '-')
|
||||
const sessionDate = new Date().toISOString().slice(0, 10)
|
||||
const sessionFolder = `.workflow/.team/QA-${sessionSlug}-${sessionDate}`
|
||||
Bash(`mkdir -p "${sessionFolder}"`)
|
||||
|
||||
// 初始化 shared memory
|
||||
Write(`${sessionFolder}/shared-memory.json`, JSON.stringify({
|
||||
discovered_issues: [],
|
||||
test_strategy: {},
|
||||
generated_tests: {},
|
||||
execution_results: {},
|
||||
defect_patterns: [],
|
||||
coverage_history: [],
|
||||
quality_score: null
|
||||
}, null, 2))
|
||||
|
||||
TeamCreate({ team_name: teamName })
|
||||
|
||||
// Spawn teammates (see SKILL.md Coordinator Spawn Template)
|
||||
// Scout, Strategist, Generator, Executor, Analyst
|
||||
```
|
||||
|
||||
### Phase 3: Create Task Chain
|
||||
|
||||
根据 qaMode 创建不同的任务链:
|
||||
|
||||
```javascript
|
||||
// Read commands/dispatch.md for full implementation
|
||||
Read("commands/dispatch.md")
|
||||
```
|
||||
|
||||
**Discovery Mode**:
|
||||
```
|
||||
SCOUT-001 → QASTRAT-001 → QAGEN-001 → QARUN-001 → QAANA-001
|
||||
```
|
||||
|
||||
**Testing Mode** (跳过 scout):
|
||||
```
|
||||
QASTRAT-001 → QAGEN-001(L1) → QARUN-001(L1) → QAGEN-002(L2) → QARUN-002(L2) → QAANA-001
|
||||
```
|
||||
|
||||
**Full QA Mode**:
|
||||
```
|
||||
SCOUT-001 → QASTRAT-001 → [QAGEN-001(L1) + QAGEN-002(L2)](parallel) → [QARUN-001 + QARUN-002](parallel) → QAANA-001 → SCOUT-002(回归)
|
||||
```
|
||||
|
||||
### Phase 4: Coordination Loop
|
||||
|
||||
```javascript
|
||||
// Read commands/monitor.md for full implementation
|
||||
Read("commands/monitor.md")
|
||||
```
|
||||
|
||||
| Received Message | Action |
|
||||
|-----------------|--------|
|
||||
| `scan_ready` | 标记 SCOUT complete → 解锁 QASTRAT |
|
||||
| `strategy_ready` | 标记 QASTRAT complete → 解锁 QAGEN |
|
||||
| `tests_generated` | 标记 QAGEN complete → 解锁 QARUN |
|
||||
| `tests_passed` | 标记 QARUN complete → 解锁 QAANA 或下一层 |
|
||||
| `tests_failed` | 评估覆盖率 → 触发 GC 循环(gc_loop_trigger)或继续 |
|
||||
| `analysis_ready` | 标记 QAANA complete → 评估质量门控 |
|
||||
| Worker: `error` | 评估严重性 → 重试或上报用户 |
|
||||
|
||||
**GC 循环触发逻辑**:
|
||||
```javascript
|
||||
if (coverage < targetCoverage && gcIteration < 3) {
|
||||
// 创建 QAGEN-fix 任务 → QARUN 重新执行
|
||||
gcIteration++
|
||||
} else if (gcIteration >= 3) {
|
||||
// 接受当前覆盖率,继续流水线
|
||||
team_msg({ type: "quality_gate", data: { status: "CONDITIONAL", coverage } })
|
||||
}
|
||||
```
|
||||
|
||||
### Phase 5: Report + Persist
|
||||
|
||||
```javascript
|
||||
// 读取 shared memory 汇总结果
|
||||
const memory = JSON.parse(Read(`${sessionFolder}/shared-memory.json`))
|
||||
|
||||
const report = {
|
||||
mode: qaMode,
|
||||
issues_found: memory.discovered_issues?.length || 0,
|
||||
test_strategy: memory.test_strategy?.layers || [],
|
||||
tests_generated: Object.keys(memory.generated_tests || {}).length,
|
||||
pass_rate: memory.execution_results?.pass_rate || 0,
|
||||
coverage: memory.execution_results?.coverage || 0,
|
||||
quality_score: memory.quality_score || 'N/A',
|
||||
defect_patterns: memory.defect_patterns?.length || 0
|
||||
}
|
||||
|
||||
mcp__ccw-tools__team_msg({
|
||||
operation: "log", team: teamName, from: "coordinator",
|
||||
to: "user", type: "quality_gate",
|
||||
summary: `[coordinator] QA完成: ${report.issues_found}个问题, 覆盖率${report.coverage}%, 质量分${report.quality_score}`
|
||||
})
|
||||
|
||||
SendMessage({
|
||||
content: `## [coordinator] Quality Assurance Report\n\n${JSON.stringify(report, null, 2)}`,
|
||||
summary: `[coordinator] QA report: ${report.quality_score}`
|
||||
})
|
||||
|
||||
// 询问下一步
|
||||
AskUserQuestion({
|
||||
questions: [{
|
||||
question: "QA 流程已完成。下一步:",
|
||||
header: "Next",
|
||||
multiSelect: false,
|
||||
options: [
|
||||
{ label: "新目标", description: "对新模块/需求执行QA" },
|
||||
{ label: "深入分析", description: "对发现的问题进行更深入分析" },
|
||||
{ label: "关闭团队", description: "关闭所有 teammate 并清理" }
|
||||
]
|
||||
}]
|
||||
})
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Scenario | Resolution |
|
||||
|----------|------------|
|
||||
| Teammate unresponsive | Send follow-up, 2x → respawn |
|
||||
| Scout finds nothing | Skip to testing mode |
|
||||
| GC loop stuck >3 iterations | Accept current coverage, continue pipeline |
|
||||
| Test environment broken | Notify user, suggest manual fix |
|
||||
| All tasks completed but quality_score < 60 | Report with WARNING, suggest re-run with deeper analysis |
|
||||
@@ -0,0 +1,220 @@
|
||||
# Command: run-fix-cycle
|
||||
|
||||
> 迭代测试执行与自动修复。运行测试套件,解析结果,失败时委派 code-developer 修复,最多迭代 5 次。
|
||||
|
||||
## When to Use
|
||||
|
||||
- Phase 3 of Executor
|
||||
- 测试代码已生成,需要执行并验证
|
||||
- GC 循环中重新执行修复后的测试
|
||||
|
||||
**Trigger conditions**:
|
||||
- QARUN-* 任务进入执行阶段
|
||||
- Generator 报告测试生成完成
|
||||
- GC 循环中 coordinator 创建的重新执行任务
|
||||
|
||||
## Strategy
|
||||
|
||||
### Delegation Mode
|
||||
|
||||
**Mode**: Sequential Delegation(修复时)/ Direct(执行时)
|
||||
**Agent Type**: `code-developer`(仅用于修复)
|
||||
**Max Iterations**: 5
|
||||
|
||||
### Decision Logic
|
||||
|
||||
```javascript
|
||||
// 每次迭代的决策
|
||||
function shouldContinue(iteration, passRate, testsFailed) {
|
||||
if (iteration >= MAX_ITERATIONS) return false
|
||||
if (testsFailed === 0) return false // 全部通过
|
||||
if (passRate >= 95 && iteration >= 2) return false // 足够好
|
||||
return true
|
||||
}
|
||||
```
|
||||
|
||||
## Execution Steps
|
||||
|
||||
### Step 1: Context Preparation
|
||||
|
||||
```javascript
|
||||
// 检测测试框架和命令
|
||||
const strategy = sharedMemory.test_strategy || {}
|
||||
const framework = strategy.test_framework || 'vitest'
|
||||
const targetLayer = task.description.match(/layer:\s*(L[123])/)?.[1] || 'L1'
|
||||
|
||||
// 构建测试命令
|
||||
function buildTestCommand(framework, layer) {
|
||||
const layerFilter = {
|
||||
'L1': 'unit',
|
||||
'L2': 'integration',
|
||||
'L3': 'e2e'
|
||||
}
|
||||
|
||||
const commands = {
|
||||
'vitest': `npx vitest run --coverage --reporter=json --outputFile=test-results.json`,
|
||||
'jest': `npx jest --coverage --json --outputFile=test-results.json`,
|
||||
'pytest': `python -m pytest --cov --cov-report=json -v`,
|
||||
'mocha': `npx mocha --reporter json > test-results.json`
|
||||
}
|
||||
|
||||
let cmd = commands[framework] || 'npm test -- --coverage'
|
||||
|
||||
// 添加层级过滤(如果测试文件按目录组织)
|
||||
const filter = layerFilter[layer]
|
||||
if (filter && framework === 'vitest') {
|
||||
cmd += ` --testPathPattern="${filter}"`
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
const testCommand = buildTestCommand(framework, targetLayer)
|
||||
|
||||
// 获取关联的测试文件
|
||||
const generatedTests = sharedMemory.generated_tests?.[targetLayer]?.files || []
|
||||
```
|
||||
|
||||
### Step 2: Execute Strategy
|
||||
|
||||
```javascript
|
||||
let iteration = 0
|
||||
const MAX_ITERATIONS = 5
|
||||
let lastOutput = ''
|
||||
let passRate = 0
|
||||
let coverage = 0
|
||||
let testsPassed = 0
|
||||
let testsFailed = 0
|
||||
|
||||
while (iteration < MAX_ITERATIONS) {
|
||||
// ===== EXECUTE TESTS =====
|
||||
lastOutput = Bash(`${testCommand} 2>&1 || true`)
|
||||
|
||||
// ===== PARSE RESULTS =====
|
||||
// 解析通过/失败数
|
||||
const passedMatch = lastOutput.match(/(\d+)\s*(?:passed|passing)/)
|
||||
const failedMatch = lastOutput.match(/(\d+)\s*(?:failed|failing)/)
|
||||
testsPassed = passedMatch ? parseInt(passedMatch[1]) : 0
|
||||
testsFailed = failedMatch ? parseInt(failedMatch[1]) : 0
|
||||
const testsTotal = testsPassed + testsFailed
|
||||
|
||||
passRate = testsTotal > 0 ? Math.round(testsPassed / testsTotal * 100) : 0
|
||||
|
||||
// 解析覆盖率
|
||||
try {
|
||||
const coverageJson = JSON.parse(Read('coverage/coverage-summary.json'))
|
||||
coverage = coverageJson.total?.lines?.pct || 0
|
||||
} catch {
|
||||
// 尝试从输出解析
|
||||
const covMatch = lastOutput.match(/(?:Lines|Stmts|All files)\s*[:|]\s*(\d+\.?\d*)%/)
|
||||
coverage = covMatch ? parseFloat(covMatch[1]) : 0
|
||||
}
|
||||
|
||||
// ===== CHECK PASS =====
|
||||
if (testsFailed === 0) {
|
||||
break // 全部通过
|
||||
}
|
||||
|
||||
// ===== SHOULD CONTINUE? =====
|
||||
if (!shouldContinue(iteration + 1, passRate, testsFailed)) {
|
||||
break
|
||||
}
|
||||
|
||||
// ===== AUTO-FIX =====
|
||||
iteration++
|
||||
|
||||
// 提取失败详情
|
||||
const failureLines = lastOutput.split('\n')
|
||||
.filter(l => /FAIL|Error|AssertionError|Expected|Received|TypeError|ReferenceError/.test(l))
|
||||
.slice(0, 30)
|
||||
.join('\n')
|
||||
|
||||
// 委派修复给 code-developer
|
||||
Task({
|
||||
subagent_type: "code-developer",
|
||||
run_in_background: false,
|
||||
description: `Fix ${testsFailed} test failures (iteration ${iteration}/${MAX_ITERATIONS})`,
|
||||
prompt: `## Goal
|
||||
Fix failing tests. ONLY modify test files, NEVER modify source code.
|
||||
|
||||
## Test Output
|
||||
\`\`\`
|
||||
${failureLines}
|
||||
\`\`\`
|
||||
|
||||
## Test Files to Fix
|
||||
${generatedTests.map(f => `- ${f}`).join('\n')}
|
||||
|
||||
## Rules
|
||||
- Read each failing test file before modifying
|
||||
- Fix: incorrect assertions, missing imports, wrong mocks, setup issues
|
||||
- Do NOT: skip tests, add \`@ts-ignore\`, use \`as any\`, modify source code
|
||||
- Keep existing test structure and naming
|
||||
- If a test is fundamentally wrong about expected behavior, fix the assertion to match actual source behavior`
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
### Step 3: Result Processing
|
||||
|
||||
```javascript
|
||||
const resultData = {
|
||||
layer: targetLayer,
|
||||
framework: framework,
|
||||
iterations: iteration,
|
||||
pass_rate: passRate,
|
||||
coverage: coverage,
|
||||
tests_passed: testsPassed,
|
||||
tests_failed: testsFailed,
|
||||
all_passed: testsFailed === 0,
|
||||
max_iterations_reached: iteration >= MAX_ITERATIONS
|
||||
}
|
||||
|
||||
// 保存执行结果
|
||||
Bash(`mkdir -p "${sessionFolder}/results"`)
|
||||
Write(`${sessionFolder}/results/run-${targetLayer}.json`, JSON.stringify(resultData, null, 2))
|
||||
|
||||
// 保存最后一次测试输出(截取关键部分)
|
||||
const outputSummary = lastOutput.split('\n').slice(-30).join('\n')
|
||||
Write(`${sessionFolder}/results/output-${targetLayer}.txt`, outputSummary)
|
||||
|
||||
// 更新 shared memory
|
||||
sharedMemory.execution_results = sharedMemory.execution_results || {}
|
||||
sharedMemory.execution_results[targetLayer] = resultData
|
||||
sharedMemory.execution_results.pass_rate = passRate
|
||||
sharedMemory.execution_results.coverage = coverage
|
||||
Write(`${sessionFolder}/shared-memory.json`, JSON.stringify(sharedMemory, null, 2))
|
||||
```
|
||||
|
||||
## Output Format
|
||||
|
||||
```
|
||||
## Test Execution Results
|
||||
|
||||
### Layer: [L1|L2|L3]
|
||||
### Framework: [vitest|jest|pytest]
|
||||
### Status: [PASS|FAIL]
|
||||
|
||||
### Results
|
||||
- Tests passed: [count]
|
||||
- Tests failed: [count]
|
||||
- Pass rate: [percent]%
|
||||
- Coverage: [percent]%
|
||||
- Fix iterations: [count]/[max]
|
||||
|
||||
### Failure Details (if any)
|
||||
- [test name]: [error description]
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Scenario | Resolution |
|
||||
|----------|------------|
|
||||
| Test command not found | Try fallback: npm test → npx vitest → npx jest → pytest |
|
||||
| Test environment broken | Report error to coordinator, suggest manual fix |
|
||||
| Max iterations reached with failures | Report current state, let coordinator decide (GC loop or accept) |
|
||||
| Coverage data unavailable | Report 0%, note coverage collection failure |
|
||||
| Sub-agent fix introduces new failures | Revert last fix, try different approach |
|
||||
| No test files to run | Report empty, notify coordinator |
|
||||
| Agent/CLI failure | Retry once, then fallback to inline execution |
|
||||
| Timeout (>5 min) | Report partial results, notify coordinator |
|
||||
252
.claude/skills/team-quality-assurance/roles/executor/role.md
Normal file
252
.claude/skills/team-quality-assurance/roles/executor/role.md
Normal file
@@ -0,0 +1,252 @@
|
||||
# Role: executor
|
||||
|
||||
测试执行者。运行测试套件,收集覆盖率数据,在测试失败时进行自动修复循环。实现 Generator-Executor(GC)循环中的执行端。
|
||||
|
||||
## Role Identity
|
||||
|
||||
- **Name**: `executor`
|
||||
- **Task Prefix**: `QARUN-*`
|
||||
- **Responsibility**: Validation(测试执行与修复)
|
||||
- **Communication**: SendMessage to coordinator only
|
||||
- **Output Tag**: `[executor]`
|
||||
|
||||
## Role Boundaries
|
||||
|
||||
### MUST
|
||||
|
||||
- 仅处理 `QARUN-*` 前缀的任务
|
||||
- 所有输出必须带 `[executor]` 标识
|
||||
- 执行测试并收集覆盖率
|
||||
- 在失败时尝试自动修复
|
||||
|
||||
### MUST NOT
|
||||
|
||||
- ❌ 从零生成新测试(那是 generator 的职责)
|
||||
- ❌ 修改源代码(除非修复测试本身)
|
||||
- ❌ 为其他角色创建任务
|
||||
- ❌ 直接与其他 worker 通信
|
||||
|
||||
## Message Types
|
||||
|
||||
| Type | Direction | Trigger | Description |
|
||||
|------|-----------|---------|-------------|
|
||||
| `tests_passed` | executor → coordinator | 所有测试通过 | 包含覆盖率数据 |
|
||||
| `tests_failed` | executor → coordinator | 测试失败 | 包含失败详情和修复尝试 |
|
||||
| `coverage_report` | executor → coordinator | 覆盖率收集完成 | 覆盖率数据 |
|
||||
| `error` | executor → coordinator | 执行环境错误 | 阻塞性错误 |
|
||||
|
||||
## Toolbox
|
||||
|
||||
### Available Commands
|
||||
|
||||
| Command | File | Phase | Description |
|
||||
|---------|------|-------|-------------|
|
||||
| `run-fix-cycle` | [commands/run-fix-cycle.md](commands/run-fix-cycle.md) | Phase 3 | 迭代测试执行与自动修复 |
|
||||
|
||||
### Subagent Capabilities
|
||||
|
||||
| Agent Type | Used By | Purpose |
|
||||
|------------|---------|---------|
|
||||
| `code-developer` | run-fix-cycle.md | 测试失败自动修复 |
|
||||
|
||||
## Execution (5-Phase)
|
||||
|
||||
### Phase 1: Task Discovery
|
||||
|
||||
```javascript
|
||||
const tasks = TaskList()
|
||||
const myTasks = tasks.filter(t =>
|
||||
t.subject.startsWith('QARUN-') &&
|
||||
t.owner === 'executor' &&
|
||||
t.status === 'pending' &&
|
||||
t.blockedBy.length === 0
|
||||
)
|
||||
|
||||
if (myTasks.length === 0) return
|
||||
const task = TaskGet({ taskId: myTasks[0].id })
|
||||
TaskUpdate({ taskId: task.id, status: 'in_progress' })
|
||||
```
|
||||
|
||||
### Phase 2: Environment Detection
|
||||
|
||||
```javascript
|
||||
// 读取 shared memory
|
||||
const sessionFolder = task.description.match(/session:\s*(.+)/)?.[1] || '.'
|
||||
let sharedMemory = {}
|
||||
try { sharedMemory = JSON.parse(Read(`${sessionFolder}/shared-memory.json`)) } catch {}
|
||||
|
||||
const strategy = sharedMemory.test_strategy || {}
|
||||
const generatedTests = sharedMemory.generated_tests || {}
|
||||
const targetLayer = task.description.match(/layer:\s*(L[123])/)?.[1] || 'L1'
|
||||
|
||||
// 检测测试命令
|
||||
function detectTestCommand(framework, layer) {
|
||||
const commands = {
|
||||
'jest': `npx jest --coverage --testPathPattern="${layer === 'L1' ? 'unit' : layer === 'L2' ? 'integration' : 'e2e'}"`,
|
||||
'vitest': `npx vitest run --coverage --reporter=json`,
|
||||
'pytest': `python -m pytest --cov --cov-report=json`,
|
||||
'mocha': `npx mocha --reporter json`,
|
||||
}
|
||||
return commands[framework] || 'npm test -- --coverage'
|
||||
}
|
||||
|
||||
const testCommand = detectTestCommand(strategy.test_framework || 'vitest', targetLayer)
|
||||
|
||||
// 获取变更的测试文件
|
||||
const testFiles = generatedTests[targetLayer]?.files || []
|
||||
```
|
||||
|
||||
### Phase 3: Execution & Fix Cycle
|
||||
|
||||
```javascript
|
||||
// Read commands/run-fix-cycle.md for full implementation
|
||||
Read("commands/run-fix-cycle.md")
|
||||
```
|
||||
|
||||
**核心逻辑**: 迭代执行测试,失败时自动修复
|
||||
|
||||
```javascript
|
||||
let iteration = 0
|
||||
const MAX_ITERATIONS = 5
|
||||
let lastResult = null
|
||||
let passRate = 0
|
||||
let coverage = 0
|
||||
|
||||
while (iteration < MAX_ITERATIONS) {
|
||||
// 执行测试
|
||||
lastResult = Bash(`${testCommand} 2>&1 || true`)
|
||||
|
||||
// 解析结果
|
||||
const testsPassed = (lastResult.match(/(\d+) passed/)?.[1] || 0) * 1
|
||||
const testsFailed = (lastResult.match(/(\d+) failed/)?.[1] || 0) * 1
|
||||
const testsTotal = testsPassed + testsFailed
|
||||
passRate = testsTotal > 0 ? (testsPassed / testsTotal * 100) : 0
|
||||
|
||||
// 解析覆盖率
|
||||
try {
|
||||
const coverageJson = JSON.parse(Read('coverage/coverage-summary.json'))
|
||||
coverage = coverageJson.total?.lines?.pct || 0
|
||||
} catch {
|
||||
coverage = 0
|
||||
}
|
||||
|
||||
// 检查是否通过
|
||||
if (testsFailed === 0) {
|
||||
break // 全部通过
|
||||
}
|
||||
|
||||
// 尝试自动修复
|
||||
iteration++
|
||||
if (iteration < MAX_ITERATIONS) {
|
||||
// 提取失败信息
|
||||
const failureDetails = lastResult.split('\n')
|
||||
.filter(l => /FAIL|Error|AssertionError|Expected|Received/.test(l))
|
||||
.slice(0, 20)
|
||||
.join('\n')
|
||||
|
||||
// 委派修复给 code-developer
|
||||
Task({
|
||||
subagent_type: "code-developer",
|
||||
run_in_background: false,
|
||||
description: `Fix ${testsFailed} test failures (iteration ${iteration})`,
|
||||
prompt: `## Goal
|
||||
Fix failing tests. Do NOT modify source code, only fix test files.
|
||||
|
||||
## Test Failures
|
||||
${failureDetails}
|
||||
|
||||
## Test Files
|
||||
${testFiles.map(f => `- ${f}`).join('\n')}
|
||||
|
||||
## Instructions
|
||||
- Read failing test files
|
||||
- Fix assertions, imports, or test setup
|
||||
- Do NOT change source code
|
||||
- Do NOT skip/ignore tests`
|
||||
})
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Phase 4: Result Analysis
|
||||
|
||||
```javascript
|
||||
const resultData = {
|
||||
layer: targetLayer,
|
||||
iterations: iteration,
|
||||
pass_rate: passRate,
|
||||
coverage: coverage,
|
||||
tests_passed: lastResult?.match(/(\d+) passed/)?.[1] || 0,
|
||||
tests_failed: lastResult?.match(/(\d+) failed/)?.[1] || 0,
|
||||
all_passed: passRate === 100 || (lastResult && !lastResult.includes('FAIL'))
|
||||
}
|
||||
|
||||
// 保存执行结果
|
||||
Bash(`mkdir -p "${sessionFolder}/results"`)
|
||||
Write(`${sessionFolder}/results/run-${targetLayer}.json`, JSON.stringify(resultData, null, 2))
|
||||
|
||||
// 更新 shared memory
|
||||
sharedMemory.execution_results = sharedMemory.execution_results || {}
|
||||
sharedMemory.execution_results[targetLayer] = resultData
|
||||
sharedMemory.execution_results.pass_rate = passRate
|
||||
sharedMemory.execution_results.coverage = coverage
|
||||
Write(`${sessionFolder}/shared-memory.json`, JSON.stringify(sharedMemory, null, 2))
|
||||
```
|
||||
|
||||
### Phase 5: Report to Coordinator
|
||||
|
||||
```javascript
|
||||
const statusMsg = resultData.all_passed
|
||||
? `全部通过 (${resultData.tests_passed} tests, 覆盖率 ${coverage}%)`
|
||||
: `${resultData.tests_failed} 个失败 (${iteration}次修复尝试, 覆盖率 ${coverage}%)`
|
||||
|
||||
const msgType = resultData.all_passed ? 'tests_passed' : 'tests_failed'
|
||||
|
||||
mcp__ccw-tools__team_msg({
|
||||
operation: "log",
|
||||
team: teamName,
|
||||
from: "executor",
|
||||
to: "coordinator",
|
||||
type: msgType,
|
||||
summary: `[executor] ${targetLayer}: ${statusMsg}`,
|
||||
ref: `${sessionFolder}/results/run-${targetLayer}.json`,
|
||||
data: { pass_rate: passRate, coverage, iterations: iteration }
|
||||
})
|
||||
|
||||
SendMessage({
|
||||
type: "message",
|
||||
recipient: "coordinator",
|
||||
content: `## [executor] Test Execution Results
|
||||
|
||||
**Task**: ${task.subject}
|
||||
**Layer**: ${targetLayer}
|
||||
**Status**: ${resultData.all_passed ? 'PASS' : 'FAIL'}
|
||||
**Pass Rate**: ${passRate}%
|
||||
**Coverage**: ${coverage}%
|
||||
**Iterations**: ${iteration}/${MAX_ITERATIONS}
|
||||
|
||||
### Details
|
||||
- Tests passed: ${resultData.tests_passed}
|
||||
- Tests failed: ${resultData.tests_failed}`,
|
||||
summary: `[executor] QARUN ${targetLayer}: ${resultData.all_passed ? 'PASS' : 'FAIL'} ${passRate}%`
|
||||
})
|
||||
|
||||
TaskUpdate({ taskId: task.id, status: 'completed' })
|
||||
|
||||
const nextTasks = TaskList().filter(t =>
|
||||
t.subject.startsWith('QARUN-') && t.owner === 'executor' &&
|
||||
t.status === 'pending' && t.blockedBy.length === 0
|
||||
)
|
||||
if (nextTasks.length > 0) { /* back to Phase 1 */ }
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Scenario | Resolution |
|
||||
|----------|------------|
|
||||
| No QARUN-* tasks available | Idle, wait for coordinator |
|
||||
| Test command fails to execute | Try fallback: `npm test`, `npx vitest run`, `pytest` |
|
||||
| Max iterations reached | Report current pass rate, let coordinator decide |
|
||||
| Coverage data unavailable | Report 0%, note coverage collection failure |
|
||||
| Test environment broken | SendMessage error to coordinator, suggest manual fix |
|
||||
| Sub-agent fix introduces new failures | Revert fix, try next failure |
|
||||
@@ -0,0 +1,258 @@
|
||||
# Command: generate-tests
|
||||
|
||||
> 按层级生成测试代码。根据 strategist 策略和项目现有测试模式,生成 L1/L2/L3 测试用例。
|
||||
|
||||
## When to Use
|
||||
|
||||
- Phase 3 of Generator
|
||||
- 策略已制定,需要生成对应层级的测试代码
|
||||
- GC 循环中修订失败的测试
|
||||
|
||||
**Trigger conditions**:
|
||||
- QAGEN-* 任务进入执行阶段
|
||||
- 测试策略中包含当前层级
|
||||
- GC 循环触发修复任务(QAGEN-fix-*)
|
||||
|
||||
## Strategy
|
||||
|
||||
### Delegation Mode
|
||||
|
||||
**Mode**: Sequential Delegation(复杂时)/ Direct(简单时)
|
||||
**Agent Type**: `code-developer`
|
||||
**Delegation Scope**: Per-layer
|
||||
|
||||
### Decision Logic
|
||||
|
||||
```javascript
|
||||
const focusFiles = layerConfig.focus_files || []
|
||||
const isGCFix = task.subject.includes('fix')
|
||||
|
||||
if (isGCFix) {
|
||||
// GC 修复模式:读取失败信息,针对性修复
|
||||
mode = 'gc-fix'
|
||||
} else if (focusFiles.length <= 3) {
|
||||
// 直接生成:内联 Read → 分析 → Write
|
||||
mode = 'direct'
|
||||
} else {
|
||||
// 委派给 code-developer
|
||||
mode = 'delegate'
|
||||
}
|
||||
```
|
||||
|
||||
## Execution Steps
|
||||
|
||||
### Step 1: Context Preparation
|
||||
|
||||
```javascript
|
||||
// 从 shared memory 获取策略
|
||||
const strategy = sharedMemory.test_strategy || {}
|
||||
const targetLayer = task.description.match(/layer:\s*(L[123])/)?.[1] || 'L1'
|
||||
|
||||
// 确定层级配置
|
||||
const layerConfig = strategy.layers?.find(l => l.level === targetLayer) || {
|
||||
level: targetLayer,
|
||||
name: targetLayer === 'L1' ? 'Unit Tests' : targetLayer === 'L2' ? 'Integration Tests' : 'E2E Tests',
|
||||
target_coverage: targetLayer === 'L1' ? 80 : targetLayer === 'L2' ? 60 : 40,
|
||||
focus_files: []
|
||||
}
|
||||
|
||||
// 学习现有测试模式(必须找 3 个相似测试文件)
|
||||
const existingTests = Glob(`**/*.{test,spec}.{ts,tsx,js,jsx}`)
|
||||
const testPatterns = existingTests.slice(0, 3).map(f => ({
|
||||
path: f,
|
||||
content: Read(f)
|
||||
}))
|
||||
|
||||
// 检测测试约定
|
||||
const testConventions = detectTestConventions(testPatterns)
|
||||
```
|
||||
|
||||
### Step 2: Execute Strategy
|
||||
|
||||
```javascript
|
||||
if (mode === 'gc-fix') {
|
||||
// GC 修复模式
|
||||
// 读取失败信息
|
||||
const failedTests = sharedMemory.execution_results?.[targetLayer]
|
||||
const failureOutput = Read(`${sessionFolder}/results/run-${targetLayer}.json`)
|
||||
|
||||
Task({
|
||||
subagent_type: "code-developer",
|
||||
run_in_background: false,
|
||||
description: `Fix failing ${targetLayer} tests (GC iteration)`,
|
||||
prompt: `## Goal
|
||||
Fix the failing tests based on execution results. Do NOT modify source code.
|
||||
|
||||
## Test Execution Results
|
||||
${JSON.stringify(failedTests, null, 2)}
|
||||
|
||||
## Test Conventions
|
||||
${JSON.stringify(testConventions, null, 2)}
|
||||
|
||||
## Instructions
|
||||
- Read each failing test file
|
||||
- Fix assertions, imports, mocks, or test setup
|
||||
- Ensure tests match actual source behavior
|
||||
- Do NOT skip or ignore tests
|
||||
- Do NOT modify source files`
|
||||
})
|
||||
|
||||
} else if (mode === 'direct') {
|
||||
// 直接生成模式
|
||||
const focusFiles = layerConfig.focus_files || []
|
||||
|
||||
for (const sourceFile of focusFiles) {
|
||||
const sourceContent = Read(sourceFile)
|
||||
|
||||
// 确定测试文件路径(遵循项目约定)
|
||||
const testPath = determineTestPath(sourceFile, testConventions)
|
||||
|
||||
// 检查是否已有测试
|
||||
let existingTest = null
|
||||
try { existingTest = Read(testPath) } catch {}
|
||||
|
||||
if (existingTest) {
|
||||
// 补充现有测试:分析缺失的测试用例
|
||||
const missingCases = analyzeMissingCases(sourceContent, existingTest)
|
||||
if (missingCases.length > 0) {
|
||||
// 追加测试用例
|
||||
Edit({
|
||||
file_path: testPath,
|
||||
old_string: findLastTestBlock(existingTest),
|
||||
new_string: `${findLastTestBlock(existingTest)}\n\n${generateCases(missingCases, testConventions)}`
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// 创建新测试文件
|
||||
const testContent = generateFullTestFile(sourceFile, sourceContent, testConventions, targetLayer)
|
||||
Write(testPath, testContent)
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// 委派模式
|
||||
const focusFiles = layerConfig.focus_files || []
|
||||
|
||||
Task({
|
||||
subagent_type: "code-developer",
|
||||
run_in_background: false,
|
||||
description: `Generate ${targetLayer} tests for ${focusFiles.length} files`,
|
||||
prompt: `## Goal
|
||||
Generate ${layerConfig.name} for the following source files.
|
||||
|
||||
## Test Framework
|
||||
${strategy.test_framework || 'vitest'}
|
||||
|
||||
## Existing Test Patterns (MUST follow these exactly)
|
||||
${testPatterns.map(t => `### ${t.path}\n\`\`\`\n${t.content.substring(0, 800)}\n\`\`\``).join('\n\n')}
|
||||
|
||||
## Test Conventions
|
||||
- Test file location: ${testConventions.location}
|
||||
- Import style: ${testConventions.importStyle}
|
||||
- Describe/it nesting: ${testConventions.nesting}
|
||||
|
||||
## Source Files to Test
|
||||
${focusFiles.map(f => `- ${f}`).join('\n')}
|
||||
|
||||
## Requirements
|
||||
- Follow existing test patterns exactly (import style, naming, structure)
|
||||
- Cover: happy path + edge cases + error cases
|
||||
- Target coverage: ${layerConfig.target_coverage}%
|
||||
- Do NOT modify source files, only create/modify test files
|
||||
- Do NOT use \`any\` type assertions
|
||||
- Do NOT skip or mark tests as TODO without implementation`
|
||||
})
|
||||
}
|
||||
|
||||
// 辅助函数
|
||||
function determineTestPath(sourceFile, conventions) {
|
||||
if (conventions.location === 'colocated') {
|
||||
return sourceFile.replace(/\.(ts|tsx|js|jsx)$/, `.test.$1`)
|
||||
} else if (conventions.location === '__tests__') {
|
||||
const dir = sourceFile.substring(0, sourceFile.lastIndexOf('/'))
|
||||
const name = sourceFile.substring(sourceFile.lastIndexOf('/') + 1)
|
||||
return `${dir}/__tests__/${name.replace(/\.(ts|tsx|js|jsx)$/, `.test.$1`)}`
|
||||
}
|
||||
return sourceFile.replace(/\.(ts|tsx|js|jsx)$/, `.test.$1`)
|
||||
}
|
||||
|
||||
function detectTestConventions(patterns) {
|
||||
const conventions = {
|
||||
location: 'colocated', // or '__tests__'
|
||||
importStyle: 'named', // or 'default'
|
||||
nesting: 'describe-it', // or 'test-only'
|
||||
framework: 'vitest'
|
||||
}
|
||||
|
||||
for (const p of patterns) {
|
||||
if (p.path.includes('__tests__')) conventions.location = '__tests__'
|
||||
if (p.content.includes("import { describe")) conventions.nesting = 'describe-it'
|
||||
if (p.content.includes("from 'vitest'")) conventions.framework = 'vitest'
|
||||
if (p.content.includes("from '@jest'") || p.content.includes("from 'jest'")) conventions.framework = 'jest'
|
||||
}
|
||||
|
||||
return conventions
|
||||
}
|
||||
```
|
||||
|
||||
### Step 3: Result Processing
|
||||
|
||||
```javascript
|
||||
// 收集生成/修改的测试文件
|
||||
const generatedTests = Bash(`git diff --name-only`).split('\n')
|
||||
.filter(f => /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(f))
|
||||
|
||||
// TypeScript 语法检查
|
||||
const syntaxResult = Bash(`npx tsc --noEmit ${generatedTests.join(' ')} 2>&1 || true`)
|
||||
const hasSyntaxErrors = syntaxResult.includes('error TS')
|
||||
|
||||
// 自动修复语法错误(最多 3 次)
|
||||
if (hasSyntaxErrors) {
|
||||
let fixAttempt = 0
|
||||
while (fixAttempt < 3 && syntaxResult.includes('error TS')) {
|
||||
const errors = syntaxResult.split('\n').filter(l => l.includes('error TS')).slice(0, 5)
|
||||
// 尝试修复每个错误...
|
||||
fixAttempt++
|
||||
}
|
||||
}
|
||||
|
||||
// 更新 shared memory
|
||||
const testInfo = {
|
||||
layer: targetLayer,
|
||||
files: generatedTests,
|
||||
count: generatedTests.length,
|
||||
syntax_clean: !hasSyntaxErrors,
|
||||
mode: mode,
|
||||
gc_fix: mode === 'gc-fix'
|
||||
}
|
||||
|
||||
sharedMemory.generated_tests = sharedMemory.generated_tests || {}
|
||||
sharedMemory.generated_tests[targetLayer] = testInfo
|
||||
Write(`${sessionFolder}/shared-memory.json`, JSON.stringify(sharedMemory, null, 2))
|
||||
```
|
||||
|
||||
## Output Format
|
||||
|
||||
```
|
||||
## Test Generation Results
|
||||
|
||||
### Layer: [L1|L2|L3]
|
||||
### Mode: [direct|delegate|gc-fix]
|
||||
### Files Generated: [count]
|
||||
- [test file path]
|
||||
|
||||
### Syntax Check: PASS/FAIL
|
||||
### Conventions Applied: [framework], [location], [nesting]
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Scenario | Resolution |
|
||||
|----------|------------|
|
||||
| No focus files in strategy | Generate L1 tests for all source files in scope |
|
||||
| No existing test patterns | Use framework defaults (vitest/jest/pytest) |
|
||||
| Sub-agent failure | Retry once, fallback to direct generation |
|
||||
| Syntax errors persist after 3 fixes | Report errors, proceed with available tests |
|
||||
| Source file not found | Skip file, log warning |
|
||||
| Agent/CLI failure | Retry once, then fallback to inline execution |
|
||||
| Timeout (>5 min) | Report partial results, notify coordinator |
|
||||
282
.claude/skills/team-quality-assurance/roles/generator/role.md
Normal file
282
.claude/skills/team-quality-assurance/roles/generator/role.md
Normal file
@@ -0,0 +1,282 @@
|
||||
# Role: generator
|
||||
|
||||
测试用例生成器。按 strategist 制定的策略和层级,生成对应的测试代码。支持 L1 单元测试、L2 集成测试、L3 E2E 测试。遵循项目现有测试模式和框架约定。
|
||||
|
||||
## Role Identity
|
||||
|
||||
- **Name**: `generator`
|
||||
- **Task Prefix**: `QAGEN-*`
|
||||
- **Responsibility**: Code generation(测试代码生成)
|
||||
- **Communication**: SendMessage to coordinator only
|
||||
- **Output Tag**: `[generator]`
|
||||
|
||||
## Role Boundaries
|
||||
|
||||
### MUST
|
||||
|
||||
- 仅处理 `QAGEN-*` 前缀的任务
|
||||
- 所有输出必须带 `[generator]` 标识
|
||||
- 遵循项目现有测试框架和模式
|
||||
- 生成的测试必须可运行
|
||||
|
||||
### MUST NOT
|
||||
|
||||
- ❌ 修改源代码(仅生成测试代码)
|
||||
- ❌ 执行测试
|
||||
- ❌ 为其他角色创建任务
|
||||
- ❌ 直接与其他 worker 通信
|
||||
|
||||
## Message Types
|
||||
|
||||
| Type | Direction | Trigger | Description |
|
||||
|------|-----------|---------|-------------|
|
||||
| `tests_generated` | generator → coordinator | 测试生成完成 | 包含生成的测试文件列表 |
|
||||
| `tests_revised` | generator → coordinator | 测试修订完成 | GC 循环中修订后 |
|
||||
| `error` | generator → coordinator | 生成失败 | 阻塞性错误 |
|
||||
|
||||
## Toolbox
|
||||
|
||||
### Available Commands
|
||||
|
||||
| Command | File | Phase | Description |
|
||||
|---------|------|-------|-------------|
|
||||
| `generate-tests` | [commands/generate-tests.md](commands/generate-tests.md) | Phase 3 | 按层级生成测试代码 |
|
||||
|
||||
### Subagent Capabilities
|
||||
|
||||
| Agent Type | Used By | Purpose |
|
||||
|------------|---------|---------|
|
||||
| `code-developer` | generate-tests.md | 复杂测试代码生成 |
|
||||
|
||||
### CLI Capabilities
|
||||
|
||||
| CLI Tool | Mode | Used By | Purpose |
|
||||
|----------|------|---------|---------|
|
||||
| `gemini` | analysis | generate-tests.md | 分析现有测试模式 |
|
||||
|
||||
## Execution (5-Phase)
|
||||
|
||||
### Phase 1: Task Discovery
|
||||
|
||||
```javascript
|
||||
const tasks = TaskList()
|
||||
const myTasks = tasks.filter(t =>
|
||||
t.subject.startsWith('QAGEN-') &&
|
||||
t.owner === 'generator' &&
|
||||
t.status === 'pending' &&
|
||||
t.blockedBy.length === 0
|
||||
)
|
||||
|
||||
if (myTasks.length === 0) return
|
||||
const task = TaskGet({ taskId: myTasks[0].id })
|
||||
TaskUpdate({ taskId: task.id, status: 'in_progress' })
|
||||
```
|
||||
|
||||
### Phase 2: Strategy & Pattern Loading
|
||||
|
||||
```javascript
|
||||
// 读取 shared memory 获取策略
|
||||
const sessionFolder = task.description.match(/session:\s*(.+)/)?.[1] || '.'
|
||||
let sharedMemory = {}
|
||||
try { sharedMemory = JSON.parse(Read(`${sessionFolder}/shared-memory.json`)) } catch {}
|
||||
|
||||
const strategy = sharedMemory.test_strategy || {}
|
||||
const targetLayer = task.description.match(/layer:\s*(L[123])/)?.[1] || strategy.layers?.[0]?.level || 'L1'
|
||||
|
||||
// 确定目标层级的详情
|
||||
const layerConfig = strategy.layers?.find(l => l.level === targetLayer) || {
|
||||
level: targetLayer,
|
||||
name: targetLayer === 'L1' ? 'Unit Tests' : targetLayer === 'L2' ? 'Integration Tests' : 'E2E Tests',
|
||||
target_coverage: targetLayer === 'L1' ? 80 : targetLayer === 'L2' ? 60 : 40,
|
||||
focus_files: []
|
||||
}
|
||||
|
||||
// 学习现有测试模式(找 3 个相似测试文件)
|
||||
const existingTests = Glob(`**/*.{test,spec}.{ts,tsx,js,jsx}`)
|
||||
const testPatterns = existingTests.slice(0, 3).map(f => ({
|
||||
path: f,
|
||||
content: Read(f)
|
||||
}))
|
||||
|
||||
// 检测测试框架和配置
|
||||
const testFramework = strategy.test_framework || 'vitest'
|
||||
```
|
||||
|
||||
### Phase 3: Test Generation
|
||||
|
||||
```javascript
|
||||
// Read commands/generate-tests.md for full implementation
|
||||
Read("commands/generate-tests.md")
|
||||
```
|
||||
|
||||
**核心策略**: 基于复杂度选择生成方式
|
||||
|
||||
```javascript
|
||||
const focusFiles = layerConfig.focus_files || []
|
||||
|
||||
if (focusFiles.length <= 3) {
|
||||
// 直接生成:读取源文件 → 分析 → 写测试
|
||||
for (const sourceFile of focusFiles) {
|
||||
const sourceContent = Read(sourceFile)
|
||||
|
||||
// 确定测试文件路径(遵循项目约定)
|
||||
const testPath = sourceFile
|
||||
.replace(/\.(ts|tsx|js|jsx)$/, `.test.$1`)
|
||||
.replace(/^src\//, 'src/__tests__/') // 或保持同级
|
||||
|
||||
// 检查是否已有测试
|
||||
let existingTest = null
|
||||
try { existingTest = Read(testPath) } catch {}
|
||||
|
||||
if (existingTest) {
|
||||
// 补充现有测试
|
||||
Edit({
|
||||
file_path: testPath,
|
||||
old_string: "// END OF TESTS",
|
||||
new_string: `// Additional tests for coverage\n// ...new test cases...\n// END OF TESTS`
|
||||
})
|
||||
} else {
|
||||
// 创建新测试文件
|
||||
Write(testPath, generateTestContent(sourceFile, sourceContent, testPatterns, testFramework))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 委派给 code-developer
|
||||
Task({
|
||||
subagent_type: "code-developer",
|
||||
run_in_background: false,
|
||||
description: `Generate ${targetLayer} tests for ${focusFiles.length} files`,
|
||||
prompt: `## Goal
|
||||
Generate ${layerConfig.name} for the following source files.
|
||||
|
||||
## Test Framework
|
||||
${testFramework}
|
||||
|
||||
## Existing Test Patterns
|
||||
${testPatterns.map(t => `### ${t.path}\n\`\`\`\n${t.content.substring(0, 500)}\n\`\`\``).join('\n\n')}
|
||||
|
||||
## Source Files to Test
|
||||
${focusFiles.map(f => `- ${f}`).join('\n')}
|
||||
|
||||
## Requirements
|
||||
- Follow existing test patterns exactly
|
||||
- Cover happy path + edge cases + error cases
|
||||
- Target coverage: ${layerConfig.target_coverage}%
|
||||
- Do NOT modify source files, only create/modify test files`
|
||||
})
|
||||
}
|
||||
|
||||
// 辅助函数
|
||||
function generateTestContent(sourceFile, sourceContent, patterns, framework) {
|
||||
// 基于模式生成测试代码骨架
|
||||
const imports = extractExports(sourceContent)
|
||||
const pattern = patterns[0]?.content || ''
|
||||
|
||||
return `import { ${imports.join(', ')} } from '${sourceFile.replace(/\.(ts|tsx|js|jsx)$/, '')}'
|
||||
|
||||
describe('${sourceFile}', () => {
|
||||
${imports.map(exp => `
|
||||
describe('${exp}', () => {
|
||||
it('should work correctly with valid input', () => {
|
||||
// TODO: implement test
|
||||
})
|
||||
|
||||
it('should handle edge cases', () => {
|
||||
// TODO: implement test
|
||||
})
|
||||
|
||||
it('should handle error cases', () => {
|
||||
// TODO: implement test
|
||||
})
|
||||
})`).join('\n')}
|
||||
})`
|
||||
}
|
||||
|
||||
function extractExports(content) {
|
||||
const matches = content.match(/export\s+(function|const|class|interface|type)\s+(\w+)/g) || []
|
||||
return matches.map(m => m.split(/\s+/).pop())
|
||||
}
|
||||
```
|
||||
|
||||
### Phase 4: Self-Validation
|
||||
|
||||
```javascript
|
||||
// 验证生成的测试文件语法正确
|
||||
const generatedTests = Bash(`git diff --name-only`).split('\n')
|
||||
.filter(f => /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(f))
|
||||
|
||||
// TypeScript 语法检查
|
||||
const syntaxResult = Bash(`npx tsc --noEmit ${generatedTests.join(' ')} 2>&1 || true`)
|
||||
const hasSyntaxErrors = syntaxResult.includes('error TS')
|
||||
|
||||
if (hasSyntaxErrors) {
|
||||
// 自动修复语法错误
|
||||
const errors = syntaxResult.split('\n').filter(l => l.includes('error TS'))
|
||||
for (const error of errors.slice(0, 5)) {
|
||||
// 解析错误并尝试修复
|
||||
}
|
||||
}
|
||||
|
||||
// 记录生成的测试
|
||||
const generatedTestInfo = {
|
||||
layer: targetLayer,
|
||||
files: generatedTests,
|
||||
count: generatedTests.length,
|
||||
syntax_clean: !hasSyntaxErrors
|
||||
}
|
||||
|
||||
// 更新 shared memory
|
||||
sharedMemory.generated_tests = sharedMemory.generated_tests || {}
|
||||
sharedMemory.generated_tests[targetLayer] = generatedTestInfo
|
||||
Write(`${sessionFolder}/shared-memory.json`, JSON.stringify(sharedMemory, null, 2))
|
||||
```
|
||||
|
||||
### Phase 5: Report to Coordinator
|
||||
|
||||
```javascript
|
||||
const msgType = task.subject.includes('fix') ? 'tests_revised' : 'tests_generated'
|
||||
|
||||
mcp__ccw-tools__team_msg({
|
||||
operation: "log",
|
||||
team: teamName,
|
||||
from: "generator",
|
||||
to: "coordinator",
|
||||
type: msgType,
|
||||
summary: `[generator] ${targetLayer} 测试生成完成: ${generatedTests.length} 文件, 语法${hasSyntaxErrors ? '有错误' : '正常'}`,
|
||||
ref: generatedTests[0]
|
||||
})
|
||||
|
||||
SendMessage({
|
||||
type: "message",
|
||||
recipient: "coordinator",
|
||||
content: `## [generator] Test Generation Results
|
||||
|
||||
**Task**: ${task.subject}
|
||||
**Layer**: ${targetLayer} - ${layerConfig.name}
|
||||
**Generated**: ${generatedTests.length} test files
|
||||
**Syntax**: ${hasSyntaxErrors ? 'ERRORS' : 'CLEAN'}
|
||||
|
||||
### Generated Files
|
||||
${generatedTests.map(f => `- ${f}`).join('\n')}`,
|
||||
summary: `[generator] QAGEN complete: ${targetLayer} ${generatedTests.length} files`
|
||||
})
|
||||
|
||||
TaskUpdate({ taskId: task.id, status: 'completed' })
|
||||
|
||||
const nextTasks = TaskList().filter(t =>
|
||||
t.subject.startsWith('QAGEN-') && t.owner === 'generator' &&
|
||||
t.status === 'pending' && t.blockedBy.length === 0
|
||||
)
|
||||
if (nextTasks.length > 0) { /* back to Phase 1 */ }
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Scenario | Resolution |
|
||||
|----------|------------|
|
||||
| No QAGEN-* tasks available | Idle, wait for coordinator |
|
||||
| Strategy not found in shared memory | Generate L1 unit tests for changed files |
|
||||
| No existing test patterns found | Use framework defaults |
|
||||
| Sub-agent failure | Retry once, fallback to direct generation |
|
||||
| Syntax errors in generated tests | Auto-fix up to 3 attempts, report remaining |
|
||||
| Source file not found | Skip file, report to coordinator |
|
||||
@@ -0,0 +1,216 @@
|
||||
# Command: scan
|
||||
|
||||
> 多视角 CLI Fan-out 扫描。从 bug、安全、测试覆盖、代码质量、UX 等视角并行分析代码,发现潜在问题。
|
||||
|
||||
## When to Use
|
||||
|
||||
- Phase 3 of Scout
|
||||
- 需要对代码库进行多视角问题扫描
|
||||
- 复杂度为 Medium 或 High 时使用 CLI Fan-out
|
||||
|
||||
**Trigger conditions**:
|
||||
- SCOUT-* 任务进入 Phase 3
|
||||
- 复杂度评估为 Medium/High
|
||||
- 需要深度分析超出 ACE 搜索能力
|
||||
|
||||
## Strategy
|
||||
|
||||
### Delegation Mode
|
||||
|
||||
**Mode**: CLI Fan-out
|
||||
**CLI Tool**: `gemini` (primary)
|
||||
**CLI Mode**: `analysis`
|
||||
**Parallel Perspectives**: 2-5(根据复杂度)
|
||||
|
||||
### Decision Logic
|
||||
|
||||
```javascript
|
||||
// 复杂度决定扫描策略
|
||||
if (complexity === 'Low') {
|
||||
// ACE 搜索 + Grep 内联分析(不使用 CLI)
|
||||
mode = 'inline'
|
||||
} else if (complexity === 'Medium') {
|
||||
// CLI Fan-out: 3 个核心视角
|
||||
mode = 'cli-fanout'
|
||||
activePerspectives = perspectives.slice(0, 3)
|
||||
} else {
|
||||
// CLI Fan-out: 所有视角
|
||||
mode = 'cli-fanout'
|
||||
activePerspectives = perspectives
|
||||
}
|
||||
```
|
||||
|
||||
## Execution Steps
|
||||
|
||||
### Step 1: Context Preparation
|
||||
|
||||
```javascript
|
||||
// 确定扫描范围
|
||||
const projectRoot = Bash(`git rev-parse --show-toplevel 2>/dev/null || pwd`).trim()
|
||||
const scanScope = task.description.match(/scope:\s*(.+)/)?.[1] || '**/*'
|
||||
|
||||
// 获取变更文件用于聚焦扫描
|
||||
const changedFiles = Bash(`git diff --name-only HEAD~5 2>/dev/null || echo ""`)
|
||||
.split('\n').filter(Boolean)
|
||||
|
||||
// 构建文件上下文
|
||||
const fileContext = changedFiles.length > 0
|
||||
? changedFiles.map(f => `@${f}`).join(' ')
|
||||
: `@${scanScope}`
|
||||
|
||||
// 已知缺陷模式(来自 shared memory)
|
||||
const knownPatternsText = knownPatterns.length > 0
|
||||
? `\nKnown defect patterns to verify: ${knownPatterns.map(p => p.description).join('; ')}`
|
||||
: ''
|
||||
```
|
||||
|
||||
### Step 2: Execute Strategy
|
||||
|
||||
```javascript
|
||||
if (mode === 'inline') {
|
||||
// 快速内联扫描
|
||||
const aceResults = mcp__ace-tool__search_context({
|
||||
project_root_path: projectRoot,
|
||||
query: "potential bugs, error handling issues, unchecked return values, security vulnerabilities, missing input validation"
|
||||
})
|
||||
|
||||
// 解析 ACE 结果并分类
|
||||
for (const result of aceResults) {
|
||||
classifyFinding(result)
|
||||
}
|
||||
} else {
|
||||
// CLI Fan-out: 每个视角一个 CLI 调用
|
||||
const perspectivePrompts = {
|
||||
'bug': `PURPOSE: Discover potential bugs and logic errors
|
||||
TASK: • Find unchecked return values • Identify race conditions • Check null/undefined handling • Find off-by-one errors • Detect resource leaks
|
||||
MODE: analysis
|
||||
CONTEXT: ${fileContext}${knownPatternsText}
|
||||
EXPECTED: List of findings with severity, file:line, description, and fix suggestion
|
||||
CONSTRAINTS: Focus on real bugs, avoid false positives`,
|
||||
|
||||
'security': `PURPOSE: Identify security vulnerabilities and risks
|
||||
TASK: • Check for injection flaws (SQL, command, XSS) • Find authentication/authorization gaps • Identify sensitive data exposure • Check input validation • Review crypto usage
|
||||
MODE: analysis
|
||||
CONTEXT: ${fileContext}
|
||||
EXPECTED: Security findings with CVSS-style severity, file:line, CWE references where applicable
|
||||
CONSTRAINTS: Focus on exploitable vulnerabilities`,
|
||||
|
||||
'test-coverage': `PURPOSE: Identify untested code paths and coverage gaps
|
||||
TASK: • Find functions/methods without tests • Identify complex logic without assertions • Check error paths without coverage • Find boundary conditions untested
|
||||
MODE: analysis
|
||||
CONTEXT: ${fileContext}
|
||||
EXPECTED: List of untested areas with file:line, complexity indicator, and test suggestion
|
||||
CONSTRAINTS: Focus on high-risk untested code`,
|
||||
|
||||
'code-quality': `PURPOSE: Detect code quality issues and anti-patterns
|
||||
TASK: • Find code duplication • Identify overly complex functions • Check naming conventions • Find dead code • Detect God objects/functions
|
||||
MODE: analysis
|
||||
CONTEXT: ${fileContext}
|
||||
EXPECTED: Quality findings with severity, file:line, and improvement suggestion
|
||||
CONSTRAINTS: Focus on maintainability impacts`,
|
||||
|
||||
'ux': `PURPOSE: Identify UX-impacting issues in code
|
||||
TASK: • Find missing loading states • Check error message quality • Identify accessibility gaps • Find inconsistent UI patterns • Check responsive handling
|
||||
MODE: analysis
|
||||
CONTEXT: ${fileContext}
|
||||
EXPECTED: UX findings with impact level, file:line, and user-facing description
|
||||
CONSTRAINTS: Focus on user-visible issues`
|
||||
}
|
||||
|
||||
for (const perspective of activePerspectives) {
|
||||
const prompt = perspectivePrompts[perspective]
|
||||
if (!prompt) continue
|
||||
|
||||
Bash(`ccw cli -p "${prompt}" --tool gemini --mode analysis --rule analysis-assess-security-risks`, {
|
||||
run_in_background: true
|
||||
})
|
||||
}
|
||||
|
||||
// 等待所有 CLI 完成(hook 回调通知)
|
||||
}
|
||||
```
|
||||
|
||||
### Step 3: Result Processing
|
||||
|
||||
```javascript
|
||||
// 聚合所有视角的结果
|
||||
const allFindings = { critical: [], high: [], medium: [], low: [] }
|
||||
|
||||
// 从 CLI 输出解析结果
|
||||
for (const perspective of activePerspectives) {
|
||||
const findings = parseCliOutput(cliResults[perspective])
|
||||
for (const finding of findings) {
|
||||
finding.perspective = perspective
|
||||
allFindings[finding.severity].push(finding)
|
||||
}
|
||||
}
|
||||
|
||||
// 去重:相同 file:line 的发现合并
|
||||
function deduplicateFindings(findings) {
|
||||
const seen = new Set()
|
||||
const unique = []
|
||||
for (const f of findings) {
|
||||
const key = `${f.file}:${f.line}`
|
||||
if (!seen.has(key)) {
|
||||
seen.add(key)
|
||||
unique.push(f)
|
||||
} else {
|
||||
// 合并视角信息到已有条目
|
||||
const existing = unique.find(u => `${u.file}:${u.line}` === key)
|
||||
if (existing) existing.perspectives = [...(existing.perspectives || [existing.perspective]), f.perspective]
|
||||
}
|
||||
}
|
||||
return unique
|
||||
}
|
||||
|
||||
for (const severity of ['critical', 'high', 'medium', 'low']) {
|
||||
allFindings[severity] = deduplicateFindings(allFindings[severity])
|
||||
}
|
||||
|
||||
// 与已知缺陷模式对比
|
||||
for (const pattern of knownPatterns) {
|
||||
for (const severity of ['critical', 'high', 'medium', 'low']) {
|
||||
for (const finding of allFindings[severity]) {
|
||||
if (finding.file === pattern.file || finding.description.includes(pattern.type)) {
|
||||
finding.known_pattern = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Output Format
|
||||
|
||||
```
|
||||
## Scan Results
|
||||
|
||||
### Perspectives Scanned: [list]
|
||||
### Complexity: [Low|Medium|High]
|
||||
|
||||
### Findings by Severity
|
||||
#### Critical ([count])
|
||||
- [file:line] [perspective] - [description]
|
||||
|
||||
#### High ([count])
|
||||
- [file:line] [perspective] - [description]
|
||||
|
||||
#### Medium ([count])
|
||||
- [file:line] - [description]
|
||||
|
||||
#### Low ([count])
|
||||
- [file:line] - [description]
|
||||
|
||||
### Known Pattern Matches: [count]
|
||||
### New Findings: [count]
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Scenario | Resolution |
|
||||
|----------|------------|
|
||||
| CLI tool unavailable | Fall back to ACE search + Grep inline analysis |
|
||||
| CLI returns empty for a perspective | Note incomplete perspective, continue others |
|
||||
| Too many findings (>50) | Prioritize critical/high, summarize medium/low |
|
||||
| Timeout on CLI call | Use partial results, note incomplete perspectives |
|
||||
| Agent/CLI failure | Retry once, then fallback to inline execution |
|
||||
| Timeout (>5 min) | Report partial results, notify coordinator |
|
||||
244
.claude/skills/team-quality-assurance/roles/scout/role.md
Normal file
244
.claude/skills/team-quality-assurance/roles/scout/role.md
Normal file
@@ -0,0 +1,244 @@
|
||||
# Role: scout
|
||||
|
||||
多视角问题侦察员。主动扫描代码库,从 bug、安全、UX、测试覆盖、代码质量等多个视角发现潜在问题,创建结构化 issue。融合 issue-discover 的多视角扫描能力。
|
||||
|
||||
## Role Identity
|
||||
|
||||
- **Name**: `scout`
|
||||
- **Task Prefix**: `SCOUT-*`
|
||||
- **Responsibility**: Orchestration(多视角扫描编排)
|
||||
- **Communication**: SendMessage to coordinator only
|
||||
- **Output Tag**: `[scout]`
|
||||
|
||||
## Role Boundaries
|
||||
|
||||
### MUST
|
||||
|
||||
- 仅处理 `SCOUT-*` 前缀的任务
|
||||
- 所有输出必须带 `[scout]` 标识
|
||||
- 仅通过 SendMessage 与 coordinator 通信
|
||||
- 严格在问题发现职责范围内工作
|
||||
|
||||
### MUST NOT
|
||||
|
||||
- ❌ 编写或修改代码
|
||||
- ❌ 执行测试
|
||||
- ❌ 为其他角色创建任务
|
||||
- ❌ 直接与其他 worker 通信
|
||||
|
||||
## Message Types
|
||||
|
||||
| Type | Direction | Trigger | Description |
|
||||
|------|-----------|---------|-------------|
|
||||
| `scan_ready` | scout → coordinator | 扫描完成 | 包含发现的问题列表 |
|
||||
| `issues_found` | scout → coordinator | 发现高优先级问题 | 需要关注的关键发现 |
|
||||
| `error` | scout → coordinator | 扫描失败 | 阻塞性错误 |
|
||||
|
||||
## Toolbox
|
||||
|
||||
### Available Commands
|
||||
|
||||
| Command | File | Phase | Description |
|
||||
|---------|------|-------|-------------|
|
||||
| `scan` | [commands/scan.md](commands/scan.md) | Phase 3 | 多视角 CLI Fan-out 扫描 |
|
||||
|
||||
### Subagent Capabilities
|
||||
|
||||
| Agent Type | Used By | Purpose |
|
||||
|------------|---------|---------|
|
||||
| `cli-explore-agent` | scan.md | 多角度代码库探索 |
|
||||
|
||||
### CLI Capabilities
|
||||
|
||||
| CLI Tool | Mode | Used By | Purpose |
|
||||
|----------|------|---------|---------|
|
||||
| `gemini` | analysis | scan.md | 多视角代码分析 |
|
||||
|
||||
## Execution (5-Phase)
|
||||
|
||||
### Phase 1: Task Discovery
|
||||
|
||||
```javascript
|
||||
const tasks = TaskList()
|
||||
const myTasks = tasks.filter(t =>
|
||||
t.subject.startsWith('SCOUT-') &&
|
||||
t.owner === 'scout' &&
|
||||
t.status === 'pending' &&
|
||||
t.blockedBy.length === 0
|
||||
)
|
||||
|
||||
if (myTasks.length === 0) return // idle
|
||||
|
||||
const task = TaskGet({ taskId: myTasks[0].id })
|
||||
TaskUpdate({ taskId: task.id, status: 'in_progress' })
|
||||
```
|
||||
|
||||
### Phase 2: Context & Scope Assessment
|
||||
|
||||
```javascript
|
||||
// 确定扫描范围
|
||||
const scanScope = task.description.match(/scope:\s*(.+)/)?.[1] || '**/*'
|
||||
|
||||
// 获取变更文件(如果有)
|
||||
const changedFiles = Bash(`git diff --name-only HEAD~5 2>/dev/null || echo ""`)
|
||||
.split('\n').filter(Boolean)
|
||||
|
||||
// 读取 shared memory 获取历史缺陷模式
|
||||
const sessionFolder = task.description.match(/session:\s*(.+)/)?.[1] || '.'
|
||||
let sharedMemory = {}
|
||||
try { sharedMemory = JSON.parse(Read(`${sessionFolder}/shared-memory.json`)) } catch {}
|
||||
const knownPatterns = sharedMemory.defect_patterns || []
|
||||
|
||||
// 确定扫描视角
|
||||
const perspectives = ["bug", "security", "test-coverage", "code-quality"]
|
||||
if (task.description.includes('ux')) perspectives.push("ux")
|
||||
|
||||
// 评估复杂度
|
||||
function assessComplexity(desc) {
|
||||
let score = 0
|
||||
if (/全项目|全量|comprehensive|full/.test(desc)) score += 3
|
||||
if (/security|安全/.test(desc)) score += 1
|
||||
if (/multiple|across|cross|多模块/.test(desc)) score += 2
|
||||
return score >= 4 ? 'High' : score >= 2 ? 'Medium' : 'Low'
|
||||
}
|
||||
const complexity = assessComplexity(task.description)
|
||||
```
|
||||
|
||||
### Phase 3: Multi-Perspective Scan
|
||||
|
||||
```javascript
|
||||
// Read commands/scan.md for full CLI Fan-out implementation
|
||||
Read("commands/scan.md")
|
||||
```
|
||||
|
||||
**核心策略**: 按视角并行执行 CLI 分析
|
||||
|
||||
```javascript
|
||||
if (complexity === 'Low') {
|
||||
// 直接使用 ACE 搜索 + Grep 进行快速扫描
|
||||
const aceResults = mcp__ace-tool__search_context({
|
||||
project_root_path: projectRoot,
|
||||
query: "potential bugs, error handling issues, unchecked return values"
|
||||
})
|
||||
// 分析结果...
|
||||
} else {
|
||||
// CLI Fan-out: 每个视角一个 CLI 调用
|
||||
for (const perspective of perspectives) {
|
||||
Bash(`ccw cli -p "PURPOSE: Scan code from ${perspective} perspective to discover potential issues
|
||||
TASK: • Analyze code patterns for ${perspective} problems • Identify anti-patterns • Check for common ${perspective} issues
|
||||
MODE: analysis
|
||||
CONTEXT: @${scanScope}
|
||||
EXPECTED: List of findings with severity (critical/high/medium/low), file:line references, description
|
||||
CONSTRAINTS: Focus on actionable findings only, no false positives" --tool gemini --mode analysis --rule analysis-assess-security-risks`, { run_in_background: true })
|
||||
}
|
||||
// 等待所有 CLI 完成,聚合结果
|
||||
}
|
||||
```
|
||||
|
||||
### Phase 4: Result Aggregation & Issue Creation
|
||||
|
||||
```javascript
|
||||
// 聚合所有视角的发现
|
||||
const allFindings = {
|
||||
critical: [],
|
||||
high: [],
|
||||
medium: [],
|
||||
low: []
|
||||
}
|
||||
|
||||
// 去重:相同 file:line 的发现合并
|
||||
// 排序:按严重性排列
|
||||
// 与已知缺陷模式对比:标记重复发现
|
||||
|
||||
const discoveredIssues = allFindings.critical
|
||||
.concat(allFindings.high)
|
||||
.map((f, i) => ({
|
||||
id: `SCOUT-ISSUE-${i + 1}`,
|
||||
severity: f.severity,
|
||||
perspective: f.perspective,
|
||||
file: f.file,
|
||||
line: f.line,
|
||||
description: f.description,
|
||||
suggestion: f.suggestion
|
||||
}))
|
||||
|
||||
// 更新 shared memory
|
||||
sharedMemory.discovered_issues = discoveredIssues
|
||||
Write(`${sessionFolder}/shared-memory.json`, JSON.stringify(sharedMemory, null, 2))
|
||||
|
||||
// 保存扫描结果
|
||||
Write(`${sessionFolder}/scan/scan-results.json`, JSON.stringify({
|
||||
scan_date: new Date().toISOString(),
|
||||
perspectives: perspectives,
|
||||
total_findings: Object.values(allFindings).flat().length,
|
||||
by_severity: {
|
||||
critical: allFindings.critical.length,
|
||||
high: allFindings.high.length,
|
||||
medium: allFindings.medium.length,
|
||||
low: allFindings.low.length
|
||||
},
|
||||
findings: allFindings,
|
||||
issues_created: discoveredIssues.length
|
||||
}, null, 2))
|
||||
```
|
||||
|
||||
### Phase 5: Report to Coordinator
|
||||
|
||||
```javascript
|
||||
const resultSummary = `发现 ${discoveredIssues.length} 个问题(Critical: ${allFindings.critical.length}, High: ${allFindings.high.length}, Medium: ${allFindings.medium.length}, Low: ${allFindings.low.length})`
|
||||
|
||||
mcp__ccw-tools__team_msg({
|
||||
operation: "log",
|
||||
team: teamName,
|
||||
from: "scout",
|
||||
to: "coordinator",
|
||||
type: discoveredIssues.length > 0 ? "issues_found" : "scan_ready",
|
||||
summary: `[scout] ${resultSummary}`,
|
||||
ref: `${sessionFolder}/scan/scan-results.json`
|
||||
})
|
||||
|
||||
SendMessage({
|
||||
type: "message",
|
||||
recipient: "coordinator",
|
||||
content: `## [scout] Scan Results
|
||||
|
||||
**Task**: ${task.subject}
|
||||
**Perspectives**: ${perspectives.join(', ')}
|
||||
**Status**: ${discoveredIssues.length > 0 ? 'Issues Found' : 'Clean'}
|
||||
|
||||
### Summary
|
||||
${resultSummary}
|
||||
|
||||
### Top Findings
|
||||
${discoveredIssues.slice(0, 5).map(i => `- **[${i.severity}]** ${i.file}:${i.line} - ${i.description}`).join('\n')}
|
||||
|
||||
### Scan Report
|
||||
${sessionFolder}/scan/scan-results.json`,
|
||||
summary: `[scout] SCOUT complete: ${resultSummary}`
|
||||
})
|
||||
|
||||
TaskUpdate({ taskId: task.id, status: 'completed' })
|
||||
|
||||
// Check for next task
|
||||
const nextTasks = TaskList().filter(t =>
|
||||
t.subject.startsWith('SCOUT-') &&
|
||||
t.owner === 'scout' &&
|
||||
t.status === 'pending' &&
|
||||
t.blockedBy.length === 0
|
||||
)
|
||||
|
||||
if (nextTasks.length > 0) {
|
||||
// Continue with next task → back to Phase 1
|
||||
}
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Scenario | Resolution |
|
||||
|----------|------------|
|
||||
| No SCOUT-* tasks available | Idle, wait for coordinator assignment |
|
||||
| CLI tool unavailable | Fall back to ACE search + Grep inline analysis |
|
||||
| Scan scope too broad | Narrow to changed files only, report partial results |
|
||||
| All perspectives return empty | Report clean scan, notify coordinator |
|
||||
| CLI timeout | Use partial results, note incomplete perspectives |
|
||||
| Critical issue beyond scope | SendMessage issues_found to coordinator |
|
||||
@@ -0,0 +1,221 @@
|
||||
# Command: analyze-scope
|
||||
|
||||
> 变更范围分析 + 测试策略制定。分析代码变更、scout 发现和项目结构,确定测试层级和覆盖率目标。
|
||||
|
||||
## When to Use
|
||||
|
||||
- Phase 2-3 of Strategist
|
||||
- 需要分析代码变更范围
|
||||
- 需要将 scout 发现转化为测试策略
|
||||
|
||||
**Trigger conditions**:
|
||||
- QASTRAT-* 任务进入执行阶段
|
||||
- 变更文件数 > 5 需要 CLI 辅助分析
|
||||
- 存在 scout 发现的高优先级问题
|
||||
|
||||
## Strategy
|
||||
|
||||
### Delegation Mode
|
||||
|
||||
**Mode**: CLI Fan-out(复杂项目)/ Direct(简单项目)
|
||||
**CLI Tool**: `gemini` (primary)
|
||||
**CLI Mode**: `analysis`
|
||||
|
||||
### Decision Logic
|
||||
|
||||
```javascript
|
||||
const totalScope = changedFiles.length + discoveredIssues.length
|
||||
if (totalScope <= 5) {
|
||||
// 直接内联分析
|
||||
mode = 'direct'
|
||||
} else if (totalScope <= 15) {
|
||||
// 单次 CLI 分析
|
||||
mode = 'single-cli'
|
||||
} else {
|
||||
// 多维度 CLI 分析
|
||||
mode = 'multi-cli'
|
||||
}
|
||||
```
|
||||
|
||||
## Execution Steps
|
||||
|
||||
### Step 1: Context Preparation
|
||||
|
||||
```javascript
|
||||
// 从 shared memory 获取 scout 发现
|
||||
const discoveredIssues = sharedMemory.discovered_issues || []
|
||||
|
||||
// 分析 git diff 获取变更范围
|
||||
const changedFiles = Bash(`git diff --name-only HEAD~5 2>/dev/null || git diff --name-only --cached 2>/dev/null || echo ""`)
|
||||
.split('\n').filter(Boolean)
|
||||
|
||||
// 分类变更文件
|
||||
const fileCategories = {
|
||||
source: changedFiles.filter(f => /\.(ts|tsx|js|jsx|py|java|go|rs)$/.test(f)),
|
||||
test: changedFiles.filter(f => /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(f) || /test_/.test(f)),
|
||||
config: changedFiles.filter(f => /\.(json|yaml|yml|toml|env)$/.test(f)),
|
||||
style: changedFiles.filter(f => /\.(css|scss|less)$/.test(f)),
|
||||
docs: changedFiles.filter(f => /\.(md|txt|rst)$/.test(f))
|
||||
}
|
||||
|
||||
// 检测项目测试框架
|
||||
const packageJson = Read('package.json')
|
||||
const testFramework = detectFramework(packageJson)
|
||||
|
||||
// 获取已有测试覆盖率基线
|
||||
let baselineCoverage = null
|
||||
try {
|
||||
const coverageSummary = JSON.parse(Read('coverage/coverage-summary.json'))
|
||||
baselineCoverage = coverageSummary.total?.lines?.pct || null
|
||||
} catch {}
|
||||
```
|
||||
|
||||
### Step 2: Execute Strategy
|
||||
|
||||
```javascript
|
||||
if (mode === 'direct') {
|
||||
// 内联分析:直接构建策略
|
||||
buildStrategyDirect(fileCategories, discoveredIssues, testFramework)
|
||||
} else if (mode === 'single-cli') {
|
||||
// 单次 CLI 综合分析
|
||||
Bash(`ccw cli -p "PURPOSE: Analyze code changes and scout findings to determine optimal test strategy
|
||||
TASK: • Classify ${changedFiles.length} changed files by risk level • Map ${discoveredIssues.length} scout issues to test requirements • Identify integration points between changed modules • Recommend test layers (L1/L2/L3) with coverage targets
|
||||
MODE: analysis
|
||||
CONTEXT: @${changedFiles.slice(0, 20).join(' @')} | Memory: Scout found ${discoveredIssues.length} issues, baseline coverage ${baselineCoverage || 'unknown'}%
|
||||
EXPECTED: JSON with layers array, each containing level, name, target_coverage, focus_files, rationale
|
||||
CONSTRAINTS: Be conservative with L3 E2E tests | Focus L1 on changed source files" --tool gemini --mode analysis --rule analysis-analyze-code-patterns`, {
|
||||
run_in_background: true
|
||||
})
|
||||
// 等待 CLI 完成
|
||||
} else {
|
||||
// 多维度分析
|
||||
// Dimension 1: 变更风险分析
|
||||
Bash(`ccw cli -p "PURPOSE: Assess risk level of code changes
|
||||
TASK: • Classify each file by change risk (high/medium/low) • Identify files touching critical paths • Map dependency chains
|
||||
MODE: analysis
|
||||
CONTEXT: @${fileCategories.source.join(' @')}
|
||||
EXPECTED: Risk matrix with file:risk_level mapping
|
||||
CONSTRAINTS: Focus on source files only" --tool gemini --mode analysis`, {
|
||||
run_in_background: true
|
||||
})
|
||||
|
||||
// Dimension 2: 测试覆盖差距分析
|
||||
Bash(`ccw cli -p "PURPOSE: Identify test coverage gaps for changed code
|
||||
TASK: • Find changed functions without tests • Map test files to source files • Identify missing integration test scenarios
|
||||
MODE: analysis
|
||||
CONTEXT: @${[...fileCategories.source, ...fileCategories.test].join(' @')}
|
||||
EXPECTED: Coverage gap report with untested functions and modules
|
||||
CONSTRAINTS: Compare existing tests to changed code" --tool gemini --mode analysis`, {
|
||||
run_in_background: true
|
||||
})
|
||||
// 等待所有 CLI 完成
|
||||
}
|
||||
```
|
||||
|
||||
### Step 3: Result Processing
|
||||
|
||||
```javascript
|
||||
// 构建测试策略
|
||||
const strategy = {
|
||||
scope: {
|
||||
total_changed: changedFiles.length,
|
||||
source_files: fileCategories.source.length,
|
||||
test_files: fileCategories.test.length,
|
||||
issue_count: discoveredIssues.length,
|
||||
baseline_coverage: baselineCoverage
|
||||
},
|
||||
test_framework: testFramework,
|
||||
layers: [],
|
||||
coverage_targets: {}
|
||||
}
|
||||
|
||||
// 层级选择算法
|
||||
// L1: Unit Tests - 所有有源码变更的文件
|
||||
if (fileCategories.source.length > 0 || discoveredIssues.length > 0) {
|
||||
const l1Files = fileCategories.source.length > 0
|
||||
? fileCategories.source
|
||||
: [...new Set(discoveredIssues.map(i => i.file))]
|
||||
|
||||
strategy.layers.push({
|
||||
level: 'L1',
|
||||
name: 'Unit Tests',
|
||||
target_coverage: 80,
|
||||
focus_files: l1Files,
|
||||
rationale: fileCategories.source.length > 0
|
||||
? '所有变更的源文件需要单元测试覆盖'
|
||||
: 'Scout 发现的问题需要测试覆盖'
|
||||
})
|
||||
}
|
||||
|
||||
// L2: Integration Tests - 多模块变更或关键问题
|
||||
if (fileCategories.source.length >= 3 || discoveredIssues.some(i => i.severity === 'critical')) {
|
||||
const integrationPoints = fileCategories.source
|
||||
.filter(f => /service|controller|handler|middleware|route|api/.test(f))
|
||||
|
||||
if (integrationPoints.length > 0) {
|
||||
strategy.layers.push({
|
||||
level: 'L2',
|
||||
name: 'Integration Tests',
|
||||
target_coverage: 60,
|
||||
focus_areas: integrationPoints,
|
||||
rationale: '多文件变更涉及模块间交互,需要集成测试'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// L3: E2E Tests - 大量高优先级问题
|
||||
const criticalHighCount = discoveredIssues
|
||||
.filter(i => i.severity === 'critical' || i.severity === 'high').length
|
||||
if (criticalHighCount >= 3) {
|
||||
strategy.layers.push({
|
||||
level: 'L3',
|
||||
name: 'E2E Tests',
|
||||
target_coverage: 40,
|
||||
focus_flows: [...new Set(discoveredIssues
|
||||
.filter(i => i.severity === 'critical' || i.severity === 'high')
|
||||
.map(i => i.file.split('/')[1] || 'main'))],
|
||||
rationale: `${criticalHighCount} 个高优先级问题需要端到端验证`
|
||||
})
|
||||
}
|
||||
|
||||
// 设置覆盖率目标
|
||||
for (const layer of strategy.layers) {
|
||||
strategy.coverage_targets[layer.level] = layer.target_coverage
|
||||
}
|
||||
```
|
||||
|
||||
## Output Format
|
||||
|
||||
```
|
||||
## Test Strategy
|
||||
|
||||
### Scope Analysis
|
||||
- Changed files: [count]
|
||||
- Source files: [count]
|
||||
- Scout issues: [count]
|
||||
- Baseline coverage: [percent]%
|
||||
|
||||
### Test Layers
|
||||
#### L1: Unit Tests
|
||||
- Coverage target: 80%
|
||||
- Focus files: [list]
|
||||
|
||||
#### L2: Integration Tests (if applicable)
|
||||
- Coverage target: 60%
|
||||
- Focus areas: [list]
|
||||
|
||||
#### L3: E2E Tests (if applicable)
|
||||
- Coverage target: 40%
|
||||
- Focus flows: [list]
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Scenario | Resolution |
|
||||
|----------|------------|
|
||||
| No changed files | Use scout issues as scope |
|
||||
| No scout issues | Generate L1 tests for all source files |
|
||||
| Test framework unknown | Default to Jest/Vitest (JS/TS) or pytest (Python) |
|
||||
| CLI analysis returns unusable results | Fall back to heuristic-based strategy |
|
||||
| Agent/CLI failure | Retry once, then fallback to inline execution |
|
||||
| Timeout (>5 min) | Report partial results, notify coordinator |
|
||||
266
.claude/skills/team-quality-assurance/roles/strategist/role.md
Normal file
266
.claude/skills/team-quality-assurance/roles/strategist/role.md
Normal file
@@ -0,0 +1,266 @@
|
||||
# Role: strategist
|
||||
|
||||
测试策略师。分析变更范围,确定测试层级(L1-L3),定义覆盖率目标,生成测试策略文档。基于 scout 发现的问题和代码变更制定针对性测试计划。
|
||||
|
||||
## Role Identity
|
||||
|
||||
- **Name**: `strategist`
|
||||
- **Task Prefix**: `QASTRAT-*`
|
||||
- **Responsibility**: Orchestration(策略制定)
|
||||
- **Communication**: SendMessage to coordinator only
|
||||
- **Output Tag**: `[strategist]`
|
||||
|
||||
## Role Boundaries
|
||||
|
||||
### MUST
|
||||
|
||||
- 仅处理 `QASTRAT-*` 前缀的任务
|
||||
- 所有输出必须带 `[strategist]` 标识
|
||||
- 仅通过 SendMessage 与 coordinator 通信
|
||||
|
||||
### MUST NOT
|
||||
|
||||
- ❌ 编写测试代码
|
||||
- ❌ 执行测试
|
||||
- ❌ 为其他角色创建任务
|
||||
- ❌ 修改源代码
|
||||
|
||||
## Message Types
|
||||
|
||||
| Type | Direction | Trigger | Description |
|
||||
|------|-----------|---------|-------------|
|
||||
| `strategy_ready` | strategist → coordinator | 策略制定完成 | 包含层级选择和覆盖率目标 |
|
||||
| `error` | strategist → coordinator | 策略制定失败 | 阻塞性错误 |
|
||||
|
||||
## Toolbox
|
||||
|
||||
### Available Commands
|
||||
|
||||
| Command | File | Phase | Description |
|
||||
|---------|------|-------|-------------|
|
||||
| `analyze-scope` | [commands/analyze-scope.md](commands/analyze-scope.md) | Phase 2-3 | 变更范围分析 + 策略制定 |
|
||||
|
||||
### Subagent Capabilities
|
||||
|
||||
| Agent Type | Used By | Purpose |
|
||||
|------------|---------|---------|
|
||||
| `cli-explore-agent` | analyze-scope.md | 代码结构和依赖分析 |
|
||||
|
||||
### CLI Capabilities
|
||||
|
||||
| CLI Tool | Mode | Used By | Purpose |
|
||||
|----------|------|---------|---------|
|
||||
| `gemini` | analysis | analyze-scope.md | 测试策略分析 |
|
||||
|
||||
## Execution (5-Phase)
|
||||
|
||||
### Phase 1: Task Discovery
|
||||
|
||||
```javascript
|
||||
const tasks = TaskList()
|
||||
const myTasks = tasks.filter(t =>
|
||||
t.subject.startsWith('QASTRAT-') &&
|
||||
t.owner === 'strategist' &&
|
||||
t.status === 'pending' &&
|
||||
t.blockedBy.length === 0
|
||||
)
|
||||
|
||||
if (myTasks.length === 0) return
|
||||
const task = TaskGet({ taskId: myTasks[0].id })
|
||||
TaskUpdate({ taskId: task.id, status: 'in_progress' })
|
||||
```
|
||||
|
||||
### Phase 2: Context & Change Analysis
|
||||
|
||||
```javascript
|
||||
// 读取 shared memory 获取 scout 发现
|
||||
const sessionFolder = task.description.match(/session:\s*(.+)/)?.[1] || '.'
|
||||
let sharedMemory = {}
|
||||
try { sharedMemory = JSON.parse(Read(`${sessionFolder}/shared-memory.json`)) } catch {}
|
||||
|
||||
const discoveredIssues = sharedMemory.discovered_issues || []
|
||||
const historicalPatterns = sharedMemory.defect_patterns || []
|
||||
|
||||
// 分析变更范围
|
||||
const changedFiles = Bash(`git diff --name-only HEAD~5 2>/dev/null || git diff --name-only --cached 2>/dev/null || echo ""`)
|
||||
.split('\n').filter(Boolean)
|
||||
|
||||
// 分类变更文件
|
||||
const fileCategories = {
|
||||
source: changedFiles.filter(f => /\.(ts|tsx|js|jsx|py|java|go|rs)$/.test(f)),
|
||||
test: changedFiles.filter(f => /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(f) || /test_/.test(f)),
|
||||
config: changedFiles.filter(f => /\.(json|yaml|yml|toml|env)$/.test(f)),
|
||||
style: changedFiles.filter(f => /\.(css|scss|less)$/.test(f))
|
||||
}
|
||||
|
||||
// 检测项目测试框架
|
||||
const testFramework = Bash(`ls package.json 2>/dev/null && (cat package.json | grep -o '"jest"\\|"vitest"\\|"mocha"\\|"pytest"' | head -1) || echo "unknown"`)
|
||||
.trim().replace(/"/g, '')
|
||||
|
||||
// 检测已有测试覆盖率
|
||||
const existingCoverage = Bash(`ls coverage/coverage-summary.json 2>/dev/null && cat coverage/coverage-summary.json | head -20 || echo "no coverage data"`)
|
||||
```
|
||||
|
||||
### Phase 3: Strategy Generation
|
||||
|
||||
```javascript
|
||||
// 基于变更范围和发现的问题制定策略
|
||||
const strategy = {
|
||||
scope: {
|
||||
total_changed: changedFiles.length,
|
||||
source_files: fileCategories.source.length,
|
||||
test_files: fileCategories.test.length,
|
||||
issue_count: discoveredIssues.length
|
||||
},
|
||||
test_framework: testFramework,
|
||||
layers: [],
|
||||
coverage_targets: {}
|
||||
}
|
||||
|
||||
// 层级选择逻辑
|
||||
if (fileCategories.source.length > 0) {
|
||||
strategy.layers.push({
|
||||
level: "L1",
|
||||
name: "Unit Tests",
|
||||
target_coverage: 80,
|
||||
focus_files: fileCategories.source,
|
||||
rationale: "所有变更的源文件需要单元测试覆盖"
|
||||
})
|
||||
}
|
||||
|
||||
if (fileCategories.source.length >= 3 || discoveredIssues.some(i => i.severity === 'critical')) {
|
||||
strategy.layers.push({
|
||||
level: "L2",
|
||||
name: "Integration Tests",
|
||||
target_coverage: 60,
|
||||
focus_areas: detectIntegrationPoints(fileCategories.source),
|
||||
rationale: "多文件变更或关键问题需要集成测试"
|
||||
})
|
||||
}
|
||||
|
||||
if (discoveredIssues.filter(i => i.severity === 'critical' || i.severity === 'high').length >= 3) {
|
||||
strategy.layers.push({
|
||||
level: "L3",
|
||||
name: "E2E Tests",
|
||||
target_coverage: 40,
|
||||
focus_flows: detectUserFlows(discoveredIssues),
|
||||
rationale: "多个高优先级问题需要端到端验证"
|
||||
})
|
||||
}
|
||||
|
||||
// 如果没有变更但有 scout 发现,聚焦于发现的问题
|
||||
if (strategy.layers.length === 0 && discoveredIssues.length > 0) {
|
||||
strategy.layers.push({
|
||||
level: "L1",
|
||||
name: "Unit Tests",
|
||||
target_coverage: 80,
|
||||
focus_files: [...new Set(discoveredIssues.map(i => i.file))],
|
||||
rationale: "Scout 发现的问题需要测试覆盖"
|
||||
})
|
||||
}
|
||||
|
||||
// 辅助函数
|
||||
function detectIntegrationPoints(files) {
|
||||
// 检测模块间交互点
|
||||
return files.filter(f => /service|controller|handler|middleware|route/.test(f))
|
||||
}
|
||||
|
||||
function detectUserFlows(issues) {
|
||||
// 从问题中推断用户流程
|
||||
return [...new Set(issues.map(i => i.file.split('/')[1] || 'main'))]
|
||||
}
|
||||
|
||||
// 生成策略文档
|
||||
const strategyDoc = `# Test Strategy
|
||||
|
||||
## Scope Analysis
|
||||
- Changed files: ${changedFiles.length}
|
||||
- Source files: ${fileCategories.source.length}
|
||||
- Scout issues: ${discoveredIssues.length}
|
||||
- Test framework: ${testFramework}
|
||||
|
||||
## Test Layers
|
||||
${strategy.layers.map(l => `### ${l.level}: ${l.name}
|
||||
- Coverage target: ${l.target_coverage}%
|
||||
- Focus: ${l.focus_files?.join(', ') || l.focus_areas?.join(', ') || l.focus_flows?.join(', ')}
|
||||
- Rationale: ${l.rationale}`).join('\n\n')}
|
||||
|
||||
## Priority Issues
|
||||
${discoveredIssues.slice(0, 10).map(i => `- [${i.severity}] ${i.file}:${i.line} - ${i.description}`).join('\n')}
|
||||
`
|
||||
|
||||
Bash(`mkdir -p "${sessionFolder}/strategy"`)
|
||||
Write(`${sessionFolder}/strategy/test-strategy.md`, strategyDoc)
|
||||
|
||||
// 更新 shared memory
|
||||
sharedMemory.test_strategy = strategy
|
||||
Write(`${sessionFolder}/shared-memory.json`, JSON.stringify(sharedMemory, null, 2))
|
||||
```
|
||||
|
||||
### Phase 4: Strategy Validation
|
||||
|
||||
```javascript
|
||||
// 验证策略合理性
|
||||
const validationChecks = {
|
||||
has_layers: strategy.layers.length > 0,
|
||||
has_targets: strategy.layers.every(l => l.target_coverage > 0),
|
||||
covers_issues: discoveredIssues.length === 0 ||
|
||||
discoveredIssues.some(i => strategy.layers.some(l =>
|
||||
l.focus_files?.includes(i.file)
|
||||
)),
|
||||
framework_detected: testFramework !== 'unknown'
|
||||
}
|
||||
|
||||
const isValid = Object.values(validationChecks).every(Boolean)
|
||||
```
|
||||
|
||||
### Phase 5: Report to Coordinator
|
||||
|
||||
```javascript
|
||||
const layersSummary = strategy.layers.map(l => `${l.level}(${l.target_coverage}%)`).join(', ')
|
||||
|
||||
mcp__ccw-tools__team_msg({
|
||||
operation: "log",
|
||||
team: teamName,
|
||||
from: "strategist",
|
||||
to: "coordinator",
|
||||
type: "strategy_ready",
|
||||
summary: `[strategist] 策略就绪: ${layersSummary}, 框架: ${testFramework}`,
|
||||
ref: `${sessionFolder}/strategy/test-strategy.md`
|
||||
})
|
||||
|
||||
SendMessage({
|
||||
type: "message",
|
||||
recipient: "coordinator",
|
||||
content: `## [strategist] Test Strategy Ready
|
||||
|
||||
**Task**: ${task.subject}
|
||||
**Layers**: ${layersSummary}
|
||||
**Framework**: ${testFramework}
|
||||
|
||||
### Layer Details
|
||||
${strategy.layers.map(l => `- **${l.level}**: ${l.name} (target: ${l.target_coverage}%, ${l.focus_files?.length || '?'} files)`).join('\n')}
|
||||
|
||||
### Strategy Document
|
||||
${sessionFolder}/strategy/test-strategy.md`,
|
||||
summary: `[strategist] QASTRAT complete: ${layersSummary}`
|
||||
})
|
||||
|
||||
TaskUpdate({ taskId: task.id, status: 'completed' })
|
||||
|
||||
const nextTasks = TaskList().filter(t =>
|
||||
t.subject.startsWith('QASTRAT-') && t.owner === 'strategist' &&
|
||||
t.status === 'pending' && t.blockedBy.length === 0
|
||||
)
|
||||
if (nextTasks.length > 0) { /* back to Phase 1 */ }
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
| Scenario | Resolution |
|
||||
|----------|------------|
|
||||
| No QASTRAT-* tasks available | Idle, wait for coordinator |
|
||||
| No changed files detected | Use scout issues as scope, or scan full project |
|
||||
| Test framework unknown | Default to Jest/Vitest for JS/TS, pytest for Python |
|
||||
| Shared memory not found | Create with defaults, proceed |
|
||||
| Critical issue beyond scope | SendMessage error to coordinator |
|
||||
131
.claude/skills/team-quality-assurance/specs/team-config.json
Normal file
131
.claude/skills/team-quality-assurance/specs/team-config.json
Normal file
@@ -0,0 +1,131 @@
|
||||
{
|
||||
"team_name": "quality-assurance",
|
||||
"version": "1.0.0",
|
||||
"description": "质量保障团队 - 融合\"软件测试\"和\"问题发现\"两大能力域,形成发现→验证→修复→回归的闭环",
|
||||
"skill_entry": "team-quality-assurance",
|
||||
"invocation": "Skill(skill=\"team-quality-assurance\", args=\"--role=coordinator ...\")",
|
||||
|
||||
"roles": {
|
||||
"coordinator": {
|
||||
"name": "coordinator",
|
||||
"responsibility": "Orchestration",
|
||||
"task_prefix": null,
|
||||
"description": "QA 团队协调者。编排 pipeline:需求澄清 → 模式选择 → 团队创建 → 任务分发 → 监控协调 → 质量门控 → 结果汇报",
|
||||
"message_types_sent": ["mode_selected", "gc_loop_trigger", "quality_gate", "task_unblocked", "error", "shutdown"],
|
||||
"message_types_received": ["scan_ready", "issues_found", "strategy_ready", "tests_generated", "tests_revised", "tests_passed", "tests_failed", "analysis_ready", "quality_report", "error"],
|
||||
"commands": ["dispatch", "monitor"]
|
||||
},
|
||||
"scout": {
|
||||
"name": "scout",
|
||||
"responsibility": "Orchestration (多视角扫描编排)",
|
||||
"task_prefix": "SCOUT-*",
|
||||
"description": "多视角问题侦察员。主动扫描代码库,从 bug、安全、UX、测试覆盖、代码质量等多个视角发现潜在问题",
|
||||
"message_types_sent": ["scan_ready", "issues_found", "error"],
|
||||
"message_types_received": [],
|
||||
"commands": ["scan"],
|
||||
"cli_tools": ["gemini"],
|
||||
"subagents": ["cli-explore-agent"]
|
||||
},
|
||||
"strategist": {
|
||||
"name": "strategist",
|
||||
"responsibility": "Orchestration (策略制定)",
|
||||
"task_prefix": "QASTRAT-*",
|
||||
"description": "测试策略师。分析变更范围,确定测试层级(L1-L3),定义覆盖率目标",
|
||||
"message_types_sent": ["strategy_ready", "error"],
|
||||
"message_types_received": [],
|
||||
"commands": ["analyze-scope"],
|
||||
"cli_tools": ["gemini"],
|
||||
"subagents": ["cli-explore-agent"]
|
||||
},
|
||||
"generator": {
|
||||
"name": "generator",
|
||||
"responsibility": "Code generation (测试代码生成)",
|
||||
"task_prefix": "QAGEN-*",
|
||||
"description": "测试用例生成器。按策略和层级生成测试代码,支持 L1/L2/L3",
|
||||
"message_types_sent": ["tests_generated", "tests_revised", "error"],
|
||||
"message_types_received": [],
|
||||
"commands": ["generate-tests"],
|
||||
"cli_tools": ["gemini"],
|
||||
"subagents": ["code-developer"]
|
||||
},
|
||||
"executor": {
|
||||
"name": "executor",
|
||||
"responsibility": "Validation (测试执行与修复)",
|
||||
"task_prefix": "QARUN-*",
|
||||
"description": "测试执行者。运行测试套件,收集覆盖率数据,失败时自动修复循环",
|
||||
"message_types_sent": ["tests_passed", "tests_failed", "coverage_report", "error"],
|
||||
"message_types_received": [],
|
||||
"commands": ["run-fix-cycle"],
|
||||
"subagents": ["code-developer"]
|
||||
},
|
||||
"analyst": {
|
||||
"name": "analyst",
|
||||
"responsibility": "Read-only analysis (质量分析)",
|
||||
"task_prefix": "QAANA-*",
|
||||
"description": "质量分析师。分析缺陷模式、覆盖率差距、测试有效性,生成综合质量报告",
|
||||
"message_types_sent": ["analysis_ready", "quality_report", "error"],
|
||||
"message_types_received": [],
|
||||
"commands": ["quality-report"],
|
||||
"cli_tools": ["gemini"]
|
||||
}
|
||||
},
|
||||
|
||||
"pipeline_modes": {
|
||||
"discovery": {
|
||||
"description": "Scout先行扫描 → 全流程",
|
||||
"stages": ["SCOUT", "QASTRAT", "QAGEN", "QARUN", "QAANA"],
|
||||
"entry_role": "scout"
|
||||
},
|
||||
"testing": {
|
||||
"description": "跳过 Scout → 直接测试",
|
||||
"stages": ["QASTRAT", "QAGEN-L1", "QARUN-L1", "QAGEN-L2", "QARUN-L2", "QAANA"],
|
||||
"entry_role": "strategist"
|
||||
},
|
||||
"full": {
|
||||
"description": "完整 QA 闭环 + 回归扫描",
|
||||
"stages": ["SCOUT", "QASTRAT", "QAGEN-L1", "QAGEN-L2", "QARUN-L1", "QARUN-L2", "QAANA", "SCOUT-REG"],
|
||||
"entry_role": "scout",
|
||||
"parallel_stages": [["QAGEN-L1", "QAGEN-L2"], ["QARUN-L1", "QARUN-L2"]]
|
||||
}
|
||||
},
|
||||
|
||||
"gc_loop": {
|
||||
"max_iterations": 3,
|
||||
"trigger": "coverage < target",
|
||||
"participants": ["generator", "executor"],
|
||||
"flow": "QAGEN-fix → QARUN-gc → evaluate"
|
||||
},
|
||||
|
||||
"shared_memory": {
|
||||
"file": "shared-memory.json",
|
||||
"fields": {
|
||||
"discovered_issues": { "owner": "scout", "type": "array" },
|
||||
"test_strategy": { "owner": "strategist", "type": "object" },
|
||||
"generated_tests": { "owner": "generator", "type": "object" },
|
||||
"execution_results": { "owner": "executor", "type": "object" },
|
||||
"defect_patterns": { "owner": "analyst", "type": "array" },
|
||||
"coverage_history": { "owner": "analyst", "type": "array" },
|
||||
"quality_score": { "owner": "analyst", "type": "number" }
|
||||
}
|
||||
},
|
||||
|
||||
"collaboration_patterns": [
|
||||
"CP-1: Linear Pipeline (Discovery/Testing mode)",
|
||||
"CP-2: Review-Fix Cycle (GC loop: Generator ↔ Executor)",
|
||||
"CP-3: Fan-out (Scout multi-perspective scan)",
|
||||
"CP-5: Escalation (Worker → Coordinator → User)",
|
||||
"CP-9: Dual-Track (Full mode: L1 + L2 parallel)",
|
||||
"CP-10: Post-Mortem (Analyst quality report)"
|
||||
],
|
||||
|
||||
"session_directory": {
|
||||
"pattern": ".workflow/.team/QA-{slug}-{date}",
|
||||
"subdirectories": ["scan", "strategy", "results", "analysis"]
|
||||
},
|
||||
|
||||
"test_layers": {
|
||||
"L1": { "name": "Unit Tests", "default_target": 80 },
|
||||
"L2": { "name": "Integration Tests", "default_target": 60 },
|
||||
"L3": { "name": "E2E Tests", "default_target": 40 }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user