moo.agent.tests.test_brain_chain

Tests for moo/agent/brain_chain.py — process_server_text pure function.

Covers every branch: - Orchestrator auto-start on “Connected” - Worker reconnect page on “Connected” + prior_goal_for_reconnect - [Mail] line suppression + REPORT: memory_summary injection - “not currently logged in” clears dispatch timer - “has connected” triggers re-page - Dig room ID tracking in rooms_built - “pages, Token: … done” triggers orchestrator auto-relay - “pages, Token: … reconnected” triggers auto-reconnect - Worker receives token → check_inbox prepended - Session state reset on new token when session_done - Auto-advance plan on dig success - Plan exhausted flag after last dig

Functions

test_auto_reconnect_repage_cooldown_blocks_rapid_followups()

After Foreman re-pages a worker via auto-reconnect, subsequent Token: X reconnected pages within the cooldown window must be ignored — otherwise a chatty LLM that pings Foreman 5 times in 30s yields 5 re-pages and the original loop returns.

test_connected_orchestrator_auto_pages_first_agent()

test_connected_orchestrator_repages_holder_when_dispatch_restored()

When dispatch.json restored a holder, Foreman re-pages them on boot — the worker often restarted with us and needs a fresh Token: X go. signal.

test_connected_orchestrator_with_prior_goal_does_not_reconnect()

test_connected_worker_does_not_auto_start()

A worker (user in chain) must not auto-page anyone.

test_connected_worker_with_prior_goal_reconnects_to_foreman()

test_dig_room_id_tracked_in_rooms_built()

test_dig_success_advances_past_skipped_room()

Digging a room deeper in the plan removes preceding rooms.

test_dig_success_advances_plan_past_built_room()

test_dig_success_triggers_plan_exhausted_when_last()

test_dig_success_unknown_room_leaves_plan_unchanged()

test_disconnect_followed_by_reconnect_triggers_re_page()

End-to-end: disconnect arms; reconnect fires the deterministic re-page.

test_dispatch_restored_arms_reconnect_cooldown()

The restore-on-Connect re-page (from dispatch.json) must also arm the cooldown so a worker's deterministic reconnect ping doesn't trigger a second re-page seconds later.

test_divine_output_auto_populates_current_plan()

Server's divine() listing populates current_plan without an LLM PLAN: directive.

test_divine_output_does_not_overwrite_active_plan()

Plan auto-extraction must defer to an existing token-page or BUILD_PLAN: plan.

test_divine_output_overrides_stale_plan_from_disk()

A plan loaded from disk on startup is stale; divine output should replace it.

test_has_connected_ignored_when_timer_still_live()

test_has_connected_re_pages_waiting_target()

test_mail_line_is_skipped()

test_mail_report_injects_memory_summary()

test_not_logged_in_clears_dispatch_timer()

test_orchestrator_auto_reconnect_ignored_when_waiting_for_other()

If Foreman is currently waiting for Tinker, a Mason reconnect should be ignored.

test_orchestrator_auto_reconnects_matching_agent()

test_orchestrator_auto_reconnects_with_site_suffix()

Multi-universe SSH users include a +site suffix in their reconnect page.

test_orchestrator_auto_relay_wraps_to_head_of_chain()

test_orchestrator_auto_relays_done_to_next_chain_agent()

test_orchestrator_does_not_inject_worker_directive()

Foreman receiving its own dispatched Token: page (echo or reconnect self-page) must not get the worker-side directive — it's not a worker.

test_orchestrator_on_connect_arms_reconnect_cooldown()

The deterministic re-page on has connected must arm the cooldown so a follow-up LLM-emitted Token: X reconnected doesn't re-page again.

test_plain_text_produces_no_actions()

test_token_done_clears_dispatch_timer()

test_token_done_page_produces_no_prepend_scripts()

A done page arriving at the orchestrator should not prepend scripts.

test_token_heartbeat_clears_dispatch_timer()

A non-done Token: X working. page from the current holder also clears Foreman's stall timer.

test_token_page_from_non_holder_does_not_clear_timer()

A Token: page from someone other than the current holder must not reset the stall timer — otherwise a stray worker page could mask a genuine stall on the actual holder.

test_token_page_resets_session_done_state()

test_token_page_worker_recognizes_go_format()

Workers receiving 'Token: X go.' should have session state reset.

test_worker_disconnect_clears_dispatch_timer()

A worker's disconnect must clear token_dispatched_at so the next has connected event triggers an automatic re-page.

test_worker_disconnect_for_non_holder_is_noop()

Disconnect events for someone other than the current holder must not touch Foreman's stall timer.

test_worker_does_not_auto_relay()

Workers must never relay — they receive tokens, not dispatch them.

test_worker_ignores_token_for_other_agent()

A worker hearing a Token: page addressed to someone else (broadcast leakage from same-room pages) must not clear its own goal.

test_worker_receives_own_token_clears_goal_and_dispatches_survey()

A worker receiving Token: <Me> go. must have its stale goal cleared, memory_summary set to an unambiguous work directive, and a deterministic @survey here command dispatched so the next LLM cycle reacts to concrete world state instead of having to decide whether the token is "really" theirs.

test_worker_receives_own_token_start_form_also_triggers_injection()

The first dispatch uses Token: Foreman start.; treat it the same as go. — both mean begin work.

test_worker_receives_stall_resume_form_also_triggers_injection()

Foreman's stall re-page uses Token: <Name> resume. — treat it the same as go. so a stuck worker gets a fresh work directive on stall recovery instead of a noise-shaped page that the LLM ignores.

test_worker_reconnect_page_strips_site_suffix()

A worker logged in as user+site should still page foreman as just <Name>.

test_worker_with_site_suffix_recognizes_token_with_bare_name()

The page text uses the bare agent name (Token: Joiner go.) even when the SSH user includes a +site routing suffix — the worker must still match its own token via the bare name.