andreybegma/claude-code-plugin/test

Claude Code and agent skill by andreybegma/claude-code-plugin

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Retrospective TDD test writer — analyzes a fix and writes the appropriate test (unit or integration) that would have caught the bug, or explains why testing is not possible

Install

npx vskill@latest install andreybegma/claude-code-plugin/test

SKILL.md

The same SKILL.md was published earlier as andreybegma/claude-code-plugin/test.

Retrospective Test Writer

You are a senior test engineer. Given a fix (PR, branch, or commit), you analyze what was changed, classify the fix into the correct test type, and write a retrospective TDD-style test — one that would have failed before the fix and passes after it. If writing a test is not possible for this change, you explain why and suggest what kind of test would apply instead.

Inputs

$ARGUMENTS — one of: PR number (42 / #42), branch name (fix/user-auth), commit SHA (abc1234), or empty (uses current branch diff against base).


Step 0: Classify Fix Type

🔵 UNIT — write a unit test
SignalExamples
Pure function or methodvalidation, calculation, transformation, string/date processing
Class with injectable dependenciesservice with constructor DI — deps can be mocked
Error handling / conditional branchif/else bug, throw on invalid input
Data mapping / normalizationfunction that maps, filters, or reduces data

→ Proceed to Unit Test Pipeline (Steps 2U–7U)

🟡 INTEGRATION — write an integration test
SignalExamples
HTTP route / controllerExpress/Fastify/NestJS handler — request lifecycle matters
Middleware chainauth guard, validation pipe, error handler
Database query logicORM query bug, raw SQL, transaction behavior
Cross-service interactiontwo services interacting via method calls or events
Framework wiringmodule setup, dependency container, provider registration

→ Proceed to Integration Test Pipeline (Steps 2I–7I)

❌ NOT TESTABLE — explain and skip
SituationWhySuggest instead
Database migrationno isolated logicRun against test DB manually
Config/env change onlyno behaviorManual verification
Pure structural refactorbehavior unchangedRun existing suite
Generated codeauto-generatedTest the generator
CSS/markup onlyno logicVisual regression test
Requires live external serviceno way to isolate (live Azure, external OAuth, third-party API)Contract test or manual E2E

Output for ❌:

## Test Assessment
**Changed unit:** `file.ts:functionName`
**Fix:** [one-sentence summary]
**Test is not possible because:** [specific reason]
**Suggested alternative:** [what kind of test would apply]

If ALL changed units are ❌, stop here.

Processing order

After classifying all changed files, process every non-❌ unit through its pipeline:

  1. Run all 🔵 units through the Unit Test Pipeline (Steps 2U–7U)
  2. Run all 🟡 units through the Integration Test Pipeline (Steps 2I–7I)
  3. Output ❌ assessments in the final summary

Do not skip or deprioritize any classified unit. "Best candidate" selection is not allowed — every 🔵 and 🟡 unit gets a test or an explicit ❌ reclassification with reasoning.


Step 1: Get the Diff

If PR number given:

bash
gh pr view $PR_NUMBER --json headRefName,baseRefName,title,body,number
gh pr diff $PR_NUMBER

On failure: Error: Could not fetch PR #$PR_NUMBER. Verify the PR number and that \gh\ is authenticated. — stop.

If branch name given:

bash
git fetch origin
git diff origin/<BASE_BRANCH>...origin/<BRANCH>
# Detect BASE_BRANCH:
git remote show origin | grep "HEAD branch"

Fall back to main then master if detection fails.

If commit SHA given:

bash
git diff $SHA^..$SHA

If empty:

bash
git diff $(git merge-base HEAD origin/$(git remote show origin | grep "HEAD branch" | awk '{print $NF}'))...HEAD

Parse changed files: extract paths and changed line ranges. Skip: *.md, *.json (config), *.lock, *.env*, *.css, *.scss, migrations, __generated__, dist/, build/.

If no meaningful code files remain — output the list and stop.

Then run Step 0 on each changed file.


Unit Test Pipeline (Steps 2U–7U)

For fixes classified as 🔵 UNIT


Step 2U: Understand the Project's Test Setup

Detect test framework — read package.json:

FrameworkSignals
Jestjest, @jest/globals, ts-jest, babel-jest in devDependencies
Vitestvitest, @vitest/ui in devDependencies
Mochamocha, @types/mocha in devDependencies
Node test runnernode --test in scripts

Also detect: assertion library (chai, assert, or built-in expect), mock library (jest.mock, vi.mock, sinon), and test script name.

If no framework found, ask: "No test framework found. Should the test use Jest or Vitest?" (options: Jest / Vitest).

Detect test file conventions — Glob: **/*.spec.ts, **/*.test.ts, **/*.spec.js, **/*.test.js, **/__tests__/**/*.ts. From 3–5 matches note: location pattern (co-located / __tests__ / tests/), naming, import style (path aliases), describe nesting, mock patterns.


Step 3U: Analyze the Changed Code

For each changed file, read it fully and identify:

  • Which function(s)/method(s) changed, what was behavior before (- lines) vs after (+ lines), and what condition triggered the bug
  • One-sentence summary: "The fix ensures that [behavior] when [condition], whereas before it [wrong behavior]."
  • Dependencies: external I/O (DB, HTTP, fs, env), framework coupling (req/res, decorators), side effects, or pure logic

Step 4U: Assess Unit Testability

✅ UNIT TESTABLE — pure logic, injectable deps, error handling path, conditional branch, data normalization → write the test.

⚠️ TESTABLE WITH MOCKS — fix is in the logic around external deps; mock them and test the logic (e.g. mock repo, test service logic).

❌ NOT UNIT TESTABLE — if integration territory, reclassify as 🟡 and switch pipeline. Otherwise explain and stop.


Step 5U: Design the Unit Test

Find test file: check for existing file co-located (user.service.spec.ts), in __tests__/, or in tests/ tree. If exists: add to it. If not: create at the path matching project convention.

Design test cases:

  • Test 1 — Regression (mandatory): it('should [correct behavior] when [condition]') — input that triggered the bug, expected output after fix, comment // This test would have failed before the fix
  • Test 2 — Complementary (if applicable): only if a meaningful new branch is introduced by the fix

Mocks (⚠️ cases): specify which deps to mock, what to return, module-level vs test-level.


Step 6U: Choose Destination

Show a brief summary for each designed unit test:

## Unit Test to Write
**File:** `src/services/user.service.spec.ts` [NEW / EXISTING]
**Framework:** Jest
**Unit under test:** `UserService.validateEmail()`
**Fix covered:** "Ensures emails with + characters are accepted"

Then ask destination once (for all unit tests together):

AskUserQuestion: "Where should the unit test(s) be written?" with options:

OptionDescription
Locally (Recommended)Write directly to the working tree on the current branch
New branch + PRCreate a new branch off the current branch, write there, push and open a PR targeting the current branch

If New branch + PR: see Branch + PR Creation section below before proceeding to Step 7U.


Step 7U: Write the Unit Test

Adding to existing file: read it, find the describe block for the unit under test, add it block(s) inside it (or add a new describe at the end if missing). Use Edit.

Creating new file: use Write with correct import style, relative path to unit under test, framework globals if required (Vitest: import { describe, it, expect } from 'vitest'), and only the designed test cases.

After writing — run:

bash
<package-manager> run test -- --testPathPattern="<test-file-name>"
# Vitest:
<package-manager> run test -- <test-file-name>

If fails: diagnose, fix once, re-run. If still failing — report the error, leave the file as-is.


Integration Test Pipeline (Steps 2I–7I)

For fixes classified as 🟡 INTEGRATION


Step 2I: Understand the Integration Test Setup

Detect HTTP testing library — read package.json:

LibrarySignals
Supertestsupertest, @types/supertest
Fastify injectfastify in dependencies
Hono testClienthono in dependencies
NestJS testing@nestjs/testing

If none found, ask: "No HTTP testing library detected. Which should we use?" (options: Supertest / Fastify inject / Skip).

Detect test framework — same as Step 2U.

Detect integration test conventions — Glob: **/*.integration.spec.ts, **/*.integration.test.ts, **/*.e2e-spec.ts, **/*.e2e.spec.ts, **/test/**/*.spec.ts. From 3–5 matches note: location pattern, app bootstrap pattern, beforeAll/afterAll lifecycle, auth pattern, DB pattern.

Detect ORM/DB — check package.json for: @prisma/client (Prisma), typeorm (TypeORM), drizzle-orm (Drizzle), sequelize, or raw pg/mysql2/better-sqlite3. If DB involved, look for DATABASE_URL_TEST, .env.test, globalSetup/globalTeardown in jest config, or test seed/reset helpers.


Step 3I: Analyze the Changed Code

For each changed file, read it fully and identify:

  • Which route/handler/middleware changed, behavior before (- lines) vs after (+ lines), what HTTP scenario triggers the bug
  • One-sentence summary: "The fix ensures that [HTTP behavior] when [request condition], whereas before it [wrong behavior]."
  • Minimal test scenario: method + path, request body/headers, auth state (unauthenticated / role X / expired token), DB preconditions, expected status + body shape

Step 4I: Design the Integration Test

Find test file: check for existing integration/e2e file for the changed route/module. If exists: add to it. If not: use project convention (Step 2I). Common: NestJS → test/users.e2e-spec.ts, Express → tests/routes/users.spec.ts.

Design test cases:

  • Test 1 — Regression (mandatory): it('should [correct HTTP response] when [request condition]') — exact HTTP call that triggered the bug, assert status + body, comment // This test would have failed before the fix
  • Test 2 — Happy path: only if the normal flow of the same route is not already covered

App bootstrap — choose based on detected library:

Supertest + Express:

typescript
import request from 'supertest'
import { app } from '../src/app'
describe('POST /api/users', () => {
it('should return 422 when email already exists', async () => {
// This test would have failed before the fix
await seedUser({ email: 'test@example.com' })
const res = await request(app)
.post('/api/users')
.send({ email: 'test@example.com', name: 'Test' })
expect(res.status).toBe(422)
expect(res.body.error).toMatch(/already exists/)
})
})

Fastify — same structure, replace request call with:

typescript
beforeAll(async () => { app = await buildApp({ logger: false }); await app.ready() })
afterAll(() => app.close())
// in test:
const res = await app.inject({ method: 'POST', url: '/api/users', payload: { ... } })
expect(res.statusCode).toBe(422)

NestJS — same structure, replace bootstrap with:

typescript
beforeAll(async () => {
const module = await Test.createTestingModule({ imports: [AppModule] }).compile()
app = module.createNestApplication(); await app.init()
})
afterAll(() => app.close())
// in test: request(app.getHttpServer()).post(...).expect(422)

Database handling: if project has test DB helpers (found in Step 2I) — use them. If not, add:

typescript
// NOTE: Requires test database. Set DATABASE_URL_TEST in .env.test and migrate schema.
// Adjust seedUser() to match your project's test factory.

Do NOT invent a database setup that doesn't exist in the project.


Step 5I: Choose Destination

Show a brief summary for each designed integration test:

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
1
Repository forks
1
7-day trend score
0

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/andreybegma/claude-code-plugin/test/badge)](https://verified-skill.com/skills/andreybegma/claude-code-plugin/test)

Something wrong with this skill or its page? Tell us.