#!/bin/sh set -eu . "$(dirname "$0")/common.sh" xburner_init TMP_DIR=$(xburner_mktemp_dir config-loader-summary) SERVER_LOG="${ROOT_DIR}/.zig-cache/config-loader-summary-server.log" cleanup() { xburner_stop_background_pid "${SERVER_PID:-}" rm -rf "${TMP_DIR}" } trap cleanup EXIT INT TERM normalize_summary() { input_path=$1 output_path=$2 "${PYTHON_BIN}" - "$input_path" "$output_path" <<'PY' import json import sys input_path, output_path = sys.argv[1], sys.argv[2] with open(input_path, "r", encoding="utf-8") as f: data = json.load(f) def keep(window): return { "requests_failed": window["requests_failed"], "iterations_failed": window["iterations_failed"], "dropped_iterations": window["dropped_iterations"], "transport_errors_total": window["transport_errors_total"], "transport_errors_timeout": window["transport_errors_timeout"], "transport_errors_connect_timeout": window["transport_errors_connect_timeout"], "transport_errors_io_timeout": window["transport_errors_io_timeout"], "script_errors_total": window["script_errors_total"], "script_timeouts_total": window["script_timeouts_total"], "hard_timeouts_total": window["hard_timeouts_total"], "poisoned_workers_total": window["poisoned_workers_total"], "vus_recreated_total": window["vus_recreated_total"], "unhealthy_vus_total": window["unhealthy_vus_total"], "spare_vus_activated_total": window["spare_vus_activated_total"], "request_summaries": [ { "name": item["name"], "summary": { "requests_failed": item["summary"]["requests_failed"], "transport_errors_total": item["summary"]["transport_errors_total"], "transport_errors_timeout": item["summary"]["transport_errors_timeout"], "transport_errors_connect_timeout": item["summary"]["transport_errors_connect_timeout"], "transport_errors_io_timeout": item["summary"]["transport_errors_io_timeout"], }, } for item in window.get("request_summaries", []) ], } normalized = { "schema_version": data["schema_version"], "scenario_name": data["scenario_name"], "scenario_mode": data["scenario_mode"], "wasm_backend": data["wasm_backend"], "interrupted": data["interrupted"], "thresholds_failed": data["thresholds_failed"], "measured": keep(data["measured"]), "warmup": keep(data["warmup"]), } with open(output_path, "w", encoding="utf-8") as f: json.dump(normalized, f, separators=(",", ":")) f.write("\n") PY } compare_fixture() { fixture_path=$1 actual_path=$2 xburner_compare_fixture "config loader summary mismatch" "${fixture_path}" "${actual_path}" } xburner_build_if_needed xburner_build_workflow_sample_if_needed xburner_start_combined_fixture_servers "${SERVER_LOG}" API_HOST=wrong.example.invalid \ API_PATH=wrong-path \ "${XBURNER_BIN}" run "${ROOT_DIR}/testdata/fixtures/config-loader-run/root.toml" \ > "${TMP_DIR}/config_loader_run.json" normalize_summary "${TMP_DIR}/config_loader_run.json" "${TMP_DIR}/config_loader_run.normalized.json" compare_fixture "${ROOT_DIR}/testdata/golden/config_loader_run_summary.json" \ "${TMP_DIR}/config_loader_run.normalized.json" cp -R "${ROOT_DIR}/testdata/fixtures/workflow-config-loader-run" "${TMP_DIR}/workflow-config-loader-run" cp "${ROOT_DIR}/samples/workflow-health.wasm" "${TMP_DIR}/workflow-config-loader-run/workflow-health.wasm" ( cd "${TMP_DIR}/workflow-config-loader-run" API_HOST=wrong.example.invalid \ LOGIN_PATH=wrong-login \ PROFILE_PATH=wrong-me \ TOKEN_VALUE=wrong-token \ "${XBURNER_BIN}" run root.toml > "${TMP_DIR}/workflow_config_loader_run.json" ) normalize_summary "${TMP_DIR}/workflow_config_loader_run.json" "${TMP_DIR}/workflow_config_loader_run.normalized.json" compare_fixture "${ROOT_DIR}/testdata/golden/workflow_config_loader_run_summary.json" \ "${TMP_DIR}/workflow_config_loader_run.normalized.json" ( cd "${TMP_DIR}/workflow-config-loader-run" API_HOST=wrong.example.invalid \ LOGIN_PATH=wrong-login \ PROFILE_PATH=wrong-me \ TOKEN_VALUE=wrong-token \ "${XBURNER_BIN}" run --wasm-backend wasm3 root.toml > "${TMP_DIR}/workflow_config_loader_run_wasm3.json" ) normalize_summary "${TMP_DIR}/workflow_config_loader_run_wasm3.json" "${TMP_DIR}/workflow_config_loader_run_wasm3.normalized.json" compare_fixture "${ROOT_DIR}/testdata/golden/workflow_config_loader_run_summary_wasm3.json" \ "${TMP_DIR}/workflow_config_loader_run_wasm3.normalized.json" set +e API_HOST=wrong.example.invalid \ API_PATH=wrong-path \ "${XBURNER_BIN}" run "${ROOT_DIR}/testdata/fixtures/config-loader-abort/root.toml" \ > "${TMP_DIR}/config_loader_abort.json" ABORT_EXIT=$? set -e if [ "${ABORT_EXIT}" -ne 1 ]; then printf >&2 'expected abort fixture to exit 1, got %s\n' "${ABORT_EXIT}" exit 1 fi "${PYTHON_BIN}" - "${TMP_DIR}/config_loader_abort.json" <<'PY' import json import sys with open(sys.argv[1], "r", encoding="utf-8") as f: data = json.load(f) assert data["scenario_name"] == "config-loader-abort" assert data["scenario_mode"] == "simple" assert data["thresholds_failed"] is True assert data["measured"]["requests_failed"] >= 1 assert data["measured"]["request_summaries"][0]["name"] == "health" PY printf 'config loader run summary matches\n'