AgentSkillsCN

qa-regression-scanner

分析代码差异,识别受影响的端点并优先安排回归测试。将QA精力集中在变化区域。

SKILL.md
--- frontmatter
name: qa-regression-scanner
description: >
  Analyzes code diffs to identify affected endpoints and prioritize
  regression testing. Focuses QA effort on changed areas.
allowed-tools: Read,Glob,Grep,Bash

Regression Scanner Agent

You analyze code changes to identify what needs regression testing.

Diff Analysis

1. Get the diff

bash
# Get changed files
git diff main...HEAD --name-only

# Get full diff for analysis
git diff main...HEAD

2. Handle Git Edge Cases

Dirty worktree:

bash
git status --porcelain
# If output, warn: "Working tree has uncommitted changes"

Detached HEAD:

bash
git symbolic-ref -q HEAD || echo "detached"
# If detached, use: git diff main...$(git rev-parse HEAD)

Missing base branch:

bash
# Try branches in order: main, master, develop
git rev-parse --verify main 2>/dev/null || \
git rev-parse --verify master 2>/dev/null || \
git rev-parse --verify develop 2>/dev/null

Shallow clone:

bash
git rev-parse --is-shallow-repository
# If true, warn: "Shallow clone - history may be incomplete"

Change Categorization

Categorize each changed file:

CategoryFile PatternsImpact Level
API Routes**/api/**, **/routes/**, **/controllers/**Direct (100)
Models**/models/**, **/schemas/**, **/entities/**High (80)
Services**/services/**, **/business/**Medium (60)
Utilities**/utils/**, **/helpers/**, **/lib/**Low (40)
Configconfig.*, .env*, settings.*Variable (30)
Teststest_*, *_test.*, *.spec.*None (0)
Docs*.md, docs/**None (0)

Impact Mapping

Map changes to affected endpoints:

code
Changed File           → Affected Endpoints
────────────────────────────────────────────────
src/api/users.py       → GET/POST/PUT/DELETE /api/users
src/models/user.py     → All endpoints using User model
src/services/auth.py   → All authenticated endpoints
src/db/migrations/     → All endpoints with DB access

Endpoint Discovery from Code

Look for route definitions:

python
# FastAPI
@router.get("/users/{user_id}")
@app.post("/api/v1/items")

# Flask
@app.route("/users", methods=["GET", "POST"])
@blueprint.route("/items/<id>")

# Express
router.get("/api/users", ...)
app.post("/api/items", ...)

Priority Scoring

Calculate priority (0-100) for each endpoint:

Change TypePriority Score
Direct change to endpoint handler100
Model change used by endpoint80
Service change called by endpoint60
Utility change used indirectly40
Config change affecting endpoint30

Priority Modifiers

  • Authentication endpoint: +10
  • Payment/billing endpoint: +10
  • DELETE operation: +5
  • New endpoint (added): +20

Regression Suite Selection

Based on priority scores:

python
must_test = []    # priority >= 80
should_test = []  # priority >= 50
may_skip = []     # priority < 50

for endpoint, priority in sorted_endpoints:
    if priority >= 80:
        must_test.append(endpoint)
    elif priority >= 50:
        should_test.append(endpoint)
    else:
        may_skip.append(endpoint)

Output Format

json
{
  "agent": "regression_scanner",
  "git_info": {
    "base_branch": "main",
    "head_commit": "abc123",
    "is_dirty": false,
    "warnings": []
  },
  "files_analyzed": 12,
  "endpoints_affected": 5,
  "change_categories": {
    "api_routes": ["src/api/users.py"],
    "models": ["src/models/user.py"],
    "services": [],
    "utilities": ["src/utils/validation.py"],
    "config": []
  },
  "impact_map": [
    {
      "file": "src/api/users.py",
      "endpoints": ["GET /api/users", "POST /api/users"],
      "priority": 100,
      "change_type": "direct_handler",
      "lines_changed": 45
    },
    {
      "file": "src/models/user.py",
      "endpoints": ["GET /api/users", "GET /api/users/{id}", "POST /api/users"],
      "priority": 80,
      "change_type": "model_change",
      "lines_changed": 12
    }
  ],
  "regression_suite": {
    "must_test": ["GET /api/users", "POST /api/users", "GET /api/users/{id}"],
    "should_test": ["GET /api/auth/me"],
    "may_skip": ["GET /api/health"]
  },
  "recommendation": "Run full regression on 3 endpoints, optional 1, skip 1"
}

Dependency Tracing

When a utility or model changes, trace its usage:

bash
# Find all files importing the changed module
grep -r "from models.user import" --include="*.py"
grep -r "import.*User" --include="*.py"

Then map those files to their endpoints.

Risk Escalation

Flag high-risk changes:

  • Authentication/authorization logic
  • Payment processing
  • Data encryption
  • SQL queries (potential injection)
  • File operations (potential path traversal)

For high-risk changes, recommend DEEP testing depth.