--- name: k6-test-maintenance description: > Maintain and improve existing k6 test scripts. Covers threshold tightening based on trend data, version migration between k6 releases, auto-fixing tests when the underlying service changes, refactoring for cleanliness, and auditing scripts against current best practices from docs. Use when the user asks to fix a failing k6 test, tighten thresholds, migrate a script to a new k6 version, refactor a test, update a script after a service change, or improve a script with best practices. Trigger on phrases like "fix my k6 test", "tighten my thresholds", "migrate to k6 v2", "update my test script", "refactor this k6 test", "my test is failing after a deploy", "apply best practices to my script", "modernize my k6 test", or "the service changed and my test broke". Also trigger when another skill (k6-trend-analysis or k6-cloud-investigate-test) hands off with a recommendation to edit a script. --- # k6 Test Maintenance Maintain, fix, and improve existing k6 test scripts. Five maintenance tasks, each with a step-by-step procedure in [`references/workflows.md`](references/workflows.md): 1. **Threshold tightening** -- adjust threshold values based on observed metrics 2. **Version migration** -- update scripts for new k6 releases 3. **Service change adaptation** -- fix tests when the underlying service changes 4. **Refactoring** -- clean up and modernize test code 5. **Best practices audit** -- check scripts against current k6 best practices ## Core principle: behavior-aware change control Classify every proposed change by whether it alters the test's runtime behavior: - **Syntactic** (behavior unchanged): the k6 runtime produces identical metrics, pass/fail results, and endpoints. Examples: rename a variable, `let` → `const`, remove unused imports, update comments, reformat. **Apply directly.** - **Behavioral** (behavior differs): anything affecting metrics, pass/fail, timing, request targets, or load shape. Examples: threshold value changes, adding `sleep()`, endpoint URL updates, check rewrites, scenario changes, new thresholds. **Always present as a diff with rationale and require confirmation.** The threshold for "behavioral" is deliberately low. If in doubt, treat it as behavioral and ask -- a trivial-looking threshold change can cascade to CI gates, SLO calculations, and alerting. ## Dependencies - **`k6-manage`** -- fetch and edit GCk6-hosted scripts safely (§5: GET, backup, edit, validate, PUT, verify by sha256). Read it before touching any cloud-hosted script. - **`gcx`** -- sole tool for Grafana Cloud API access. - **mcp-k6** tools -- `validate_script` and `get_documentation`. Check availability first; fall back to `k6 x docs` if absent. - **`k6 x docs`** CLI -- documentation lookup when mcp-k6 isn't configured. - **`k6` CLI** -- local validation (`k6 inspect`, `k6 run`). ## Validation loop (every edit) Every workflow produces a modified script. Never present or PUT an unvalidated script -- run this loop, fixing and re-running until it passes: 1. **Parse-check**: `k6 inspect