package execution import "../agent" import "../conversation" import "../provider" import "../sessionstore" import "../tool" import "core:mem" import "core:strings" import "core:sync" import "core:testing" import "core:thread" import "core:time" TEST_LIMITS :: conversation.Projection_Limits{16 * 1024 * 1024, 10000, 20000} Fake_Mode :: enum { Normal, Text, Hold_Terminal, Hold_Tool, Flood, Byte_Flood, Missing_Terminal, Duplicate_Terminal, Late_Usage, Stale, Foreign_Hostile, Oversized, Oversized_Tool, Exhausted_Tool, Unknown_Tool } Worker_Fake :: struct { mode: Fake_Mode, runs, tools, saves, fail_save: int, arrived, release: sync.Sema, hold_save: bool, oversized_save: bool, exhausted_save: bool, snapshots_ok, tools_ok: bool, revisions: [32]conversation.Revision, saved_models: [32]string, // Static observations only, never retain borrowed snapshots. } fake_wall :: proc(_: rawptr) -> i64 { return 100 } fake_monotonic :: proc(_: rawptr) -> time.Duration { return 1000 } worker_fake_run :: proc(data: rawptr, request: provider.Request, sink: provider.Sink, cancel: provider.Cancel_Check) { fake := (^Worker_Fake)(data) fake.runs += 1 fake.snapshots_ok = fake.snapshots_ok && request.instructions == "frozen" && len(request.tools) == 1 && request.tools[0].name == "fake" if fake.mode == .Normal && fake.runs == 2 { fake.snapshots_ok = fake.snapshots_ok && len(request.messages) == 4 && len(request.messages[1].content) == 3 // text/calls, not visible reasoning } if fake.mode == .Hold_Terminal && fake.runs == 1 { sink.emit(sink.data, request.identity, provider.Text_Delta{"partial"}) sink.emit(sink.data, request.identity, provider.Completed{}) sync.post(&fake.arrived) sync.wait(&fake.release) fake.snapshots_ok = fake.snapshots_ok && request.selection.model.id == "model" && request.messages[0].content[0].(conversation.Text).text == "prompt" return } if fake.mode == .Byte_Flood { bytes := make([]byte, 2 * 1024 * 1024) defer delete(bytes) for &byte in bytes do byte = 'x' for i in 0..<3 { if i == 1 do sync.post(&fake.arrived) sink.emit(sink.data, request.identity, provider.Text_Delta{transmute(string)bytes}) } sink.emit(sink.data, request.identity, provider.Completed{}) return } if fake.mode == .Flood { for i in 0.. tool.Result { fake := (^Worker_Fake)(data) fake.tools += 1 fake.tools_ok = fake.tools_ok && ctx.workspace == "/workspace" && ctx.max_output_bytes == TOOL_OUTPUT_BYTES && ctx.deadline == 1000 + 120 * time.Second && ctx.selection.model.id == "model" fake.tools_ok = fake.tools_ok && ctx.native.id == "fake-native" && ctx.process.id == "fake-process" stale := ctx.identity; stale.attempt += 100 ctx.progress.emit(ctx.progress.data, stale, call.id, "stale progress") ctx.progress.emit(ctx.progress.data, ctx.identity, call.id, "semantic progress") if fake.mode == .Hold_Tool && fake.tools == 1 { sync.post(&fake.arrived); sync.wait(&fake.release) } if fake.mode == .Oversized_Tool { bytes := make([]byte, TOOL_OUTPUT_BYTES + 1, ctx.allocator) for &byte in bytes do byte = 'x' return {status = .Success, text = transmute(string)bytes, execution = {state = .Completed}} } if fake.mode == .Exhausted_Tool { bytes, _ := make([]byte, OUTPUT_ALLOCATION_BYTES + 1, ctx.allocator) // Deliberately broken injected tool ignores allocation refusal. return {status = .Success, text = transmute(string)bytes, execution = {state = .Completed}} } status := tool.Status.Success if call.id == "b" do status = .Denied return {status = status, text = strings.clone("owned result", ctx.allocator), execution = {state = .Completed}} } worker_fake_save :: proc(data: rawptr, request: sessionstore.Save_Request, allocator: mem.Allocator) -> sessionstore.Error { fake := (^Worker_Fake)(data) i := fake.saves; fake.saves += 1 fake.revisions[i] = request.revision if request.session.selection.model.id == "model" do fake.saved_models[i] = "model" else do fake.saved_models[i] = "other" fake.snapshots_ok = fake.snapshots_ok && request.revision == request.session.revision && request.session.id == "executor" if fake.hold_save && i == 0 { sync.post(&fake.arrived); sync.wait(&fake.release) fake.snapshots_ok = fake.snapshots_ok && request.session.selection.model.id == "model" } if fake.saves == fake.fail_save do return {.IO, strings.clone("fake save failure", allocator)} if fake.oversized_save { bytes := make([]byte, TOOL_OUTPUT_BYTES + 1, allocator) return {.IO, transmute(string)bytes} } if fake.exhausted_save { _, _ = make([]byte, OUTPUT_ALLOCATION_BYTES + 1, allocator) } // Deliberately ignored error. return {} } Observed :: struct { executor: ^Executor, reentry: conversation.Error, direct_reentry: conversation.Error, events, progress, text, started: int, order_ok: bool, } observe :: proc(data: rawptr, event: agent.Event) { value := (^Observed)(data) value.events += 1 value.reentry = send(value.executor, agent.Submit{"recursive"}) value.direct_reentry = step(value.executor.runtime, agent.Submit{"direct recursive"}, "", nil, TEST_LIMITS).error switch _ in event { case agent.Turn_Started: value.started += 1; value.order_ok = value.order_ok && value.executor.active == nil case agent.Tool_Progress: value.progress += 1 case agent.Text_Appended: value.text += 1 case agent.Admission, agent.Tool_Started, agent.Tool_Finished, agent.Turn_Finished, agent.Turn_Failed, agent.Turn_Cancelled, agent.Queue_Discarded, agent.Reasoning_Changed, agent.Durability_Warning: case: } } Fixture :: struct { runtime: Runtime, executor: Executor, issuer: agent.Identity_Issuer, identity_mutex: sync.Mutex, registry: tool.Registry, fake: Worker_Fake, observed: Observed, } fixture_init :: proc(value: ^Fixture, mode: Fake_Mode = .Normal, policy: agent.Checkpoint_Policy = .Durable) { value.fake.mode = mode; value.fake.snapshots_ok = true; value.fake.tools_ok = true tool.init(&value.registry, context.allocator) tool.register(&value.registry, {name = "fake", description = "definition", input_schema_json = "{}", data = &value.fake, execute = worker_fake_tool}) init(&value.runtime, {model = {&value.fake, worker_fake_run}, tools = &value.registry, store = {data = &value.fake, save = worker_fake_save}, clock = {wall = fake_wall, monotonic = fake_monotonic}, identities = &value.issuer, identity_mutex = &value.identity_mutex, checkpoint_policy = policy}, context.allocator) conversation.init(&value.runtime.conversation, "executor", "/workspace", {model = {"fake", "model"}}, context.allocator, 100) value.observed = {executor = &value.executor, order_ok = true} assert(init_executor(&value.executor, &value.runtime, {instructions = "frozen", projection_limits = TEST_LIMITS, native = {id = "fake-native", description = "memory fixture"}, process = {id = "fake-process", description = "memory fixture"}}, {&value.observed, observe}, context.allocator) == .None) } fixture_destroy :: proc(value: ^Fixture) { close(&value.executor) destroy_executor(&value.executor) destroy(&value.runtime) tool.destroy(&value.registry) } drain :: proc(value: ^Executor) { iterations := 0 for value.active != nil && iterations < 1000 { assert(poll(value, true)); iterations += 1 } assert(iterations < 1000) } @(test) workers_complete_sequential_tools_and_real_durable_acknowledgements :: proc(t: ^testing.T) { f: Fixture; fixture_init(&f); defer fixture_destroy(&f) testing.expect_value(t, send(&f.executor, agent.Submit{"prompt"}), conversation.Error.None) poll(&f.executor, true) // Model snapshot captured before next-turn selection changes. send(&f.executor, agent.Set_Selection{{model = {"fake", "other"}}}) drain(&f.executor) testing.expect_value(t, f.fake.runs, 2) testing.expect_value(t, f.fake.tools, 2) testing.expect_value(t, f.fake.saves, 5) testing.expect_value(t, f.observed.progress, 2) testing.expect(t, f.fake.snapshots_ok && f.fake.tools_ok && f.observed.order_ok) testing.expect_value(t, f.observed.reentry, conversation.Error.Invalid_State) testing.expect_value(t, f.observed.direct_reentry, conversation.Error.Invalid_State) testing.expect_value(t, f.runtime.conversation.turns[0].outcome, conversation.Outcome.Complete) testing.expect_value(t, f.runtime.conversation.messages[1].content[1].(conversation.Reasoning).text, "safe summary") testing.expect_value(t, f.runtime.conversation.messages[4].content[0].(conversation.Text).text, "first") testing.expect_value(t, f.runtime.agent.durable_revision, f.runtime.conversation.revision) } @(test) terminal_callback_cannot_release_worker_or_checkpoint_before_return :: proc(t: ^testing.T) { f: Fixture; fixture_init(&f, .Hold_Terminal); defer fixture_destroy(&f) send(&f.executor, agent.Submit{"prompt"}) poll(&f.executor, true) // start gate, model worker sync.wait(&f.fake.arrived) testing.expect(t, poll(&f.executor)) // text, not terminal testing.expect(t, !poll(&f.executor)) testing.expect_value(t, f.runtime.agent.phase, agent.Phase.Awaiting_Model) testing.expect_value(t, f.fake.saves, 1) send(&f.executor, agent.Set_Selection{{model = {"fake", "other"}}}) send(&f.executor, agent.Cancel{}) sync.post(&f.fake.release) drain(&f.executor) testing.expect(t, f.fake.snapshots_ok) testing.expect_value(t, f.runtime.conversation.turns[0].outcome, conversation.Outcome.Cancelled) testing.expect_value(t, f.runtime.conversation.messages[1].content[0].(conversation.Text).text, "partial") } @(test) full_mailbox_cancellation_unblocks_producer_and_retains_final_metadata :: proc(t: ^testing.T) { f: Fixture; fixture_init(&f, .Flood); defer fixture_destroy(&f) send(&f.executor, agent.Submit{"prompt"}); poll(&f.executor, true) sync.wait(&f.fake.arrived) job := f.executor.active sync.mutex_lock(&job.mutex) testing.expect_value(t, job.count, MAILBOX_ITEMS) testing.expect(t, job.bytes <= MAILBOX_BYTES) sync.mutex_unlock(&job.mutex) send(&f.executor, agent.Cancel{}) drain(&f.executor) testing.expect_value(t, f.runtime.conversation.turns[0].outcome, conversation.Outcome.Cancelled) testing.expect_value(t, f.runtime.conversation.requests[0].usage.output.value, u64(7)) testing.expect_value(t, f.runtime.conversation.requests[0].served_model, "served") testing.expect_value(t, f.observed.text, 0) // Cancelled queued output is ignored, not canonicalized. } @(test) superseded_save_snapshots_are_owned_serialized_and_pending_is_bounded :: proc(t: ^testing.T) { f: Fixture; fixture_init(&f, .Text); defer fixture_destroy(&f) f.fake.hold_save = true send(&f.executor, agent.Submit{"prompt"}) sync.wait(&f.fake.arrived) for i in 0..<10 { selection := conversation.Selection{model = {"fake", "other"}, variant = "a"} if i % 2 == 1 do selection.variant = "b" send(&f.executor, agent.Set_Selection{selection}) testing.expect(t, f.executor.pending != nil) } sync.post(&f.fake.release) drain(&f.executor) testing.expect(t, f.fake.snapshots_ok) testing.expect_value(t, f.fake.saves, 3) // initial, latest replacement, end; no 10-worker fanout. testing.expect_value(t, f.fake.saved_models[0], "model") for i in 1.. f.fake.revisions[i - 1]) testing.expect_value(t, f.fake.runs, 1) } @(test) failed_result_save_and_explicit_retry_never_replay_effects :: proc(t: ^testing.T) { f: Fixture; fixture_init(&f); defer fixture_destroy(&f) f.fake.fail_save = 3 // start, batch, first result send(&f.executor, agent.Submit{"prompt"}); send(&f.executor, agent.Submit{"queued"}) drain(&f.executor) testing.expect_value(t, f.runtime.agent.phase, agent.Phase.Durability_Blocked) testing.expect_value(t, f.fake.tools, 1) testing.expect_value(t, len(f.runtime.agent.pending.items), 0) testing.expect(t, !close(&f.executor)) send(&f.executor, agent.Retry_Save{}) drain(&f.executor) testing.expect_value(t, f.runtime.agent.phase, agent.Phase.Idle) testing.expect_value(t, f.fake.tools, 1) testing.expect_value(t, f.fake.runs, 1) } @(test) adapter_missing_duplicate_and_oversized_terminal_fail_without_effects :: proc(t: ^testing.T) { for mode in ([?]Fake_Mode{.Missing_Terminal, .Duplicate_Terminal, .Oversized}) { f: Fixture; fixture_init(&f, mode) send(&f.executor, agent.Submit{"prompt"}); drain(&f.executor) testing.expect_value(t, f.runtime.conversation.turns[0].outcome, conversation.Outcome.Failed) testing.expect_value(t, f.fake.tools, 0) fixture_destroy(&f) } } @(test) stale_callbacks_are_ignored_without_mutation :: proc(t: ^testing.T) { f: Fixture; fixture_init(&f, .Stale); defer fixture_destroy(&f) send(&f.executor, agent.Submit{"prompt"}); drain(&f.executor) testing.expect_value(t, f.observed.text, 1) testing.expect_value(t, f.runtime.conversation.messages[1].content[0].(conversation.Text).text, "first") // Duplicate completion remains borrowed/caller-owned on immediate input too. identity := f.runtime.conversation.requests[0].provenance.identity testing.expect_value(t, send(&f.executor, agent.Model_Event{identity, provider.Completed{}}), conversation.Error.Invalid_State) testing.expect_value(t, f.fake.saves, 2) } @(test) late_metadata_before_adapter_return_is_normalized_once :: proc(t: ^testing.T) { f: Fixture; fixture_init(&f, .Late_Usage); defer fixture_destroy(&f) send(&f.executor, agent.Submit{"prompt"}); drain(&f.executor) testing.expect_value(t, f.runtime.conversation.requests[0].usage.output.value, u64(5)) testing.expect_value(t, f.runtime.conversation.requests[0].usage_sequence, u64(2)) testing.expect_value(t, f.runtime.conversation.requests[0].served_model, "served") testing.expect_value(t, f.runtime.conversation.turns[0].outcome, conversation.Outcome.Complete) } @(test) shutdown_drains_full_mailbox_and_checkpoints_cancellation_before_teardown :: proc(t: ^testing.T) { f: Fixture; fixture_init(&f, .Flood); defer fixture_destroy(&f) send(&f.executor, agent.Submit{"prompt"}); send(&f.executor, agent.Submit{"queued"}) poll(&f.executor, true); sync.wait(&f.fake.arrived) testing.expect(t, close(&f.executor)) testing.expect(t, f.executor.active == nil && f.executor.pending == nil) testing.expect_value(t, len(f.runtime.agent.pending.items), 0) testing.expect_value(t, f.fake.saves, 2) testing.expect_value(t, send(&f.executor, agent.Submit{"refuse"}), conversation.Error.Invalid_State) testing.expect(t, close(&f.executor)) } @(test) volatile_policy_never_invokes_store_and_idle_shutdown_saves_latest_selection :: proc(t: ^testing.T) { for policy in ([?]agent.Checkpoint_Policy{.Durable, .Volatile}) { f: Fixture; fixture_init(&f, .Text, policy) send(&f.executor, agent.Set_Selection{{model = {"fake", "other"}}}) testing.expect(t, close(&f.executor)) testing.expect_value(t, f.fake.saves, int(policy == .Durable)) testing.expect_value(t, f.runtime.agent.durable_revision, f.runtime.conversation.revision) fixture_destroy(&f) } } @(test) executor_setup_requires_services_and_repeated_empty_teardown_is_safe :: proc(t: ^testing.T) { value: Executor; runtime: Runtime testing.expect_value(t, init_executor(&value, &runtime, {}, {}, context.allocator), conversation.Error.Invalid_State) destroy_executor(&value); destroy_executor(&value) budget := Budget{backing = context.allocator, limit = 8} a := budget_allocator(&budget) bytes, allocation := make([]byte, 9, a) testing.expect(t, allocation != nil && bytes == nil) bytes, allocation = make([]byte, 8, a) testing.expect(t, allocation == nil) delete(bytes, a) bytes, allocation = make([]byte, 1, a) testing.expect(t, allocation != nil && bytes == nil) // Allocation-work quota is not refunded. _, allocation = a.procedure(a.data, .Free_All, 0, 0, nil, 0) testing.expect_value(t, allocation, mem.Allocator_Error.Mode_Not_Implemented) } @(test) mailbox_byte_budget_backpressure_is_independent_of_item_count :: proc(t: ^testing.T) { f: Fixture; fixture_init(&f, .Byte_Flood); defer fixture_destroy(&f) send(&f.executor, agent.Submit{"prompt"}); poll(&f.executor, true) sync.wait(&f.fake.arrived) job := f.executor.active sync.mutex_lock(&job.mutex) testing.expect_value(t, job.count, 1) testing.expect(t, job.bytes > 2 * 1024 * 1024 && job.bytes <= MAILBOX_BYTES) sync.mutex_unlock(&job.mutex) testing.expect(t, close(&f.executor)) } @(test) tool_cancel_records_late_completed_effect_and_interrupts_unstarted_call :: proc(t: ^testing.T) { f: Fixture; fixture_init(&f, .Hold_Tool); defer fixture_destroy(&f) send(&f.executor, agent.Submit{"prompt"}) for f.runtime.agent.phase != .Executing_Tools do poll(&f.executor, true) sync.wait(&f.fake.arrived) send(&f.executor, agent.Cancel{}) sync.post(&f.fake.release) drain(&f.executor) testing.expect_value(t, f.fake.tools, 1) testing.expect_value(t, f.runtime.conversation.turns[0].outcome, conversation.Outcome.Cancelled) result := f.runtime.conversation.messages[2].content[0].(conversation.Tool_Result) testing.expect_value(t, result.status, conversation.Tool_Status.Success) testing.expect_value(t, result.execution.state, conversation.Execution_State.Completed) testing.expect_value(t, f.runtime.conversation.messages[1].content[1].(conversation.Tool_Call).state, conversation.Call_State.Interrupted) } @(test) unknown_tool_is_ordinary_invalid_arguments_then_model_followup :: proc(t: ^testing.T) { f: Fixture; fixture_init(&f, .Unknown_Tool); defer fixture_destroy(&f) send(&f.executor, agent.Submit{"prompt"}); drain(&f.executor) testing.expect_value(t, f.fake.tools, 0) testing.expect_value(t, f.fake.runs, 2) testing.expect_value(t, f.runtime.conversation.messages[2].content[0].(conversation.Tool_Result).status, conversation.Tool_Status.Invalid_Arguments) testing.expect_value(t, f.runtime.conversation.turns[0].outcome, conversation.Outcome.Complete) } Owner_Thread_Test :: struct { issuer: ^agent.Identity_Issuer, mutex: ^sync.Mutex, allocator: mem.Allocator, turn: conversation.Turn_Id, request: conversation.Request_Id, completed: bool, } concurrent_owner :: proc(t: ^thread.Thread) { data := (^Owner_Thread_Test)(t.data) context.allocator = data.allocator f: Fixture; fixture_init(&f, .Text); defer fixture_destroy(&f) f.runtime.services.identities = data.issuer f.runtime.services.identity_mutex = data.mutex send(&f.executor, agent.Submit{"prompt"}); drain(&f.executor) data.turn = f.runtime.conversation.turns[0].id data.request = f.runtime.conversation.requests[0].provenance.identity.request data.completed = f.runtime.conversation.turns[0].outcome == .Complete } @(test) root_identity_issuer_is_serialized_across_independent_owner_threads :: proc(t: ^testing.T) { issuer: agent.Identity_Issuer; mutex: sync.Mutex data := [2]Owner_Thread_Test{{issuer = &issuer, mutex = &mutex, allocator = context.allocator}, {issuer = &issuer, mutex = &mutex, allocator = context.allocator}} threads: [2]^thread.Thread for i in 0..<2 { threads[i] = thread.create(concurrent_owner); threads[i].data = &data[i]; thread.start(threads[i]) } for worker in threads { thread.join(worker); thread.destroy(worker) } testing.expect(t, data[0].completed && data[1].completed) testing.expect(t, data[0].turn != data[1].turn && data[0].request != data[1].request) } @(test) queued_turns_capture_selection_on_dequeue_and_suspension_does_not_pause_workers :: proc(t: ^testing.T) { f: Fixture; fixture_init(&f, .Hold_Terminal); defer fixture_destroy(&f) send(&f.executor, agent.Submit{"prompt"}); poll(&f.executor, true) sync.wait(&f.fake.arrived) send(&f.executor, agent.Submit{"second"}) send(&f.executor, agent.Set_Selection{{model = {"fake", "other"}}}) send(&f.executor, agent.Suspend{true}) sync.post(&f.fake.release) drain(&f.executor) testing.expect_value(t, f.fake.runs, 1) testing.expect_value(t, len(f.runtime.agent.pending.items), 1) send(&f.executor, agent.Suspend{false}); drain(&f.executor) testing.expect_value(t, f.fake.runs, 2) testing.expect_value(t, f.runtime.conversation.turns[0].selection.model.id, "model") testing.expect_value(t, f.runtime.conversation.turns[1].selection.model.id, "other") testing.expect_value(t, f.observed.started, 2) } @(test) many_turns_release_worker_mailboxes_and_snapshots_on_every_join :: proc(t: ^testing.T) { f: Fixture; fixture_init(&f, .Text); defer fixture_destroy(&f) // Save fixture logs are bounded separately; reset them after each completed turn. for i in 0..<100 { send(&f.executor, agent.Submit{"prompt"}); drain(&f.executor) testing.expect(t, f.executor.active == nil && f.executor.pending == nil) testing.expect_value(t, f.runtime.agent.phase, agent.Phase.Idle) f.fake.saves = 0 } testing.expect_value(t, f.fake.runs, 100) testing.expect_value(t, len(f.runtime.conversation.turns), 100) testing.expect(t, f.fake.snapshots_ok) } @(test) oversized_tool_result_fails_infrastructure_but_preserves_completed_effect_metadata :: proc(t: ^testing.T) { f: Fixture; fixture_init(&f, .Oversized_Tool); defer fixture_destroy(&f) send(&f.executor, agent.Submit{"prompt"}); drain(&f.executor) testing.expect_value(t, f.fake.tools, 1) testing.expect_value(t, f.fake.runs, 1) testing.expect_value(t, f.runtime.conversation.turns[0].failure, conversation.Failure_Cause.Tool_Infrastructure) testing.expect_value(t, f.runtime.conversation.messages[2].content[0].(conversation.Tool_Result).execution.state, conversation.Execution_State.Completed) } @(test) oversized_store_error_uses_reliable_failure_path_and_shutdown_does_not_retry :: proc(t: ^testing.T) { f: Fixture; fixture_init(&f, .Text); defer fixture_destroy(&f) f.fake.oversized_save = true send(&f.executor, agent.Submit{"prompt"}); drain(&f.executor) testing.expect_value(t, f.runtime.agent.phase, agent.Phase.Durability_Blocked) testing.expect_value(t, f.fake.saves, 1) testing.expect(t, !close(&f.executor)) testing.expect_value(t, f.fake.saves, 1) testing.expect_value(t, f.fake.runs, 0) } @(test) ignored_output_allocation_refusal_cannot_be_acknowledged_as_success :: proc(t: ^testing.T) { f: Fixture; fixture_init(&f, .Exhausted_Tool) send(&f.executor, agent.Submit{"prompt"}); drain(&f.executor) testing.expect_value(t, f.runtime.conversation.turns[0].failure, conversation.Failure_Cause.Tool_Infrastructure) testing.expect_value(t, f.fake.tools, 1) fixture_destroy(&f) f = {}; fixture_init(&f, .Text) f.fake.exhausted_save = true send(&f.executor, agent.Submit{"prompt"}); drain(&f.executor) testing.expect_value(t, f.runtime.agent.phase, agent.Phase.Durability_Blocked) testing.expect_value(t, f.fake.runs, 0) fixture_destroy(&f) } @(test) frozen_registry_survives_source_definition_replacement :: proc(t: ^testing.T) { f: Fixture; fixture_init(&f); defer fixture_destroy(&f) f.registry.entries[0].name = "replacement" f.registry.entries[0].execute = nil send(&f.executor, agent.Submit{"prompt"}); drain(&f.executor) testing.expect_value(t, f.fake.tools, 2) testing.expect(t, f.fake.snapshots_ok) testing.expect_value(t, f.runtime.conversation.turns[0].outcome, conversation.Outcome.Complete) } @(test) executor_refuses_attachment_to_an_already_active_immediate_reducer :: proc(t: ^testing.T) { f: Fixture; fixture_init(&f, .Text); defer fixture_destroy(&f) destroy_executor(&f.executor) step(&f.runtime, agent.Submit{"prompt"}, "frozen", nil, TEST_LIMITS) testing.expect_value(t, init_executor(&f.executor, &f.runtime, {instructions = "frozen", projection_limits = TEST_LIMITS}, {}, context.allocator), conversation.Error.Invalid_State) testing.expect(t, f.runtime.executor == nil) } @(test) idle_shutdown_save_failure_blocks_retry_without_revising_a_durable_completed_turn :: proc(t: ^testing.T) { f: Fixture; fixture_init(&f, .Text); defer fixture_destroy(&f) send(&f.executor, agent.Submit{"prompt"}); drain(&f.executor) f.fake.fail_save = 3 send(&f.executor, agent.Set_Selection{{model = {"fake", "other"}}}) testing.expect(t, !close(&f.executor)) testing.expect_value(t, f.runtime.agent.phase, agent.Phase.Durability_Blocked) testing.expect_value(t, f.runtime.conversation.turns[0].outcome, conversation.Outcome.Complete) testing.expect_value(t, f.runtime.conversation.turns[0].failure, conversation.Failure_Cause.None) send(&f.executor, agent.Retry_Save{}); drain(&f.executor) testing.expect_value(t, f.runtime.agent.phase, agent.Phase.Idle) testing.expect_value(t, f.fake.runs, 1) testing.expect_value(t, f.fake.saves, 4) testing.expect(t, close(&f.executor)) testing.expect_value(t, f.runtime.conversation.turns[0].outcome, conversation.Outcome.Complete) }