@team-agent/installer 0.5.128 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/README.zh.md +1 -1
- package/package.json +4 -8
- package/skills/team-agent/SKILL.md +37 -20
- package/skills/team-agent/command-coverage.json +169 -183
- package/skills/team-agent/docs/reference/team-agent-operator.md +64 -30
- package/skills/team-agent/references/recovery-runbook.md +1 -1
- package/skills/team-agent/references/team-agent-operator.md +64 -30
- package/templates/team_state.md +1 -1
- package/Cargo.lock +0 -1063
- package/Cargo.toml +0 -36
- package/crates/team-agent/Cargo.toml +0 -69
- package/crates/team-agent/src/app_server_test_support.rs +0 -258
- package/crates/team-agent/src/cli/adapters.rs +0 -1288
- package/crates/team-agent/src/cli/arguments.rs +0 -405
- package/crates/team-agent/src/cli/attach_app_server_leader.rs +0 -98
- package/crates/team-agent/src/cli/diagnose.rs +0 -1721
- package/crates/team-agent/src/cli/emit.rs +0 -2930
- package/crates/team-agent/src/cli/grok_slot.rs +0 -384
- package/crates/team-agent/src/cli/helpers.rs +0 -91
- package/crates/team-agent/src/cli/intent/runtime.rs +0 -1216
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -912
- package/crates/team-agent/src/cli/intent/tests.rs +0 -689
- package/crates/team-agent/src/cli/intent.rs +0 -664
- package/crates/team-agent/src/cli/leader.rs +0 -300
- package/crates/team-agent/src/cli/leader_prompt.rs +0 -261
- package/crates/team-agent/src/cli/leaders.rs +0 -418
- package/crates/team-agent/src/cli/mod.rs +0 -6545
- package/crates/team-agent/src/cli/models.rs +0 -1206
- package/crates/team-agent/src/cli/named_address.rs +0 -1651
- package/crates/team-agent/src/cli/profile.rs +0 -342
- package/crates/team-agent/src/cli/route.rs +0 -212
- package/crates/team-agent/src/cli/schedule.rs +0 -175
- package/crates/team-agent/src/cli/send/coordinator.rs +0 -164
- package/crates/team-agent/src/cli/send/mailbox.rs +0 -145
- package/crates/team-agent/src/cli/send/persist.rs +0 -156
- package/crates/team-agent/src/cli/send/presentation.rs +0 -370
- package/crates/team-agent/src/cli/send/resolve.rs +0 -573
- package/crates/team-agent/src/cli/send.rs +0 -199
- package/crates/team-agent/src/cli/shutdown_socket.rs +0 -288
- package/crates/team-agent/src/cli/spec.rs +0 -165
- package/crates/team-agent/src/cli/status.rs +0 -280
- package/crates/team-agent/src/cli/status_port/agents.rs +0 -358
- package/crates/team-agent/src/cli/status_port/approvals.rs +0 -79
- package/crates/team-agent/src/cli/status_port/brief.rs +0 -1981
- package/crates/team-agent/src/cli/status_port/compact.rs +0 -240
- package/crates/team-agent/src/cli/status_port/format.rs +0 -146
- package/crates/team-agent/src/cli/status_port/inbox.rs +0 -62
- package/crates/team-agent/src/cli/status_port/runtime.rs +0 -197
- package/crates/team-agent/src/cli/status_port/snapshot.rs +0 -208
- package/crates/team-agent/src/cli/status_port/store.rs +0 -416
- package/crates/team-agent/src/cli/status_port/tests.rs +0 -90
- package/crates/team-agent/src/cli/status_port.rs +0 -92
- package/crates/team-agent/src/cli/tests/base.rs +0 -885
- package/crates/team-agent/src/cli/tests/divergence.rs +0 -518
- package/crates/team-agent/src/cli/tests/lane_c.rs +0 -453
- package/crates/team-agent/src/cli/tests/leader_watch.rs +0 -322
- package/crates/team-agent/src/cli/tests/main_preserved.rs +0 -430
- package/crates/team-agent/src/cli/tests/missing_subcommands.rs +0 -336
- package/crates/team-agent/src/cli/tests/mod.rs +0 -137
- package/crates/team-agent/src/cli/tests/named_address.rs +0 -761
- package/crates/team-agent/src/cli/tests/parser_safety.rs +0 -383
- package/crates/team-agent/src/cli/tests/run_delegation.rs +0 -484
- package/crates/team-agent/src/cli/tests/shutdown_kill_plan.rs +0 -2179
- package/crates/team-agent/src/cli/tests/status_brief.rs +0 -1514
- package/crates/team-agent/src/cli/tests/status_send.rs +0 -888
- package/crates/team-agent/src/cli/tests/verb_install_skill.rs +0 -93
- package/crates/team-agent/src/cli/tests/verb_profile.rs +0 -392
- package/crates/team-agent/src/cli/triage.rs +0 -234
- package/crates/team-agent/src/cli/types.rs +0 -591
- package/crates/team-agent/src/codex_app_server.rs +0 -546
- package/crates/team-agent/src/communication_mode/mod.rs +0 -56
- package/crates/team-agent/src/compiler/tests.rs +0 -827
- package/crates/team-agent/src/compiler.rs +0 -890
- package/crates/team-agent/src/conpty/backend.rs +0 -829
- package/crates/team-agent/src/conpty/mod.rs +0 -33
- package/crates/team-agent/src/contract_runtime/backend.rs +0 -1744
- package/crates/team-agent/src/contract_runtime/commands.rs +0 -671
- package/crates/team-agent/src/contract_runtime/config.rs +0 -364
- package/crates/team-agent/src/contract_runtime/config_tests.rs +0 -76
- package/crates/team-agent/src/contract_runtime/discovery.rs +0 -449
- package/crates/team-agent/src/contract_runtime/fork.rs +0 -361
- package/crates/team-agent/src/contract_runtime/forward.rs +0 -288
- package/crates/team-agent/src/contract_runtime/framework.rs +0 -367
- package/crates/team-agent/src/contract_runtime/mcp.rs +0 -394
- package/crates/team-agent/src/contract_runtime/mod.rs +0 -17
- package/crates/team-agent/src/contract_runtime/prompt.rs +0 -216
- package/crates/team-agent/src/contract_runtime/pump.rs +0 -271
- package/crates/team-agent/src/contract_runtime/registry.rs +0 -553
- package/crates/team-agent/src/contract_runtime/workspace.rs +0 -228
- package/crates/team-agent/src/coordinator/backoff.rs +0 -741
- package/crates/team-agent/src/coordinator/conpty_shim.rs +0 -805
- package/crates/team-agent/src/coordinator/health.rs +0 -1185
- package/crates/team-agent/src/coordinator/mod.rs +0 -119
- package/crates/team-agent/src/coordinator/orphan.rs +0 -110
- package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -798
- package/crates/team-agent/src/coordinator/runtime_observation.rs +0 -84
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +0 -2309
- package/crates/team-agent/src/coordinator/steps/delivery.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/health_sync.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/mod.rs +0 -126
- package/crates/team-agent/src/coordinator/steps/persist.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/runtime_prompts.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/session_gate.rs +0 -16
- package/crates/team-agent/src/coordinator/tests/a0_lostupdate.rs +0 -158
- package/crates/team-agent/src/coordinator/tests/abnormal.rs +0 -312
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +0 -300
- package/crates/team-agent/src/coordinator/tests/basics.rs +0 -211
- package/crates/team-agent/src/coordinator/tests/daemon.rs +0 -514
- package/crates/team-agent/src/coordinator/tests/energy.rs +0 -549
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +0 -503
- package/crates/team-agent/src/coordinator/tests/main_preserved.rs +0 -186
- package/crates/team-agent/src/coordinator/tests/mod.rs +0 -295
- package/crates/team-agent/src/coordinator/tests/s3_bounded.rs +0 -207
- package/crates/team-agent/src/coordinator/tests/spine.rs +0 -308
- package/crates/team-agent/src/coordinator/tests/takeover.rs +0 -286
- package/crates/team-agent/src/coordinator/tests/tick_core.rs +0 -237
- package/crates/team-agent/src/coordinator/tick.rs +0 -3024
- package/crates/team-agent/src/coordinator/types.rs +0 -540
- package/crates/team-agent/src/db/agent_health_capture.rs +0 -126
- package/crates/team-agent/src/db/message_store.rs +0 -1527
- package/crates/team-agent/src/db/migration.rs +0 -984
- package/crates/team-agent/src/db/mod.rs +0 -26
- package/crates/team-agent/src/db/schema.rs +0 -663
- package/crates/team-agent/src/diagnose/comms.rs +0 -242
- package/crates/team-agent/src/diagnose/mod.rs +0 -44
- package/crates/team-agent/src/diagnose/orphans.rs +0 -889
- package/crates/team-agent/src/direct_delivery.rs +0 -368
- package/crates/team-agent/src/event_log.rs +0 -502
- package/crates/team-agent/src/fake_worker.rs +0 -303
- package/crates/team-agent/src/inbox_store.rs +0 -169
- package/crates/team-agent/src/kill_audit.rs +0 -106
- package/crates/team-agent/src/layout/manager.rs +0 -248
- package/crates/team-agent/src/layout/mod.rs +0 -36
- package/crates/team-agent/src/layout/overlay.rs +0 -134
- package/crates/team-agent/src/layout/placement.rs +0 -52
- package/crates/team-agent/src/layout/recovery.rs +0 -106
- package/crates/team-agent/src/layout/runtime_sessions.rs +0 -317
- package/crates/team-agent/src/layout/sessions.rs +0 -294
- package/crates/team-agent/src/layout/tmux_endpoint.rs +0 -165
- package/crates/team-agent/src/layout/worker_env.rs +0 -721
- package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -37
- package/crates/team-agent/src/leader/helpers.rs +0 -178
- package/crates/team-agent/src/leader/incident.rs +0 -6
- package/crates/team-agent/src/leader/lease.rs +0 -3356
- package/crates/team-agent/src/leader/mod.rs +0 -104
- package/crates/team-agent/src/leader/owner_bind.rs +0 -400
- package/crates/team-agent/src/leader/prompt.rs +0 -905
- package/crates/team-agent/src/leader/provider_attribution.rs +0 -247
- package/crates/team-agent/src/leader/rediscover/tests.rs +0 -689
- package/crates/team-agent/src/leader/rediscover.rs +0 -1192
- package/crates/team-agent/src/leader/registry.rs +0 -888
- package/crates/team-agent/src/leader/start.rs +0 -4501
- package/crates/team-agent/src/leader/takeover.rs +0 -65
- package/crates/team-agent/src/leader/tests/basics.rs +0 -337
- package/crates/team-agent/src/leader/tests/byte_findings.rs +0 -355
- package/crates/team-agent/src/leader/tests/claim_leader_mailbox_flush_contract.rs +0 -544
- package/crates/team-agent/src/leader/tests/historical_inventory_upgrade_gate_red.rs +0 -624
- package/crates/team-agent/src/leader/tests/identity.rs +0 -465
- package/crates/team-agent/src/leader/tests/identity_session_names.rs +0 -42
- package/crates/team-agent/src/leader/tests/idle.rs +0 -113
- package/crates/team-agent/src/leader/tests/lease_api.rs +0 -520
- package/crates/team-agent/src/leader/tests/lease_claim.rs +0 -629
- package/crates/team-agent/src/leader/tests/mod.rs +0 -106
- package/crates/team-agent/src/leader/tests/prompt_contract.rs +0 -268
- package/crates/team-agent/src/leader/tests/rediscover.rs +0 -403
- package/crates/team-agent/src/leader/tests/rehomed_env.rs +0 -83
- package/crates/team-agent/src/leader/tests/team_in_team_state_scope_red.rs +0 -1273
- package/crates/team-agent/src/leader/tests/terminal_and_replay_vs_rerender_invariants_red.rs +0 -417
- package/crates/team-agent/src/leader/tests/wake_start_owner.rs +0 -168
- package/crates/team-agent/src/leader/types.rs +0 -534
- package/crates/team-agent/src/lib.rs +0 -147
- package/crates/team-agent/src/lifecycle/helpers.rs +0 -212
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +0 -881
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +0 -598
- package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -332
- package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +0 -204
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -107
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +0 -144
- package/crates/team-agent/src/lifecycle/launch/identity.rs +0 -674
- package/crates/team-agent/src/lifecycle/launch/layout.rs +0 -350
- package/crates/team-agent/src/lifecycle/launch/leader_context.rs +0 -589
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +0 -160
- package/crates/team-agent/src/lifecycle/launch/ownership.rs +0 -105
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +0 -899
- package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +0 -225
- package/crates/team-agent/src/lifecycle/launch/plan.rs +0 -269
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -5200
- package/crates/team-agent/src/lifecycle/launch/quick_start_transport.rs +0 -368
- package/crates/team-agent/src/lifecycle/launch/readiness.rs +0 -519
- package/crates/team-agent/src/lifecycle/launch/role_source.rs +0 -287
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -473
- package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -801
- package/crates/team-agent/src/lifecycle/launch/state_projection.rs +0 -624
- package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -558
- package/crates/team-agent/src/lifecycle/launch.rs +0 -557
- package/crates/team-agent/src/lifecycle/lock.rs +0 -350
- package/crates/team-agent/src/lifecycle/mod.rs +0 -79
- package/crates/team-agent/src/lifecycle/pane_input_lock.rs +0 -239
- package/crates/team-agent/src/lifecycle/profile_launch.rs +0 -1067
- package/crates/team-agent/src/lifecycle/profile_smoke.rs +0 -557
- package/crates/team-agent/src/lifecycle/restart/agent.rs +0 -2199
- package/crates/team-agent/src/lifecycle/restart/avatar.rs +0 -1798
- package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +0 -163
- package/crates/team-agent/src/lifecycle/restart/common.rs +0 -2362
- package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +0 -65
- package/crates/team-agent/src/lifecycle/restart/preflight.rs +0 -113
- package/crates/team-agent/src/lifecycle/restart/rebuild.rs +0 -5135
- package/crates/team-agent/src/lifecycle/restart/remove.rs +0 -1504
- package/crates/team-agent/src/lifecycle/restart/selection.rs +0 -559
- package/crates/team-agent/src/lifecycle/restart/team_state.rs +0 -329
- package/crates/team-agent/src/lifecycle/restart.rs +0 -227
- package/crates/team-agent/src/lifecycle/role_config.rs +0 -1230
- package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +0 -1021
- package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +0 -1205
- package/crates/team-agent/src/lifecycle/tests/b0_legacy_snapshot_nonauthority_contract.rs +0 -265
- package/crates/team-agent/src/lifecycle/tests/b0_reader_hideone_audit_contract.rs +0 -490
- package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +0 -656
- package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +0 -325
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +0 -447
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +0 -1638
- package/crates/team-agent/src/lifecycle/tests/clone_agent_preserves_source_tools.rs +0 -427
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +0 -770
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +0 -419
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +0 -2035
- package/crates/team-agent/src/lifecycle/tests/core.rs +0 -1327
- package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +0 -315
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_g0.stdout.txt +0 -222
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_spaced_ids.stdout.txt +0 -9
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +0 -72
- package/crates/team-agent/src/lifecycle/tests/gate_fixtures.rs +0 -562
- package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +0 -110
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +0 -512
- package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +0 -921
- package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +0 -68
- package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +0 -1851
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +0 -3983
- package/crates/team-agent/src/lifecycle/tests/lifecycle_lock.rs +0 -339
- package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +0 -596
- package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +0 -513
- package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +0 -69
- package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +0 -824
- package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +0 -723
- package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +0 -164
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +0 -200
- package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +0 -210
- package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +0 -527
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +0 -1062
- package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +0 -1419
- package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +0 -98
- package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +0 -550
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +0 -226
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +0 -332
- package/crates/team-agent/src/lifecycle/tests/realmachine_clusters_1_6_red.rs +0 -786
- package/crates/team-agent/src/lifecycle/tests/realmachine_residual_g1_g4_red.rs +0 -648
- package/crates/team-agent/src/lifecycle/tests/restart.rs +0 -185
- package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +0 -1053
- package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +0 -679
- package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1126
- package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +0 -153
- package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +0 -427
- package/crates/team-agent/src/lifecycle/tests/stale_team_saveconflict_contract.rs +0 -431
- package/crates/team-agent/src/lifecycle/tests/startup_latency_contract.rs +0 -1066
- package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +0 -876
- package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +0 -1026
- package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +0 -342
- package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +0 -543
- package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +0 -1103
- package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +0 -1276
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_roster_red.rs +0 -145
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +0 -603
- package/crates/team-agent/src/lifecycle/tests/test_isolation_escape_contract.rs +0 -936
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +0 -970
- package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +0 -995
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -836
- package/crates/team-agent/src/lifecycle/tests.rs +0 -105
- package/crates/team-agent/src/lifecycle/types.rs +0 -877
- package/crates/team-agent/src/lifecycle/worker_command_context.rs +0 -363
- package/crates/team-agent/src/main.rs +0 -52
- package/crates/team-agent/src/mcp_server/helpers.rs +0 -510
- package/crates/team-agent/src/mcp_server/lifecycle_tools/mod.rs +0 -6
- package/crates/team-agent/src/mcp_server/lifecycle_tools/state_status.rs +0 -43
- package/crates/team-agent/src/mcp_server/mod.rs +0 -119
- package/crates/team-agent/src/mcp_server/normalize.rs +0 -485
- package/crates/team-agent/src/mcp_server/readiness.rs +0 -527
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +0 -348
- package/crates/team-agent/src/mcp_server/tests/golden.rs +0 -285
- package/crates/team-agent/src/mcp_server/tests/normalize.rs +0 -247
- package/crates/team-agent/src/mcp_server/tests/scoped.rs +0 -158
- package/crates/team-agent/src/mcp_server/tests/send.rs +0 -353
- package/crates/team-agent/src/mcp_server/tests/tools.rs +0 -341
- package/crates/team-agent/src/mcp_server/tests/wire.rs +0 -254
- package/crates/team-agent/src/mcp_server/tests.rs +0 -43
- package/crates/team-agent/src/mcp_server/tools.rs +0 -889
- package/crates/team-agent/src/mcp_server/types.rs +0 -396
- package/crates/team-agent/src/mcp_server/wire.rs +0 -867
- package/crates/team-agent/src/messaging/activity.rs +0 -461
- package/crates/team-agent/src/messaging/address.rs +0 -87
- package/crates/team-agent/src/messaging/delivery.rs +0 -3727
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +0 -234
- package/crates/team-agent/src/messaging/enter_rescue.rs +0 -362
- package/crates/team-agent/src/messaging/enter_rescue_tests.rs +0 -633
- package/crates/team-agent/src/messaging/helpers.rs +0 -336
- package/crates/team-agent/src/messaging/leader_channel.rs +0 -287
- package/crates/team-agent/src/messaging/leader_receiver.rs +0 -786
- package/crates/team-agent/src/messaging/mod.rs +0 -167
- package/crates/team-agent/src/messaging/persist.rs +0 -377
- package/crates/team-agent/src/messaging/presentation.rs +0 -417
- package/crates/team-agent/src/messaging/reminders.rs +0 -316
- package/crates/team-agent/src/messaging/results/collection_tests.rs +0 -719
- package/crates/team-agent/src/messaging/results.rs +0 -1415
- package/crates/team-agent/src/messaging/scheduler.rs +0 -223
- package/crates/team-agent/src/messaging/selftest.rs +0 -315
- package/crates/team-agent/src/messaging/send.rs +0 -981
- package/crates/team-agent/src/messaging/tests/basic.rs +0 -346
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +0 -657
- package/crates/team-agent/src/messaging/tests/e23.rs +0 -49
- package/crates/team-agent/src/messaging/tests/leader_channel.rs +0 -169
- package/crates/team-agent/src/messaging/tests/leader_inject_acceptance.rs +0 -817
- package/crates/team-agent/src/messaging/tests/main_preserved.rs +0 -85
- package/crates/team-agent/src/messaging/tests/mod.rs +0 -306
- package/crates/team-agent/src/messaging/tests/runtime.rs +0 -3549
- package/crates/team-agent/src/messaging/tests/spine.rs +0 -853
- package/crates/team-agent/src/messaging/tests/wave2.rs +0 -381
- package/crates/team-agent/src/messaging/trust.rs +0 -215
- package/crates/team-agent/src/messaging/types.rs +0 -472
- package/crates/team-agent/src/messaging/wait.rs +0 -366
- package/crates/team-agent/src/messaging/watchers.rs +0 -916
- package/crates/team-agent/src/model/enums.rs +0 -356
- package/crates/team-agent/src/model/errors.rs +0 -18
- package/crates/team-agent/src/model/ids.rs +0 -165
- package/crates/team-agent/src/model/mod.rs +0 -29
- package/crates/team-agent/src/model/name_similarity.rs +0 -252
- package/crates/team-agent/src/model/pane_authority_refusal.rs +0 -359
- package/crates/team-agent/src/model/paths.rs +0 -257
- package/crates/team-agent/src/model/routing.rs +0 -387
- package/crates/team-agent/src/model/spec.rs +0 -1184
- package/crates/team-agent/src/model/task_graph.rs +0 -321
- package/crates/team-agent/src/model/testdata/fuzz.golden.yaml +0 -43
- package/crates/team-agent/src/model/testdata/fuzz.yaml +0 -43
- package/crates/team-agent/src/model/testdata/spec_invalid_a.yaml +0 -209
- package/crates/team-agent/src/model/testdata/team.spec.golden.yaml +0 -208
- package/crates/team-agent/src/model/testdata/team.spec.yaml +0 -208
- package/crates/team-agent/src/model/yaml/tests.rs +0 -188
- package/crates/team-agent/src/model/yaml.rs +0 -802
- package/crates/team-agent/src/os_probe.rs +0 -280
- package/crates/team-agent/src/packaging/install.rs +0 -219
- package/crates/team-agent/src/packaging/migrate.rs +0 -38
- package/crates/team-agent/src/packaging/mod.rs +0 -91
- package/crates/team-agent/src/packaging/repair.rs +0 -33
- package/crates/team-agent/src/packaging/tests.rs +0 -822
- package/crates/team-agent/src/packaging/types.rs +0 -417
- package/crates/team-agent/src/platform/argv.rs +0 -331
- package/crates/team-agent/src/platform/errors.rs +0 -104
- package/crates/team-agent/src/platform/file_lock.rs +0 -279
- package/crates/team-agent/src/platform/mod.rs +0 -5
- package/crates/team-agent/src/platform/process.rs +0 -545
- package/crates/team-agent/src/provider/adapter.rs +0 -1150
- package/crates/team-agent/src/provider/adapters/claude.rs +0 -78
- package/crates/team-agent/src/provider/adapters/claude_fork.rs +0 -131
- package/crates/team-agent/src/provider/adapters/copilot.rs +0 -75
- package/crates/team-agent/src/provider/adapters/copilot_fork.rs +0 -307
- package/crates/team-agent/src/provider/adapters/fake.rs +0 -18
- package/crates/team-agent/src/provider/adapters/mod.rs +0 -30
- package/crates/team-agent/src/provider/adapters/pi.rs +0 -106
- package/crates/team-agent/src/provider/approvals/mod.rs +0 -3
- package/crates/team-agent/src/provider/approvals/parsing.rs +0 -586
- package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +0 -205
- package/crates/team-agent/src/provider/argv_route.rs +0 -405
- package/crates/team-agent/src/provider/bypass_flags.rs +0 -116
- package/crates/team-agent/src/provider/classify.rs +0 -708
- package/crates/team-agent/src/provider/command_helpers.rs +0 -45
- package/crates/team-agent/src/provider/faults.rs +0 -165
- package/crates/team-agent/src/provider/helpers.rs +0 -52
- package/crates/team-agent/src/provider/mod.rs +0 -78
- package/crates/team-agent/src/provider/model_catalog.rs +0 -910
- package/crates/team-agent/src/provider/session/capture.rs +0 -2731
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +0 -123
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -172
- package/crates/team-agent/src/provider/session/context_fork.rs +0 -396
- package/crates/team-agent/src/provider/session/mod.rs +0 -36
- package/crates/team-agent/src/provider/session/resume.rs +0 -269
- package/crates/team-agent/src/provider/session_scan/claude.rs +0 -523
- package/crates/team-agent/src/provider/session_scan/common/tests.rs +0 -316
- package/crates/team-agent/src/provider/session_scan/common.rs +0 -654
- package/crates/team-agent/src/provider/session_scan/copilot.rs +0 -280
- package/crates/team-agent/src/provider/session_scan/pi.rs +0 -185
- package/crates/team-agent/src/provider/session_scan.rs +0 -71
- package/crates/team-agent/src/provider/startup_prompt.rs +0 -757
- package/crates/team-agent/src/provider/submit_now.rs +0 -71
- package/crates/team-agent/src/provider/testdata/copilot-ready-marker.txt +0 -5
- package/crates/team-agent/src/provider/testdata/copilot-trust-prompt.txt +0 -19
- package/crates/team-agent/src/provider/testdata/grok-models-authenticated.stdout +0 -9
- package/crates/team-agent/src/provider/testdata/grok-models-unauthenticated.stdout +0 -7
- package/crates/team-agent/src/provider/tests/adapter.rs +0 -441
- package/crates/team-agent/src/provider/tests/classify.rs +0 -148
- package/crates/team-agent/src/provider/tests/command_helpers.rs +0 -35
- package/crates/team-agent/src/provider/tests/copilot_fork.rs +0 -191
- package/crates/team-agent/src/provider/tests/faults.rs +0 -200
- package/crates/team-agent/src/provider/tests/idle.rs +0 -177
- package/crates/team-agent/src/provider/tests/wire.rs +0 -213
- package/crates/team-agent/src/provider/tests.rs +0 -32
- package/crates/team-agent/src/provider/types.rs +0 -529
- package/crates/team-agent/src/provider/wire.rs +0 -394
- package/crates/team-agent/src/redaction.rs +0 -259
- package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +0 -248
- package/crates/team-agent/src/state/abnormal_watch.rs +0 -144
- package/crates/team-agent/src/state/identity.rs +0 -914
- package/crates/team-agent/src/state/identity_keys.rs +0 -132
- package/crates/team-agent/src/state/mod.rs +0 -74
- package/crates/team-agent/src/state/owner_gate.rs +0 -482
- package/crates/team-agent/src/state/ownership.rs +0 -563
- package/crates/team-agent/src/state/paths.rs +0 -395
- package/crates/team-agent/src/state/persist.rs +0 -3811
- package/crates/team-agent/src/state/projection.rs +0 -1508
- package/crates/team-agent/src/state/repository/intent.rs +0 -14
- package/crates/team-agent/src/state/repository/tests.rs +0 -184
- package/crates/team-agent/src/state/repository.rs +0 -866
- package/crates/team-agent/src/state/selector.rs +0 -160
- package/crates/team-agent/src/state/testdata/state-rich.canonical.json +0 -133
- package/crates/team-agent/src/test_support/models_timeout_fixture.rs +0 -144
- package/crates/team-agent/src/tmux_backend/enter_rescue.rs +0 -325
- package/crates/team-agent/src/tmux_backend/enter_rescue_tests.rs +0 -432
- package/crates/team-agent/src/tmux_backend/native_input.rs +0 -513
- package/crates/team-agent/src/tmux_backend/native_input_tests.rs +0 -742
- package/crates/team-agent/src/tmux_backend/tests.rs +0 -4103
- package/crates/team-agent/src/tmux_backend.rs +0 -4492
- package/crates/team-agent/src/topology.rs +0 -537
- package/crates/team-agent/src/transport/enter_rescue.rs +0 -166
- package/crates/team-agent/src/transport/native_input.rs +0 -491
- package/crates/team-agent/src/transport/test_support.rs +0 -743
- package/crates/team-agent/src/transport/tests/behavior.rs +0 -326
- package/crates/team-agent/src/transport/tests/mod.rs +0 -194
- package/crates/team-agent/src/transport/tests/wire.rs +0 -574
- package/crates/team-agent/src/transport.rs +0 -1655
- package/crates/team-agent/src/transport_factory.rs +0 -819
|
@@ -1,2179 +0,0 @@
|
|
|
1
|
-
//! E12 (P0) · `sessions_to_kill` 纯决策单测(kill 决策下沉)。
|
|
2
|
-
//!
|
|
3
|
-
//! spare = state 锚 session(anchor_sessions) ∪ `team-agent-leader-` 命名前缀(并集,锚优先)。
|
|
4
|
-
//! Cleanup is always per-session and ownership-gated; a socket is never sufficient authority for kill-server.
|
|
5
|
-
//! 集成面由 tests/b5_leader_terminal_kill_red.rs 的真 tmux 契约覆盖,此处锁纯决策 + 4 反向 case。
|
|
6
|
-
|
|
7
|
-
use crate::cli::lifecycle_port::{sessions_to_kill, KillDecision};
|
|
8
|
-
use crate::transport::{
|
|
9
|
-
AttachOutcome, BackendKind, CaptureRange, CapturedText, InjectPayload, InjectReport, Key,
|
|
10
|
-
PaneField, PaneId, PaneInfo, SessionName, SetEnvOutcome, SpawnResult, Target, Transport,
|
|
11
|
-
TransportError, WindowName,
|
|
12
|
-
};
|
|
13
|
-
use serde_json::json;
|
|
14
|
-
use std::collections::{BTreeMap, BTreeSet};
|
|
15
|
-
use std::path::{Path, PathBuf};
|
|
16
|
-
use std::sync::Mutex;
|
|
17
|
-
|
|
18
|
-
fn names(raw: &[&str]) -> Vec<SessionName> {
|
|
19
|
-
raw.iter().map(|name| SessionName::new(*name)).collect()
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
fn anchors(raw: &[&str]) -> BTreeSet<String> {
|
|
23
|
-
raw.iter().map(|s| s.to_string()).collect()
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
#[test]
|
|
27
|
-
fn leader_anchors_are_endpoint_scoped_and_unknown_anchors_stay_protected() {
|
|
28
|
-
use crate::cli::lifecycle_port::collect_state_leader_anchor_pane_ids as collect;
|
|
29
|
-
let state = json!({
|
|
30
|
-
"team_owner": {"pane_id": "%2"},
|
|
31
|
-
"leader_receiver": {"pane_id": "%2", "tmux_socket": "/tmp/s4-host.sock"},
|
|
32
|
-
"teams": {
|
|
33
|
-
"local": {
|
|
34
|
-
"team_owner": {"pane_id": "%3", "tmux_socket": "/tmp/s4-worker.sock"},
|
|
35
|
-
"leader_receiver": {"pane_id": "%3"}
|
|
36
|
-
},
|
|
37
|
-
"legacy": {"team_owner": {"pane_id": "%4"}}
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
assert_eq!(collect(&state, Some("/tmp/s4-worker.sock")), anchors(&["%3", "%4"]));
|
|
41
|
-
assert_eq!(collect(&state, Some("/tmp/s4-host.sock")), anchors(&["%2", "%4"]));
|
|
42
|
-
assert_eq!(collect(&state, None), anchors(&["%2", "%3", "%4"]));
|
|
43
|
-
|
|
44
|
-
// An unrelated receiver's socket is not evidence about the owner's pane.
|
|
45
|
-
let different_panes = json!({
|
|
46
|
-
"team_owner": {"pane_id": "%5"},
|
|
47
|
-
"leader_receiver": {"pane_id": "%2", "tmux_socket": "/tmp/s4-host.sock"}
|
|
48
|
-
});
|
|
49
|
-
assert_eq!(collect(&different_panes, Some("/tmp/s4-worker.sock")), anchors(&["%5"]));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
#[test]
|
|
53
|
-
#[cfg(unix)]
|
|
54
|
-
fn leader_anchor_endpoint_aliases_preserve_same_server_protection() {
|
|
55
|
-
use crate::cli::lifecycle_port::collect_state_leader_anchor_pane_ids as collect;
|
|
56
|
-
let ws = tmp_shutdown_workspace("anchor-endpoint-alias");
|
|
57
|
-
let socket = ws.join("server.sock");
|
|
58
|
-
let alias = ws.join("alias.sock");
|
|
59
|
-
std::fs::write(&socket, b"fixture").unwrap();
|
|
60
|
-
std::os::unix::fs::symlink(&socket, &alias).unwrap();
|
|
61
|
-
let state = json!({"leader_receiver": {"pane_id": "%2", "tmux_socket": alias}});
|
|
62
|
-
assert_eq!(collect(&state, socket.to_str()), anchors(&["%2"]));
|
|
63
|
-
let short_name = format!("s4-anchor-{}", std::process::id());
|
|
64
|
-
let full_path = crate::tmux_backend::socket_path_for_name(&short_name).unwrap();
|
|
65
|
-
let state = json!({"leader_receiver": {"pane_id": "%2", "tmux_socket": short_name}});
|
|
66
|
-
assert_eq!(collect(&state, full_path.to_str()), anchors(&["%2"]));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// RC-4: even an apparently exclusive socket uses per-session cleanup.
|
|
70
|
-
#[test]
|
|
71
|
-
fn rc4_exclusive_socket_is_fail_closed() {
|
|
72
|
-
assert_eq!(
|
|
73
|
-
sessions_to_kill(&names(&["team-x", "team-y"]), &BTreeSet::new()),
|
|
74
|
-
KillDecision::KillIndividually {
|
|
75
|
-
to_kill: names(&["team-x", "team-y"]),
|
|
76
|
-
spared: vec![]
|
|
77
|
-
}
|
|
78
|
-
);
|
|
79
|
-
// 空 session 集 → 逐 kill(no-op),不整 server 拆(没东西可拆)。
|
|
80
|
-
assert_eq!(
|
|
81
|
-
sessions_to_kill(&[], &BTreeSet::new()),
|
|
82
|
-
KillDecision::KillIndividually {
|
|
83
|
-
to_kill: vec![],
|
|
84
|
-
spared: vec![]
|
|
85
|
-
}
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// RC-1(本 P0 复现):in_tmux leader 在用户 session(**无前缀**),靠 state 锚 spare → 用户 session 存活。
|
|
90
|
-
#[test]
|
|
91
|
-
fn rc1_in_tmux_no_prefix_anchor_spares_user_session() {
|
|
92
|
-
let sessions = names(&["team-coder-team", "team-x"]); // 用户 session 无 leader 前缀
|
|
93
|
-
let anchor = anchors(&["team-coder-team"]); // state 锚 pane 所在 session
|
|
94
|
-
let decision = sessions_to_kill(&sessions, &anchor);
|
|
95
|
-
match decision {
|
|
96
|
-
KillDecision::KillIndividually { to_kill, spared } => {
|
|
97
|
-
assert_eq!(
|
|
98
|
-
to_kill,
|
|
99
|
-
names(&["team-x"]),
|
|
100
|
-
"only non-anchor session killed"
|
|
101
|
-
);
|
|
102
|
-
assert_eq!(
|
|
103
|
-
spared,
|
|
104
|
-
names(&["team-coder-team"]),
|
|
105
|
-
"user/leader session spared by anchor"
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
other => panic!("anchor session must force per-session kill, not {other:?}"),
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// 前缀判据仍生效(并集):leader 前缀 session spare,即使无 state 锚。
|
|
113
|
-
#[test]
|
|
114
|
-
fn prefix_session_spared_without_anchor() {
|
|
115
|
-
let sessions = names(&["team-agent-leader-claude-ws-deadbeef", "team-x"]);
|
|
116
|
-
let decision = sessions_to_kill(&sessions, &BTreeSet::new());
|
|
117
|
-
match decision {
|
|
118
|
-
KillDecision::KillIndividually { to_kill, spared } => {
|
|
119
|
-
assert_eq!(to_kill, names(&["team-x"]));
|
|
120
|
-
assert_eq!(spared, names(&["team-agent-leader-claude-ws-deadbeef"]));
|
|
121
|
-
}
|
|
122
|
-
other => panic!("prefix session must spare, not {other:?}"),
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// RC-2(state 损坏无锚):anchor_sessions 空 → 退命名前缀判据(此处仅前缀 spare;无前缀则全 kill)。
|
|
127
|
-
// (spare_fallback_to_naming event 在 anchor_anchor_sessions 发,本纯函数只验退化后的决策。)
|
|
128
|
-
#[test]
|
|
129
|
-
fn rc2_no_anchor_falls_back_to_naming() {
|
|
130
|
-
// 无锚 + 有前缀 leader → 前缀 spare。
|
|
131
|
-
let with_leader = sessions_to_kill(
|
|
132
|
-
&names(&["team-agent-leader-codex-ws-cafe", "team-x"]),
|
|
133
|
-
&BTreeSet::new(),
|
|
134
|
-
);
|
|
135
|
-
assert!(matches!(with_leader, KillDecision::KillIndividually { .. }));
|
|
136
|
-
// 无锚 + 无前缀仍只能逐 session 返回,实际 shutdown 会因 marker 缺失拒绝杀灭。
|
|
137
|
-
assert_eq!(
|
|
138
|
-
sessions_to_kill(&names(&["team-x"]), &BTreeSet::new()),
|
|
139
|
-
KillDecision::KillIndividually {
|
|
140
|
-
to_kill: names(&["team-x"]),
|
|
141
|
-
spared: vec![]
|
|
142
|
-
}
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// RC-3(共享 socket):目标 2 session + 用户 1 session(锚)→ 只 kill 目标 2,用户存活,不整 server 拆。
|
|
147
|
-
#[test]
|
|
148
|
-
fn rc3_shared_socket_kills_only_target_sessions() {
|
|
149
|
-
let sessions = names(&["team-a", "team-b", "user-shell"]);
|
|
150
|
-
let anchor = anchors(&["user-shell"]);
|
|
151
|
-
let decision = sessions_to_kill(&sessions, &anchor);
|
|
152
|
-
match decision {
|
|
153
|
-
KillDecision::KillIndividually { to_kill, spared } => {
|
|
154
|
-
assert_eq!(to_kill, names(&["team-a", "team-b"]));
|
|
155
|
-
assert_eq!(spared, names(&["user-shell"]));
|
|
156
|
-
}
|
|
157
|
-
other => panic!("shared socket must not whole-server kill, got {other:?}"),
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// 并集语义:同一 session 既前缀又锚 → spare 一次(不重复)。
|
|
162
|
-
#[test]
|
|
163
|
-
fn union_prefix_and_anchor_no_double_count() {
|
|
164
|
-
let sessions = names(&["team-agent-leader-claude-ws-beef"]);
|
|
165
|
-
let anchor = anchors(&["team-agent-leader-claude-ws-beef"]);
|
|
166
|
-
let decision = sessions_to_kill(&sessions, &anchor);
|
|
167
|
-
assert_eq!(
|
|
168
|
-
decision,
|
|
169
|
-
KillDecision::KillIndividually {
|
|
170
|
-
to_kill: vec![],
|
|
171
|
-
spared: names(&["team-agent-leader-claude-ws-beef"])
|
|
172
|
-
}
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
#[test]
|
|
177
|
-
fn missing_coordinator_is_ok_when_shutdown_cleaned_session() {
|
|
178
|
-
let ws = tmp_shutdown_workspace("missing-coordinator-clean");
|
|
179
|
-
crate::state::persist::save_runtime_state(
|
|
180
|
-
&ws,
|
|
181
|
-
&json!({
|
|
182
|
-
"session_name": "team-lane-l1-clean-shutdown",
|
|
183
|
-
"agents": {
|
|
184
|
-
"fake_impl": {
|
|
185
|
-
"status": "running",
|
|
186
|
-
"provider": "fake",
|
|
187
|
-
"window": "fake_impl"
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}),
|
|
191
|
-
)
|
|
192
|
-
.unwrap();
|
|
193
|
-
let out = crate::cli::lifecycle_port::shutdown_with_transport(
|
|
194
|
-
&ws,
|
|
195
|
-
true,
|
|
196
|
-
None,
|
|
197
|
-
&CleanShutdownTransport::new(),
|
|
198
|
-
)
|
|
199
|
-
.expect("shutdown should complete");
|
|
200
|
-
assert_eq!(out["coordinator"]["status"], json!("missing"));
|
|
201
|
-
assert_eq!(
|
|
202
|
-
out["ok"],
|
|
203
|
-
json!(true),
|
|
204
|
-
"coordinator.status=missing alone must not make a fully cleaned shutdown partial: {out}"
|
|
205
|
-
);
|
|
206
|
-
assert_eq!(out["status"], json!("ok"));
|
|
207
|
-
assert_eq!(out["residuals"]["sessions"], json!([]));
|
|
208
|
-
assert_eq!(out["residuals"]["processes"], json!([]));
|
|
209
|
-
assert_eq!(out["residuals"]["owned_files"], json!([]));
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
#[test]
|
|
213
|
-
fn owned_empty_endpoint_cleanup_removes_socket_file_before_reporting_ok() {
|
|
214
|
-
let ws = tmp_shutdown_workspace("owned-empty-endpoint-clean");
|
|
215
|
-
let socket = ws.join("owned.sock");
|
|
216
|
-
std::fs::write(&socket, b"socket").unwrap();
|
|
217
|
-
crate::state::persist::save_runtime_state(
|
|
218
|
-
&ws,
|
|
219
|
-
&json!({
|
|
220
|
-
"session_name": "team-owned-clean",
|
|
221
|
-
"team_key": "team-owned-clean",
|
|
222
|
-
"generation": "team-owned-clean",
|
|
223
|
-
"tmux_endpoint": socket.to_string_lossy(),
|
|
224
|
-
"tmux_socket": socket.to_string_lossy(),
|
|
225
|
-
"tmux_socket_source": "workspace",
|
|
226
|
-
"is_external_leader": false,
|
|
227
|
-
"agents": {}
|
|
228
|
-
}),
|
|
229
|
-
)
|
|
230
|
-
.unwrap();
|
|
231
|
-
let transport = CleanShutdownTransport::new().with_owned_session(
|
|
232
|
-
&ws,
|
|
233
|
-
"team-owned-clean",
|
|
234
|
-
"team-owned-clean",
|
|
235
|
-
"team-owned-clean",
|
|
236
|
-
);
|
|
237
|
-
|
|
238
|
-
let out = crate::cli::lifecycle_port::shutdown_with_transport(&ws, true, None, &transport)
|
|
239
|
-
.expect("shutdown should complete");
|
|
240
|
-
|
|
241
|
-
assert_eq!(out["ok"], json!(true));
|
|
242
|
-
assert_eq!(out["status"], json!("ok"));
|
|
243
|
-
assert_eq!(out["residuals"]["owned_files"], json!([]));
|
|
244
|
-
assert!(
|
|
245
|
-
socket.exists(),
|
|
246
|
-
"fail-closed endpoint cleanup must preserve the socket file"
|
|
247
|
-
);
|
|
248
|
-
assert!(
|
|
249
|
-
!transport.kill_server_called(),
|
|
250
|
-
"endpoint ownership must not authorize server teardown"
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
#[test]
|
|
255
|
-
fn leader_env_endpoint_is_not_owned_or_removed() {
|
|
256
|
-
let ws = tmp_shutdown_workspace("leader-env-endpoint-spared");
|
|
257
|
-
let socket = ws.join("leader-env.sock");
|
|
258
|
-
std::fs::write(&socket, b"socket").unwrap();
|
|
259
|
-
crate::state::persist::save_runtime_state(
|
|
260
|
-
&ws,
|
|
261
|
-
&json!({
|
|
262
|
-
"session_name": "team-external",
|
|
263
|
-
"tmux_endpoint": socket.to_string_lossy(),
|
|
264
|
-
"tmux_socket": socket.to_string_lossy(),
|
|
265
|
-
"tmux_socket_source": "leader_env",
|
|
266
|
-
"is_external_leader": true,
|
|
267
|
-
"agents": {}
|
|
268
|
-
}),
|
|
269
|
-
)
|
|
270
|
-
.unwrap();
|
|
271
|
-
let transport = CleanShutdownTransport::new();
|
|
272
|
-
|
|
273
|
-
let out = crate::cli::lifecycle_port::shutdown_with_transport(&ws, true, None, &transport)
|
|
274
|
-
.expect("shutdown should complete");
|
|
275
|
-
|
|
276
|
-
assert_eq!(out["ok"], json!(true));
|
|
277
|
-
assert_eq!(out["residuals"]["owned_files"], json!([]));
|
|
278
|
-
assert!(socket.exists(), "leader_env socket is not team-owned");
|
|
279
|
-
assert!(
|
|
280
|
-
!transport.kill_server_called(),
|
|
281
|
-
"leader_env/shared socket must never be torn down by owned cleanup"
|
|
282
|
-
);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
#[test]
|
|
286
|
-
fn owned_file_residual_makes_shutdown_failed_not_partial() {
|
|
287
|
-
let ws = tmp_shutdown_workspace("owned-file-residual-failed");
|
|
288
|
-
let socket_dir = ws.join("owned-dir.sock");
|
|
289
|
-
std::fs::create_dir_all(&socket_dir).unwrap();
|
|
290
|
-
crate::state::persist::save_runtime_state(
|
|
291
|
-
&ws,
|
|
292
|
-
&json!({
|
|
293
|
-
"session_name": "team-owned-residual",
|
|
294
|
-
"team_key": "team-owned-residual",
|
|
295
|
-
"generation": "team-owned-residual",
|
|
296
|
-
"tmux_endpoint": socket_dir.to_string_lossy(),
|
|
297
|
-
"tmux_socket": socket_dir.to_string_lossy(),
|
|
298
|
-
"tmux_socket_source": "workspace",
|
|
299
|
-
"is_external_leader": false,
|
|
300
|
-
"agents": {}
|
|
301
|
-
}),
|
|
302
|
-
)
|
|
303
|
-
.unwrap();
|
|
304
|
-
let transport = CleanShutdownTransport::new().with_owned_session(
|
|
305
|
-
&ws,
|
|
306
|
-
"team-owned-residual",
|
|
307
|
-
"team-owned-residual",
|
|
308
|
-
"team-owned-residual",
|
|
309
|
-
);
|
|
310
|
-
|
|
311
|
-
let out = crate::cli::lifecycle_port::shutdown_with_transport(&ws, true, None, &transport)
|
|
312
|
-
.expect("shutdown should complete");
|
|
313
|
-
|
|
314
|
-
assert_eq!(out["ok"], json!(true));
|
|
315
|
-
assert_eq!(out["status"], json!("ok"));
|
|
316
|
-
assert_eq!(out["phase"], json!(null));
|
|
317
|
-
assert_eq!(out["residuals"]["owned_files"], json!([]));
|
|
318
|
-
assert!(socket_dir.exists(), "fail-closed cleanup preserves residual files");
|
|
319
|
-
assert!(!transport.kill_server_called());
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
#[test]
|
|
323
|
-
fn scoped_shutdown_keeps_owned_endpoint_when_sibling_session_remains() {
|
|
324
|
-
let ws = tmp_shutdown_workspace("scoped-owned-endpoint-sibling");
|
|
325
|
-
let socket = ws.join("owned-shared.sock");
|
|
326
|
-
std::fs::write(&socket, b"socket").unwrap();
|
|
327
|
-
crate::state::persist::save_runtime_state(
|
|
328
|
-
&ws,
|
|
329
|
-
&json!({
|
|
330
|
-
"active_team_key": "team-a",
|
|
331
|
-
"teams": {
|
|
332
|
-
"team-a": {
|
|
333
|
-
"team_key": "team-a",
|
|
334
|
-
"status": "alive",
|
|
335
|
-
"session_name": "team-a",
|
|
336
|
-
"tmux_endpoint": socket.to_string_lossy(),
|
|
337
|
-
"tmux_socket": socket.to_string_lossy(),
|
|
338
|
-
"tmux_socket_source": "workspace",
|
|
339
|
-
"is_external_leader": false,
|
|
340
|
-
"agents": {}
|
|
341
|
-
},
|
|
342
|
-
"team-b": {
|
|
343
|
-
"team_key": "team-b",
|
|
344
|
-
"status": "alive",
|
|
345
|
-
"session_name": "team-b",
|
|
346
|
-
"tmux_endpoint": socket.to_string_lossy(),
|
|
347
|
-
"tmux_socket": socket.to_string_lossy(),
|
|
348
|
-
"tmux_socket_source": "workspace",
|
|
349
|
-
"is_external_leader": false,
|
|
350
|
-
"agents": {}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}),
|
|
354
|
-
)
|
|
355
|
-
.unwrap();
|
|
356
|
-
let transport = CleanShutdownTransport::new()
|
|
357
|
-
.with_targets(vec![PaneInfo {
|
|
358
|
-
pane_id: PaneId::new("%2"),
|
|
359
|
-
session: SessionName::new("team-b"),
|
|
360
|
-
window_index: Some(0),
|
|
361
|
-
window_name: Some(WindowName::new("worker")),
|
|
362
|
-
pane_index: Some(0),
|
|
363
|
-
tty: None,
|
|
364
|
-
current_command: Some("fake".to_string()),
|
|
365
|
-
current_path: None,
|
|
366
|
-
active: true,
|
|
367
|
-
pane_pid: None,
|
|
368
|
-
leader_env: BTreeMap::new(),
|
|
369
|
-
}])
|
|
370
|
-
.with_targets_persist_after_kill();
|
|
371
|
-
|
|
372
|
-
let out =
|
|
373
|
-
crate::cli::lifecycle_port::shutdown_with_transport(&ws, true, Some("team-a"), &transport)
|
|
374
|
-
.expect("shutdown should complete");
|
|
375
|
-
|
|
376
|
-
// 0.4.0 refactor: shutdown now reports `ok=false` when sessions appear as
|
|
377
|
-
// residuals (`status="failed"`). This test uses
|
|
378
|
-
// `with_targets_persist_after_kill()` which leaves the killed session
|
|
379
|
-
// visible to the residual probe, so the new refactor surfaces it as a
|
|
380
|
-
// residual. The actual contract of this test is the SOCKET keep behavior
|
|
381
|
-
// (owned endpoint preserved when sibling sessions live on it), which the
|
|
382
|
-
// assertions below cover. We assert no owned_files residual + socket on
|
|
383
|
-
// disk + no kill_server, which are the invariants this test actually
|
|
384
|
-
// exists to guard.
|
|
385
|
-
assert_eq!(out["residuals"]["owned_files"], json!([]), "full out={out}");
|
|
386
|
-
assert!(
|
|
387
|
-
socket.exists(),
|
|
388
|
-
"owned endpoint stays while sibling team session remains"
|
|
389
|
-
);
|
|
390
|
-
assert!(
|
|
391
|
-
!transport.kill_server_called(),
|
|
392
|
-
"scoped shutdown must not tear down a non-empty shared owned endpoint"
|
|
393
|
-
);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
#[test]
|
|
397
|
-
fn scoped_clean_shutdown_persists_team_shutdown_status_after_disk_roundtrip() {
|
|
398
|
-
let ws = tmp_shutdown_workspace("scoped-clean-status-roundtrip");
|
|
399
|
-
crate::state::persist::save_runtime_state(
|
|
400
|
-
&ws,
|
|
401
|
-
&json!({
|
|
402
|
-
"schema_version": 1,
|
|
403
|
-
"active_team_key": "current",
|
|
404
|
-
"team_key": "current",
|
|
405
|
-
"generation": "current",
|
|
406
|
-
"session_name": "team-current",
|
|
407
|
-
"team_dir": ws.display().to_string(),
|
|
408
|
-
"workspace": ws.display().to_string(),
|
|
409
|
-
"agents": {
|
|
410
|
-
"adminweb": {
|
|
411
|
-
"agent_id": "adminweb",
|
|
412
|
-
"status": "running",
|
|
413
|
-
"provider": "fake",
|
|
414
|
-
"window": "adminweb"
|
|
415
|
-
}
|
|
416
|
-
},
|
|
417
|
-
"teams": {
|
|
418
|
-
"current": {
|
|
419
|
-
"team_key": "current",
|
|
420
|
-
"generation": "current",
|
|
421
|
-
"session_name": "team-current",
|
|
422
|
-
"team_dir": ws.display().to_string(),
|
|
423
|
-
"workspace": ws.display().to_string(),
|
|
424
|
-
"agents": {
|
|
425
|
-
"adminweb": {
|
|
426
|
-
"agent_id": "adminweb",
|
|
427
|
-
"status": "running",
|
|
428
|
-
"provider": "fake",
|
|
429
|
-
"window": "adminweb"
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
}),
|
|
435
|
-
)
|
|
436
|
-
.unwrap();
|
|
437
|
-
|
|
438
|
-
let out = crate::cli::lifecycle_port::shutdown_with_transport(
|
|
439
|
-
&ws,
|
|
440
|
-
true,
|
|
441
|
-
Some("current"),
|
|
442
|
-
&CleanShutdownTransport::new().with_owned_session(
|
|
443
|
-
&ws,
|
|
444
|
-
"team-current",
|
|
445
|
-
"current",
|
|
446
|
-
"current",
|
|
447
|
-
),
|
|
448
|
-
)
|
|
449
|
-
.expect("shutdown should complete");
|
|
450
|
-
|
|
451
|
-
assert_eq!(out["ok"], json!(true), "shutdown report: {out}");
|
|
452
|
-
assert_eq!(out["session_killed"], json!(true), "shutdown report: {out}");
|
|
453
|
-
assert_eq!(
|
|
454
|
-
out["verification_degraded"],
|
|
455
|
-
json!(false),
|
|
456
|
-
"shutdown report: {out}"
|
|
457
|
-
);
|
|
458
|
-
let saved = crate::state::persist::load_runtime_state(&ws).unwrap();
|
|
459
|
-
assert_eq!(
|
|
460
|
-
saved
|
|
461
|
-
.pointer("/teams/current/status")
|
|
462
|
-
.and_then(serde_json::Value::as_str),
|
|
463
|
-
Some("shutdown"),
|
|
464
|
-
"0.5.27 RED: clean scoped shutdown returned session_killed=true and not degraded, \
|
|
465
|
-
so disk state must persist teams.current.status=shutdown. The compact projected \
|
|
466
|
-
save path must not drop the tombstone; saved={saved}"
|
|
467
|
-
);
|
|
468
|
-
assert_eq!(
|
|
469
|
-
saved
|
|
470
|
-
.pointer("/teams/current/agents/adminweb/status")
|
|
471
|
-
.and_then(serde_json::Value::as_str),
|
|
472
|
-
Some("stopped"),
|
|
473
|
-
"0.5.27 RED: clean shutdown must also persist stopped agents under the retained team; saved={saved}"
|
|
474
|
-
);
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
#[test]
|
|
478
|
-
fn scoped_degraded_shutdown_does_not_persist_team_shutdown_status() {
|
|
479
|
-
let ws = tmp_shutdown_workspace("scoped-degraded-no-status");
|
|
480
|
-
crate::state::persist::save_runtime_state(
|
|
481
|
-
&ws,
|
|
482
|
-
&json!({
|
|
483
|
-
"schema_version": 1,
|
|
484
|
-
"active_team_key": "current",
|
|
485
|
-
"team_key": "current",
|
|
486
|
-
"generation": "current",
|
|
487
|
-
"session_name": "team-current",
|
|
488
|
-
"agents": {
|
|
489
|
-
"adminweb": {
|
|
490
|
-
"agent_id": "adminweb",
|
|
491
|
-
"status": "running",
|
|
492
|
-
"provider": "fake",
|
|
493
|
-
"window": "adminweb"
|
|
494
|
-
}
|
|
495
|
-
},
|
|
496
|
-
"teams": {
|
|
497
|
-
"current": {
|
|
498
|
-
"team_key": "current",
|
|
499
|
-
"generation": "current",
|
|
500
|
-
"session_name": "team-current",
|
|
501
|
-
"agents": {
|
|
502
|
-
"adminweb": {
|
|
503
|
-
"agent_id": "adminweb",
|
|
504
|
-
"status": "running",
|
|
505
|
-
"provider": "fake",
|
|
506
|
-
"window": "adminweb"
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
}),
|
|
512
|
-
)
|
|
513
|
-
.unwrap();
|
|
514
|
-
|
|
515
|
-
let out = crate::cli::lifecycle_port::shutdown_with_transport(
|
|
516
|
-
&ws,
|
|
517
|
-
true,
|
|
518
|
-
Some("current"),
|
|
519
|
-
&CleanShutdownTransport::new()
|
|
520
|
-
.with_owned_session(&ws, "team-current", "current", "current")
|
|
521
|
-
.with_probe_timeout("ps_table"),
|
|
522
|
-
)
|
|
523
|
-
.expect("shutdown should complete");
|
|
524
|
-
|
|
525
|
-
assert_eq!(out["session_killed"], json!(true), "shutdown report: {out}");
|
|
526
|
-
assert_eq!(
|
|
527
|
-
out["verification_degraded"],
|
|
528
|
-
json!(true),
|
|
529
|
-
"shutdown report: {out}"
|
|
530
|
-
);
|
|
531
|
-
let saved = crate::state::persist::load_runtime_state(&ws).unwrap();
|
|
532
|
-
assert_ne!(
|
|
533
|
-
saved
|
|
534
|
-
.pointer("/teams/current/status")
|
|
535
|
-
.and_then(serde_json::Value::as_str),
|
|
536
|
-
Some("shutdown"),
|
|
537
|
-
"degraded shutdown must remain dirty/diagnostic and must not stamp \
|
|
538
|
-
teams.current.status=shutdown; saved={saved}"
|
|
539
|
-
);
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
#[test]
|
|
543
|
-
fn repeated_owned_endpoint_shutdowns_leave_no_socket_file_growth() {
|
|
544
|
-
#[cfg(unix)]
|
|
545
|
-
const CHILD: &str = "RB11_F01_NATURAL_PROBE_FAILURE_CHILD";
|
|
546
|
-
#[cfg(unix)]
|
|
547
|
-
const TEST: &str =
|
|
548
|
-
"cli::tests::shutdown_kill_plan::repeated_owned_endpoint_shutdowns_leave_no_socket_file_growth";
|
|
549
|
-
|
|
550
|
-
#[cfg(unix)]
|
|
551
|
-
if std::env::var_os(CHILD).is_none() {
|
|
552
|
-
let path = tmp_shutdown_workspace("rb11-f01-empty-path").join("bin");
|
|
553
|
-
std::fs::create_dir_all(&path).unwrap();
|
|
554
|
-
let output = std::process::Command::new(std::env::current_exe().unwrap())
|
|
555
|
-
.args(["--exact", TEST, "--nocapture", "--test-threads=1"])
|
|
556
|
-
.env(CHILD, "1")
|
|
557
|
-
.env("PATH", path)
|
|
558
|
-
.output()
|
|
559
|
-
.unwrap();
|
|
560
|
-
assert!(
|
|
561
|
-
output.status.success(),
|
|
562
|
-
"directed child failed: status={} stdout={} stderr={}",
|
|
563
|
-
output.status,
|
|
564
|
-
String::from_utf8_lossy(&output.stdout),
|
|
565
|
-
String::from_utf8_lossy(&output.stderr)
|
|
566
|
-
);
|
|
567
|
-
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
568
|
-
assert!(
|
|
569
|
-
stdout.contains("running 1 test")
|
|
570
|
-
&& stdout.contains(&format!("test {TEST} ..."))
|
|
571
|
-
&& stdout.contains("RB11_F01_CHILD_SUCCESS"),
|
|
572
|
-
"directed child omitted success marker: stdout={} stderr={}",
|
|
573
|
-
stdout,
|
|
574
|
-
String::from_utf8_lossy(&output.stderr)
|
|
575
|
-
);
|
|
576
|
-
println!("RB11_F01_DIRECTED_CHILD_OUTPUT\n{stdout}");
|
|
577
|
-
return;
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
#[cfg(unix)]
|
|
581
|
-
let expected_probe_failure = std::env::var_os(CHILD).is_some();
|
|
582
|
-
#[cfg(not(unix))]
|
|
583
|
-
let expected_probe_failure = false;
|
|
584
|
-
let ws = tmp_shutdown_workspace("owned-loop-no-growth");
|
|
585
|
-
let sockets = (0..20)
|
|
586
|
-
.map(|idx| ws.join(format!("owned-loop-{idx}.sock")))
|
|
587
|
-
.collect::<Vec<_>>();
|
|
588
|
-
let starting = sockets.iter().filter(|path| path.exists()).count();
|
|
589
|
-
for (iteration, socket) in sockets.iter().enumerate() {
|
|
590
|
-
std::fs::write(socket, b"socket").unwrap();
|
|
591
|
-
crate::state::persist::save_runtime_state(
|
|
592
|
-
&ws,
|
|
593
|
-
&json!({
|
|
594
|
-
"session_name": "team-owned-loop",
|
|
595
|
-
"team_key": "team-owned-loop",
|
|
596
|
-
"generation": "team-owned-loop",
|
|
597
|
-
"tmux_endpoint": socket.to_string_lossy(),
|
|
598
|
-
"tmux_socket": socket.to_string_lossy(),
|
|
599
|
-
"tmux_socket_source": "workspace",
|
|
600
|
-
"is_external_leader": false,
|
|
601
|
-
"agents": {}
|
|
602
|
-
}),
|
|
603
|
-
)
|
|
604
|
-
.unwrap();
|
|
605
|
-
let before_len = crate::event_log::EventLog::new(&ws)
|
|
606
|
-
.tail(0)
|
|
607
|
-
.expect("read shutdown event boundary")
|
|
608
|
-
.len();
|
|
609
|
-
let result = crate::cli::lifecycle_port::shutdown_with_transport(
|
|
610
|
-
&ws,
|
|
611
|
-
true,
|
|
612
|
-
None,
|
|
613
|
-
&CleanShutdownTransport::new().with_owned_session(
|
|
614
|
-
&ws,
|
|
615
|
-
"team-owned-loop",
|
|
616
|
-
"team-owned-loop",
|
|
617
|
-
"team-owned-loop",
|
|
618
|
-
),
|
|
619
|
-
);
|
|
620
|
-
let out = match &result {
|
|
621
|
-
Ok(out) if !shutdown_result_is_degraded(out) => out,
|
|
622
|
-
Ok(out) if expected_probe_failure => {
|
|
623
|
-
let diagnostic =
|
|
624
|
-
shutdown_invocation_diagnostic(&ws, before_len, iteration, socket, &result);
|
|
625
|
-
assert!(
|
|
626
|
-
shutdown_result_is_degraded(out),
|
|
627
|
-
"directed probe-failure child unexpectedly clean: {diagnostic}"
|
|
628
|
-
);
|
|
629
|
-
assert_eq!(
|
|
630
|
-
out["ok"],
|
|
631
|
-
json!(false),
|
|
632
|
-
"probe failure must remain degraded: {out}"
|
|
633
|
-
);
|
|
634
|
-
if iteration == 0 {
|
|
635
|
-
println!("RB11_F01_FIRST_FAILURE {diagnostic}");
|
|
636
|
-
}
|
|
637
|
-
out
|
|
638
|
-
}
|
|
639
|
-
Ok(out) => {
|
|
640
|
-
let diagnostic =
|
|
641
|
-
shutdown_invocation_diagnostic(&ws, before_len, iteration, socket, &result);
|
|
642
|
-
panic!("unexpected degraded shutdown: {diagnostic}");
|
|
643
|
-
}
|
|
644
|
-
Err(error) => {
|
|
645
|
-
let diagnostic =
|
|
646
|
-
shutdown_invocation_diagnostic(&ws, before_len, iteration, socket, &result);
|
|
647
|
-
panic!("shutdown invocation failed: {error}; {diagnostic}");
|
|
648
|
-
}
|
|
649
|
-
};
|
|
650
|
-
if !expected_probe_failure {
|
|
651
|
-
assert_eq!(out["ok"], json!(true), "shutdown report: {out}");
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
let ending = sockets.iter().filter(|path| path.exists()).count();
|
|
655
|
-
assert_eq!(
|
|
656
|
-
ending,
|
|
657
|
-
starting + sockets.len(),
|
|
658
|
-
"fail-closed endpoint cleanup must not remove unverified socket files"
|
|
659
|
-
);
|
|
660
|
-
#[cfg(unix)]
|
|
661
|
-
if expected_probe_failure {
|
|
662
|
-
println!("RB11_F01_CHILD_SUCCESS iterations={}", sockets.len());
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
fn shutdown_result_is_degraded(out: &serde_json::Value) -> bool {
|
|
667
|
-
out["ok"] != json!(true)
|
|
668
|
-
|| out["probe_degraded"] == json!(true)
|
|
669
|
-
|| out["verification_degraded"] == json!(true)
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
fn shutdown_invocation_diagnostic(
|
|
673
|
-
ws: &Path,
|
|
674
|
-
before_len: usize,
|
|
675
|
-
iteration: usize,
|
|
676
|
-
socket: &Path,
|
|
677
|
-
result: &Result<serde_json::Value, crate::cli::CliError>,
|
|
678
|
-
) -> String {
|
|
679
|
-
let result_summary = match result {
|
|
680
|
-
Ok(out) => format!("report={out}"),
|
|
681
|
-
Err(error) => format!("error={error}"),
|
|
682
|
-
};
|
|
683
|
-
let events = crate::event_log::EventLog::new(ws)
|
|
684
|
-
.tail(0)
|
|
685
|
-
.unwrap_or_else(|error| {
|
|
686
|
-
panic!(
|
|
687
|
-
"shutdown diagnostic event read failed: iteration={iteration} socket={} \
|
|
688
|
-
{result_summary}; error={error}",
|
|
689
|
-
socket.display()
|
|
690
|
-
)
|
|
691
|
-
});
|
|
692
|
-
let appended = events.get(before_len..).unwrap_or_else(|| {
|
|
693
|
-
panic!(
|
|
694
|
-
"shutdown diagnostic boundary invalid: iteration={iteration} socket={} \
|
|
695
|
-
{result_summary}; before_len={before_len} event_len={}",
|
|
696
|
-
socket.display(),
|
|
697
|
-
events.len()
|
|
698
|
-
)
|
|
699
|
-
});
|
|
700
|
-
fn event_name(event: &serde_json::Value) -> Option<&str> {
|
|
701
|
-
event["event"].as_str()
|
|
702
|
-
}
|
|
703
|
-
let starts = appended
|
|
704
|
-
.iter()
|
|
705
|
-
.enumerate()
|
|
706
|
-
.filter(|(_, event)| event_name(event) == Some("lifecycle.shutdown.started"))
|
|
707
|
-
.map(|(index, _)| index)
|
|
708
|
-
.collect::<Vec<_>>();
|
|
709
|
-
let terminals = appended
|
|
710
|
-
.iter()
|
|
711
|
-
.enumerate()
|
|
712
|
-
.filter(|(_, event)| event_name(event) == Some("lifecycle.shutdown"))
|
|
713
|
-
.map(|(index, _)| index)
|
|
714
|
-
.collect::<Vec<_>>();
|
|
715
|
-
if starts.len() != 1 || terminals.len() != 1 || starts[0] >= terminals[0] {
|
|
716
|
-
panic!(
|
|
717
|
-
"shutdown diagnostic markers invalid: iteration={iteration} socket={} \
|
|
718
|
-
{result_summary}; appended={appended:?}",
|
|
719
|
-
socket.display()
|
|
720
|
-
);
|
|
721
|
-
}
|
|
722
|
-
let terminal = &appended[terminals[0]];
|
|
723
|
-
// These diagnostics use deliberately unverified fixture paths, not the
|
|
724
|
-
// computed workspace endpoint. A source label cannot grant ownership.
|
|
725
|
-
let workspace_socket = crate::tmux_backend::socket_name_for_workspace(ws);
|
|
726
|
-
assert_ne!(
|
|
727
|
-
socket.file_name(),
|
|
728
|
-
Some(std::ffi::OsStr::new(&workspace_socket)),
|
|
729
|
-
"diagnostic fixture unexpectedly uses the owned workspace socket"
|
|
730
|
-
);
|
|
731
|
-
if !terminal["owned_endpoint"].is_null() {
|
|
732
|
-
panic!(
|
|
733
|
-
"shutdown diagnostic falsely claimed fixture endpoint ownership: \
|
|
734
|
-
iteration={iteration} socket={} {result_summary}; terminal={terminal}",
|
|
735
|
-
socket.display()
|
|
736
|
-
);
|
|
737
|
-
}
|
|
738
|
-
let bounded = &appended[starts[0]..=terminals[0]];
|
|
739
|
-
let probe_failures = bounded
|
|
740
|
-
.iter()
|
|
741
|
-
.filter(|event| event_name(event) == Some("shutdown.process_probe_failed"))
|
|
742
|
-
.cloned()
|
|
743
|
-
.collect::<Vec<_>>();
|
|
744
|
-
if probe_failures.is_empty() {
|
|
745
|
-
panic!(
|
|
746
|
-
"shutdown diagnostic missing process-probe failure: iteration={iteration} \
|
|
747
|
-
socket={} {result_summary}; bounded={bounded:?}",
|
|
748
|
-
socket.display()
|
|
749
|
-
);
|
|
750
|
-
}
|
|
751
|
-
for event in &probe_failures {
|
|
752
|
-
let phase = event["phase"].as_str();
|
|
753
|
-
if event["probe"].as_str() != Some("ps_table")
|
|
754
|
-
|| !matches!(phase, Some("entry" | "residual_round" | "post_verify"))
|
|
755
|
-
|| !matches!(
|
|
756
|
-
event["error"].as_str(),
|
|
757
|
-
Some(error)
|
|
758
|
-
if !error.trim().is_empty()
|
|
759
|
-
&& !error.contains("exited with status")
|
|
760
|
-
&& (error.contains("No such file") || error.contains("os error 2"))
|
|
761
|
-
)
|
|
762
|
-
{
|
|
763
|
-
panic!(
|
|
764
|
-
"shutdown diagnostic probe failure invalid: iteration={iteration} \
|
|
765
|
-
socket={} {result_summary}; event={event}",
|
|
766
|
-
socket.display()
|
|
767
|
-
);
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
format!(
|
|
771
|
-
"iteration={iteration} socket={} {result_summary}; probe_failures={probe_failures:?}",
|
|
772
|
-
socket.display()
|
|
773
|
-
)
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
#[cfg(unix)]
|
|
777
|
-
#[test]
|
|
778
|
-
fn rb07_probe_failure_diagnostic_is_iteration_bound() {
|
|
779
|
-
const CHILD: &str = "RB07_PROBE_FAILURE_DIAGNOSTIC_CHILD";
|
|
780
|
-
const TEST: &str =
|
|
781
|
-
"cli::tests::shutdown_kill_plan::rb07_probe_failure_diagnostic_is_iteration_bound";
|
|
782
|
-
if std::env::var_os(CHILD).is_none() {
|
|
783
|
-
let path = tmp_shutdown_workspace("rb07-empty-path").join("bin");
|
|
784
|
-
std::fs::create_dir_all(&path).unwrap();
|
|
785
|
-
let output = std::process::Command::new(std::env::current_exe().unwrap())
|
|
786
|
-
.args(["--exact", TEST, "--nocapture"])
|
|
787
|
-
.env(CHILD, "1")
|
|
788
|
-
.env("PATH", path)
|
|
789
|
-
.output()
|
|
790
|
-
.unwrap();
|
|
791
|
-
assert!(
|
|
792
|
-
output.status.success(),
|
|
793
|
-
"directed child failed: status={} stdout={} stderr={}",
|
|
794
|
-
output.status,
|
|
795
|
-
String::from_utf8_lossy(&output.stdout),
|
|
796
|
-
String::from_utf8_lossy(&output.stderr)
|
|
797
|
-
);
|
|
798
|
-
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
799
|
-
assert!(
|
|
800
|
-
stdout.contains("running 1 test")
|
|
801
|
-
&& stdout.contains(&format!("test {TEST} ..."))
|
|
802
|
-
&& stdout.contains("RB07_CHILD_SUCCESS"),
|
|
803
|
-
"directed child omitted success marker: stdout={} stderr={}",
|
|
804
|
-
stdout,
|
|
805
|
-
String::from_utf8_lossy(&output.stderr)
|
|
806
|
-
);
|
|
807
|
-
return;
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
let ws = tmp_shutdown_workspace("rb07-child");
|
|
811
|
-
let socket = ws.join("owned.sock");
|
|
812
|
-
crate::state::persist::save_runtime_state(
|
|
813
|
-
&ws,
|
|
814
|
-
&json!({
|
|
815
|
-
"session_name": "team-rb07-child",
|
|
816
|
-
"tmux_endpoint": socket.to_string_lossy(),
|
|
817
|
-
"tmux_socket": socket.to_string_lossy(),
|
|
818
|
-
"tmux_socket_source": "workspace",
|
|
819
|
-
"is_external_leader": false,
|
|
820
|
-
"agents": {}
|
|
821
|
-
}),
|
|
822
|
-
)
|
|
823
|
-
.unwrap();
|
|
824
|
-
let event_log = crate::event_log::EventLog::new(&ws);
|
|
825
|
-
event_log
|
|
826
|
-
.write(
|
|
827
|
-
"shutdown.process_probe_failed",
|
|
828
|
-
json!({
|
|
829
|
-
"phase": "entry",
|
|
830
|
-
"probe": "ps_table",
|
|
831
|
-
"error": "rb07-stale-decoy"
|
|
832
|
-
}),
|
|
833
|
-
)
|
|
834
|
-
.unwrap();
|
|
835
|
-
let before_len = event_log.tail(0).unwrap().len();
|
|
836
|
-
let result = crate::cli::lifecycle_port::shutdown_with_transport(
|
|
837
|
-
&ws,
|
|
838
|
-
true,
|
|
839
|
-
None,
|
|
840
|
-
&CleanShutdownTransport::new(),
|
|
841
|
-
);
|
|
842
|
-
let diagnostic = shutdown_invocation_diagnostic(&ws, before_len, 0, &socket, &result);
|
|
843
|
-
let failures = match result {
|
|
844
|
-
Ok(out) => {
|
|
845
|
-
assert!(
|
|
846
|
-
shutdown_result_is_degraded(&out),
|
|
847
|
-
"child must force ps failure: {out}"
|
|
848
|
-
);
|
|
849
|
-
let text = diagnostic;
|
|
850
|
-
assert!(
|
|
851
|
-
!text.contains("rb07-stale-decoy"),
|
|
852
|
-
"stale event leaked: {text}"
|
|
853
|
-
);
|
|
854
|
-
text
|
|
855
|
-
}
|
|
856
|
-
Err(error) => panic!("child shutdown unexpectedly returned Err: {error}; {diagnostic}"),
|
|
857
|
-
};
|
|
858
|
-
assert!(
|
|
859
|
-
failures.contains("probe_failures=["),
|
|
860
|
-
"missing bounded failures: {failures}"
|
|
861
|
-
);
|
|
862
|
-
println!("RB07_CHILD_SUCCESS {failures}");
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
fn tmp_shutdown_workspace(tag: &str) -> PathBuf {
|
|
866
|
-
use std::sync::atomic::{AtomicU64, Ordering};
|
|
867
|
-
static N: AtomicU64 = AtomicU64::new(0);
|
|
868
|
-
let dir = std::env::temp_dir().join(format!(
|
|
869
|
-
"ta-shutdown-{tag}-{}-{}",
|
|
870
|
-
std::process::id(),
|
|
871
|
-
N.fetch_add(1, Ordering::Relaxed)
|
|
872
|
-
));
|
|
873
|
-
std::fs::create_dir_all(dir.join(".team").join("runtime")).unwrap();
|
|
874
|
-
dir
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
struct CleanShutdownTransport {
|
|
878
|
-
session_present: Mutex<bool>,
|
|
879
|
-
targets: Vec<PaneInfo>,
|
|
880
|
-
kill_server_called: Mutex<bool>,
|
|
881
|
-
probe_timeout_kind: Option<&'static str>,
|
|
882
|
-
targets_persist_after_kill: bool,
|
|
883
|
-
kill_session_error: Option<String>,
|
|
884
|
-
owner: Option<crate::transport::SessionOwner>,
|
|
885
|
-
// E49 (0.3.24 P0, shutdown kills leader CLI): record per-pane / per-window /
|
|
886
|
-
// per-session kill targets so RED contracts can assert (a) the leader pane is
|
|
887
|
-
// never killed and (b) worker panes ARE killed via the new per-pane path.
|
|
888
|
-
killed_panes: Mutex<Vec<String>>,
|
|
889
|
-
killed_window_targets: Mutex<Vec<String>>,
|
|
890
|
-
killed_sessions: Mutex<Vec<String>>,
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
impl CleanShutdownTransport {
|
|
894
|
-
fn new() -> Self {
|
|
895
|
-
Self {
|
|
896
|
-
session_present: Mutex::new(true),
|
|
897
|
-
targets: Vec::new(),
|
|
898
|
-
kill_server_called: Mutex::new(false),
|
|
899
|
-
probe_timeout_kind: None,
|
|
900
|
-
targets_persist_after_kill: false,
|
|
901
|
-
kill_session_error: None,
|
|
902
|
-
owner: None,
|
|
903
|
-
killed_panes: Mutex::new(Vec::new()),
|
|
904
|
-
killed_window_targets: Mutex::new(Vec::new()),
|
|
905
|
-
killed_sessions: Mutex::new(Vec::new()),
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
|
|
909
|
-
fn with_targets(mut self, targets: Vec<PaneInfo>) -> Self {
|
|
910
|
-
self.targets = targets;
|
|
911
|
-
self
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
fn with_owned_session(
|
|
915
|
-
mut self,
|
|
916
|
-
workspace: &Path,
|
|
917
|
-
session: &str,
|
|
918
|
-
team: &str,
|
|
919
|
-
generation: &str,
|
|
920
|
-
) -> Self {
|
|
921
|
-
self.owner = Some(crate::transport::SessionOwner {
|
|
922
|
-
workspace: workspace
|
|
923
|
-
.canonicalize()
|
|
924
|
-
.unwrap_or_else(|_| workspace.to_path_buf())
|
|
925
|
-
.to_string_lossy()
|
|
926
|
-
.into_owned(),
|
|
927
|
-
team: team.to_string(),
|
|
928
|
-
generation: generation.to_string(),
|
|
929
|
-
});
|
|
930
|
-
if self.targets.is_empty() {
|
|
931
|
-
self.targets.push(PaneInfo {
|
|
932
|
-
pane_id: PaneId::new("%owned"),
|
|
933
|
-
session: SessionName::new(session),
|
|
934
|
-
window_index: Some(0),
|
|
935
|
-
window_name: Some(WindowName::new("owned")),
|
|
936
|
-
pane_index: Some(0),
|
|
937
|
-
tty: None,
|
|
938
|
-
current_command: Some("codex".to_string()),
|
|
939
|
-
current_path: Some(workspace.to_path_buf()),
|
|
940
|
-
active: true,
|
|
941
|
-
pane_pid: None,
|
|
942
|
-
leader_env: BTreeMap::new(),
|
|
943
|
-
});
|
|
944
|
-
} else {
|
|
945
|
-
for target in &mut self.targets {
|
|
946
|
-
if target.current_path.is_none() {
|
|
947
|
-
target.current_path = Some(workspace.to_path_buf());
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
self
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
fn kill_server_called(&self) -> bool {
|
|
955
|
-
*self.kill_server_called.lock().unwrap()
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
fn with_probe_timeout(mut self, probe: &'static str) -> Self {
|
|
959
|
-
self.probe_timeout_kind = Some(probe);
|
|
960
|
-
self
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
fn with_targets_persist_after_kill(mut self) -> Self {
|
|
964
|
-
self.targets_persist_after_kill = true;
|
|
965
|
-
self
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
fn with_kill_session_error(mut self, detail: impl Into<String>) -> Self {
|
|
969
|
-
self.kill_session_error = Some(detail.into());
|
|
970
|
-
self
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
/// E49 (0.3.24 P0): observed per-pane kill targets, in call order.
|
|
974
|
-
fn killed_panes(&self) -> Vec<String> {
|
|
975
|
-
self.killed_panes.lock().unwrap().clone()
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
/// E49 (0.3.24 P0): observed per-window kill targets (target stringified).
|
|
979
|
-
fn killed_window_targets(&self) -> Vec<String> {
|
|
980
|
-
self.killed_window_targets.lock().unwrap().clone()
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
/// E49 (0.3.24 P0): observed per-session kill targets, in call order.
|
|
984
|
-
fn killed_sessions_observed(&self) -> Vec<String> {
|
|
985
|
-
self.killed_sessions.lock().unwrap().clone()
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
impl Transport for CleanShutdownTransport {
|
|
990
|
-
fn kind(&self) -> BackendKind {
|
|
991
|
-
BackendKind::Tmux
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
fn spawn_first(
|
|
995
|
-
&self,
|
|
996
|
-
_session: &SessionName,
|
|
997
|
-
_window: &WindowName,
|
|
998
|
-
_argv: &[String],
|
|
999
|
-
_cwd: &Path,
|
|
1000
|
-
_env: &BTreeMap<String, String>,
|
|
1001
|
-
) -> Result<SpawnResult, TransportError> {
|
|
1002
|
-
unimplemented!("shutdown test does not spawn")
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
fn spawn_into(
|
|
1006
|
-
&self,
|
|
1007
|
-
_session: &SessionName,
|
|
1008
|
-
_window: &WindowName,
|
|
1009
|
-
_argv: &[String],
|
|
1010
|
-
_cwd: &Path,
|
|
1011
|
-
_env: &BTreeMap<String, String>,
|
|
1012
|
-
) -> Result<SpawnResult, TransportError> {
|
|
1013
|
-
unimplemented!("shutdown test does not spawn")
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
fn inject(
|
|
1017
|
-
&self,
|
|
1018
|
-
_target: &Target,
|
|
1019
|
-
_payload: &InjectPayload,
|
|
1020
|
-
_submit: Key,
|
|
1021
|
-
_bracketed: bool,
|
|
1022
|
-
) -> Result<InjectReport, TransportError> {
|
|
1023
|
-
unimplemented!("shutdown test does not inject")
|
|
1024
|
-
}
|
|
1025
|
-
|
|
1026
|
-
fn send_keys(&self, _target: &Target, _keys: &[Key]) -> Result<(), TransportError> {
|
|
1027
|
-
Ok(())
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
fn capture(
|
|
1031
|
-
&self,
|
|
1032
|
-
_target: &Target,
|
|
1033
|
-
range: CaptureRange,
|
|
1034
|
-
) -> Result<CapturedText, TransportError> {
|
|
1035
|
-
Ok(CapturedText {
|
|
1036
|
-
text: String::new(),
|
|
1037
|
-
range,
|
|
1038
|
-
})
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
fn query(&self, _target: &Target, _field: PaneField) -> Result<Option<String>, TransportError> {
|
|
1042
|
-
Ok(None)
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1045
|
-
fn liveness(
|
|
1046
|
-
&self,
|
|
1047
|
-
_pane: &PaneId,
|
|
1048
|
-
) -> Result<crate::model::enums::PaneLiveness, TransportError> {
|
|
1049
|
-
Ok(crate::model::enums::PaneLiveness::Live)
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
|
-
fn list_targets(&self) -> Result<Vec<PaneInfo>, TransportError> {
|
|
1053
|
-
if *self.session_present.lock().unwrap() || self.targets_persist_after_kill {
|
|
1054
|
-
Ok(self.targets.clone())
|
|
1055
|
-
} else {
|
|
1056
|
-
Ok(Vec::new())
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
fn has_session(&self, _session: &SessionName) -> Result<bool, TransportError> {
|
|
1061
|
-
Ok(*self.session_present.lock().unwrap())
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
fn session_owner(
|
|
1065
|
-
&self,
|
|
1066
|
-
_session: &SessionName,
|
|
1067
|
-
) -> Result<Option<crate::transport::SessionOwner>, TransportError> {
|
|
1068
|
-
Ok(self.owner.clone())
|
|
1069
|
-
}
|
|
1070
|
-
|
|
1071
|
-
fn list_windows(&self, _session: &SessionName) -> Result<Vec<WindowName>, TransportError> {
|
|
1072
|
-
Ok(Vec::new())
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
|
-
fn set_session_env(
|
|
1076
|
-
&self,
|
|
1077
|
-
_session: &SessionName,
|
|
1078
|
-
_key: &str,
|
|
1079
|
-
_value: &str,
|
|
1080
|
-
) -> Result<SetEnvOutcome, TransportError> {
|
|
1081
|
-
Ok(SetEnvOutcome::Applied)
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
fn kill_session(&self, session: &SessionName) -> Result<(), TransportError> {
|
|
1085
|
-
if let Some(probe) = self.probe_timeout_kind {
|
|
1086
|
-
crate::os_probe::set_probe_timeout_for_test(probe, None, 900);
|
|
1087
|
-
}
|
|
1088
|
-
self.killed_sessions
|
|
1089
|
-
.lock()
|
|
1090
|
-
.unwrap()
|
|
1091
|
-
.push(session.as_str().to_string());
|
|
1092
|
-
*self.session_present.lock().unwrap() = false;
|
|
1093
|
-
match self.kill_session_error.as_deref() {
|
|
1094
|
-
Some(detail) => Err(TransportError::Subprocess {
|
|
1095
|
-
argv: vec![
|
|
1096
|
-
"tmux".to_string(),
|
|
1097
|
-
"kill-session".to_string(),
|
|
1098
|
-
"-t".to_string(),
|
|
1099
|
-
session.as_str().to_string(),
|
|
1100
|
-
],
|
|
1101
|
-
code: Some(1),
|
|
1102
|
-
stderr: detail.to_string(),
|
|
1103
|
-
}),
|
|
1104
|
-
None => Ok(()),
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
fn kill_server(&self) -> Result<(), TransportError> {
|
|
1109
|
-
*self.kill_server_called.lock().unwrap() = true;
|
|
1110
|
-
Ok(())
|
|
1111
|
-
}
|
|
1112
|
-
|
|
1113
|
-
fn kill_window(&self, target: &Target) -> Result<(), TransportError> {
|
|
1114
|
-
self.killed_window_targets
|
|
1115
|
-
.lock()
|
|
1116
|
-
.unwrap()
|
|
1117
|
-
.push(format!("{target:?}"));
|
|
1118
|
-
Ok(())
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
fn kill_pane(&self, pane: &PaneId) -> Result<(), TransportError> {
|
|
1122
|
-
self.killed_panes
|
|
1123
|
-
.lock()
|
|
1124
|
-
.unwrap()
|
|
1125
|
-
.push(pane.as_str().to_string());
|
|
1126
|
-
Ok(())
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
fn attach_session(&self, _session: &SessionName) -> Result<AttachOutcome, TransportError> {
|
|
1130
|
-
Ok(AttachOutcome::Attached)
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
#[test]
|
|
1135
|
-
fn lsof_cwd_timeout_is_diagnostic_not_shutdown_partial() {
|
|
1136
|
-
let ws = tmp_shutdown_workspace("lsof-cwd-timeout-diagnostic");
|
|
1137
|
-
crate::state::persist::save_runtime_state(
|
|
1138
|
-
&ws,
|
|
1139
|
-
&json!({
|
|
1140
|
-
"session_name": "team-lsof-cwd-timeout",
|
|
1141
|
-
"team_key": "team-lsof-cwd-timeout",
|
|
1142
|
-
"generation": "team-lsof-cwd-timeout",
|
|
1143
|
-
"is_external_leader": true,
|
|
1144
|
-
"agents": {
|
|
1145
|
-
"fake_impl": {
|
|
1146
|
-
"status": "running",
|
|
1147
|
-
"provider": "fake",
|
|
1148
|
-
"window": "fake_impl"
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
}),
|
|
1152
|
-
)
|
|
1153
|
-
.unwrap();
|
|
1154
|
-
|
|
1155
|
-
let out = crate::cli::lifecycle_port::shutdown_with_transport(
|
|
1156
|
-
&ws,
|
|
1157
|
-
true,
|
|
1158
|
-
None,
|
|
1159
|
-
&CleanShutdownTransport::new()
|
|
1160
|
-
.with_owned_session(
|
|
1161
|
-
&ws,
|
|
1162
|
-
"team-lsof-cwd-timeout",
|
|
1163
|
-
"team-lsof-cwd-timeout",
|
|
1164
|
-
"team-lsof-cwd-timeout",
|
|
1165
|
-
)
|
|
1166
|
-
.with_probe_timeout("lsof_cwd"),
|
|
1167
|
-
)
|
|
1168
|
-
.expect("shutdown should complete");
|
|
1169
|
-
|
|
1170
|
-
assert_eq!(out["ok"], json!(true));
|
|
1171
|
-
assert_eq!(out["status"], json!("ok"));
|
|
1172
|
-
assert_eq!(out["phase"], json!(null));
|
|
1173
|
-
assert_eq!(out["verification_degraded"], json!(true));
|
|
1174
|
-
assert_eq!(out["probe_timeout_kind"], json!("lsof_cwd"));
|
|
1175
|
-
assert_eq!(out["residuals"]["sessions"], json!([]));
|
|
1176
|
-
assert_eq!(out["residuals"]["processes"], json!([]));
|
|
1177
|
-
|
|
1178
|
-
let events = crate::event_log::EventLog::new(&ws)
|
|
1179
|
-
.tail(0)
|
|
1180
|
-
.expect("events");
|
|
1181
|
-
let shutdown = events
|
|
1182
|
-
.iter()
|
|
1183
|
-
.find(|event| {
|
|
1184
|
-
event.get("event").and_then(serde_json::Value::as_str) == Some("lifecycle.shutdown")
|
|
1185
|
-
})
|
|
1186
|
-
.unwrap_or_else(|| panic!("missing lifecycle.shutdown event: {events:?}"));
|
|
1187
|
-
assert_eq!(shutdown["status"], json!("ok"));
|
|
1188
|
-
assert_eq!(shutdown["phase"], json!(null));
|
|
1189
|
-
assert_eq!(shutdown["verification_degraded"], json!(true));
|
|
1190
|
-
assert_eq!(shutdown["probe_timeout_kind"], json!("lsof_cwd"));
|
|
1191
|
-
}
|
|
1192
|
-
|
|
1193
|
-
#[test]
|
|
1194
|
-
fn ps_table_timeout_still_degrades_shutdown_truth() {
|
|
1195
|
-
let ws = tmp_shutdown_workspace("ps-table-timeout-partial");
|
|
1196
|
-
crate::state::persist::save_runtime_state(
|
|
1197
|
-
&ws,
|
|
1198
|
-
&json!({
|
|
1199
|
-
"session_name": "team-ps-table-timeout",
|
|
1200
|
-
"team_key": "team-ps-table-timeout",
|
|
1201
|
-
"generation": "team-ps-table-timeout",
|
|
1202
|
-
"agents": {
|
|
1203
|
-
"fake_impl": {
|
|
1204
|
-
"status": "running",
|
|
1205
|
-
"provider": "fake",
|
|
1206
|
-
"window": "fake_impl"
|
|
1207
|
-
}
|
|
1208
|
-
}
|
|
1209
|
-
}),
|
|
1210
|
-
)
|
|
1211
|
-
.unwrap();
|
|
1212
|
-
|
|
1213
|
-
let out = crate::cli::lifecycle_port::shutdown_with_transport(
|
|
1214
|
-
&ws,
|
|
1215
|
-
true,
|
|
1216
|
-
None,
|
|
1217
|
-
&CleanShutdownTransport::new()
|
|
1218
|
-
.with_owned_session(
|
|
1219
|
-
&ws,
|
|
1220
|
-
"team-ps-table-timeout",
|
|
1221
|
-
"team-ps-table-timeout",
|
|
1222
|
-
"team-ps-table-timeout",
|
|
1223
|
-
)
|
|
1224
|
-
.with_probe_timeout("ps_table"),
|
|
1225
|
-
)
|
|
1226
|
-
.expect("shutdown should complete");
|
|
1227
|
-
|
|
1228
|
-
assert_eq!(out["ok"], json!(false));
|
|
1229
|
-
assert_eq!(out["status"], json!("partial"));
|
|
1230
|
-
assert_eq!(out["phase"], json!("os_probe"));
|
|
1231
|
-
assert_eq!(out["verification_degraded"], json!(true));
|
|
1232
|
-
assert_eq!(out["probe_timeout_kind"], json!("ps_table"));
|
|
1233
|
-
}
|
|
1234
|
-
|
|
1235
|
-
#[test]
|
|
1236
|
-
fn bounded_coordinator_stop_returns_grace_window_late_success() {
|
|
1237
|
-
let ws = tmp_shutdown_workspace("late-coordinator-stop-success");
|
|
1238
|
-
let report = crate::cli::lifecycle_port::stop_coordinator_bounded_with(
|
|
1239
|
-
crate::coordinator::WorkspacePath::new(ws),
|
|
1240
|
-
std::time::Duration::from_millis(5),
|
|
1241
|
-
|_workspace| {
|
|
1242
|
-
std::thread::sleep(std::time::Duration::from_millis(25));
|
|
1243
|
-
Ok(crate::coordinator::StopReport {
|
|
1244
|
-
ok: true,
|
|
1245
|
-
status: crate::coordinator::StopOutcome::Stopped,
|
|
1246
|
-
pid: Some(crate::coordinator::Pid::new(12345)),
|
|
1247
|
-
})
|
|
1248
|
-
},
|
|
1249
|
-
)
|
|
1250
|
-
.expect("late result inside grace window must be returned")
|
|
1251
|
-
.expect("stop result should be ok");
|
|
1252
|
-
|
|
1253
|
-
assert!(report.ok, "late success must not be discarded as timeout");
|
|
1254
|
-
assert_eq!(report.status, crate::coordinator::StopOutcome::Stopped);
|
|
1255
|
-
}
|
|
1256
|
-
|
|
1257
|
-
#[test]
|
|
1258
|
-
fn bounded_coordinator_stop_retains_completion_beyond_old_1150ms_cap() {
|
|
1259
|
-
let ws = tmp_shutdown_workspace("coordinator-stop-after-old-cap");
|
|
1260
|
-
let cleanup = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
|
|
1261
|
-
let worker_cleanup = cleanup.clone();
|
|
1262
|
-
let report = crate::cli::lifecycle_port::stop_coordinator_bounded_with(
|
|
1263
|
-
crate::coordinator::WorkspacePath::new(ws),
|
|
1264
|
-
std::time::Duration::from_secs(20),
|
|
1265
|
-
move |_workspace| {
|
|
1266
|
-
std::thread::sleep(std::time::Duration::from_millis(1300));
|
|
1267
|
-
worker_cleanup.store(true, std::sync::atomic::Ordering::SeqCst);
|
|
1268
|
-
Ok(crate::coordinator::StopReport {
|
|
1269
|
-
ok: true,
|
|
1270
|
-
status: crate::coordinator::StopOutcome::Stopped,
|
|
1271
|
-
pid: Some(crate::coordinator::Pid::new(12345)),
|
|
1272
|
-
})
|
|
1273
|
-
},
|
|
1274
|
-
)
|
|
1275
|
-
.expect("completion inside the shutdown budget must not be abandoned")
|
|
1276
|
-
.expect("owned stop completed successfully");
|
|
1277
|
-
|
|
1278
|
-
assert!(cleanup.load(std::sync::atomic::Ordering::SeqCst));
|
|
1279
|
-
assert!(report.ok);
|
|
1280
|
-
assert_eq!(report.status, crate::coordinator::StopOutcome::Stopped);
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
#[test]
|
|
1284
|
-
fn bounded_coordinator_stop_does_not_claim_completion_after_budget_exhaustion() {
|
|
1285
|
-
let ws = tmp_shutdown_workspace("coordinator-stop-real-timeout");
|
|
1286
|
-
let (release_tx, release_rx) = std::sync::mpsc::channel();
|
|
1287
|
-
let (completed_tx, completed_rx) = std::sync::mpsc::channel();
|
|
1288
|
-
let report = crate::cli::lifecycle_port::stop_coordinator_bounded_with(
|
|
1289
|
-
crate::coordinator::WorkspacePath::new(ws),
|
|
1290
|
-
std::time::Duration::from_millis(1),
|
|
1291
|
-
move |_workspace| {
|
|
1292
|
-
release_rx.recv().unwrap();
|
|
1293
|
-
completed_tx.send(()).unwrap();
|
|
1294
|
-
Ok(crate::coordinator::StopReport {
|
|
1295
|
-
ok: true,
|
|
1296
|
-
status: crate::coordinator::StopOutcome::Stopped,
|
|
1297
|
-
pid: Some(crate::coordinator::Pid::new(12345)),
|
|
1298
|
-
})
|
|
1299
|
-
},
|
|
1300
|
-
);
|
|
1301
|
-
|
|
1302
|
-
assert!(report.is_none(), "an unfinished stop must remain unknown");
|
|
1303
|
-
assert!(matches!(
|
|
1304
|
-
completed_rx.try_recv(),
|
|
1305
|
-
Err(std::sync::mpsc::TryRecvError::Empty)
|
|
1306
|
-
));
|
|
1307
|
-
release_tx.send(()).unwrap();
|
|
1308
|
-
completed_rx
|
|
1309
|
-
.recv_timeout(std::time::Duration::from_secs(5))
|
|
1310
|
-
.expect("release the controlled worker without leaving a blocked thread");
|
|
1311
|
-
}
|
|
1312
|
-
|
|
1313
|
-
#[test]
|
|
1314
|
-
fn shutdown_outcome_late_or_postcheck_gone_is_ok_with_lsof_diagnostic() {
|
|
1315
|
-
let out = crate::cli::lifecycle_port::classify_shutdown_outcome(
|
|
1316
|
-
crate::cli::lifecycle_port::ShutdownOutcomeInput {
|
|
1317
|
-
kill_error: false,
|
|
1318
|
-
session_residuals: false,
|
|
1319
|
-
process_residuals: false,
|
|
1320
|
-
owned_file_residuals: false,
|
|
1321
|
-
cleanup_truth_degraded: false,
|
|
1322
|
-
coordinator_timeout: true,
|
|
1323
|
-
coordinator_stop_ok: None,
|
|
1324
|
-
coordinator_post_stop: crate::cli::lifecycle_port::CoordinatorStopObservation::Gone,
|
|
1325
|
-
target_session_spared: false,
|
|
1326
|
-
},
|
|
1327
|
-
);
|
|
1328
|
-
|
|
1329
|
-
assert!(out.ok);
|
|
1330
|
-
assert_eq!(out.status, "ok");
|
|
1331
|
-
assert_eq!(out.phase, None);
|
|
1332
|
-
}
|
|
1333
|
-
|
|
1334
|
-
#[test]
|
|
1335
|
-
fn shutdown_outcome_coordinator_timeout_still_running_is_timeout() {
|
|
1336
|
-
let out = crate::cli::lifecycle_port::classify_shutdown_outcome(
|
|
1337
|
-
crate::cli::lifecycle_port::ShutdownOutcomeInput {
|
|
1338
|
-
kill_error: false,
|
|
1339
|
-
session_residuals: false,
|
|
1340
|
-
process_residuals: false,
|
|
1341
|
-
owned_file_residuals: false,
|
|
1342
|
-
cleanup_truth_degraded: false,
|
|
1343
|
-
coordinator_timeout: true,
|
|
1344
|
-
coordinator_stop_ok: None,
|
|
1345
|
-
coordinator_post_stop: crate::cli::lifecycle_port::CoordinatorStopObservation::Running,
|
|
1346
|
-
target_session_spared: false,
|
|
1347
|
-
},
|
|
1348
|
-
);
|
|
1349
|
-
|
|
1350
|
-
assert!(!out.ok);
|
|
1351
|
-
assert_eq!(out.status, "timeout");
|
|
1352
|
-
assert_eq!(out.phase, Some("stop_coordinator"));
|
|
1353
|
-
}
|
|
1354
|
-
|
|
1355
|
-
#[test]
|
|
1356
|
-
fn shutdown_outcome_ps_table_degraded_still_partial_after_coordinator_gone() {
|
|
1357
|
-
let out = crate::cli::lifecycle_port::classify_shutdown_outcome(
|
|
1358
|
-
crate::cli::lifecycle_port::ShutdownOutcomeInput {
|
|
1359
|
-
kill_error: false,
|
|
1360
|
-
session_residuals: false,
|
|
1361
|
-
process_residuals: false,
|
|
1362
|
-
owned_file_residuals: false,
|
|
1363
|
-
cleanup_truth_degraded: true,
|
|
1364
|
-
coordinator_timeout: true,
|
|
1365
|
-
coordinator_stop_ok: None,
|
|
1366
|
-
coordinator_post_stop: crate::cli::lifecycle_port::CoordinatorStopObservation::Gone,
|
|
1367
|
-
target_session_spared: false,
|
|
1368
|
-
},
|
|
1369
|
-
);
|
|
1370
|
-
|
|
1371
|
-
assert!(!out.ok);
|
|
1372
|
-
assert_eq!(out.status, "partial");
|
|
1373
|
-
assert_eq!(out.phase, Some("os_probe"));
|
|
1374
|
-
}
|
|
1375
|
-
|
|
1376
|
-
#[test]
|
|
1377
|
-
fn leader_env_tmux_socket_never_kills_server_even_when_sessions_look_exclusive() {
|
|
1378
|
-
let ws = tmp_shutdown_workspace("leader-env-socket-no-kill-server");
|
|
1379
|
-
crate::state::persist::save_runtime_state(
|
|
1380
|
-
&ws,
|
|
1381
|
-
&json!({
|
|
1382
|
-
"is_external_leader": true,
|
|
1383
|
-
"team_key": "team-layout",
|
|
1384
|
-
"generation": "team-layout",
|
|
1385
|
-
"session_name": "team-layout",
|
|
1386
|
-
"tmux_socket_source": "leader_env",
|
|
1387
|
-
"agents": {
|
|
1388
|
-
"fake_impl": {
|
|
1389
|
-
"status": "running",
|
|
1390
|
-
"provider": "fake",
|
|
1391
|
-
"window": "fake_impl"
|
|
1392
|
-
}
|
|
1393
|
-
}
|
|
1394
|
-
}),
|
|
1395
|
-
)
|
|
1396
|
-
.unwrap();
|
|
1397
|
-
let transport = CleanShutdownTransport::new().with_targets(vec![PaneInfo {
|
|
1398
|
-
pane_id: PaneId::new("%1"),
|
|
1399
|
-
session: SessionName::new("team-layout"),
|
|
1400
|
-
window_index: Some(0),
|
|
1401
|
-
window_name: Some(WindowName::new("team-w1")),
|
|
1402
|
-
pane_index: Some(0),
|
|
1403
|
-
tty: None,
|
|
1404
|
-
current_command: None,
|
|
1405
|
-
current_path: None,
|
|
1406
|
-
active: true,
|
|
1407
|
-
pane_pid: None,
|
|
1408
|
-
leader_env: BTreeMap::new(),
|
|
1409
|
-
}]);
|
|
1410
|
-
let transport = transport.with_owned_session(&ws, "team-layout", "team-layout", "team-layout");
|
|
1411
|
-
|
|
1412
|
-
let out = crate::cli::lifecycle_port::shutdown_with_transport(&ws, true, None, &transport)
|
|
1413
|
-
.expect("shutdown should complete");
|
|
1414
|
-
|
|
1415
|
-
assert_eq!(out["ok"], json!(true));
|
|
1416
|
-
assert_eq!(out["killed_sessions"], json!(["team-layout"]));
|
|
1417
|
-
assert_eq!(out["spared_sessions"], json!([]));
|
|
1418
|
-
assert!(
|
|
1419
|
-
!transport.kill_server_called(),
|
|
1420
|
-
"leader-env/shared socket shutdown must kill sessions individually, never kill-server"
|
|
1421
|
-
);
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
|
-
/// E49 (0.3.24 P0, shutdown kills leader CLI): managed-leader topology with
|
|
1425
|
-
/// leader anchor pane + worker panes in the SAME tmux session.
|
|
1426
|
-
///
|
|
1427
|
-
/// Pre-fix (cli/mod.rs:629-638): `transport.kill_session(state.session_name)`
|
|
1428
|
-
/// killed the session unconditionally — including the leader's own pane.
|
|
1429
|
-
/// User truth: "执行命令绝不能关掉启动自己的那个 leader CLI". macmini repro:
|
|
1430
|
-
/// run `team-agent quick-start ...`, then `team-agent shutdown` from the
|
|
1431
|
-
/// same terminal → leader CLI dies.
|
|
1432
|
-
///
|
|
1433
|
-
/// Architect-approved fix:
|
|
1434
|
-
/// * pre :629 guard: when state is managed (NOT external leader) and the
|
|
1435
|
-
/// leader_receiver / team_owner anchor pane is in `state.session_name`,
|
|
1436
|
-
/// do NOT call kill_session(state.session_name). Instead kill workers
|
|
1437
|
-
/// per-pane via `kill_pane`, deriving pane_ids from state.agents +
|
|
1438
|
-
/// teams[*].agents and EXCLUDING the leader anchor pane ids
|
|
1439
|
-
/// (`collect_state_leader_anchor_pane_ids`).
|
|
1440
|
-
/// * cli/mod.rs:384-435 managed_leader_socket_cleanup: spare any session
|
|
1441
|
-
/// carrying a leader anchor; never kill_session it.
|
|
1442
|
-
///
|
|
1443
|
-
/// Pre-fix test asserted `killed_sessions=["team-current"]` — that was
|
|
1444
|
-
/// LOCKING THE BUG (the architect explicitly named it). Post-fix:
|
|
1445
|
-
/// * spared_sessions contains "team-current"
|
|
1446
|
-
/// * killed_sessions does NOT contain "team-current"
|
|
1447
|
-
/// * killed_panes contains worker panes %w1, %w2
|
|
1448
|
-
/// * killed_panes does NOT contain %leader
|
|
1449
|
-
/// * no kill_server call
|
|
1450
|
-
#[test]
|
|
1451
|
-
fn e49_managed_leader_shutdown_spares_leader_session_and_kills_workers_per_pane() {
|
|
1452
|
-
let ws = tmp_shutdown_workspace("e49-managed-leader-spares-session");
|
|
1453
|
-
crate::state::persist::save_runtime_state(
|
|
1454
|
-
&ws,
|
|
1455
|
-
&json!({
|
|
1456
|
-
"session_name": "team-current",
|
|
1457
|
-
"team_key": "current",
|
|
1458
|
-
"generation": "current",
|
|
1459
|
-
"is_external_leader": false,
|
|
1460
|
-
"leader_receiver": {"pane_id": "%leader"},
|
|
1461
|
-
"team_owner": {"pane_id": "%leader"},
|
|
1462
|
-
"agents": {
|
|
1463
|
-
"w1": {"status": "running", "provider": "codex", "window": "w1", "pane_id": "%w1"},
|
|
1464
|
-
"w2": {"status": "running", "provider": "codex", "window": "w2", "pane_id": "%w2"}
|
|
1465
|
-
}
|
|
1466
|
-
}),
|
|
1467
|
-
)
|
|
1468
|
-
.unwrap();
|
|
1469
|
-
let transport = CleanShutdownTransport::new()
|
|
1470
|
-
.with_targets(vec![
|
|
1471
|
-
// Leader anchor pane
|
|
1472
|
-
PaneInfo {
|
|
1473
|
-
pane_id: PaneId::new("%leader"),
|
|
1474
|
-
session: SessionName::new("team-current"),
|
|
1475
|
-
window_index: Some(0),
|
|
1476
|
-
window_name: Some(WindowName::new("leader")),
|
|
1477
|
-
pane_index: Some(0),
|
|
1478
|
-
tty: None,
|
|
1479
|
-
current_command: Some("codex".to_string()),
|
|
1480
|
-
current_path: None,
|
|
1481
|
-
active: true,
|
|
1482
|
-
pane_pid: None,
|
|
1483
|
-
leader_env: BTreeMap::new(),
|
|
1484
|
-
},
|
|
1485
|
-
// Worker pane 1
|
|
1486
|
-
PaneInfo {
|
|
1487
|
-
pane_id: PaneId::new("%w1"),
|
|
1488
|
-
session: SessionName::new("team-current"),
|
|
1489
|
-
window_index: Some(1),
|
|
1490
|
-
window_name: Some(WindowName::new("w1")),
|
|
1491
|
-
pane_index: Some(0),
|
|
1492
|
-
tty: None,
|
|
1493
|
-
current_command: Some("codex".to_string()),
|
|
1494
|
-
current_path: None,
|
|
1495
|
-
active: false,
|
|
1496
|
-
pane_pid: None,
|
|
1497
|
-
leader_env: BTreeMap::new(),
|
|
1498
|
-
},
|
|
1499
|
-
// Worker pane 2
|
|
1500
|
-
PaneInfo {
|
|
1501
|
-
pane_id: PaneId::new("%w2"),
|
|
1502
|
-
session: SessionName::new("team-current"),
|
|
1503
|
-
window_index: Some(2),
|
|
1504
|
-
window_name: Some(WindowName::new("w2")),
|
|
1505
|
-
pane_index: Some(0),
|
|
1506
|
-
tty: None,
|
|
1507
|
-
current_command: Some("codex".to_string()),
|
|
1508
|
-
current_path: None,
|
|
1509
|
-
active: false,
|
|
1510
|
-
pane_pid: None,
|
|
1511
|
-
leader_env: BTreeMap::new(),
|
|
1512
|
-
},
|
|
1513
|
-
])
|
|
1514
|
-
.with_targets_persist_after_kill()
|
|
1515
|
-
.with_owned_session(&ws, "team-current", "current", "current");
|
|
1516
|
-
|
|
1517
|
-
let out = crate::cli::lifecycle_port::shutdown_with_transport(&ws, true, None, &transport)
|
|
1518
|
-
.expect("shutdown should complete");
|
|
1519
|
-
|
|
1520
|
-
let killed_sessions = transport.killed_sessions_observed();
|
|
1521
|
-
assert!(
|
|
1522
|
-
!killed_sessions.iter().any(|s| s == "team-current"),
|
|
1523
|
-
"E49 (RED): managed-leader shutdown must NEVER kill_session(team-current) — \
|
|
1524
|
-
that ends the leader's own pane (the user's CLI). Got transport \
|
|
1525
|
-
killed_sessions={killed_sessions:?}"
|
|
1526
|
-
);
|
|
1527
|
-
let killed_panes = transport.killed_panes();
|
|
1528
|
-
assert!(
|
|
1529
|
-
!killed_panes.iter().any(|p| p == "%leader"),
|
|
1530
|
-
"E49 (RED): leader anchor pane %leader must NEVER be killed. Got \
|
|
1531
|
-
killed_panes={killed_panes:?}"
|
|
1532
|
-
);
|
|
1533
|
-
assert!(
|
|
1534
|
-
killed_panes.iter().any(|p| p == "%w1"),
|
|
1535
|
-
"E49: worker pane %w1 must be killed per-pane (workers cleared, leader spared). \
|
|
1536
|
-
Got killed_panes={killed_panes:?}"
|
|
1537
|
-
);
|
|
1538
|
-
assert!(
|
|
1539
|
-
killed_panes.iter().any(|p| p == "%w2"),
|
|
1540
|
-
"E49: worker pane %w2 must be killed per-pane. Got killed_panes={killed_panes:?}"
|
|
1541
|
-
);
|
|
1542
|
-
assert!(
|
|
1543
|
-
!transport.kill_server_called(),
|
|
1544
|
-
"E49: managed topology must never kill the tmux server (would end leader pane)."
|
|
1545
|
-
);
|
|
1546
|
-
// Report-level assertions: the leader session must appear in spared_sessions,
|
|
1547
|
-
// not killed_sessions.
|
|
1548
|
-
let out_killed = out["killed_sessions"]
|
|
1549
|
-
.as_array()
|
|
1550
|
-
.cloned()
|
|
1551
|
-
.unwrap_or_default();
|
|
1552
|
-
let out_spared = out["spared_sessions"]
|
|
1553
|
-
.as_array()
|
|
1554
|
-
.cloned()
|
|
1555
|
-
.unwrap_or_default();
|
|
1556
|
-
assert!(
|
|
1557
|
-
!out_killed
|
|
1558
|
-
.iter()
|
|
1559
|
-
.any(|v| v.as_str() == Some("team-current")),
|
|
1560
|
-
"E49: report's killed_sessions must NOT contain the leader session. Got {out_killed:?}"
|
|
1561
|
-
);
|
|
1562
|
-
assert!(
|
|
1563
|
-
out_spared
|
|
1564
|
-
.iter()
|
|
1565
|
-
.any(|v| v.as_str() == Some("team-current")),
|
|
1566
|
-
"E49: report's spared_sessions MUST contain the leader session. Got {out_spared:?}"
|
|
1567
|
-
);
|
|
1568
|
-
// 0.4.0 refactor: when the target session is deliberately spared (E49
|
|
1569
|
-
// managed-leader topology), shutdown reports
|
|
1570
|
-
// `status="dirty_state", phase="target_session_spared", ok=false`. This
|
|
1571
|
-
// is semantically the SUCCESS path for E49 — leader pane preserved — but
|
|
1572
|
-
// the new refactor surfaces it as a non-clean exit so callers can detect
|
|
1573
|
-
// residual sessions. The E49 invariant (leader spared, workers killed per
|
|
1574
|
-
// pane) is already verified by the preceding `out_killed` / `out_spared`
|
|
1575
|
-
// assertions; here we pin the new top-level shape.
|
|
1576
|
-
assert_eq!(
|
|
1577
|
-
out["status"],
|
|
1578
|
-
json!("dirty_state"),
|
|
1579
|
-
"0.4.0 refactor: managed-leader spare path surfaces dirty_state \
|
|
1580
|
-
(target_session_spared) — leader was spared, not killed. Got out={out}"
|
|
1581
|
-
);
|
|
1582
|
-
assert_eq!(
|
|
1583
|
-
out["phase"],
|
|
1584
|
-
json!("target_session_spared"),
|
|
1585
|
-
"0.4.0 refactor: phase must name the spare reason. Got out={out}"
|
|
1586
|
-
);
|
|
1587
|
-
assert_eq!(out["session_killed"], json!(false));
|
|
1588
|
-
}
|
|
1589
|
-
|
|
1590
|
-
/// E49 regression guard: external-leader topology (is_external_leader=true)
|
|
1591
|
-
/// must STILL kill_session unconditionally. In that topology the team session
|
|
1592
|
-
/// is a disposable worker session and the leader pane lives elsewhere
|
|
1593
|
-
/// (a separate terminal / different socket). Sparing the session here would
|
|
1594
|
-
/// leak worker processes after shutdown.
|
|
1595
|
-
#[test]
|
|
1596
|
-
fn e49_external_leader_shutdown_still_kills_team_session_unconditionally() {
|
|
1597
|
-
let ws = tmp_shutdown_workspace("e49-external-leader-still-kills");
|
|
1598
|
-
crate::state::persist::save_runtime_state(
|
|
1599
|
-
&ws,
|
|
1600
|
-
&json!({
|
|
1601
|
-
"session_name": "team-external",
|
|
1602
|
-
"team_key": "team-external",
|
|
1603
|
-
"generation": "team-external",
|
|
1604
|
-
"is_external_leader": true,
|
|
1605
|
-
"leader_receiver": {"pane_id": "%leaderelsewhere"},
|
|
1606
|
-
"agents": {
|
|
1607
|
-
"w1": {"status": "running", "provider": "codex", "window": "w1", "pane_id": "%w1"}
|
|
1608
|
-
}
|
|
1609
|
-
}),
|
|
1610
|
-
)
|
|
1611
|
-
.unwrap();
|
|
1612
|
-
let transport = CleanShutdownTransport::new()
|
|
1613
|
-
.with_targets(vec![
|
|
1614
|
-
// Worker pane in team session
|
|
1615
|
-
PaneInfo {
|
|
1616
|
-
pane_id: PaneId::new("%w1"),
|
|
1617
|
-
session: SessionName::new("team-external"),
|
|
1618
|
-
window_index: Some(0),
|
|
1619
|
-
window_name: Some(WindowName::new("w1")),
|
|
1620
|
-
pane_index: Some(0),
|
|
1621
|
-
tty: None,
|
|
1622
|
-
current_command: Some("codex".to_string()),
|
|
1623
|
-
current_path: None,
|
|
1624
|
-
active: true,
|
|
1625
|
-
pane_pid: None,
|
|
1626
|
-
leader_env: BTreeMap::new(),
|
|
1627
|
-
},
|
|
1628
|
-
// Leader pane is in a DIFFERENT session (external topology)
|
|
1629
|
-
PaneInfo {
|
|
1630
|
-
pane_id: PaneId::new("%leaderelsewhere"),
|
|
1631
|
-
session: SessionName::new("user-shell"),
|
|
1632
|
-
window_index: Some(0),
|
|
1633
|
-
window_name: Some(WindowName::new("shell")),
|
|
1634
|
-
pane_index: Some(0),
|
|
1635
|
-
tty: None,
|
|
1636
|
-
current_command: Some("zsh".to_string()),
|
|
1637
|
-
current_path: None,
|
|
1638
|
-
active: true,
|
|
1639
|
-
pane_pid: None,
|
|
1640
|
-
leader_env: BTreeMap::new(),
|
|
1641
|
-
},
|
|
1642
|
-
])
|
|
1643
|
-
.with_targets_persist_after_kill()
|
|
1644
|
-
.with_owned_session(&ws, "team-external", "team-external", "team-external");
|
|
1645
|
-
|
|
1646
|
-
let event_log = crate::event_log::EventLog::new(&ws);
|
|
1647
|
-
let event_start = event_log.tail(0).expect("events before shutdown").len();
|
|
1648
|
-
let out = crate::cli::lifecycle_port::shutdown_with_transport(&ws, true, None, &transport)
|
|
1649
|
-
.expect("shutdown should complete");
|
|
1650
|
-
|
|
1651
|
-
let killed_sessions = transport.killed_sessions_observed();
|
|
1652
|
-
assert!(
|
|
1653
|
-
killed_sessions.iter().any(|s| s == "team-external"),
|
|
1654
|
-
"E49 regression guard: external-leader topology must STILL kill_session \
|
|
1655
|
-
the team session — leader pane lives elsewhere so this is safe. Got \
|
|
1656
|
-
transport killed_sessions={killed_sessions:?}"
|
|
1657
|
-
);
|
|
1658
|
-
if out["ok"] != json!(true) {
|
|
1659
|
-
let events = event_log.tail(0).expect("events after shutdown");
|
|
1660
|
-
let invocation_events = events
|
|
1661
|
-
.into_iter()
|
|
1662
|
-
.skip(event_start)
|
|
1663
|
-
.take(64)
|
|
1664
|
-
.collect::<Vec<_>>();
|
|
1665
|
-
panic!(
|
|
1666
|
-
"E49 external-leader shutdown returned a non-clean outcome: workspace tag=e49-external-leader-still-kills, expected session=team-external, shutdown report={out}, killed_sessions={killed_sessions:?}, bounded invocation events={invocation_events:?}"
|
|
1667
|
-
);
|
|
1668
|
-
}
|
|
1669
|
-
assert_eq!(out["ok"], json!(true));
|
|
1670
|
-
}
|
|
1671
|
-
|
|
1672
|
-
#[test]
|
|
1673
|
-
fn e49_external_leader_non_clean_diagnostic_is_bounded_and_still_kills() {
|
|
1674
|
-
let ws = tmp_shutdown_workspace("e49-external-leader-non-clean");
|
|
1675
|
-
crate::state::persist::save_runtime_state(
|
|
1676
|
-
&ws,
|
|
1677
|
-
&json!({
|
|
1678
|
-
"session_name": "team-external",
|
|
1679
|
-
"team_key": "team-external",
|
|
1680
|
-
"generation": "team-external",
|
|
1681
|
-
"is_external_leader": true,
|
|
1682
|
-
"leader_receiver": {"pane_id": "%leaderelsewhere"},
|
|
1683
|
-
"agents": {
|
|
1684
|
-
"w1": {"status": "running", "provider": "codex", "window": "w1", "pane_id": "%w1"}
|
|
1685
|
-
}
|
|
1686
|
-
}),
|
|
1687
|
-
)
|
|
1688
|
-
.unwrap();
|
|
1689
|
-
let transport = CleanShutdownTransport::new()
|
|
1690
|
-
.with_targets(vec![PaneInfo {
|
|
1691
|
-
pane_id: PaneId::new("%w1"),
|
|
1692
|
-
session: SessionName::new("team-external"),
|
|
1693
|
-
window_index: Some(0),
|
|
1694
|
-
window_name: Some(WindowName::new("w1")),
|
|
1695
|
-
pane_index: Some(0),
|
|
1696
|
-
tty: None,
|
|
1697
|
-
current_command: Some("codex".to_string()),
|
|
1698
|
-
current_path: None,
|
|
1699
|
-
active: true,
|
|
1700
|
-
pane_pid: None,
|
|
1701
|
-
leader_env: BTreeMap::new(),
|
|
1702
|
-
}])
|
|
1703
|
-
.with_kill_session_error("deterministic E49 kill-session failure")
|
|
1704
|
-
.with_owned_session(&ws, "team-external", "team-external", "team-external");
|
|
1705
|
-
|
|
1706
|
-
let event_log = crate::event_log::EventLog::new(&ws);
|
|
1707
|
-
let event_start = event_log.tail(0).expect("events before shutdown").len();
|
|
1708
|
-
let diagnostic = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
|
1709
|
-
let out = crate::cli::lifecycle_port::shutdown_with_transport(&ws, true, None, &transport)
|
|
1710
|
-
.expect("shutdown should complete");
|
|
1711
|
-
let killed_sessions = transport.killed_sessions_observed();
|
|
1712
|
-
assert!(
|
|
1713
|
-
killed_sessions.iter().any(|s| s == "team-external"),
|
|
1714
|
-
concat!(
|
|
1715
|
-
"E49 non-clean path must still attempt kill_session(team-external); ",
|
|
1716
|
-
"got killed_sessions={:?}"
|
|
1717
|
-
),
|
|
1718
|
-
killed_sessions
|
|
1719
|
-
);
|
|
1720
|
-
if out["ok"] != json!(true) {
|
|
1721
|
-
let events = event_log.tail(0).expect("events after shutdown");
|
|
1722
|
-
let invocation_events = events
|
|
1723
|
-
.into_iter()
|
|
1724
|
-
.skip(event_start)
|
|
1725
|
-
.take(64)
|
|
1726
|
-
.collect::<Vec<_>>();
|
|
1727
|
-
panic!(
|
|
1728
|
-
"E49 external-leader shutdown returned a non-clean outcome: workspace tag=e49-external-leader-non-clean, expected session=team-external, shutdown report={out}, killed_sessions={killed_sessions:?}, bounded invocation events={invocation_events:?}"
|
|
1729
|
-
);
|
|
1730
|
-
}
|
|
1731
|
-
}))
|
|
1732
|
-
.expect_err("deterministic kill-session error must exercise the diagnostic path");
|
|
1733
|
-
let diagnostic = diagnostic
|
|
1734
|
-
.downcast_ref::<String>()
|
|
1735
|
-
.cloned()
|
|
1736
|
-
.or_else(|| diagnostic.downcast_ref::<&str>().map(ToString::to_string))
|
|
1737
|
-
.expect("diagnostic panic should carry text");
|
|
1738
|
-
let bounded_events = diagnostic
|
|
1739
|
-
.split("bounded invocation events=")
|
|
1740
|
-
.nth(1)
|
|
1741
|
-
.expect("diagnostic should include bounded invocation events");
|
|
1742
|
-
let event_count = bounded_events.matches("\"event\":").count();
|
|
1743
|
-
assert!(
|
|
1744
|
-
event_count > 0,
|
|
1745
|
-
"diagnostic should include invocation events"
|
|
1746
|
-
);
|
|
1747
|
-
assert!(
|
|
1748
|
-
event_count <= 64,
|
|
1749
|
-
"diagnostic must be bounded to 64 invocation events, got {event_count}"
|
|
1750
|
-
);
|
|
1751
|
-
}
|
|
1752
|
-
|
|
1753
|
-
/// E49 regression guard: managed topology where the leader anchor pane is NOT
|
|
1754
|
-
/// in `state.session_name` (e.g. a stale state from an aborted launch where
|
|
1755
|
-
/// only worker panes exist in the session). The pre-fix behaviour (kill_session)
|
|
1756
|
-
/// is preserved here — no leader pane is at risk.
|
|
1757
|
-
#[test]
|
|
1758
|
-
fn e49_managed_leader_without_anchor_in_session_still_kills_session() {
|
|
1759
|
-
let ws = tmp_shutdown_workspace("e49-managed-no-anchor-in-session");
|
|
1760
|
-
crate::state::persist::save_runtime_state(
|
|
1761
|
-
&ws,
|
|
1762
|
-
&json!({
|
|
1763
|
-
"session_name": "team-orphan",
|
|
1764
|
-
"team_key": "team-orphan",
|
|
1765
|
-
"generation": "team-orphan",
|
|
1766
|
-
"is_external_leader": false,
|
|
1767
|
-
"agents": {
|
|
1768
|
-
"w1": {"status": "running", "provider": "codex", "window": "w1", "pane_id": "%w1"}
|
|
1769
|
-
}
|
|
1770
|
-
}),
|
|
1771
|
-
)
|
|
1772
|
-
.unwrap();
|
|
1773
|
-
let transport = CleanShutdownTransport::new()
|
|
1774
|
-
.with_targets(vec![PaneInfo {
|
|
1775
|
-
pane_id: PaneId::new("%w1"),
|
|
1776
|
-
session: SessionName::new("team-orphan"),
|
|
1777
|
-
window_index: Some(0),
|
|
1778
|
-
window_name: Some(WindowName::new("w1")),
|
|
1779
|
-
pane_index: Some(0),
|
|
1780
|
-
tty: None,
|
|
1781
|
-
current_command: Some("codex".to_string()),
|
|
1782
|
-
current_path: None,
|
|
1783
|
-
active: true,
|
|
1784
|
-
pane_pid: None,
|
|
1785
|
-
leader_env: BTreeMap::new(),
|
|
1786
|
-
}])
|
|
1787
|
-
.with_targets_persist_after_kill()
|
|
1788
|
-
.with_owned_session(&ws, "team-orphan", "team-orphan", "team-orphan");
|
|
1789
|
-
|
|
1790
|
-
let out = crate::cli::lifecycle_port::shutdown_with_transport(&ws, true, None, &transport)
|
|
1791
|
-
.expect("shutdown should complete");
|
|
1792
|
-
|
|
1793
|
-
let killed_sessions = transport.killed_sessions_observed();
|
|
1794
|
-
assert!(
|
|
1795
|
-
killed_sessions.iter().any(|s| s == "team-orphan"),
|
|
1796
|
-
"E49 regression guard: when no leader anchor pane is in the session, \
|
|
1797
|
-
the pre-fix kill_session path is preserved (no leader is at risk). \
|
|
1798
|
-
Got transport killed_sessions={killed_sessions:?}"
|
|
1799
|
-
);
|
|
1800
|
-
assert_eq!(out["ok"], json!(true));
|
|
1801
|
-
}
|
|
1802
|
-
|
|
1803
|
-
#[test]
|
|
1804
|
-
fn shutdown_missing_topology_marker_defaults_to_managed_cleanup() {
|
|
1805
|
-
let ws = tmp_shutdown_workspace("missing-topology-marker-managed-cleanup");
|
|
1806
|
-
crate::state::persist::save_runtime_state(
|
|
1807
|
-
&ws,
|
|
1808
|
-
&json!({
|
|
1809
|
-
"session_name": "team-current",
|
|
1810
|
-
"team_key": "team-current",
|
|
1811
|
-
"generation": "team-current",
|
|
1812
|
-
"agents": {}
|
|
1813
|
-
}),
|
|
1814
|
-
)
|
|
1815
|
-
.unwrap();
|
|
1816
|
-
let transport = CleanShutdownTransport::new()
|
|
1817
|
-
.with_targets(vec![PaneInfo {
|
|
1818
|
-
pane_id: PaneId::new("%1"),
|
|
1819
|
-
session: SessionName::new("team-current"),
|
|
1820
|
-
window_index: Some(0),
|
|
1821
|
-
window_name: Some(WindowName::new("leader")),
|
|
1822
|
-
pane_index: Some(0),
|
|
1823
|
-
tty: None,
|
|
1824
|
-
current_command: Some("codex".to_string()),
|
|
1825
|
-
current_path: None,
|
|
1826
|
-
active: true,
|
|
1827
|
-
pane_pid: None,
|
|
1828
|
-
leader_env: BTreeMap::new(),
|
|
1829
|
-
}])
|
|
1830
|
-
.with_targets_persist_after_kill()
|
|
1831
|
-
.with_owned_session(&ws, "team-current", "team-current", "team-current");
|
|
1832
|
-
|
|
1833
|
-
let out = crate::cli::lifecycle_port::shutdown_with_transport(&ws, true, None, &transport)
|
|
1834
|
-
.expect("shutdown should complete");
|
|
1835
|
-
|
|
1836
|
-
assert_eq!(out["ok"], json!(true));
|
|
1837
|
-
assert_eq!(out["killed_sessions"], json!(["team-current"]));
|
|
1838
|
-
assert_eq!(out["spared_sessions"], json!([]));
|
|
1839
|
-
assert!(
|
|
1840
|
-
!transport.kill_server_called(),
|
|
1841
|
-
"missing topology marker must default to managed cleanup, not external kill-server"
|
|
1842
|
-
);
|
|
1843
|
-
}
|
|
1844
|
-
|
|
1845
|
-
// ════════════════════════════════════════════════════════════════════════
|
|
1846
|
-
// unit-0 (Stage 0) characterization tests
|
|
1847
|
-
//
|
|
1848
|
-
// These pin the CURRENT classify_shutdown_outcome behavior so that the
|
|
1849
|
-
// Stage 1 refactor (unit-2: move shutdown into lifecycle and feed real
|
|
1850
|
-
// session-kill facts into the classifier) is detectable as a behavior
|
|
1851
|
-
// change rather than an accidental regression.
|
|
1852
|
-
//
|
|
1853
|
-
// The classifier today does NOT consume `session_killed` / `spared_sessions`
|
|
1854
|
-
// facts — it only looks at residuals. That is the 0.3.39 false-green bug
|
|
1855
|
-
// surface. The tests below LOCK the current OK/failed/partial/timeout
|
|
1856
|
-
// branches against opaque residual booleans so that:
|
|
1857
|
-
// - unit-2 can wire in the missing topology facts and we observe the
|
|
1858
|
-
// intended new behavior on the false-green scenario,
|
|
1859
|
-
// - any unintended status change in OTHER branches breaks the suite.
|
|
1860
|
-
// ════════════════════════════════════════════════════════════════════════
|
|
1861
|
-
|
|
1862
|
-
#[test]
|
|
1863
|
-
fn unit0_classify_outcome_no_residuals_returns_ok() {
|
|
1864
|
-
// Baseline: nothing residual, coordinator clean -> ok/status:"ok".
|
|
1865
|
-
let out = crate::cli::lifecycle_port::classify_shutdown_outcome(
|
|
1866
|
-
crate::cli::lifecycle_port::ShutdownOutcomeInput {
|
|
1867
|
-
kill_error: false,
|
|
1868
|
-
session_residuals: false,
|
|
1869
|
-
process_residuals: false,
|
|
1870
|
-
owned_file_residuals: false,
|
|
1871
|
-
cleanup_truth_degraded: false,
|
|
1872
|
-
coordinator_timeout: false,
|
|
1873
|
-
coordinator_stop_ok: Some(true),
|
|
1874
|
-
coordinator_post_stop:
|
|
1875
|
-
crate::cli::lifecycle_port::CoordinatorStopObservation::NotNeeded,
|
|
1876
|
-
target_session_spared: false,
|
|
1877
|
-
},
|
|
1878
|
-
);
|
|
1879
|
-
assert!(out.ok);
|
|
1880
|
-
assert_eq!(out.status, "ok");
|
|
1881
|
-
assert_eq!(out.phase, None);
|
|
1882
|
-
}
|
|
1883
|
-
|
|
1884
|
-
#[test]
|
|
1885
|
-
fn unit0_classify_outcome_session_residual_returns_failed() {
|
|
1886
|
-
let out = crate::cli::lifecycle_port::classify_shutdown_outcome(
|
|
1887
|
-
crate::cli::lifecycle_port::ShutdownOutcomeInput {
|
|
1888
|
-
kill_error: false,
|
|
1889
|
-
session_residuals: true,
|
|
1890
|
-
process_residuals: false,
|
|
1891
|
-
owned_file_residuals: false,
|
|
1892
|
-
cleanup_truth_degraded: false,
|
|
1893
|
-
coordinator_timeout: false,
|
|
1894
|
-
coordinator_stop_ok: Some(true),
|
|
1895
|
-
coordinator_post_stop: crate::cli::lifecycle_port::CoordinatorStopObservation::Gone,
|
|
1896
|
-
target_session_spared: false,
|
|
1897
|
-
},
|
|
1898
|
-
);
|
|
1899
|
-
assert!(!out.ok);
|
|
1900
|
-
assert_eq!(out.status, "failed");
|
|
1901
|
-
}
|
|
1902
|
-
|
|
1903
|
-
#[test]
|
|
1904
|
-
fn unit0_classify_outcome_coordinator_timeout_returns_timeout_phase() {
|
|
1905
|
-
let out = crate::cli::lifecycle_port::classify_shutdown_outcome(
|
|
1906
|
-
crate::cli::lifecycle_port::ShutdownOutcomeInput {
|
|
1907
|
-
kill_error: false,
|
|
1908
|
-
session_residuals: false,
|
|
1909
|
-
process_residuals: false,
|
|
1910
|
-
owned_file_residuals: false,
|
|
1911
|
-
cleanup_truth_degraded: false,
|
|
1912
|
-
coordinator_timeout: true,
|
|
1913
|
-
coordinator_stop_ok: Some(false),
|
|
1914
|
-
coordinator_post_stop: crate::cli::lifecycle_port::CoordinatorStopObservation::Running,
|
|
1915
|
-
target_session_spared: false,
|
|
1916
|
-
},
|
|
1917
|
-
);
|
|
1918
|
-
assert!(!out.ok);
|
|
1919
|
-
assert_eq!(out.status, "timeout");
|
|
1920
|
-
assert_eq!(out.phase, Some("stop_coordinator"));
|
|
1921
|
-
}
|
|
1922
|
-
|
|
1923
|
-
#[test]
|
|
1924
|
-
fn unit0_classify_outcome_cleanup_truth_degraded_returns_partial_os_probe() {
|
|
1925
|
-
let out = crate::cli::lifecycle_port::classify_shutdown_outcome(
|
|
1926
|
-
crate::cli::lifecycle_port::ShutdownOutcomeInput {
|
|
1927
|
-
kill_error: false,
|
|
1928
|
-
session_residuals: false,
|
|
1929
|
-
process_residuals: false,
|
|
1930
|
-
owned_file_residuals: false,
|
|
1931
|
-
cleanup_truth_degraded: true,
|
|
1932
|
-
coordinator_timeout: false,
|
|
1933
|
-
coordinator_stop_ok: Some(true),
|
|
1934
|
-
coordinator_post_stop: crate::cli::lifecycle_port::CoordinatorStopObservation::Gone,
|
|
1935
|
-
target_session_spared: false,
|
|
1936
|
-
},
|
|
1937
|
-
);
|
|
1938
|
-
assert!(!out.ok);
|
|
1939
|
-
assert_eq!(out.status, "partial");
|
|
1940
|
-
assert_eq!(out.phase, Some("os_probe"));
|
|
1941
|
-
}
|
|
1942
|
-
|
|
1943
|
-
#[test]
|
|
1944
|
-
fn unit2_classify_outcome_target_session_spared_is_not_green() {
|
|
1945
|
-
// unit-2 false-green guard: when the target worker session was spared
|
|
1946
|
-
// (still alive) the classifier MUST NOT return ok/status:"ok". This is
|
|
1947
|
-
// the 0.3.39 shutdown false-green shape unit-2 fixes.
|
|
1948
|
-
let out = crate::cli::lifecycle_port::classify_shutdown_outcome(
|
|
1949
|
-
crate::cli::lifecycle_port::ShutdownOutcomeInput {
|
|
1950
|
-
kill_error: false,
|
|
1951
|
-
session_residuals: false,
|
|
1952
|
-
process_residuals: false,
|
|
1953
|
-
owned_file_residuals: false,
|
|
1954
|
-
cleanup_truth_degraded: false,
|
|
1955
|
-
coordinator_timeout: false,
|
|
1956
|
-
coordinator_stop_ok: Some(true),
|
|
1957
|
-
coordinator_post_stop: crate::cli::lifecycle_port::CoordinatorStopObservation::Gone,
|
|
1958
|
-
target_session_spared: true,
|
|
1959
|
-
},
|
|
1960
|
-
);
|
|
1961
|
-
assert!(
|
|
1962
|
-
!out.ok,
|
|
1963
|
-
"false-green regression: target_session_spared=true must force ok=false"
|
|
1964
|
-
);
|
|
1965
|
-
assert_eq!(out.status, "dirty_state");
|
|
1966
|
-
assert_eq!(out.phase, Some("target_session_spared"));
|
|
1967
|
-
}
|
|
1968
|
-
|
|
1969
|
-
#[test]
|
|
1970
|
-
fn unit0_sessions_to_kill_leader_prefixed_session_is_always_spared() {
|
|
1971
|
-
// Pinned invariant: a session named `team-agent-leader-*` is NEVER in
|
|
1972
|
-
// the kill list, even without an anchor. unit-1/3 wraps this in typed
|
|
1973
|
-
// identity; the behavior must remain identical.
|
|
1974
|
-
use crate::transport::SessionName;
|
|
1975
|
-
let session_names = vec![
|
|
1976
|
-
SessionName::new("team-real-worker"),
|
|
1977
|
-
SessionName::new("team-agent-leader-claude-x"),
|
|
1978
|
-
];
|
|
1979
|
-
let decision = sessions_to_kill(&session_names, &BTreeSet::new());
|
|
1980
|
-
match decision {
|
|
1981
|
-
KillDecision::KillIndividually { to_kill, spared } => {
|
|
1982
|
-
assert!(to_kill.iter().any(|s| s.as_str() == "team-real-worker"));
|
|
1983
|
-
assert!(!to_kill
|
|
1984
|
-
.iter()
|
|
1985
|
-
.any(|s| s.as_str().starts_with("team-agent-leader-")));
|
|
1986
|
-
assert!(spared
|
|
1987
|
-
.iter()
|
|
1988
|
-
.any(|s| s.as_str() == "team-agent-leader-claude-x"));
|
|
1989
|
-
}
|
|
1990
|
-
other => panic!(
|
|
1991
|
-
"expected KillIndividually with leader spared; got {:?}",
|
|
1992
|
-
other
|
|
1993
|
-
),
|
|
1994
|
-
}
|
|
1995
|
-
}
|
|
1996
|
-
|
|
1997
|
-
const ISSUE_269_ROOT_PID: u32 = 2_147_000_001;
|
|
1998
|
-
|
|
1999
|
-
std::thread_local! {
|
|
2000
|
-
static ISSUE_269_LIVENESS_CALLS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
|
|
2001
|
-
static ISSUE_269_FIRST_ALIVE: std::cell::RefCell<Option<std::time::Instant>> = const { std::cell::RefCell::new(None) };
|
|
2002
|
-
static ISSUE_269_DEATH_DELAY: std::cell::Cell<Option<std::time::Duration>> = const { std::cell::Cell::new(None) };
|
|
2003
|
-
}
|
|
2004
|
-
|
|
2005
|
-
struct ShutdownWorkspaceCleanup(PathBuf);
|
|
2006
|
-
|
|
2007
|
-
impl Drop for ShutdownWorkspaceCleanup {
|
|
2008
|
-
fn drop(&mut self) {
|
|
2009
|
-
let _ = std::fs::remove_dir_all(&self.0);
|
|
2010
|
-
}
|
|
2011
|
-
}
|
|
2012
|
-
|
|
2013
|
-
fn reset_issue_269_probe_state() {
|
|
2014
|
-
ISSUE_269_LIVENESS_CALLS.with(|calls| calls.set(0));
|
|
2015
|
-
ISSUE_269_FIRST_ALIVE.with(|first| *first.borrow_mut() = None);
|
|
2016
|
-
ISSUE_269_DEATH_DELAY.with(|delay| delay.set(None));
|
|
2017
|
-
}
|
|
2018
|
-
|
|
2019
|
-
fn issue_269_liveness_call_count() -> usize {
|
|
2020
|
-
ISSUE_269_LIVENESS_CALLS.with(std::cell::Cell::get)
|
|
2021
|
-
}
|
|
2022
|
-
|
|
2023
|
-
fn issue_269_empty_process_table() -> Result<Vec<String>, String> {
|
|
2024
|
-
Ok(Vec::new())
|
|
2025
|
-
}
|
|
2026
|
-
|
|
2027
|
-
fn issue_269_transient_liveness(pid: u32) -> bool {
|
|
2028
|
-
if pid != ISSUE_269_ROOT_PID {
|
|
2029
|
-
return false;
|
|
2030
|
-
}
|
|
2031
|
-
ISSUE_269_LIVENESS_CALLS.with(|calls| {
|
|
2032
|
-
let call = calls.get();
|
|
2033
|
-
calls.set(call + 1);
|
|
2034
|
-
match call {
|
|
2035
|
-
0 => {
|
|
2036
|
-
ISSUE_269_FIRST_ALIVE.with(|first| *first.borrow_mut() = Some(std::time::Instant::now()));
|
|
2037
|
-
true
|
|
2038
|
-
}
|
|
2039
|
-
1 => {
|
|
2040
|
-
let elapsed = ISSUE_269_FIRST_ALIVE.with(|first| {
|
|
2041
|
-
first.borrow().as_ref().map(std::time::Instant::elapsed)
|
|
2042
|
-
});
|
|
2043
|
-
ISSUE_269_DEATH_DELAY.with(|delay| delay.set(elapsed));
|
|
2044
|
-
false
|
|
2045
|
-
}
|
|
2046
|
-
_ => false,
|
|
2047
|
-
}
|
|
2048
|
-
})
|
|
2049
|
-
}
|
|
2050
|
-
|
|
2051
|
-
fn issue_269_persistent_liveness(pid: u32) -> bool {
|
|
2052
|
-
if pid == ISSUE_269_ROOT_PID {
|
|
2053
|
-
ISSUE_269_LIVENESS_CALLS.with(|calls| calls.set(calls.get() + 1));
|
|
2054
|
-
true
|
|
2055
|
-
} else {
|
|
2056
|
-
false
|
|
2057
|
-
}
|
|
2058
|
-
}
|
|
2059
|
-
|
|
2060
|
-
fn issue_269_already_gone_liveness(pid: u32) -> bool {
|
|
2061
|
-
if pid == ISSUE_269_ROOT_PID {
|
|
2062
|
-
ISSUE_269_LIVENESS_CALLS.with(|calls| calls.set(calls.get() + 1));
|
|
2063
|
-
}
|
|
2064
|
-
false
|
|
2065
|
-
}
|
|
2066
|
-
|
|
2067
|
-
fn save_issue_269_root_state(workspace: &Path, session: &str) {
|
|
2068
|
-
crate::state::persist::save_runtime_state(
|
|
2069
|
-
workspace,
|
|
2070
|
-
&json!({
|
|
2071
|
-
"session_name": session,
|
|
2072
|
-
"team_key": session,
|
|
2073
|
-
"generation": session,
|
|
2074
|
-
"agents": {
|
|
2075
|
-
"worker": {
|
|
2076
|
-
"status": "running",
|
|
2077
|
-
"provider": "fake",
|
|
2078
|
-
"window": "worker",
|
|
2079
|
-
"provider_pid": ISSUE_269_ROOT_PID
|
|
2080
|
-
}
|
|
2081
|
-
}
|
|
2082
|
-
}),
|
|
2083
|
-
)
|
|
2084
|
-
.unwrap();
|
|
2085
|
-
}
|
|
2086
|
-
|
|
2087
|
-
fn shutdown_issue_269_with_probes(
|
|
2088
|
-
workspace: &Path,
|
|
2089
|
-
session: &str,
|
|
2090
|
-
liveness: fn(u32) -> bool,
|
|
2091
|
-
) -> serde_json::Value {
|
|
2092
|
-
let transport = CleanShutdownTransport::new().with_owned_session(
|
|
2093
|
-
workspace,
|
|
2094
|
-
session,
|
|
2095
|
-
session,
|
|
2096
|
-
session,
|
|
2097
|
-
);
|
|
2098
|
-
crate::cli::lifecycle_port::with_process_table_test_probe(
|
|
2099
|
-
issue_269_empty_process_table,
|
|
2100
|
-
|| {
|
|
2101
|
-
crate::cli::lifecycle_port::with_pid_liveness_test_probe(liveness, || {
|
|
2102
|
-
crate::cli::lifecycle_port::shutdown_with_transport(
|
|
2103
|
-
workspace,
|
|
2104
|
-
true,
|
|
2105
|
-
None,
|
|
2106
|
-
&transport,
|
|
2107
|
-
)
|
|
2108
|
-
.expect("shutdown should complete")
|
|
2109
|
-
})
|
|
2110
|
-
},
|
|
2111
|
-
)
|
|
2112
|
-
}
|
|
2113
|
-
|
|
2114
|
-
#[test]
|
|
2115
|
-
fn issue269_transient_unmatched_root_converges_inside_grace() {
|
|
2116
|
-
let workspace = tmp_shutdown_workspace("issue269-transient-root");
|
|
2117
|
-
let _workspace_cleanup = ShutdownWorkspaceCleanup(workspace.clone());
|
|
2118
|
-
let session = "team-issue269-transient";
|
|
2119
|
-
save_issue_269_root_state(&workspace, session);
|
|
2120
|
-
reset_issue_269_probe_state();
|
|
2121
|
-
|
|
2122
|
-
let started = std::time::Instant::now();
|
|
2123
|
-
let out = shutdown_issue_269_with_probes(&workspace, session, issue_269_transient_liveness);
|
|
2124
|
-
let elapsed = started.elapsed();
|
|
2125
|
-
let calls = issue_269_liveness_call_count();
|
|
2126
|
-
let death_delay = ISSUE_269_DEATH_DELAY.with(std::cell::Cell::get);
|
|
2127
|
-
|
|
2128
|
-
assert_eq!(
|
|
2129
|
-
out["ok"],
|
|
2130
|
-
json!(true),
|
|
2131
|
-
"an absent final process-table row plus a root that dies during the bounded grace must converge; ppid=0/empty-command is only a conservative placeholder, not a measured identity: {out}"
|
|
2132
|
-
);
|
|
2133
|
-
assert_eq!(out["residuals"]["processes"], json!([]), "{out}");
|
|
2134
|
-
assert!(calls >= 2, "the wait must observe both live and gone states; calls={calls}");
|
|
2135
|
-
assert!(death_delay.is_some_and(|delay| delay <= std::time::Duration::from_millis(500)), "root did not disappear within the bounded grace: {death_delay:?}");
|
|
2136
|
-
assert!(elapsed < std::time::Duration::from_secs(2), "shutdown exceeded the bounded wait: {elapsed:?}");
|
|
2137
|
-
}
|
|
2138
|
-
|
|
2139
|
-
#[test]
|
|
2140
|
-
fn issue269_persistent_unmatched_root_remains_a_residual_after_grace() {
|
|
2141
|
-
let workspace = tmp_shutdown_workspace("issue269-persistent-root");
|
|
2142
|
-
let _workspace_cleanup = ShutdownWorkspaceCleanup(workspace.clone());
|
|
2143
|
-
let session = "team-issue269-persistent";
|
|
2144
|
-
save_issue_269_root_state(&workspace, session);
|
|
2145
|
-
reset_issue_269_probe_state();
|
|
2146
|
-
|
|
2147
|
-
let started = std::time::Instant::now();
|
|
2148
|
-
let out = shutdown_issue_269_with_probes(&workspace, session, issue_269_persistent_liveness);
|
|
2149
|
-
let elapsed = started.elapsed();
|
|
2150
|
-
let calls = issue_269_liveness_call_count();
|
|
2151
|
-
let residuals = out["residuals"]["processes"].as_array().unwrap();
|
|
2152
|
-
|
|
2153
|
-
assert_eq!(out["ok"], json!(false), "a live root must not be filtered by placeholder fields: {out}");
|
|
2154
|
-
assert_eq!(residuals.len(), 1, "{out}");
|
|
2155
|
-
assert_eq!(residuals[0]["pid"], json!(ISSUE_269_ROOT_PID), "{out}");
|
|
2156
|
-
assert_eq!(residuals[0]["ppid"], json!(0), "{out}");
|
|
2157
|
-
assert_eq!(residuals[0]["command"], json!(""), "{out}");
|
|
2158
|
-
assert!((2..=30).contains(&calls), "persistent-root polling must remain bounded; calls={calls}");
|
|
2159
|
-
assert!(elapsed < std::time::Duration::from_secs(2), "shutdown exceeded the bounded wait: {elapsed:?}");
|
|
2160
|
-
}
|
|
2161
|
-
|
|
2162
|
-
#[test]
|
|
2163
|
-
fn issue269_already_gone_root_returns_without_fixed_grace_sleep() {
|
|
2164
|
-
let workspace = tmp_shutdown_workspace("issue269-already-gone-root");
|
|
2165
|
-
let _workspace_cleanup = ShutdownWorkspaceCleanup(workspace.clone());
|
|
2166
|
-
let session = "team-issue269-gone";
|
|
2167
|
-
save_issue_269_root_state(&workspace, session);
|
|
2168
|
-
reset_issue_269_probe_state();
|
|
2169
|
-
|
|
2170
|
-
let started = std::time::Instant::now();
|
|
2171
|
-
let out = shutdown_issue_269_with_probes(&workspace, session, issue_269_already_gone_liveness);
|
|
2172
|
-
let elapsed = started.elapsed();
|
|
2173
|
-
let calls = issue_269_liveness_call_count();
|
|
2174
|
-
|
|
2175
|
-
assert_eq!(out["ok"], json!(true), "{out}");
|
|
2176
|
-
assert_eq!(out["residuals"]["processes"], json!([]), "{out}");
|
|
2177
|
-
assert!(calls >= 2, "the final verification path and wait path must both observe liveness; calls={calls}");
|
|
2178
|
-
assert!(elapsed < std::time::Duration::from_millis(450), "already-gone roots must not incur a fixed grace sleep: {elapsed:?}");
|
|
2179
|
-
}
|