@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,3983 +0,0 @@
|
|
|
1
|
-
#[path = "../../../tests/support/hermetic.rs"]
|
|
2
|
-
mod hermetic_guard;
|
|
3
|
-
|
|
4
|
-
use super::*;
|
|
5
|
-
use crate::tmux_backend::TmuxBackend;
|
|
6
|
-
use crate::transport::test_support::OfflineTransport;
|
|
7
|
-
use crate::transport::Transport;
|
|
8
|
-
use serde_json::json;
|
|
9
|
-
use serial_test::serial;
|
|
10
|
-
|
|
11
|
-
fn enter_hermetic(tag: &str) -> hermetic_guard::HermeticTestEnv {
|
|
12
|
-
let env = hermetic_guard::HermeticTestEnv::enter(tag);
|
|
13
|
-
env.scrub_tmux();
|
|
14
|
-
env.assert_no_real_tmux();
|
|
15
|
-
env
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
fn launch_source() -> String {
|
|
19
|
-
let src = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("src/lifecycle");
|
|
20
|
-
let mut files = vec![src.join("launch.rs")];
|
|
21
|
-
let mut siblings = std::fs::read_dir(src.join("launch"))
|
|
22
|
-
.expect("read launch module directory")
|
|
23
|
-
.map(|entry| entry.expect("read launch module entry").path())
|
|
24
|
-
.filter(|path| path.extension().and_then(|ext| ext.to_str()) == Some("rs"))
|
|
25
|
-
.collect::<Vec<_>>();
|
|
26
|
-
siblings.sort();
|
|
27
|
-
files.extend(siblings);
|
|
28
|
-
|
|
29
|
-
files
|
|
30
|
-
.into_iter()
|
|
31
|
-
.map(|path| {
|
|
32
|
-
format!(
|
|
33
|
-
"\n// @source {}\n{}",
|
|
34
|
-
path.strip_prefix(&src).unwrap().display(),
|
|
35
|
-
std::fs::read_to_string(&path).expect("read launch source")
|
|
36
|
-
)
|
|
37
|
-
})
|
|
38
|
-
.collect()
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const QS_TEAM_MD: &str =
|
|
42
|
-
"---\nname: quickteam\nobjective: Quick start.\nprovider: codex\n---\n\nQuick-start team.\n";
|
|
43
|
-
pub(super) const QS_VALID_ROLE: &str = "---\nname: implementer\nrole: Implementation Engineer\nprovider: fake\nmodel: fake\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nImplement bounded tasks.\n";
|
|
44
|
-
const QS_ROLE_NO_PROVIDER: &str = "---\nname: implementer\nrole: Implementation Engineer\nmodel: gpt-5.5\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nImplement bounded tasks.\n";
|
|
45
|
-
|
|
46
|
-
/// A REAL team dir `<base>/teamdir/{TEAM.md, agents/implementer.md}` — already in team-dir
|
|
47
|
-
/// layout, so quick_start's prepare_quick_start_team returns it as-is and writes the compiled
|
|
48
|
-
/// `team.spec.yaml` into it (diagnose/quick_start.py:prepare_quick_start_team, before launch).
|
|
49
|
-
pub(super) fn quick_start_team_dir(role_doc: &str) -> PathBuf {
|
|
50
|
-
let team = temp_ws().join("teamdir");
|
|
51
|
-
std::fs::create_dir_all(team.join("agents")).unwrap();
|
|
52
|
-
std::fs::write(team.join("TEAM.md"), QS_TEAM_MD).unwrap();
|
|
53
|
-
std::fs::write(team.join("agents").join("implementer.md"), role_doc).unwrap();
|
|
54
|
-
team
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
fn quick_start_team_dir_with_roles(role_docs: &[(&str, &str)]) -> PathBuf {
|
|
58
|
-
let team = temp_ws().join("teamdir");
|
|
59
|
-
std::fs::create_dir_all(team.join("agents")).unwrap();
|
|
60
|
-
std::fs::write(team.join("TEAM.md"), QS_TEAM_MD).unwrap();
|
|
61
|
-
for (file, role_doc) in role_docs {
|
|
62
|
-
std::fs::write(team.join("agents").join(file), role_doc).unwrap();
|
|
63
|
-
}
|
|
64
|
-
team
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
fn role_doc(id: &str) -> String {
|
|
68
|
-
provider_role_doc(id, "fake", "fake")
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
fn provider_role_doc(id: &str, provider: &str, model: &str) -> String {
|
|
72
|
-
format!(
|
|
73
|
-
"---\nname: {id}\nrole: {id} Worker\nprovider: {provider}\nmodel: {model}\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\n{id} worker.\n"
|
|
74
|
-
)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
fn layout_pane(
|
|
78
|
-
session: &str,
|
|
79
|
-
window: &str,
|
|
80
|
-
pane: &str,
|
|
81
|
-
pane_index: u32,
|
|
82
|
-
) -> crate::transport::PaneInfo {
|
|
83
|
-
crate::transport::PaneInfo {
|
|
84
|
-
pane_id: crate::transport::PaneId::new(pane),
|
|
85
|
-
session: crate::transport::SessionName::new(session),
|
|
86
|
-
window_index: None,
|
|
87
|
-
window_name: Some(crate::transport::WindowName::new(window)),
|
|
88
|
-
pane_index: Some(pane_index),
|
|
89
|
-
tty: None,
|
|
90
|
-
current_command: Some("team-agent".to_string()),
|
|
91
|
-
current_path: None,
|
|
92
|
-
active: pane_index == 0,
|
|
93
|
-
pane_pid: None,
|
|
94
|
-
leader_env: std::collections::BTreeMap::new(),
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/// E5 spec 迁移:spec 不再落 team_dir,而在 <team_workspace>/.team/runtime/<team_key>/。
|
|
99
|
-
/// quick-start 未显式指定 id 时,team_key 来自 compiled TEAM.md name(`quickteam`)。
|
|
100
|
-
pub(super) fn quick_start_runtime_spec_path(team: &std::path::Path) -> PathBuf {
|
|
101
|
-
let workspace = crate::model::paths::team_workspace(team).unwrap();
|
|
102
|
-
crate::model::paths::runtime_spec_path(&workspace, "quickteam")
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/// 在 team 自身或其 team_workspace 父下找 .team/runtime/*/team.spec.yaml。run_workspace 解析
|
|
106
|
-
/// 可能是 team 或父、team_key 可能因 state 缺省而非 team 名,故扫整个 runtime 目录任一子目录。
|
|
107
|
-
/// `team_key` 给定时优先精确命中,否则取扫到的第一个。
|
|
108
|
-
pub(super) fn find_runtime_spec(team: &std::path::Path, team_key: &str) -> Option<PathBuf> {
|
|
109
|
-
let mut workspaces = vec![team.to_path_buf()];
|
|
110
|
-
if let Ok(ws) = crate::model::paths::team_workspace(team) {
|
|
111
|
-
workspaces.push(ws);
|
|
112
|
-
}
|
|
113
|
-
// 精确命中优先。
|
|
114
|
-
for ws in &workspaces {
|
|
115
|
-
let exact = crate::model::paths::runtime_spec_path(ws, team_key);
|
|
116
|
-
if exact.exists() {
|
|
117
|
-
return Some(exact);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
// 回退:扫 .team/runtime/*/team.spec.yaml。
|
|
121
|
-
for ws in &workspaces {
|
|
122
|
-
let runtime = crate::model::paths::runtime_dir(ws);
|
|
123
|
-
let Ok(entries) = std::fs::read_dir(&runtime) else {
|
|
124
|
-
continue;
|
|
125
|
-
};
|
|
126
|
-
for entry in entries.flatten() {
|
|
127
|
-
let spec = entry.path().join("team.spec.yaml");
|
|
128
|
-
if spec.exists() {
|
|
129
|
-
return Some(spec);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
None
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/// A no-owner running workspace: state.json carries session_name + agents but NO team_owner →
|
|
137
|
-
/// check_team_owner returns None = allowed (owner_gate.rs:48), so the owner-gated entry points can
|
|
138
|
-
/// proceed PAST the owner gate. Also inits the real team.db.
|
|
139
|
-
fn unowned_running_ws() -> PathBuf {
|
|
140
|
-
let ws = temp_ws();
|
|
141
|
-
crate::state::persist::save_runtime_state(
|
|
142
|
-
&ws,
|
|
143
|
-
&json!({
|
|
144
|
-
"session_name": "team-x",
|
|
145
|
-
"agents": { "w1": { "provider": "fake", "role": "Worker", "model": "fake", "auth_mode": "subscription" } },
|
|
146
|
-
}),
|
|
147
|
-
)
|
|
148
|
-
.unwrap();
|
|
149
|
-
let _ = crate::message_store::MessageStore::open(&ws).unwrap();
|
|
150
|
-
ws
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// P0 — quick_start over a VALID team dir must COMPILE the real spec (the compiler runs before any
|
|
154
|
-
// launch/spawn) → team.spec.yaml is written carrying the agent set, and the result is NOT the
|
|
155
|
-
// hardcoded "no role docs found" PreflightBlocked. Golden: quick_start.py → _compile_team_dir_spec
|
|
156
|
-
// writes spec_path=team_dir/team.spec.yaml BEFORE launch.
|
|
157
|
-
#[test]
|
|
158
|
-
#[serial(env)]
|
|
159
|
-
fn quick_start_compiles_real_spec_to_team_spec_yaml() {
|
|
160
|
-
let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("launch-spawn-compile-spec");
|
|
161
|
-
let team = quick_start_team_dir(QS_VALID_ROLE);
|
|
162
|
-
seed_healthy_coordinator(&crate::model::paths::team_workspace(&team).unwrap());
|
|
163
|
-
let transport = OfflineTransport::new();
|
|
164
|
-
let result = quick_start_with_transport(&team, None, true, None, &transport);
|
|
165
|
-
|
|
166
|
-
// OBSERVABLE 1 (real compiler ran; spawn-independent): the compiled spec is written.
|
|
167
|
-
// E5: spec lands in .team/runtime/<team_key>/ (NOT the user team dir).
|
|
168
|
-
let spec_path = quick_start_runtime_spec_path(&team);
|
|
169
|
-
assert!(
|
|
170
|
-
spec_path.exists(),
|
|
171
|
-
"quick_start must compile the team dir and write team.spec.yaml under .team/runtime/<team_key>/ \
|
|
172
|
-
(the real compiler runs before launch); the stub returns before compiling. result={result:?}"
|
|
173
|
-
);
|
|
174
|
-
assert!(
|
|
175
|
-
!team.join("team.spec.yaml").exists(),
|
|
176
|
-
"E5: spec must NOT be written into the user team dir"
|
|
177
|
-
);
|
|
178
|
-
let spec_text = std::fs::read_to_string(&spec_path).unwrap_or_default();
|
|
179
|
-
assert!(
|
|
180
|
-
spec_text.contains("implementer"),
|
|
181
|
-
"the compiled team.spec.yaml must carry the role-doc agent 'implementer'"
|
|
182
|
-
);
|
|
183
|
-
|
|
184
|
-
// OBSERVABLE 2 (report, robust): a VALID dir must never be the hardcoded always-blocked stub.
|
|
185
|
-
if let Ok(QuickStartReport::PreflightBlocked { blockers, .. }) = &result {
|
|
186
|
-
assert!(
|
|
187
|
-
!blockers.iter().any(|b| b.contains("no role docs found")),
|
|
188
|
-
"a VALID team dir must never yield the hardcoded 'no role docs found' blocker"
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
#[test]
|
|
194
|
-
#[serial(env)]
|
|
195
|
-
fn quick_start_without_team_id_uses_compiled_team_name_as_canonical_key() {
|
|
196
|
-
let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("launch-spawn-canonical-team");
|
|
197
|
-
let team = quick_start_team_dir(QS_VALID_ROLE);
|
|
198
|
-
let workspace = crate::model::paths::team_workspace(&team).unwrap();
|
|
199
|
-
seed_healthy_coordinator(&workspace);
|
|
200
|
-
let transport = OfflineTransport::new();
|
|
201
|
-
|
|
202
|
-
let result = quick_start_with_transport(&team, None, true, None, &transport);
|
|
203
|
-
assert!(result.is_ok(), "quick-start fixture must run: {result:?}");
|
|
204
|
-
|
|
205
|
-
let state = crate::state::persist::load_runtime_state(&workspace).unwrap();
|
|
206
|
-
assert_eq!(state["active_team_key"], json!("quickteam"));
|
|
207
|
-
assert_eq!(state["team_key"], json!("quickteam"));
|
|
208
|
-
assert!(state["teams"].get("quickteam").is_some(), "{state}");
|
|
209
|
-
assert!(state["teams"].get("teamdir").is_none(), "{state}");
|
|
210
|
-
assert!(
|
|
211
|
-
crate::model::paths::runtime_spec_path(&workspace, "quickteam").exists(),
|
|
212
|
-
"runtime spec must share the canonical key"
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
#[test]
|
|
217
|
-
#[serial(env)]
|
|
218
|
-
fn existing_runtime_producer_scopes_canonical_team() {
|
|
219
|
-
let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("launch-spawn-existing-producer");
|
|
220
|
-
let team = quick_start_team_dir(QS_VALID_ROLE);
|
|
221
|
-
seed_healthy_coordinator(&crate::model::paths::team_workspace(&team).unwrap());
|
|
222
|
-
let transport = OfflineTransport::new();
|
|
223
|
-
let first = quick_start_with_transport(&team, Some("from-name"), true, None, &transport)
|
|
224
|
-
.expect("first quick-start");
|
|
225
|
-
match &first {
|
|
226
|
-
QuickStartReport::Ready { team: canonical, .. } => {
|
|
227
|
-
assert_eq!(canonical, "from-name", "Ready producer must emit canonical team");
|
|
228
|
-
}
|
|
229
|
-
other => panic!("first quick-start must be Ready; got {other:?}"),
|
|
230
|
-
}
|
|
231
|
-
let second = quick_start_with_transport(&team, Some("from-name"), true, None, &transport)
|
|
232
|
-
.expect("second quick-start");
|
|
233
|
-
match second {
|
|
234
|
-
QuickStartReport::ExistingRuntime {
|
|
235
|
-
team: canonical,
|
|
236
|
-
agent_ids,
|
|
237
|
-
..
|
|
238
|
-
} => {
|
|
239
|
-
assert_eq!(canonical.as_deref(), Some("from-name"));
|
|
240
|
-
assert!(
|
|
241
|
-
agent_ids.iter().any(|id| id == "implementer"),
|
|
242
|
-
"ExistingRuntime producer agent_ids={agent_ids:?}"
|
|
243
|
-
);
|
|
244
|
-
}
|
|
245
|
-
other => panic!("duplicate quick-start must be ExistingRuntime; got {other:?}"),
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
#[test]
|
|
250
|
-
#[serial(env)]
|
|
251
|
-
fn existing_runtime_requested_bob_does_not_emit_alice_members_or_attach() {
|
|
252
|
-
let team = quick_start_team_dir(QS_VALID_ROLE);
|
|
253
|
-
let workspace = crate::model::paths::team_workspace(&team).unwrap();
|
|
254
|
-
let state = json!({
|
|
255
|
-
"active_team_key": "alice",
|
|
256
|
-
"agents": { "alice": { "window": "alice" } },
|
|
257
|
-
"session_name": "team-alice",
|
|
258
|
-
"tmux_endpoint": "/tmp/shared.sock",
|
|
259
|
-
"teams": {
|
|
260
|
-
"alice": {
|
|
261
|
-
"agents": { "alice": { "window": "alice" } },
|
|
262
|
-
"session_name": "team-alice"
|
|
263
|
-
},
|
|
264
|
-
"bob": {
|
|
265
|
-
"agents": { "bob": { "window": "bob" } },
|
|
266
|
-
"session_name": "team-bob"
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
crate::state::persist::save_runtime_state(&workspace, &state).unwrap();
|
|
271
|
-
let report = quick_start_with_transport(&team, Some("bob"), true, None, &OfflineTransport::new())
|
|
272
|
-
.expect("requested bob existing runtime");
|
|
273
|
-
match report {
|
|
274
|
-
QuickStartReport::ExistingRuntime {
|
|
275
|
-
team: canonical,
|
|
276
|
-
agent_ids,
|
|
277
|
-
session_name,
|
|
278
|
-
attach_commands,
|
|
279
|
-
..
|
|
280
|
-
} => {
|
|
281
|
-
assert_eq!(canonical.as_deref(), Some("bob"));
|
|
282
|
-
assert_eq!(agent_ids, vec!["bob".to_string()]);
|
|
283
|
-
assert_eq!(
|
|
284
|
-
session_name.as_ref().map(|session| session.as_str()),
|
|
285
|
-
Some("team-bob")
|
|
286
|
-
);
|
|
287
|
-
assert!(
|
|
288
|
-
attach_commands.iter().any(|command| command.contains("team-bob")),
|
|
289
|
-
"attach must follow bob session; got {attach_commands:?}"
|
|
290
|
-
);
|
|
291
|
-
assert!(
|
|
292
|
-
attach_commands
|
|
293
|
-
.iter()
|
|
294
|
-
.all(|command| !command.contains("alice") && !command.contains("team-alice")),
|
|
295
|
-
"attach must not steer to alice; got {attach_commands:?}"
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
other => panic!("expected ExistingRuntime for bob; got {other:?}"),
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
#[test]
|
|
303
|
-
#[serial(env)]
|
|
304
|
-
fn existing_runtime_empty_top_level_agents_still_emits_bob() {
|
|
305
|
-
let team = quick_start_team_dir(QS_VALID_ROLE);
|
|
306
|
-
let workspace = crate::model::paths::team_workspace(&team).unwrap();
|
|
307
|
-
let state = json!({
|
|
308
|
-
"active_team_key": "bob",
|
|
309
|
-
"agents": {},
|
|
310
|
-
"teams": {
|
|
311
|
-
"bob": {
|
|
312
|
-
"agents": { "bob": { "window": "bob" } },
|
|
313
|
-
"session_name": "team-bob"
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
crate::state::persist::save_runtime_state(&workspace, &state).unwrap();
|
|
318
|
-
let report = quick_start_with_transport(&team, Some("bob"), true, None, &OfflineTransport::new())
|
|
319
|
-
.expect("requested bob with empty top-level agents");
|
|
320
|
-
match report {
|
|
321
|
-
QuickStartReport::ExistingRuntime { agent_ids, .. } => {
|
|
322
|
-
assert_eq!(agent_ids, vec!["bob".to_string()]);
|
|
323
|
-
}
|
|
324
|
-
other => panic!("expected ExistingRuntime; got {other:?}"),
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
#[test]
|
|
329
|
-
#[serial(env)]
|
|
330
|
-
fn quick_start_teamdir_under_dot_team_uses_project_workspace_for_status_and_collect() {
|
|
331
|
-
let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("launch-spawn-dot-team-workspace");
|
|
332
|
-
let workspace = temp_ws();
|
|
333
|
-
seed_healthy_coordinator(&workspace);
|
|
334
|
-
let team = workspace.join(".team").join("current");
|
|
335
|
-
std::fs::create_dir_all(team.join("agents")).unwrap();
|
|
336
|
-
std::fs::write(team.join("TEAM.md"), QS_TEAM_MD).unwrap();
|
|
337
|
-
std::fs::write(team.join("agents").join("implementer.md"), QS_VALID_ROLE).unwrap();
|
|
338
|
-
|
|
339
|
-
let transport = OfflineTransport::new();
|
|
340
|
-
let result = quick_start_with_transport(&team, None, true, None, &transport);
|
|
341
|
-
assert!(
|
|
342
|
-
matches!(result, Ok(QuickStartReport::Ready { .. })),
|
|
343
|
-
"quick-start failed: {result:?}"
|
|
344
|
-
);
|
|
345
|
-
|
|
346
|
-
let state_path = crate::state::persist::runtime_state_path(&workspace);
|
|
347
|
-
assert!(
|
|
348
|
-
state_path.exists(),
|
|
349
|
-
"quick-start .team/current must persist runtime state under project root"
|
|
350
|
-
);
|
|
351
|
-
assert!(
|
|
352
|
-
!workspace
|
|
353
|
-
.join(".team")
|
|
354
|
-
.join(".team")
|
|
355
|
-
.join("runtime")
|
|
356
|
-
.join("state.json")
|
|
357
|
-
.exists(),
|
|
358
|
-
"quick-start .team/current must not create nested .team/.team runtime state"
|
|
359
|
-
);
|
|
360
|
-
|
|
361
|
-
for input in [&workspace, &team] {
|
|
362
|
-
let selected = crate::state::selector::resolve_active_team(
|
|
363
|
-
input,
|
|
364
|
-
None,
|
|
365
|
-
crate::state::selector::SelectorMode::RuntimeOnly,
|
|
366
|
-
)
|
|
367
|
-
.expect("status/collect selector should resolve project root");
|
|
368
|
-
assert_eq!(
|
|
369
|
-
selected.run_workspace,
|
|
370
|
-
workspace,
|
|
371
|
-
"input={}",
|
|
372
|
-
input.display()
|
|
373
|
-
);
|
|
374
|
-
// E5: selector resolves spec_path to .team/runtime/<canonical team_key>/.
|
|
375
|
-
let expected_spec = crate::model::paths::runtime_spec_path(&workspace, "quickteam");
|
|
376
|
-
assert_eq!(
|
|
377
|
-
selected
|
|
378
|
-
.spec_path
|
|
379
|
-
.as_deref()
|
|
380
|
-
.map(std::fs::canonicalize)
|
|
381
|
-
.transpose()
|
|
382
|
-
.unwrap(),
|
|
383
|
-
Some(std::fs::canonicalize(&expected_spec).unwrap()),
|
|
384
|
-
"input={}",
|
|
385
|
-
input.display()
|
|
386
|
-
);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
let status = crate::cli::cmd_status(&crate::cli::StatusArgs {
|
|
390
|
-
agent: None,
|
|
391
|
-
workspace: team.clone(),
|
|
392
|
-
detail: false,
|
|
393
|
-
summary: false,
|
|
394
|
-
json: true,
|
|
395
|
-
team: None,
|
|
396
|
-
});
|
|
397
|
-
assert!(
|
|
398
|
-
status.is_ok(),
|
|
399
|
-
"status should normalize teamdir to project-root runtime state: {status:?}"
|
|
400
|
-
);
|
|
401
|
-
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
#[test]
|
|
405
|
-
#[serial(env)]
|
|
406
|
-
fn quick_start_default_workspace_compiled_spec_uses_project_root() {
|
|
407
|
-
let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("launch-spawn-default-workspace");
|
|
408
|
-
let workspace = temp_ws();
|
|
409
|
-
std::fs::create_dir_all(workspace.join("agents")).unwrap();
|
|
410
|
-
std::fs::write(workspace.join("TEAM.md"), QS_TEAM_MD).unwrap();
|
|
411
|
-
std::fs::write(
|
|
412
|
-
workspace.join("agents").join("implementer.md"),
|
|
413
|
-
QS_VALID_ROLE,
|
|
414
|
-
)
|
|
415
|
-
.unwrap();
|
|
416
|
-
seed_healthy_coordinator(&workspace);
|
|
417
|
-
let transport = OfflineTransport::new();
|
|
418
|
-
|
|
419
|
-
let report = quick_start_with_transport_in_workspace(
|
|
420
|
-
&workspace, &workspace, None, true, None, &transport,
|
|
421
|
-
)
|
|
422
|
-
.expect("quick-start workspace-root team should reach a report");
|
|
423
|
-
assert!(
|
|
424
|
-
matches!(report, QuickStartReport::Ready { .. }),
|
|
425
|
-
"quick-start failed: {report:?}"
|
|
426
|
-
);
|
|
427
|
-
|
|
428
|
-
let state = crate::state::persist::load_runtime_state(&workspace).unwrap();
|
|
429
|
-
let spec_path = state
|
|
430
|
-
.get("spec_path")
|
|
431
|
-
.and_then(serde_json::Value::as_str)
|
|
432
|
-
.map(PathBuf::from)
|
|
433
|
-
.expect("quick-start state should carry spec_path");
|
|
434
|
-
let spec = crate::model::yaml::loads(&std::fs::read_to_string(spec_path).unwrap()).unwrap();
|
|
435
|
-
assert_eq!(
|
|
436
|
-
spec.get("team")
|
|
437
|
-
.and_then(|team| team.get("workspace"))
|
|
438
|
-
.and_then(crate::model::yaml::Value::as_str),
|
|
439
|
-
Some(workspace.to_string_lossy().as_ref()),
|
|
440
|
-
"compiled team.workspace must be the project root, not its parent"
|
|
441
|
-
);
|
|
442
|
-
for agent in spec
|
|
443
|
-
.get("agents")
|
|
444
|
-
.and_then(crate::model::yaml::Value::as_list)
|
|
445
|
-
.unwrap()
|
|
446
|
-
{
|
|
447
|
-
assert_eq!(
|
|
448
|
-
agent
|
|
449
|
-
.get("working_directory")
|
|
450
|
-
.and_then(crate::model::yaml::Value::as_str),
|
|
451
|
-
Some(workspace.to_string_lossy().as_ref()),
|
|
452
|
-
"compiled agent working_directory must be the project root"
|
|
453
|
-
);
|
|
454
|
-
}
|
|
455
|
-
assert_eq!(
|
|
456
|
-
transport.spawn_cwd_records(),
|
|
457
|
-
vec![workspace],
|
|
458
|
-
"quick-start must spawn workers from the project root"
|
|
459
|
-
);
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
// P0 — quick_start over an INVALID role doc (missing `provider`) must surface the REAL compile
|
|
463
|
-
// error, distinct from the stub's hardcoded "no role docs found". Golden: compile_team raises
|
|
464
|
-
// "missing front matter field provider" (compiler.py:_validate_role_doc), before preflight.
|
|
465
|
-
#[test]
|
|
466
|
-
fn quick_start_invalid_role_doc_surfaces_real_compile_error() {
|
|
467
|
-
let team = quick_start_team_dir(QS_ROLE_NO_PROVIDER);
|
|
468
|
-
let transport = OfflineTransport::new();
|
|
469
|
-
let result = quick_start_with_transport(&team, None, true, None, &transport);
|
|
470
|
-
|
|
471
|
-
let text = format!("{result:?}");
|
|
472
|
-
assert!(
|
|
473
|
-
text.contains("provider"),
|
|
474
|
-
"an invalid role doc (missing provider) must surface the real compile error mentioning \
|
|
475
|
-
'provider'; got {text}"
|
|
476
|
-
);
|
|
477
|
-
assert!(
|
|
478
|
-
!text.contains("no role docs found"),
|
|
479
|
-
"must NOT be the hardcoded stub blocker — real preflight/compile distinguishes the cause"
|
|
480
|
-
);
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
// P0 — launch (dry_run) over a real compiled spec must resolve the REAL route/permission plan
|
|
484
|
-
// (no spawn) — NOT the hardcoded RequirementUnmet stub. Golden: launch/core.py dry_run resolves
|
|
485
|
-
// routing + permissions without starting any process.
|
|
486
|
-
#[test]
|
|
487
|
-
fn launch_dry_run_resolves_real_plan_not_stub_error() {
|
|
488
|
-
let team = quick_start_team_dir(QS_VALID_ROLE);
|
|
489
|
-
let spec = crate::compiler::compile_team(&team).expect("compile the seeded valid team");
|
|
490
|
-
let spec_path = team.join("team.spec.yaml");
|
|
491
|
-
std::fs::write(&spec_path, crate::model::yaml::dumps(&spec)).unwrap();
|
|
492
|
-
|
|
493
|
-
let result = launch(&spec_path, true, true, true);
|
|
494
|
-
|
|
495
|
-
match result {
|
|
496
|
-
Err(LifecycleError::RequirementUnmet(msg)) if msg.contains("not available") => {
|
|
497
|
-
panic!("launch returned the hardcoded stub error; the real dry_run plan was never resolved");
|
|
498
|
-
}
|
|
499
|
-
Ok(report) => {
|
|
500
|
-
assert!(report.dry_run, "dry_run launch must report dry_run=true");
|
|
501
|
-
assert!(
|
|
502
|
-
!report.routes.is_empty(),
|
|
503
|
-
"dry_run launch must resolve a real route plan from the compiled spec"
|
|
504
|
-
);
|
|
505
|
-
}
|
|
506
|
-
// any OTHER Err (a real requirement/transport error) still proves the stub is gone.
|
|
507
|
-
Err(_) => {}
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
// P1 — start_agent must PROCEED past the owner gate for a no-owner workspace (check_team_owner →
|
|
512
|
-
// None = allowed). The stub hard-returns OwnerRefused unconditionally. Golden: lifecycle/start.py
|
|
513
|
-
// runs under the owner gate, then the resume-or-fresh decision. (The resume/fresh PLAN + real
|
|
514
|
-
// spawn is the #[ignore] OS boundary — see quick_start_full_ready_real_spawn.)
|
|
515
|
-
#[test]
|
|
516
|
-
fn start_agent_proceeds_past_owner_gate_for_unowned_workspace() {
|
|
517
|
-
let ws = unowned_running_ws();
|
|
518
|
-
let transport = OfflineTransport::new();
|
|
519
|
-
let result = start_agent_with_transport(
|
|
520
|
-
&ws,
|
|
521
|
-
&AgentId::new("w1"),
|
|
522
|
-
false,
|
|
523
|
-
false,
|
|
524
|
-
true,
|
|
525
|
-
None,
|
|
526
|
-
&transport,
|
|
527
|
-
);
|
|
528
|
-
assert!(
|
|
529
|
-
!matches!(result, Err(LifecycleError::OwnerRefused(_))),
|
|
530
|
-
"start_agent must reach the real chain for a no-owner workspace, not hard-refuse owner; got {result:?}"
|
|
531
|
-
);
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
// P1 — restart (Route B) must PROCEED past the owner gate for a no-owner workspace. Stub →
|
|
535
|
-
// OwnerRefused. Golden: restart/orchestration.py runs the resume-selection under the owner gate.
|
|
536
|
-
#[test]
|
|
537
|
-
fn restart_proceeds_past_owner_gate_for_unowned_workspace() {
|
|
538
|
-
let ws = unowned_running_ws();
|
|
539
|
-
let transport = OfflineTransport::new();
|
|
540
|
-
let result = restart_with_transport(&ws, true, None, &transport);
|
|
541
|
-
assert!(
|
|
542
|
-
!matches!(result, Err(LifecycleError::OwnerRefused(_))),
|
|
543
|
-
"restart must reach the real Route-B chain for a no-owner workspace; got {result:?}"
|
|
544
|
-
);
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
// P1 — add_agent must PROCEED past the owner gate (no-owner ws) and reach the real recompile chain.
|
|
548
|
-
// Stub → OwnerRefused. Golden: lifecycle/operations.py:add_agent recompiles the role doc into the
|
|
549
|
-
// spec under the owner gate.
|
|
550
|
-
#[test]
|
|
551
|
-
fn add_agent_proceeds_past_owner_gate_and_reaches_recompile() {
|
|
552
|
-
let ws = unowned_running_ws();
|
|
553
|
-
let role = ws.join("w2-role.md");
|
|
554
|
-
std::fs::write(
|
|
555
|
-
&role,
|
|
556
|
-
"---\nname: w2\nrole: Second Worker\nprovider: fake\nmodel: fake\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nSecond worker.\n",
|
|
557
|
-
)
|
|
558
|
-
.unwrap();
|
|
559
|
-
let transport = OfflineTransport::new();
|
|
560
|
-
let result = add_agent_with_transport(&ws, &AgentId::new("w2"), &role, false, None, &transport);
|
|
561
|
-
assert!(
|
|
562
|
-
!matches!(result, Err(LifecycleError::OwnerRefused(_))),
|
|
563
|
-
"add_agent must reach the real recompile chain for a no-owner workspace; got {result:?}"
|
|
564
|
-
);
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
// P1 — fork_agent must PROCEED past the owner gate (no-owner ws). Stub → OwnerRefused.
|
|
568
|
-
// Golden: lifecycle/operations.py:fork_agent native session fork under the owner gate.
|
|
569
|
-
#[test]
|
|
570
|
-
fn fork_agent_proceeds_past_owner_gate_for_unowned_workspace() {
|
|
571
|
-
let ws = unowned_running_ws();
|
|
572
|
-
let transport = OfflineTransport::new();
|
|
573
|
-
let result = fork_agent_with_transport(
|
|
574
|
-
&ws,
|
|
575
|
-
&AgentId::new("w1"),
|
|
576
|
-
&AgentId::new("w1-fork"),
|
|
577
|
-
None,
|
|
578
|
-
false,
|
|
579
|
-
None,
|
|
580
|
-
&transport,
|
|
581
|
-
);
|
|
582
|
-
assert!(
|
|
583
|
-
!matches!(result, Err(LifecycleError::OwnerRefused(_))),
|
|
584
|
-
"fork_agent must reach the real native-fork chain for a no-owner workspace; got {result:?}"
|
|
585
|
-
);
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
// REAL-MACHINE boundary (acceptance framework): a full quick_start that actually LAUNCHES workers
|
|
589
|
-
// needs a live tmux + provider spawn — db/state seeding + the Ready report happen INSIDE launch()'s
|
|
590
|
-
// real spawn. Asserted by the acceptance crate, not here (do NOT fake the spawn).
|
|
591
|
-
#[test]
|
|
592
|
-
#[ignore = "real-machine: full quick_start Ready needs a live tmux + provider spawn (db/state seeding \
|
|
593
|
-
happens inside launch's real spawn). Acceptance-crate boundary, not a unit RED."]
|
|
594
|
-
fn quick_start_full_ready_real_spawn() {
|
|
595
|
-
let team = quick_start_team_dir(QS_VALID_ROLE);
|
|
596
|
-
let report = quick_start(&team, None, true, None).expect("quick_start launches the team");
|
|
597
|
-
assert!(
|
|
598
|
-
matches!(report, QuickStartReport::Ready { .. }),
|
|
599
|
-
"got {report:?}"
|
|
600
|
-
);
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
// ═════════════════════════════════════════════════════════════════════════
|
|
604
|
-
// SPINE-WIRING (③ review→fix) RED — lifecycle wiring divergences vs golden v0.2.11
|
|
605
|
-
// (diagnose/quick_start.py, launch/core.py + config.py + routing.py, restart/orchestration.py,
|
|
606
|
-
// lifecycle/operations.py). /tmp/spine_divergences.md #8/#15, #10, #12, #13, #14.
|
|
607
|
-
// ═════════════════════════════════════════════════════════════════════════
|
|
608
|
-
|
|
609
|
-
const QS_TEAM_MD_DANGEROUS: &str =
|
|
610
|
-
"---\nname: dangerteam\nobjective: Dangerous.\nprovider: codex\ndangerous_auto_approve: true\n---\n\nteam.\n";
|
|
611
|
-
|
|
612
|
-
fn quick_start_team_dir_custom(team_md: &str, role_doc: &str) -> PathBuf {
|
|
613
|
-
let team = temp_ws().join("teamdir");
|
|
614
|
-
std::fs::create_dir_all(team.join("agents")).unwrap();
|
|
615
|
-
std::fs::write(team.join("TEAM.md"), team_md).unwrap();
|
|
616
|
-
std::fs::write(team.join("agents").join("implementer.md"), role_doc).unwrap();
|
|
617
|
-
team
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
fn compiled_spec_path(team: &std::path::Path) -> PathBuf {
|
|
621
|
-
let spec = crate::compiler::compile_team(team).expect("compile team");
|
|
622
|
-
let spec_path = team.join("team.spec.yaml");
|
|
623
|
-
std::fs::write(&spec_path, crate::model::yaml::dumps(&spec)).unwrap();
|
|
624
|
-
spec_path
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
fn raw_runtime_state(workspace: &std::path::Path) -> (String, serde_json::Value) {
|
|
628
|
-
let state_path = crate::model::paths::runtime_dir(workspace).join("state.json");
|
|
629
|
-
let raw = std::fs::read_to_string(&state_path)
|
|
630
|
-
.unwrap_or_else(|e| panic!("read state.json at {}: {e}", state_path.display()));
|
|
631
|
-
let state = serde_json::from_str(&raw).expect("state.json must parse");
|
|
632
|
-
(raw, state)
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
struct EnvVarGuard {
|
|
636
|
-
key: &'static str,
|
|
637
|
-
previous: Option<String>,
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
impl EnvVarGuard {
|
|
641
|
-
fn set(key: &'static str, value: &str) -> Self {
|
|
642
|
-
let previous = std::env::var(key).ok();
|
|
643
|
-
unsafe {
|
|
644
|
-
std::env::set_var(key, value);
|
|
645
|
-
}
|
|
646
|
-
Self { key, previous }
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
fn unset(key: &'static str) -> Self {
|
|
650
|
-
let previous = std::env::var(key).ok();
|
|
651
|
-
unsafe {
|
|
652
|
-
std::env::remove_var(key);
|
|
653
|
-
}
|
|
654
|
-
Self { key, previous }
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
impl Drop for EnvVarGuard {
|
|
659
|
-
fn drop(&mut self) {
|
|
660
|
-
unsafe {
|
|
661
|
-
if let Some(value) = self.previous.take() {
|
|
662
|
-
std::env::set_var(self.key, value);
|
|
663
|
-
} else {
|
|
664
|
-
std::env::remove_var(self.key);
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
fn compiled_spec_path_with_paused_agent(team: &std::path::Path) -> PathBuf {
|
|
671
|
-
let mut spec = crate::compiler::compile_team(team).expect("compile team");
|
|
672
|
-
let crate::model::yaml::Value::Map(root) = &mut spec else {
|
|
673
|
-
panic!("compiled spec must be a map");
|
|
674
|
-
};
|
|
675
|
-
let agents = root
|
|
676
|
-
.iter_mut()
|
|
677
|
-
.find(|(key, _)| key == "agents")
|
|
678
|
-
.and_then(|(_, value)| match value {
|
|
679
|
-
crate::model::yaml::Value::List(agents) => Some(agents),
|
|
680
|
-
_ => None,
|
|
681
|
-
})
|
|
682
|
-
.expect("compiled spec must contain agents");
|
|
683
|
-
let first = agents
|
|
684
|
-
.first_mut()
|
|
685
|
-
.expect("compiled spec must contain an agent");
|
|
686
|
-
let crate::model::yaml::Value::Map(agent) = first else {
|
|
687
|
-
panic!("compiled agent must be a map");
|
|
688
|
-
};
|
|
689
|
-
agent.push(("paused".to_string(), crate::model::yaml::Value::Bool(true)));
|
|
690
|
-
let spec_path = team.join("team.spec.yaml");
|
|
691
|
-
std::fs::write(&spec_path, crate::model::yaml::dumps(&spec)).unwrap();
|
|
692
|
-
spec_path
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
fn unowned_running_ws_all_paused() -> PathBuf {
|
|
696
|
-
let ws = temp_ws();
|
|
697
|
-
crate::state::persist::save_runtime_state(
|
|
698
|
-
&ws,
|
|
699
|
-
&json!({
|
|
700
|
-
"session_name": "team-x",
|
|
701
|
-
"agents": { "w1": { "provider": "fake", "role": "Worker", "model": "fake", "auth_mode": "subscription", "status": "paused" } },
|
|
702
|
-
}),
|
|
703
|
-
)
|
|
704
|
-
.unwrap();
|
|
705
|
-
let _ = crate::message_store::MessageStore::open(&ws).unwrap();
|
|
706
|
-
ws
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
// #15 — quick_start seeds runtime state under team_workspace(team_dir) (the PARENT), not inside the
|
|
710
|
-
// team dir, so restart/status can locate it. Golden quick_start.py:35 team_workspace(team_dir).
|
|
711
|
-
#[test]
|
|
712
|
-
#[serial(env)]
|
|
713
|
-
fn spine_quick_start_seeds_state_under_team_workspace_not_team_dir() {
|
|
714
|
-
let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("launch-spawn-spine-workspace");
|
|
715
|
-
let team = quick_start_team_dir(QS_VALID_ROLE); // <base>/teamdir
|
|
716
|
-
seed_healthy_coordinator(&crate::model::paths::team_workspace(&team).unwrap());
|
|
717
|
-
let transport = OfflineTransport::new();
|
|
718
|
-
let _ = quick_start_with_transport(&team, None, true, None, &transport);
|
|
719
|
-
let workspace = team.parent().unwrap(); // team_workspace(<base>/teamdir) = <base>
|
|
720
|
-
let ws_state = crate::model::paths::runtime_dir(workspace).join("state.json");
|
|
721
|
-
assert!(
|
|
722
|
-
ws_state.exists(),
|
|
723
|
-
"quick_start must seed runtime state under team_workspace(team_dir)={} (not inside the team dir)",
|
|
724
|
-
workspace.display()
|
|
725
|
-
);
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
// #10 removed — launch dry-run safety was derived from spec.runtime.dangerous_auto_approve.
|
|
729
|
-
// 0.5.66 bypass 单源:该字段废弃,safety 改由 per-agent `dangerously_skip_permissions` 派生。
|
|
730
|
-
|
|
731
|
-
// #12 — launch dry-run produces one RoutingDecision PER spec.task via route_task, with the real task id
|
|
732
|
-
// and the route_task reason taxonomy — not one synthetic 'default_assignee' route. Golden core.py:77-88.
|
|
733
|
-
#[test]
|
|
734
|
-
fn spine_launch_dry_run_routes_one_per_task_with_route_reason() {
|
|
735
|
-
let team = quick_start_team_dir(QS_VALID_ROLE);
|
|
736
|
-
let spec_path = compiled_spec_path(&team);
|
|
737
|
-
let report = launch(&spec_path, true, true, true).expect("dry_run launch");
|
|
738
|
-
// compile_team emits one task 'task_initial' assigned to 'implementer' → reason 'explicit assignee on task'.
|
|
739
|
-
let route = report
|
|
740
|
-
.routes
|
|
741
|
-
.iter()
|
|
742
|
-
.find(|r| r.task_id.as_deref() == Some("task_initial"))
|
|
743
|
-
.unwrap_or_else(|| panic!("a route for task_initial expected; got {:?}", report.routes));
|
|
744
|
-
assert_eq!(
|
|
745
|
-
route.reason, "explicit assignee on task",
|
|
746
|
-
"the route reason must come from route_task, not the hardcoded 'default_assignee'"
|
|
747
|
-
);
|
|
748
|
-
assert_eq!(route.selected_agent.as_str(), "implementer");
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
// #13 — an empty/all-paused restart decision set is NOT an atomic refusal (remove the empty-decisions
|
|
752
|
-
// clause); only a non-empty unresumable set (and !allow_fresh) refuses. Golden orchestration.py.
|
|
753
|
-
#[test]
|
|
754
|
-
fn spine_restart_empty_team_is_not_atomic_refusal() {
|
|
755
|
-
let ws = unowned_running_ws_all_paused();
|
|
756
|
-
let transport = OfflineTransport::new();
|
|
757
|
-
let result = restart_with_transport(&ws, true, None, &transport);
|
|
758
|
-
assert!(
|
|
759
|
-
!matches!(result, Ok(RestartReport::RefusedResumeAtomicity { .. })),
|
|
760
|
-
"an all-paused/empty team must NOT yield an atomic refusal (empty decision set is not a refusal); got {result:?}"
|
|
761
|
-
);
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
// E25 — add_agent duplicate membership is runtime-state based, not role-doc/spec-file based.
|
|
765
|
-
#[test]
|
|
766
|
-
fn spine_add_agent_rejects_duplicate_agent_id() {
|
|
767
|
-
let team = quick_start_team_dir(QS_VALID_ROLE); // team already has agent 'implementer'
|
|
768
|
-
crate::state::persist::save_runtime_state(
|
|
769
|
-
&team,
|
|
770
|
-
&json!({
|
|
771
|
-
"session_name": "team-quickteam",
|
|
772
|
-
"agents": {
|
|
773
|
-
"implementer": {"status": "running", "provider": "fake", "window": "implementer"}
|
|
774
|
-
}
|
|
775
|
-
}),
|
|
776
|
-
)
|
|
777
|
-
.unwrap();
|
|
778
|
-
let role = team.join("dup-role.md");
|
|
779
|
-
std::fs::write(&role, QS_VALID_ROLE).unwrap(); // a role doc named 'implementer' = duplicate
|
|
780
|
-
let transport = OfflineTransport::new();
|
|
781
|
-
let result = add_agent_with_transport(
|
|
782
|
-
&team,
|
|
783
|
-
&AgentId::new("implementer"),
|
|
784
|
-
&role,
|
|
785
|
-
false,
|
|
786
|
-
None,
|
|
787
|
-
&transport,
|
|
788
|
-
);
|
|
789
|
-
let text = format!("{result:?}");
|
|
790
|
-
assert!(
|
|
791
|
-
text.contains("already exists"),
|
|
792
|
-
"add_agent must reject an id already present in runtime state; got {text}"
|
|
793
|
-
);
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
// E5 Bug1 — add-agent must NOT copy the external role file into <team_dir>/agents (the
|
|
797
|
-
// self-copy O_TRUNC truncation reproduced on real machine), and must still inject the new
|
|
798
|
-
// agent into the compiled spec by reading the role file in place.
|
|
799
|
-
#[test]
|
|
800
|
-
fn e5_add_agent_does_not_copy_role_into_platform_dir_and_injects_into_spec() {
|
|
801
|
-
let team = quick_start_team_dir(QS_VALID_ROLE);
|
|
802
|
-
seed_canonical_team_identity(&team, "teamdir");
|
|
803
|
-
// External role file OUTSIDE team_dir/agents, with recognizable body content.
|
|
804
|
-
let role = team.parent().unwrap().join("w2-external-role.md");
|
|
805
|
-
let role_body = "---\nname: w2\nrole: Second Worker\nprovider: fake\nmodel: fake\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nUNIQUE-E5-BUG1-MARKER body for w2.\n";
|
|
806
|
-
std::fs::write(&role, role_body).unwrap();
|
|
807
|
-
let transport = OfflineTransport::new();
|
|
808
|
-
// The spawn may not complete under OfflineTransport; we only assert the no-copy + spec-inject
|
|
809
|
-
// observables, which happen BEFORE spawn. Ignore the spawn-stage Result.
|
|
810
|
-
let _ = add_agent_with_transport(&team, &AgentId::new("w2"), &role, false, None, &transport);
|
|
811
|
-
|
|
812
|
-
// (1) No copy landed in the platform agents dir.
|
|
813
|
-
let copied = team.join("agents").join("w2.md");
|
|
814
|
-
assert!(
|
|
815
|
-
!copied.exists(),
|
|
816
|
-
"add-agent must NOT copy the role file into <team_dir>/agents (anti-pattern + O_TRUNC bug)"
|
|
817
|
-
);
|
|
818
|
-
// (2) The external role file is untouched (not truncated by a self-copy).
|
|
819
|
-
assert_eq!(
|
|
820
|
-
std::fs::read_to_string(&role).unwrap(),
|
|
821
|
-
role_body,
|
|
822
|
-
"external role file must be left intact (no truncating self-copy)"
|
|
823
|
-
);
|
|
824
|
-
// (3) The compiled spec (under .team/runtime/<team_key>/, NOT the user team dir) carries w2.
|
|
825
|
-
let runtime_spec = find_runtime_spec(&team, "teamdir").expect("runtime spec written");
|
|
826
|
-
let spec_text = std::fs::read_to_string(&runtime_spec).unwrap();
|
|
827
|
-
assert!(
|
|
828
|
-
spec_text.contains("w2"),
|
|
829
|
-
"compiled spec must inject the new agent w2 (read in place, not copied); spec=\n{spec_text}"
|
|
830
|
-
);
|
|
831
|
-
assert!(
|
|
832
|
-
!team.join("team.spec.yaml").exists(),
|
|
833
|
-
"E5: add_agent must NOT write spec into the user team dir"
|
|
834
|
-
);
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
// E5 task#3 / E4 — restart rebuilds the runtime spec from role docs EVERY time: editing a role
|
|
838
|
-
// doc (here: rename a role) is reflected in the freshly-written runtime spec after restart.
|
|
839
|
-
#[test]
|
|
840
|
-
fn e5_restart_rebuilds_runtime_spec_from_role_docs() {
|
|
841
|
-
let ws = restart_ws_two_resumable_workers(); // has TEAM.md + agents/{alpha,bravo}.md + state
|
|
842
|
-
// Edit a role doc AFTER initial compile: change alpha's role text.
|
|
843
|
-
std::fs::write(
|
|
844
|
-
ws.join("agents").join("alpha.md"),
|
|
845
|
-
"---\nname: alpha\nrole: RENAMED Alpha Role\nprovider: fake\nmodel: fake\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nAlpha edited.\n",
|
|
846
|
-
)
|
|
847
|
-
.unwrap();
|
|
848
|
-
let transport = OfflineTransport::new();
|
|
849
|
-
let _ = restart_with_transport(&ws, false, None, &transport);
|
|
850
|
-
// The runtime spec (rebuilt from role docs) must carry the edited role text.
|
|
851
|
-
let runtime_spec = find_runtime_spec(&ws, "restartteam").expect("runtime spec rebuilt");
|
|
852
|
-
let spec_text = std::fs::read_to_string(&runtime_spec).unwrap();
|
|
853
|
-
assert!(
|
|
854
|
-
spec_text.contains("RENAMED Alpha Role"),
|
|
855
|
-
"restart must rebuild runtime spec from role docs (E4: TEAM.md/role edits take effect); spec=\n{spec_text}"
|
|
856
|
-
);
|
|
857
|
-
assert!(
|
|
858
|
-
!ws.join("team.spec.yaml").exists(),
|
|
859
|
-
"E5: rebuilt spec must land in .team/runtime, not the user team dir"
|
|
860
|
-
);
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
// RED-2 (P0) — restart existence gate must use selected.spec_path (read-order B: runtime spec),
|
|
864
|
-
// NOT the user-dir team.spec.yaml. spec-demote put spec under .team/runtime/<key>/, so the old
|
|
865
|
-
// pre-resolve gate (`!workspace.join("team.spec.yaml").exists()`) falsely reported "missing spec".
|
|
866
|
-
#[test]
|
|
867
|
-
fn red2_restart_finds_runtime_spec_not_missing_when_user_dir_has_no_spec() {
|
|
868
|
-
let ws = restart_ws_two_resumable_workers(); // has TEAM.md + agents + state
|
|
869
|
-
// Simulate spec-demote: remove any user-dir spec the fixture wrote; restart must still find
|
|
870
|
-
// the runtime spec (rebuilt from role docs / read-order B), NOT report "missing spec".
|
|
871
|
-
let _ = std::fs::remove_file(ws.join("team.spec.yaml"));
|
|
872
|
-
assert!(
|
|
873
|
-
!ws.join("team.spec.yaml").exists(),
|
|
874
|
-
"user-dir spec removed (spec-demote condition)"
|
|
875
|
-
);
|
|
876
|
-
let transport = OfflineTransport::new();
|
|
877
|
-
let result = restart_with_transport(&ws, false, None, &transport);
|
|
878
|
-
// The gate must NOT short-circuit with "missing spec for restart" — restart must proceed
|
|
879
|
-
// (any later resume/rebuild outcome is fine; we only assert the spec-missing gate is gone).
|
|
880
|
-
let text = format!("{result:?}");
|
|
881
|
-
assert!(
|
|
882
|
-
!text.contains("missing spec for restart"),
|
|
883
|
-
"RED-2: restart must locate the runtime spec via read-order B, not report missing; got {text}"
|
|
884
|
-
);
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
// RED-2 negative — a truly empty workspace (no role docs, no spec, no state) must STILL report
|
|
888
|
-
// missing spec (gate moved, not removed).
|
|
889
|
-
#[test]
|
|
890
|
-
fn red2_restart_empty_workspace_still_reports_missing() {
|
|
891
|
-
let ws = temp_ws(); // empty, no TEAM.md/agents/spec/state
|
|
892
|
-
let transport = OfflineTransport::new();
|
|
893
|
-
let result = restart_with_transport(&ws, false, None, &transport);
|
|
894
|
-
let text = format!("{result:?}");
|
|
895
|
-
assert!(
|
|
896
|
-
text.contains("missing spec")
|
|
897
|
-
|| text.to_lowercase().contains("not found")
|
|
898
|
-
|| text.contains("no_local_team_context")
|
|
899
|
-
|| text.to_lowercase().contains("invalid workspace")
|
|
900
|
-
|| text.contains("role definitions missing"),
|
|
901
|
-
"RED-2 negative: empty workspace restart must still error (missing/not-found); got {text}"
|
|
902
|
-
);
|
|
903
|
-
let _ = std::fs::remove_dir_all(&ws);
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
// RED-2-STILL (P0) — the ENTRY gate (input_has_no_local_team_context) must judge on the
|
|
907
|
-
// canonical_run_workspace-resolved path, not raw. quick-start <team_dir> lands .team under the
|
|
908
|
-
// resolved workspace (team_dir's parent when invoked from there); restart <team_dir> with raw gate
|
|
909
|
-
// checks team_dir's own (empty) .team → false "no context" early-exit before the down-moved gate.
|
|
910
|
-
//
|
|
911
|
-
// Two forms (leader hard requirement — must lock BOTH, not the coincidental same-dir form):
|
|
912
|
-
// Form A: .team in the team_dir's PARENT (standard quick-start <dir> from parent cwd).
|
|
913
|
-
// Form B: .team in the team_dir itself (cwd == team_dir).
|
|
914
|
-
#[test]
|
|
915
|
-
fn red2still_entry_gate_resolves_parent_dot_team_form_a() {
|
|
916
|
-
// Build: base/ (has .team) + base/teamdir/{TEAM.md, agents/} (role docs, NO own .team).
|
|
917
|
-
let base = temp_ws();
|
|
918
|
-
let team_dir = base.join("teamdir");
|
|
919
|
-
std::fs::create_dir_all(team_dir.join("agents")).unwrap();
|
|
920
|
-
std::fs::write(
|
|
921
|
-
team_dir.join("TEAM.md"),
|
|
922
|
-
"---\nname: teamdir\nobjective: o\nprovider: codex\n---\nt.\n",
|
|
923
|
-
)
|
|
924
|
-
.unwrap();
|
|
925
|
-
std::fs::write(team_dir.join("agents").join("w1.md"), QS_VALID_ROLE).unwrap();
|
|
926
|
-
// .team lives in the PARENT (base), with a runtime spec — mirrors quick-start <dir> from base cwd.
|
|
927
|
-
let spec = crate::compiler::compile_team(&team_dir).unwrap();
|
|
928
|
-
let runtime_spec = crate::model::paths::runtime_spec_path(&base, "teamdir");
|
|
929
|
-
std::fs::create_dir_all(runtime_spec.parent().unwrap()).unwrap();
|
|
930
|
-
std::fs::write(&runtime_spec, crate::model::yaml::dumps(&spec)).unwrap();
|
|
931
|
-
// Seed minimal team state under base so resolve finds it.
|
|
932
|
-
crate::state::persist::save_runtime_state(
|
|
933
|
-
&base,
|
|
934
|
-
&json!({"session_name": "team-teamdir", "team_dir": team_dir.to_string_lossy(),
|
|
935
|
-
"spec_path": runtime_spec.to_string_lossy(),
|
|
936
|
-
"agents": {"w1": {"status": "running", "provider": "fake"}}}),
|
|
937
|
-
)
|
|
938
|
-
.unwrap();
|
|
939
|
-
// Entry gate on team_dir: raw team_dir has NO .team (it's in parent), but resolved → base has it.
|
|
940
|
-
assert!(
|
|
941
|
-
crate::lifecycle::restart::input_has_no_local_team_context(&team_dir),
|
|
942
|
-
"precondition: raw team_dir has no local .team (it's in the parent)"
|
|
943
|
-
);
|
|
944
|
-
let resolved = crate::model::paths::canonical_run_workspace(&team_dir).unwrap();
|
|
945
|
-
assert!(
|
|
946
|
-
!crate::lifecycle::restart::input_has_no_local_team_context(&resolved),
|
|
947
|
-
"RED-2-STILL: gate on canonical_run_workspace-resolved path must see parent .team (false)"
|
|
948
|
-
);
|
|
949
|
-
// Full restart on team_dir must NOT early-exit with missing spec.
|
|
950
|
-
let transport = OfflineTransport::new();
|
|
951
|
-
let text = format!(
|
|
952
|
-
"{:?}",
|
|
953
|
-
restart_with_transport(&team_dir, false, None, &transport)
|
|
954
|
-
);
|
|
955
|
-
assert!(
|
|
956
|
-
!text.contains("missing spec for restart") && !text.contains("active team spec not found"),
|
|
957
|
-
"RED-2-STILL Form A: restart <team_dir> (.team in parent) must not report missing; got {text}"
|
|
958
|
-
);
|
|
959
|
-
let _ = std::fs::remove_dir_all(&base);
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
#[test]
|
|
963
|
-
fn red2still_entry_gate_same_dir_dot_team_form_b() {
|
|
964
|
-
// Form B: .team in team_dir itself (cwd == team_dir at quick-start time).
|
|
965
|
-
let team_dir = temp_ws();
|
|
966
|
-
std::fs::create_dir_all(team_dir.join("agents")).unwrap();
|
|
967
|
-
std::fs::write(
|
|
968
|
-
team_dir.join("TEAM.md"),
|
|
969
|
-
"---\nname: tb\nobjective: o\nprovider: codex\n---\nt.\n",
|
|
970
|
-
)
|
|
971
|
-
.unwrap();
|
|
972
|
-
std::fs::write(team_dir.join("agents").join("w1.md"), QS_VALID_ROLE).unwrap();
|
|
973
|
-
let spec = crate::compiler::compile_team(&team_dir).unwrap();
|
|
974
|
-
let runtime_spec = crate::model::paths::runtime_spec_path(&team_dir, "tb");
|
|
975
|
-
std::fs::create_dir_all(runtime_spec.parent().unwrap()).unwrap();
|
|
976
|
-
std::fs::write(&runtime_spec, crate::model::yaml::dumps(&spec)).unwrap();
|
|
977
|
-
crate::state::persist::save_runtime_state(
|
|
978
|
-
&team_dir,
|
|
979
|
-
&json!({"session_name": "team-tb", "team_dir": team_dir.to_string_lossy(),
|
|
980
|
-
"spec_path": runtime_spec.to_string_lossy(),
|
|
981
|
-
"agents": {"w1": {"status": "running", "provider": "fake"}}}),
|
|
982
|
-
)
|
|
983
|
-
.unwrap();
|
|
984
|
-
let transport = OfflineTransport::new();
|
|
985
|
-
let text = format!(
|
|
986
|
-
"{:?}",
|
|
987
|
-
restart_with_transport(&team_dir, false, None, &transport)
|
|
988
|
-
);
|
|
989
|
-
assert!(
|
|
990
|
-
!text.contains("missing spec for restart") && !text.contains("active team spec not found"),
|
|
991
|
-
"RED-2-STILL Form B: restart <team_dir> (.team in team_dir) must not report missing; got {text}"
|
|
992
|
-
);
|
|
993
|
-
let _ = std::fs::remove_dir_all(&team_dir);
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
// E5 task#3 / RC-A6b — restart with role definitions MISSING explicitly refuses (lists what's
|
|
997
|
-
// missing) and leaves the previous runtime spec in place (no silent path, no data destruction).
|
|
998
|
-
#[test]
|
|
999
|
-
fn e5_restart_missing_role_docs_refuses_and_preserves_old_spec() {
|
|
1000
|
-
let ws = restart_ws_two_resumable_workers();
|
|
1001
|
-
// Pre-seed a previous runtime spec so we can assert it survives the refusal.
|
|
1002
|
-
let prev_spec = crate::model::paths::runtime_spec_path(&ws, "restartteam");
|
|
1003
|
-
std::fs::create_dir_all(prev_spec.parent().unwrap()).unwrap();
|
|
1004
|
-
std::fs::write(&prev_spec, "PREVIOUS-RUNTIME-SPEC-MARKER\n").unwrap();
|
|
1005
|
-
// Remove the role definitions (TEAM.md) → role source gone.
|
|
1006
|
-
std::fs::remove_file(ws.join("TEAM.md")).unwrap();
|
|
1007
|
-
let transport = OfflineTransport::new();
|
|
1008
|
-
let result = restart_with_transport(&ws, false, None, &transport);
|
|
1009
|
-
let text = format!("{result:?}");
|
|
1010
|
-
assert!(
|
|
1011
|
-
text.contains("role definitions missing") || text.to_lowercase().contains("missing"),
|
|
1012
|
-
"restart with missing role docs must explicitly refuse listing what's missing; got {text}"
|
|
1013
|
-
);
|
|
1014
|
-
// Old runtime spec preserved untouched (T2: no data destruction on refusal).
|
|
1015
|
-
assert_eq!(
|
|
1016
|
-
std::fs::read_to_string(&prev_spec).unwrap(),
|
|
1017
|
-
"PREVIOUS-RUNTIME-SPEC-MARKER\n",
|
|
1018
|
-
"previous runtime spec must be left in place on refusal"
|
|
1019
|
-
);
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
#[test]
|
|
1023
|
-
fn e5_restart_missing_role_docs_refuses_even_after_endpoint_convergence_marker() {
|
|
1024
|
-
let _harness_gate =
|
|
1025
|
-
EnvVarGuard::unset("TEAM_AGENT_TEST_ENDPOINT_CONVERGENCE_HARNESS_SPEC_FALLBACK");
|
|
1026
|
-
let ws = restart_ws_two_resumable_workers();
|
|
1027
|
-
let prev_spec = crate::model::paths::runtime_spec_path(&ws, "restartteam");
|
|
1028
|
-
std::fs::create_dir_all(prev_spec.parent().unwrap()).unwrap();
|
|
1029
|
-
std::fs::write(&prev_spec, "PREVIOUS-RUNTIME-SPEC-MARKER\n").unwrap();
|
|
1030
|
-
|
|
1031
|
-
let mut state = crate::state::persist::load_runtime_state(&ws).unwrap();
|
|
1032
|
-
state["topology_convergence"] = json!({
|
|
1033
|
-
"status": "converged",
|
|
1034
|
-
"old_tmux_endpoint": "/tmp/old",
|
|
1035
|
-
"new_tmux_endpoint": "/tmp/new",
|
|
1036
|
-
"reason": "old_endpoint_dead"
|
|
1037
|
-
});
|
|
1038
|
-
crate::state::persist::save_runtime_state(&ws, &state).unwrap();
|
|
1039
|
-
std::fs::remove_file(ws.join("TEAM.md")).unwrap();
|
|
1040
|
-
|
|
1041
|
-
let result = restart_with_transport(&ws, false, None, &OfflineTransport::new());
|
|
1042
|
-
let text = format!("{result:?}");
|
|
1043
|
-
assert!(
|
|
1044
|
-
text.contains("role definitions missing"),
|
|
1045
|
-
"production marker alone must not enable runtime-spec fallback; got {text}"
|
|
1046
|
-
);
|
|
1047
|
-
assert_eq!(
|
|
1048
|
-
std::fs::read_to_string(&prev_spec).unwrap(),
|
|
1049
|
-
"PREVIOUS-RUNTIME-SPEC-MARKER\n",
|
|
1050
|
-
"previous runtime spec must be preserved on missing role docs refusal"
|
|
1051
|
-
);
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
// E5 §3 解耦(tester 场景2)— add-agent on a team whose runtime spec already exists must still
|
|
1055
|
-
// resolve team_dir to the USER role dir for compile_team (find TEAM.md/agents), not the runtime
|
|
1056
|
-
// spec dir. Regression: SelectedTeam.spec_workspace=runtime was used as team_dir → compile_team
|
|
1057
|
-
// looked for TEAM.md under .team/runtime/<key>/ → "missing TEAM.md".
|
|
1058
|
-
#[test]
|
|
1059
|
-
fn e5_add_agent_resolves_team_dir_to_role_dir_when_runtime_spec_exists() {
|
|
1060
|
-
let team = quick_start_team_dir(QS_VALID_ROLE);
|
|
1061
|
-
// Pre-create the runtime spec so the selector's runtime-first branch is taken (migrated team).
|
|
1062
|
-
let runtime_spec = quick_start_runtime_spec_path(&team);
|
|
1063
|
-
std::fs::create_dir_all(runtime_spec.parent().unwrap()).unwrap();
|
|
1064
|
-
let base = crate::compiler::compile_team(&team).unwrap();
|
|
1065
|
-
std::fs::write(&runtime_spec, crate::model::yaml::dumps(&base)).unwrap();
|
|
1066
|
-
// External role file (relative-ish, outside agents/).
|
|
1067
|
-
let role = team.join("w2-role.md");
|
|
1068
|
-
std::fs::write(
|
|
1069
|
-
&role,
|
|
1070
|
-
"---\nname: w2\nrole: Second Worker\nprovider: fake\nmodel: fake\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nw2.\n",
|
|
1071
|
-
)
|
|
1072
|
-
.unwrap();
|
|
1073
|
-
let transport = OfflineTransport::new();
|
|
1074
|
-
let result =
|
|
1075
|
-
add_agent_with_transport(&team, &AgentId::new("w2"), &role, false, None, &transport);
|
|
1076
|
-
// Core decoupling signature: must NOT fail because compile_team looked for TEAM.md/agents under
|
|
1077
|
-
// the runtime spec dir. Before the fix, team_dir=spec_workspace(runtime) → "missing TEAM.md".
|
|
1078
|
-
let text = format!("{result:?}");
|
|
1079
|
-
assert!(
|
|
1080
|
-
!text.contains("missing TEAM.md") && !text.to_lowercase().contains("missing agents"),
|
|
1081
|
-
"add-agent must resolve team_dir to the role dir for compile_team (not the runtime spec dir); got {text}"
|
|
1082
|
-
);
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
// E5 grep guard G1 — writers must land spec via runtime_spec_path (.team/runtime/<team_key>/),
|
|
1086
|
-
// never write team.spec.yaml into the user team_dir/agents_dir. Pins the spec-demote invariant.
|
|
1087
|
-
#[test]
|
|
1088
|
-
fn e5_guard_g1_writers_use_runtime_spec_path_not_user_dir() {
|
|
1089
|
-
let source = launch_source();
|
|
1090
|
-
let runtime_writes = source.matches("runtime_spec_path(").count();
|
|
1091
|
-
assert!(
|
|
1092
|
-
runtime_writes >= 2,
|
|
1093
|
-
"G1: quick_start + add_agent must write spec via runtime_spec_path (found {runtime_writes})"
|
|
1094
|
-
);
|
|
1095
|
-
for forbidden in [
|
|
1096
|
-
"let spec_path = agents_dir.join(\"team.spec.yaml\");\n std::fs::write",
|
|
1097
|
-
"let spec_path = team_dir.join(\"team.spec.yaml\");\n std::fs::write",
|
|
1098
|
-
] {
|
|
1099
|
-
assert!(
|
|
1100
|
-
!source.contains(forbidden),
|
|
1101
|
-
"G1: user-dir spec write idiom must be gone: {forbidden:?}"
|
|
1102
|
-
);
|
|
1103
|
-
}
|
|
1104
|
-
}
|
|
1105
|
-
|
|
1106
|
-
// E5 grep guard G2 — launch.rs must NOT copy a role file into the platform team dir.
|
|
1107
|
-
// Pins the Bug1 fix: no `fs::copy` of a role file + no `materialize_added_role_file` reborn.
|
|
1108
|
-
#[test]
|
|
1109
|
-
fn e5_guard_g2_no_copy_role_into_platform_dir() {
|
|
1110
|
-
let source = launch_source();
|
|
1111
|
-
assert!(
|
|
1112
|
-
!source.contains("materialize_added_role_file"),
|
|
1113
|
-
"G2: materialize_added_role_file (role copy anti-pattern) must stay deleted"
|
|
1114
|
-
);
|
|
1115
|
-
assert!(
|
|
1116
|
-
!source.contains("copy role file"),
|
|
1117
|
-
"G2: no 'copy role file' into the platform agents dir (O_TRUNC self-copy bug)"
|
|
1118
|
-
);
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
// ═════════════════════════════════════════════════════════════════════════
|
|
1122
|
-
// SPAWN sub-phase RED — launch(dry_run=false) must REALLY spawn (unlocks the acceptance
|
|
1123
|
-
// framework's cheap real-machine Tier-1). Golden launch/core.py: create the session + one worker
|
|
1124
|
-
// window per agent running its provider command (with workspace + agent-id context), populate the
|
|
1125
|
-
// started list, attach the leader receiver. Today launch(dry_run=false) is the hardcoded stub
|
|
1126
|
-
// RequirementUnmet("launch spawn requires live transport/provider boundary").
|
|
1127
|
-
// ═════════════════════════════════════════════════════════════════════════
|
|
1128
|
-
|
|
1129
|
-
// P0 — launch(dry_run=false) over a real compiled spec must run the real spawn chain (create session +
|
|
1130
|
-
// spawn ≥1 worker, populating LaunchReport.started), NOT the hardcoded spawn stub. The recording-
|
|
1131
|
-
// transport spawn-CALL assertion (spawn_first/spawn_into argv) needs a transport-injection seam in
|
|
1132
|
-
// launch — flagged to the leader (launch takes no transport today); the real tmux new-session is the
|
|
1133
|
-
// #[ignore] acceptance boundary (see quick_start_full_ready_real_spawn). Here we assert the seam-
|
|
1134
|
-
// independent observable: the spawn stub is gone + LaunchReport.started is populated + dry_run=false.
|
|
1135
|
-
//
|
|
1136
|
-
// CONVERTED to #[ignore] (final real-daemon sub-phase): the porter wires PUBLIC launch() to the real
|
|
1137
|
-
// TmuxBackend (today it uses NoopLaunchTransport), so once wired this test spawns REAL tmux — a unit
|
|
1138
|
-
// test must not. The OS-edge-mocked spawn-orchestration coverage moved to
|
|
1139
|
-
// `launch_with_transport_records_one_spawn_per_agent_carrying_build_command` (recording mock transport).
|
|
1140
|
-
#[test]
|
|
1141
|
-
#[ignore = "real-machine: public launch(dry_run=false) spawns real tmux once wired to TmuxBackend; \
|
|
1142
|
-
in-process coverage is launch_with_transport_records_one_spawn_per_agent_carrying_build_command"]
|
|
1143
|
-
fn spawn_launch_not_dry_run_is_no_longer_the_spawn_stub() {
|
|
1144
|
-
let team = quick_start_team_dir(QS_VALID_ROLE);
|
|
1145
|
-
let spec_path = compiled_spec_path(&team);
|
|
1146
|
-
|
|
1147
|
-
let result = launch(&spec_path, false, true, true);
|
|
1148
|
-
|
|
1149
|
-
match result {
|
|
1150
|
-
Err(LifecycleError::RequirementUnmet(msg)) if msg.contains("requires live transport") => {
|
|
1151
|
-
panic!(
|
|
1152
|
-
"launch(dry_run=false) still returns the hardcoded spawn stub; the real spawn was never wired: {msg}"
|
|
1153
|
-
);
|
|
1154
|
-
}
|
|
1155
|
-
Ok(report) => {
|
|
1156
|
-
assert!(!report.dry_run, "a real launch must report dry_run=false");
|
|
1157
|
-
assert!(
|
|
1158
|
-
!report.started.is_empty(),
|
|
1159
|
-
"launch(dry_run=false) must spawn >=1 worker and populate LaunchReport.started; got {:?}",
|
|
1160
|
-
report.started
|
|
1161
|
-
);
|
|
1162
|
-
}
|
|
1163
|
-
// any OTHER Err (a real transport/preflight error from the wired spawn) still proves the stub is gone.
|
|
1164
|
-
Err(_) => {}
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
// ═════════════════════════════════════════════════════════════════════════
|
|
1169
|
-
// (C) public launch → real TmuxBackend. The OS edge is mocked by a RECORDING transport via the
|
|
1170
|
-
// launch_with_transport seam; the REAL TmuxBackend swap is exercised by the acceptance framework
|
|
1171
|
-
// (#[ignore] spawn_launch_not_dry_run_is_no_longer_the_spawn_stub). Golden launch/core.py.
|
|
1172
|
-
// ═════════════════════════════════════════════════════════════════════════
|
|
1173
|
-
|
|
1174
|
-
// (C) — launch_with_transport(dry_run=false, <recording transport>) creates one spawn per compiled
|
|
1175
|
-
// agent, the recorded spawn argv carries that agent's provider build_command, and LaunchReport.started
|
|
1176
|
-
// lists them. NOTE: GREEN today — spawn_agents already drives the injected transport; this LOCKS the
|
|
1177
|
-
// spawn orchestration contract (replacing the now-#[ignore]'d public-launch test's in-process coverage).
|
|
1178
|
-
// The genuine remaining gap — public launch() must construct a real TmuxBackend (today NoopLaunchTransport)
|
|
1179
|
-
// — is not cleanly assertable in-process without spawning; it rides the porter's wiring + the #[ignore]
|
|
1180
|
-
// real-machine test above.
|
|
1181
|
-
#[test]
|
|
1182
|
-
fn launch_with_transport_records_one_spawn_per_agent_carrying_build_command() {
|
|
1183
|
-
let team = quick_start_team_dir(QS_VALID_ROLE); // one agent: implementer / provider fake
|
|
1184
|
-
let spec_path = compiled_spec_path(&team);
|
|
1185
|
-
let transport = OfflineTransport::new();
|
|
1186
|
-
|
|
1187
|
-
let report = launch_with_transport(&spec_path, false, true, true, &transport)
|
|
1188
|
-
.expect("launch_with_transport must spawn against the recording transport");
|
|
1189
|
-
|
|
1190
|
-
let recorded = transport.spawn_records();
|
|
1191
|
-
assert_eq!(
|
|
1192
|
-
recorded.len(),
|
|
1193
|
-
report.started.len(),
|
|
1194
|
-
"exactly one spawn per started agent; recorded={recorded:?} started={:?}",
|
|
1195
|
-
report.started
|
|
1196
|
-
);
|
|
1197
|
-
assert!(
|
|
1198
|
-
!report.started.is_empty(),
|
|
1199
|
-
"a real (non-dry-run) launch must spawn >=1 worker"
|
|
1200
|
-
);
|
|
1201
|
-
assert!(
|
|
1202
|
-
!report.dry_run,
|
|
1203
|
-
"launch_with_transport(dry_run=false) must report dry_run=false"
|
|
1204
|
-
);
|
|
1205
|
-
assert_eq!(
|
|
1206
|
-
recorded[0].0, "spawn_first",
|
|
1207
|
-
"the first worker uses new-session (spawn_first)"
|
|
1208
|
-
);
|
|
1209
|
-
assert!(
|
|
1210
|
-
recorded
|
|
1211
|
-
.iter()
|
|
1212
|
-
.any(|(_, argv)| argv.iter().any(|a| a == "fake-worker")),
|
|
1213
|
-
"each spawn argv must carry the agent's provider build_command (fake-worker); got {recorded:?}"
|
|
1214
|
-
);
|
|
1215
|
-
assert!(
|
|
1216
|
-
report
|
|
1217
|
-
.started
|
|
1218
|
-
.iter()
|
|
1219
|
-
.any(|s| s.agent_id.as_str() == "implementer"),
|
|
1220
|
-
"LaunchReport.started must list the compiled agent; got {:?}",
|
|
1221
|
-
report.started
|
|
1222
|
-
);
|
|
1223
|
-
let workspace = crate::model::paths::team_workspace(&team).unwrap();
|
|
1224
|
-
let state = crate::state::persist::load_runtime_state(&workspace).unwrap();
|
|
1225
|
-
let generation = report.started[0].spawned_at.as_str();
|
|
1226
|
-
assert_eq!(state["generation"], generation);
|
|
1227
|
-
let team_key = crate::state::projection::team_state_key(&state);
|
|
1228
|
-
assert_eq!(state["teams"][&team_key]["generation"], generation);
|
|
1229
|
-
let owner = transport.session_owner(&SessionName::new("team-quickteam")).unwrap().unwrap();
|
|
1230
|
-
assert_eq!(owner.generation, generation);
|
|
1231
|
-
}
|
|
1232
|
-
|
|
1233
|
-
#[test]
|
|
1234
|
-
#[serial(env)]
|
|
1235
|
-
fn start_agent_session_generation_inherits_birth_or_stamps_recreated_session() {
|
|
1236
|
-
for canonical_state in [false, true] {
|
|
1237
|
-
for existing_session in [true, false] {
|
|
1238
|
-
for explicit_generation in [true, false] {
|
|
1239
|
-
let ws = restart_ws_one_resumable_worker();
|
|
1240
|
-
let mut state = crate::state::persist::load_runtime_state(&ws).unwrap();
|
|
1241
|
-
let birth = "2026-07-14T00:00:00+00:00";
|
|
1242
|
-
state["agents"]["alpha"]["status"] = json!("stopped");
|
|
1243
|
-
state["agents"]["alpha"]["spawned_at"] = json!(birth);
|
|
1244
|
-
if explicit_generation {
|
|
1245
|
-
state["generation"] = json!("explicit-session-birth");
|
|
1246
|
-
}
|
|
1247
|
-
let team_key = crate::state::projection::team_state_key(&state);
|
|
1248
|
-
if canonical_state {
|
|
1249
|
-
state["team_key"] = json!(team_key);
|
|
1250
|
-
state["active_team_key"] = json!(team_key);
|
|
1251
|
-
state["teams"] = json!({});
|
|
1252
|
-
state["teams"][&team_key] = crate::state::projection::compact_team_state(&state);
|
|
1253
|
-
}
|
|
1254
|
-
let inherited = if explicit_generation { "explicit-session-birth" } else { birth };
|
|
1255
|
-
crate::state::persist::save_runtime_state(&ws, &state).unwrap();
|
|
1256
|
-
let transport = OfflineTransport::new()
|
|
1257
|
-
.with_session_present(existing_session)
|
|
1258
|
-
.with_session_owner(&ws, &team_key, inherited);
|
|
1259
|
-
let result = start_agent_with_transport(
|
|
1260
|
-
&ws, &aid("alpha"), false, false, false, None, &transport,
|
|
1261
|
-
).unwrap();
|
|
1262
|
-
assert!(matches!(result, StartAgentOutcome::Running { .. }), "{result:?}");
|
|
1263
|
-
let state = crate::state::persist::load_runtime_state(&ws).unwrap();
|
|
1264
|
-
let spawned_at = state["agents"]["alpha"]["spawned_at"].as_str().unwrap();
|
|
1265
|
-
assert_ne!(spawned_at, birth);
|
|
1266
|
-
let expected = if existing_session { inherited } else { spawned_at };
|
|
1267
|
-
assert_eq!(state["generation"], expected);
|
|
1268
|
-
if canonical_state {
|
|
1269
|
-
assert_eq!(state["teams"][&team_key]["generation"], expected);
|
|
1270
|
-
} else {
|
|
1271
|
-
// Legacy flat state stays flat; generation persistence does
|
|
1272
|
-
// not implicitly migrate it to a canonical teams table.
|
|
1273
|
-
assert!(state.get("teams").is_none());
|
|
1274
|
-
}
|
|
1275
|
-
let owner = transport.session_owner(&SessionName::new("team-restartone")).unwrap().unwrap();
|
|
1276
|
-
assert_eq!(owner.generation, expected);
|
|
1277
|
-
assert_eq!(transport.calls().contains(&"set_session_owner_with_generation"), !existing_session);
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
// ═════════════════════════════════════════════════════════════════════════
|
|
1284
|
-
// rt-host-a REGRESSION — `team-agent quick-start` compiles+seeds but NEVER spawns workers:
|
|
1285
|
-
// quick_start_with_transport hardcodes launch dry_run=TRUE, so launch takes the started=Vec::new()
|
|
1286
|
-
// branch and spawn_agents is never called. The 788-green missed it (no test drove quick_start through
|
|
1287
|
-
// the spawn path). Golden: a real quick-start must spawn one worker per compiled agent into the session.
|
|
1288
|
-
// ═════════════════════════════════════════════════════════════════════════
|
|
1289
|
-
|
|
1290
|
-
/// Seed a HEALTHY coordinator at `workspace` (this process's pid + matching metadata + db schema) so
|
|
1291
|
-
/// quick_start's internal start_coordinator returns AlreadyRunning — NO real daemon subprocess spawn.
|
|
1292
|
-
pub(super) fn seed_healthy_coordinator(workspace: &std::path::Path) {
|
|
1293
|
-
hermetic_guard::seed_in_process_coordinator(workspace);
|
|
1294
|
-
}
|
|
1295
|
-
|
|
1296
|
-
#[test]
|
|
1297
|
-
#[cfg(unix)]
|
|
1298
|
-
#[serial(env)]
|
|
1299
|
-
fn issue337_owned_fixture_caller_admits_fresh_launch_without_guard_bypass() {
|
|
1300
|
-
let env = hermetic_guard::HermeticTestEnv::enter_with_leader("issue337-fixture-caller");
|
|
1301
|
-
let workspace = env.workspace("ws");
|
|
1302
|
-
let team = workspace.join("roles");
|
|
1303
|
-
std::fs::create_dir_all(team.join("agents")).unwrap();
|
|
1304
|
-
std::fs::write(team.join("TEAM.md"), QS_TEAM_MD).unwrap();
|
|
1305
|
-
std::fs::write(team.join("agents/implementer.md"), QS_VALID_ROLE).unwrap();
|
|
1306
|
-
seed_healthy_coordinator(&workspace);
|
|
1307
|
-
let transport = OfflineTransport::new();
|
|
1308
|
-
let report = quick_start_with_transport_in_workspace(
|
|
1309
|
-
&workspace, &team, None, true, Some("fixture-team"), &transport,
|
|
1310
|
-
).unwrap();
|
|
1311
|
-
let QuickStartReport::Ready { launch, .. } = report else { panic!("owned caller must admit launch: {report:?}") };
|
|
1312
|
-
assert!(launch.leader_receiver_attached);
|
|
1313
|
-
assert_eq!(launch.started.len(), 1);
|
|
1314
|
-
assert_eq!(transport.spawn_records().len(), 1);
|
|
1315
|
-
let socket = std::env::var("TMUX").unwrap().split(',').next().unwrap().to_string();
|
|
1316
|
-
assert!(std::path::Path::new(&socket).exists());
|
|
1317
|
-
drop(env);
|
|
1318
|
-
assert!(!std::path::Path::new(&socket).exists());
|
|
1319
|
-
}
|
|
1320
|
-
|
|
1321
|
-
fn seed_canonical_team_identity(workspace: &std::path::Path, team_key: &str) {
|
|
1322
|
-
let mut state = crate::state::persist::load_runtime_state(workspace).unwrap();
|
|
1323
|
-
state["active_team_key"] = json!(team_key);
|
|
1324
|
-
crate::state::persist::save_runtime_state(workspace, &state).unwrap();
|
|
1325
|
-
}
|
|
1326
|
-
|
|
1327
|
-
// RED — quick_start_with_transport must drive the REAL spawn path: launch.dry_run==false, started
|
|
1328
|
-
// non-empty (one per compiled agent), and the transport records >=1 spawn carrying that agent's
|
|
1329
|
-
// provider build_command. Today the dry_run=true bug -> launch.started empty + ZERO spawns recorded ->
|
|
1330
|
-
// RED at assertion (NOT a panic). OS-safe: recording transport (no real tmux) + seeded-healthy
|
|
1331
|
-
// coordinator (start_coordinator AlreadyRunning -> no daemon subprocess).
|
|
1332
|
-
#[test]
|
|
1333
|
-
#[serial(env)]
|
|
1334
|
-
fn quick_start_with_transport_spawns_workers_not_dry_run() {
|
|
1335
|
-
let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("launch-spawn-spawn-path");
|
|
1336
|
-
let team = quick_start_team_dir(QS_VALID_ROLE); // one agent: implementer / provider fake
|
|
1337
|
-
let workspace = team.parent().expect("team_workspace(team_dir) = parent"); // where start_coordinator runs
|
|
1338
|
-
seed_healthy_coordinator(workspace);
|
|
1339
|
-
let transport = OfflineTransport::new();
|
|
1340
|
-
|
|
1341
|
-
let report = quick_start_with_transport(&team, None, true, None, &transport)
|
|
1342
|
-
.expect("quick_start_with_transport must reach a report");
|
|
1343
|
-
|
|
1344
|
-
let launch = match report {
|
|
1345
|
-
QuickStartReport::Ready { launch, .. } => *launch,
|
|
1346
|
-
other => panic!("quick_start must reach Ready (the spawn path); got {other:?}"),
|
|
1347
|
-
};
|
|
1348
|
-
// (1) the rt-host-a bug: launch dry_run hardcoded true -> this is the load-bearing regression assert.
|
|
1349
|
-
assert!(
|
|
1350
|
-
!launch.dry_run,
|
|
1351
|
-
"quick_start must SPAWN workers (launch.dry_run == false); the rt-host-a bug hardcodes dry_run=true \
|
|
1352
|
-
so launch takes the empty started branch and never spawns"
|
|
1353
|
-
);
|
|
1354
|
-
// (2) one started entry per compiled agent (the dry-run branch leaves this empty).
|
|
1355
|
-
assert!(
|
|
1356
|
-
!launch.started.is_empty(),
|
|
1357
|
-
"quick_start must populate launch.started (>=1 worker spawned), not the dry-run empty Vec; got {:?}",
|
|
1358
|
-
launch.started
|
|
1359
|
-
);
|
|
1360
|
-
assert!(
|
|
1361
|
-
launch
|
|
1362
|
-
.started
|
|
1363
|
-
.iter()
|
|
1364
|
-
.any(|s| s.agent_id.as_str() == "implementer"),
|
|
1365
|
-
"launch.started must list the compiled agent 'implementer'; got {:?}",
|
|
1366
|
-
launch.started
|
|
1367
|
-
);
|
|
1368
|
-
// (3) the transport actually recorded the spawn, carrying the provider build_command.
|
|
1369
|
-
let recorded = transport.spawn_records();
|
|
1370
|
-
assert!(
|
|
1371
|
-
!recorded.is_empty(),
|
|
1372
|
-
"quick_start must drive the transport spawn path (>=1 spawn recorded); the dry-run bug records ZERO spawns"
|
|
1373
|
-
);
|
|
1374
|
-
assert_eq!(
|
|
1375
|
-
recorded[0].0, "spawn_first",
|
|
1376
|
-
"the first worker uses new-session (spawn_first); got {recorded:?}"
|
|
1377
|
-
);
|
|
1378
|
-
assert!(
|
|
1379
|
-
recorded
|
|
1380
|
-
.iter()
|
|
1381
|
-
.any(|(_, argv)| argv.iter().any(|a| a == "fake-worker")),
|
|
1382
|
-
"the spawn argv must carry the agent's provider build_command (fake-worker); got {recorded:?}"
|
|
1383
|
-
);
|
|
1384
|
-
}
|
|
1385
|
-
|
|
1386
|
-
#[test]
|
|
1387
|
-
fn adaptive_layout_plan_8_workers_is_3_3_2() {
|
|
1388
|
-
let agents = (1..=8)
|
|
1389
|
-
.map(|i| AgentId::new(format!("w{i}")))
|
|
1390
|
-
.collect::<Vec<_>>();
|
|
1391
|
-
let plan = adaptive_layout_plan(&agents, 3);
|
|
1392
|
-
let windows = plan
|
|
1393
|
-
.iter()
|
|
1394
|
-
.map(|placement| placement.layout_window.as_str().to_string())
|
|
1395
|
-
.collect::<Vec<_>>();
|
|
1396
|
-
assert_eq!(
|
|
1397
|
-
windows,
|
|
1398
|
-
vec![
|
|
1399
|
-
"team-w1", "team-w1", "team-w1", "team-w2", "team-w2", "team-w2", "team-w3", "team-w3",
|
|
1400
|
-
]
|
|
1401
|
-
);
|
|
1402
|
-
let pane_counts = ["team-w1", "team-w2", "team-w3"]
|
|
1403
|
-
.into_iter()
|
|
1404
|
-
.map(|window| {
|
|
1405
|
-
windows
|
|
1406
|
-
.iter()
|
|
1407
|
-
.filter(|actual| actual.as_str() == window)
|
|
1408
|
-
.count()
|
|
1409
|
-
})
|
|
1410
|
-
.collect::<Vec<_>>();
|
|
1411
|
-
assert_eq!(pane_counts, vec![3, 3, 2]);
|
|
1412
|
-
assert_eq!(
|
|
1413
|
-
plan.iter()
|
|
1414
|
-
.filter(|placement| placement.starts_window)
|
|
1415
|
-
.map(|placement| placement.agent_id.as_str().to_string())
|
|
1416
|
-
.collect::<Vec<_>>(),
|
|
1417
|
-
vec!["w1", "w4", "w7"]
|
|
1418
|
-
);
|
|
1419
|
-
}
|
|
1420
|
-
|
|
1421
|
-
#[test]
|
|
1422
|
-
#[serial(env)]
|
|
1423
|
-
fn quick_start_default_adaptive_groups_workers_into_layout_panes() {
|
|
1424
|
-
let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("launch-spawn-adaptive-layout");
|
|
1425
|
-
let roles = (1..=4)
|
|
1426
|
-
.map(|i| {
|
|
1427
|
-
let id = format!("w{i}");
|
|
1428
|
-
(format!("{id}.md"), role_doc(&id))
|
|
1429
|
-
})
|
|
1430
|
-
.collect::<Vec<_>>();
|
|
1431
|
-
let role_refs = roles
|
|
1432
|
-
.iter()
|
|
1433
|
-
.map(|(file, doc)| (file.as_str(), doc.as_str()))
|
|
1434
|
-
.collect::<Vec<_>>();
|
|
1435
|
-
let team = quick_start_team_dir_with_roles(&role_refs);
|
|
1436
|
-
let workspace = team.parent().expect("team_workspace(team_dir) = parent");
|
|
1437
|
-
seed_healthy_coordinator(workspace);
|
|
1438
|
-
let transport = OfflineTransport::new();
|
|
1439
|
-
|
|
1440
|
-
let report = quick_start_with_transport(&team, None, true, None, &transport)
|
|
1441
|
-
.expect("quick_start_with_transport must reach Ready");
|
|
1442
|
-
|
|
1443
|
-
let (launch, attach_commands) = match report {
|
|
1444
|
-
QuickStartReport::Ready {
|
|
1445
|
-
launch,
|
|
1446
|
-
attach_commands,
|
|
1447
|
-
..
|
|
1448
|
-
} => (*launch, attach_commands),
|
|
1449
|
-
other => panic!("quick_start must reach Ready; got {other:?}"),
|
|
1450
|
-
};
|
|
1451
|
-
// 0.3.28 Step 4b: adaptive 3-pane tiling replaced with 1-window-per-agent
|
|
1452
|
-
// Python-parity layout. 4 workers → spawn_first + 3×spawn_into, each in its
|
|
1453
|
-
// own window named after the agent_id. No team-w<N> windows; no splits.
|
|
1454
|
-
assert_eq!(
|
|
1455
|
-
transport
|
|
1456
|
-
.spawn_records()
|
|
1457
|
-
.iter()
|
|
1458
|
-
.map(|(kind, _)| kind.as_str())
|
|
1459
|
-
.collect::<Vec<_>>(),
|
|
1460
|
-
vec!["spawn_first", "spawn_into", "spawn_into", "spawn_into"],
|
|
1461
|
-
"0.3.28 Step 4b: 4 workers → 1 spawn_first + 3 spawn_into; \
|
|
1462
|
-
no splits in worker session"
|
|
1463
|
-
);
|
|
1464
|
-
|
|
1465
|
-
let (_raw, state) = raw_runtime_state(workspace);
|
|
1466
|
-
assert!(
|
|
1467
|
-
transport
|
|
1468
|
-
.pane_title_records()
|
|
1469
|
-
.iter()
|
|
1470
|
-
.all(|(session, _, _, _)| Some(session.as_str())
|
|
1471
|
-
== state
|
|
1472
|
-
.get("session_name")
|
|
1473
|
-
.and_then(serde_json::Value::as_str)),
|
|
1474
|
-
"pane titles must be configured inside the team session"
|
|
1475
|
-
);
|
|
1476
|
-
// Each worker lives in its OWN window named `agent_id` (Python parity).
|
|
1477
|
-
assert_eq!(state.pointer("/agents/w1/window"), Some(&json!("w1")));
|
|
1478
|
-
assert_eq!(state.pointer("/agents/w4/window"), Some(&json!("w4")));
|
|
1479
|
-
// attach commands point to the per-agent windows.
|
|
1480
|
-
assert!(
|
|
1481
|
-
attach_commands.iter().any(|cmd| cmd.contains(":w1")),
|
|
1482
|
-
"attach commands must include the per-agent windows: {attach_commands:?}"
|
|
1483
|
-
);
|
|
1484
|
-
}
|
|
1485
|
-
|
|
1486
|
-
#[test]
|
|
1487
|
-
#[serial(env)]
|
|
1488
|
-
fn quick_start_tmux_backend_uses_workspace_private_endpoint() {
|
|
1489
|
-
let leader_socket = "/tmp/team-agent-layout-leader-socket";
|
|
1490
|
-
let _tmux = EnvVarGuard::set("TMUX", &format!("{leader_socket},123,0"));
|
|
1491
|
-
let workspace = std::path::Path::new("/tmp/layout-workspace");
|
|
1492
|
-
let backend = quick_start_tmux_backend(workspace);
|
|
1493
|
-
let expected = TmuxBackend::for_workspace(workspace);
|
|
1494
|
-
|
|
1495
|
-
assert_eq!(
|
|
1496
|
-
crate::transport::Transport::tmux_endpoint(&backend),
|
|
1497
|
-
crate::transport::Transport::tmux_endpoint(&expected),
|
|
1498
|
-
"quick-start workers must use the workspace-private socket, not ambient $TMUX"
|
|
1499
|
-
);
|
|
1500
|
-
assert_eq!(
|
|
1501
|
-
selected_tmux_socket_source(&backend, workspace),
|
|
1502
|
-
Some("workspace")
|
|
1503
|
-
);
|
|
1504
|
-
}
|
|
1505
|
-
|
|
1506
|
-
#[test]
|
|
1507
|
-
#[serial(env)]
|
|
1508
|
-
fn quick_start_persists_selected_tmux_endpoint_and_attach_commands() {
|
|
1509
|
-
let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("launch-spawn-endpoint-attach");
|
|
1510
|
-
let team = quick_start_team_dir(QS_VALID_ROLE);
|
|
1511
|
-
let workspace = team.parent().expect("team_workspace(team_dir) = parent");
|
|
1512
|
-
seed_healthy_coordinator(workspace);
|
|
1513
|
-
let endpoint = "/tmp/team-agent-layout-selected-socket";
|
|
1514
|
-
let transport = OfflineTransport::new().with_tmux_endpoint(endpoint);
|
|
1515
|
-
|
|
1516
|
-
let report = quick_start_with_transport(&team, None, true, None, &transport)
|
|
1517
|
-
.expect("quick_start_with_transport must reach Ready");
|
|
1518
|
-
let attach_commands = match report {
|
|
1519
|
-
QuickStartReport::Ready {
|
|
1520
|
-
attach_commands, ..
|
|
1521
|
-
} => attach_commands,
|
|
1522
|
-
other => panic!("quick_start must reach Ready; got {other:?}"),
|
|
1523
|
-
};
|
|
1524
|
-
|
|
1525
|
-
assert!(
|
|
1526
|
-
attach_commands
|
|
1527
|
-
.iter()
|
|
1528
|
-
.any(|cmd| cmd.contains(&format!("tmux -S {endpoint} attach -t "))),
|
|
1529
|
-
"attach commands must use the selected socket endpoint: {attach_commands:?}"
|
|
1530
|
-
);
|
|
1531
|
-
assert!(
|
|
1532
|
-
!attach_commands.iter().any(|cmd| cmd.contains(":leader")),
|
|
1533
|
-
"managed metadata does not prove an unreported leader window exists: {attach_commands:?}"
|
|
1534
|
-
);
|
|
1535
|
-
assert!(attach_commands.iter().any(|cmd| cmd.ends_with(":implementer")));
|
|
1536
|
-
let (_raw, state) = raw_runtime_state(workspace);
|
|
1537
|
-
assert_eq!(state["tmux_endpoint"], json!(endpoint));
|
|
1538
|
-
assert_eq!(state["tmux_socket"], json!(endpoint));
|
|
1539
|
-
assert_eq!(state["is_external_leader"], json!(false));
|
|
1540
|
-
assert_eq!(
|
|
1541
|
-
state["teams"]["quickteam"]["is_external_leader"],
|
|
1542
|
-
json!(false)
|
|
1543
|
-
);
|
|
1544
|
-
}
|
|
1545
|
-
|
|
1546
|
-
#[test]
|
|
1547
|
-
fn annotate_runtime_tmux_endpoint_persists_workspace_socket_as_full_path() {
|
|
1548
|
-
let workspace = temp_ws();
|
|
1549
|
-
let short = crate::tmux_backend::socket_name_for_workspace(&workspace);
|
|
1550
|
-
let expected = crate::tmux_backend::socket_path_for_workspace(&workspace)
|
|
1551
|
-
.expect("workspace socket should have a physical path");
|
|
1552
|
-
let transport = OfflineTransport::new().with_tmux_endpoint(short);
|
|
1553
|
-
let mut state = json!({});
|
|
1554
|
-
|
|
1555
|
-
annotate_runtime_tmux_endpoint(&mut state, &transport, &workspace);
|
|
1556
|
-
|
|
1557
|
-
assert_eq!(
|
|
1558
|
-
state["tmux_endpoint"],
|
|
1559
|
-
json!(expected.to_string_lossy().to_string()),
|
|
1560
|
-
"runtime endpoint state must persist the full tmux socket path, not the short -L name"
|
|
1561
|
-
);
|
|
1562
|
-
assert_eq!(
|
|
1563
|
-
state["tmux_socket"], state["tmux_endpoint"],
|
|
1564
|
-
"tmux_socket mirrors the canonical persisted endpoint"
|
|
1565
|
-
);
|
|
1566
|
-
}
|
|
1567
|
-
|
|
1568
|
-
#[test]
|
|
1569
|
-
#[serial(env)]
|
|
1570
|
-
fn quick_start_preserves_managed_leader_topology_without_inventing_a_leader_window() {
|
|
1571
|
-
let hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("launch-spawn-managed-leader");
|
|
1572
|
-
let workspace = hermetic.root();
|
|
1573
|
-
let team = workspace.join("teamdir");
|
|
1574
|
-
std::fs::create_dir_all(team.join("agents")).unwrap();
|
|
1575
|
-
std::fs::write(team.join("TEAM.md"), QS_TEAM_MD).unwrap();
|
|
1576
|
-
std::fs::write(team.join("agents/implementer.md"), QS_VALID_ROLE).unwrap();
|
|
1577
|
-
seed_healthy_coordinator(workspace);
|
|
1578
|
-
let endpoint = std::env::var("TMUX").unwrap().split(',').next().unwrap().to_string();
|
|
1579
|
-
crate::state::persist::save_runtime_state(
|
|
1580
|
-
workspace,
|
|
1581
|
-
&json!({
|
|
1582
|
-
"active_team_key": "teamdir",
|
|
1583
|
-
"session_name": null,
|
|
1584
|
-
"is_external_leader": false,
|
|
1585
|
-
"leader_client": {"diagnostic_only": true, "attach_mode": "attach-session"},
|
|
1586
|
-
"tmux_socket": endpoint,
|
|
1587
|
-
"tmux_endpoint": endpoint,
|
|
1588
|
-
"agents": {},
|
|
1589
|
-
"teams": {
|
|
1590
|
-
"teamdir": {
|
|
1591
|
-
"session_name": null,
|
|
1592
|
-
"is_external_leader": false,
|
|
1593
|
-
"leader_client": {"diagnostic_only": true, "attach_mode": "attach-session"},
|
|
1594
|
-
"agents": {}
|
|
1595
|
-
}
|
|
1596
|
-
}
|
|
1597
|
-
}),
|
|
1598
|
-
)
|
|
1599
|
-
.expect("seed managed leader state");
|
|
1600
|
-
let attached = crate::cli::cmd_attach_leader(&crate::cli::AttachLeaderArgs {
|
|
1601
|
-
workspace: workspace.to_path_buf(), team: Some("teamdir".into()), pane: None,
|
|
1602
|
-
provider: crate::model::enums::Provider::Fake, confirm: false, json: true,
|
|
1603
|
-
}).expect("bind the real owned caller through the public lease port");
|
|
1604
|
-
assert_eq!(attached.exit, crate::cli::ExitCode::Ok, "{attached:?}");
|
|
1605
|
-
let mut state = crate::state::persist::load_runtime_state(workspace).unwrap();
|
|
1606
|
-
assert!(state["session_name"].is_null(), "leader-only bootstrap has no worker session");
|
|
1607
|
-
assert!(state["teams"]["teamdir"]["session_name"].is_null());
|
|
1608
|
-
assert!(state["teams"]["teamdir"]["agents"].as_object().unwrap().is_empty());
|
|
1609
|
-
// The owned fake caller models the already-managed launcher topology;
|
|
1610
|
-
// retain the real binding while setting the presentation fixture metadata.
|
|
1611
|
-
state["is_external_leader"] = json!(false);
|
|
1612
|
-
state["leader_client"] = json!({"diagnostic_only": true, "attach_mode": "attach-session"});
|
|
1613
|
-
state["teams"]["teamdir"]["is_external_leader"] = json!(false);
|
|
1614
|
-
state["teams"]["teamdir"]["leader_client"] = state["leader_client"].clone();
|
|
1615
|
-
crate::state::persist::save_runtime_state(workspace, &state).unwrap();
|
|
1616
|
-
let transport = OfflineTransport::new();
|
|
1617
|
-
|
|
1618
|
-
let report = quick_start_with_transport(&team, None, true, Some("teamdir"), &transport)
|
|
1619
|
-
.expect("quick_start_with_transport must reach Ready");
|
|
1620
|
-
let attach_commands = match report {
|
|
1621
|
-
QuickStartReport::Ready {
|
|
1622
|
-
attach_commands, ..
|
|
1623
|
-
} => attach_commands,
|
|
1624
|
-
other => panic!("quick_start must reach Ready; got {other:?}"),
|
|
1625
|
-
};
|
|
1626
|
-
|
|
1627
|
-
assert!(
|
|
1628
|
-
!attach_commands.iter().any(|cmd| cmd.contains(":leader")),
|
|
1629
|
-
"managed ownership must survive, but a missing physical leader window is not an attach target: {attach_commands:?}"
|
|
1630
|
-
);
|
|
1631
|
-
assert!(attach_commands.iter().any(|cmd| cmd.ends_with(":implementer")));
|
|
1632
|
-
let (_raw, state) = raw_runtime_state(workspace);
|
|
1633
|
-
assert_eq!(state["is_external_leader"], json!(false));
|
|
1634
|
-
assert_eq!(state["leader_client"]["diagnostic_only"], json!(true));
|
|
1635
|
-
}
|
|
1636
|
-
|
|
1637
|
-
#[test]
|
|
1638
|
-
fn fresh_managed_state_without_receiver_is_not_attached() {
|
|
1639
|
-
let workspace = temp_ws();
|
|
1640
|
-
crate::state::persist::save_runtime_state(
|
|
1641
|
-
&workspace,
|
|
1642
|
-
&json!({
|
|
1643
|
-
"active_team_key": "teamdir",
|
|
1644
|
-
"session_name": "team-teamdir",
|
|
1645
|
-
"is_external_leader": false,
|
|
1646
|
-
"agents": {"implementer": {"status": "running"}},
|
|
1647
|
-
"teams": {
|
|
1648
|
-
"teamdir": {
|
|
1649
|
-
"session_name": "team-teamdir",
|
|
1650
|
-
"is_external_leader": false,
|
|
1651
|
-
"agents": {"implementer": {"status": "running"}}
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1654
|
-
}),
|
|
1655
|
-
)
|
|
1656
|
-
.unwrap();
|
|
1657
|
-
|
|
1658
|
-
assert!(
|
|
1659
|
-
!crate::lifecycle::launch::launched_team_receiver_is_attached(&workspace, "teamdir"),
|
|
1660
|
-
"managed topology with missing leader_receiver must not be reported attached"
|
|
1661
|
-
);
|
|
1662
|
-
}
|
|
1663
|
-
|
|
1664
|
-
#[test]
|
|
1665
|
-
fn attach_window_names_for_state_agents_include_managed_leader_and_layout_windows() {
|
|
1666
|
-
let state = json!({
|
|
1667
|
-
"is_external_leader": false,
|
|
1668
|
-
"agents": {
|
|
1669
|
-
"w1": {"layout_window": "team-w1", "window": "w1"},
|
|
1670
|
-
"w2": {"layout_window": "team-w1", "window": "w2"},
|
|
1671
|
-
"w4": {"layout_window": "team-w2", "window": "w4"}
|
|
1672
|
-
}
|
|
1673
|
-
});
|
|
1674
|
-
|
|
1675
|
-
let windows = crate::lifecycle::launch::attach_window_names_for_state_agents(
|
|
1676
|
-
&state,
|
|
1677
|
-
["w1", "w2", "w4"].into_iter(),
|
|
1678
|
-
);
|
|
1679
|
-
|
|
1680
|
-
assert_eq!(windows, vec!["leader", "team-w1", "team-w2"]);
|
|
1681
|
-
}
|
|
1682
|
-
|
|
1683
|
-
// REAL-MACHINE residency boundary (acceptance framework): the PUBLIC quick_start (real TmuxBackend +
|
|
1684
|
-
// real start_coordinator) on a fresh ws must leave a LIVE tmux session AND a ps-verifiable resident
|
|
1685
|
-
// coordinator daemon (start_coordinator -> live pid). The framework verifies residency via ps; here we
|
|
1686
|
-
// only assert the in-report spawn observable. #[ignore] — spawns real tmux + a real daemon subprocess.
|
|
1687
|
-
#[test]
|
|
1688
|
-
#[ignore = "real-machine: live tmux session + resident coordinator daemon (framework verifies via ps)"]
|
|
1689
|
-
fn quick_start_fresh_ws_spawns_resident_tmux_and_coordinator() {
|
|
1690
|
-
let team = quick_start_team_dir(QS_VALID_ROLE);
|
|
1691
|
-
let report = quick_start(&team, None, true, None).expect("quick_start");
|
|
1692
|
-
match report {
|
|
1693
|
-
QuickStartReport::Ready { launch, .. } => {
|
|
1694
|
-
assert!(
|
|
1695
|
-
!launch.dry_run,
|
|
1696
|
-
"a real quick_start must spawn (not dry-run)"
|
|
1697
|
-
);
|
|
1698
|
-
assert!(
|
|
1699
|
-
!launch.started.is_empty(),
|
|
1700
|
-
"a real quick_start must spawn >=1 worker into a live tmux session; got {:?}",
|
|
1701
|
-
launch.started
|
|
1702
|
-
);
|
|
1703
|
-
}
|
|
1704
|
-
other => panic!("a fresh quick_start must reach Ready; got {other:?}"),
|
|
1705
|
-
}
|
|
1706
|
-
}
|
|
1707
|
-
|
|
1708
|
-
// ═════════════════════════════════════════════════════════════════════════
|
|
1709
|
-
// rt-host-a LOOP #2 — cli-handler DELEGATION sweep (same-class stub): restart / start_agent /
|
|
1710
|
-
// add_agent return RequirementUnmet at the spawn boundary and NEVER drive the transport (zero spawns)
|
|
1711
|
-
// nor start the coordinator. RED via the new *_with_transport seams + a RecordingTransport. OS-safe:
|
|
1712
|
-
// recording transport (no real tmux) + seeded-healthy-coordinator (start_coordinator AlreadyRunning).
|
|
1713
|
-
// Golden: restart/orchestration.py (Route-B resume spawn), lifecycle/start.py, lifecycle/operations.py.
|
|
1714
|
-
// ═════════════════════════════════════════════════════════════════════════
|
|
1715
|
-
|
|
1716
|
-
pub(super) const DELEG_ROLE_ALPHA: &str = "---\nname: alpha\nrole: Alpha Worker\nprovider: fake\nmodel: fake\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nAlpha.\n";
|
|
1717
|
-
pub(super) const DELEG_ROLE_BRAVO: &str = "---\nname: bravo\nrole: Bravo Worker\nprovider: fake\nmodel: fake\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nBravo.\n";
|
|
1718
|
-
const DELEG_ROLE_WORKER2: &str = "---\nname: worker2\nrole: Second Worker\nprovider: fake\nmodel: fake\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nSecond worker.\n";
|
|
1719
|
-
|
|
1720
|
-
/// A workspace (= self-contained team dir) with a compiled 2-agent spec + state listing alpha/bravo as
|
|
1721
|
-
/// running `fake` workers that were never captured (no session_id / first_send_at), so restart and
|
|
1722
|
-
/// start-agent fresh-spawn them without --allow-fresh (fake has no resume) + a seeded HEALTHY
|
|
1723
|
-
/// coordinator. Resume-path tests use [`restart_ws_two_copilot_resumable_workers`].
|
|
1724
|
-
pub(super) fn restart_ws_two_resumable_workers() -> PathBuf {
|
|
1725
|
-
restart_team_ws(
|
|
1726
|
-
&[("alpha", DELEG_ROLE_ALPHA.to_string()), ("bravo", DELEG_ROLE_BRAVO.to_string())],
|
|
1727
|
-
json!({
|
|
1728
|
-
"alpha": {"status": "running", "provider": "fake"},
|
|
1729
|
-
"bravo": {"status": "running", "provider": "fake"}
|
|
1730
|
-
}),
|
|
1731
|
-
)
|
|
1732
|
-
}
|
|
1733
|
-
|
|
1734
|
-
/// Same team as [`restart_ws_two_resumable_workers`], but alpha/bravo are Copilot workers whose
|
|
1735
|
-
/// session ids exist in `<home>/.copilot/session-store.db` (the Copilot resume backing), so restart
|
|
1736
|
-
/// takes the Route-B RESUME path. The caller holds `#[serial(env)]` with `HOME=<home>`.
|
|
1737
|
-
pub(super) fn restart_ws_two_copilot_resumable_workers(home: &std::path::Path) -> PathBuf {
|
|
1738
|
-
seed_copilot_session_store(home, &["sess-a", "sess-b"]);
|
|
1739
|
-
restart_team_ws(
|
|
1740
|
-
&[
|
|
1741
|
-
("alpha", provider_role_doc("alpha", "copilot", "gpt-5.5")),
|
|
1742
|
-
("bravo", provider_role_doc("bravo", "copilot", "gpt-5.5")),
|
|
1743
|
-
],
|
|
1744
|
-
json!({
|
|
1745
|
-
"alpha": {"status": "running", "provider": "copilot", "session_id": "sess-a", "first_send_at": "2026-05-27T10:00:00+00:00"},
|
|
1746
|
-
"bravo": {"status": "running", "provider": "copilot", "session_id": "sess-b", "first_send_at": "2026-05-27T10:00:00+00:00"}
|
|
1747
|
-
}),
|
|
1748
|
-
)
|
|
1749
|
-
}
|
|
1750
|
-
|
|
1751
|
-
/// Copilot resume backing is a `sessions` row in `$HOME/.copilot/session-store.db`.
|
|
1752
|
-
pub(super) fn seed_copilot_session_store(home: &std::path::Path, session_ids: &[&str]) {
|
|
1753
|
-
let db = home.join(".copilot").join("session-store.db");
|
|
1754
|
-
std::fs::create_dir_all(db.parent().unwrap()).unwrap();
|
|
1755
|
-
let conn = rusqlite::Connection::open(db).unwrap();
|
|
1756
|
-
conn.execute_batch("create table if not exists sessions (id text primary key);").unwrap();
|
|
1757
|
-
for session_id in session_ids {
|
|
1758
|
-
conn.execute(
|
|
1759
|
-
"insert or replace into sessions(id) values (?1)",
|
|
1760
|
-
[*session_id],
|
|
1761
|
-
)
|
|
1762
|
-
.unwrap();
|
|
1763
|
-
}
|
|
1764
|
-
}
|
|
1765
|
-
|
|
1766
|
-
fn restart_team_ws(roles: &[(&str, String)], agents: serde_json::Value) -> PathBuf {
|
|
1767
|
-
let ws = temp_ws().join("restartteam");
|
|
1768
|
-
std::fs::create_dir_all(ws.join("agents")).unwrap();
|
|
1769
|
-
std::fs::write(
|
|
1770
|
-
ws.join("TEAM.md"),
|
|
1771
|
-
"---\nname: restartteam\nobjective: Restart probe.\nprovider: codex\n---\n\nteam.\n",
|
|
1772
|
-
)
|
|
1773
|
-
.unwrap();
|
|
1774
|
-
for (id, doc) in roles {
|
|
1775
|
-
std::fs::write(ws.join("agents").join(format!("{id}.md")), doc).unwrap();
|
|
1776
|
-
}
|
|
1777
|
-
let spec = crate::compiler::compile_team(&ws).expect("compile 2-agent team");
|
|
1778
|
-
std::fs::write(ws.join("team.spec.yaml"), crate::model::yaml::dumps(&spec)).unwrap();
|
|
1779
|
-
crate::state::persist::save_runtime_state(
|
|
1780
|
-
&ws,
|
|
1781
|
-
&json!({
|
|
1782
|
-
"session_name": "team-restartteam",
|
|
1783
|
-
"agents": agents
|
|
1784
|
-
}),
|
|
1785
|
-
)
|
|
1786
|
-
.unwrap();
|
|
1787
|
-
seed_healthy_coordinator(&ws); // start_coordinator -> AlreadyRunning (no real daemon subprocess)
|
|
1788
|
-
ws
|
|
1789
|
-
}
|
|
1790
|
-
|
|
1791
|
-
fn restart_ws_one_resumable_worker() -> PathBuf {
|
|
1792
|
-
let ws = temp_ws().join("restartone");
|
|
1793
|
-
std::fs::create_dir_all(ws.join("agents")).unwrap();
|
|
1794
|
-
std::fs::write(
|
|
1795
|
-
ws.join("TEAM.md"),
|
|
1796
|
-
"---\nname: restartone\nobjective: Restart readiness probe.\nprovider: codex\n---\n\nteam.\n",
|
|
1797
|
-
)
|
|
1798
|
-
.unwrap();
|
|
1799
|
-
std::fs::write(ws.join("agents").join("alpha.md"), DELEG_ROLE_ALPHA).unwrap();
|
|
1800
|
-
let spec = crate::compiler::compile_team(&ws).expect("compile 1-agent team");
|
|
1801
|
-
std::fs::write(ws.join("team.spec.yaml"), crate::model::yaml::dumps(&spec)).unwrap();
|
|
1802
|
-
crate::state::persist::save_runtime_state(
|
|
1803
|
-
&ws,
|
|
1804
|
-
&json!({
|
|
1805
|
-
"session_name": "team-restartone",
|
|
1806
|
-
"agents": {
|
|
1807
|
-
"alpha": {"status": "running", "provider": "fake"}
|
|
1808
|
-
}
|
|
1809
|
-
}),
|
|
1810
|
-
)
|
|
1811
|
-
.unwrap();
|
|
1812
|
-
seed_healthy_coordinator(&ws);
|
|
1813
|
-
ws
|
|
1814
|
-
}
|
|
1815
|
-
|
|
1816
|
-
// 2 [P0] — restart_with_transport must drive the REAL Route-B resume spawn: one spawn per resumable
|
|
1817
|
-
// worker. The first resumed worker recreates the session with spawn_first; later workers may use
|
|
1818
|
-
// spawn_into only after a live-session check proves that recreated session still exists. Each spawn
|
|
1819
|
-
// carries the provider resume command, and the coordinator is started. Copilot is the resumable
|
|
1820
|
-
// legacy provider; its backing is the hermetic HOME session store.
|
|
1821
|
-
#[test]
|
|
1822
|
-
#[serial(env)]
|
|
1823
|
-
fn restart_with_transport_spawns_resumable_workers_not_stub() {
|
|
1824
|
-
let hermetic = enter_hermetic("launch-spawn-restart-resume");
|
|
1825
|
-
let ws = restart_ws_two_copilot_resumable_workers(hermetic.home());
|
|
1826
|
-
let mut state = crate::state::persist::load_runtime_state(&ws).unwrap();
|
|
1827
|
-
state["generation"] = json!("old-destroyed-session-birth");
|
|
1828
|
-
crate::state::persist::save_runtime_state(&ws, &state).unwrap();
|
|
1829
|
-
let transport = OfflineTransport::new();
|
|
1830
|
-
|
|
1831
|
-
let result = restart_with_transport(&ws, false, None, &transport);
|
|
1832
|
-
|
|
1833
|
-
let recorded = transport.spawn_records();
|
|
1834
|
-
assert_eq!(
|
|
1835
|
-
recorded.len(),
|
|
1836
|
-
2,
|
|
1837
|
-
"restart must spawn ONE worker per resumable agent (alpha, bravo); the rt-host-a stub returns \
|
|
1838
|
-
RequirementUnmet with ZERO spawns; got {recorded:?}"
|
|
1839
|
-
);
|
|
1840
|
-
assert_eq!(
|
|
1841
|
-
recorded[0].0, "spawn_first",
|
|
1842
|
-
"with has-session=false before alpha, restart must recreate the session with spawn_first; got {recorded:?}"
|
|
1843
|
-
);
|
|
1844
|
-
assert_eq!(
|
|
1845
|
-
recorded[1].0, "spawn_into",
|
|
1846
|
-
"with has-session=true after alpha spawn, restart may add bravo with spawn_into; this is liveness-based, not index-based; got {recorded:?}"
|
|
1847
|
-
);
|
|
1848
|
-
assert!(
|
|
1849
|
-
recorded.iter().all(|(_, argv)| argv.iter().any(|a| a == "copilot")
|
|
1850
|
-
&& argv.iter().any(|a| a == "--resume")),
|
|
1851
|
-
"each resumed worker's spawn argv must carry the provider resume command (copilot --resume); got {recorded:?}"
|
|
1852
|
-
);
|
|
1853
|
-
assert!(
|
|
1854
|
-
matches!(result, Ok(RestartReport::Restarted { coordinator_started: true, .. })),
|
|
1855
|
-
"restart must reach RestartReport::Restarted with coordinator_started=true (AlreadyRunning, seeded); got {result:?}"
|
|
1856
|
-
);
|
|
1857
|
-
let state = crate::state::persist::load_runtime_state(&ws).unwrap();
|
|
1858
|
-
let generation = state["agents"]["alpha"]["spawned_at"].as_str().unwrap();
|
|
1859
|
-
assert_ne!(generation, "old-destroyed-session-birth");
|
|
1860
|
-
assert_eq!(state["generation"], generation);
|
|
1861
|
-
assert!(state.get("teams").is_none(), "legacy flat state must remain flat");
|
|
1862
|
-
let owner = transport.session_owner(&SessionName::new("team-restartteam")).unwrap().unwrap();
|
|
1863
|
-
assert_eq!(owner.generation, generation);
|
|
1864
|
-
let events = crate::event_log::EventLog::new(&ws).tail(20).unwrap();
|
|
1865
|
-
let completed = events
|
|
1866
|
-
.iter()
|
|
1867
|
-
.find(|event| event.get("event").and_then(|v| v.as_str()) == Some("restart.completed"))
|
|
1868
|
-
.expect("restart.completed event for successful restart");
|
|
1869
|
-
assert_eq!(completed.get("rc").and_then(|v| v.as_str()), Some("ok"));
|
|
1870
|
-
|
|
1871
|
-
let ws = restart_ws_two_copilot_resumable_workers(hermetic.home());
|
|
1872
|
-
let dead_after_first = OfflineTransport::new().with_session_absent_after_spawn_first();
|
|
1873
|
-
let result = restart_with_transport_with_readiness_deadline(
|
|
1874
|
-
&ws,
|
|
1875
|
-
false,
|
|
1876
|
-
None,
|
|
1877
|
-
&dead_after_first,
|
|
1878
|
-
Some(0),
|
|
1879
|
-
);
|
|
1880
|
-
let recorded = dead_after_first.spawn_records();
|
|
1881
|
-
assert_eq!(
|
|
1882
|
-
recorded.len(),
|
|
1883
|
-
1,
|
|
1884
|
-
"if a resumed session disappears after alpha, restart must fail fast before bravo; got result={result:?} recorded={recorded:?}"
|
|
1885
|
-
);
|
|
1886
|
-
assert!(
|
|
1887
|
-
recorded.iter().all(|(kind, _)| kind == "spawn_first"),
|
|
1888
|
-
"restart must not call spawn_into/new-window against a dead server; result={result:?} recorded={recorded:?}"
|
|
1889
|
-
);
|
|
1890
|
-
let result_debug = format!("{result:?}");
|
|
1891
|
-
let report = result.expect("resume integrity failure should return a typed failed report");
|
|
1892
|
-
let RestartReport::Failed { failed_agents, .. } = report else {
|
|
1893
|
-
panic!("resume integrity failure must not be Partial/Restarted; got {report:?}");
|
|
1894
|
-
};
|
|
1895
|
-
assert_eq!(failed_agents.len(), 1);
|
|
1896
|
-
assert_eq!(failed_agents[0].agent_id.as_str(), "alpha");
|
|
1897
|
-
assert_eq!(failed_agents[0].phase, "resume");
|
|
1898
|
-
assert!(
|
|
1899
|
-
dead_after_first.calls().iter().all(|call| *call != "kill_session"),
|
|
1900
|
-
"a single worker/session disappearance must not trigger another shared-session kill; calls={:?}",
|
|
1901
|
-
dead_after_first.calls()
|
|
1902
|
-
);
|
|
1903
|
-
let events = crate::event_log::EventLog::new(&ws).tail(20).unwrap();
|
|
1904
|
-
let failed = events
|
|
1905
|
-
.iter()
|
|
1906
|
-
.find(|event| event.get("event").and_then(|v| v.as_str()) == Some("restart.agent_failed"))
|
|
1907
|
-
.expect("restart.agent_failed event for isolated alpha");
|
|
1908
|
-
assert_eq!(
|
|
1909
|
-
failed.get("agent_id").and_then(|v| v.as_str()),
|
|
1910
|
-
Some("alpha")
|
|
1911
|
-
);
|
|
1912
|
-
assert!(
|
|
1913
|
-
failed
|
|
1914
|
-
.get("error")
|
|
1915
|
-
.and_then(|v| v.as_str())
|
|
1916
|
-
.is_some_and(|error| error.contains("session_disappeared_after_spawn")),
|
|
1917
|
-
"restart must report the first resumed agent/session disappearance explicitly; event={failed} result={result_debug}"
|
|
1918
|
-
);
|
|
1919
|
-
}
|
|
1920
|
-
|
|
1921
|
-
#[test]
|
|
1922
|
-
fn restart_runtime_spec_spawns_from_run_workspace_not_runtime_dir() {
|
|
1923
|
-
let workspace = temp_ws();
|
|
1924
|
-
std::fs::create_dir_all(workspace.join("agents")).unwrap();
|
|
1925
|
-
std::fs::write(
|
|
1926
|
-
workspace.join("TEAM.md"),
|
|
1927
|
-
"---\nname: current\nobjective: Restart cwd probe.\nprovider: codex\n---\n\nteam.\n",
|
|
1928
|
-
)
|
|
1929
|
-
.unwrap();
|
|
1930
|
-
std::fs::write(workspace.join("agents").join("alpha.md"), DELEG_ROLE_ALPHA).unwrap();
|
|
1931
|
-
let spec = crate::compiler::compile_team(&workspace).expect("compile project-root team");
|
|
1932
|
-
let spec_path = crate::model::paths::runtime_spec_path(&workspace, "current");
|
|
1933
|
-
std::fs::create_dir_all(spec_path.parent().unwrap()).unwrap();
|
|
1934
|
-
std::fs::write(&spec_path, crate::model::yaml::dumps(&spec)).unwrap();
|
|
1935
|
-
crate::state::persist::save_runtime_state(
|
|
1936
|
-
&workspace,
|
|
1937
|
-
&json!({
|
|
1938
|
-
"active_team_key": "current",
|
|
1939
|
-
"session_name": "team-current",
|
|
1940
|
-
"spec_path": spec_path.to_string_lossy(),
|
|
1941
|
-
"team_dir": workspace.to_string_lossy(),
|
|
1942
|
-
"agents": {
|
|
1943
|
-
"alpha": {
|
|
1944
|
-
"status": "running",
|
|
1945
|
-
"provider": "fake",
|
|
1946
|
-
"spawn_cwd": null
|
|
1947
|
-
}
|
|
1948
|
-
}
|
|
1949
|
-
}),
|
|
1950
|
-
)
|
|
1951
|
-
.unwrap();
|
|
1952
|
-
seed_healthy_coordinator(&workspace);
|
|
1953
|
-
let transport = OfflineTransport::new();
|
|
1954
|
-
|
|
1955
|
-
let result = restart_with_transport(&workspace, false, Some("current"), &transport);
|
|
1956
|
-
|
|
1957
|
-
assert!(
|
|
1958
|
-
matches!(result, Ok(RestartReport::Restarted { .. })),
|
|
1959
|
-
"restart should succeed for a never-captured project-root team: {result:?}"
|
|
1960
|
-
);
|
|
1961
|
-
assert_eq!(
|
|
1962
|
-
transport.spawn_cwd_records(),
|
|
1963
|
-
vec![workspace.clone()],
|
|
1964
|
-
"restart must spawn from run_workspace, not .team/runtime/<team>"
|
|
1965
|
-
);
|
|
1966
|
-
let state = crate::state::persist::load_runtime_state(&workspace).unwrap();
|
|
1967
|
-
assert_eq!(
|
|
1968
|
-
state
|
|
1969
|
-
.get("agents")
|
|
1970
|
-
.and_then(|agents| agents.get("alpha"))
|
|
1971
|
-
.and_then(|agent| agent.get("spawn_cwd"))
|
|
1972
|
-
.and_then(serde_json::Value::as_str),
|
|
1973
|
-
Some(workspace.to_string_lossy().as_ref()),
|
|
1974
|
-
"restart must persist the actual spawn cwd for later diagnostics"
|
|
1975
|
-
);
|
|
1976
|
-
let rebuilt_spec =
|
|
1977
|
-
crate::model::yaml::loads(&std::fs::read_to_string(&spec_path).unwrap()).unwrap();
|
|
1978
|
-
assert_eq!(
|
|
1979
|
-
rebuilt_spec
|
|
1980
|
-
.get("team")
|
|
1981
|
-
.and_then(|team| team.get("workspace"))
|
|
1982
|
-
.and_then(crate::model::yaml::Value::as_str),
|
|
1983
|
-
Some(workspace.to_string_lossy().as_ref()),
|
|
1984
|
-
"restart spec rebuild must keep team.workspace at the project root"
|
|
1985
|
-
);
|
|
1986
|
-
for agent in rebuilt_spec
|
|
1987
|
-
.get("agents")
|
|
1988
|
-
.and_then(crate::model::yaml::Value::as_list)
|
|
1989
|
-
.unwrap()
|
|
1990
|
-
{
|
|
1991
|
-
assert_eq!(
|
|
1992
|
-
agent
|
|
1993
|
-
.get("working_directory")
|
|
1994
|
-
.and_then(crate::model::yaml::Value::as_str),
|
|
1995
|
-
Some(workspace.to_string_lossy().as_ref()),
|
|
1996
|
-
"restart spec rebuild must keep agent working_directory at the project root"
|
|
1997
|
-
);
|
|
1998
|
-
}
|
|
1999
|
-
}
|
|
2000
|
-
|
|
2001
|
-
#[test]
|
|
2002
|
-
#[serial(env)]
|
|
2003
|
-
fn restart_allow_fresh_does_not_force_fresh_other_agents_when_one_session_capture_times_out() {
|
|
2004
|
-
let hermetic = enter_hermetic("launch-spawn-restart-atomic");
|
|
2005
|
-
let ws = temp_ws().join("restartatomic");
|
|
2006
|
-
std::fs::create_dir_all(ws.join("agents")).unwrap();
|
|
2007
|
-
std::fs::write(
|
|
2008
|
-
ws.join("TEAM.md"),
|
|
2009
|
-
"---\nname: restartatomic\nobjective: Restart atomicity probe.\nprovider: codex\n---\n\nteam.\n",
|
|
2010
|
-
)
|
|
2011
|
-
.unwrap();
|
|
2012
|
-
std::fs::write(
|
|
2013
|
-
ws.join("agents").join("alpha.md"),
|
|
2014
|
-
provider_role_doc("alpha", "copilot", "gpt-5.5"),
|
|
2015
|
-
)
|
|
2016
|
-
.unwrap();
|
|
2017
|
-
std::fs::write(
|
|
2018
|
-
ws.join("agents").join("bravo.md"),
|
|
2019
|
-
provider_role_doc("bravo", "copilot", "gpt-5.5"),
|
|
2020
|
-
)
|
|
2021
|
-
.unwrap();
|
|
2022
|
-
|
|
2023
|
-
// alpha's resume backing is its Copilot session-store row; bravo has none, so only bravo's
|
|
2024
|
-
// session convergence times out.
|
|
2025
|
-
let alpha_session = "019ee540-37ed-7a20-a141-1d654224d209";
|
|
2026
|
-
seed_copilot_session_store(hermetic.home(), &[alpha_session]);
|
|
2027
|
-
|
|
2028
|
-
let spec = crate::compiler::compile_team(&ws).expect("compile restart team");
|
|
2029
|
-
std::fs::write(ws.join("team.spec.yaml"), crate::model::yaml::dumps(&spec)).unwrap();
|
|
2030
|
-
crate::state::persist::save_runtime_state(
|
|
2031
|
-
&ws,
|
|
2032
|
-
&json!({
|
|
2033
|
-
"session_name": "team-restartatomic",
|
|
2034
|
-
"agents": {
|
|
2035
|
-
"alpha": {
|
|
2036
|
-
"status": "running",
|
|
2037
|
-
"provider": "copilot",
|
|
2038
|
-
"session_id": alpha_session,
|
|
2039
|
-
"first_send_at": "2026-05-27T10:00:00+00:00"
|
|
2040
|
-
},
|
|
2041
|
-
"bravo": {
|
|
2042
|
-
"status": "running",
|
|
2043
|
-
"provider": "copilot",
|
|
2044
|
-
"session_id": null,
|
|
2045
|
-
"spawn_cwd": ws.to_string_lossy(),
|
|
2046
|
-
"first_send_at": "2026-05-27T10:00:00+00:00"
|
|
2047
|
-
}
|
|
2048
|
-
}
|
|
2049
|
-
}),
|
|
2050
|
-
)
|
|
2051
|
-
.unwrap();
|
|
2052
|
-
seed_healthy_coordinator(&ws);
|
|
2053
|
-
let transport = OfflineTransport::new();
|
|
2054
|
-
|
|
2055
|
-
let result = restart_with_transport_with_session_convergence_deadline(
|
|
2056
|
-
&ws,
|
|
2057
|
-
true,
|
|
2058
|
-
None,
|
|
2059
|
-
&transport,
|
|
2060
|
-
Some(0),
|
|
2061
|
-
None,
|
|
2062
|
-
);
|
|
2063
|
-
|
|
2064
|
-
assert!(
|
|
2065
|
-
matches!(result, Ok(RestartReport::Restarted { .. })),
|
|
2066
|
-
"allow-fresh restart should complete with alpha resumed and bravo fresh; got {result:?}"
|
|
2067
|
-
);
|
|
2068
|
-
let events = crate::event_log::EventLog::new(&ws).tail(80).unwrap();
|
|
2069
|
-
let decisions = events
|
|
2070
|
-
.iter()
|
|
2071
|
-
.filter(|event| {
|
|
2072
|
-
event.get("event").and_then(|v| v.as_str()) == Some("restart.resume_decision")
|
|
2073
|
-
})
|
|
2074
|
-
.collect::<Vec<_>>();
|
|
2075
|
-
let alpha = decisions
|
|
2076
|
-
.iter()
|
|
2077
|
-
.find(|event| event.get("worker_id").and_then(|v| v.as_str()) == Some("alpha"))
|
|
2078
|
-
.expect("alpha decision");
|
|
2079
|
-
assert_eq!(
|
|
2080
|
-
alpha.get("decision").and_then(|v| v.as_str()),
|
|
2081
|
-
Some("resume"),
|
|
2082
|
-
"alpha has session_id plus a matching Copilot session-store row and must not be forced fresh: {alpha}"
|
|
2083
|
-
);
|
|
2084
|
-
assert!(
|
|
2085
|
-
alpha.get("forced_fresh").is_none(),
|
|
2086
|
-
"alpha must not inherit bravo's convergence timeout: {alpha}"
|
|
2087
|
-
);
|
|
2088
|
-
let bravo = decisions
|
|
2089
|
-
.iter()
|
|
2090
|
-
.find(|event| event.get("worker_id").and_then(|v| v.as_str()) == Some("bravo"))
|
|
2091
|
-
.expect("bravo decision");
|
|
2092
|
-
assert_eq!(
|
|
2093
|
-
bravo.get("decision").and_then(|v| v.as_str()),
|
|
2094
|
-
Some("fresh_start")
|
|
2095
|
-
);
|
|
2096
|
-
assert_eq!(
|
|
2097
|
-
bravo.get("forced_fresh").and_then(|v| v.as_bool()),
|
|
2098
|
-
Some(true),
|
|
2099
|
-
"only the missing-session agent should carry forced_fresh: {bravo}"
|
|
2100
|
-
);
|
|
2101
|
-
}
|
|
2102
|
-
|
|
2103
|
-
#[test]
|
|
2104
|
-
fn restart_spawn_failure_isolated_to_partial_report() {
|
|
2105
|
-
let ws = restart_ws_two_resumable_workers();
|
|
2106
|
-
let transport = OfflineTransport::new().with_spawn_failure("bravo", "injected bravo failure");
|
|
2107
|
-
|
|
2108
|
-
let result = restart_with_transport(&ws, false, None, &transport);
|
|
2109
|
-
|
|
2110
|
-
let report = result.expect("single worker failure must be represented as partial report");
|
|
2111
|
-
let RestartReport::Partial {
|
|
2112
|
-
agents,
|
|
2113
|
-
failed_agents,
|
|
2114
|
-
coordinator_started,
|
|
2115
|
-
..
|
|
2116
|
-
} = report
|
|
2117
|
-
else {
|
|
2118
|
-
panic!("single worker failure must return RestartReport::Partial; got {report:?}");
|
|
2119
|
-
};
|
|
2120
|
-
assert!(
|
|
2121
|
-
coordinator_started,
|
|
2122
|
-
"partial restart still starts coordinator for successful agents"
|
|
2123
|
-
);
|
|
2124
|
-
assert_eq!(
|
|
2125
|
-
agents
|
|
2126
|
-
.iter()
|
|
2127
|
-
.map(|agent| agent.agent_id.as_str())
|
|
2128
|
-
.collect::<Vec<_>>(),
|
|
2129
|
-
vec!["alpha"]
|
|
2130
|
-
);
|
|
2131
|
-
assert_eq!(failed_agents.len(), 1);
|
|
2132
|
-
assert_eq!(failed_agents[0].agent_id.as_str(), "bravo");
|
|
2133
|
-
assert_eq!(failed_agents[0].phase, "spawn");
|
|
2134
|
-
|
|
2135
|
-
let state = crate::state::persist::load_runtime_state(&ws).unwrap();
|
|
2136
|
-
assert_eq!(
|
|
2137
|
-
state
|
|
2138
|
-
.pointer("/agents/alpha/status")
|
|
2139
|
-
.and_then(|v| v.as_str()),
|
|
2140
|
-
Some("running")
|
|
2141
|
-
);
|
|
2142
|
-
assert_eq!(
|
|
2143
|
-
state
|
|
2144
|
-
.pointer("/agents/bravo/status")
|
|
2145
|
-
.and_then(|v| v.as_str()),
|
|
2146
|
-
Some("failed")
|
|
2147
|
-
);
|
|
2148
|
-
assert!(
|
|
2149
|
-
state
|
|
2150
|
-
.pointer("/agents/bravo/restart_error")
|
|
2151
|
-
.and_then(|v| v.as_str())
|
|
2152
|
-
.is_some_and(|error| error.contains("injected bravo failure")),
|
|
2153
|
-
"failed agent must retain restart_error in state: {state}"
|
|
2154
|
-
);
|
|
2155
|
-
|
|
2156
|
-
let events = crate::event_log::EventLog::new(&ws).tail(20).unwrap();
|
|
2157
|
-
let completed = events
|
|
2158
|
-
.iter()
|
|
2159
|
-
.find(|event| event.get("event").and_then(|v| v.as_str()) == Some("restart.completed"))
|
|
2160
|
-
.expect("restart.completed event for partial restart");
|
|
2161
|
-
assert_eq!(
|
|
2162
|
-
completed.get("rc").and_then(|v| v.as_str()),
|
|
2163
|
-
Some("partial")
|
|
2164
|
-
);
|
|
2165
|
-
assert!(
|
|
2166
|
-
completed
|
|
2167
|
-
.get("successful_agents")
|
|
2168
|
-
.and_then(|v| v.as_array())
|
|
2169
|
-
.is_some_and(|agents| agents.iter().any(|agent| agent.as_str() == Some("alpha"))),
|
|
2170
|
-
"completed event must list successful agents: {completed}"
|
|
2171
|
-
);
|
|
2172
|
-
assert!(
|
|
2173
|
-
completed
|
|
2174
|
-
.get("failed_agents")
|
|
2175
|
-
.and_then(|v| v.as_array())
|
|
2176
|
-
.is_some_and(|agents| agents.iter().any(|agent| {
|
|
2177
|
-
agent.get("agent_id").and_then(|v| v.as_str()) == Some("bravo")
|
|
2178
|
-
&& agent.get("phase").and_then(|v| v.as_str()) == Some("spawn")
|
|
2179
|
-
})),
|
|
2180
|
-
"completed event must list failed agents with phase: {completed}"
|
|
2181
|
-
);
|
|
2182
|
-
}
|
|
2183
|
-
|
|
2184
|
-
#[test]
|
|
2185
|
-
fn restart_all_spawn_failures_return_failed_report() {
|
|
2186
|
-
let ws = restart_ws_one_resumable_worker();
|
|
2187
|
-
let transport = OfflineTransport::new().with_spawn_failure("alpha", "injected alpha failure");
|
|
2188
|
-
|
|
2189
|
-
let result = restart_with_transport(&ws, false, None, &transport);
|
|
2190
|
-
|
|
2191
|
-
let report = result.expect("all worker failures should return typed failed report");
|
|
2192
|
-
let RestartReport::Failed { failed_agents, .. } = report else {
|
|
2193
|
-
panic!("all worker failures must return RestartReport::Failed; got {report:?}");
|
|
2194
|
-
};
|
|
2195
|
-
assert_eq!(failed_agents.len(), 1);
|
|
2196
|
-
assert_eq!(failed_agents[0].agent_id.as_str(), "alpha");
|
|
2197
|
-
assert_eq!(failed_agents[0].phase, "spawn");
|
|
2198
|
-
|
|
2199
|
-
let events = crate::event_log::EventLog::new(&ws).tail(20).unwrap();
|
|
2200
|
-
let completed = events
|
|
2201
|
-
.iter()
|
|
2202
|
-
.find(|event| event.get("event").and_then(|v| v.as_str()) == Some("restart.completed"))
|
|
2203
|
-
.expect("restart.completed event for failed restart");
|
|
2204
|
-
assert_eq!(completed.get("rc").and_then(|v| v.as_str()), Some("fail"));
|
|
2205
|
-
}
|
|
2206
|
-
|
|
2207
|
-
#[test]
|
|
2208
|
-
fn restart_spawn_loop_keeps_failure_isolation_guard() {
|
|
2209
|
-
let source = include_str!("../restart/rebuild.rs");
|
|
2210
|
-
let start = source
|
|
2211
|
-
.find("BEGIN_B5_RESTART_ISOLATION_LOOP")
|
|
2212
|
-
.expect("B5 isolation loop start marker");
|
|
2213
|
-
let end = source
|
|
2214
|
-
.find("END_B5_RESTART_ISOLATION_LOOP")
|
|
2215
|
-
.expect("B5 isolation loop end marker");
|
|
2216
|
-
let body = &source[start..end];
|
|
2217
|
-
for forbidden in ["?;", "break", "return "] {
|
|
2218
|
-
assert!(
|
|
2219
|
-
!body.contains(forbidden),
|
|
2220
|
-
"B5 spawn loop must not fail-fast via {forbidden:?}; body={body}"
|
|
2221
|
-
);
|
|
2222
|
-
}
|
|
2223
|
-
assert!(
|
|
2224
|
-
body.contains("continue"),
|
|
2225
|
-
"B5 spawn loop should isolate per-agent failures and continue; body={body}"
|
|
2226
|
-
);
|
|
2227
|
-
}
|
|
2228
|
-
|
|
2229
|
-
#[test]
|
|
2230
|
-
fn restart_times_out_when_spawned_worker_pane_is_not_addressable() {
|
|
2231
|
-
let ws = restart_ws_one_resumable_worker();
|
|
2232
|
-
let transport = OfflineTransport::new().with_spawned_panes_addressable(false);
|
|
2233
|
-
|
|
2234
|
-
let result =
|
|
2235
|
-
restart_with_transport_with_readiness_deadline(&ws, false, None, &transport, Some(0));
|
|
2236
|
-
|
|
2237
|
-
let text = format!("{result:?}");
|
|
2238
|
-
assert!(
|
|
2239
|
-
text.contains("restart not ready")
|
|
2240
|
-
&& text.contains("worker pane addressable: no")
|
|
2241
|
-
&& text.contains("Action:")
|
|
2242
|
-
&& text.contains("Log:"),
|
|
2243
|
-
"restart must refuse with N38 readiness timeout details, not return ok; got {text}"
|
|
2244
|
-
);
|
|
2245
|
-
assert!(
|
|
2246
|
-
!matches!(result, Ok(RestartReport::Restarted { .. })),
|
|
2247
|
-
"restart readiness timeout must not return Restarted ok"
|
|
2248
|
-
);
|
|
2249
|
-
let events = crate::event_log::EventLog::new(&ws).tail(20).unwrap();
|
|
2250
|
-
let timeout = events
|
|
2251
|
-
.iter()
|
|
2252
|
-
.find(|event| {
|
|
2253
|
-
event.get("event").and_then(|v| v.as_str()) == Some("restart.readiness_timeout")
|
|
2254
|
-
})
|
|
2255
|
-
.expect("restart.readiness_timeout event");
|
|
2256
|
-
assert_eq!(
|
|
2257
|
-
timeout
|
|
2258
|
-
.get("worker_pane_addressable")
|
|
2259
|
-
.and_then(|v| v.as_bool()),
|
|
2260
|
-
Some(false),
|
|
2261
|
-
"timeout event must carry the failed readiness condition: {timeout}"
|
|
2262
|
-
);
|
|
2263
|
-
}
|
|
2264
|
-
|
|
2265
|
-
// 3 [P0] — start_agent_with_transport on a non-paused agent with a session_id must spawn EXACTLY ONE
|
|
2266
|
-
// worker (resume) carrying the provider resume command. Today the stub returns RequirementUnmet with
|
|
2267
|
-
// ZERO spawns -> RED at recorded.len(). Copilot is the resumable legacy provider; its backing is the
|
|
2268
|
-
// hermetic HOME session store.
|
|
2269
|
-
#[test]
|
|
2270
|
-
#[serial(env)]
|
|
2271
|
-
fn start_agent_with_transport_spawns_resume_not_stub() {
|
|
2272
|
-
let hermetic = enter_hermetic("launch-spawn-start-agent-resume");
|
|
2273
|
-
let ws = temp_ws().join("startagentws");
|
|
2274
|
-
std::fs::create_dir_all(&ws).unwrap();
|
|
2275
|
-
seed_copilot_session_store(hermetic.home(), &["sess-a"]);
|
|
2276
|
-
crate::state::persist::save_runtime_state(
|
|
2277
|
-
&ws,
|
|
2278
|
-
&json!({
|
|
2279
|
-
"session_name": "team-sa",
|
|
2280
|
-
"agents": {"alpha": {"status": "running", "provider": "copilot", "session_id": "sess-a", "first_send_at": "2026-05-27T10:00:00+00:00"}}
|
|
2281
|
-
}),
|
|
2282
|
-
)
|
|
2283
|
-
.unwrap();
|
|
2284
|
-
seed_healthy_coordinator(&ws);
|
|
2285
|
-
let transport = OfflineTransport::new();
|
|
2286
|
-
|
|
2287
|
-
let _result = start_agent_with_transport(
|
|
2288
|
-
&ws,
|
|
2289
|
-
&AgentId::new("alpha"),
|
|
2290
|
-
false,
|
|
2291
|
-
false,
|
|
2292
|
-
false,
|
|
2293
|
-
None,
|
|
2294
|
-
&transport,
|
|
2295
|
-
);
|
|
2296
|
-
|
|
2297
|
-
let recorded = transport.spawn_records();
|
|
2298
|
-
assert_eq!(
|
|
2299
|
-
recorded.len(),
|
|
2300
|
-
1,
|
|
2301
|
-
"start_agent must spawn EXACTLY ONE worker (resume); the rt-host-a stub returns RequirementUnmet \
|
|
2302
|
-
with ZERO spawns; got {recorded:?}"
|
|
2303
|
-
);
|
|
2304
|
-
assert!(
|
|
2305
|
-
recorded[0].1.iter().any(|a| a == "copilot")
|
|
2306
|
-
&& recorded[0]
|
|
2307
|
-
.1
|
|
2308
|
-
.windows(2)
|
|
2309
|
-
.any(|pair| pair[0] == "--resume" && pair[1] == "sess-a"),
|
|
2310
|
-
"the resume spawn argv must carry the provider resume command (copilot --resume sess-a); got {:?}",
|
|
2311
|
-
recorded[0].1
|
|
2312
|
-
);
|
|
2313
|
-
}
|
|
2314
|
-
|
|
2315
|
-
// 4 [P0] — add_agent_with_transport must (a) recompile + write the spec (already works) AND (b) spawn
|
|
2316
|
-
// the new worker window. Today the stub recompiles then returns RequirementUnmet with ZERO spawns ->
|
|
2317
|
-
// RED at (b). OS-safe: the new role file is OUTSIDE agents/ (so it's not a dup), seeded healthy coordinator.
|
|
2318
|
-
#[test]
|
|
2319
|
-
fn add_agent_with_transport_spawns_new_worker_not_stub() {
|
|
2320
|
-
let team = temp_ws().join("addteam");
|
|
2321
|
-
std::fs::create_dir_all(team.join("agents")).unwrap();
|
|
2322
|
-
std::fs::write(
|
|
2323
|
-
team.join("TEAM.md"),
|
|
2324
|
-
"---\nname: addteam\nobjective: Add probe.\nprovider: codex\n---\n\nteam.\n",
|
|
2325
|
-
)
|
|
2326
|
-
.unwrap();
|
|
2327
|
-
std::fs::write(team.join("agents").join("implementer.md"), QS_VALID_ROLE).unwrap(); // existing agent
|
|
2328
|
-
let role_file = team.join("worker2-role.md"); // OUTSIDE agents/ -> not a duplicate of an existing agent
|
|
2329
|
-
std::fs::write(&role_file, DELEG_ROLE_WORKER2).unwrap();
|
|
2330
|
-
seed_healthy_coordinator(&team);
|
|
2331
|
-
seed_canonical_team_identity(&team, "addteam");
|
|
2332
|
-
let transport = OfflineTransport::new();
|
|
2333
|
-
|
|
2334
|
-
let _result = add_agent_with_transport(
|
|
2335
|
-
&team,
|
|
2336
|
-
&AgentId::new("worker2"),
|
|
2337
|
-
&role_file,
|
|
2338
|
-
false,
|
|
2339
|
-
None,
|
|
2340
|
-
&transport,
|
|
2341
|
-
);
|
|
2342
|
-
|
|
2343
|
-
// (a) the recompiled spec was written (real subsystem step). E5: under .team/runtime/<team_key>/,
|
|
2344
|
-
// NOT the user team dir.
|
|
2345
|
-
let runtime_spec = find_runtime_spec(&team, "addteam");
|
|
2346
|
-
assert!(
|
|
2347
|
-
runtime_spec.is_some(),
|
|
2348
|
-
"add_agent must recompile + write team.spec.yaml under .team/runtime/<team_key>/"
|
|
2349
|
-
);
|
|
2350
|
-
assert!(
|
|
2351
|
-
!team.join("team.spec.yaml").exists(),
|
|
2352
|
-
"E5: add_agent must NOT write spec into the user team dir"
|
|
2353
|
-
);
|
|
2354
|
-
// (b) the new worker window was spawned (RED: stub recompiles then RequirementUnmet -> ZERO spawns).
|
|
2355
|
-
let recorded = transport.spawn_records();
|
|
2356
|
-
assert!(
|
|
2357
|
-
!recorded.is_empty(),
|
|
2358
|
-
"add_agent must spawn the new worker window (>=1 recorded spawn); the rt-host-a stub recompiles \
|
|
2359
|
-
then returns RequirementUnmet with ZERO spawns; got {recorded:?}"
|
|
2360
|
-
);
|
|
2361
|
-
assert!(
|
|
2362
|
-
recorded.iter().any(|(_, argv)| argv.iter().any(|a| a == "fake-worker")),
|
|
2363
|
-
"the new worker's spawn argv must carry the provider build_command (fake-worker); got {recorded:?}"
|
|
2364
|
-
);
|
|
2365
|
-
}
|
|
2366
|
-
|
|
2367
|
-
#[test]
|
|
2368
|
-
fn add_agent_role_doc_exists_runtime_missing_succeeds() {
|
|
2369
|
-
let team = temp_ws().join("add_role_doc_team");
|
|
2370
|
-
std::fs::create_dir_all(team.join("agents")).unwrap();
|
|
2371
|
-
std::fs::write(
|
|
2372
|
-
team.join("TEAM.md"),
|
|
2373
|
-
"---\nname: addroledoc\nobjective: Add role-doc probe.\nprovider: codex\n---\n\nteam.\n",
|
|
2374
|
-
)
|
|
2375
|
-
.unwrap();
|
|
2376
|
-
std::fs::write(team.join("agents").join("implementer.md"), QS_VALID_ROLE).unwrap();
|
|
2377
|
-
let role_file = team.join("agents").join("worker2.md");
|
|
2378
|
-
std::fs::write(&role_file, DELEG_ROLE_WORKER2).unwrap();
|
|
2379
|
-
crate::state::persist::save_runtime_state(
|
|
2380
|
-
&team,
|
|
2381
|
-
&json!({
|
|
2382
|
-
"session_name": "team-addroledoc",
|
|
2383
|
-
"agents": {
|
|
2384
|
-
"implementer": {"status": "running", "provider": "fake", "window": "implementer"}
|
|
2385
|
-
}
|
|
2386
|
-
}),
|
|
2387
|
-
)
|
|
2388
|
-
.unwrap();
|
|
2389
|
-
seed_healthy_coordinator(&team);
|
|
2390
|
-
let transport = OfflineTransport::new();
|
|
2391
|
-
|
|
2392
|
-
let result = add_agent_with_transport(
|
|
2393
|
-
&team,
|
|
2394
|
-
&AgentId::new("worker2"),
|
|
2395
|
-
&role_file,
|
|
2396
|
-
false,
|
|
2397
|
-
None,
|
|
2398
|
-
&transport,
|
|
2399
|
-
);
|
|
2400
|
-
|
|
2401
|
-
assert!(
|
|
2402
|
-
result.is_ok(),
|
|
2403
|
-
"a prepared agents/<id>.md role doc is not membership; runtime state is authoritative: {result:?}"
|
|
2404
|
-
);
|
|
2405
|
-
let state = crate::state::persist::load_runtime_state(&team).expect("load state");
|
|
2406
|
-
assert!(
|
|
2407
|
-
state.pointer("/agents/worker2").is_some(),
|
|
2408
|
-
"add-agent must add worker2 to runtime state; state={state}"
|
|
2409
|
-
);
|
|
2410
|
-
assert_eq!(
|
|
2411
|
-
transport.spawn_records().len(),
|
|
2412
|
-
1,
|
|
2413
|
-
"add-agent must spawn exactly the new worker"
|
|
2414
|
-
);
|
|
2415
|
-
}
|
|
2416
|
-
|
|
2417
|
-
#[test]
|
|
2418
|
-
fn start_agent_runtime_missing_role_doc_exists_no_side_effect() {
|
|
2419
|
-
let team = temp_ws().join("start_missing_team");
|
|
2420
|
-
std::fs::create_dir_all(team.join("agents")).unwrap();
|
|
2421
|
-
std::fs::write(
|
|
2422
|
-
team.join("TEAM.md"),
|
|
2423
|
-
"---\nname: startmissing\nobjective: Start missing probe.\nprovider: codex\n---\n\nteam.\n",
|
|
2424
|
-
)
|
|
2425
|
-
.unwrap();
|
|
2426
|
-
std::fs::write(team.join("agents").join("reviewer.md"), DELEG_ROLE_WORKER2).unwrap();
|
|
2427
|
-
crate::state::persist::save_runtime_state(
|
|
2428
|
-
&team,
|
|
2429
|
-
&json!({
|
|
2430
|
-
"session_name": "team-startmissing",
|
|
2431
|
-
"agents": {
|
|
2432
|
-
"implementer": {"status": "running", "provider": "fake", "window": "implementer"}
|
|
2433
|
-
}
|
|
2434
|
-
}),
|
|
2435
|
-
)
|
|
2436
|
-
.unwrap();
|
|
2437
|
-
let transport = OfflineTransport::new();
|
|
2438
|
-
|
|
2439
|
-
let result = start_agent_with_transport(
|
|
2440
|
-
&team,
|
|
2441
|
-
&AgentId::new("reviewer"),
|
|
2442
|
-
false,
|
|
2443
|
-
false,
|
|
2444
|
-
true,
|
|
2445
|
-
None,
|
|
2446
|
-
&transport,
|
|
2447
|
-
);
|
|
2448
|
-
|
|
2449
|
-
let text = format!("{result:?}");
|
|
2450
|
-
assert!(
|
|
2451
|
-
text.contains("not found"),
|
|
2452
|
-
"start-agent must refuse runtime-missing agents before side effects; got {text}"
|
|
2453
|
-
);
|
|
2454
|
-
assert!(
|
|
2455
|
-
transport.spawn_records().is_empty(),
|
|
2456
|
-
"runtime-missing start-agent must not spawn a pane"
|
|
2457
|
-
);
|
|
2458
|
-
assert!(
|
|
2459
|
-
!team
|
|
2460
|
-
.join(".team")
|
|
2461
|
-
.join("runtime")
|
|
2462
|
-
.join("mcp")
|
|
2463
|
-
.join("reviewer.json")
|
|
2464
|
-
.exists(),
|
|
2465
|
-
"runtime-missing start-agent must not write worker MCP config"
|
|
2466
|
-
);
|
|
2467
|
-
let events = crate::event_log::EventLog::new(&team)
|
|
2468
|
-
.tail(20)
|
|
2469
|
-
.unwrap_or_default();
|
|
2470
|
-
assert!(
|
|
2471
|
-
!events.iter().any(|event| {
|
|
2472
|
-
event.get("event").and_then(|v| v.as_str()) == Some("start_agent.agent_start")
|
|
2473
|
-
}),
|
|
2474
|
-
"runtime-missing start-agent must not emit start_agent.agent_start; events={events:?}"
|
|
2475
|
-
);
|
|
2476
|
-
}
|
|
2477
|
-
|
|
2478
|
-
/// 0.4.6 tuple-atomic contract (audit §Restart 修改清单, line 177): Copilot
|
|
2479
|
-
/// fresh restart MUST leave `session_id=null` in persisted state. The argv
|
|
2480
|
-
/// still carries `--session-id <uuid>` (planned capture hint), and the row
|
|
2481
|
-
/// keeps `_pending_session_id=<uuid>` so the Copilot scanner can confirm
|
|
2482
|
-
/// the sqlite entry on next tick and promote into the authoritative tuple.
|
|
2483
|
-
/// Pre-0.4.6, restart promoted the planned uuid directly into `session_id`
|
|
2484
|
-
/// without scanner confirmation, violating the capture-only-writer rule
|
|
2485
|
-
/// (audit §Restart 当前违规 #1).
|
|
2486
|
-
#[test]
|
|
2487
|
-
fn restart_allow_fresh_copilot_keeps_session_id_null_until_capture_confirms() {
|
|
2488
|
-
let ws = temp_ws().join("restartcopilot");
|
|
2489
|
-
std::fs::create_dir_all(ws.join("agents")).unwrap();
|
|
2490
|
-
std::fs::write(
|
|
2491
|
-
ws.join("TEAM.md"),
|
|
2492
|
-
"---\nname: restartcopilot\nobjective: Restart copilot probe.\nprovider: copilot\n---\n\nteam.\n",
|
|
2493
|
-
)
|
|
2494
|
-
.unwrap();
|
|
2495
|
-
std::fs::write(
|
|
2496
|
-
ws.join("agents").join("alpha.md"),
|
|
2497
|
-
"---\nname: alpha\nrole: Alpha Worker\nprovider: copilot\nmodel: gpt-5.5\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nAlpha.\n",
|
|
2498
|
-
)
|
|
2499
|
-
.unwrap();
|
|
2500
|
-
let spec = crate::compiler::compile_team(&ws).expect("compile copilot team");
|
|
2501
|
-
std::fs::write(ws.join("team.spec.yaml"), crate::model::yaml::dumps(&spec)).unwrap();
|
|
2502
|
-
crate::state::persist::save_runtime_state(
|
|
2503
|
-
&ws,
|
|
2504
|
-
&json!({
|
|
2505
|
-
"session_name": "team-restartcopilot",
|
|
2506
|
-
"agents": {
|
|
2507
|
-
"alpha": {
|
|
2508
|
-
"status": "running",
|
|
2509
|
-
"provider": "copilot",
|
|
2510
|
-
"window": "alpha",
|
|
2511
|
-
"first_send_at": "2026-05-27T10:00:00+00:00",
|
|
2512
|
-
"session_id": null,
|
|
2513
|
-
"rollout_path": "/tmp/stale-copilot-rollout.jsonl",
|
|
2514
|
-
"captured_at": "2026-05-27T10:00:00+00:00",
|
|
2515
|
-
"captured_via": "stale",
|
|
2516
|
-
"attribution_confidence": "stale"
|
|
2517
|
-
}
|
|
2518
|
-
}
|
|
2519
|
-
}),
|
|
2520
|
-
)
|
|
2521
|
-
.unwrap();
|
|
2522
|
-
seed_healthy_coordinator(&ws);
|
|
2523
|
-
let transport = OfflineTransport::new();
|
|
2524
|
-
|
|
2525
|
-
let result = restart_with_transport(&ws, true, None, &transport);
|
|
2526
|
-
|
|
2527
|
-
assert!(
|
|
2528
|
-
matches!(result, Ok(RestartReport::Restarted { .. })),
|
|
2529
|
-
"allow-fresh restart should fresh-spawn the copilot worker; got {result:?}"
|
|
2530
|
-
);
|
|
2531
|
-
let recorded = transport.spawn_records();
|
|
2532
|
-
assert_eq!(
|
|
2533
|
-
recorded.len(),
|
|
2534
|
-
1,
|
|
2535
|
-
"expected one copilot spawn; got {recorded:?}"
|
|
2536
|
-
);
|
|
2537
|
-
let session_arg = recorded[0]
|
|
2538
|
-
.1
|
|
2539
|
-
.windows(2)
|
|
2540
|
-
.find_map(|pair| (pair[0] == "--session-id").then(|| pair[1].clone()))
|
|
2541
|
-
.expect("copilot fresh spawn argv must include --session-id");
|
|
2542
|
-
let instructions =
|
|
2543
|
-
std::fs::read_to_string(ws.join(".team/runtime/copilot-instructions/alpha/AGENTS.md"))
|
|
2544
|
-
.expect("restart/add/clone spawn must materialize Copilot instructions");
|
|
2545
|
-
assert!(instructions.contains("Alpha Worker"));
|
|
2546
|
-
let state = crate::state::persist::load_runtime_state(&ws).expect("load state");
|
|
2547
|
-
let agent = state.pointer("/agents/alpha").expect("alpha state");
|
|
2548
|
-
// 0.4.6 contract: session_id stays null until scanner confirms sqlite.
|
|
2549
|
-
assert_eq!(
|
|
2550
|
-
agent.get("session_id"),
|
|
2551
|
-
Some(&serde_json::Value::Null),
|
|
2552
|
-
"fresh restart must NOT promote planned id into session_id; \
|
|
2553
|
-
capture (scanner) is the only authoritative writer. agent={agent}"
|
|
2554
|
-
);
|
|
2555
|
-
// The pending hint is preserved so the Copilot scanner has the
|
|
2556
|
-
// expected-id binding on the next coordinator tick.
|
|
2557
|
-
assert_eq!(
|
|
2558
|
-
agent
|
|
2559
|
-
.get("_pending_session_id")
|
|
2560
|
-
.and_then(serde_json::Value::as_str),
|
|
2561
|
-
Some(session_arg.as_str()),
|
|
2562
|
-
"fresh restart must retain _pending_session_id matching argv --session-id; \
|
|
2563
|
-
this is the capture hint the scanner uses for sqlite confirmation"
|
|
2564
|
-
);
|
|
2565
|
-
for stale in [
|
|
2566
|
-
"rollout_path",
|
|
2567
|
-
"captured_at",
|
|
2568
|
-
"captured_via",
|
|
2569
|
-
"attribution_confidence",
|
|
2570
|
-
] {
|
|
2571
|
-
let value = agent.get(stale);
|
|
2572
|
-
assert!(
|
|
2573
|
-
value.is_none() || value == Some(&serde_json::Value::Null),
|
|
2574
|
-
"fresh restart must clear stale capture field {stale}; got {value:?}"
|
|
2575
|
-
);
|
|
2576
|
-
}
|
|
2577
|
-
// Second classify must NOT silently refuse — the row has no session_id
|
|
2578
|
-
// (caller still needs to use --allow-fresh or wait for capture).
|
|
2579
|
-
let plan = crate::lifecycle::restart::classify_restart_plan(&state, false)
|
|
2580
|
-
.expect("classify second restart");
|
|
2581
|
-
// The worker has session_id=null + a non-empty _pending_session_id,
|
|
2582
|
-
// so classify treats it as no-persisted-session-id (not backing-missing),
|
|
2583
|
-
// which `--allow-fresh` resolves cleanly without loops.
|
|
2584
|
-
let _ = plan; // shape verified above; details depend on classifier internals.
|
|
2585
|
-
}
|
|
2586
|
-
|
|
2587
|
-
/// 0.4.6 tuple-atomic contract (audit, line 268): Claude fresh restart
|
|
2588
|
-
/// leaves session_id=null even when input row had a stale session_id.
|
|
2589
|
-
/// The poisoned-row scenario (Bug 045 release-engineer state).
|
|
2590
|
-
#[test]
|
|
2591
|
-
fn restart_allow_fresh_claude_clears_poisoned_session_id() {
|
|
2592
|
-
let ws = temp_ws().join("restartclaude046");
|
|
2593
|
-
std::fs::create_dir_all(ws.join("agents")).unwrap();
|
|
2594
|
-
std::fs::write(
|
|
2595
|
-
ws.join("TEAM.md"),
|
|
2596
|
-
"---\nname: restartclaude046\nobjective: 0.4.6 contract.\nprovider: claude\n---\n\nteam.\n",
|
|
2597
|
-
)
|
|
2598
|
-
.unwrap();
|
|
2599
|
-
std::fs::write(
|
|
2600
|
-
ws.join("agents").join("alpha.md"),
|
|
2601
|
-
"---\nname: alpha\nrole: Alpha\nprovider: claude\nmodel: sonnet\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nAlpha.\n",
|
|
2602
|
-
)
|
|
2603
|
-
.unwrap();
|
|
2604
|
-
let spec = crate::compiler::compile_team(&ws).expect("compile");
|
|
2605
|
-
std::fs::write(ws.join("team.spec.yaml"), crate::model::yaml::dumps(&spec)).unwrap();
|
|
2606
|
-
let stale_uuid = "bd68bfbd-b9b6-4e0e-8197-ce5a47c4a930";
|
|
2607
|
-
crate::state::persist::save_runtime_state(
|
|
2608
|
-
&ws,
|
|
2609
|
-
&json!({
|
|
2610
|
-
"session_name": "team-restartclaude046",
|
|
2611
|
-
"agents": {
|
|
2612
|
-
"alpha": {
|
|
2613
|
-
"status": "running",
|
|
2614
|
-
"provider": "claude",
|
|
2615
|
-
"window": "alpha",
|
|
2616
|
-
"first_send_at": "2026-06-23T10:00:00+00:00",
|
|
2617
|
-
"session_id": stale_uuid,
|
|
2618
|
-
"rollout_path": null,
|
|
2619
|
-
"captured_at": null,
|
|
2620
|
-
"captured_via": null
|
|
2621
|
-
}
|
|
2622
|
-
}
|
|
2623
|
-
}),
|
|
2624
|
-
)
|
|
2625
|
-
.unwrap();
|
|
2626
|
-
seed_healthy_coordinator(&ws);
|
|
2627
|
-
let transport = OfflineTransport::new();
|
|
2628
|
-
|
|
2629
|
-
let result = restart_with_transport(&ws, true, None, &transport);
|
|
2630
|
-
assert!(
|
|
2631
|
-
matches!(result, Ok(RestartReport::Restarted { .. })),
|
|
2632
|
-
"allow-fresh restart should fresh-spawn the claude worker; got {result:?}"
|
|
2633
|
-
);
|
|
2634
|
-
|
|
2635
|
-
let state = crate::state::persist::load_runtime_state(&ws).expect("load state");
|
|
2636
|
-
let agent = state.pointer("/agents/alpha").expect("alpha");
|
|
2637
|
-
assert_eq!(
|
|
2638
|
-
agent.get("session_id"),
|
|
2639
|
-
Some(&serde_json::Value::Null),
|
|
2640
|
-
"0.4.6 contract: Claude fresh restart must clear stale session_id; agent={agent}"
|
|
2641
|
-
);
|
|
2642
|
-
// C1 dual-projection: teams.<key>.agents.alpha.session_id must also be null.
|
|
2643
|
-
if let Some(teams) = state.get("teams").and_then(serde_json::Value::as_object) {
|
|
2644
|
-
for (team_key, team_state) in teams {
|
|
2645
|
-
if let Some(team_alpha) = team_state.pointer("/agents/alpha") {
|
|
2646
|
-
let team_session = team_alpha.get("session_id");
|
|
2647
|
-
assert!(
|
|
2648
|
-
team_session.is_none() || team_session == Some(&serde_json::Value::Null),
|
|
2649
|
-
"0.4.6: teams.{team_key}.agents.alpha.session_id must be null; got {team_session:?}"
|
|
2650
|
-
);
|
|
2651
|
-
}
|
|
2652
|
-
}
|
|
2653
|
-
}
|
|
2654
|
-
}
|
|
2655
|
-
|
|
2656
|
-
/// 0.4.6 tuple-atomic contract (audit §Fork 修改清单, line 201): fork
|
|
2657
|
-
/// with a scalar `session_id` but no rollout_path/captured_at/captured_via
|
|
2658
|
-
/// must be REFUSED before the native fork. Pre-0.4.6 fork only checked
|
|
2659
|
-
/// session_id non-empty, which let it attach to a session with no
|
|
2660
|
-
/// confirmed backing.
|
|
2661
|
-
#[test]
|
|
2662
|
-
fn fork_refuses_source_with_partial_tuple() {
|
|
2663
|
-
let ws = temp_ws().join("forkpartial046");
|
|
2664
|
-
std::fs::create_dir_all(ws.join("agents")).unwrap();
|
|
2665
|
-
std::fs::write(
|
|
2666
|
-
ws.join("TEAM.md"),
|
|
2667
|
-
"---\nname: forkpartial046\nobjective: fork tuple.\nprovider: codex\n---\n\nteam.\n",
|
|
2668
|
-
)
|
|
2669
|
-
.unwrap();
|
|
2670
|
-
std::fs::write(
|
|
2671
|
-
ws.join("agents").join("src.md"),
|
|
2672
|
-
"---\nname: src\nrole: Source\nprovider: copilot\nmodel: gpt-5.5\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nSrc.\n",
|
|
2673
|
-
)
|
|
2674
|
-
.unwrap();
|
|
2675
|
-
let spec = crate::compiler::compile_team(&ws).expect("compile");
|
|
2676
|
-
std::fs::write(ws.join("team.spec.yaml"), crate::model::yaml::dumps(&spec)).unwrap();
|
|
2677
|
-
crate::state::persist::save_runtime_state(
|
|
2678
|
-
&ws,
|
|
2679
|
-
&json!({
|
|
2680
|
-
"session_name": "team-forkpartial046",
|
|
2681
|
-
"agents": {
|
|
2682
|
-
"src": {
|
|
2683
|
-
"status": "running",
|
|
2684
|
-
"provider": "copilot",
|
|
2685
|
-
"window": "src",
|
|
2686
|
-
"first_send_at": "2026-06-25T10:00:00+00:00",
|
|
2687
|
-
"session_id": "scalar-only-uuid",
|
|
2688
|
-
"rollout_path": null,
|
|
2689
|
-
"captured_at": null,
|
|
2690
|
-
"captured_via": null
|
|
2691
|
-
}
|
|
2692
|
-
}
|
|
2693
|
-
}),
|
|
2694
|
-
)
|
|
2695
|
-
.unwrap();
|
|
2696
|
-
let transport = OfflineTransport::new();
|
|
2697
|
-
|
|
2698
|
-
// fork_agent is the entry point; it should refuse with a clear message.
|
|
2699
|
-
let src_id = crate::model::ids::AgentId::new("src");
|
|
2700
|
-
let dst_id = crate::model::ids::AgentId::new("clone");
|
|
2701
|
-
let result = crate::lifecycle::fork_agent_with_transport(
|
|
2702
|
-
&ws, &src_id, &dst_id, None, // label
|
|
2703
|
-
false, // open_display
|
|
2704
|
-
None, // team
|
|
2705
|
-
&transport,
|
|
2706
|
-
);
|
|
2707
|
-
assert!(
|
|
2708
|
-
result.is_err(),
|
|
2709
|
-
"0.4.6: fork with partial source tuple must be refused; got Ok({result:?})"
|
|
2710
|
-
);
|
|
2711
|
-
let err = result.unwrap_err().to_string();
|
|
2712
|
-
assert!(
|
|
2713
|
-
err.contains("unverified")
|
|
2714
|
-
|| err.contains("未验证")
|
|
2715
|
-
|| err.contains("backing")
|
|
2716
|
-
|| err.contains("incomplete"),
|
|
2717
|
-
"0.4.6/in-window: unverified providers refuse before backing check; got error={err}"
|
|
2718
|
-
);
|
|
2719
|
-
}
|
|
2720
|
-
|
|
2721
|
-
#[test]
|
|
2722
|
-
fn stop_agent_adaptive_kills_target_pane_not_shared_layout_window() {
|
|
2723
|
-
let roles = [("w1.md", role_doc("w1")), ("w2.md", role_doc("w2"))];
|
|
2724
|
-
let role_refs = roles
|
|
2725
|
-
.iter()
|
|
2726
|
-
.map(|(file, doc)| (*file, doc.as_str()))
|
|
2727
|
-
.collect::<Vec<_>>();
|
|
2728
|
-
let team = quick_start_team_dir_with_roles(&role_refs);
|
|
2729
|
-
let spec = crate::compiler::compile_team(&team).unwrap();
|
|
2730
|
-
std::fs::write(
|
|
2731
|
-
team.join("team.spec.yaml"),
|
|
2732
|
-
crate::model::yaml::dumps(&spec),
|
|
2733
|
-
)
|
|
2734
|
-
.unwrap();
|
|
2735
|
-
let session = "team-layout-stop";
|
|
2736
|
-
crate::state::persist::save_runtime_state(
|
|
2737
|
-
&team,
|
|
2738
|
-
&json!({
|
|
2739
|
-
"session_name": session,
|
|
2740
|
-
"legacy_display_key": "adaptive",
|
|
2741
|
-
"agents": {
|
|
2742
|
-
"w1": {"status": "running", "provider": "fake", "window": "team-w1", "layout_window": "team-w1", "layout_index": 0, "pane_index": 0, "pane_id": "%1"},
|
|
2743
|
-
"w2": {"status": "running", "provider": "fake", "window": "team-w1", "layout_window": "team-w1", "layout_index": 0, "pane_index": 1, "pane_id": "%2"}
|
|
2744
|
-
}
|
|
2745
|
-
}),
|
|
2746
|
-
)
|
|
2747
|
-
.unwrap();
|
|
2748
|
-
let transport = OfflineTransport::new()
|
|
2749
|
-
.with_targets(vec![
|
|
2750
|
-
layout_pane(session, "team-w1", "%1", 0),
|
|
2751
|
-
layout_pane(session, "team-w1", "%2", 1),
|
|
2752
|
-
])
|
|
2753
|
-
.with_pane_presence("%2", true);
|
|
2754
|
-
|
|
2755
|
-
let report = stop_agent_with_transport(&team, &AgentId::new("w2"), None, &transport).unwrap();
|
|
2756
|
-
|
|
2757
|
-
assert!(report.stopped);
|
|
2758
|
-
assert_eq!(report.target, "%2");
|
|
2759
|
-
assert!(
|
|
2760
|
-
transport.calls().iter().any(|call| *call == "kill_pane"),
|
|
2761
|
-
"adaptive stop must kill only the target pane"
|
|
2762
|
-
);
|
|
2763
|
-
assert!(
|
|
2764
|
-
!transport.calls().iter().any(|call| *call == "kill_window"),
|
|
2765
|
-
"adaptive stop must not kill the shared layout window"
|
|
2766
|
-
);
|
|
2767
|
-
let (_raw, state) = raw_runtime_state(&team);
|
|
2768
|
-
assert_eq!(state.pointer("/agents/w1/pane_id"), Some(&json!("%1")));
|
|
2769
|
-
assert_eq!(
|
|
2770
|
-
state.pointer("/agents/w1/layout_window"),
|
|
2771
|
-
Some(&json!("team-w1"))
|
|
2772
|
-
);
|
|
2773
|
-
}
|
|
2774
|
-
|
|
2775
|
-
// ═════════════════════════════════════════════════════════════════════════
|
|
2776
|
-
// WAVE 2 · LANE A — agent-lifecycle byte-parity contracts. stop_agent / reset_agent / remove_agent /
|
|
2777
|
-
// fork_agent are stubs (OwnerRefused / RequirementUnmet / "session_id missing"). These RED contracts
|
|
2778
|
-
// LOCK the golden behavior (lifecycle/operations.py + agents.py). The existing tolerant tests accept the
|
|
2779
|
-
// stub; these are STRICTER (RED today). OS-safe: no-owner ws + seeded spec/state, non-running agents
|
|
2780
|
-
// (pure fs/state). Transport-asserting parts (kill_window / native-fork spawn) -> seam + #[ignore].
|
|
2781
|
-
// ═════════════════════════════════════════════════════════════════════════
|
|
2782
|
-
|
|
2783
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
2784
|
-
// collect #223 — task-scoped seeding (RED). Golden launch/core.py:69 ALWAYS seeds the runtime
|
|
2785
|
-
// state's `tasks` key from spec.tasks (≥ []); the doc compiler emits a default task
|
|
2786
|
-
// {id:"task_initial",…} (compiler.rs:308). Rust initial_runtime_state (launch.rs) emits only
|
|
2787
|
-
// {session_name,team_dir,agents} — NO tasks key → send/collect cannot resolve the task. RED.
|
|
2788
|
-
// OS-safe: OfflineTransport (zero real spawn).
|
|
2789
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
2790
|
-
#[test]
|
|
2791
|
-
#[serial(env)]
|
|
2792
|
-
fn quick_start_seeds_tasks_key_from_compiled_spec() {
|
|
2793
|
-
let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("launch-spawn-tasks-key");
|
|
2794
|
-
let team = quick_start_team_dir(QS_VALID_ROLE);
|
|
2795
|
-
seed_healthy_coordinator(&crate::model::paths::team_workspace(&team).unwrap());
|
|
2796
|
-
let transport = OfflineTransport::new();
|
|
2797
|
-
let _ = quick_start_with_transport(&team, None, true, None, &transport);
|
|
2798
|
-
let workspace = team
|
|
2799
|
-
.parent()
|
|
2800
|
-
.expect("team_workspace(<base>/teamdir) = <base>");
|
|
2801
|
-
let state = crate::state::persist::load_runtime_state(workspace)
|
|
2802
|
-
.expect("runtime state.json must exist after quick_start");
|
|
2803
|
-
// (b) the tasks KEY must always be present and a JSON array (golden launch/core.py:69 default []).
|
|
2804
|
-
let tasks = match state.get("tasks") {
|
|
2805
|
-
Some(t) => t,
|
|
2806
|
-
None => panic!(
|
|
2807
|
-
"initial_runtime_state MUST seed a `tasks` key (golden launch/core.py:69 `tasks=[…spec.tasks]`); \
|
|
2808
|
-
state keys = {:?}",
|
|
2809
|
-
state.as_object().map(|o| o.keys().cloned().collect::<Vec<_>>())
|
|
2810
|
-
),
|
|
2811
|
-
};
|
|
2812
|
-
let tasks = tasks
|
|
2813
|
-
.as_array()
|
|
2814
|
-
.expect("`tasks` must be a JSON array (golden default [])");
|
|
2815
|
-
// (a) spec.tasks must be carried into runtime state — the doc compiler's default task id.
|
|
2816
|
-
assert!(
|
|
2817
|
-
tasks
|
|
2818
|
-
.iter()
|
|
2819
|
-
.any(|t| t.get("id").and_then(|v| v.as_str()) == Some("task_initial")),
|
|
2820
|
-
"state.tasks must carry the compiled spec's task (id=task_initial); got {tasks:?}"
|
|
2821
|
-
);
|
|
2822
|
-
}
|
|
2823
|
-
|
|
2824
|
-
// Stage A — golden launch/core.py:62-71 seeded top-level runtime state in insertion order:
|
|
2825
|
-
// spec_path, workspace, team_dir, team_key, session_name, leader, agents, tasks.
|
|
2826
|
-
//
|
|
2827
|
-
// The runtime state is tmux-only; no display backend is persisted.
|
|
2828
|
-
// NEW (Bug 1/2 — team-in-team state scope, see tests/team_in_team_state_scope_red.rs):
|
|
2829
|
-
// `active_team_key` and `teams` are appended at the tail so the runtime can carry the
|
|
2830
|
-
// nested team-in-team scope alongside the original flat fields. Owner-binding fields
|
|
2831
|
-
// (`leader_receiver` / `team_owner` / `owner_epoch`) live ONLY under
|
|
2832
|
-
// `teams[<active_team_key>]` — Bug 2 owner team-scope (N1/N12/N18/N29) deliberately
|
|
2833
|
-
// keeps them OFF the root so per-team isolation has a single source of truth and
|
|
2834
|
-
// cross-team reads cannot accidentally pick up another team's binding from the root.
|
|
2835
|
-
// The post-launch hook drops the top-level owner triple when the launched pane is
|
|
2836
|
-
// unbound (empty pane_id), and only the per-team entry retains the binding.
|
|
2837
|
-
// R1: topology is explicit; fresh managed teams carry `is_external_leader=false`
|
|
2838
|
-
// before the team-in-team suffix. Canonical `team_key` is seeded before owner
|
|
2839
|
-
// binding; the remaining order stays the golden prefix + topology marker + new
|
|
2840
|
-
// suffix (active_team_key, teams).
|
|
2841
|
-
#[test]
|
|
2842
|
-
#[serial(env)]
|
|
2843
|
-
fn quick_start_unbound_state_producer_seeds_spec_path_workspace_leader() {
|
|
2844
|
-
let _hermetic = enter_hermetic("launch-spawn-state-seeds");
|
|
2845
|
-
// Bug 2 owner team-scope: top-level owner triple is dropped when the seeded
|
|
2846
|
-
// pane is empty; an ambient TMUX_PANE (tests run inside the dev's tmux session)
|
|
2847
|
-
// would otherwise leak into the caller-identity seed, inflate the seeded owner
|
|
2848
|
-
// with a non-empty pane, and keep the top-level keys present — masking the
|
|
2849
|
-
// per-team-isolation invariant this assertion locks. Force-unset for the test.
|
|
2850
|
-
let _tmux_pane = EnvVarGuard::unset("TMUX_PANE");
|
|
2851
|
-
let _tmux = EnvVarGuard::unset("TMUX");
|
|
2852
|
-
let team = quick_start_team_dir(QS_VALID_ROLE);
|
|
2853
|
-
let transport = OfflineTransport::new();
|
|
2854
|
-
let workspace = team
|
|
2855
|
-
.parent()
|
|
2856
|
-
.expect("team_workspace(<base>/teamdir) = <base>");
|
|
2857
|
-
// Test the real unbound state producer plus recording-only worker stage.
|
|
2858
|
-
// Public start correctly refuses this absent caller (separate regressions).
|
|
2859
|
-
crate::lifecycle::launch::materialize_unbound_state_for_test(
|
|
2860
|
-
workspace, &team, "quickteam", &transport,
|
|
2861
|
-
).expect("materialize the unbound producer fixture without public start");
|
|
2862
|
-
// E5: spec_path in state now points to .team/runtime/<team_key>/, team_dir stays the user role dir.
|
|
2863
|
-
let spec_path = quick_start_runtime_spec_path(&team);
|
|
2864
|
-
let (raw, state) = raw_runtime_state(workspace);
|
|
2865
|
-
let keys = state
|
|
2866
|
-
.as_object()
|
|
2867
|
-
.expect("state root object")
|
|
2868
|
-
.keys()
|
|
2869
|
-
.cloned()
|
|
2870
|
-
.collect::<Vec<_>>();
|
|
2871
|
-
assert_eq!(
|
|
2872
|
-
keys,
|
|
2873
|
-
vec![
|
|
2874
|
-
"spec_path",
|
|
2875
|
-
"workspace",
|
|
2876
|
-
"team_dir",
|
|
2877
|
-
// Seed canonical identity before owner binding so the initial
|
|
2878
|
-
// receiver is written under the same team key as the saved state.
|
|
2879
|
-
"team_key",
|
|
2880
|
-
"session_name",
|
|
2881
|
-
"leader",
|
|
2882
|
-
"agents",
|
|
2883
|
-
"tasks",
|
|
2884
|
-
"is_external_leader",
|
|
2885
|
-
// 0.5.x Phase 1d hot-path 接线 (裁决1 msg_76e1d98202b8):
|
|
2886
|
-
// `transport = { kind, source }` inserted here by
|
|
2887
|
-
// `annotate_runtime_transport`. Kind is `"tmux"` for the
|
|
2888
|
-
// default tmux path (byte-equivalent behavior + new metadata
|
|
2889
|
-
// field); source is `"unknown"` until Phase 2 threads
|
|
2890
|
-
// `ResolvedTransport.source` through the launch call site.
|
|
2891
|
-
"transport",
|
|
2892
|
-
"active_team_key",
|
|
2893
|
-
// Persist physical session birth independently of worker respawns.
|
|
2894
|
-
"generation",
|
|
2895
|
-
"teams",
|
|
2896
|
-
],
|
|
2897
|
-
"state.json top-level key order must match golden launch/core.py:62-71 \
|
|
2898
|
-
plus R1 topology marker and Bug 1/2 team-in-team suffix \
|
|
2899
|
-
(is_external_leader, active_team_key, teams). \
|
|
2900
|
-
Bug 2 owner team-scope (N1/N12/N18/N29) deliberately keeps owner / \
|
|
2901
|
-
leader_receiver / owner_epoch OFF the top level — they live ONLY under \
|
|
2902
|
-
teams[<active_team_key>] so per-team isolation has a single source of \
|
|
2903
|
-
truth (no shadow copy on the root that callers could read across teams); \
|
|
2904
|
-
raw={raw}"
|
|
2905
|
-
);
|
|
2906
|
-
assert_eq!(
|
|
2907
|
-
state["spec_path"],
|
|
2908
|
-
json!(spec_path.canonicalize().unwrap().to_string_lossy())
|
|
2909
|
-
);
|
|
2910
|
-
assert_eq!(state["workspace"], json!(workspace.to_string_lossy()));
|
|
2911
|
-
assert_eq!(state["team_dir"], json!(team.to_string_lossy()));
|
|
2912
|
-
assert_eq!(state["session_name"], json!("team-quickteam"));
|
|
2913
|
-
assert_eq!(
|
|
2914
|
-
state["leader"]["id"],
|
|
2915
|
-
json!("leader"),
|
|
2916
|
-
"leader must be copied from compiled spec.leader"
|
|
2917
|
-
);
|
|
2918
|
-
assert!(
|
|
2919
|
-
state["agents"]
|
|
2920
|
-
.as_object()
|
|
2921
|
-
.is_some_and(|agents| agents.contains_key("implementer")),
|
|
2922
|
-
"existing agents value must remain seeded from compiled spec; got {:?}",
|
|
2923
|
-
state["agents"]
|
|
2924
|
-
);
|
|
2925
|
-
assert!(
|
|
2926
|
-
state["tasks"].as_array().is_some_and(|tasks| {
|
|
2927
|
-
tasks
|
|
2928
|
-
.iter()
|
|
2929
|
-
.any(|task| task.get("id").and_then(|id| id.as_str()) == Some("task_initial"))
|
|
2930
|
-
}),
|
|
2931
|
-
"existing tasks value must remain seeded from compiled spec; got {:?}",
|
|
2932
|
-
state["tasks"]
|
|
2933
|
-
);
|
|
2934
|
-
assert_eq!(state["is_external_leader"], json!(false));
|
|
2935
|
-
}
|
|
2936
|
-
|
|
2937
|
-
// Stage B1 — golden launch/core.py:238-255 writes the running agent state only after
|
|
2938
|
-
// a successful spawn. The fixed clock is a test seam for `spawned_at`; capture intentionally
|
|
2939
|
-
// misses, so session/capture fields remain present JSON nulls. MCP install is deterministic:
|
|
2940
|
-
// provider_cli/adapter.py:111-114 writes workspace/.team/runtime/mcp/<agent>.json.
|
|
2941
|
-
#[test]
|
|
2942
|
-
#[serial(env)]
|
|
2943
|
-
fn quick_start_running_agent_state_shape_after_spawn_is_golden() {
|
|
2944
|
-
let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("launch-spawn-running-state");
|
|
2945
|
-
const FIXED_SPAWNED_AT: &str = "2026-06-04T00:00:00+00:00";
|
|
2946
|
-
let _clock_guard = EnvVarGuard::set("TEAM_AGENT_TEST_FIXED_SPAWNED_AT", FIXED_SPAWNED_AT);
|
|
2947
|
-
let team = quick_start_team_dir(QS_VALID_ROLE);
|
|
2948
|
-
seed_healthy_coordinator(&crate::model::paths::team_workspace(&team).unwrap());
|
|
2949
|
-
let transport = OfflineTransport::new();
|
|
2950
|
-
let _ = quick_start_with_transport(&team, None, true, None, &transport);
|
|
2951
|
-
let workspace = team
|
|
2952
|
-
.parent()
|
|
2953
|
-
.expect("team_workspace(<base>/teamdir) = <base>");
|
|
2954
|
-
let (raw, state) = raw_runtime_state(workspace);
|
|
2955
|
-
let agent = state
|
|
2956
|
-
.pointer("/agents/implementer")
|
|
2957
|
-
.unwrap_or_else(|| panic!("implementer agent state missing; raw={raw}"));
|
|
2958
|
-
let keys = agent
|
|
2959
|
-
.as_object()
|
|
2960
|
-
.expect("agent state object")
|
|
2961
|
-
.keys()
|
|
2962
|
-
.cloned()
|
|
2963
|
-
.collect::<Vec<_>>();
|
|
2964
|
-
// 0.3.28 Step 4b: adaptive layout fields (layout_window, layout_index,
|
|
2965
|
-
// pane_index, display) removed from running agent state — 1-window-per-agent
|
|
2966
|
-
// means no layout bookkeeping needed.
|
|
2967
|
-
assert_eq!(
|
|
2968
|
-
keys,
|
|
2969
|
-
vec![
|
|
2970
|
-
"status",
|
|
2971
|
-
"provider",
|
|
2972
|
-
"agent_id",
|
|
2973
|
-
"model",
|
|
2974
|
-
"auth_mode",
|
|
2975
|
-
"profile",
|
|
2976
|
-
"window",
|
|
2977
|
-
"mcp_config",
|
|
2978
|
-
"effective_approval_policy",
|
|
2979
|
-
// 0.5.66 bypass 单源:fresh spawn 记录运行面 bypass 值(restart drift 挡板)。
|
|
2980
|
-
"as_launched_dangerously_skip_permissions",
|
|
2981
|
-
"session_id",
|
|
2982
|
-
"rollout_path",
|
|
2983
|
-
"captured_at",
|
|
2984
|
-
"captured_via",
|
|
2985
|
-
"attribution_confidence",
|
|
2986
|
-
"capture_state",
|
|
2987
|
-
"spawn_cwd",
|
|
2988
|
-
"spawned_at",
|
|
2989
|
-
"pane_id",
|
|
2990
|
-
],
|
|
2991
|
-
"the fake worker has no pre-assigned session id, so no framework _pending_session_id; raw={raw}"
|
|
2992
|
-
);
|
|
2993
|
-
assert_eq!(agent["status"], json!("running"));
|
|
2994
|
-
assert_eq!(agent["provider"], json!("fake"));
|
|
2995
|
-
assert_eq!(agent["agent_id"], json!("implementer"));
|
|
2996
|
-
assert_eq!(agent["model"], json!("fake"));
|
|
2997
|
-
assert_eq!(agent["auth_mode"], json!("subscription"));
|
|
2998
|
-
assert!(agent["profile"].is_null());
|
|
2999
|
-
assert_eq!(agent["window"], json!("implementer"));
|
|
3000
|
-
assert_eq!(
|
|
3001
|
-
agent["mcp_config"],
|
|
3002
|
-
json!(workspace
|
|
3003
|
-
.join(".team/runtime/mcp/implementer.json")
|
|
3004
|
-
.to_string_lossy())
|
|
3005
|
-
);
|
|
3006
|
-
assert!(agent["session_id"].is_null());
|
|
3007
|
-
assert!(agent["rollout_path"].is_null());
|
|
3008
|
-
assert!(agent["captured_at"].is_null());
|
|
3009
|
-
assert!(agent["captured_via"].is_null());
|
|
3010
|
-
assert!(agent["attribution_confidence"].is_null());
|
|
3011
|
-
// 0.3.28 Step 4b: layout_window/layout_index/pane_index/display removed.
|
|
3012
|
-
// No adaptive bookkeeping needed — each worker has its own window named
|
|
3013
|
-
// after the agent_id.
|
|
3014
|
-
assert!(agent.get("layout_window").is_none());
|
|
3015
|
-
assert!(agent.get("layout_index").is_none());
|
|
3016
|
-
assert!(agent.get("pane_index").is_none());
|
|
3017
|
-
assert!(agent.get("display").is_none());
|
|
3018
|
-
// D5 (#264) / Python launch/core.py:253 — fresh launch persists spawn_cwd=workspace.
|
|
3019
|
-
assert_eq!(agent["spawn_cwd"], json!(workspace.to_string_lossy()));
|
|
3020
|
-
assert_eq!(agent["spawned_at"], json!(FIXED_SPAWNED_AT));
|
|
3021
|
-
assert_eq!(
|
|
3022
|
-
agent["pane_id"],
|
|
3023
|
-
json!("%0"),
|
|
3024
|
-
"#252 RC2: launch must persist the real pane_id returned by the transport, not drop it when pane_pid is unavailable"
|
|
3025
|
-
);
|
|
3026
|
-
let events = crate::event_log::EventLog::new(workspace)
|
|
3027
|
-
.tail(0)
|
|
3028
|
-
.expect("read event log");
|
|
3029
|
-
let spawn_event = events
|
|
3030
|
-
.iter()
|
|
3031
|
-
.find(|event| {
|
|
3032
|
-
event.get("event").and_then(serde_json::Value::as_str)
|
|
3033
|
-
== Some("provider.worker.spawn_argv")
|
|
3034
|
-
&& event.get("agent_id").and_then(serde_json::Value::as_str) == Some("implementer")
|
|
3035
|
-
})
|
|
3036
|
-
.unwrap_or_else(|| panic!("provider.worker.spawn_argv missing; events={events:?}"));
|
|
3037
|
-
assert_eq!(spawn_event["spawn_cwd"], json!(workspace.to_string_lossy()));
|
|
3038
|
-
assert_eq!(spawn_event["spawned_at"], json!(FIXED_SPAWNED_AT));
|
|
3039
|
-
assert_eq!(spawn_event["source"], json!("launch"));
|
|
3040
|
-
assert_eq!(spawn_event["spawn_epoch"], json!(0));
|
|
3041
|
-
let actual_keys = spawn_event
|
|
3042
|
-
.as_object()
|
|
3043
|
-
.expect("spawn event object")
|
|
3044
|
-
.keys()
|
|
3045
|
-
.map(String::as_str)
|
|
3046
|
-
.collect::<std::collections::BTreeSet<_>>();
|
|
3047
|
-
let expected_keys = [
|
|
3048
|
-
"agent_id",
|
|
3049
|
-
"argv",
|
|
3050
|
-
"env_overlay_keys",
|
|
3051
|
-
"env_unset",
|
|
3052
|
-
"event",
|
|
3053
|
-
"expected_session_id",
|
|
3054
|
-
"provider",
|
|
3055
|
-
"session_id_in_argv",
|
|
3056
|
-
"source",
|
|
3057
|
-
"spawn_cwd",
|
|
3058
|
-
"spawn_epoch",
|
|
3059
|
-
"spawned_at",
|
|
3060
|
-
"tmux_endpoint",
|
|
3061
|
-
"tmux_endpoint_source",
|
|
3062
|
-
"tmux_start_mode",
|
|
3063
|
-
"ts",
|
|
3064
|
-
]
|
|
3065
|
-
.into_iter()
|
|
3066
|
-
.collect::<std::collections::BTreeSet<_>>();
|
|
3067
|
-
assert_eq!(
|
|
3068
|
-
actual_keys, expected_keys,
|
|
3069
|
-
"spawn event schema must be canonical"
|
|
3070
|
-
);
|
|
3071
|
-
}
|
|
3072
|
-
|
|
3073
|
-
// Stage B2 — golden launch/core.py:171-173 writes paused workers as exactly
|
|
3074
|
-
// {status, provider} and skips spawn entirely.
|
|
3075
|
-
#[test]
|
|
3076
|
-
fn quick_start_paused_agent_state_is_paused_provider_only_and_not_spawned() {
|
|
3077
|
-
let team = quick_start_team_dir(QS_VALID_ROLE);
|
|
3078
|
-
let spec_path = compiled_spec_path_with_paused_agent(&team);
|
|
3079
|
-
let workspace = team
|
|
3080
|
-
.parent()
|
|
3081
|
-
.expect("team_workspace(<base>/teamdir) = <base>");
|
|
3082
|
-
crate::state::persist::save_runtime_state(
|
|
3083
|
-
workspace,
|
|
3084
|
-
&json!({
|
|
3085
|
-
"session_name": "team-quickteam",
|
|
3086
|
-
"team_dir": team.to_string_lossy(),
|
|
3087
|
-
"agents": {
|
|
3088
|
-
"implementer": {
|
|
3089
|
-
"provider": "fake",
|
|
3090
|
-
"role": "Implementation Engineer",
|
|
3091
|
-
"model": "fake",
|
|
3092
|
-
"auth_mode": "subscription"
|
|
3093
|
-
}
|
|
3094
|
-
},
|
|
3095
|
-
"tasks": []
|
|
3096
|
-
}),
|
|
3097
|
-
)
|
|
3098
|
-
.expect("seed pre-launch runtime state");
|
|
3099
|
-
let transport = OfflineTransport::new();
|
|
3100
|
-
let _ = launch_with_transport(&spec_path, false, true, true, &transport);
|
|
3101
|
-
let (raw, state) = raw_runtime_state(workspace);
|
|
3102
|
-
let agent = state
|
|
3103
|
-
.pointer("/agents/implementer")
|
|
3104
|
-
.unwrap_or_else(|| panic!("implementer agent state missing; raw={raw}"));
|
|
3105
|
-
let keys = agent
|
|
3106
|
-
.as_object()
|
|
3107
|
-
.expect("agent state object")
|
|
3108
|
-
.keys()
|
|
3109
|
-
.cloned()
|
|
3110
|
-
.collect::<Vec<_>>();
|
|
3111
|
-
assert_eq!(
|
|
3112
|
-
keys,
|
|
3113
|
-
vec!["status", "provider"],
|
|
3114
|
-
"paused agent state must be exactly golden launch/core.py:171-173; raw={raw}"
|
|
3115
|
-
);
|
|
3116
|
-
assert_eq!(agent["status"], json!("paused"));
|
|
3117
|
-
assert_eq!(agent["provider"], json!("fake"));
|
|
3118
|
-
assert!(
|
|
3119
|
-
transport.spawn_records().is_empty(),
|
|
3120
|
-
"paused agent must not spawn any terminal window; got {:?}",
|
|
3121
|
-
transport.spawn_records()
|
|
3122
|
-
);
|
|
3123
|
-
}
|
|
3124
|
-
|
|
3125
|
-
// ═════════════════════════════════════════════════════════════════════════════
|
|
3126
|
-
// 0.3.24 add-agent socket drift fix (macmini demo-director startup blocker).
|
|
3127
|
-
//
|
|
3128
|
-
// Root cause: `launch.rs::add_agent` / `fork_agent` hardcoded
|
|
3129
|
-
// `TmuxBackend::for_workspace(...)` (workspace-hash socket, e.g.
|
|
3130
|
-
// `/private/tmp/tmux-501/ta-<hash>/termclaud`) instead of consulting the
|
|
3131
|
-
// team's persisted `tmux_endpoint` (set at `team-agent launch` time, e.g.
|
|
3132
|
-
// `/private/tmp/tmux-501/default`). The orphan `claude` process then spawned
|
|
3133
|
-
// onto the wrong socket; the leader (running on the persisted socket) never
|
|
3134
|
-
// saw the window; state never registered; `add_agent` returned `ok=true`
|
|
3135
|
-
// (假绿) because the lifecycle layer didn't verify reachability post-spawn.
|
|
3136
|
-
//
|
|
3137
|
-
// Architect-approved fix has 4 调整:
|
|
3138
|
-
// 1. Reuse state-aware resolver (`lifecycle::restart::lifecycle_worker_tmux_backend_for_selected_state`).
|
|
3139
|
-
// 2. fork-agent same path.
|
|
3140
|
-
// 3. Endpoint annotate folded into start_agent state-save (no parallel
|
|
3141
|
-
// `annotate_runtime_tmux_endpoint` race with coordinator).
|
|
3142
|
-
// 4. Strict-non-capture reachability gate post-spawn (uses `has_pane` /
|
|
3143
|
-
// `liveness` / `list_targets` only — never `capture` to avoid E31 timing).
|
|
3144
|
-
// ═════════════════════════════════════════════════════════════════════════════
|
|
3145
|
-
|
|
3146
|
-
/// **RED**: `add_agent` must read the team's persisted `tmux_endpoint` (set at
|
|
3147
|
-
/// `team-agent launch` time and stored in the runtime state) and resolve the
|
|
3148
|
-
/// transport's socket to that endpoint — NOT the workspace-hash for_workspace
|
|
3149
|
-
/// socket. We exercise the resolver directly (the public surface
|
|
3150
|
-
/// `lifecycle::restart::lifecycle_worker_tmux_backend_for_selected_state`) so
|
|
3151
|
-
/// the contract is independent of CLI plumbing.
|
|
3152
|
-
#[test]
|
|
3153
|
-
fn add_agent_resolves_to_persisted_endpoint_socket_not_workspace_hash() {
|
|
3154
|
-
let team = temp_ws().join("addteam-persisted-endpoint");
|
|
3155
|
-
std::fs::create_dir_all(&team).unwrap();
|
|
3156
|
-
let live_endpoint = "/private/tmp/tmux-501/default".to_string();
|
|
3157
|
-
crate::state::persist::save_runtime_state(
|
|
3158
|
-
&team,
|
|
3159
|
-
&json!({
|
|
3160
|
-
"session_name": "team-persisted",
|
|
3161
|
-
"tmux_endpoint": live_endpoint.clone(),
|
|
3162
|
-
"tmux_socket": live_endpoint.clone(),
|
|
3163
|
-
"agents": {}
|
|
3164
|
-
}),
|
|
3165
|
-
)
|
|
3166
|
-
.unwrap();
|
|
3167
|
-
|
|
3168
|
-
let resolved =
|
|
3169
|
-
crate::lifecycle::restart::lifecycle_worker_tmux_backend_for_selected_state(&team, None)
|
|
3170
|
-
.expect("resolver must succeed when state is present");
|
|
3171
|
-
|
|
3172
|
-
let endpoint =
|
|
3173
|
-
<crate::tmux_backend::TmuxBackend as crate::transport::Transport>::tmux_endpoint(&resolved);
|
|
3174
|
-
assert_eq!(
|
|
3175
|
-
endpoint.as_deref(),
|
|
3176
|
-
Some(live_endpoint.as_str()),
|
|
3177
|
-
"0.3.24 add-agent socket drift fix: the state-aware resolver must \
|
|
3178
|
-
route to the PERSISTED tmux_endpoint ({live_endpoint}), not the \
|
|
3179
|
-
workspace-hash for_workspace socket. Got: {endpoint:?}. macmini \
|
|
3180
|
-
repro: add-agent demo-director spawned `claude` on the wrong socket \
|
|
3181
|
-
while the live team ran on the persisted default socket — orphan \
|
|
3182
|
-
process + ok=true假绿."
|
|
3183
|
-
);
|
|
3184
|
-
}
|
|
3185
|
-
|
|
3186
|
-
/// **Regression guard**: lifecycle worker resolution must ignore the leader
|
|
3187
|
-
/// receiver endpoint. The receiver may live on the caller's default socket
|
|
3188
|
-
/// while workers/coordinator remain on their persisted private socket.
|
|
3189
|
-
#[test]
|
|
3190
|
-
fn lifecycle_worker_resolver_prefers_persisted_worker_over_leader_receiver() {
|
|
3191
|
-
let team = temp_ws().join("addteam-split-leader-worker-endpoints");
|
|
3192
|
-
std::fs::create_dir_all(&team).unwrap();
|
|
3193
|
-
let worker_endpoint = "/private/tmp/tmux-501/ta-worker";
|
|
3194
|
-
let leader_endpoint = "/private/tmp/tmux-501/default";
|
|
3195
|
-
crate::state::persist::save_runtime_state(
|
|
3196
|
-
&team,
|
|
3197
|
-
&json!({
|
|
3198
|
-
"session_name": "team-split",
|
|
3199
|
-
"tmux_endpoint": worker_endpoint,
|
|
3200
|
-
"tmux_socket": worker_endpoint,
|
|
3201
|
-
"leader_receiver": {
|
|
3202
|
-
"pane_id": "%169",
|
|
3203
|
-
"tmux_socket": leader_endpoint,
|
|
3204
|
-
"status": "attached"
|
|
3205
|
-
},
|
|
3206
|
-
"agents": {}
|
|
3207
|
-
}),
|
|
3208
|
-
)
|
|
3209
|
-
.unwrap();
|
|
3210
|
-
|
|
3211
|
-
let resolved = crate::lifecycle::restart::lifecycle_worker_tmux_backend_for_selected_state(
|
|
3212
|
-
&team, None,
|
|
3213
|
-
)
|
|
3214
|
-
.expect("resolver must succeed when state has worker and receiver endpoints");
|
|
3215
|
-
let endpoint = <crate::tmux_backend::TmuxBackend as crate::transport::Transport>::tmux_endpoint(
|
|
3216
|
-
&resolved,
|
|
3217
|
-
);
|
|
3218
|
-
assert_eq!(
|
|
3219
|
-
endpoint.as_deref(),
|
|
3220
|
-
Some(worker_endpoint),
|
|
3221
|
-
"worker lifecycle operations must stay on persisted worker endpoint, not leader receiver"
|
|
3222
|
-
);
|
|
3223
|
-
}
|
|
3224
|
-
|
|
3225
|
-
/// **Regression guard**: annotating a worker spawn must not overwrite a
|
|
3226
|
-
/// persisted worker endpoint with the independent leader receiver endpoint.
|
|
3227
|
-
#[test]
|
|
3228
|
-
fn annotate_runtime_tmux_endpoint_does_not_follow_leader_receiver() {
|
|
3229
|
-
let worker_endpoint = "/private/tmp/tmux-501/ta-worker";
|
|
3230
|
-
let leader_endpoint = "/private/tmp/tmux-501/default";
|
|
3231
|
-
let mut state = json!({
|
|
3232
|
-
"tmux_endpoint": worker_endpoint,
|
|
3233
|
-
"tmux_socket": worker_endpoint,
|
|
3234
|
-
"leader_receiver": {"tmux_socket": leader_endpoint}
|
|
3235
|
-
});
|
|
3236
|
-
let transport = OfflineTransport::new().with_tmux_endpoint(worker_endpoint);
|
|
3237
|
-
crate::lifecycle::launch::annotate_runtime_tmux_endpoint(
|
|
3238
|
-
&mut state,
|
|
3239
|
-
&transport,
|
|
3240
|
-
std::path::Path::new("/tmp/annotate-split"),
|
|
3241
|
-
);
|
|
3242
|
-
assert_eq!(state["tmux_endpoint"], json!(worker_endpoint));
|
|
3243
|
-
assert_eq!(state["tmux_socket"], json!(worker_endpoint));
|
|
3244
|
-
}
|
|
3245
|
-
|
|
3246
|
-
/// **Regression guard**: cold workspace (no persisted endpoint) must safely
|
|
3247
|
-
/// fall back to `TmuxBackend::for_workspace(workspace)`. Encodes the
|
|
3248
|
-
/// first-agent / fresh-launch path so a future refactor doesn't accidentally
|
|
3249
|
-
/// panic/None there.
|
|
3250
|
-
#[test]
|
|
3251
|
-
fn add_agent_resolver_falls_back_to_workspace_socket_when_no_persisted_endpoint() {
|
|
3252
|
-
let team = temp_ws().join("addteam-cold-fallback");
|
|
3253
|
-
std::fs::create_dir_all(&team).unwrap();
|
|
3254
|
-
// NOTE: no save_runtime_state — cold workspace, no persisted endpoint.
|
|
3255
|
-
|
|
3256
|
-
let resolved =
|
|
3257
|
-
crate::lifecycle::restart::lifecycle_worker_tmux_backend_for_selected_state(&team, None)
|
|
3258
|
-
.expect("resolver must succeed (fall back to for_workspace) on cold workspace");
|
|
3259
|
-
|
|
3260
|
-
let endpoint =
|
|
3261
|
-
<crate::tmux_backend::TmuxBackend as crate::transport::Transport>::tmux_endpoint(&resolved);
|
|
3262
|
-
let fallback = <crate::tmux_backend::TmuxBackend as crate::transport::Transport>::tmux_endpoint(
|
|
3263
|
-
&crate::tmux_backend::TmuxBackend::for_workspace(&team),
|
|
3264
|
-
);
|
|
3265
|
-
assert_eq!(
|
|
3266
|
-
endpoint, fallback,
|
|
3267
|
-
"0.3.24 regression guard: when state has no persisted tmux_endpoint, \
|
|
3268
|
-
resolver must fall back to TmuxBackend::for_workspace (workspace-hash \
|
|
3269
|
-
socket). Got endpoint={endpoint:?} expected fallback={fallback:?}."
|
|
3270
|
-
);
|
|
3271
|
-
}
|
|
3272
|
-
|
|
3273
|
-
/// **RED**: `add_agent` must verify reachability AFTER spawn (strict,
|
|
3274
|
-
/// non-capture). A spawn that lands on the wrong tmux socket (or on the right
|
|
3275
|
-
/// socket but produces no addressable pane) must surface as a structured
|
|
3276
|
-
/// `Err`, NOT `ok=true`. Models the macmini假绿 root cause: the spawn
|
|
3277
|
-
/// recorded into the OfflineTransport but `has_pane` / `liveness` /
|
|
3278
|
-
/// `list_targets` all say "not addressable" (`spawned_panes_addressable=false`).
|
|
3279
|
-
#[test]
|
|
3280
|
-
fn add_agent_reachability_gate_returns_error_when_spawn_pane_not_addressable() {
|
|
3281
|
-
let team = temp_ws().join("addteam-reachability-gate");
|
|
3282
|
-
std::fs::create_dir_all(team.join("agents")).unwrap();
|
|
3283
|
-
std::fs::write(
|
|
3284
|
-
team.join("TEAM.md"),
|
|
3285
|
-
"---\nname: reachgate\nobjective: Reachability probe.\nprovider: codex\n---\n\nteam.\n",
|
|
3286
|
-
)
|
|
3287
|
-
.unwrap();
|
|
3288
|
-
std::fs::write(team.join("agents").join("implementer.md"), QS_VALID_ROLE).unwrap();
|
|
3289
|
-
let role_file = team.join("worker2-role.md");
|
|
3290
|
-
std::fs::write(&role_file, DELEG_ROLE_WORKER2).unwrap();
|
|
3291
|
-
seed_healthy_coordinator(&team);
|
|
3292
|
-
seed_canonical_team_identity(&team, "reachgate");
|
|
3293
|
-
|
|
3294
|
-
// Models "spawn to wrong socket" / "spawn succeeded but pane orphan": the
|
|
3295
|
-
// OfflineTransport records the spawn but reports the new pane is NOT
|
|
3296
|
-
// addressable (has_pane→Some(false), liveness defaults to Unknown=fall
|
|
3297
|
-
// through, list_targets doesn't include it).
|
|
3298
|
-
let transport = OfflineTransport::new()
|
|
3299
|
-
.with_spawned_panes_addressable(false)
|
|
3300
|
-
.with_default_liveness(crate::transport::PaneLiveness::Dead);
|
|
3301
|
-
|
|
3302
|
-
let result = crate::lifecycle::add_agent_with_transport(
|
|
3303
|
-
&team,
|
|
3304
|
-
&AgentId::new("worker2"),
|
|
3305
|
-
&role_file,
|
|
3306
|
-
false,
|
|
3307
|
-
None,
|
|
3308
|
-
&transport,
|
|
3309
|
-
);
|
|
3310
|
-
|
|
3311
|
-
// The spawn DID record (proving we reached the spawn step), but the gate
|
|
3312
|
-
// must NOT let the function return Ok — pane is not addressable so the
|
|
3313
|
-
// caller must see the structured failure and roll back / retry.
|
|
3314
|
-
assert!(
|
|
3315
|
-
!transport.spawn_records().is_empty(),
|
|
3316
|
-
"add-agent must still attempt the spawn (gate fires post-spawn); \
|
|
3317
|
-
got no spawn records — indicates a regression where the gate fires \
|
|
3318
|
-
too early."
|
|
3319
|
-
);
|
|
3320
|
-
assert!(
|
|
3321
|
-
result.is_err(),
|
|
3322
|
-
"0.3.24 reachability gate: add-agent must return Err when the spawned \
|
|
3323
|
-
pane is not addressable on the transport's socket (macmini假绿 root \
|
|
3324
|
-
cause). Got Ok(...) — gate did not fire."
|
|
3325
|
-
);
|
|
3326
|
-
let err_msg = result.unwrap_err().to_string();
|
|
3327
|
-
assert!(
|
|
3328
|
-
err_msg.contains("unreachable")
|
|
3329
|
-
|| err_msg.contains("not addressable")
|
|
3330
|
-
|| err_msg.contains("socket drift"),
|
|
3331
|
-
"0.3.24 reachability gate: error message must name the unreachable / \
|
|
3332
|
-
socket-drift symptom so operators can diagnose. Got: {err_msg}"
|
|
3333
|
-
);
|
|
3334
|
-
}
|
|
3335
|
-
|
|
3336
|
-
/// **Regression guard**: when the spawned pane IS addressable (default
|
|
3337
|
-
/// `OfflineTransport` state), reachability gate passes and add-agent returns
|
|
3338
|
-
/// Ok as before. Ensures the gate is precision, not blanket.
|
|
3339
|
-
#[test]
|
|
3340
|
-
fn add_agent_reachability_gate_passes_when_spawn_pane_addressable() {
|
|
3341
|
-
let team = temp_ws().join("addteam-gate-pass");
|
|
3342
|
-
std::fs::create_dir_all(team.join("agents")).unwrap();
|
|
3343
|
-
std::fs::write(
|
|
3344
|
-
team.join("TEAM.md"),
|
|
3345
|
-
"---\nname: gatepass\nobjective: Gate-pass probe.\nprovider: codex\n---\n\nteam.\n",
|
|
3346
|
-
)
|
|
3347
|
-
.unwrap();
|
|
3348
|
-
std::fs::write(team.join("agents").join("implementer.md"), QS_VALID_ROLE).unwrap();
|
|
3349
|
-
let role_file = team.join("worker2-role.md");
|
|
3350
|
-
std::fs::write(&role_file, DELEG_ROLE_WORKER2).unwrap();
|
|
3351
|
-
seed_healthy_coordinator(&team);
|
|
3352
|
-
seed_canonical_team_identity(&team, "gatepass");
|
|
3353
|
-
|
|
3354
|
-
// Default OfflineTransport: spawned_panes_addressable=true, liveness=Unknown
|
|
3355
|
-
// (treated as not-Dead by the gate's fallthrough).
|
|
3356
|
-
let transport = OfflineTransport::new();
|
|
3357
|
-
|
|
3358
|
-
let result = crate::lifecycle::add_agent_with_transport(
|
|
3359
|
-
&team,
|
|
3360
|
-
&AgentId::new("worker2"),
|
|
3361
|
-
&role_file,
|
|
3362
|
-
false,
|
|
3363
|
-
None,
|
|
3364
|
-
&transport,
|
|
3365
|
-
);
|
|
3366
|
-
|
|
3367
|
-
assert!(
|
|
3368
|
-
result.is_ok(),
|
|
3369
|
-
"0.3.24 reachability gate regression guard: when spawn pane is \
|
|
3370
|
-
addressable, add-agent must still return Ok. Got: {result:?}"
|
|
3371
|
-
);
|
|
3372
|
-
}
|
|
3373
|
-
|
|
3374
|
-
// ═════════════════════════════════════════════════════════════════════════════
|
|
3375
|
-
// E43 add-agent window layout drift (0.3.24 bug#3, demo-director startup blocker).
|
|
3376
|
-
//
|
|
3377
|
-
// Root cause (architect res_f27ff9b29957): with `legacy_display_key=adaptive` in
|
|
3378
|
-
// state AND stale `agents.<id>.layout_window="team-w2"` residue, the existing
|
|
3379
|
-
// `adaptive_placement_for_agent` validates a layout_window claim by checking
|
|
3380
|
-
// whether the existing agent's `pane_id` is in `live_panes` — but it does NOT
|
|
3381
|
-
// verify that the live pane's `window_name` actually equals the claimed
|
|
3382
|
-
// `layout_window`. So a live `%X` whose REAL window_name is "architect" still
|
|
3383
|
-
// "validates" the stale "team-w2" claim, the placement returns
|
|
3384
|
-
// `layout_window=team-w2, starts_window=false`, and `spawn_agent_window`
|
|
3385
|
-
// issues `tmux split-window -t :team-w2` which fails with
|
|
3386
|
-
// "can't find window: team-w2". macmini repro: demo-director add-agent blocks.
|
|
3387
|
-
//
|
|
3388
|
-
// Architect-approved minimal fix (3 调整, NO restructure of display/topology):
|
|
3389
|
-
// Fix A — `adaptive_placement_for_agent`: validate the live pane's
|
|
3390
|
-
// window_name MATCHES the agent's claimed layout_window. If pane_id is
|
|
3391
|
-
// live but lives under a different window_name, treat the agent's
|
|
3392
|
-
// layout_window claim as stale and skip it (don't count toward the
|
|
3393
|
-
// "windows with room" map).
|
|
3394
|
-
// Fix B — `adaptive_existing_placement_for_agent`: when the agent's
|
|
3395
|
-
// claimed layout_window is NOT present in live_windows, fall back to a
|
|
3396
|
-
// `starts_window=true` placement with `layout_window=agent_id` instead
|
|
3397
|
-
// of synthesising a fresh stale-named window.
|
|
3398
|
-
// Fix C — `spawn_agent_window`: pre-split guard. When `!starts_window` and
|
|
3399
|
-
// the target window is NOT in live_windows, downgrade to spawn_into
|
|
3400
|
-
// (a new window named `agent_id`) instead of splitting a phantom.
|
|
3401
|
-
// ═════════════════════════════════════════════════════════════════════════════
|
|
3402
|
-
|
|
3403
|
-
/// **RED — Fix A**: `adaptive_placement_for_agent` must skip an existing
|
|
3404
|
-
/// agent whose live pane resides under a window_name that differs from the
|
|
3405
|
-
/// agent's claimed `layout_window`. Real-machine state: agent "architect"
|
|
3406
|
-
/// carries `layout_window="team-w2"` (stale residue) but its live pane lives
|
|
3407
|
-
/// under `window_name="architect"`. The new placement for demo-director must
|
|
3408
|
-
/// NOT inherit the stale "team-w2" claim.
|
|
3409
|
-
#[test]
|
|
3410
|
-
fn e43_adaptive_placement_skips_existing_agent_whose_live_pane_window_name_differs_from_claim() {
|
|
3411
|
-
use crate::lifecycle::launch::{adaptive_placement_for_agent, LayoutPlacement};
|
|
3412
|
-
use crate::model::ids::AgentId;
|
|
3413
|
-
use crate::transport::{SessionName, WindowName};
|
|
3414
|
-
|
|
3415
|
-
let state = json!({
|
|
3416
|
-
"legacy_display_key": "adaptive",
|
|
3417
|
-
"session_name": "team-iso",
|
|
3418
|
-
"agents": {
|
|
3419
|
-
"architect": {
|
|
3420
|
-
"status": "running",
|
|
3421
|
-
"provider": "fake",
|
|
3422
|
-
"window": "architect",
|
|
3423
|
-
// Stale residue — placement must NOT inherit this name.
|
|
3424
|
-
"layout_window": "team-w2",
|
|
3425
|
-
"pane_id": "%1",
|
|
3426
|
-
}
|
|
3427
|
-
}
|
|
3428
|
-
});
|
|
3429
|
-
|
|
3430
|
-
let transport = OfflineTransport::new()
|
|
3431
|
-
.with_targets(vec![layout_pane("team-iso", "architect", "%1", 0)])
|
|
3432
|
-
.with_windows(vec![WindowName::new("architect")]);
|
|
3433
|
-
|
|
3434
|
-
let placement = adaptive_placement_for_agent(
|
|
3435
|
-
&state,
|
|
3436
|
-
&transport,
|
|
3437
|
-
&SessionName::new("team-iso"),
|
|
3438
|
-
&AgentId::new("demo-director"),
|
|
3439
|
-
);
|
|
3440
|
-
|
|
3441
|
-
// **E45 amendment (0.3.24 bug#4)**: when the live session has NO real
|
|
3442
|
-
// adaptive layout window (the topology is effectively per-agent — live
|
|
3443
|
-
// windows are `architect` not `team-wN`), placement returns None. The
|
|
3444
|
-
// caller (`start_agent_at_paths` → `spawn_agent_window`) then falls back
|
|
3445
|
-
// to opening a new window named after `agent_id`. This is the macmini
|
|
3446
|
-
// demo-director repro fix: per-agent topology must NOT be tricked into
|
|
3447
|
-
// adaptive mode by stale `layout_window=team-w2` residue.
|
|
3448
|
-
//
|
|
3449
|
-
// Pre-E45 expectation was Some(starts_window=true) with a fresh
|
|
3450
|
-
// team-w<next> name, but that forced an adaptive shape onto a session
|
|
3451
|
-
// that was already per-agent — which led to E45 bug#4 (split-window
|
|
3452
|
-
// into the developer worker after stale state pointed there).
|
|
3453
|
-
if let Some(p) = placement {
|
|
3454
|
-
// If we ever do return Some here, the STALE name must still not
|
|
3455
|
-
// survive — this branch shouldn't fire post-E45 but guards against
|
|
3456
|
-
// future regressions where placement re-enables adaptive on
|
|
3457
|
-
// per-agent live topology.
|
|
3458
|
-
assert_ne!(
|
|
3459
|
-
p.layout_window.as_str(),
|
|
3460
|
-
"team-w2",
|
|
3461
|
-
"E43 Fix A still applies: stale layout_window 'team-w2' must \
|
|
3462
|
-
NEVER survive. Got {p:?}"
|
|
3463
|
-
);
|
|
3464
|
-
let _: LayoutPlacement = p; // type witness
|
|
3465
|
-
}
|
|
3466
|
-
}
|
|
3467
|
-
|
|
3468
|
-
/// **RED — Fix C end-to-end**: `add_agent` end-to-end must NOT emit a
|
|
3469
|
-
/// spawn_split with the stale window name. With state carrying
|
|
3470
|
-
/// `legacy_display_key=adaptive` + stale `layout_window=team-w2` residue and
|
|
3471
|
-
/// live tmux windows named per-agent, the spawn must be a `spawn_into`
|
|
3472
|
-
/// (new window) — NOT `spawn_split` against the missing 'team-w2'.
|
|
3473
|
-
#[test]
|
|
3474
|
-
fn e43_add_agent_does_not_split_against_phantom_layout_window() {
|
|
3475
|
-
use crate::transport::WindowName;
|
|
3476
|
-
|
|
3477
|
-
let team = temp_ws().join("e43-add-agent-phantom-window");
|
|
3478
|
-
std::fs::create_dir_all(team.join("agents")).unwrap();
|
|
3479
|
-
std::fs::write(
|
|
3480
|
-
team.join("TEAM.md"),
|
|
3481
|
-
"---\nname: e43probe\nobjective: E43 probe.\nprovider: codex\n---\n\nteam.\n",
|
|
3482
|
-
)
|
|
3483
|
-
.unwrap();
|
|
3484
|
-
std::fs::write(team.join("agents").join("architect.md"), QS_VALID_ROLE).unwrap();
|
|
3485
|
-
let role_file = team.join("worker2-role.md");
|
|
3486
|
-
std::fs::write(&role_file, DELEG_ROLE_WORKER2).unwrap();
|
|
3487
|
-
// Real-machine repro: existing 'architect' carries stale layout_window=team-w2
|
|
3488
|
-
// residue; live tmux shows it under window_name='architect' (per-agent
|
|
3489
|
-
// layout). adaptive_layout flag is on.
|
|
3490
|
-
crate::state::persist::save_runtime_state(
|
|
3491
|
-
&team,
|
|
3492
|
-
&json!({
|
|
3493
|
-
"session_name": "team-iso",
|
|
3494
|
-
"legacy_display_key": "adaptive",
|
|
3495
|
-
"agents": {
|
|
3496
|
-
"architect": {
|
|
3497
|
-
"status": "running",
|
|
3498
|
-
"provider": "fake",
|
|
3499
|
-
"window": "architect",
|
|
3500
|
-
"layout_window": "team-w2",
|
|
3501
|
-
"pane_id": "%1",
|
|
3502
|
-
}
|
|
3503
|
-
}
|
|
3504
|
-
}),
|
|
3505
|
-
)
|
|
3506
|
-
.unwrap();
|
|
3507
|
-
seed_healthy_coordinator(&team);
|
|
3508
|
-
|
|
3509
|
-
let transport = OfflineTransport::new()
|
|
3510
|
-
.with_targets(vec![layout_pane("team-iso", "architect", "%1", 0)])
|
|
3511
|
-
.with_windows(vec![WindowName::new("architect")])
|
|
3512
|
-
.with_session_present(true);
|
|
3513
|
-
|
|
3514
|
-
let _result = crate::lifecycle::add_agent_with_transport(
|
|
3515
|
-
&team,
|
|
3516
|
-
&AgentId::new("worker2"),
|
|
3517
|
-
&role_file,
|
|
3518
|
-
false,
|
|
3519
|
-
None,
|
|
3520
|
-
&transport,
|
|
3521
|
-
);
|
|
3522
|
-
|
|
3523
|
-
let spawn_window_records = transport.spawn_window_records();
|
|
3524
|
-
// The macmini failure mode: split-window -t :team-w2. We must not split,
|
|
3525
|
-
// and we definitely must not target "team-w2".
|
|
3526
|
-
let stale_split = spawn_window_records
|
|
3527
|
-
.iter()
|
|
3528
|
-
.any(|(kind, window)| kind == "spawn_split" && window == "team-w2");
|
|
3529
|
-
assert!(
|
|
3530
|
-
!stale_split,
|
|
3531
|
-
"E43 Fix C end-to-end: add-agent must NOT issue spawn_split with \
|
|
3532
|
-
stale window name 'team-w2' (real-machine macmini error: \
|
|
3533
|
-
'tmux split-window -t :team-w2 → can't find window: team-w2'). \
|
|
3534
|
-
spawn_window_records={spawn_window_records:?}"
|
|
3535
|
-
);
|
|
3536
|
-
// The agent must actually be spawned somewhere (new window or split into
|
|
3537
|
-
// a valid live window). We at least expect one spawn recorded.
|
|
3538
|
-
assert!(
|
|
3539
|
-
!spawn_window_records.is_empty(),
|
|
3540
|
-
"E43 Fix C: add-agent must still attempt the spawn; got no records."
|
|
3541
|
-
);
|
|
3542
|
-
}
|
|
3543
|
-
|
|
3544
|
-
// ═════════════════════════════════════════════════════════════════════════════
|
|
3545
|
-
// E45 per-agent window drift (0.3.24 task#326 P0).
|
|
3546
|
-
//
|
|
3547
|
-
// Surfaced AFTER E43 (c5ed576) fixed the team-w2 phantom split. New repro:
|
|
3548
|
-
// state has legacy_display_key=adaptive + an existing `developer` worker whose
|
|
3549
|
-
// state row carries `layout_window=developer, layout_index=0, pane_id=%519`,
|
|
3550
|
-
// live tmux shows `developer` window with that pane. add-agent demo-director
|
|
3551
|
-
// resolves placement via `adaptive_placement_for_agent`, which finds the
|
|
3552
|
-
// `developer` window valid (pane_id live + window_name matches), groups
|
|
3553
|
-
// demo-director into it (count<3) → returns
|
|
3554
|
-
// `layout_window=developer, starts_window=false` → `spawn_agent_window`
|
|
3555
|
-
// issues `split-window -t :developer` which SUCCEEDS — splitting into the
|
|
3556
|
-
// developer worker's pane. macmini repro: add-agent demo-director hijacked
|
|
3557
|
-
// the developer worker's window @453 (2 panes), no new window.
|
|
3558
|
-
//
|
|
3559
|
-
// Root cause (architect): adaptive_placement_for_agent accepts ANY state
|
|
3560
|
-
// layout_window/window as adaptive (including per-agent names like
|
|
3561
|
-
// `developer`). E45 fix: only canonical `team-w<N>[-suffix]` windows count
|
|
3562
|
-
// as adaptive layout windows.
|
|
3563
|
-
// ═════════════════════════════════════════════════════════════════════════════
|
|
3564
|
-
|
|
3565
|
-
/// **RED — Fix #2**: `adaptive_placement_for_agent` must NOT count a
|
|
3566
|
-
/// per-agent window (e.g. `developer`) as adaptive layout space, even when
|
|
3567
|
-
/// it has matching live pane + window_name. With no real adaptive
|
|
3568
|
-
/// `team-w<N>` window in the live session, placement returns None so the
|
|
3569
|
-
/// caller opens a new per-agent window.
|
|
3570
|
-
#[test]
|
|
3571
|
-
fn e45_adaptive_placement_returns_none_when_no_real_team_w_window_present_in_state() {
|
|
3572
|
-
use crate::lifecycle::launch::adaptive_placement_for_agent;
|
|
3573
|
-
use crate::model::ids::AgentId;
|
|
3574
|
-
use crate::transport::{SessionName, WindowName};
|
|
3575
|
-
|
|
3576
|
-
// Real-machine state: adaptive on, developer's layout_window is
|
|
3577
|
-
// literally `developer` (per-agent name, NOT team-wN), pane_id %519
|
|
3578
|
-
// lives under the `developer` window.
|
|
3579
|
-
let state = json!({
|
|
3580
|
-
"legacy_display_key": "adaptive",
|
|
3581
|
-
"session_name": "team-iso",
|
|
3582
|
-
"agents": {
|
|
3583
|
-
"developer": {
|
|
3584
|
-
"status": "running",
|
|
3585
|
-
"provider": "fake",
|
|
3586
|
-
"window": "developer",
|
|
3587
|
-
"layout_window": "developer",
|
|
3588
|
-
"layout_index": 0u64,
|
|
3589
|
-
"pane_id": "%519",
|
|
3590
|
-
},
|
|
3591
|
-
"test-engineer": {
|
|
3592
|
-
"status": "running",
|
|
3593
|
-
"provider": "fake",
|
|
3594
|
-
"window": "test-engineer",
|
|
3595
|
-
"layout_window": "test-engineer",
|
|
3596
|
-
"pane_id": "%521",
|
|
3597
|
-
}
|
|
3598
|
-
}
|
|
3599
|
-
});
|
|
3600
|
-
|
|
3601
|
-
let transport = OfflineTransport::new()
|
|
3602
|
-
.with_targets(vec![
|
|
3603
|
-
layout_pane("team-iso", "developer", "%519", 0),
|
|
3604
|
-
layout_pane("team-iso", "test-engineer", "%521", 0),
|
|
3605
|
-
])
|
|
3606
|
-
.with_windows(vec![
|
|
3607
|
-
WindowName::new("developer"),
|
|
3608
|
-
WindowName::new("test-engineer"),
|
|
3609
|
-
]);
|
|
3610
|
-
|
|
3611
|
-
let placement = adaptive_placement_for_agent(
|
|
3612
|
-
&state,
|
|
3613
|
-
&transport,
|
|
3614
|
-
&SessionName::new("team-iso"),
|
|
3615
|
-
&AgentId::new("demo-director"),
|
|
3616
|
-
);
|
|
3617
|
-
|
|
3618
|
-
assert!(
|
|
3619
|
-
placement.is_none(),
|
|
3620
|
-
"E45 (0.3.24 bug#4): placement must return None when the live \
|
|
3621
|
-
session has NO real `team-w<N>` adaptive window. Per-agent windows \
|
|
3622
|
-
like `developer` are NOT adaptive layout windows — they are \
|
|
3623
|
-
per-agent topology, even if legacy_display_key=adaptive lingers in \
|
|
3624
|
-
state. With no real adaptive layout, the caller falls back to \
|
|
3625
|
-
opening a new per-agent window named after agent_id. Got \
|
|
3626
|
-
{placement:?} — must be None to prevent split-window -t :developer \
|
|
3627
|
-
hijacking the developer worker's pane (macmini repro)."
|
|
3628
|
-
);
|
|
3629
|
-
}
|
|
3630
|
-
|
|
3631
|
-
/// **RED — Fix #3**: `adaptive_existing_placement_for_agent` must return
|
|
3632
|
-
/// None when the agent's claimed layout_window is per-agent (not team-wN).
|
|
3633
|
-
/// The caller then falls back to non-placement spawn path which opens /
|
|
3634
|
-
/// reuses a window named after agent_id.
|
|
3635
|
-
#[test]
|
|
3636
|
-
fn e45_adaptive_existing_placement_returns_none_when_claim_is_per_agent_window() {
|
|
3637
|
-
use crate::lifecycle::launch::adaptive_existing_placement_for_agent;
|
|
3638
|
-
use crate::model::ids::AgentId;
|
|
3639
|
-
use crate::transport::{SessionName, WindowName};
|
|
3640
|
-
|
|
3641
|
-
let state = json!({
|
|
3642
|
-
"legacy_display_key": "adaptive",
|
|
3643
|
-
"session_name": "team-iso",
|
|
3644
|
-
"agents": {
|
|
3645
|
-
"developer": {
|
|
3646
|
-
"status": "running",
|
|
3647
|
-
"provider": "fake",
|
|
3648
|
-
"window": "developer",
|
|
3649
|
-
"layout_window": "developer",
|
|
3650
|
-
"layout_index": 0u64,
|
|
3651
|
-
"pane_id": "%519",
|
|
3652
|
-
}
|
|
3653
|
-
}
|
|
3654
|
-
});
|
|
3655
|
-
|
|
3656
|
-
let transport = OfflineTransport::new()
|
|
3657
|
-
.with_targets(vec![layout_pane("team-iso", "developer", "%519", 0)])
|
|
3658
|
-
.with_windows(vec![WindowName::new("developer")]);
|
|
3659
|
-
|
|
3660
|
-
let placement = adaptive_existing_placement_for_agent(
|
|
3661
|
-
&state,
|
|
3662
|
-
&transport,
|
|
3663
|
-
&SessionName::new("team-iso"),
|
|
3664
|
-
&AgentId::new("developer"),
|
|
3665
|
-
);
|
|
3666
|
-
|
|
3667
|
-
assert!(
|
|
3668
|
-
placement.is_none(),
|
|
3669
|
-
"E45 (0.3.24 bug#4): existing-placement must return None when \
|
|
3670
|
-
claimed layout_window is per-agent (e.g. `developer`). Only real \
|
|
3671
|
-
`team-w<N>[-suffix]` windows are honored as existing adaptive \
|
|
3672
|
-
placements. Got {placement:?}."
|
|
3673
|
-
);
|
|
3674
|
-
}
|
|
3675
|
-
|
|
3676
|
-
/// **RED — end-to-end Fix #2 + Fix #3 + defence**: add-agent against a
|
|
3677
|
-
/// per-agent live topology + adaptive backend in state must issue
|
|
3678
|
-
/// spawn_into (new window named after agent_id) and MUST NOT spawn_split
|
|
3679
|
-
/// into any existing per-agent window. macmini repro: split-window
|
|
3680
|
-
/// -t :developer would hijack the developer worker's pane.
|
|
3681
|
-
#[test]
|
|
3682
|
-
fn e45_add_agent_opens_new_window_does_not_split_into_per_agent_window() {
|
|
3683
|
-
use crate::transport::WindowName;
|
|
3684
|
-
|
|
3685
|
-
let team = temp_ws().join("e45-per-agent-no-split");
|
|
3686
|
-
std::fs::create_dir_all(team.join("agents")).unwrap();
|
|
3687
|
-
std::fs::write(
|
|
3688
|
-
team.join("TEAM.md"),
|
|
3689
|
-
"---\nname: e45probe\nobjective: E45 probe.\nprovider: codex\n---\n\nteam.\n",
|
|
3690
|
-
)
|
|
3691
|
-
.unwrap();
|
|
3692
|
-
std::fs::write(team.join("agents").join("developer.md"), QS_VALID_ROLE).unwrap();
|
|
3693
|
-
let role_file = team.join("worker2-role.md");
|
|
3694
|
-
std::fs::write(&role_file, DELEG_ROLE_WORKER2).unwrap();
|
|
3695
|
-
|
|
3696
|
-
// Real-machine state: legacy_display_key=adaptive, but the existing
|
|
3697
|
-
// `developer` worker carries per-agent layout_window=developer with
|
|
3698
|
-
// layout_index=0. macmini-equivalent state shape.
|
|
3699
|
-
crate::state::persist::save_runtime_state(
|
|
3700
|
-
&team,
|
|
3701
|
-
&json!({
|
|
3702
|
-
"session_name": "team-iso",
|
|
3703
|
-
"legacy_display_key": "adaptive",
|
|
3704
|
-
"agents": {
|
|
3705
|
-
"developer": {
|
|
3706
|
-
"status": "running",
|
|
3707
|
-
"provider": "fake",
|
|
3708
|
-
"window": "developer",
|
|
3709
|
-
"layout_window": "developer",
|
|
3710
|
-
"layout_index": 0u64,
|
|
3711
|
-
"pane_id": "%519",
|
|
3712
|
-
}
|
|
3713
|
-
}
|
|
3714
|
-
}),
|
|
3715
|
-
)
|
|
3716
|
-
.unwrap();
|
|
3717
|
-
seed_healthy_coordinator(&team);
|
|
3718
|
-
|
|
3719
|
-
let transport = OfflineTransport::new()
|
|
3720
|
-
.with_targets(vec![layout_pane("team-iso", "developer", "%519", 0)])
|
|
3721
|
-
.with_windows(vec![WindowName::new("developer")])
|
|
3722
|
-
.with_session_present(true);
|
|
3723
|
-
|
|
3724
|
-
let _result = crate::lifecycle::add_agent_with_transport(
|
|
3725
|
-
&team,
|
|
3726
|
-
&AgentId::new("worker2"),
|
|
3727
|
-
&role_file,
|
|
3728
|
-
false,
|
|
3729
|
-
None,
|
|
3730
|
-
&transport,
|
|
3731
|
-
);
|
|
3732
|
-
|
|
3733
|
-
let spawn_records = transport.spawn_window_records();
|
|
3734
|
-
// PRIMARY assertion: no spawn_split anywhere — adaptive placement
|
|
3735
|
-
// refused to group into the per-agent `developer` window.
|
|
3736
|
-
let any_split = spawn_records.iter().any(|(kind, _)| kind == "spawn_split");
|
|
3737
|
-
assert!(
|
|
3738
|
-
!any_split,
|
|
3739
|
-
"E45 end-to-end: add-agent against a per-agent live topology must \
|
|
3740
|
-
NOT issue spawn_split into any window (macmini repro: \
|
|
3741
|
-
split-window -t :developer would hijack the developer worker's \
|
|
3742
|
-
pane). Got spawn_records={spawn_records:?}"
|
|
3743
|
-
);
|
|
3744
|
-
// Defence: the spawn target name must not be `developer` (the existing
|
|
3745
|
-
// per-agent window) — if it were, the spawn would hijack.
|
|
3746
|
-
let spawned_into_developer = spawn_records
|
|
3747
|
-
.iter()
|
|
3748
|
-
.any(|(_, window)| window == "developer");
|
|
3749
|
-
assert!(
|
|
3750
|
-
!spawned_into_developer,
|
|
3751
|
-
"E45 end-to-end: spawn target must NOT be `developer` (the existing \
|
|
3752
|
-
worker's window). Got spawn_records={spawn_records:?}"
|
|
3753
|
-
);
|
|
3754
|
-
// The new worker must have been spawned somewhere (proves we reached
|
|
3755
|
-
// the spawn step and didn't refuse silently).
|
|
3756
|
-
assert!(
|
|
3757
|
-
!spawn_records.is_empty(),
|
|
3758
|
-
"E45 end-to-end: add-agent must still attempt the spawn; got no \
|
|
3759
|
-
records."
|
|
3760
|
-
);
|
|
3761
|
-
}
|
|
3762
|
-
|
|
3763
|
-
/// **Regression guard**: helper `is_adaptive_layout_window` golden cases.
|
|
3764
|
-
/// `team-w1`, `team-w42`, `team-w7-foo` are adaptive; agent_id names and
|
|
3765
|
-
/// other shapes are not.
|
|
3766
|
-
#[test]
|
|
3767
|
-
fn e45_is_adaptive_layout_window_recognises_team_w_pattern_only() {
|
|
3768
|
-
use crate::lifecycle::launch::is_adaptive_layout_window_pub as is_adapt;
|
|
3769
|
-
|
|
3770
|
-
assert!(is_adapt("team-w1"), "team-w1 must be adaptive");
|
|
3771
|
-
assert!(is_adapt("team-w2"), "team-w2 must be adaptive");
|
|
3772
|
-
assert!(is_adapt("team-w42"), "team-w42 must be adaptive");
|
|
3773
|
-
assert!(
|
|
3774
|
-
is_adapt("team-w7-suffix"),
|
|
3775
|
-
"team-w7-suffix must be adaptive"
|
|
3776
|
-
);
|
|
3777
|
-
|
|
3778
|
-
assert!(
|
|
3779
|
-
!is_adapt("developer"),
|
|
3780
|
-
"developer is per-agent, not adaptive"
|
|
3781
|
-
);
|
|
3782
|
-
assert!(
|
|
3783
|
-
!is_adapt("architect"),
|
|
3784
|
-
"architect is per-agent, not adaptive"
|
|
3785
|
-
);
|
|
3786
|
-
assert!(!is_adapt("demo-director"), "demo-director is per-agent");
|
|
3787
|
-
assert!(!is_adapt("leader"), "leader is not adaptive");
|
|
3788
|
-
assert!(!is_adapt(""), "empty is not adaptive");
|
|
3789
|
-
assert!(!is_adapt("team-w"), "team-w (no index) is not adaptive");
|
|
3790
|
-
assert!(
|
|
3791
|
-
!is_adapt("team-w0"),
|
|
3792
|
-
"team-w0 (index 0 invalid post-subtract) is not adaptive"
|
|
3793
|
-
);
|
|
3794
|
-
assert!(
|
|
3795
|
-
!is_adapt("team-wfoo"),
|
|
3796
|
-
"team-wfoo (non-numeric) is not adaptive"
|
|
3797
|
-
);
|
|
3798
|
-
}
|
|
3799
|
-
|
|
3800
|
-
// ═════════════════════════════════════════════════════════════════════════════
|
|
3801
|
-
// E42 (0.3.24 P0, double-spec deadlock) — add-agent / remove-agent must read
|
|
3802
|
-
// the SAME canonical spec, and add-agent's writes must be atomic (rollback on
|
|
3803
|
-
// any downstream failure).
|
|
3804
|
-
// ═════════════════════════════════════════════════════════════════════════════
|
|
3805
|
-
|
|
3806
|
-
/// **E42 RED (a) round-trip**: stale `state.spec_path` points at a legacy
|
|
3807
|
-
/// user-dir spec while the canonical runtime spec is authoritative.
|
|
3808
|
-
/// add-agent writes to canonical; remove-agent (from_spec=true, force=true)
|
|
3809
|
-
/// must succeed because the fix routes lifecycle_paths::spec_workspace to
|
|
3810
|
-
/// canonical, not the stale legacy path.
|
|
3811
|
-
#[test]
|
|
3812
|
-
fn e42_add_then_remove_round_trip_resolves_canonical_spec_not_legacy() {
|
|
3813
|
-
let team = temp_ws().join("e42-roundtrip");
|
|
3814
|
-
std::fs::create_dir_all(team.join("agents")).unwrap();
|
|
3815
|
-
std::fs::write(
|
|
3816
|
-
team.join("TEAM.md"),
|
|
3817
|
-
"---\nname: e42rt\nobjective: E42 round-trip probe.\nprovider: codex\n---\n\nteam.\n",
|
|
3818
|
-
)
|
|
3819
|
-
.unwrap();
|
|
3820
|
-
std::fs::write(team.join("agents").join("implementer.md"), QS_VALID_ROLE).unwrap();
|
|
3821
|
-
let role_file = team.join("newagent.md");
|
|
3822
|
-
std::fs::write(&role_file, DELEG_ROLE_WORKER2).unwrap();
|
|
3823
|
-
seed_healthy_coordinator(&team);
|
|
3824
|
-
// Pre-populate the state with a STALE spec_path pointing at a legacy
|
|
3825
|
-
// user-dir spec that does NOT carry the new agent we are about to add.
|
|
3826
|
-
// canonical runtime spec is what add-agent writes to.
|
|
3827
|
-
let team_ws = crate::model::paths::team_workspace(&team).unwrap();
|
|
3828
|
-
let legacy_spec_dir = team_ws.join(".team").join("e42rt");
|
|
3829
|
-
std::fs::create_dir_all(&legacy_spec_dir).unwrap();
|
|
3830
|
-
let legacy_spec_path = legacy_spec_dir.join("team.spec.yaml");
|
|
3831
|
-
std::fs::write(
|
|
3832
|
-
&legacy_spec_path,
|
|
3833
|
-
"name: e42rt\nagents: []\nrouting:\n rules: []\n",
|
|
3834
|
-
)
|
|
3835
|
-
.unwrap();
|
|
3836
|
-
crate::state::persist::save_runtime_state(
|
|
3837
|
-
&team,
|
|
3838
|
-
&json!({
|
|
3839
|
-
"session_name": "team-iso",
|
|
3840
|
-
"spec_path": legacy_spec_path.to_string_lossy(),
|
|
3841
|
-
"agents": {
|
|
3842
|
-
"implementer": {"status": "running", "provider": "fake", "window": "implementer"}
|
|
3843
|
-
}
|
|
3844
|
-
}),
|
|
3845
|
-
)
|
|
3846
|
-
.unwrap();
|
|
3847
|
-
let transport = OfflineTransport::new();
|
|
3848
|
-
|
|
3849
|
-
// (1) add-agent succeeds (writes canonical spec + state)
|
|
3850
|
-
let add_result = crate::lifecycle::add_agent_with_transport(
|
|
3851
|
-
&team,
|
|
3852
|
-
&AgentId::new("worker2"),
|
|
3853
|
-
&role_file,
|
|
3854
|
-
false,
|
|
3855
|
-
None,
|
|
3856
|
-
&transport,
|
|
3857
|
-
);
|
|
3858
|
-
assert!(
|
|
3859
|
-
add_result.is_ok(),
|
|
3860
|
-
"E42 (a) round-trip: add-agent must succeed even with stale state.spec_path; \
|
|
3861
|
-
got {add_result:?}"
|
|
3862
|
-
);
|
|
3863
|
-
// (2) remove-agent must find the agent (lifecycle_paths resolves canonical,
|
|
3864
|
-
// not the stale legacy spec)
|
|
3865
|
-
let remove_result = crate::lifecycle::remove_agent_with_transport(
|
|
3866
|
-
&team,
|
|
3867
|
-
&AgentId::new("worker2"),
|
|
3868
|
-
true,
|
|
3869
|
-
true,
|
|
3870
|
-
None,
|
|
3871
|
-
&transport,
|
|
3872
|
-
);
|
|
3873
|
-
assert!(
|
|
3874
|
-
remove_result.is_ok(),
|
|
3875
|
-
"E42 (a) round-trip: remove-agent must find the agent add-agent just wrote \
|
|
3876
|
-
(canonical-first lifecycle_paths). Pre-fix: stale state.spec_path wins → \
|
|
3877
|
-
remove sees legacy spec without the new agent → 'unknown'. Got {remove_result:?}"
|
|
3878
|
-
);
|
|
3879
|
-
}
|
|
3880
|
-
|
|
3881
|
-
/// **E42 RED (b) re-add symmetry**: after add(x), a second add(x) must say
|
|
3882
|
-
/// "already exists" AND remove(x) must recognise x — never give relative
|
|
3883
|
-
/// existence judgments. Same canonical truth source on both sides.
|
|
3884
|
-
#[test]
|
|
3885
|
-
fn e42_re_add_and_remove_agree_on_existence_after_add() {
|
|
3886
|
-
let team = temp_ws().join("e42-readdsym");
|
|
3887
|
-
std::fs::create_dir_all(team.join("agents")).unwrap();
|
|
3888
|
-
std::fs::write(
|
|
3889
|
-
team.join("TEAM.md"),
|
|
3890
|
-
"---\nname: e42sym\nobjective: E42 symmetry probe.\nprovider: codex\n---\n\nteam.\n",
|
|
3891
|
-
)
|
|
3892
|
-
.unwrap();
|
|
3893
|
-
std::fs::write(team.join("agents").join("implementer.md"), QS_VALID_ROLE).unwrap();
|
|
3894
|
-
let role_file = team.join("newagent.md");
|
|
3895
|
-
std::fs::write(&role_file, DELEG_ROLE_WORKER2).unwrap();
|
|
3896
|
-
seed_healthy_coordinator(&team);
|
|
3897
|
-
seed_canonical_team_identity(&team, "e42sym");
|
|
3898
|
-
let transport = OfflineTransport::new();
|
|
3899
|
-
// (1) first add
|
|
3900
|
-
let r1 = crate::lifecycle::add_agent_with_transport(
|
|
3901
|
-
&team,
|
|
3902
|
-
&AgentId::new("worker2"),
|
|
3903
|
-
&role_file,
|
|
3904
|
-
false,
|
|
3905
|
-
None,
|
|
3906
|
-
&transport,
|
|
3907
|
-
);
|
|
3908
|
-
assert!(r1.is_ok(), "first add must succeed; got {r1:?}");
|
|
3909
|
-
// (2) second add must report already-exists Err (not Ok)
|
|
3910
|
-
let r2 = crate::lifecycle::add_agent_with_transport(
|
|
3911
|
-
&team,
|
|
3912
|
-
&AgentId::new("worker2"),
|
|
3913
|
-
&role_file,
|
|
3914
|
-
false,
|
|
3915
|
-
None,
|
|
3916
|
-
&transport,
|
|
3917
|
-
);
|
|
3918
|
-
assert!(
|
|
3919
|
-
r2.is_err(),
|
|
3920
|
-
"E42 (b) symmetry: second add must Err 'already exists'; got {r2:?}"
|
|
3921
|
-
);
|
|
3922
|
-
// (3) remove must also see the agent (no relative judgments)
|
|
3923
|
-
let r3 = crate::lifecycle::remove_agent_with_transport(
|
|
3924
|
-
&team,
|
|
3925
|
-
&AgentId::new("worker2"),
|
|
3926
|
-
true,
|
|
3927
|
-
true,
|
|
3928
|
-
None,
|
|
3929
|
-
&transport,
|
|
3930
|
-
);
|
|
3931
|
-
assert!(
|
|
3932
|
-
r3.is_ok(),
|
|
3933
|
-
"E42 (b) symmetry: remove must see what add wrote — both reading canonical. \
|
|
3934
|
-
Got {r3:?}"
|
|
3935
|
-
);
|
|
3936
|
-
}
|
|
3937
|
-
|
|
3938
|
-
/// **E42 RED (d) projection consistency**: after add(x), canonical runtime
|
|
3939
|
-
/// spec AND runtime state agents map BOTH contain x; lifecycle_paths
|
|
3940
|
-
/// resolves spec_workspace to canonical (not legacy).
|
|
3941
|
-
#[test]
|
|
3942
|
-
fn e42_add_writes_to_canonical_runtime_spec_and_state_consistently() {
|
|
3943
|
-
let team = temp_ws().join("e42-projection");
|
|
3944
|
-
std::fs::create_dir_all(team.join("agents")).unwrap();
|
|
3945
|
-
std::fs::write(
|
|
3946
|
-
team.join("TEAM.md"),
|
|
3947
|
-
"---\nname: e42proj\nobjective: E42 projection probe.\nprovider: codex\n---\n\nteam.\n",
|
|
3948
|
-
)
|
|
3949
|
-
.unwrap();
|
|
3950
|
-
std::fs::write(team.join("agents").join("implementer.md"), QS_VALID_ROLE).unwrap();
|
|
3951
|
-
let role_file = team.join("newagent.md");
|
|
3952
|
-
std::fs::write(&role_file, DELEG_ROLE_WORKER2).unwrap();
|
|
3953
|
-
seed_healthy_coordinator(&team);
|
|
3954
|
-
seed_canonical_team_identity(&team, "e42proj");
|
|
3955
|
-
let transport = OfflineTransport::new();
|
|
3956
|
-
let _ = crate::lifecycle::add_agent_with_transport(
|
|
3957
|
-
&team,
|
|
3958
|
-
&AgentId::new("worker2"),
|
|
3959
|
-
&role_file,
|
|
3960
|
-
false,
|
|
3961
|
-
None,
|
|
3962
|
-
&transport,
|
|
3963
|
-
)
|
|
3964
|
-
.expect("add must succeed");
|
|
3965
|
-
|
|
3966
|
-
// (a) runtime state has worker2 — read same way add_agent does (team_workspace
|
|
3967
|
-
// resolves the run_workspace, and select_runtime_state reads canonical-scoped).
|
|
3968
|
-
let state = crate::state::persist::load_runtime_state(&team).unwrap();
|
|
3969
|
-
assert!(
|
|
3970
|
-
state.pointer("/agents/worker2").is_some(),
|
|
3971
|
-
"E42 (d): runtime state must contain worker2 after add; state={state}"
|
|
3972
|
-
);
|
|
3973
|
-
|
|
3974
|
-
// (b) canonical runtime spec has worker2
|
|
3975
|
-
let runtime_spec = find_runtime_spec(&team, "e42proj");
|
|
3976
|
-
let canonical_spec_path = runtime_spec.expect("canonical runtime spec must exist");
|
|
3977
|
-
let canonical_spec_text = std::fs::read_to_string(&canonical_spec_path).unwrap();
|
|
3978
|
-
assert!(
|
|
3979
|
-
canonical_spec_text.contains("worker2"),
|
|
3980
|
-
"E42 (d): canonical runtime spec must contain worker2; \
|
|
3981
|
-
canonical_spec={canonical_spec_text}"
|
|
3982
|
-
);
|
|
3983
|
-
}
|