QA k6 Writer
Purpose
Write k6 performance tests from test case specifications and performance plans. Transform structured performance requirements (from qa-nfr-analyst, qa-plan-creator performance plans) into executable k6 scripts with scenarios, thresholds, checks, and CI-friendly output.
Trigger Phrases
- "Write k6 tests for [API/endpoint]"
- "Generate k6 load tests from performance plan"
- "Create k6 stress tests for [service]"
- "Add k6 soak tests with thresholds"
- "k6 spike test for [endpoint]"
- "Performance tests with k6 scenarios"
- "k6 smoke test for [API]"
- "Breakpoint testing with k6"
- "k6 tests with custom metrics"
- "k6 CI integration for GitHub Actions"
Test Types
| Type |
Purpose |
Key Characteristics |
| Load testing |
Validate behavior under expected load |
Steady VUs, target throughput |
| Stress testing |
Find breaking point |
Ramp up until failure |
| Soak testing |
Detect memory leaks, degradation |
Sustained load over hours |
| Spike testing |
Sudden traffic surge |
Sharp ramp up/down |
| Smoke testing |
Quick sanity check |
1–5 VUs, minimal duration |
| Breakpoint testing |
Find capacity limit |
Incremental load until threshold fails |
Key Features
| Feature |
Description |
| JavaScript ES6 |
Standard JS syntax; no transpilation required |
| Scenarios |
Multiple executors: shared-iterations, per-vu-iterations, constant-arrival-rate, ramping-arrival-rate, externally-controlled |
| Thresholds |
Pass/fail criteria: http_req_duration, http_req_failed, custom metrics |
| Checks |
Assertions: check(res, { 'status is 200': (r) => r.status === 200 }) |
| Stages |
Ramp-up, steady, ramp-down for realistic load profiles |
| Custom metrics |
Trend, Rate, Counter, Gauge for business metrics |
| Protocols |
HTTP, WebSocket, gRPC |
Workflow
- Read performance test plan — From qa-plan-creator (performance plan) or qa-nfr-analyst (NFR specs)
- Define scenarios — Map load profiles to k6 scenarios with appropriate executors
- Set thresholds — Translate SLAs (p95, error rate) into threshold expressions
- Generate k6 script — Produce
.js file with export default function, HTTP calls, checks, groups
- Configure output — JSON, CSV, InfluxDB, Prometheus, or CI-friendly summary
Context7 MCP
Use Context7 MCP for k6 documentation when:
- Scenario executor options or syntax are uncertain
- Threshold expressions or custom metrics need verification
- WebSocket, gRPC, or advanced options require clarification
- Output format or CI integration details are needed
Key Patterns
| Pattern |
Usage |
export default function(options) |
Main entry; receives options (env, etc.) |
http.get(url) / http.post(url, body) |
HTTP requests; returns response |
check(res, assertions) |
Assertions; returns boolean; does not fail test |
sleep(duration) |
Think time between actions |
group(name, fn) |
Logical grouping; metrics tagged by group |
Trend, Rate, Counter, Gauge |
Custom metrics |
scenarios in options |
Define executor-based scenarios |
Threshold Examples
thresholds: {
'http_req_duration': ['p(95)<200', 'p(99)<500'],
'http_req_failed': ['rate<0.01'],
'http_reqs': ['count>1000'],
}
Scenario Executors
| Executor |
Use Case |
shared-iterations |
Fixed total iterations across all VUs |
per-vu-iterations |
Each VU runs N iterations |
constant-arrival-rate |
Fixed request rate (RPS) |
ramping-arrival-rate |
Ramping RPS (stress/spike) |
externally-controlled |
Control VUs from external source |
See references/patterns.md for load profiles, scenario executors, thresholds, custom metrics, groups.
Output
- k6 scripts —
.js files in tests/ or performance/ per project convention
- CI config — GitHub Actions workflow for
k6 run, threshold pass/fail
Scope
Can do (autonomous):
- Generate k6 scripts from performance plans and NFR specs
- Define scenarios with appropriate executors (load, stress, soak, spike)
- Set thresholds from SLAs (p95, p99, error rate)
- Add checks for status codes and response validation
- Use stages for ramping; custom metrics (Trend, Rate, Counter, Gauge)
- Support HTTP, WebSocket, gRPC
- Generate GitHub Actions CI workflow for k6
- Use Context7 MCP for k6 docs
Cannot do (requires confirmation):
- Change production service configuration
- Add dependencies not in package.json
- Override project k6 config without approval
- Target production without explicit consent
Will not do (out of scope):
- Execute tests (user runs
k6 run script.js)
- Write E2E functional tests (use qa-playwright-ts-writer)
- Modify CI/CD pipelines beyond k6 integration
- Provision load infrastructure (k6 Cloud, etc.)
References
references/patterns.md — Load profiles, scenario executors, thresholds, custom metrics, groups
references/config.md — options, scenarios, stages, thresholds, output formats
references/best-practices.md — Realistic load, correlation, parameterization, CI integration
Quality Checklist
Troubleshooting
| Symptom |
Likely Cause |
Fix |
| Thresholds fail in CI |
Different baseline or env |
Align thresholds with target env; use env-specific config |
High http_req_failed |
Timeouts, 5xx, or wrong assertions |
Increase timeout; fix check logic; verify endpoint |
| VUs not ramping as expected |
Wrong executor or stage config |
Use ramping-vus or ramping-arrival-rate for stress |
| Metrics not tagged |
Missing groups |
Wrap logic in group('name', () => { ... }) |
| Script fails to run |
ES module or import error |
Use export default; ensure k6-compatible imports |
| WebSocket/gRPC errors |
Protocol-specific setup |
Use k6/experimental/grpc or k6/ws; check Context7 docs |
| CI exit code 0 despite failures |
Thresholds not enforced |
Ensure --threshold or options.thresholds set; k6 exits non-zero on threshold fail |
1---2name: qa-k6-writer3description: Generate k6 performance tests in JavaScript for load, stress, soak, and spike testing with thresholds, scenarios, checks, and CI-friendly output.4---56# QA k6 Writer78## Purpose910Write k6 performance tests from test case specifications and performance plans. Transform structured performance requirements (from qa-nfr-analyst, qa-plan-creator performance plans) into executable k6 scripts with scenarios, thresholds, checks, and CI-friendly output.1112## Trigger Phrases1314- "Write k6 tests for [API/endpoint]"15- "Generate k6 load tests from performance plan"16- "Create k6 stress tests for [service]"17- "Add k6 soak tests with thresholds"18- "k6 spike test for [endpoint]"19- "Performance tests with k6 scenarios"20- "k6 smoke test for [API]"21- "Breakpoint testing with k6"22- "k6 tests with custom metrics"23- "k6 CI integration for GitHub Actions"2425## Test Types2627| Type | Purpose | Key Characteristics |28|------|---------|---------------------|29| **Load testing** | Validate behavior under expected load | Steady VUs, target throughput |30| **Stress testing** | Find breaking point | Ramp up until failure |31| **Soak testing** | Detect memory leaks, degradation | Sustained load over hours |32| **Spike testing** | Sudden traffic surge | Sharp ramp up/down |33| **Smoke testing** | Quick sanity check | 1–5 VUs, minimal duration |34| **Breakpoint testing** | Find capacity limit | Incremental load until threshold fails |3536## Key Features3738| Feature | Description |39|---------|-------------|40| **JavaScript ES6** | Standard JS syntax; no transpilation required |41| **Scenarios** | Multiple executors: shared-iterations, per-vu-iterations, constant-arrival-rate, ramping-arrival-rate, externally-controlled |42| **Thresholds** | Pass/fail criteria: `http_req_duration`, `http_req_failed`, custom metrics |43| **Checks** | Assertions: `check(res, { 'status is 200': (r) => r.status === 200 })` |44| **Stages** | Ramp-up, steady, ramp-down for realistic load profiles |45| **Custom metrics** | Trend, Rate, Counter, Gauge for business metrics |46| **Protocols** | HTTP, WebSocket, gRPC |4748## Workflow49501. **Read performance test plan** — From qa-plan-creator (performance plan) or qa-nfr-analyst (NFR specs)512. **Define scenarios** — Map load profiles to k6 scenarios with appropriate executors523. **Set thresholds** — Translate SLAs (p95, error rate) into threshold expressions534. **Generate k6 script** — Produce `.js` file with `export default function`, HTTP calls, checks, groups545. **Configure output** — JSON, CSV, InfluxDB, Prometheus, or CI-friendly summary5556## Context7 MCP5758Use **Context7 MCP** for k6 documentation when:59- Scenario executor options or syntax are uncertain60- Threshold expressions or custom metrics need verification61- WebSocket, gRPC, or advanced options require clarification62- Output format or CI integration details are needed6364## Key Patterns6566| Pattern | Usage |67|---------|-------|68| `export default function(options)` | Main entry; receives `options` (env, etc.) |69| `http.get(url)` / `http.post(url, body)` | HTTP requests; returns response |70| `check(res, assertions)` | Assertions; returns boolean; does not fail test |71| `sleep(duration)` | Think time between actions |72| `group(name, fn)` | Logical grouping; metrics tagged by group |73| `Trend`, `Rate`, `Counter`, `Gauge` | Custom metrics |74| `scenarios` in options | Define executor-based scenarios |7576### Threshold Examples7778```javascript79thresholds: {80 'http_req_duration': ['p(95)<200', 'p(99)<500'],81 'http_req_failed': ['rate<0.01'],82 'http_reqs': ['count>1000'],83}84```8586### Scenario Executors8788| Executor | Use Case |89|----------|----------|90| `shared-iterations` | Fixed total iterations across all VUs |91| `per-vu-iterations` | Each VU runs N iterations |92| `constant-arrival-rate` | Fixed request rate (RPS) |93| `ramping-arrival-rate` | Ramping RPS (stress/spike) |94| `externally-controlled` | Control VUs from external source |9596See `references/patterns.md` for load profiles, scenario executors, thresholds, custom metrics, groups.9798## Output99100- **k6 scripts** — `.js` files in `tests/` or `performance/` per project convention101- **CI config** — GitHub Actions workflow for `k6 run`, threshold pass/fail102103## Scope104105**Can do (autonomous):**106- Generate k6 scripts from performance plans and NFR specs107- Define scenarios with appropriate executors (load, stress, soak, spike)108- Set thresholds from SLAs (p95, p99, error rate)109- Add checks for status codes and response validation110- Use stages for ramping; custom metrics (Trend, Rate, Counter, Gauge)111- Support HTTP, WebSocket, gRPC112- Generate GitHub Actions CI workflow for k6113- Use Context7 MCP for k6 docs114115**Cannot do (requires confirmation):**116- Change production service configuration117- Add dependencies not in package.json118- Override project k6 config without approval119- Target production without explicit consent120121**Will not do (out of scope):**122- Execute tests (user runs `k6 run script.js`)123- Write E2E functional tests (use qa-playwright-ts-writer)124- Modify CI/CD pipelines beyond k6 integration125- Provision load infrastructure (k6 Cloud, etc.)126127## References128129- `references/patterns.md` — Load profiles, scenario executors, thresholds, custom metrics, groups130- `references/config.md` — options, scenarios, stages, thresholds, output formats131- `references/best-practices.md` — Realistic load, correlation, parameterization, CI integration132133## Quality Checklist134135- [ ] Scenarios match performance plan load profiles136- [ ] Thresholds reflect SLAs (p95, p99, error rate)137- [ ] Checks validate critical responses; use `threshold` for pass/fail138- [ ] Think time (sleep) between requests where realistic139- [ ] No hardcoded secrets; use `__ENV` or options140- [ ] Groups used for logical metric segmentation141- [ ] Output format suitable for CI (JSON summary or exit code)142- [ ] Stages/ramping match test type (stress = ramp up, soak = steady)143144## Troubleshooting145146| Symptom | Likely Cause | Fix |147|---------|--------------|-----|148| Thresholds fail in CI | Different baseline or env | Align thresholds with target env; use env-specific config |149| High `http_req_failed` | Timeouts, 5xx, or wrong assertions | Increase timeout; fix check logic; verify endpoint |150| VUs not ramping as expected | Wrong executor or stage config | Use `ramping-vus` or `ramping-arrival-rate` for stress |151| Metrics not tagged | Missing groups | Wrap logic in `group('name', () => { ... })` |152| Script fails to run | ES module or import error | Use `export default`; ensure k6-compatible imports |153| WebSocket/gRPC errors | Protocol-specific setup | Use `k6/experimental/grpc` or `k6/ws`; check Context7 docs |154| CI exit code 0 despite failures | Thresholds not enforced | Ensure `--threshold` or options.thresholds set; k6 exits non-zero on threshold fail |