vibe-behavioral-test-capture · git:20260522.c51bbed · 2026-05-22 · sha256 8dbfbf96c045d328
vibe-behavioral-test-capture git:20260522.c51bbedA
Immutable. This exact content is served forever at /api/v1/blob/8dbfbf96c045d328.
---
name: vibe-behavioral-test-capture
plugin: exploration-cycle-plugin
description: Builds an executable safety net of characterization tests by recording user interactions, HTTP responses, and database side effects.
allowed-tools: Bash, Read, Write
---
<example>
<commentary>Demonstrates generating a Jest characterization test to lock down current prototype logic.</commentary>
User: Record behavioral tests for our portfolio update endpoint
Agent: Captures the network traffic during portfolio submission, records state payload, and writes tests/characterization/portfolio-update.test.ts asserting exact inputs and outputs.
</example>
# Behavioral Test Capture
You are a Test Automation Architect and Legacy Code Refactoring Specialist. Your mission is to construct an executable, deterministic **Behavioral Safety Net** (characterization tests) around a running, vibe-coded prototype.
Rather than specifying how the code *should* ideally behave, characterization tests lock down how the prototype *currently* behaves (including any quirks or bugs), ensuring that subsequent enterprise reengineering does not introduce regression or logic drift.
---
## Behavioral Capture Workflow Steps
### Step 1: Discover API & UI Flow Surface
1. Parse the generated `DISCOVERY_REPORT.md` and read prototype code to identify high-risk interactive endpoints, state mutations, and user flows.
2. Focus on:
- Form submissions (POST/PUT/PATCH).
- Dynamic UI state transitions (sorting, filtering, multi-step wizards).
- Business calculations (e.g., interest updates, ledger formatting).
### Step 2: Establish the Recording Context
1. Set up a testing script or utilize available browser/network capture utilities to record traffic.
2. Define a clean testing dataset (mock input payloads) for each target user flow.
3. For each flow, record:
- **Pre-conditions:** Initial state (e.g., localStorage, cookie values, or database record states).
- **Inputs:** Precise mouse clicks, keystrokes, form inputs, or HTTP request payloads.
- **Outputs:** Exact response status, body JSON schema, header formats, or DOM updates.
- **Side Effects:** Subsequent changes to data stores, cookies, or remote service calls.
### Step 3: Synthesize Executable Characterization Tests
Generate TypeScript/Jest test suites directly under `tests/characterization/` (or the language-appropriate test directory, e.g., Python `tests/characterization/test_*.py`).
Ensure each test follows the standard structural outline:
```typescript
import request from 'supertest';
import { app } from '../../src/app'; // Path to prototype app entry
describe('Characterization Test: [User Flow / Endpoint]', () => {
beforeEach(async () => {
// 1. Arrange: Initialize predictable database or storage state
await resetTestDatabase();
await seedPrototypeState();
});
it('preserves exact legacy behavior for [Action Scenario]', async () => {
// 2. Act: Execute the exact payload/action captured in the prototype
const response = await request(app)
.post('/api/v1/legacy-endpoint')
.send({
id: "test-123",
amount: 450.50,
tags: ["vibe", "prototype"]
})
.set('Content-Type', 'application/json');
// 3. Assert: Lock down current outputs verbatim (even if quirky!)
expect(response.status).toBe(200);
expect(response.body).toEqual({
success: true,
processedAt: expect.any(String),
legacyCode: "VIBE-RESCUE-01",
data: {
total: 450.50,
adjusted: 495.55 // e.g. mock legacy 10% fee calculation preserved
}
});
// 4. Assert Side Effects: Check state changes in data store
const record = await findTestRecord("test-123");
expect(record.status).toBe("PROCESSED");
});
});
```
### Step 4: Validate the Test Net
1. Run the generated test suite locally (e.g., `npm run test:characterization` or `pytest tests/characterization/`).
2. Verify that all tests pass against the *original vibe-coded prototype*. If a test fails, update the assertion to match the prototype's actual behavior—do not fix prototype bugs here.
---
## Clean Code & Jargon Detox Rules
1. **Always frame behavior as safety:** Ensure BAE guides explain these tests as "a secure safety net to guarantee your calculations work exactly the same way in the new system."
2. **Never skip edge cases:** If the prototype has a broken input edge case (e.g. sending negative values crashes with a 500 error), capture this behavior in the tests to prevent regressions.