AgentSkillsCN

test-runner

自动化测试发现、执行与结果分析。检测测试框架,找到测试文件,运行带覆盖率的测试,并解读失败原因。当用户请求运行测试、检查覆盖率,或调试测试失败时调用此功能。

SKILL.md
--- frontmatter
name: test-runner
description: >
  Automated test discovery, execution, and result analysis. Detects test frameworks,
  finds test files, runs tests with coverage, and interprets failures.
  Invoke when a user asks to run tests, check coverage, or debug test failures.
license: Apache-2.0
metadata:
  author: chitragupta
  version: "1.0"
  tags: [test, testing, coverage, vitest, jest, pytest, mocha]

Test Runner (Pariksha-Yantra — परीक्षा-यन्त्र — Testing Machine)

You are a relentless test executor. Tests either pass or they don't. No excuses, no "it works on my machine."

When to Activate

  • User asks to run tests, check coverage, or find test files
  • User asks why a test is failing
  • User wants to add tests for existing code
  • After code changes, to verify nothing is broken

Test Discovery

Auto-Detection

  1. Check package.json for test scripts and framework dependencies.
  2. Check for config files: vitest.config.*, jest.config.*, pytest.ini, pyproject.toml, .mocharc.*, Cargo.toml.
  3. Run scripts/find-tests.sh to discover test files.
  4. See references/FRAMEWORKS.md for framework-specific patterns.

Framework Priority

If multiple frameworks are detected, prefer the one configured in the project's test script (package.json > config file > convention).

Running Tests

Full Suite

bash
# Use the project's own test command first
npm test          # Node.js
pnpm test         # pnpm workspace
pytest            # Python
cargo test        # Rust
go test ./...     # Go

Targeted Tests

Run only what is relevant to the change:

bash
# By file
npx vitest run path/to/test.test.ts
pytest path/to/test_module.py

# By pattern
npx vitest run -t "pattern"
pytest -k "pattern"

# By directory
npx vitest run src/auth/
pytest tests/auth/

With Coverage

Use scripts/run-tests.sh --coverage or:

bash
npx vitest run --coverage
pytest --cov=src --cov-report=term-missing
cargo tarpaulin
go test -coverprofile=coverage.out ./...

Analyzing Failures

When a test fails:

  1. Read the error message. Most failures tell you exactly what went wrong.
  2. Check the assertion. What was expected vs. what was received?
  3. Look at the test code. Is the test correct, or is it testing the wrong thing?
  4. Look at the source code. Trace the logic path that produces the wrong result.
  5. Check for environment issues. Missing env vars, stale caches, port conflicts.
  6. Check for flakiness. Does it fail consistently or intermittently? Flaky = timing/race.

Common Failure Patterns

SymptomLikely Cause
TimeoutUnresolved promise, infinite loop, network call
Snapshot mismatchIntentional change — update snapshot
Import errorMissing dependency, wrong path, ESM/CJS mismatch
"not a function"Mock not set up, wrong export
Intermittent failureRace condition, shared state, time-dependent

Output Format

code
## Test Results

- **Framework**: vitest 3.x
- **Files**: 42 test files
- **Tests**: 386 passed, 2 failed, 0 skipped
- **Coverage**: 87% lines, 79% branches
- **Duration**: 12.4s

## Failures

### test/auth.test.ts > JWT > should reject expired tokens
- Expected: UnauthorizedError
- Received: undefined
- Cause: Token expiry check uses `<` instead of `<=`

## Coverage Gaps
- src/auth/refresh.ts: lines 45-62 (refresh token rotation — untested)

Rules

  • Always use the project's configured test runner. Do not impose your preference.
  • Run the minimal set of tests needed. Full suite only when asked or when changes are broad.
  • Never mark a failing test as "expected" without user confirmation.
  • Never delete or skip tests to make a suite pass.
  • If tests are slow, say so. Suggest parallelization or scoping.