moo.agent.tests.test_brain

Tests for moo/agent/brain — surviving helper logic plus the new Stage-2 tool loop wiring. Tests of the deleted _dispatch_actions/_script_queue/ _drain_script/_rewrite_board_post/_is_redundant_teleport paths have been removed; their behaviour now lives in moo/agent/agent_tools.py (covered by test_agent_tools.py).

Functions

test_apply_agent_response_folds_back_foreman_paged()

test_apply_agent_response_folds_back_token_dispatch()

test_apply_agent_response_session_done_via_deps_runs_through_handle_done()

test_apply_patch_bad_directive_ignored(tmp_path)

test_apply_patch_no_config_dir_noop()

test_apply_patch_note_no_arrow_required(tmp_path)

test_apply_patch_note_reloads_context(tmp_path)

test_apply_patch_note_written_to_file(tmp_path)

test_apply_patch_updates_rules(tmp_path)

test_build_user_message_bare_window()

test_build_user_message_goal_plan_and_summary_ordering()

test_build_user_message_includes_goal()

test_build_user_message_includes_memory_summary()

test_build_user_message_includes_plan()

test_build_user_message_includes_wakeup_counter()

test_build_user_message_no_wakeup_counter_at_zero()

test_build_user_message_wakeup_counter_before_window()

test_check_rules_first_match_wins()

test_check_rules_match()

test_check_rules_no_match()

test_check_verb_test_mistake_ignores_unrelated_errors()

test_check_verb_test_mistake_ignores_when_last_cmd_isnt_look()

test_check_verb_test_mistake_injects_hint()

test_compile_rules_empty()

test_compile_rules_returns_patterns()

test_enqueue_output_resets_activity_time()

test_extract_room_names_excludes_nested()

test_extract_room_names_from_yaml_empty()

test_extract_room_names_from_yaml_quoted()

test_extract_room_names_from_yaml_unquoted()

test_initial_goal_and_plan_empty()

test_llm_cycle_applies_soul_patch_note(tmp_path)

A soul_patches entry in the AgentResponse is appended to SOUL.patch.md.

test_llm_cycle_done_field_blocked_without_foreman_page()

test_llm_cycle_done_field_clears_goal()

The legacy done field clears the goal when foreman has been paged.

test_llm_cycle_emits_cycle_marker()

test_llm_cycle_emits_pending_done_msg_at_start()

Pending done message emitted at the start of the next _llm_cycle.

test_llm_cycle_handles_build_plan_field(tmp_path)

test_llm_cycle_marker_emitted_on_llm_error()

test_llm_cycle_marker_records_zero_tool_calls_as_goal_only()

test_llm_cycle_null_plan_leaves_current_plan_untouched()

test_llm_cycle_plan_field_sets_current_plan()

test_make_deps_exposes_live_state()

test_productive_cycle_resets_empty_cycle_budget()

A productive cycle clears empty_cycle_count so a later zero-action cycle in the same task gets a fresh 3-cycle nudge window.

test_productive_worker_cycle_schedules_auto_recycle()

A worker cycle that ends with tool calls but without paging foreman done must auto-fire another cycle — otherwise the LLM stops mid-mission after one or two tool calls and the chain stalls until Foreman's stall timer fires.

test_record_tool_dispatch_logs_to_window_and_action_callback()

test_resolve_intent_case_insensitive()

test_resolve_intent_known()

test_resolve_intent_unknown_passthrough()

test_run_llm_with_retry_maps_usage_limit_exceeded_to_none()

A UsageLimitExceeded from the tool-call cap surfaces as None and emits a [Cycle] tool_call_cap_hit thought so the recycle path fires.

test_run_llm_with_retry_maps_validation_failure_to_none()

test_save_build_plan_creates_yaml_file(tmp_path)

test_save_build_plan_expands_newlines(tmp_path)

test_save_build_plan_no_config_dir_is_noop()

test_save_build_plan_oserror_does_not_raise(...)

test_save_traversal_plan_oserror_does_not_raise(...)

test_session_done_blocks_output_wakeup()

After done is signalled, enqueue_output must not trigger a new LLM cycle.

test_set_status_calls_callback()

test_set_status_no_duplicate_callback()

test_set_status_sequences()

test_stall_check_falls_through_on_sentinel_values(...)

test_stall_check_falls_through_on_subprocess_failure(...)

test_stall_check_falls_through_when_env_vars_missing(...)

test_stall_check_honors_minimum_of_configured_timeout(...)

test_stall_check_repages_when_target_exceeds_adaptive_threshold(...)

test_stall_check_skips_repage_when_target_is_actively_cycling(...)

test_status_enum_values()

test_update_current_room_from_burrow_output()

test_update_current_room_from_move_output_still_works()

test_worker_cycle_after_done_does_not_recycle()

Once the worker has paged foreman done, no more auto-recycles.

testlooks_like_error_false()

testlooks_like_error_true()

Classes

FakeConnection()

Records send() calls; request() is unused in brain unit tests.