@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.
Files changed (436) hide show
  1. package/README.md +4 -4
  2. package/README.zh.md +1 -1
  3. package/package.json +4 -8
  4. package/skills/team-agent/SKILL.md +37 -20
  5. package/skills/team-agent/command-coverage.json +169 -183
  6. package/skills/team-agent/docs/reference/team-agent-operator.md +64 -30
  7. package/skills/team-agent/references/recovery-runbook.md +1 -1
  8. package/skills/team-agent/references/team-agent-operator.md +64 -30
  9. package/templates/team_state.md +1 -1
  10. package/Cargo.lock +0 -1063
  11. package/Cargo.toml +0 -36
  12. package/crates/team-agent/Cargo.toml +0 -69
  13. package/crates/team-agent/src/app_server_test_support.rs +0 -258
  14. package/crates/team-agent/src/cli/adapters.rs +0 -1288
  15. package/crates/team-agent/src/cli/arguments.rs +0 -405
  16. package/crates/team-agent/src/cli/attach_app_server_leader.rs +0 -98
  17. package/crates/team-agent/src/cli/diagnose.rs +0 -1721
  18. package/crates/team-agent/src/cli/emit.rs +0 -2930
  19. package/crates/team-agent/src/cli/grok_slot.rs +0 -384
  20. package/crates/team-agent/src/cli/helpers.rs +0 -91
  21. package/crates/team-agent/src/cli/intent/runtime.rs +0 -1216
  22. package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -912
  23. package/crates/team-agent/src/cli/intent/tests.rs +0 -689
  24. package/crates/team-agent/src/cli/intent.rs +0 -664
  25. package/crates/team-agent/src/cli/leader.rs +0 -300
  26. package/crates/team-agent/src/cli/leader_prompt.rs +0 -261
  27. package/crates/team-agent/src/cli/leaders.rs +0 -418
  28. package/crates/team-agent/src/cli/mod.rs +0 -6545
  29. package/crates/team-agent/src/cli/models.rs +0 -1206
  30. package/crates/team-agent/src/cli/named_address.rs +0 -1651
  31. package/crates/team-agent/src/cli/profile.rs +0 -342
  32. package/crates/team-agent/src/cli/route.rs +0 -212
  33. package/crates/team-agent/src/cli/schedule.rs +0 -175
  34. package/crates/team-agent/src/cli/send/coordinator.rs +0 -164
  35. package/crates/team-agent/src/cli/send/mailbox.rs +0 -145
  36. package/crates/team-agent/src/cli/send/persist.rs +0 -156
  37. package/crates/team-agent/src/cli/send/presentation.rs +0 -370
  38. package/crates/team-agent/src/cli/send/resolve.rs +0 -573
  39. package/crates/team-agent/src/cli/send.rs +0 -199
  40. package/crates/team-agent/src/cli/shutdown_socket.rs +0 -288
  41. package/crates/team-agent/src/cli/spec.rs +0 -165
  42. package/crates/team-agent/src/cli/status.rs +0 -280
  43. package/crates/team-agent/src/cli/status_port/agents.rs +0 -358
  44. package/crates/team-agent/src/cli/status_port/approvals.rs +0 -79
  45. package/crates/team-agent/src/cli/status_port/brief.rs +0 -1981
  46. package/crates/team-agent/src/cli/status_port/compact.rs +0 -240
  47. package/crates/team-agent/src/cli/status_port/format.rs +0 -146
  48. package/crates/team-agent/src/cli/status_port/inbox.rs +0 -62
  49. package/crates/team-agent/src/cli/status_port/runtime.rs +0 -197
  50. package/crates/team-agent/src/cli/status_port/snapshot.rs +0 -208
  51. package/crates/team-agent/src/cli/status_port/store.rs +0 -416
  52. package/crates/team-agent/src/cli/status_port/tests.rs +0 -90
  53. package/crates/team-agent/src/cli/status_port.rs +0 -92
  54. package/crates/team-agent/src/cli/tests/base.rs +0 -885
  55. package/crates/team-agent/src/cli/tests/divergence.rs +0 -518
  56. package/crates/team-agent/src/cli/tests/lane_c.rs +0 -453
  57. package/crates/team-agent/src/cli/tests/leader_watch.rs +0 -322
  58. package/crates/team-agent/src/cli/tests/main_preserved.rs +0 -430
  59. package/crates/team-agent/src/cli/tests/missing_subcommands.rs +0 -336
  60. package/crates/team-agent/src/cli/tests/mod.rs +0 -137
  61. package/crates/team-agent/src/cli/tests/named_address.rs +0 -761
  62. package/crates/team-agent/src/cli/tests/parser_safety.rs +0 -383
  63. package/crates/team-agent/src/cli/tests/run_delegation.rs +0 -484
  64. package/crates/team-agent/src/cli/tests/shutdown_kill_plan.rs +0 -2179
  65. package/crates/team-agent/src/cli/tests/status_brief.rs +0 -1514
  66. package/crates/team-agent/src/cli/tests/status_send.rs +0 -888
  67. package/crates/team-agent/src/cli/tests/verb_install_skill.rs +0 -93
  68. package/crates/team-agent/src/cli/tests/verb_profile.rs +0 -392
  69. package/crates/team-agent/src/cli/triage.rs +0 -234
  70. package/crates/team-agent/src/cli/types.rs +0 -591
  71. package/crates/team-agent/src/codex_app_server.rs +0 -546
  72. package/crates/team-agent/src/communication_mode/mod.rs +0 -56
  73. package/crates/team-agent/src/compiler/tests.rs +0 -827
  74. package/crates/team-agent/src/compiler.rs +0 -890
  75. package/crates/team-agent/src/conpty/backend.rs +0 -829
  76. package/crates/team-agent/src/conpty/mod.rs +0 -33
  77. package/crates/team-agent/src/contract_runtime/backend.rs +0 -1744
  78. package/crates/team-agent/src/contract_runtime/commands.rs +0 -671
  79. package/crates/team-agent/src/contract_runtime/config.rs +0 -364
  80. package/crates/team-agent/src/contract_runtime/config_tests.rs +0 -76
  81. package/crates/team-agent/src/contract_runtime/discovery.rs +0 -449
  82. package/crates/team-agent/src/contract_runtime/fork.rs +0 -361
  83. package/crates/team-agent/src/contract_runtime/forward.rs +0 -288
  84. package/crates/team-agent/src/contract_runtime/framework.rs +0 -367
  85. package/crates/team-agent/src/contract_runtime/mcp.rs +0 -394
  86. package/crates/team-agent/src/contract_runtime/mod.rs +0 -17
  87. package/crates/team-agent/src/contract_runtime/prompt.rs +0 -216
  88. package/crates/team-agent/src/contract_runtime/pump.rs +0 -271
  89. package/crates/team-agent/src/contract_runtime/registry.rs +0 -553
  90. package/crates/team-agent/src/contract_runtime/workspace.rs +0 -228
  91. package/crates/team-agent/src/coordinator/backoff.rs +0 -741
  92. package/crates/team-agent/src/coordinator/conpty_shim.rs +0 -805
  93. package/crates/team-agent/src/coordinator/health.rs +0 -1185
  94. package/crates/team-agent/src/coordinator/mod.rs +0 -119
  95. package/crates/team-agent/src/coordinator/orphan.rs +0 -110
  96. package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -798
  97. package/crates/team-agent/src/coordinator/runtime_observation.rs +0 -84
  98. package/crates/team-agent/src/coordinator/steps/abnormal.rs +0 -2309
  99. package/crates/team-agent/src/coordinator/steps/delivery.rs +0 -15
  100. package/crates/team-agent/src/coordinator/steps/health_sync.rs +0 -15
  101. package/crates/team-agent/src/coordinator/steps/mod.rs +0 -126
  102. package/crates/team-agent/src/coordinator/steps/persist.rs +0 -15
  103. package/crates/team-agent/src/coordinator/steps/runtime_prompts.rs +0 -15
  104. package/crates/team-agent/src/coordinator/steps/session_gate.rs +0 -16
  105. package/crates/team-agent/src/coordinator/tests/a0_lostupdate.rs +0 -158
  106. package/crates/team-agent/src/coordinator/tests/abnormal.rs +0 -312
  107. package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +0 -300
  108. package/crates/team-agent/src/coordinator/tests/basics.rs +0 -211
  109. package/crates/team-agent/src/coordinator/tests/daemon.rs +0 -514
  110. package/crates/team-agent/src/coordinator/tests/energy.rs +0 -549
  111. package/crates/team-agent/src/coordinator/tests/health_sync.rs +0 -503
  112. package/crates/team-agent/src/coordinator/tests/main_preserved.rs +0 -186
  113. package/crates/team-agent/src/coordinator/tests/mod.rs +0 -295
  114. package/crates/team-agent/src/coordinator/tests/s3_bounded.rs +0 -207
  115. package/crates/team-agent/src/coordinator/tests/spine.rs +0 -308
  116. package/crates/team-agent/src/coordinator/tests/takeover.rs +0 -286
  117. package/crates/team-agent/src/coordinator/tests/tick_core.rs +0 -237
  118. package/crates/team-agent/src/coordinator/tick.rs +0 -3024
  119. package/crates/team-agent/src/coordinator/types.rs +0 -540
  120. package/crates/team-agent/src/db/agent_health_capture.rs +0 -126
  121. package/crates/team-agent/src/db/message_store.rs +0 -1527
  122. package/crates/team-agent/src/db/migration.rs +0 -984
  123. package/crates/team-agent/src/db/mod.rs +0 -26
  124. package/crates/team-agent/src/db/schema.rs +0 -663
  125. package/crates/team-agent/src/diagnose/comms.rs +0 -242
  126. package/crates/team-agent/src/diagnose/mod.rs +0 -44
  127. package/crates/team-agent/src/diagnose/orphans.rs +0 -889
  128. package/crates/team-agent/src/direct_delivery.rs +0 -368
  129. package/crates/team-agent/src/event_log.rs +0 -502
  130. package/crates/team-agent/src/fake_worker.rs +0 -303
  131. package/crates/team-agent/src/inbox_store.rs +0 -169
  132. package/crates/team-agent/src/kill_audit.rs +0 -106
  133. package/crates/team-agent/src/layout/manager.rs +0 -248
  134. package/crates/team-agent/src/layout/mod.rs +0 -36
  135. package/crates/team-agent/src/layout/overlay.rs +0 -134
  136. package/crates/team-agent/src/layout/placement.rs +0 -52
  137. package/crates/team-agent/src/layout/recovery.rs +0 -106
  138. package/crates/team-agent/src/layout/runtime_sessions.rs +0 -317
  139. package/crates/team-agent/src/layout/sessions.rs +0 -294
  140. package/crates/team-agent/src/layout/tmux_endpoint.rs +0 -165
  141. package/crates/team-agent/src/layout/worker_env.rs +0 -721
  142. package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -37
  143. package/crates/team-agent/src/leader/helpers.rs +0 -178
  144. package/crates/team-agent/src/leader/incident.rs +0 -6
  145. package/crates/team-agent/src/leader/lease.rs +0 -3356
  146. package/crates/team-agent/src/leader/mod.rs +0 -104
  147. package/crates/team-agent/src/leader/owner_bind.rs +0 -400
  148. package/crates/team-agent/src/leader/prompt.rs +0 -905
  149. package/crates/team-agent/src/leader/provider_attribution.rs +0 -247
  150. package/crates/team-agent/src/leader/rediscover/tests.rs +0 -689
  151. package/crates/team-agent/src/leader/rediscover.rs +0 -1192
  152. package/crates/team-agent/src/leader/registry.rs +0 -888
  153. package/crates/team-agent/src/leader/start.rs +0 -4501
  154. package/crates/team-agent/src/leader/takeover.rs +0 -65
  155. package/crates/team-agent/src/leader/tests/basics.rs +0 -337
  156. package/crates/team-agent/src/leader/tests/byte_findings.rs +0 -355
  157. package/crates/team-agent/src/leader/tests/claim_leader_mailbox_flush_contract.rs +0 -544
  158. package/crates/team-agent/src/leader/tests/historical_inventory_upgrade_gate_red.rs +0 -624
  159. package/crates/team-agent/src/leader/tests/identity.rs +0 -465
  160. package/crates/team-agent/src/leader/tests/identity_session_names.rs +0 -42
  161. package/crates/team-agent/src/leader/tests/idle.rs +0 -113
  162. package/crates/team-agent/src/leader/tests/lease_api.rs +0 -520
  163. package/crates/team-agent/src/leader/tests/lease_claim.rs +0 -629
  164. package/crates/team-agent/src/leader/tests/mod.rs +0 -106
  165. package/crates/team-agent/src/leader/tests/prompt_contract.rs +0 -268
  166. package/crates/team-agent/src/leader/tests/rediscover.rs +0 -403
  167. package/crates/team-agent/src/leader/tests/rehomed_env.rs +0 -83
  168. package/crates/team-agent/src/leader/tests/team_in_team_state_scope_red.rs +0 -1273
  169. package/crates/team-agent/src/leader/tests/terminal_and_replay_vs_rerender_invariants_red.rs +0 -417
  170. package/crates/team-agent/src/leader/tests/wake_start_owner.rs +0 -168
  171. package/crates/team-agent/src/leader/types.rs +0 -534
  172. package/crates/team-agent/src/lib.rs +0 -147
  173. package/crates/team-agent/src/lifecycle/helpers.rs +0 -212
  174. package/crates/team-agent/src/lifecycle/launch/add_agent.rs +0 -881
  175. package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +0 -598
  176. package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -332
  177. package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +0 -204
  178. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -107
  179. package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +0 -144
  180. package/crates/team-agent/src/lifecycle/launch/identity.rs +0 -674
  181. package/crates/team-agent/src/lifecycle/launch/layout.rs +0 -350
  182. package/crates/team-agent/src/lifecycle/launch/leader_context.rs +0 -589
  183. package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +0 -160
  184. package/crates/team-agent/src/lifecycle/launch/ownership.rs +0 -105
  185. package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +0 -899
  186. package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +0 -225
  187. package/crates/team-agent/src/lifecycle/launch/plan.rs +0 -269
  188. package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -5200
  189. package/crates/team-agent/src/lifecycle/launch/quick_start_transport.rs +0 -368
  190. package/crates/team-agent/src/lifecycle/launch/readiness.rs +0 -519
  191. package/crates/team-agent/src/lifecycle/launch/role_source.rs +0 -287
  192. package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -473
  193. package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -801
  194. package/crates/team-agent/src/lifecycle/launch/state_projection.rs +0 -624
  195. package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -558
  196. package/crates/team-agent/src/lifecycle/launch.rs +0 -557
  197. package/crates/team-agent/src/lifecycle/lock.rs +0 -350
  198. package/crates/team-agent/src/lifecycle/mod.rs +0 -79
  199. package/crates/team-agent/src/lifecycle/pane_input_lock.rs +0 -239
  200. package/crates/team-agent/src/lifecycle/profile_launch.rs +0 -1067
  201. package/crates/team-agent/src/lifecycle/profile_smoke.rs +0 -557
  202. package/crates/team-agent/src/lifecycle/restart/agent.rs +0 -2199
  203. package/crates/team-agent/src/lifecycle/restart/avatar.rs +0 -1798
  204. package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +0 -163
  205. package/crates/team-agent/src/lifecycle/restart/common.rs +0 -2362
  206. package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +0 -65
  207. package/crates/team-agent/src/lifecycle/restart/preflight.rs +0 -113
  208. package/crates/team-agent/src/lifecycle/restart/rebuild.rs +0 -5135
  209. package/crates/team-agent/src/lifecycle/restart/remove.rs +0 -1504
  210. package/crates/team-agent/src/lifecycle/restart/selection.rs +0 -559
  211. package/crates/team-agent/src/lifecycle/restart/team_state.rs +0 -329
  212. package/crates/team-agent/src/lifecycle/restart.rs +0 -227
  213. package/crates/team-agent/src/lifecycle/role_config.rs +0 -1230
  214. package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +0 -1021
  215. package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +0 -1205
  216. package/crates/team-agent/src/lifecycle/tests/b0_legacy_snapshot_nonauthority_contract.rs +0 -265
  217. package/crates/team-agent/src/lifecycle/tests/b0_reader_hideone_audit_contract.rs +0 -490
  218. package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +0 -656
  219. package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +0 -325
  220. package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +0 -447
  221. package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +0 -1638
  222. package/crates/team-agent/src/lifecycle/tests/clone_agent_preserves_source_tools.rs +0 -427
  223. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +0 -770
  224. package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +0 -419
  225. package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +0 -2035
  226. package/crates/team-agent/src/lifecycle/tests/core.rs +0 -1327
  227. package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +0 -315
  228. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_g0.stdout.txt +0 -222
  229. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_spaced_ids.stdout.txt +0 -9
  230. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +0 -72
  231. package/crates/team-agent/src/lifecycle/tests/gate_fixtures.rs +0 -562
  232. package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +0 -110
  233. package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +0 -512
  234. package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +0 -921
  235. package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +0 -68
  236. package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +0 -1851
  237. package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +0 -3983
  238. package/crates/team-agent/src/lifecycle/tests/lifecycle_lock.rs +0 -339
  239. package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +0 -596
  240. package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +0 -513
  241. package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +0 -69
  242. package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +0 -824
  243. package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +0 -723
  244. package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +0 -164
  245. package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +0 -200
  246. package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +0 -210
  247. package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +0 -527
  248. package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +0 -1062
  249. package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +0 -1419
  250. package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +0 -98
  251. package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +0 -550
  252. package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +0 -226
  253. package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +0 -332
  254. package/crates/team-agent/src/lifecycle/tests/realmachine_clusters_1_6_red.rs +0 -786
  255. package/crates/team-agent/src/lifecycle/tests/realmachine_residual_g1_g4_red.rs +0 -648
  256. package/crates/team-agent/src/lifecycle/tests/restart.rs +0 -185
  257. package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +0 -1053
  258. package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +0 -679
  259. package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1126
  260. package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +0 -153
  261. package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +0 -427
  262. package/crates/team-agent/src/lifecycle/tests/stale_team_saveconflict_contract.rs +0 -431
  263. package/crates/team-agent/src/lifecycle/tests/startup_latency_contract.rs +0 -1066
  264. package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +0 -876
  265. package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +0 -1026
  266. package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +0 -342
  267. package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +0 -543
  268. package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +0 -1103
  269. package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +0 -1276
  270. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_roster_red.rs +0 -145
  271. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +0 -603
  272. package/crates/team-agent/src/lifecycle/tests/test_isolation_escape_contract.rs +0 -936
  273. package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +0 -970
  274. package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +0 -995
  275. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -836
  276. package/crates/team-agent/src/lifecycle/tests.rs +0 -105
  277. package/crates/team-agent/src/lifecycle/types.rs +0 -877
  278. package/crates/team-agent/src/lifecycle/worker_command_context.rs +0 -363
  279. package/crates/team-agent/src/main.rs +0 -52
  280. package/crates/team-agent/src/mcp_server/helpers.rs +0 -510
  281. package/crates/team-agent/src/mcp_server/lifecycle_tools/mod.rs +0 -6
  282. package/crates/team-agent/src/mcp_server/lifecycle_tools/state_status.rs +0 -43
  283. package/crates/team-agent/src/mcp_server/mod.rs +0 -119
  284. package/crates/team-agent/src/mcp_server/normalize.rs +0 -485
  285. package/crates/team-agent/src/mcp_server/readiness.rs +0 -527
  286. package/crates/team-agent/src/mcp_server/readiness_tests.rs +0 -348
  287. package/crates/team-agent/src/mcp_server/tests/golden.rs +0 -285
  288. package/crates/team-agent/src/mcp_server/tests/normalize.rs +0 -247
  289. package/crates/team-agent/src/mcp_server/tests/scoped.rs +0 -158
  290. package/crates/team-agent/src/mcp_server/tests/send.rs +0 -353
  291. package/crates/team-agent/src/mcp_server/tests/tools.rs +0 -341
  292. package/crates/team-agent/src/mcp_server/tests/wire.rs +0 -254
  293. package/crates/team-agent/src/mcp_server/tests.rs +0 -43
  294. package/crates/team-agent/src/mcp_server/tools.rs +0 -889
  295. package/crates/team-agent/src/mcp_server/types.rs +0 -396
  296. package/crates/team-agent/src/mcp_server/wire.rs +0 -867
  297. package/crates/team-agent/src/messaging/activity.rs +0 -461
  298. package/crates/team-agent/src/messaging/address.rs +0 -87
  299. package/crates/team-agent/src/messaging/delivery.rs +0 -3727
  300. package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +0 -234
  301. package/crates/team-agent/src/messaging/enter_rescue.rs +0 -362
  302. package/crates/team-agent/src/messaging/enter_rescue_tests.rs +0 -633
  303. package/crates/team-agent/src/messaging/helpers.rs +0 -336
  304. package/crates/team-agent/src/messaging/leader_channel.rs +0 -287
  305. package/crates/team-agent/src/messaging/leader_receiver.rs +0 -786
  306. package/crates/team-agent/src/messaging/mod.rs +0 -167
  307. package/crates/team-agent/src/messaging/persist.rs +0 -377
  308. package/crates/team-agent/src/messaging/presentation.rs +0 -417
  309. package/crates/team-agent/src/messaging/reminders.rs +0 -316
  310. package/crates/team-agent/src/messaging/results/collection_tests.rs +0 -719
  311. package/crates/team-agent/src/messaging/results.rs +0 -1415
  312. package/crates/team-agent/src/messaging/scheduler.rs +0 -223
  313. package/crates/team-agent/src/messaging/selftest.rs +0 -315
  314. package/crates/team-agent/src/messaging/send.rs +0 -981
  315. package/crates/team-agent/src/messaging/tests/basic.rs +0 -346
  316. package/crates/team-agent/src/messaging/tests/dup_inject.rs +0 -657
  317. package/crates/team-agent/src/messaging/tests/e23.rs +0 -49
  318. package/crates/team-agent/src/messaging/tests/leader_channel.rs +0 -169
  319. package/crates/team-agent/src/messaging/tests/leader_inject_acceptance.rs +0 -817
  320. package/crates/team-agent/src/messaging/tests/main_preserved.rs +0 -85
  321. package/crates/team-agent/src/messaging/tests/mod.rs +0 -306
  322. package/crates/team-agent/src/messaging/tests/runtime.rs +0 -3549
  323. package/crates/team-agent/src/messaging/tests/spine.rs +0 -853
  324. package/crates/team-agent/src/messaging/tests/wave2.rs +0 -381
  325. package/crates/team-agent/src/messaging/trust.rs +0 -215
  326. package/crates/team-agent/src/messaging/types.rs +0 -472
  327. package/crates/team-agent/src/messaging/wait.rs +0 -366
  328. package/crates/team-agent/src/messaging/watchers.rs +0 -916
  329. package/crates/team-agent/src/model/enums.rs +0 -356
  330. package/crates/team-agent/src/model/errors.rs +0 -18
  331. package/crates/team-agent/src/model/ids.rs +0 -165
  332. package/crates/team-agent/src/model/mod.rs +0 -29
  333. package/crates/team-agent/src/model/name_similarity.rs +0 -252
  334. package/crates/team-agent/src/model/pane_authority_refusal.rs +0 -359
  335. package/crates/team-agent/src/model/paths.rs +0 -257
  336. package/crates/team-agent/src/model/routing.rs +0 -387
  337. package/crates/team-agent/src/model/spec.rs +0 -1184
  338. package/crates/team-agent/src/model/task_graph.rs +0 -321
  339. package/crates/team-agent/src/model/testdata/fuzz.golden.yaml +0 -43
  340. package/crates/team-agent/src/model/testdata/fuzz.yaml +0 -43
  341. package/crates/team-agent/src/model/testdata/spec_invalid_a.yaml +0 -209
  342. package/crates/team-agent/src/model/testdata/team.spec.golden.yaml +0 -208
  343. package/crates/team-agent/src/model/testdata/team.spec.yaml +0 -208
  344. package/crates/team-agent/src/model/yaml/tests.rs +0 -188
  345. package/crates/team-agent/src/model/yaml.rs +0 -802
  346. package/crates/team-agent/src/os_probe.rs +0 -280
  347. package/crates/team-agent/src/packaging/install.rs +0 -219
  348. package/crates/team-agent/src/packaging/migrate.rs +0 -38
  349. package/crates/team-agent/src/packaging/mod.rs +0 -91
  350. package/crates/team-agent/src/packaging/repair.rs +0 -33
  351. package/crates/team-agent/src/packaging/tests.rs +0 -822
  352. package/crates/team-agent/src/packaging/types.rs +0 -417
  353. package/crates/team-agent/src/platform/argv.rs +0 -331
  354. package/crates/team-agent/src/platform/errors.rs +0 -104
  355. package/crates/team-agent/src/platform/file_lock.rs +0 -279
  356. package/crates/team-agent/src/platform/mod.rs +0 -5
  357. package/crates/team-agent/src/platform/process.rs +0 -545
  358. package/crates/team-agent/src/provider/adapter.rs +0 -1150
  359. package/crates/team-agent/src/provider/adapters/claude.rs +0 -78
  360. package/crates/team-agent/src/provider/adapters/claude_fork.rs +0 -131
  361. package/crates/team-agent/src/provider/adapters/copilot.rs +0 -75
  362. package/crates/team-agent/src/provider/adapters/copilot_fork.rs +0 -307
  363. package/crates/team-agent/src/provider/adapters/fake.rs +0 -18
  364. package/crates/team-agent/src/provider/adapters/mod.rs +0 -30
  365. package/crates/team-agent/src/provider/adapters/pi.rs +0 -106
  366. package/crates/team-agent/src/provider/approvals/mod.rs +0 -3
  367. package/crates/team-agent/src/provider/approvals/parsing.rs +0 -586
  368. package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +0 -205
  369. package/crates/team-agent/src/provider/argv_route.rs +0 -405
  370. package/crates/team-agent/src/provider/bypass_flags.rs +0 -116
  371. package/crates/team-agent/src/provider/classify.rs +0 -708
  372. package/crates/team-agent/src/provider/command_helpers.rs +0 -45
  373. package/crates/team-agent/src/provider/faults.rs +0 -165
  374. package/crates/team-agent/src/provider/helpers.rs +0 -52
  375. package/crates/team-agent/src/provider/mod.rs +0 -78
  376. package/crates/team-agent/src/provider/model_catalog.rs +0 -910
  377. package/crates/team-agent/src/provider/session/capture.rs +0 -2731
  378. package/crates/team-agent/src/provider/session/context_fork/claude.rs +0 -123
  379. package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -172
  380. package/crates/team-agent/src/provider/session/context_fork.rs +0 -396
  381. package/crates/team-agent/src/provider/session/mod.rs +0 -36
  382. package/crates/team-agent/src/provider/session/resume.rs +0 -269
  383. package/crates/team-agent/src/provider/session_scan/claude.rs +0 -523
  384. package/crates/team-agent/src/provider/session_scan/common/tests.rs +0 -316
  385. package/crates/team-agent/src/provider/session_scan/common.rs +0 -654
  386. package/crates/team-agent/src/provider/session_scan/copilot.rs +0 -280
  387. package/crates/team-agent/src/provider/session_scan/pi.rs +0 -185
  388. package/crates/team-agent/src/provider/session_scan.rs +0 -71
  389. package/crates/team-agent/src/provider/startup_prompt.rs +0 -757
  390. package/crates/team-agent/src/provider/submit_now.rs +0 -71
  391. package/crates/team-agent/src/provider/testdata/copilot-ready-marker.txt +0 -5
  392. package/crates/team-agent/src/provider/testdata/copilot-trust-prompt.txt +0 -19
  393. package/crates/team-agent/src/provider/testdata/grok-models-authenticated.stdout +0 -9
  394. package/crates/team-agent/src/provider/testdata/grok-models-unauthenticated.stdout +0 -7
  395. package/crates/team-agent/src/provider/tests/adapter.rs +0 -441
  396. package/crates/team-agent/src/provider/tests/classify.rs +0 -148
  397. package/crates/team-agent/src/provider/tests/command_helpers.rs +0 -35
  398. package/crates/team-agent/src/provider/tests/copilot_fork.rs +0 -191
  399. package/crates/team-agent/src/provider/tests/faults.rs +0 -200
  400. package/crates/team-agent/src/provider/tests/idle.rs +0 -177
  401. package/crates/team-agent/src/provider/tests/wire.rs +0 -213
  402. package/crates/team-agent/src/provider/tests.rs +0 -32
  403. package/crates/team-agent/src/provider/types.rs +0 -529
  404. package/crates/team-agent/src/provider/wire.rs +0 -394
  405. package/crates/team-agent/src/redaction.rs +0 -259
  406. package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +0 -248
  407. package/crates/team-agent/src/state/abnormal_watch.rs +0 -144
  408. package/crates/team-agent/src/state/identity.rs +0 -914
  409. package/crates/team-agent/src/state/identity_keys.rs +0 -132
  410. package/crates/team-agent/src/state/mod.rs +0 -74
  411. package/crates/team-agent/src/state/owner_gate.rs +0 -482
  412. package/crates/team-agent/src/state/ownership.rs +0 -563
  413. package/crates/team-agent/src/state/paths.rs +0 -395
  414. package/crates/team-agent/src/state/persist.rs +0 -3811
  415. package/crates/team-agent/src/state/projection.rs +0 -1508
  416. package/crates/team-agent/src/state/repository/intent.rs +0 -14
  417. package/crates/team-agent/src/state/repository/tests.rs +0 -184
  418. package/crates/team-agent/src/state/repository.rs +0 -866
  419. package/crates/team-agent/src/state/selector.rs +0 -160
  420. package/crates/team-agent/src/state/testdata/state-rich.canonical.json +0 -133
  421. package/crates/team-agent/src/test_support/models_timeout_fixture.rs +0 -144
  422. package/crates/team-agent/src/tmux_backend/enter_rescue.rs +0 -325
  423. package/crates/team-agent/src/tmux_backend/enter_rescue_tests.rs +0 -432
  424. package/crates/team-agent/src/tmux_backend/native_input.rs +0 -513
  425. package/crates/team-agent/src/tmux_backend/native_input_tests.rs +0 -742
  426. package/crates/team-agent/src/tmux_backend/tests.rs +0 -4103
  427. package/crates/team-agent/src/tmux_backend.rs +0 -4492
  428. package/crates/team-agent/src/topology.rs +0 -537
  429. package/crates/team-agent/src/transport/enter_rescue.rs +0 -166
  430. package/crates/team-agent/src/transport/native_input.rs +0 -491
  431. package/crates/team-agent/src/transport/test_support.rs +0 -743
  432. package/crates/team-agent/src/transport/tests/behavior.rs +0 -326
  433. package/crates/team-agent/src/transport/tests/mod.rs +0 -194
  434. package/crates/team-agent/src/transport/tests/wire.rs +0 -574
  435. package/crates/team-agent/src/transport.rs +0 -1655
  436. package/crates/team-agent/src/transport_factory.rs +0 -819
@@ -1,1638 +0,0 @@
1
- //! Independent Issue #283 lifecycle properties, using only frozen-baseline seams.
2
- #![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
3
- #![cfg(unix)]
4
- #[path = "../../../tests/support/hermetic.rs"]
5
- mod hermetic;
6
- use crate::leader::{LeaderStartMode, LeaderStartPlan};
7
- use crate::lifecycle::launch::{
8
- add_agent_with_transport, fork_agent_with_transport, quick_start_with_transport_in_workspace,
9
- };
10
- use crate::lifecycle::{
11
- launch_with_transport_in_workspace, reset_agent_with_transport, restart_with_transport,
12
- start_agent_with_transport,
13
- };
14
- use crate::model::enums::Provider;
15
- use crate::model::ids::AgentId;
16
- use crate::state::persist::{load_runtime_state, save_runtime_state};
17
- use crate::transport::test_support::OfflineTransport;
18
- use crate::transport::{PaneId, PaneInfo, SessionName, WindowName};
19
- use serde_json::{json, Value};
20
- use serial_test::serial;
21
- use std::collections::BTreeMap;
22
- use std::fs;
23
- use std::os::unix::fs::PermissionsExt;
24
- use std::path::{Path, PathBuf};
25
- use std::process::{Command, Stdio};
26
- use std::time::{Duration, Instant};
27
-
28
- const SWITCH: &str = "TEAM_AGENT_CLI_ARGV_ROUTING";
29
- const CANONICAL: &[(&str, Provider)] = &[
30
- ("claude", Provider::Claude),
31
- ("claude", Provider::ClaudeCode),
32
- ("codex", Provider::Codex),
33
- ("copilot", Provider::Copilot),
34
- ("gemini_cli", Provider::GeminiCli),
35
- ("grok", Provider::Grok),
36
- ("pi", Provider::Pi),
37
- ];
38
- struct Fixture {
39
- guards: Vec<hermetic::EnvOverride>,
40
- env: hermetic::HermeticTestEnv,
41
- ws: PathBuf,
42
- team: PathBuf,
43
- bin: PathBuf,
44
- probes: PathBuf,
45
- }
46
- impl Fixture {
47
- fn new(tag: &str) -> Self {
48
- let env = hermetic::HermeticTestEnv::enter_with_leader(tag);
49
- let ws = env.workspace("workspace");
50
- let team = ws.join("roles");
51
- fs::create_dir_all(team.join("agents")).unwrap();
52
- let bin = env.root().join("bin");
53
- fs::create_dir(&bin).unwrap();
54
- let probes = env.root().join("probe-argv");
55
- let native = env.root().join("native-argv");
56
- let script = format!("#!/bin/sh\ncase \"$1\" in\n--version) printf '%s\\n' \"$*\" >> '{}'; echo 0.87.1; exit 0;;\n--list-models) printf '%s\\n' \"$*\" >> '{}'; printf 'provider model\\nteam-agent qwen3.8-27b\\n'; exit 0;;\nplugin|mcp|auth|list) printf '%s\\n' \"$*\" >> '{}'; exit 0;;\nesac\nprintf '%s\\0' \"$@\" > '{}'\n/bin/kill -TERM \"$PPID\"\n", probes.display(), probes.display(), probes.display(), native.display());
57
- for name in ["claude", "codex", "copilot", "gemini", "grok", "agent"] {
58
- executable(&bin.join(name), &script);
59
- }
60
- let real_pi = env.root().join("pi-real");
61
- executable(&real_pi, &script);
62
- std::os::unix::fs::symlink(&real_pi, bin.join("pi")).unwrap();
63
- let caller = std::env::var("TMUX").expect("owned fixture caller").split(',').next().unwrap().to_string();
64
- let native_tmux = hermetic::fixture_tmux_binary();
65
- executable(&bin.join("tmux"), &format!(
66
- "#!/bin/sh\nwant_socket=0\nfor argument in \"$@\"; do\n if [ \"$want_socket\" = 1 ]; then\n if [ \"$argument\" = {} ]; then exec {} \"$@\"; fi\n break\n fi\n if [ \"$argument\" = -S ]; then want_socket=1; fi\ndone\ncase \"$*\" in\n*-V*) echo 'tmux 3.4';;\n*has-session*) exit 1;;\n*list-sessions*|*list-windows*|*list-panes*) exit 0;;\n*) exit 0;;\nesac\n",
67
- crate::cli::shell_quote(&caller), crate::cli::shell_quote(&native_tmux.to_string_lossy()),
68
- ));
69
- let guards = vec![
70
- env.with_env("PATH", &format!("{}:/usr/bin:/bin", bin.display())),
71
- env.with_env(SWITCH, "off"),
72
- env.with_env(
73
- "TEAM_AGENT_TEST_PROCESS_ANCESTRY_ARGV_JSON",
74
- "[\"/bin/zsh\"]",
75
- ),
76
- env.with_env("TEAM_AGENT_RESTART_SESSION_CAPTURE_DEADLINE_MS", "25"),
77
- env.with_env("TEAM_AGENT_RESTART_SESSION_CAPTURE_POLL_MS", "5"),
78
- ];
79
- seed_coordinator(&ws);
80
- Self {
81
- guards,
82
- env,
83
- ws,
84
- team,
85
- bin,
86
- probes,
87
- }
88
- }
89
- fn config(&self) -> PathBuf {
90
- self.env.home().join(".team-agent/argv-routing.json")
91
- }
92
- fn seed(&self, enabled: bool, providers: Value) {
93
- self.raw(&json!({"schema_version":1,"enabled":enabled,"providers":providers}).to_string());
94
- }
95
- fn raw(&self, raw: &str) {
96
- fs::write(self.config(), raw).unwrap();
97
- }
98
- fn switch(&self, value: Option<&str>) {
99
- unsafe {
100
- if let Some(v) = value {
101
- std::env::set_var(SWITCH, v);
102
- } else {
103
- std::env::remove_var(SWITCH);
104
- }
105
- }
106
- }
107
- fn spec(&self, provider: &str, ids: &[&str]) -> PathBuf {
108
- fs::write(self.team.join("TEAM.md"), "---\nname: argvteam\nobjective: Literal argv route fixture.\n---\n\nTeam.\n").unwrap();
109
- for id in ids {
110
- fs::write(
111
- self.team.join(format!("agents/{id}.md")),
112
- role(provider, id),
113
- )
114
- .unwrap();
115
- }
116
- let spec = crate::compiler::compile_team(&self.team).unwrap();
117
- let path = self.team.join("team.spec.yaml");
118
- fs::write(&path, crate::model::yaml::dumps(&spec)).unwrap();
119
- path
120
- }
121
- fn cold(&self, provider: &str) -> Vec<String> {
122
- let spec = self.spec(provider, &["worker"]);
123
- let t = offline();
124
- // Each property sample is a new fixture-owned cold generation, not an
125
- // unauthorized overwrite of a live topology. No real pane/process exists.
126
- let state_path = crate::state::persist::runtime_state_path(&self.ws);
127
- fs::create_dir_all(state_path.parent().unwrap()).unwrap();
128
- // Missing files can legitimately recover from the process-local state
129
- // cache. A literal empty fixture snapshot starts a new cold generation.
130
- fs::write(state_path, "{}").unwrap();
131
- let result = launch_with_transport_in_workspace(&self.ws, &spec, false, false, true, &t);
132
- assert!(
133
- result.is_ok(),
134
- "fixture library cold boundary must reach native plan: {result:?}"
135
- );
136
- let spawns = t.spawn_records();
137
- assert_eq!(spawns.len(), 1);
138
- spawns[0].1.clone()
139
- }
140
- fn leader(
141
- &self,
142
- provider: Provider,
143
- external: bool,
144
- attach: bool,
145
- ) -> Result<LeaderStartPlan, crate::leader::LeaderError> {
146
- crate::leader::start::leader_start_plan_after_ambient_authority_check(
147
- provider,
148
- &[],
149
- &self.ws,
150
- attach,
151
- attach,
152
- None,
153
- external,
154
- )
155
- }
156
- fn start_team(&self, provider: &str, ids: &[&str]) -> OfflineTransport {
157
- self.spec(provider, ids);
158
- let t = offline();
159
- let report = quick_start_with_transport_in_workspace(
160
- &self.ws,
161
- &self.team,
162
- None,
163
- true,
164
- Some("argvteam"),
165
- &t,
166
- )
167
- .unwrap();
168
- assert!(
169
- matches!(report, crate::lifecycle::QuickStartReport::Ready { .. }),
170
- "setup must produce real spawn: {report:?}"
171
- );
172
- assert_eq!(t.spawn_records().len(), ids.len());
173
- t
174
- }
175
- fn mutate_agent(&self, id: &str, f: impl FnOnce(&mut Value)) {
176
- let selected =
177
- crate::state::projection::select_runtime_state(&self.ws, Some("argvteam")).unwrap();
178
- let mut state = selected;
179
- f(&mut state["agents"][id]);
180
- crate::state::projection::save_team_scoped_state_with_lifecycle_topology_authority(
181
- &self.ws,
182
- &state,
183
- "argvteam",
184
- &[id],
185
- )
186
- .unwrap();
187
- }
188
- fn native_file(&self) -> PathBuf {
189
- self.env.root().join("native-argv")
190
- }
191
- }
192
- // Field guards restore changed environment before HermeticTestEnv removes its owned root.
193
- impl Drop for Fixture {
194
- fn drop(&mut self) {
195
- self.guards.clear();
196
- }
197
- }
198
- fn offline() -> OfflineTransport {
199
- let mut t = OfflineTransport::new();
200
- for index in 0..=8 {
201
- t = t.with_capture_for_pane(
202
- format!("%{index}"),
203
- "Claude Code\n> \nOpenAI Codex\ncodex>\n❯\n / commands · ? help\n",
204
- );
205
- }
206
- t
207
- }
208
- fn executable(path: &Path, script: &str) {
209
- fs::write(path, script).unwrap();
210
- fs::set_permissions(path, fs::Permissions::from_mode(0o755)).unwrap();
211
- }
212
- fn role(provider: &str, id: &str) -> String {
213
- let model = if provider == "pi" {
214
- "team-agent/qwen3.8-27b"
215
- } else {
216
- "gpt-5.5"
217
- };
218
- format!("---\nname: {id}\nrole: {id} Worker\nprovider: {provider}\nmodel: {model}\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nLiteral route worker.\n")
219
- }
220
- fn seed_coordinator(ws: &Path) {
221
- let workspace = crate::coordinator::WorkspacePath::new(ws.to_path_buf());
222
- let pid = crate::coordinator::Pid::new(std::process::id());
223
- fs::create_dir_all(crate::model::paths::runtime_dir(ws)).unwrap();
224
- crate::coordinator::write_coordinator_metadata(
225
- &workspace,
226
- pid,
227
- crate::coordinator::MetadataSource::Boot,
228
- )
229
- .unwrap();
230
- fs::write(
231
- crate::coordinator::coordinator_pid_path(&workspace),
232
- pid.to_string(),
233
- )
234
- .unwrap();
235
- }
236
- fn normalized(argv: &[String]) -> Vec<String> {
237
- let mut result = argv.to_vec();
238
- for i in 1..result.len() {
239
- if result[i - 1] == "--session-id" {
240
- result[i] = "<baseline-dynamic-session-id>".into();
241
- }
242
- }
243
- result
244
- }
245
- fn injected(base: &[String], route: &[String], actual: &[String]) {
246
- let mut expected = base[..1].to_vec();
247
- expected.extend_from_slice(route);
248
- expected.extend_from_slice(&base[1..]);
249
- assert_eq!(
250
- normalized(actual),
251
- normalized(&expected),
252
- "R must be inserted once immediately after executable; native tail unchanged"
253
- );
254
- }
255
- fn assert_route(actual: &[String], route: &[&str]) {
256
- assert!(
257
- actual.len() > route.len(),
258
- "native executable and tail must exist"
259
- );
260
- assert_eq!(
261
- &actual[1..=route.len()],
262
- route,
263
- "route missing/incorrect at final native spawn: {actual:?}"
264
- );
265
- for token in route {
266
- assert_eq!(
267
- actual.iter().filter(|v| v.as_str() == *token).count(),
268
- 1,
269
- "duplicate route token {token}"
270
- );
271
- }
272
- }
273
- fn same_leader_env(actual: &BTreeMap<String, String>, base: &BTreeMap<String, String>) {
274
- let mut actual = actual.clone();
275
- let mut base = base.clone();
276
- // This intentional caller-input difference is not product env injection.
277
- actual.remove(SWITCH);
278
- base.remove(SWITCH);
279
- assert!(
280
- actual == base,
281
- "native env changed beyond the caller's routing override"
282
- );
283
- }
284
- fn live_pane(ws: &Path) -> PaneInfo {
285
- let state = crate::state::projection::select_runtime_state(ws, Some("argvteam")).unwrap();
286
- PaneInfo {
287
- pane_id: PaneId::new("%old"),
288
- session: SessionName::new(state["session_name"].as_str().unwrap()),
289
- window_index: None,
290
- window_name: Some(WindowName::new("worker")),
291
- pane_index: None,
292
- tty: None,
293
- current_command: Some("copilot".into()),
294
- current_path: None,
295
- active: true,
296
- pane_pid: None,
297
- leader_env: BTreeMap::new(),
298
- }
299
- }
300
-
301
- #[test]
302
- #[serial(env)]
303
- fn a01_default_off_matches_explicit_off_at_cold_common_and_leader_boundaries() {
304
- let f = Fixture::new("argv-a01");
305
- f.switch(None);
306
- let cold = f.cold("copilot");
307
- assert!(!f.config().exists());
308
- unsafe {
309
- std::env::set_var("TMUX", "fixture,1,0");
310
- }
311
- let leader = f.leader(Provider::Codex, true, false).unwrap();
312
- f.seed(
313
- true,
314
- json!({"codex":["must-not-appear"],"copilot":["must-not-appear"]}),
315
- );
316
- f.switch(Some("off"));
317
- assert_eq!(normalized(&f.cold("copilot")), normalized(&cold));
318
- let off_leader = f.leader(Provider::Codex, true, false).unwrap();
319
- assert_eq!(off_leader.argv, leader.argv);
320
- same_leader_env(&off_leader.leader_env, &leader.leader_env);
321
- assert_eq!(off_leader.workspace, leader.workspace);
322
- assert_eq!(off_leader.identity, leader.identity);
323
- unsafe {
324
- std::env::remove_var("TMUX");
325
- }
326
- drop(f);
327
- let f = Fixture::new("argv-a01-common");
328
- f.switch(None);
329
- f.start_team("copilot", &["worker"]);
330
- let baseline = offline();
331
- start_agent_with_transport(
332
- &f.ws,
333
- &AgentId::new("worker"),
334
- true,
335
- false,
336
- false,
337
- Some("argvteam"),
338
- &baseline,
339
- )
340
- .unwrap();
341
- f.seed(true, json!({"copilot":["must-not-appear"]}));
342
- f.switch(Some("off"));
343
- let t = offline();
344
- start_agent_with_transport(
345
- &f.ws,
346
- &AgentId::new("worker"),
347
- true,
348
- false,
349
- false,
350
- Some("argvteam"),
351
- &t,
352
- )
353
- .unwrap();
354
- assert_eq!(
355
- normalized(&t.spawn_records()[0].1),
356
- normalized(&baseline.spawn_records()[0].1)
357
- );
358
- assert_eq!(t.spawn_cwd_records(), baseline.spawn_cwd_records());
359
- assert!(!t.spawn_records()[0]
360
- .1
361
- .iter()
362
- .any(|v| v == "must-not-appear"));
363
- assert!(!f.config().with_file_name("argv-routing.lock").exists());
364
- }
365
-
366
- #[test]
367
- #[serial(env)]
368
- fn a02_off_invalid_and_unopted_bad_json_preserve_native_startup() {
369
- let f = Fixture::new("argv-a02");
370
- let base = f.cold("copilot");
371
- for raw in [
372
- "bad JSON",
373
- r#"{"enabled":false,"providers":"bad"}"#,
374
- r#"{"enabled":true,"providers":{"copilot":[0]}}"#,
375
- ] {
376
- f.raw(raw);
377
- for value in [Some("off"), Some(" 0 "), Some(""), Some("bogus")] {
378
- f.switch(value);
379
- assert_eq!(normalized(&f.cold("copilot")), normalized(&base));
380
- }
381
- }
382
- for raw in [
383
- "bad JSON",
384
- r#"{"enabled":false,"providers":"bad"}"#,
385
- r#"{"enabled":"unknown"}"#,
386
- ] {
387
- f.raw(raw);
388
- f.switch(None);
389
- assert_eq!(normalized(&f.cold("copilot")), normalized(&base));
390
- }
391
- }
392
-
393
- #[test]
394
- #[serial(env)]
395
- fn a02_forced_off_proves_no_config_open_with_fifo_and_bounded_child() {
396
- let f = Fixture::new("argv-fifo");
397
- let path = std::ffi::CString::new(f.config().as_os_str().as_encoded_bytes()).unwrap();
398
- assert_eq!(unsafe { libc::mkfifo(path.as_ptr(), 0o600) }, 0);
399
- let mut child = Command::new(std::env::current_exe().unwrap())
400
- .args([
401
- "--exact",
402
- "lifecycle::tests::cli_argv_routing_red::off_fifo_child",
403
- "--ignored",
404
- ])
405
- .env(SWITCH, "off")
406
- .env("ARGV_RED_WORKSPACE", &f.ws)
407
- .stdout(Stdio::null())
408
- .stderr(Stdio::null())
409
- .spawn()
410
- .unwrap();
411
- let start = Instant::now();
412
- loop {
413
- if let Some(status) = child.try_wait().unwrap() {
414
- assert!(
415
- status.success(),
416
- "OFF child plan must succeed without reading FIFO"
417
- );
418
- break;
419
- }
420
- if start.elapsed() > Duration::from_secs(3) {
421
- child.kill().unwrap();
422
- child.wait().unwrap();
423
- panic!("OFF opened FIFO instead of short-circuiting before configuration read");
424
- }
425
- std::thread::sleep(Duration::from_millis(10));
426
- }
427
- }
428
- #[test]
429
- #[ignore = "invoked only by bounded no-config-open property"]
430
- fn off_fifo_child() {
431
- let ws = PathBuf::from(std::env::var_os("ARGV_RED_WORKSPACE").expect("subprocess-only helper"));
432
- crate::leader::start::leader_start_plan_after_ambient_authority_check(
433
- Provider::Codex,
434
- &[],
435
- &ws,
436
- false,
437
- false,
438
- None,
439
- false,
440
- )
441
- .unwrap();
442
- }
443
-
444
- #[test]
445
- #[serial(env)]
446
- fn a03_persisted_enabled_and_env_override_apply_at_native_cold_boundary() {
447
- let f = Fixture::new("argv-a03");
448
- let base = f.cold("copilot");
449
- for (persisted, env, should_route) in [
450
- (true, None, true),
451
- (false, None, false),
452
- (false, Some("on"), true),
453
- (true, Some("false"), false),
454
- ] {
455
- f.seed(persisted, json!({"copilot":["route-priority"]}));
456
- f.switch(env);
457
- let argv = f.cold("copilot");
458
- injected(
459
- &base,
460
- &if should_route {
461
- vec!["route-priority".into()]
462
- } else {
463
- vec![]
464
- },
465
- &argv,
466
- );
467
- }
468
- }
469
-
470
- #[test]
471
- #[serial(env)]
472
- fn a05_generated_literal_tokens_roundtrip_cli_json_native_and_posix_wrappers() {
473
- let f = Fixture::new("argv-literal");
474
- let base = f.cold("copilot");
475
- let sentinel = f.env.root().join("INJECTION-MUST-NOT-RUN");
476
- for seed in 0..16 {
477
- let route = vec![
478
- "".into(),
479
- format!(" 路由{seed} 🚀 "),
480
- "\"x\" 'y'\nline".into(),
481
- format!(
482
- "; touch {}; $(touch {}); `touch {}`",
483
- sentinel.display(),
484
- sentinel.display(),
485
- sentinel.display()
486
- ),
487
- "{workspace}".into(),
488
- "--help".into(),
489
- "--json".into(),
490
- "--no-display".into(),
491
- "--".into(),
492
- ];
493
- let mut cmd = Command::new(super::test_binary_path());
494
- cmd.current_dir(&f.ws)
495
- .args(["route", "set", "copilot", "--json", "--"])
496
- .args(&route)
497
- .env(SWITCH, "off");
498
- let out = cmd.output().unwrap();
499
- assert!(
500
- out.status.success(),
501
- "CLI literal property requires successful storage: {:?}",
502
- String::from_utf8_lossy(&out.stderr)
503
- );
504
- let persisted: Value = serde_json::from_slice(&fs::read(f.config()).unwrap()).unwrap();
505
- assert_eq!(persisted["providers"]["copilot"], json!(route));
506
- f.switch(Some("on"));
507
- let actual = f.cold("copilot");
508
- injected(&base, &route, &actual);
509
- let mut recorded = actual.clone();
510
- recorded[0] = f.bin.join("copilot").to_string_lossy().into_owned();
511
- for leader in [false, true] {
512
- let line = if leader {
513
- crate::tmux_backend::leader_shell_wrapper_command(
514
- &recorded,
515
- &f.ws,
516
- &BTreeMap::new(),
517
- &[],
518
- "copilot",
519
- )
520
- } else {
521
- crate::tmux_backend::worker_shell_wrapper_command(
522
- &recorded,
523
- &f.ws,
524
- &BTreeMap::new(),
525
- &[],
526
- "copilot",
527
- )
528
- };
529
- // Recorder terminates its exact parent shell after capturing argv; no inert-tail orphan.
530
- let status = Command::new("/bin/sh")
531
- .args(["-c", &line])
532
- .stdout(Stdio::null())
533
- .stderr(Stdio::null())
534
- .status()
535
- .unwrap();
536
- assert!(!status.success());
537
- let bytes = fs::read(f.native_file()).unwrap();
538
- let args = bytes
539
- .split(|b| *b == 0)
540
- .take(recorded.len() - 1)
541
- .map(|v| String::from_utf8(v.to_vec()).unwrap())
542
- .collect::<Vec<_>>();
543
- assert_eq!(args, recorded[1..]);
544
- assert!(!sentinel.exists());
545
- }
546
- f.switch(Some("off"));
547
- }
548
- }
549
-
550
- fn provider_property(key: &str, provider: Provider) {
551
- let f = Fixture::new("argv-provider");
552
- let _leader = f.env.with_env("TEAM_AGENT_LEADER_PROVIDER", "pi");
553
- let _caller = f.env.with_env("TEAM_AGENT_CALLER_PROVIDER", "pi");
554
- let wire = crate::provider::wire::provider_wire(provider);
555
- let base = f.cold(wire);
556
- let providers = CANONICAL
557
- .iter()
558
- .map(|(k, _)| ((*k).to_string(), json!([format!("route-only-{k}")])))
559
- .collect::<serde_json::Map<_, _>>();
560
- f.seed(true, Value::Object(providers));
561
- f.switch(None);
562
- let actual = f.cold(wire);
563
- f.seed(true, json!({"pi":["pi-must-not-leak"]}));
564
- if provider != Provider::Pi {
565
- assert_eq!(normalized(&f.cold(wire)), normalized(&base));
566
- }
567
- injected(&base, &[format!("route-only-{key}")], &actual);
568
- assert_eq!(
569
- actual
570
- .iter()
571
- .filter(|v| v.starts_with("route-only-"))
572
- .count(),
573
- 1
574
- );
575
- }
576
- macro_rules! provider_tests { ($($name:ident => $key:literal, $provider:ident;)*) => { $(#[test] #[serial(env)] fn $name() { provider_property($key, Provider::$provider); })* }; }
577
- provider_tests! {
578
- a06_claude => "claude", Claude;
579
- a06_claude_code => "claude", ClaudeCode;
580
- a06_copilot => "copilot", Copilot;
581
- a06_gemini_cli => "gemini_cli", GeminiCli;
582
- a06_pi => "pi", Pi;
583
- }
584
-
585
- #[test]
586
- #[serial(env)]
587
- fn a06_fake_worker_is_outside_native_router_even_under_invalid_optin() {
588
- let f = Fixture::new("argv-fake");
589
- let base = f.cold("fake");
590
- f.raw("invalid JSON");
591
- f.switch(Some("on"));
592
- assert_eq!(f.cold("fake"), base);
593
- assert!(base.iter().any(|v| v == "fake-worker"));
594
- }
595
-
596
- #[test]
597
- #[serial(env)]
598
- fn a07_leader_new_existing_exec_managed_new_session_and_attach_modes() {
599
- let mut samples = Vec::new();
600
- for existing in [false, true] {
601
- let f = Fixture::new("argv-leader");
602
- if existing {
603
- save_runtime_state(
604
- &f.ws,
605
- &json!({"active_team_key":"argvteam","session_name":"team-argvteam","agents":{}}),
606
- )
607
- .unwrap();
608
- }
609
- for (tmux, external, expected_mode) in [
610
- (true, true, LeaderStartMode::ExecProvider),
611
- (false, false, LeaderStartMode::ManagedTmuxClient),
612
- (false, true, LeaderStartMode::NewTmuxSession),
613
- ] {
614
- unsafe {
615
- if tmux {
616
- std::env::set_var("TMUX", "fixture,1,0");
617
- } else {
618
- std::env::remove_var("TMUX");
619
- }
620
- }
621
- f.switch(Some("off"));
622
- let base = f.leader(Provider::Pi, external, false).unwrap();
623
- f.seed(true, json!({"pi":["--mode","rpc"]}));
624
- f.switch(None);
625
- let routed = f.leader(Provider::Pi, external, false).unwrap();
626
- assert_eq!(routed.mode, expected_mode);
627
- same_leader_env(&routed.leader_env, &base.leader_env);
628
- assert_eq!(routed.workspace, base.workspace);
629
- assert_eq!(routed.identity, base.identity);
630
- if routed.mode == LeaderStartMode::ExecProvider {
631
- assert_eq!(routed.argv, routed.provider_argv);
632
- }
633
- if routed.mode == LeaderStartMode::ManagedTmuxClient {
634
- assert!(!routed.argv.iter().any(|v| v == "--mode" || v == "rpc"));
635
- }
636
- if routed.mode == LeaderStartMode::NewTmuxSession {
637
- // Execute the actual encoded shell payload against a recorder,
638
- // not tmux or a real provider. This path execs, so exit normally.
639
- executable(
640
- &f.env.root().join("pi-real"),
641
- &format!(
642
- "#!/bin/sh\nprintf '%s\\0' \"$@\" > '{}'\nexit 0\n",
643
- f.native_file().display()
644
- ),
645
- );
646
- let shell = routed.argv.last().unwrap();
647
- assert!(shell.starts_with("cd "));
648
- assert!(Command::new("/bin/sh")
649
- .args(["-c", shell])
650
- .stdout(Stdio::null())
651
- .stderr(Stdio::null())
652
- .status()
653
- .unwrap()
654
- .success());
655
- let bytes = fs::read(f.native_file()).unwrap();
656
- let actual = bytes
657
- .split(|b| *b == 0)
658
- .take(routed.provider_argv.len() - 1)
659
- .map(|v| String::from_utf8(v.to_vec()).unwrap())
660
- .collect::<Vec<_>>();
661
- assert_eq!(actual, routed.provider_argv[1..]);
662
- }
663
- samples.push((base.provider_argv, routed.provider_argv));
664
- }
665
- unsafe {
666
- std::env::remove_var("TMUX");
667
- }
668
- f.raw("invalid but opt-in");
669
- f.switch(Some("on"));
670
- let attach = f.leader(Provider::Pi, true, true).unwrap();
671
- assert_eq!(attach.mode, LeaderStartMode::AttachExisting);
672
- assert!(attach.provider_argv.is_empty());
673
- }
674
- assert_eq!(samples.len(), 6);
675
- for (base, routed) in samples {
676
- injected(&base, &["--mode".into(), "rpc".into()], &routed);
677
- }
678
- }
679
-
680
- #[test]
681
- #[serial(env)]
682
- fn a07_pi_explicit_invalid_arguments_remain_rejected_under_routing() {
683
- let f = Fixture::new("argv-pi-reject");
684
- f.seed(true, json!({"pi":["--mode","rpc"]}));
685
- f.switch(None);
686
- for args in [
687
- vec!["--thinking".to_string(), "invalid".into()],
688
- vec!["--unknown".into()],
689
- ] {
690
- let result = crate::leader::start::leader_start_plan_after_ambient_authority_check(
691
- Provider::Pi,
692
- &args,
693
- &f.ws,
694
- false,
695
- false,
696
- None,
697
- false,
698
- );
699
- assert!(
700
- result.is_err(),
701
- "route must not weaken Pi explicit input validation"
702
- );
703
- }
704
- }
705
-
706
- #[test]
707
- #[serial(env)]
708
- fn a08_quick_start_first_later_paused_dry_run_and_live_noop() {
709
- let f = Fixture::new("argv-quick");
710
- f.seed(true, json!({"copilot":["cold-route"]}));
711
- f.switch(None);
712
- let t = f.start_team("copilot", &["worker", "mate"]);
713
- let observed_spawns = t.spawn_records();
714
- let noop =
715
- quick_start_with_transport_in_workspace(&f.ws, &f.team, None, true, Some("argvteam"), &t);
716
- assert!(noop.is_ok());
717
- assert_eq!(t.spawn_records().len(), 2, "live-noop must not spawn again");
718
- let spec = f.spec("copilot", &["worker", "mate"]);
719
- f.raw("invalid schema");
720
- f.switch(Some("on"));
721
- let dry = offline();
722
- assert!(launch_with_transport_in_workspace(&f.ws, &spec, true, false, true, &dry).is_ok());
723
- assert!(dry.spawn_records().is_empty());
724
- drop(f);
725
- let f = Fixture::new("argv-paused");
726
- let spec = f.spec("copilot", &["worker", "mate"]);
727
- f.raw("invalid schema");
728
- f.switch(Some("on"));
729
- // Typed paused flags, not assumptions about YAML renderer indentation.
730
- use crate::model::yaml::Value as Yaml;
731
- let mut paused = crate::model::yaml::loads(&fs::read_to_string(&spec).unwrap()).unwrap();
732
- let Yaml::Map(top) = &mut paused else {
733
- panic!("fixture spec object");
734
- };
735
- let Yaml::List(agents) = &mut top.iter_mut().find(|(key, _)| key == "agents").unwrap().1 else {
736
- panic!("fixture agents list");
737
- };
738
- for agent in agents {
739
- let Yaml::Map(fields) = agent else {
740
- panic!("fixture agent object");
741
- };
742
- if let Some((_, value)) = fields.iter_mut().find(|(key, _)| key == "paused") {
743
- *value = Yaml::Bool(true);
744
- } else {
745
- fields.push(("paused".into(), Yaml::Bool(true)));
746
- }
747
- }
748
- fs::write(&spec, crate::model::yaml::dumps(&paused)).unwrap();
749
- let paused_t = offline();
750
- let result = launch_with_transport_in_workspace(&f.ws, &spec, false, false, true, &paused_t);
751
- assert!(
752
- result.is_ok(),
753
- "paused-only must not validate opt-in routing: {result:?}"
754
- );
755
- assert!(paused_t.spawn_records().is_empty());
756
- for (_, argv) in observed_spawns {
757
- assert_route(&argv, &["cold-route"]);
758
- }
759
- }
760
-
761
- #[test]
762
- #[serial(env)]
763
- fn a09_start_fresh_missing_backing_reset_and_add_use_new_route_once() {
764
- let f = Fixture::new("argv-single");
765
- f.start_team("copilot", &["worker"]);
766
- f.seed(true, json!({"copilot":["single-route"]}));
767
- f.switch(None);
768
- let mut samples = Vec::new();
769
- for backing in [false, true] {
770
- f.mutate_agent("worker", |a| {
771
- a["status"] = json!("stopped");
772
- if backing {
773
- a["session_id"] = json!("lost-session");
774
- a["rollout_path"] = json!(f.ws.join("missing.jsonl"));
775
- a["captured_at"] = json!("2026-01-01T00:00:00Z");
776
- a["captured_via"] = json!("session_scan");
777
- }
778
- });
779
- let t = offline();
780
- let result = start_agent_with_transport(
781
- &f.ws,
782
- &AgentId::new("worker"),
783
- false,
784
- false,
785
- true,
786
- Some("argvteam"),
787
- &t,
788
- );
789
- assert!(
790
- result.is_ok(),
791
- "allow-fresh missing backing fixture: {result:?}"
792
- );
793
- assert_eq!(t.spawn_records().len(), 1);
794
- samples.push(t.spawn_records()[0].1.clone());
795
- }
796
- let reset = offline();
797
- let result = reset_agent_with_transport(
798
- &f.ws,
799
- &AgentId::new("worker"),
800
- true,
801
- false,
802
- Some("argvteam"),
803
- &reset,
804
- );
805
- assert!(result.is_ok(), "reset fixture: {result:?}");
806
- assert_eq!(reset.spawn_records().len(), 1);
807
- samples.push(reset.spawn_records()[0].1.clone());
808
- let role_file = f.ws.join("mate-role.md");
809
- fs::write(&role_file, role("copilot", "mate")).unwrap();
810
- let added = offline().with_session_present(true);
811
- add_agent_with_transport(
812
- &f.team,
813
- &AgentId::new("mate"),
814
- &role_file,
815
- false,
816
- Some("argvteam"),
817
- &added,
818
- )
819
- .unwrap();
820
- assert_eq!(added.spawn_records().len(), 1);
821
- samples.push(added.spawn_records()[0].1.clone());
822
- assert_eq!(samples.len(), 4);
823
- for argv in samples {
824
- assert_route(&argv, &["single-route"]);
825
- }
826
- }
827
-
828
- #[test]
829
- #[serial(env)]
830
- fn a09_resume_retains_session_metadata_while_routes_change() {
831
- let f = Fixture::new("argv-resume");
832
- f.start_team("pi", &["worker"]);
833
- let selected = crate::state::projection::select_runtime_state(&f.ws, Some("argvteam")).unwrap();
834
- // Native --session-id pins fresh seats in Pi\'s shared project session root.
835
- assert!(selected["agents"]["worker"]["_pending_session_id"].as_str().is_some_and(|id| !id.is_empty()));
836
- assert!(selected["agents"]["worker"]["session_id"].is_null(), "a pending native id is not a captured session");
837
- let session_id = "8d6c1f2e-4a5b-4c7d-9e0f-a09000000001";
838
- let session = crate::lifecycle::launch::pi_mcp::pi_seat_paths(&f.ws, "argvteam", "worker")
839
- .sessions
840
- .join("valid.jsonl");
841
- fs::create_dir_all(session.parent().unwrap()).unwrap();
842
- fs::write(&session, format!("{}\n{}\n", json!({"type":"session","version":3,"id":session_id,"cwd":f.ws,"timestamp":"2026-01-01T00:00:00Z"}), json!({"type":"message","id":"a","parentId":null,"timestamp":"2026-01-01T00:00:01Z","message":{"role":"user","content":[{"type":"text","text":"seed"}]}}))).unwrap();
843
- f.mutate_agent("worker", |a| {
844
- a["status"] = json!("stopped");
845
- a["session_id"] = json!(session_id);
846
- a["rollout_path"] = json!(session);
847
- a["captured_at"] = json!("2026-01-01T00:00:01Z");
848
- a["captured_via"] = json!("session_scan");
849
- a["capture_state"] = json!("captured");
850
- a["first_send_at"] = json!("2026-01-01T00:00:01Z");
851
- });
852
- f.seed(true, json!({"pi":["resume-route"]}));
853
- f.switch(None);
854
- let t = offline();
855
- start_agent_with_transport(
856
- &f.ws,
857
- &AgentId::new("worker"),
858
- false,
859
- false,
860
- false,
861
- Some("argvteam"),
862
- &t,
863
- )
864
- .unwrap();
865
- assert_eq!(t.spawn_records().len(), 1);
866
- let argv = t.spawn_records()[0].1.clone();
867
- assert!(argv
868
- .windows(2)
869
- .any(|p| p[0] == "--session" && Path::new(&p[1]) == session));
870
- assert!(!argv.iter().any(|v| v == "--session-id"));
871
- let retained = offline().with_session_present(true);
872
- let reset = reset_agent_with_transport(
873
- &f.ws,
874
- &AgentId::new("worker"),
875
- false,
876
- false,
877
- Some("argvteam"),
878
- &retained,
879
- );
880
- // Existing reset policy requires discard-session even with a valid tuple.
881
- // Protect refusal; routing must not invent a retain-session reset branch.
882
- assert!(matches!(
883
- reset,
884
- Ok(crate::lifecycle::ResetAgentOutcome::Refused { .. })
885
- ));
886
- assert!(retained.spawn_records().is_empty());
887
- let restarted = offline()
888
- .with_session_present(true)
889
- .with_default_liveness(crate::transport::PaneLiveness::Dead);
890
- let report = restart_with_transport(&f.ws, false, Some("argvteam"), &restarted);
891
- assert!(report.is_ok(), "in-session resume fixture: {report:?}");
892
- assert_eq!(restarted.spawn_records().len(), 1);
893
- let restart_argv = restarted.spawn_records()[0].1.clone();
894
- assert!(restart_argv
895
- .windows(2)
896
- .any(|p| p[0] == "--session" && Path::new(&p[1]) == session));
897
- assert_route(&argv, &["resume-route"]);
898
- assert_route(&restart_argv, &["resume-route"]);
899
- }
900
-
901
- #[test]
902
- #[serial(env)]
903
- fn a09_remove_rollback_respawns_original_seat_with_route_once() {
904
- let f = Fixture::new("argv-rollback");
905
- f.start_team("copilot", &["worker", "mate"]);
906
- f.mutate_agent("worker", |a| {
907
- a["pane_id"] = json!("%old");
908
- a["window"] = json!("worker");
909
- });
910
- let _fail = f.env.with_env(
911
- "TEAM_AGENT_TEST_FAIL_REMOVE_AFTER_AGENT_HEALTH_DELETE",
912
- "argv-route-red",
913
- );
914
- f.seed(true, json!({"copilot":["rollback-route"]}));
915
- f.switch(None);
916
- let t = offline()
917
- .with_session_present(true)
918
- .with_targets(vec![live_pane(&f.ws)]);
919
- let result = crate::lifecycle::restart::remove_agent_with_transport(
920
- &f.ws,
921
- &AgentId::new("worker"),
922
- true,
923
- true,
924
- Some("argvteam"),
925
- &t,
926
- );
927
- assert!(result.is_err());
928
- assert_eq!(
929
- t.spawn_records().len(),
930
- 1,
931
- "fault must reach rollback respawn: {result:?}"
932
- );
933
- assert_route(&t.spawn_records()[0].1, &["rollback-route"]);
934
- let state = crate::state::projection::select_runtime_state(&f.ws, Some("argvteam")).unwrap();
935
- assert!(
936
- state["agents"]["worker"].is_object(),
937
- "rollback must restore original seat"
938
- );
939
- }
940
-
941
- #[test]
942
- #[serial(env)]
943
- fn a09_pi_fork_inherits_session_and_routes_only_new_native_spawn() {
944
- let f = Fixture::new("argv-fork");
945
- f.start_team("pi", &["worker"]);
946
- let session = crate::lifecycle::launch::pi_mcp::pi_seat_paths(&f.ws, "argvteam", "worker")
947
- .sessions
948
- .join("source.jsonl");
949
- fs::create_dir_all(session.parent().unwrap()).unwrap();
950
- let id = "fc317e54-bdbb-4ce5-8c1a-2b1bf33a9700";
951
- fs::write(&session, format!("{}\n{}\n", json!({"type":"session","version":3,"id":id,"cwd":f.ws,"timestamp":"2026-01-01T00:00:00Z"}), json!({"type":"message","id":"seed01","parentId":null,"timestamp":"2026-01-01T00:00:01Z","message":{"role":"user","content":[{"type":"text","text":"fork seed"}]}}))).unwrap();
952
- f.mutate_agent("worker", |a| {
953
- a["session_id"] = json!(id);
954
- a["rollout_path"] = json!(session);
955
- a["captured_at"] = json!("2026-01-01T00:00:01Z");
956
- a["captured_via"] = json!("session_scan");
957
- a["capture_state"] = json!("captured");
958
- });
959
- let original = fs::read(&session).unwrap();
960
- f.seed(true, json!({"pi":["fork-route"]}));
961
- f.switch(None);
962
- let t = offline().with_session_present(true);
963
- let report = fork_agent_with_transport(
964
- &f.ws,
965
- &AgentId::new("worker"),
966
- &AgentId::new("forked"),
967
- None,
968
- false,
969
- Some("argvteam"),
970
- &t,
971
- );
972
- assert!(
973
- report.is_ok(),
974
- "valid v3 Pi fork must reach native spawn: {report:?}"
975
- );
976
- assert_eq!(t.spawn_records().len(), 1);
977
- assert_route(&t.spawn_records()[0].1, &["fork-route"]);
978
- assert_eq!(fs::read(session).unwrap(), original);
979
- }
980
-
981
- #[test]
982
- #[serial(env)]
983
- fn a09_claude_fork_spawns_native_fork_seat_and_leaves_source_unchanged() {
984
- let f = Fixture::new("argv-claude-fork");
985
- f.start_team("claude", &["worker"]);
986
- let parent = "11111111-2222-4333-8444-555555555555";
987
- let transcript = f.ws.join("parent-transcript.jsonl");
988
- fs::write(&transcript, "{\"type\":\"user\"}\n").unwrap();
989
- f.mutate_agent("worker", |a| {
990
- a["session_id"] = json!(parent);
991
- a["rollout_path"] = json!(transcript);
992
- a["captured_at"] = json!("2026-01-01T00:00:01Z");
993
- a["captured_via"] = json!("session_scan");
994
- a["capture_state"] = json!("captured");
995
- });
996
- let tuple = |state: &Value| {
997
- ["session_id", "rollout_path", "captured_at", "captured_via"]
998
- .map(|key| state["agents"]["worker"][key].clone())
999
- };
1000
- let before =
1001
- tuple(&crate::state::projection::select_runtime_state(&f.ws, Some("argvteam")).unwrap());
1002
-
1003
- // No in-place branch: the same id is refused before any key or spawn.
1004
- let same = offline().with_session_present(true);
1005
- let refused = fork_agent_with_transport(
1006
- &f.ws,
1007
- &AgentId::new("worker"),
1008
- &AgentId::new("worker"),
1009
- None,
1010
- false,
1011
- Some("argvteam"),
1012
- &same,
1013
- );
1014
- assert!(format!("{refused:?}").contains("new seat"), "{refused:?}");
1015
- assert!(same.spawn_records().is_empty() && same.inject_payloads().is_empty());
1016
-
1017
- let t = offline().with_session_present(true);
1018
- let report = fork_agent_with_transport(
1019
- &f.ws,
1020
- &AgentId::new("worker"),
1021
- &AgentId::new("forked"),
1022
- None,
1023
- false,
1024
- Some("argvteam"),
1025
- &t,
1026
- )
1027
- .expect("a legacy Claude seat forks into a new seat in one call");
1028
- assert_eq!(report.new_agent_id.as_str(), "forked");
1029
- // The shim never writes the child transcript: pending, never a fabricated id.
1030
- assert_eq!(
1031
- report.backing_state,
1032
- crate::lifecycle::ForkBackingState::PendingContextFork
1033
- );
1034
- assert!(report.session_id.is_none());
1035
- let spawns = t.spawn_records();
1036
- assert_eq!(spawns.len(), 1);
1037
- let argv = &spawns[0].1;
1038
- let after = |flag: &str| {
1039
- argv.iter()
1040
- .position(|value| value == flag)
1041
- .and_then(|index| argv.get(index + 1))
1042
- .cloned()
1043
- };
1044
- assert_eq!(after("--resume").as_deref(), Some(parent), "{argv:?}");
1045
- assert!(
1046
- argv.iter().any(|value| value == "--fork-session"),
1047
- "{argv:?}"
1048
- );
1049
- let child = after("--session-id").expect("preassigned child session");
1050
- assert_ne!(child, parent);
1051
-
1052
- let state = crate::state::projection::select_runtime_state(&f.ws, Some("argvteam")).unwrap();
1053
- let row = &state["agents"]["forked"];
1054
- assert_eq!(row["provider"], "claude", "{row}");
1055
- assert_eq!(row["status"], "running", "{row}");
1056
- assert_eq!(row["_pending_session_id"], json!(child), "{row}");
1057
- assert!(
1058
- row.get("_fork_parent_session_id").is_none(),
1059
- "one-shot fork instruction: {row}"
1060
- );
1061
- assert!(
1062
- row.get("forked_from").is_none(),
1063
- "capture must own the new row: {row}"
1064
- );
1065
- assert_eq!(tuple(&state), before, "the parent tuple is only read");
1066
- assert_eq!(
1067
- fs::read_to_string(&transcript).unwrap(),
1068
- "{\"type\":\"user\"}\n"
1069
- );
1070
- let events = crate::event_log::EventLog::new(&f.ws).tail(0).unwrap();
1071
- let spawn = events
1072
- .iter()
1073
- .rev()
1074
- .find(|event| {
1075
- event["event"] == "provider.worker.spawn_argv" && event["agent_id"] == "forked"
1076
- })
1077
- .expect("fork spawn argv event");
1078
- assert!(
1079
- spawn["env_overlay_keys"].as_array().is_some_and(|keys| keys
1080
- .iter()
1081
- .any(|key| key == "CLAUDE_CODE_RESUME_THRESHOLD_MINUTES")),
1082
- "a fork never stops on the stale-resume modal: {spawn}"
1083
- );
1084
- }
1085
-
1086
- #[test]
1087
- #[serial(env)]
1088
- fn a09_public_clone_reaches_native_argv_without_inheriting_old_route() {
1089
- let f = Fixture::new("argv-clone");
1090
- f.start_team("copilot", &["worker"]);
1091
- // Public clone has no Transport seam: this fixture tmux executes the actual
1092
- // generated provider shell line against the argv recorder, never real tmux.
1093
- let calls = f.env.root().join("clone-spawn-calls");
1094
- let identity = f.env.root().join("clone-pane-identity");
1095
- executable(
1096
- &f.bin.join("tmux"),
1097
- &format!(
1098
- r#"#!/bin/sh
1099
- if [ "$1" = -S ] || [ "$1" = -L ]; then shift 2; fi
1100
- op=$1; shift
1101
- case "$op" in
1102
- -V) echo 'tmux 3.4';;
1103
- has-session) exit 0;;
1104
- new-window|new-session|split-window)
1105
- previous=''
1106
- for last do
1107
- case "$previous" in -s|-t) session=$last;; -n) window=$last;; esac
1108
- previous=$last
1109
- done
1110
- printf '%s\n' "$op" >> '{}'
1111
- printf '%%99__TA_FIELD__%s__TA_FIELD__1__TA_FIELD__%s__TA_FIELD__0__TA_FIELD__/dev/pts/99__TA_FIELD__copilot__TA_FIELD__1__TA_FIELD__{}__TA_FIELD__0__TA_FIELD__0__TA_FIELD__1__TA_FIELD__\n' "$session" "$window" > '{}'
1112
- /bin/sh -c "$last" >/dev/null 2>&1
1113
- echo %99; exit 0;;
1114
- list-panes) while IFS= read -r line; do printf '%s\n' "$line"; done < '{}';;
1115
- display-message) for last do :; done; case "$last" in *pane_id*) echo %99;; *pane_dead*) echo 0;; *pane_width*) echo 120;; esac;;
1116
- capture-pane) printf '%s\n' '❯' ' / commands · ? help';;
1117
- *) exit 0;;
1118
- esac
1119
- "#,
1120
- calls.display(),
1121
- f.ws.display(),
1122
- identity.display(),
1123
- identity.display()
1124
- ),
1125
- );
1126
- f.seed(true, json!({"copilot":["clone-route"]}));
1127
- f.switch(None);
1128
- let cloned = crate::lifecycle::clone_agent(
1129
- &f.ws,
1130
- &AgentId::new("worker"),
1131
- &AgentId::new("cloned"),
1132
- None,
1133
- false,
1134
- Some("argvteam"),
1135
- );
1136
- assert!(
1137
- cloned.is_ok(),
1138
- "public clone fixture must complete: {cloned:?}"
1139
- );
1140
- assert_eq!(fs::read_to_string(calls).unwrap().lines().count(), 1);
1141
- let bytes = fs::read(f.native_file()).unwrap();
1142
- let args = bytes
1143
- .split(|b| *b == 0)
1144
- .filter(|b| !b.is_empty())
1145
- .map(|b| String::from_utf8(b.to_vec()).unwrap())
1146
- .collect::<Vec<_>>();
1147
- assert_eq!(args.first().map(String::as_str), Some("clone-route"));
1148
- assert_eq!(
1149
- args.iter().filter(|v| v.as_str() == "clone-route").count(),
1150
- 1
1151
- );
1152
- }
1153
-
1154
- #[test]
1155
- #[serial(env)]
1156
- fn a09_allowed_force_recreate_uses_route_once_after_old_seat_is_dead() {
1157
- let f = Fixture::new("argv-force");
1158
- f.start_team("copilot", &["worker"]);
1159
- let role_file = f.ws.join("replacement.md");
1160
- fs::write(&role_file, role("copilot", "worker")).unwrap();
1161
- f.seed(true, json!({"copilot":["force-route"]}));
1162
- f.switch(None);
1163
- let t = offline();
1164
- let result = crate::lifecycle::launch::add_agent_with_transport_force(
1165
- &f.team,
1166
- &AgentId::new("worker"),
1167
- &role_file,
1168
- false,
1169
- Some("argvteam"),
1170
- true,
1171
- &t,
1172
- );
1173
- assert!(
1174
- result.is_ok(),
1175
- "allowed dead-seat force fixture must complete: {result:?}"
1176
- );
1177
- assert_eq!(t.spawn_records().len(), 1);
1178
- assert_route(&t.spawn_records()[0].1, &["force-route"]);
1179
- }
1180
-
1181
- #[test]
1182
- #[serial(env)]
1183
- fn a10_live_start_noop_is_not_validated_against_bad_route_config() {
1184
- let f = Fixture::new("argv-keep");
1185
- f.start_team("copilot", &["worker"]);
1186
- f.mutate_agent("worker", |a| {
1187
- a["pane_id"] = json!("%old");
1188
- a["window"] = json!("worker");
1189
- });
1190
- f.raw("invalid JSON");
1191
- f.switch(Some("on"));
1192
- let t = offline()
1193
- .with_session_present(true)
1194
- .with_targets(vec![live_pane(&f.ws)])
1195
- .with_windows(vec![WindowName::new("worker")])
1196
- .with_liveness("%old", crate::transport::PaneLiveness::Live);
1197
- // The baseline restart library deliberately rebuilds live seats. Observe
1198
- // the actual existing live-seat Noop surface, without inventing new policy.
1199
- let result = start_agent_with_transport(
1200
- &f.ws,
1201
- &AgentId::new("worker"),
1202
- false,
1203
- false,
1204
- false,
1205
- Some("argvteam"),
1206
- &t,
1207
- );
1208
- assert!(
1209
- matches!(result, Ok(crate::lifecycle::StartAgentOutcome::Noop { .. })),
1210
- "live Noop must not consult router: {result:?}"
1211
- );
1212
- assert!(t.spawn_records().is_empty());
1213
- }
1214
-
1215
- #[test]
1216
- #[serial(env)]
1217
- fn a10_restart_first_parallel_later_reloads_mapping_without_stacking() {
1218
- let f = Fixture::new("argv-restart");
1219
- f.start_team("copilot", &["worker", "mate", "third"]);
1220
- let mut samples = Vec::new();
1221
- for marker in ["route-generation-one", "route-generation-two"] {
1222
- f.seed(true, json!({"copilot":[marker]}));
1223
- f.switch(None);
1224
- let t = offline();
1225
- let result = restart_with_transport(&f.ws, true, Some("argvteam"), &t);
1226
- assert!(
1227
- result.is_ok(),
1228
- "restart fixture must reach plans: {result:?}"
1229
- );
1230
- assert_eq!(t.spawn_records().len(), 3);
1231
- for (_, argv) in t.spawn_records() {
1232
- samples.push((marker, argv));
1233
- }
1234
- }
1235
- assert_eq!(samples.len(), 6);
1236
- for (marker, argv) in samples {
1237
- assert_route(&argv, &[marker]);
1238
- if marker.ends_with("two") {
1239
- assert!(!argv.iter().any(|v| v == "route-generation-one"));
1240
- }
1241
- }
1242
- }
1243
-
1244
- #[test]
1245
- #[serial(env)]
1246
- fn a11_enabled_bad_schema_fails_before_native_spawn_at_all_three_boundaries() {
1247
- let f = Fixture::new("argv-errors");
1248
- f.start_team("copilot", &["worker"]);
1249
- for raw in [
1250
- "bad JSON",
1251
- r#"{"schema_version":2,"enabled":true,"providers":{}}"#,
1252
- r#"{"schema_version":1,"enabled":true,"providers":{"unknown":[]}}"#,
1253
- r#"{"schema_version":1,"enabled":true,"providers":{"pi":[7]}}"#,
1254
- r#"{"schema_version":1,"enabled":true,"providers":{"pi":["\u0000"]}}"#,
1255
- r#"{"schema_version":1,"enabled":true,"providers":{"pi":[],"pi":[]}}"#,
1256
- ] {
1257
- f.raw(raw);
1258
- f.switch(Some("on"));
1259
- let spec = f.spec("copilot", &["worker"]);
1260
- let cold = offline();
1261
- assert!(
1262
- launch_with_transport_in_workspace(&f.ws, &spec, false, false, true, &cold).is_err(),
1263
- "ON cold must reject {raw}"
1264
- );
1265
- assert!(cold.spawn_records().is_empty());
1266
- let single = offline();
1267
- assert!(
1268
- start_agent_with_transport(
1269
- &f.ws,
1270
- &AgentId::new("worker"),
1271
- true,
1272
- false,
1273
- false,
1274
- Some("argvteam"),
1275
- &single
1276
- )
1277
- .is_err(),
1278
- "ON single must reject {raw}"
1279
- );
1280
- assert!(single.spawn_records().is_empty());
1281
- let leader = f.leader(Provider::Codex, false, false);
1282
- assert!(leader.is_err(), "ON leader must reject {raw}");
1283
- }
1284
- f.seed(true, json!({"pi":[]}));
1285
- f.switch(None);
1286
- fs::remove_file(f.config()).unwrap();
1287
- fs::create_dir(f.config()).unwrap();
1288
- f.switch(Some("on"));
1289
- assert!(f.leader(Provider::Codex, false, false).is_err());
1290
- fs::remove_dir(f.config()).unwrap();
1291
- let _home = f.env.with_env("HOME", "relative-home");
1292
- assert!(f.leader(Provider::Codex, false, false).is_err());
1293
- }
1294
-
1295
- #[test]
1296
- #[serial(env)]
1297
- fn a13_materializer_version_catalog_and_nonagent_command_builders_are_not_routed() {
1298
- let f = Fixture::new("argv-probes");
1299
- f.seed(
1300
- true,
1301
- json!({"pi":["--mode","rpc"],"copilot":["must-not-pollute-probe"]}),
1302
- );
1303
- f.switch(None);
1304
- let base = f.cold("pi");
1305
- let _ = crate::lifecycle::launch::pi_mcp::pi_model_candidates("team-agent/qwen3.8-27b");
1306
- let probes = fs::read_to_string(&f.probes).unwrap();
1307
- assert!(probes.contains("--version"));
1308
- assert!(probes.contains("--list-models"));
1309
- for line in probes.lines() {
1310
- assert!(!line.contains("rpc") && !line.contains("--mode"));
1311
- }
1312
- assert!(
1313
- !f.native_file().exists(),
1314
- "plan/materializer must not execute native provider session"
1315
- );
1316
- assert_route(&base, &["--mode", "rpc"]);
1317
- }
1318
-
1319
- #[test]
1320
- #[serial(env)]
1321
- fn a07_attach_existing_never_opens_enabled_invalid_route_config() {
1322
- let f = Fixture::new("argv-attach");
1323
- // This planner-only case explicitly models attach from outside tmux,
1324
- // not the owned caller used by positive worker-start fixtures.
1325
- f.env.scrub_tmux();
1326
- f.raw("invalid JSON");
1327
- f.switch(Some("on"));
1328
- let plan = f.leader(Provider::Pi, true, true).unwrap();
1329
- assert_eq!(plan.mode, LeaderStartMode::AttachExisting);
1330
- assert!(plan.provider_argv.is_empty());
1331
- assert!(!plan.argv.iter().any(|v| v == "rpc"));
1332
- }
1333
-
1334
- #[test]
1335
- #[serial(env)]
1336
- fn a13_all_provider_version_and_auth_auxiliary_argv_are_native() {
1337
- let f = Fixture::new("argv-aux");
1338
- let mappings = CANONICAL
1339
- .iter()
1340
- .map(|(k, _)| ((*k).to_string(), json!(["route-must-not-enter-aux"])))
1341
- .collect::<serde_json::Map<_, _>>();
1342
- f.seed(true, Value::Object(mappings));
1343
- f.switch(None);
1344
- for (_, provider) in CANONICAL {
1345
- assert!(crate::provider::get_adapter(*provider).version().is_ok());
1346
- }
1347
- let _ = crate::provider::get_adapter(Provider::ClaudeCode)
1348
- .auth_hint(crate::model::enums::AuthMode::Subscription);
1349
- let _ = f.cold("copilot");
1350
- let probes = fs::read_to_string(&f.probes).unwrap();
1351
- assert!(!probes.contains("route-must-not-enter-aux"));
1352
- assert!(probes.contains("--version"));
1353
- }
1354
-
1355
- #[test]
1356
- #[serial(env)]
1357
- fn a14_posix_native_recorder_literal_vector_positive_guard() {
1358
- let f = Fixture::new("argv-posix-positive");
1359
- let sentinel = f.env.root().join("MUST-NOT-EXIST");
1360
- let argv = vec![
1361
- f.bin.join("pi").to_string_lossy().into_owned(),
1362
- "".into(),
1363
- " x y ".into(),
1364
- "路由🚀".into(),
1365
- "'\"\\\n".into(),
1366
- format!(
1367
- ";touch {};$(touch {});`touch {}`",
1368
- sentinel.display(),
1369
- sentinel.display(),
1370
- sentinel.display()
1371
- ),
1372
- "--help".into(),
1373
- "--json".into(),
1374
- "--no-display".into(),
1375
- "--".into(),
1376
- ];
1377
- for leader in [false, true] {
1378
- let line = if leader {
1379
- crate::tmux_backend::leader_shell_wrapper_command(
1380
- &argv,
1381
- &f.ws,
1382
- &BTreeMap::new(),
1383
- &[],
1384
- "pi",
1385
- )
1386
- } else {
1387
- crate::tmux_backend::worker_shell_wrapper_command(
1388
- &argv,
1389
- &f.ws,
1390
- &BTreeMap::new(),
1391
- &[],
1392
- "pi",
1393
- )
1394
- };
1395
- let status = Command::new("/bin/sh")
1396
- .args(["-c", &line])
1397
- .stdout(Stdio::null())
1398
- .stderr(Stdio::null())
1399
- .status()
1400
- .unwrap();
1401
- assert!(!status.success());
1402
- let bytes = fs::read(f.native_file()).unwrap();
1403
- let received = bytes
1404
- .split(|b| *b == 0)
1405
- .take(argv.len() - 1)
1406
- .map(|v| String::from_utf8(v.to_vec()).unwrap())
1407
- .collect::<Vec<_>>();
1408
- assert_eq!(received, argv[1..]);
1409
- assert!(!sentinel.exists());
1410
- }
1411
- }
1412
-
1413
- #[test]
1414
- #[serial(env)]
1415
- fn a14_conpty_spawn_request_frame_preserves_routed_vector_not_windows_live_pass() {
1416
- use conpty_transport::protocol::{read_frame, write_frame, SpawnRequest};
1417
- let f = Fixture::new("argv-conpty");
1418
- f.seed(
1419
- true,
1420
- json!({"copilot":["", "a b", "路由", "\"x\"\\", "line\nbreak"]}),
1421
- );
1422
- f.switch(None);
1423
- let argv = f.cold("copilot");
1424
- assert_eq!(&argv[1..6], &["", "a b", "路由", "\"x\"\\", "line\nbreak"]);
1425
- let request = SpawnRequest {
1426
- session: "team-argvteam".into(),
1427
- window: "worker".into(),
1428
- argv: argv.clone(),
1429
- cwd: f.ws.to_string_lossy().into_owned(),
1430
- env: BTreeMap::new(),
1431
- env_unset: vec![],
1432
- cols: 120,
1433
- rows: 30,
1434
- };
1435
- let mut wire = Vec::new();
1436
- write_frame(&mut wire, &serde_json::to_vec(&request).unwrap()).unwrap();
1437
- let decoded: SpawnRequest =
1438
- serde_json::from_slice(&read_frame(&mut wire.as_slice()).unwrap()).unwrap();
1439
- assert_eq!(decoded.argv, argv);
1440
- assert_eq!(decoded.cwd, request.cwd);
1441
- }
1442
-
1443
- #[test]
1444
- #[serial(env)]
1445
- fn a15_provider_drift_and_unknown_force_remain_refused() {
1446
- let f = Fixture::new("argv-drift");
1447
- f.start_team("copilot", &["worker"]);
1448
- f.seed(
1449
- true,
1450
- json!({"pi":["must-not-spawn"],"copilot":["must-not-spawn"]}),
1451
- );
1452
- f.switch(None);
1453
- f.mutate_agent("worker", |a| {
1454
- a["status"] = json!("stopped");
1455
- a["pane_id"] = json!("%old");
1456
- });
1457
- let before = crate::state::projection::select_runtime_state(&f.ws, Some("argvteam")).unwrap();
1458
- let drift = crate::lifecycle::role_config::start_agent_from_role(
1459
- &f.ws,
1460
- &AgentId::new("worker"),
1461
- &crate::lifecycle::role_config::RoleConfigPatch {
1462
- provider: Some("pi".into()),
1463
- ..Default::default()
1464
- },
1465
- true,
1466
- Some("argvteam"),
1467
- );
1468
- assert!(
1469
- matches!(drift, Err(crate::lifecycle::LifecycleError::RequirementUnmet(ref message)) if message.contains("provider change is not allowed"))
1470
- );
1471
- assert!(!f.native_file().exists());
1472
- let role_file = f.ws.join("replacement.md");
1473
- fs::write(&role_file, role("copilot", "worker")).unwrap();
1474
- // The public role-config admission guard owns unknown/live force refusal.
1475
- // Its native tmux fixture returns inconclusive identity, never proven dead.
1476
- executable(&f.bin.join("tmux"), "#!/bin/sh\ncase \"$*\" in\n*-V*) echo 'tmux 3.4';;\n*display-message*) echo 'fixture backend unavailable' >&2; exit 1;;\n*) exit 0;;\nesac\n");
1477
- let forced = crate::lifecycle::role_config::add_agent_from_role(
1478
- &f.ws,
1479
- &AgentId::new("worker"),
1480
- Some(&role_file),
1481
- &Default::default(),
1482
- true,
1483
- Some("argvteam"),
1484
- );
1485
- assert!(
1486
- forced.is_err(),
1487
- "unknown old pane must not be force-recreated"
1488
- );
1489
- assert!(!f.native_file().exists());
1490
- let after = crate::state::projection::select_runtime_state(&f.ws, Some("argvteam")).unwrap();
1491
- assert_eq!(
1492
- after["agents"]["worker"]["provider"],
1493
- before["agents"]["worker"]["provider"]
1494
- );
1495
- }
1496
-
1497
- #[test]
1498
- #[serial(env)]
1499
- fn issue381_every_cursor_name_adds_through_the_contract_leaf_never_legacy_agent() {
1500
- let f = Fixture::new("cursor-contract-add");
1501
- f.start_team("copilot", &["worker"]);
1502
- let before = crate::state::projection::select_runtime_state(&f.ws, Some("argvteam")).unwrap();
1503
- let probes_before = fs::read_to_string(&f.probes).unwrap_or_default();
1504
- for (index, name) in ["cursor", "cursor-agent", "agent", "cursor_agent"].into_iter().enumerate() {
1505
- let id = format!("cursor-{index}");
1506
- let added = crate::lifecycle::role_config::add_agent_from_role(
1507
- &f.ws,
1508
- &AgentId::new(&id),
1509
- None,
1510
- &crate::lifecycle::role_config::RoleConfigPatch {
1511
- provider: Some(name.into()),
1512
- model: Some("gpt-5.6-luna-xhigh".into()),
1513
- bypass: Some(true),
1514
- // An omitted --prompt still yields a valid contract role body.
1515
- prompt: (index > 0).then(|| "Reply to every task.".into()),
1516
- ..Default::default()
1517
- },
1518
- false,
1519
- Some("argvteam"),
1520
- );
1521
- // The fixture PATH has a fake legacy `agent` but no `cursor-agent`:
1522
- // the contract leaf's discovery refuses before any native effect.
1523
- let error = added.expect_err("no cursor-agent on PATH").to_string();
1524
- assert!(error.contains("cursor-agent"), "{name}: {error}");
1525
- assert!(!f.team.join(format!("agents/{id}.md")).exists(), "{name}: role rolled back");
1526
- let after = crate::state::projection::select_runtime_state(&f.ws, Some("argvteam")).unwrap();
1527
- assert!(after["agents"].get(&id).is_none(), "{name}: seed row rolled back");
1528
- assert_eq!(after["agents"]["worker"], before["agents"]["worker"], "{name}");
1529
- }
1530
- let probes = fs::read_to_string(&f.probes).unwrap_or_default();
1531
- assert_eq!(probes, probes_before, "no legacy `agent` probe or catalog read");
1532
- }
1533
-
1534
- #[test]
1535
- #[serial(env)]
1536
- fn a15_route_does_not_relax_running_start_reset_discard_or_unsupported_fork() {
1537
- let f = Fixture::new("argv-old-refusals");
1538
- f.start_team("copilot", &["worker"]);
1539
- f.mutate_agent("worker", |a| {
1540
- a["pane_id"] = json!("%old");
1541
- a["window"] = json!("worker");
1542
- });
1543
- f.seed(true, json!({"copilot":["refusal-route"]}));
1544
- f.switch(None);
1545
- let t = offline()
1546
- .with_session_present(true)
1547
- .with_targets(vec![live_pane(&f.ws)])
1548
- .with_windows(vec![WindowName::new("worker")])
1549
- .with_liveness("%old", crate::transport::PaneLiveness::Live);
1550
- let start = start_agent_with_transport(
1551
- &f.ws,
1552
- &AgentId::new("worker"),
1553
- false,
1554
- false,
1555
- false,
1556
- Some("argvteam"),
1557
- &t,
1558
- );
1559
- assert!(
1560
- matches!(
1561
- start,
1562
- Err(_) | Ok(crate::lifecycle::StartAgentOutcome::Noop { .. })
1563
- ),
1564
- "existing live seat must refuse/noop without spawn"
1565
- );
1566
- assert!(t.spawn_records().is_empty());
1567
- let reset = reset_agent_with_transport(
1568
- &f.ws,
1569
- &AgentId::new("worker"),
1570
- false,
1571
- false,
1572
- Some("argvteam"),
1573
- &t,
1574
- )
1575
- .unwrap();
1576
- assert!(matches!(
1577
- reset,
1578
- crate::lifecycle::ResetAgentOutcome::Refused { .. }
1579
- ));
1580
- assert!(t.spawn_records().is_empty());
1581
- let fork = fork_agent_with_transport(
1582
- &f.ws,
1583
- &AgentId::new("worker"),
1584
- &AgentId::new("forked"),
1585
- None,
1586
- false,
1587
- Some("argvteam"),
1588
- &t,
1589
- );
1590
- assert!(fork.is_err());
1591
- assert!(t.spawn_records().is_empty());
1592
- let before = load_runtime_state(&f.ws).unwrap();
1593
- assert!(before.pointer("/agents/forked").is_none());
1594
- }
1595
-
1596
- #[test]
1597
- #[serial(env)]
1598
- fn a16_cold_spawn_refuses_retired_or_missing_worker_provider_before_any_pane() {
1599
- use crate::model::yaml::Value as Yaml;
1600
- // A pre-upgrade spec agent naming a retired legacy key, or naming no
1601
- // provider at all, never falls back to a legacy engine. `grok` is a
1602
- // runtime alias of grok_build, so it takes the native route instead.
1603
- for (tag, provider, expected) in [
1604
- ("argv-retired-codex", Some("codex"), "legacy codex seat has no runtime in this release"),
1605
- ("argv-native-grok", Some("grok"), "no legacy fallback"),
1606
- ("argv-missing-provider", None, "unknown worker provider \"\""),
1607
- ] {
1608
- let f = Fixture::new(tag);
1609
- let spec = f.spec("copilot", &["worker"]);
1610
- let mut edited = crate::model::yaml::loads(&fs::read_to_string(&spec).unwrap()).unwrap();
1611
- let Yaml::Map(top) = &mut edited else {
1612
- panic!("fixture spec object");
1613
- };
1614
- let Yaml::List(agents) = &mut top.iter_mut().find(|(key, _)| key == "agents").unwrap().1 else {
1615
- panic!("fixture agents list");
1616
- };
1617
- for agent in agents {
1618
- let Yaml::Map(fields) = agent else {
1619
- panic!("fixture agent object");
1620
- };
1621
- fields.retain(|(key, _)| key != "provider");
1622
- if let Some(provider) = provider {
1623
- fields.push(("provider".into(), Yaml::Str(provider.into())));
1624
- }
1625
- }
1626
- fs::write(&spec, crate::model::yaml::dumps(&edited)).unwrap();
1627
- let state_path = crate::state::persist::runtime_state_path(&f.ws);
1628
- fs::create_dir_all(state_path.parent().unwrap()).unwrap();
1629
- fs::write(state_path, "{}").unwrap();
1630
- let t = offline();
1631
- let error = launch_with_transport_in_workspace(&f.ws, &spec, false, false, true, &t)
1632
- .unwrap_err()
1633
- .to_string();
1634
- assert!(error.contains(expected), "{tag}: {error}");
1635
- assert!(t.spawn_records().is_empty(), "{tag}");
1636
- assert!(!f.native_file().exists(), "{tag}");
1637
- }
1638
- }