const std = @import("std"); const config = @import("../config.zig"); const literals = @import("literals.zig"); const ByteSize = config.ByteSize; const CookieJarScope = config.CookieJarScope; const Duration = config.Duration; const Execution = config.Execution; const HttpMethod = config.HttpMethod; const ScenarioConfig = config.ScenarioConfig; const ScenarioMode = config.ScenarioMode; const ThresholdMetric = config.ThresholdMetric; const ThresholdOperator = config.ThresholdOperator; const ThresholdValue = config.ThresholdValue; const WasmBackend = config.WasmBackend; test "parse workflow config with setup requests and thresholds" { const source = \\[scenario] \\name = "http-login-flow" \\protocol = "http" \\target = "https://example.internal" \\wasm = "./scenario.wasm" \\ \\[execution] \\mode = "constant-arrival-rate" \\rate = 200 \\duration = "60s" \\warmup = "5s" \\pre_allocated_vus = 64 \\max_vus = 128 \\ \\[[setup.requests]] \\name = "bootstrap-auth" \\method = "POST" \\path = "/v1/bootstrap-login" \\headers = { content-type = "application/json" } \\body = "{\"username\":\"seed-user\",\"password\":\"seed-pass\"}" \\store_body_as = "setup.BOOTSTRAP_LOGIN_BODY" \\capture_body_max_bytes = 4096 \\ \\[http.defaults] \\use_tls = true \\cookie_jar = true \\cookie_jar_scope = "vu" \\max_steps_per_iteration = 16 \\ \\[http.defaults.tls] \\ca_file = "./certs/ca.pem" \\insecure_skip_verify = false \\server_name = "example.internal" \\ \\[[http.requests]] \\id = 1 \\name = "login" \\method = "POST" \\path = "/v1/login" \\headers = { content-type = "application/json" } \\timeout_ms = 1000 \\pass_response_body = true \\capture_body_max_bytes = 2048 \\ \\[[http.requests]] \\id = 2 \\name = "get-me" \\method = "GET" \\path = "/v1/me" \\headers = { authorization = "Bearer ${iter.TOKEN}" } \\timeout_ms = 1000 \\pass_response_body = true \\capture_body_max_bytes = 4096 \\ \\[[http.requests]] \\id = 3 \\name = "get-orders" \\method = "GET" \\path = "/v1/orders/${iter.USER_ID}" \\headers = { authorization = "Bearer ${iter.TOKEN}" } \\timeout_ms = 1000 \\delay_before_ms = 250 \\pass_response_body = false \\ \\[[thresholds]] \\metric = "http.request.duration.p99" \\scope = { request = "login" } \\op = "<=" \\value = "500ms" \\ \\[[thresholds]] \\metric = "http.error_rate" \\op = "<=" \\value = "0.01" ; var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit(); try std.testing.expectEqual(ScenarioMode.workflow, parsed.scenario.mode()); try std.testing.expectEqual(Execution.Mode.constant_arrival_rate, parsed.execution.mode); try std.testing.expectEqual(Duration.fromSeconds(60).nanos, parsed.execution.duration.nanos); try std.testing.expectEqual(Duration.fromSeconds(5).nanos, parsed.execution.warmup.nanos); try std.testing.expectEqual(true, parsed.http.defaults.use_tls); try std.testing.expectEqual(CookieJarScope.vu, parsed.http.defaults.cookie_jar_scope); try std.testing.expectEqualStrings("./certs/ca.pem", parsed.http.defaults.tls.ca_file.?); try std.testing.expectEqual(@as(usize, 1), parsed.setup.requests.len); try std.testing.expectEqualStrings("setup.BOOTSTRAP_LOGIN_BODY", parsed.setup.requests[0].store_body_as.?); try std.testing.expectEqual(@as(usize, 3), parsed.http.requests.len); try std.testing.expectEqual(HttpMethod.POST, parsed.http.requests[0].method); try std.testing.expectEqualStrings("content-type", parsed.http.requests[0].headers[0].key); try std.testing.expectEqualStrings("application/json", parsed.http.requests[0].headers[0].value); try std.testing.expectEqual(@as(u32, 250), parsed.http.requests[2].delay_before_ms); try std.testing.expectEqual(@as(usize, 2), parsed.thresholds.len); try std.testing.expectEqual(ThresholdMetric.http_request_duration_p99, parsed.thresholds[0].metric); try std.testing.expectEqual(ThresholdOperator.lte, parsed.thresholds[0].op); try std.testing.expectEqualStrings("login", parsed.thresholds[0].scope.request.?); try std.testing.expectEqual(ThresholdValue{ .duration = Duration.fromMillis(500) }, parsed.thresholds[0].value); } test "parse threshold expressions with logical operators" { const source = \\[scenario] \\name = "expr" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "health" \\method = "GET" \\path = "/health" \\ \\[[thresholds]] \\scope = { request = "health" } \\expr = "check.pass_rate >= 1.0 && http.request.duration.p99 <= 500ms" ; var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit(); try std.testing.expectEqual(config.ThresholdExpressionMode.all_of, parsed.thresholds[0].expression_mode.?); try std.testing.expectEqual(@as(usize, 2), parsed.thresholds[0].expression_clauses.len); try std.testing.expectEqual(ThresholdMetric.check_pass_rate, parsed.thresholds[0].expression_clauses[0].metric); try std.testing.expectEqual(ThresholdMetric.http_request_duration_p99, parsed.thresholds[0].expression_clauses[1].metric); } test "parse simple mode config without wasm" { const source = \\[scenario] \\name = "simple-healthcheck" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 4 \\duration = "30s" \\warmup = "3s" \\thread_count = 3 \\ \\[[http.requests]] \\id = 1 \\name = "health" \\method = "GET" \\path = "/health" \\timeout_ms = 500 \\ \\[[thresholds]] \\metric = "http.request.duration.p99" \\op = "<=" \\value = "200ms" ; var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit(); try std.testing.expectEqual(ScenarioMode.simple, parsed.scenario.mode()); try std.testing.expectEqual(WasmBackend.wamr, parsed.scenario.wasm_backend); try std.testing.expectEqual(@as(usize, 1), parsed.http.requests.len); try std.testing.expectEqual(Duration.fromSeconds(3).nanos, parsed.execution.warmup.nanos); try std.testing.expectEqual(Duration.fromMillis(100).nanos, parsed.execution.script_timeout.nanos); try std.testing.expectEqual(@as(u32, 0), parsed.execution.max_poisoned_workers); try std.testing.expectEqual(@as(u32, 3), parsed.execution.thread_count.?); try std.testing.expectEqual(@as(usize, 3), parsed.execution.effectiveThreadCount(8)); } test "parse grpc simple mode config using shared request schema" { const source = \\[scenario] \\name = "grpc-health" \\protocol = "grpc" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 2 \\duration = "10s" \\ \\[http.defaults] \\cookie_jar = false \\headers = { x-env = "fixture" } \\ \\[[http.requests]] \\id = 1 \\name = "check" \\method = "POST" \\path = "/grpc.health.v1.Health/Check" \\body = "\x0a\x00" \\timeout_ms = 750 \\capture_body_max_bytes = 1024 ; var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit(); try std.testing.expectEqual(ScenarioMode.simple, parsed.scenario.mode()); try std.testing.expectEqual(config.Protocol.grpc, parsed.scenario.protocol); try std.testing.expectEqual(false, parsed.http.defaults.cookie_jar); try std.testing.expectEqualStrings("fixture", parsed.http.requests[0].headers[0].value); try std.testing.expectEqualStrings("/grpc.health.v1.Health/Check", parsed.http.requests[0].path); try std.testing.expectEqual(HttpMethod.POST, parsed.http.requests[0].method); try std.testing.expectEqual(@as(u32, 1024), parsed.http.requests[0].capture_body_max_bytes); } test "http request defaults apply and request headers override by key" { const source = \\[scenario] \\name = "defaults" \\protocol = "http" \\target = "https://example.internal" \\wasm = "./scenario.wasm" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[http] \\version = "1.1" \\max_connections = 12 \\ \\[http.defaults] \\headers = { authorization = "Bearer default", accept = "application/json" } \\connect_timeout_ms = 150 \\timeout_ms = 900 \\delay_before_ms = 25 \\pass_response_body = true \\capture_body_max_bytes = 2048 \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" \\headers = { authorization = "Bearer override" } \\ \\[[http.requests]] \\id = 2 \\name = "two" \\method = "GET" \\path = "/two" \\connect_timeout_ms = 50 \\timeout_ms = 100 \\pass_response_body = false \\check_status_code = 200 \\check_body_contains = "ok" \\check_response_header = "x-trace-id" ; var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit(); try std.testing.expectEqual(config.HttpVersion.http11, parsed.http.version); try std.testing.expectEqual(@as(?u32, 12), parsed.http.max_connections); try std.testing.expectEqual(@as(usize, 2), parsed.http.defaults.headers.len); try std.testing.expectEqual(@as(u32, 150), parsed.http.requests[0].connect_timeout_ms); try std.testing.expectEqual(@as(u32, 900), parsed.http.requests[0].timeout_ms); try std.testing.expectEqual(@as(u32, 25), parsed.http.requests[0].delay_before_ms); try std.testing.expectEqual(true, parsed.http.requests[0].pass_response_body); try std.testing.expectEqual(@as(u32, 2048), parsed.http.requests[0].capture_body_max_bytes); try std.testing.expectEqual(@as(usize, 2), parsed.http.requests[0].headers.len); try std.testing.expectEqualStrings("accept", parsed.http.requests[0].headers[0].key); try std.testing.expectEqualStrings("application/json", parsed.http.requests[0].headers[0].value); try std.testing.expectEqualStrings("authorization", parsed.http.requests[0].headers[1].key); try std.testing.expectEqualStrings("Bearer override", parsed.http.requests[0].headers[1].value); try std.testing.expectEqual(@as(u32, 50), parsed.http.requests[1].connect_timeout_ms); try std.testing.expectEqual(@as(u32, 100), parsed.http.requests[1].timeout_ms); try std.testing.expectEqual(@as(u32, 25), parsed.http.requests[1].delay_before_ms); try std.testing.expectEqual(false, parsed.http.requests[1].pass_response_body); try std.testing.expectEqual(@as(u32, 2048), parsed.http.requests[1].capture_body_max_bytes); try std.testing.expectEqual(@as(?u16, 200), parsed.http.requests[1].check_status_code); try std.testing.expectEqualStrings("ok", parsed.http.requests[1].check_body_contains.?); try std.testing.expectEqualStrings("x-trace-id", parsed.http.requests[1].check_response_header.?); try std.testing.expectEqual(@as(usize, 2), parsed.http.requests[1].headers.len); } test "reject non-positive http max_connections" { const source = \\[scenario] \\name = "defaults" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[http] \\max_connections = 0 \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ; try std.testing.expectError(error.HttpMaxConnectionsMustBePositive, ScenarioConfig.parse(std.testing.allocator, source)); } test "parse plugin directory and plugin exporters" { const source = \\[scenario] \\name = "plugins" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[plugins] \\dir = "./samples/plugins/csv" \\ \\[http] \\transport_plugin = "custom-http" \\ \\[[exporters.plugins]] \\name = "csv" \\config = { path = "./out.csv" } \\ \\[[http.requests]] \\id = 1 \\name = "health" \\method = "GET" \\path = "/health" ; var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit(); try std.testing.expectEqualStrings("./samples/plugins/csv", parsed.plugins.dir.?); try std.testing.expectEqualStrings("custom-http", parsed.http.transport_plugin.?); try std.testing.expectEqual(@as(usize, 1), parsed.exporters.plugins.len); try std.testing.expectEqualStrings("csv", parsed.exporters.plugins[0].name); try std.testing.expectEqualStrings("path", parsed.exporters.plugins[0].config[0].key); } test "parse http version settings" { const source = \\[scenario] \\name = "http2" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[http] \\version = "auto" \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ; var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit(); try std.testing.expectEqual(config.HttpVersion.auto, parsed.http.version); } test "reject http2 without tls" { const source = \\[scenario] \\name = "http2" \\protocol = "http" \\target = "http://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[http] \\version = "2" \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ; try std.testing.expectError(error.Http2RequiresTls, ScenarioConfig.parse(std.testing.allocator, source)); } test "parseFile expands include directives before parsing" { var tmp_dir = std.testing.tmpDir(.{}); defer tmp_dir.cleanup(); try tmp_dir.dir.writeFile(.{ .sub_path = "common.toml", .data = \\[http.defaults] \\headers = { accept = "application/json" } \\timeout_ms = 250 \\ \\[[http.requests]] \\id = 1 \\name = "health" \\method = "GET" \\path = "/health" , }); try tmp_dir.dir.writeFile(.{ .sub_path = "scenario.toml", .data = \\include = "./common.toml" \\ \\[scenario] \\name = "include" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" , }); const config_path = try std.fmt.allocPrint(std.testing.allocator, ".zig-cache/tmp/{s}/scenario.toml", .{tmp_dir.sub_path}); defer std.testing.allocator.free(config_path); var parsed = try ScenarioConfig.parseFile(std.testing.allocator, config_path, 1024 * 1024); defer parsed.deinit(); try std.testing.expectEqual(@as(usize, 1), parsed.http.requests.len); try std.testing.expectEqual(@as(u32, 250), parsed.http.requests[0].timeout_ms); try std.testing.expectEqual(@as(usize, 1), parsed.http.requests[0].headers.len); try std.testing.expectEqualStrings("accept", parsed.http.requests[0].headers[0].key); } test "parseFile rejects include cycles" { var tmp_dir = std.testing.tmpDir(.{}); defer tmp_dir.cleanup(); try tmp_dir.dir.writeFile(.{ .sub_path = "a.toml", .data = \\include = "./b.toml" \\ \\[scenario] \\name = "a" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "health" \\method = "GET" \\path = "/health" , }); try tmp_dir.dir.writeFile(.{ .sub_path = "b.toml", .data = "include = \"./a.toml\"\n", }); const config_path = try std.fmt.allocPrint(std.testing.allocator, ".zig-cache/tmp/{s}/a.toml", .{tmp_dir.sub_path}); defer std.testing.allocator.free(config_path); try std.testing.expectError(error.IncludeCycle, ScenarioConfig.parseFile(std.testing.allocator, config_path, 1024 * 1024)); } test "parseFile loads env_file values before placeholder resolution" { var tmp_dir = std.testing.tmpDir(.{}); defer tmp_dir.cleanup(); try tmp_dir.dir.writeFile(.{ .sub_path = ".env", .data = \\API_HOST=env.example.internal \\TOKEN="secret-token" , }); try tmp_dir.dir.writeFile(.{ .sub_path = "scenario.toml", .data = \\env_file = "./.env" \\ \\[scenario] \\name = "env-file" \\protocol = "http" \\target = "https://${API_HOST}" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "health" \\method = "GET" \\path = "/v1/${iter.USER_ID}" \\headers = { authorization = "Bearer ${TOKEN}" } , }); const config_path = try std.fmt.allocPrint(std.testing.allocator, ".zig-cache/tmp/{s}/scenario.toml", .{tmp_dir.sub_path}); defer std.testing.allocator.free(config_path); var parsed = try ScenarioConfig.parseFile(std.testing.allocator, config_path, 1024 * 1024); defer parsed.deinit(); try std.testing.expectEqualStrings("https://env.example.internal", parsed.scenario.target); try std.testing.expectEqualStrings("/v1/${iter.USER_ID}", parsed.http.requests[0].path); try std.testing.expectEqualStrings("Bearer secret-token", parsed.http.requests[0].headers[0].value); } test "parseFile rejects invalid env_file entries" { var tmp_dir = std.testing.tmpDir(.{}); defer tmp_dir.cleanup(); try tmp_dir.dir.writeFile(.{ .sub_path = ".env", .data = "NOT_VALID\n", }); try tmp_dir.dir.writeFile(.{ .sub_path = "scenario.toml", .data = \\env_file = "./.env" \\ \\[scenario] \\name = "env-file" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "health" \\method = "GET" \\path = "/health" , }); const config_path = try std.fmt.allocPrint(std.testing.allocator, ".zig-cache/tmp/{s}/scenario.toml", .{tmp_dir.sub_path}); defer std.testing.allocator.free(config_path); try std.testing.expectError(error.InvalidEnvFileEntry, ScenarioConfig.parseFile(std.testing.allocator, config_path, 1024 * 1024)); } test "parse workflow execution timeout and poison settings" { const source = \\[scenario] \\name = "workflow" \\protocol = "http" \\target = "https://example.internal" \\wasm = "./scenario.wasm" \\wasm_backend = "wasm3" \\recovery.window = "8s" \\recovery.max_recreates = 5 \\ \\[execution] \\mode = "constant-arrival-rate" \\rate = 25 \\duration = "30s" \\pre_allocated_vus = 4 \\max_vus = 8 \\script_timeout = "250ms" \\max_poisoned_workers = 2 \\ \\[[http.requests]] \\id = 1 \\name = "health" \\method = "GET" \\path = "/health" ; var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit(); try std.testing.expectEqual(WasmBackend.wasm3, parsed.scenario.wasm_backend); try std.testing.expectEqual(Duration.fromSeconds(8).nanos, parsed.recovery.window.nanos); try std.testing.expectEqual(@as(u32, 5), parsed.recovery.max_recreates); try std.testing.expectEqual(Duration.fromMillis(250).nanos, parsed.execution.script_timeout.nanos); try std.testing.expectEqual(@as(u32, 2), parsed.execution.max_poisoned_workers); } test "default recovery policy matches previous behavior" { const source = \\[scenario] \\name = "workflow" \\protocol = "http" \\target = "https://example.internal" \\wasm = "./scenario.wasm" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "health" \\method = "GET" \\path = "/health" ; var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit(); try std.testing.expectEqual(Duration.fromSeconds(5).nanos, parsed.recovery.window.nanos); try std.testing.expectEqual(@as(u32, 3), parsed.recovery.max_recreates); } test "parse scheduler lag threshold metrics" { try std.testing.expectEqual( ThresholdMetric.scheduler_lag_avg, try literals.parseThresholdMetric("\"executor.scheduler_lag.avg\""), ); try std.testing.expectEqual( ThresholdMetric.scheduler_lag_max, try literals.parseThresholdMetric("\"executor.scheduler_lag.max\""), ); } test "parse transport timeout threshold metrics" { try std.testing.expectEqual( ThresholdMetric.http_transport_timeout_total, try literals.parseThresholdMetric("\"http.transport.timeout_total\""), ); try std.testing.expectEqual( ThresholdMetric.http_transport_timeout_rate, try literals.parseThresholdMetric("\"http.transport.timeout_rate\""), ); try std.testing.expectEqual( ThresholdMetric.http_transport_connect_timeout_total, try literals.parseThresholdMetric("\"http.transport.connect_timeout_total\""), ); try std.testing.expectEqual( ThresholdMetric.http_transport_connect_timeout_rate, try literals.parseThresholdMetric("\"http.transport.connect_timeout_rate\""), ); try std.testing.expectEqual( ThresholdMetric.http_transport_io_timeout_total, try literals.parseThresholdMetric("\"http.transport.io_timeout_total\""), ); try std.testing.expectEqual( ThresholdMetric.http_transport_io_timeout_rate, try literals.parseThresholdMetric("\"http.transport.io_timeout_rate\""), ); try std.testing.expectEqual( ThresholdMetric.check_failed_total, try literals.parseThresholdMetric("\"check.failed_total\""), ); try std.testing.expectEqual( ThresholdMetric.check_pass_rate, try literals.parseThresholdMetric("\"check.pass_rate\""), ); } test "reject unsupported wasm backend" { const source = \\[scenario] \\name = "workflow" \\protocol = "http" \\target = "https://example.internal" \\wasm = "./scenario.wasm" \\wasm_backend = "unknown" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "health" \\method = "GET" \\path = "/health" ; try std.testing.expectError(error.UnsupportedWasmBackend, ScenarioConfig.parse(std.testing.allocator, source)); } test "resolve environment variables while preserving runtime placeholders" { const home = std.process.getEnvVarOwned(std.testing.allocator, "HOME") catch return error.SkipZigTest; defer std.testing.allocator.free(home); const source = \\[scenario] \\name = "env" \\protocol = "http" \\target = "https://${HOME}" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "path" \\method = "GET" \\path = "/v1/${iter.USER_ID}" ; var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit(); const expected_target = try std.fmt.allocPrint(std.testing.allocator, "https://{s}", .{home}); defer std.testing.allocator.free(expected_target); try std.testing.expectEqualStrings(expected_target, parsed.scenario.target); try std.testing.expectEqualStrings("/v1/${iter.USER_ID}", parsed.http.requests[0].path); } test "reject duplicate request ids" { const source = \\[scenario] \\name = "dup" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" \\ \\[[http.requests]] \\id = 1 \\name = "two" \\method = "GET" \\path = "/two" ; try std.testing.expectError(error.DuplicateRequestId, ScenarioConfig.parse(std.testing.allocator, source)); } test "reject plugin usage without plugin directory" { const source = \\[scenario] \\name = "plugin-missing-dir" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[http] \\transport_plugin = "custom-http" \\ \\[[http.requests]] \\id = 1 \\name = "health" \\method = "GET" \\path = "/health" ; try std.testing.expectError(error.PluginDirectoryRequired, ScenarioConfig.parse(std.testing.allocator, source)); } test "reject invalid request paths" { const source = \\[scenario] \\name = "bad-path" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "bad" \\method = "GET" \\path = "v1/no-leading-slash" ; try std.testing.expectError(error.InvalidRequestPath, ScenarioConfig.parse(std.testing.allocator, source)); } test "reject simple mode with multiple requests" { const source = \\[scenario] \\name = "simple-too-many" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "first" \\method = "GET" \\path = "/one" \\ \\[[http.requests]] \\id = 2 \\name = "second" \\method = "GET" \\path = "/two" ; try std.testing.expectError(error.SimpleModeRequiresSingleRequest, ScenarioConfig.parse(std.testing.allocator, source)); } test "reject grpc requests that do not use POST" { const source = \\[scenario] \\name = "grpc-bad-method" \\protocol = "grpc" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[http.defaults] \\cookie_jar = false \\ \\[[http.requests]] \\id = 1 \\name = "bad" \\method = "GET" \\path = "/grpc.health.v1.Health/Check" ; try std.testing.expectError(error.GrpcRequiresPostMethod, ScenarioConfig.parse(std.testing.allocator, source)); } test "reject grpc scenarios that enable cookie jars" { const source = \\[scenario] \\name = "grpc-cookie" \\protocol = "grpc" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[http.defaults] \\cookie_jar = true \\ \\[[http.requests]] \\id = 1 \\name = "check" \\method = "POST" \\path = "/grpc.health.v1.Health/Check" ; try std.testing.expectError(error.GrpcCookieJarUnsupported, ScenarioConfig.parse(std.testing.allocator, source)); } test "parse grpc workflow mode with shared request schema" { const source = \\[scenario] \\name = "grpc-workflow" \\protocol = "grpc" \\target = "https://example.internal" \\wasm = "./scenario.wasm" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[http.defaults] \\cookie_jar = false \\ \\[[http.requests]] \\id = 1 \\name = "check" \\method = "POST" \\path = "/grpc.health.v1.Health/Check" \\pass_response_body = true ; var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit(); try std.testing.expectEqual(ScenarioMode.workflow, parsed.scenario.mode()); try std.testing.expectEqual(config.Protocol.grpc, parsed.scenario.protocol); try std.testing.expectEqual(true, parsed.http.requests[0].pass_response_body); } test "parse setup and shutdown timeouts" { const source = \\[scenario] \\name = "timeouts" \\protocol = "http" \\target = "https://example.internal" \\wasm = "./scenario.wasm" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "5s" \\setup_timeout = "7s" \\shutdown_timeout = "45s" \\ \\[[setup.requests]] \\name = "bootstrap" \\method = "POST" \\path = "/bootstrap" \\timeout_ms = 1200 \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ; var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit(); try std.testing.expectEqual(Duration.fromSeconds(7).nanos, parsed.execution.setup_timeout.nanos); try std.testing.expectEqual(Duration.fromSeconds(45).nanos, parsed.execution.shutdown_timeout.nanos); try std.testing.expectEqual(@as(u32, 1200), parsed.setup.requests[0].timeout_ms); } test "parse ramping vus stages and exporters" { const source = \\[scenario] \\name = "ramping" \\protocol = "grpc" \\target = "https://example.internal" \\ \\[execution] \\mode = "ramping-vus" \\duration = "10s" \\ \\[[execution.stages]] \\target_vus = 2 \\duration = "3s" \\ \\[[execution.stages]] \\target_vus = 4 \\duration = "7s" \\ \\[http.defaults] \\cookie_jar = false \\ \\[exporters.otlp] \\url = "http://127.0.0.1:4318/v1/metrics" \\retry_max_attempts = 6 \\retry_max_elapsed = "45s" \\buffer_max_exports = 12 \\ \\[[http.requests]] \\id = 1 \\name = "echo" \\method = "POST" \\path = "/grpc.testing.Echo/Unary" ; var parsed = try ScenarioConfig.parse(std.testing.allocator, source); defer parsed.deinit(); try std.testing.expectEqual(Execution.Mode.ramping_vus, parsed.execution.mode); try std.testing.expectEqual(@as(usize, 2), parsed.execution.stages.len); try std.testing.expectEqual(@as(u32, 4), parsed.execution.maxRampingVus()); try std.testing.expectEqual(@as(u32, 0), parsed.execution.rampingTargetAt(0)); try std.testing.expectEqual(@as(u32, 1), parsed.execution.rampingTargetAt(Duration.fromSeconds(2).nanos)); try std.testing.expectEqualStrings("http://127.0.0.1:4318/v1/metrics", parsed.exporters.otlp.?.url); try std.testing.expectEqual(@as(u32, 6), parsed.exporters.otlp.?.retry_max_attempts); try std.testing.expectEqual(Duration.fromSeconds(45).nanos, parsed.exporters.otlp.?.retry_max_elapsed.nanos); try std.testing.expectEqual(@as(u32, 12), parsed.exporters.otlp.?.buffer_max_exports); } test "reject warmup longer than duration" { const source = \\[scenario] \\name = "warmup" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\warmup = "2s" \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ; try std.testing.expectError(error.WarmupExceedsDuration, ScenarioConfig.parse(std.testing.allocator, source)); } test "reject invalid otlp retry settings" { const zero_attempts = \\[scenario] \\name = "otlp" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[exporters.otlp] \\url = "http://127.0.0.1:4318/v1/metrics" \\retry_max_attempts = 0 \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ; try std.testing.expectError(error.OtlpRetryMaxAttemptsMustBePositive, ScenarioConfig.parse(std.testing.allocator, zero_attempts)); const zero_elapsed = \\[scenario] \\name = "otlp" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[exporters.otlp] \\url = "http://127.0.0.1:4318/v1/metrics" \\retry_max_elapsed = "0ms" \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ; try std.testing.expectError(error.OtlpRetryMaxElapsedMustBePositive, ScenarioConfig.parse(std.testing.allocator, zero_elapsed)); const zero_buffer = \\[scenario] \\name = "otlp" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[exporters.otlp] \\url = "http://127.0.0.1:4318/v1/metrics" \\buffer_max_exports = 0 \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ; try std.testing.expectError(error.OtlpBufferMaxExportsMustBePositive, ScenarioConfig.parse(std.testing.allocator, zero_buffer)); } test "reject zero script timeout" { const source = \\[scenario] \\name = "timeout" \\protocol = "http" \\target = "https://example.internal" \\wasm = "./scenario.wasm" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\script_timeout = "0ms" \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ; try std.testing.expectError(error.ScriptTimeoutMustBePositive, ScenarioConfig.parse(std.testing.allocator, source)); } test "reject zero execution thread count" { const source = \\[scenario] \\name = "threads" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\thread_count = 0 \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ; try std.testing.expectError(error.ExecutionThreadCountMustBePositive, ScenarioConfig.parse(std.testing.allocator, source)); } test "reject invalid recovery policy values" { const zero_window = \\[scenario] \\name = "workflow" \\protocol = "http" \\target = "https://example.internal" \\wasm = "./scenario.wasm" \\recovery.window = "0ms" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ; try std.testing.expectError(error.RecoveryWindowMustBePositive, ScenarioConfig.parse(std.testing.allocator, zero_window)); const zero_max = \\[scenario] \\name = "workflow" \\protocol = "http" \\target = "https://example.internal" \\wasm = "./scenario.wasm" \\recovery.max_recreates = 0 \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ; try std.testing.expectError(error.RecoveryMaxRecreatesMustBePositive, ScenarioConfig.parse(std.testing.allocator, zero_max)); } test "reject arrival rate configs where pre allocated vus exceed max" { const source = \\[scenario] \\name = "arrival-rate" \\protocol = "http" \\target = "https://example.internal" \\wasm = "./scenario.wasm" \\ \\[execution] \\mode = "constant-arrival-rate" \\rate = 100 \\duration = "10s" \\pre_allocated_vus = 32 \\max_vus = 16 \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ; try std.testing.expectError(error.PreAllocatedVusExceedsMaxVus, ScenarioConfig.parse(std.testing.allocator, source)); } test "reject setup request store keys outside setup namespace" { const source = \\[scenario] \\name = "setup" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[setup.requests]] \\name = "bootstrap" \\method = "POST" \\path = "/bootstrap" \\store_body_as = "iter.BAD" \\ \\[[http.requests]] \\id = 1 \\name = "one" \\method = "GET" \\path = "/one" ; try std.testing.expectError(error.InvalidSetupStoreKey, ScenarioConfig.parse(std.testing.allocator, source)); } test "reject thresholds with unknown request scopes" { const source = \\[scenario] \\name = "threshold" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "known" \\method = "GET" \\path = "/one" \\ \\[[thresholds]] \\metric = "http.request.duration.p99" \\scope = { request = "unknown" } \\op = "<=" \\value = "200ms" ; try std.testing.expectError(error.UnknownThresholdRequest, ScenarioConfig.parse(std.testing.allocator, source)); } test "reject thresholds with unknown scenario scopes" { const source = \\[scenario] \\name = "threshold" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "known" \\method = "GET" \\path = "/one" \\ \\[[thresholds]] \\metric = "http.error_rate" \\scope = { scenario = "other" } \\op = "<=" \\value = "0.01" ; try std.testing.expectError(error.UnknownThresholdScenario, ScenarioConfig.parse(std.testing.allocator, source)); } test "reject request-scoped iteration thresholds" { const source = \\[scenario] \\name = "threshold" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "known" \\method = "GET" \\path = "/one" \\ \\[[thresholds]] \\metric = "iteration.success_rate" \\scope = { request = "known" } \\op = ">=" \\value = "1.0" ; try std.testing.expectError(error.InvalidThresholdScope, ScenarioConfig.parse(std.testing.allocator, source)); } test "reject thresholds with invalid value kind" { const source = \\[scenario] \\name = "threshold" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "known" \\method = "GET" \\path = "/one" \\ \\[[thresholds]] \\metric = "http.request.duration.p99" \\op = "<=" \\value = "0.01" ; try std.testing.expectError(error.InvalidThresholdValue, ScenarioConfig.parse(std.testing.allocator, source)); } test "parse byte size helper" { try std.testing.expectEqual(@as(u64, 4096), (try literals.parseByteSizeLiteral("4KiB")).bytes); } test "parse ratio helper" { try std.testing.expectApproxEqAbs(@as(f64, 0.01), try literals.parseRatioLiteral("0.01"), 0.000001); try std.testing.expectError(error.RatioOutOfRange, literals.parseRatioLiteral("1.2")); } test "reject template placeholders outside allowed namespaces" { const source = \\[scenario] \\name = "bad-template" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "bad" \\method = "GET" \\path = "/v1/${bad.KEY}" ; try std.testing.expectError(error.InvalidTemplateVariable, ScenarioConfig.parse(std.testing.allocator, source)); } test "reject header values containing newlines" { const source = \\[scenario] \\name = "bad-header" \\protocol = "http" \\target = "https://example.internal" \\ \\[execution] \\mode = "constant-vus" \\vus = 1 \\duration = "1s" \\ \\[[http.requests]] \\id = 1 \\name = "bad" \\method = "GET" \\path = "/one" \\headers = { authorization = "Bearer one\nBearer two" } ; try std.testing.expectError(error.InvalidHeaderValue, ScenarioConfig.parse(std.testing.allocator, source)); }