跪拜 Guibai
← All articles
AI · Testing · Backend

api-scenario-runner Executes Full Business-Chain API Tests with Three-Level Assertions and CI-Ready Compilation

By 狂师 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

End-to-end API testing now has an AI-driven path that treats a whole business flow as the unit under test, not isolated endpoints. That means fewer surprises in production where every endpoint works but the checkout still fails, and it turns scenario definitions into executable, CI-friendly pytest code.

Summary

All the single-interface tests can pass while the business flow still breaks. api-scenario-runner closes that gap by treating the whole chain from registration to order query as one test scenario. It reads a scenario YAML file, sends requests in sequence, auto-extracts and injects variables, and adds Bearer token headers where needed.

Assertions run at three levels: status code, business code, and JSONPath, plus a terminal DB state check that only allows SELECT with parameterized SQL. Failure stops execution and a snapshot file records the real request, response, and variables after injection, with sensitive values masked. Failures classify into five categories: missing variable, assertion failure, API error, connection error, and DB error.

Two execution modes exist: direct run and compile to a pytest project. Compiled scripts drop into the existing test hierarchy, schedule through api-test-executor, and feed a pipeline that includes cleanup and reporting. A dedicated idempotency round proves a second run goes green without changes, thanks to dynamic timestamp usernames and proper data cleanup, separating CI-viable tests from flaky ones.

Takeaways
— api-scenario-runner executes scenario YAML files, sending requests in order and auto-injecting variables and Bearer tokens.
— It uses three-level assertions: status code, business code, and JSONPath, followed by DB terminal-state assertions that only run SELECT and parameterized SQL.
— On failure, it stops immediately and saves a steps_snapshot.json with injected request, response, and variable views, with sensitive values masked.
— Failures are classified into five categories: VARIABLE_MISSING, ASSERTION_FAILED, API_ERROR, CONNECTION_ERROR, DB_ERROR.
— It supports compile mode that generates a pytest project (test_scenario_<id>.py and data/scenario_<id>.yaml) reusing the project's utils/config.
— The shopping flow scenario includes 14 API call steps, all passing in the demo, plus 4 DB terminal checks.
— Idempotency is ensured by dynamic timestamp-based usernames and cleanup through api-testdata-cleaner, so a second run stays green.
Conclusions

Moving from single-interface tests to whole business chains catches integration failures that unit-style API tests miss, like a token that doesn't propagate from login to order.

The idempotency round is the real gate for CI adoption; most test suites fail on repeated runs due to state pollution, and dynamic data plus cleanup is the solution.

Compiling scenario YAML to pytest bridges declarative AI-driven test design with existing test infrastructure, letting teams adopt the approach without abandoning their current runners and reporters.

Concepts & terms
scenario YAML file
A declarative definition of a business-flow test: the sequence of API calls, variable extraction and injection rules, assertion conditions, and optional DB terminal checks.
three-level assertion
Step-level checks that verify HTTP status code, business response code, and JSONPath values in that order, before a final database state assertion runs.
steps_snapshot.json
A diagnostic file saved on failure that captures the actual injected request, response, and variable values for each step, with sensitive fields masked, to help debug why a scenario failed.
From the discussion

The discussion focuses on the guardrails built into the Skill system and on aligning verification granularity with business granularity. Both comments treat single-interface green status as insufficient, arguing that global chain control must be verified first. The split of scenario modeling and chain execution into separate Skills is seen as a sound way to separate the 'what' from the 'how'. One comment adds that even 99.99% end-to-end success leaves a 0.01% gap that demands one-click rollback, failure replay, and per-step logging to avoid production incidents.

— The Skill's core value lies in its guardrails (SELECT-only DB assertions, SQL parameterization, no hardcoded connection strings, fail-fast scene preservation, sensitive-value masking), not in raw coverage.
— Stronger automation abilities require clearer boundary drawing; agent automation is ultimately judged by how it handles failures and blocks overstepping, not by its raw capability.
— Local controllability does not equal global controllability; a single interface passing while the business chain stalls illustrates the same gap.
— Acceptance granularity must match business granularity, and separating scenario modeling from chain execution cleanly divides the testing 'what' from the running 'how'.
— The 0.01% failure risk in end-to-end chains comes from cross-service state inconsistency leaving dirty data, so the chain needs one-click rollback, failure replay, and step-level logs to stay safe in production.
Featured comments
GALer阿青

What impresses me most about this Skill system isn't the coverage, but those guardrails: DB assertions only allow SELECT, SQL parameterization, orchestration files forbid hardcoded connection strings, fail-fast preserves the scene, and sensitive values are masked in snapshots. The stronger the capability, the more it tests whether the boundaries are drawn clearly enough. In the end, agent automation often isn't about how much it can do, but whether there's a scene preserved when it errs, and whether it's blocked when it oversteps. A single interface being all green while the business chain stalls is essentially the same thing: local controllability isn't global controllability. Treating the chain as a whole test is a way of first verifying controllability, then discussing automation.

GALer阿青

A single interface all green yet the business still stalls—that pitfall is all too real: the granularity of acceptance has to align with the granularity of the business. Splitting scenario modeling and chain execution into two Skills, each managing what to test and how to run, is a clever combination. One more point: end-to-end 99.99% is already strong, but that 0.01% is often dirty data left by cross-service state inconsistency; the chain still needs one-click rollback, failure replay, and logs at every step, otherwise no matter how high the coverage, you fear production blowing up.

See top comments, translated →
Source: juejin.cn ↗ Google Translate ↗ Backup ↗