const std = @import("std"); const config = @import("../config.zig"); const http_executor = @import("../protocol/http_executor.zig"); const runner_log = @import("log.zig"); const runner_setup = @import("setup.zig"); const runtime = @import("../runtime.zig"); const template = @import("../template.zig"); const workflow_scenario = @import("../workflow/scenario.zig"); const http = std.http; pub fn applyInitialStore(store: *template.VarStore, initial_store: ?*const template.VarStore) !void { if (initial_store) |value| { try store.cloneFrom(value); } } pub fn runSetupPhase( allocator: std.mem.Allocator, client: *http.Client, store: *template.VarStore, tls_context: *http_executor.TlsContext, scenario: *const config.ScenarioConfig, logger: *runner_log.Logger, ) !void { try runner_setup.runSetupPhase(allocator, client, store, tls_context, scenario, logger); } pub fn runWorkflowSetup( allocator: std.mem.Allocator, store: *template.VarStore, scenario: *const config.ScenarioConfig, logger: *runner_log.Logger, ) !workflow_scenario.ScenarioLifecycle { const wasm_path = scenario.scenario.wasm.?; _ = try runtime.validateWorkflowModule(allocator, wasm_path, runtime.fromConfigBackend(scenario.scenario.wasm_backend)); var lifecycle = try workflow_scenario.ScenarioLifecycle.init(allocator, store, scenario, logger); errdefer lifecycle.deinit(); try lifecycle.runSetup(store, scenario); return lifecycle; } pub fn runWorkflowTeardown( lifecycle: ?*workflow_scenario.ScenarioLifecycle, scenario: *const config.ScenarioConfig, interrupted: bool, logger: *runner_log.Logger, ) !bool { const value = lifecycle orelse return false; switch (value.runTeardown(scenario, interrupted)) { .not_present, .completed => return false, .skipped => { try logger.log(.warn, "workflow teardown skipped after shutdown deadline", .{ .component = "workflow", .source = .host, .event = "workflow_teardown_skipped", }); return false; }, .failed => { try logger.log(.err, "workflow teardown failed", .{ .component = "workflow", .source = .host, .event = "workflow_teardown_failed", }); return true; }, } }