Verify AI-generated scripts before CI

Generated code saves time, but CI needs deterministic and reviewable tests. Use this checklist before you commit or wire a script into your pipeline. For practice, assume your artifact is still the QuickPizza script from earlier milestones (from the Cloud script editor or from disk), then reuse the same checklist for internal APIs.

To validate your script for CI, complete these steps.

  1. Validate script structure. Confirm the following items.

    • Imports resolve correctly.
    • options contains only supported settings for where you run (local k6 vs Grafana Cloud k6 validation rules can differ; refer to Use k6 Script Authoring mode if analysis flagged option combinations).
    • The default function contains the user-flow requests you intend to test.
  2. Validate pass/fail logic. Confirm the following items.

    • check() coverage exists for critical requests. For QuickPizza, require at minimum status 200 on the paths you care about.
    • thresholds are explicit and tied to your SLO or team target when you move beyond demos.
    • Threshold names match the metrics you actually emit.
  3. Validate load realism and pacing. Confirm the following items.

    • Scenario shape matches expected traffic.
    • Requests are paced appropriately (sleep and/or scenario executors).
    • Health and internal endpoints are excluded unless intentionally tested.
  4. Validate secrets and environment handling. Confirm the following items.

    • Tokens and credentials come from environment variables, not hardcoded values.
    • Base URLs and environment-specific values are parameterized.
    • When your script references Grafana Cloud k6 secrets by name, create and configure those secrets in your stack before you run the test in the UI or in CI. A missing secret at run time fails the run the same way a wrong credential does. Refer to Create and manage secrets for setup, rotation, and access control.
  5. Run pre-CI checks on a copy of the script your pipeline will execute. If you have been iterating in the Grafana Cloud k6 script editor, optionally run a short Create and Run smoke in the UI first so checks and thresholds behave as expected in Cloud before the CLI becomes the main gate. Refer to Use the script editor. Then use local commands like these.

    Bash
    k6 run --iterations 1 your-script.js
    k6 run your-script.js

    The first command catches syntax and import issues quickly. The second runs with the script’s own options so thresholds and duration match what CI will exercise (keep duration short while learning).

  6. Add the script to CI only after local validation passes and peer review is complete.

You now have a repeatable verification gate for AI-assisted scripts. In the final milestone, you wrap up and choose where to go next.

Were you successful?


page 8 of 9