@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,1851 +0,0 @@
1
- use super::launch_spawn::{seed_healthy_coordinator, DELEG_ROLE_ALPHA, DELEG_ROLE_BRAVO};
2
- use super::*;
3
-
4
- // ═════════════════════════════════════════════════════════════════════════
5
-
6
- // Fork sources run on `copilot`, the legacy provider whose adapter still claims native fork, so a
7
- // refusal from the legacy fork entry cannot be explained by a missing capability.
8
- pub(super) const COPILOT_ROLE_ALPHA: &str = "---\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";
9
- const DELEG_ROLE_ALPHA_COMPAT: &str = "---\nname: alpha\nrole: Alpha Worker\nprovider: copilot\nmodel: gpt-5.5\nauth_mode: compatible_api\ndangerously_skip_permissions: false\nprofile: alpha-compat\ntools:\n - mcp_team\n---\n\nAlpha.\n";
10
-
11
- /// The legacy fork entry never forks in-window and never substitutes a fresh replacement: a
12
- /// non-retired legacy row is refused as unverified, naming its provider.
13
- pub(super) fn assert_legacy_fork_unverified<T: std::fmt::Debug>(
14
- result: &Result<T, LifecycleError>,
15
- provider: &str,
16
- ) {
17
- let expected = format!(
18
- "{provider} native session fork is unverified (未验证); no legacy fork or fresh replacement was performed"
19
- );
20
- assert!(
21
- matches!(result, Err(LifecycleError::Provider(message)) if *message == expected),
22
- "the legacy fork entry must refuse a {provider} row as unverified; got {result:?}"
23
- );
24
- }
25
-
26
- type LaneKills = std::sync::Arc<std::sync::Mutex<Vec<String>>>;
27
- pub(super) type LaneSpawns = std::sync::Arc<std::sync::Mutex<Vec<(String, Vec<String>)>>>;
28
-
29
- pub(super) struct LaneHomeGuard {
30
- previous: Option<std::ffi::OsString>,
31
- root: PathBuf,
32
- }
33
-
34
- impl LaneHomeGuard {
35
- pub(super) fn enter(tag: &str) -> Self {
36
- static HOME_SEQ: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
37
- let root = std::env::temp_dir().join(format!(
38
- "ta-lane-home-{tag}-{}-{}",
39
- std::process::id(),
40
- HOME_SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
41
- ));
42
- let _ = std::fs::remove_dir_all(&root);
43
- std::fs::create_dir_all(&root).unwrap();
44
- let previous = std::env::var_os("HOME");
45
- std::env::set_var("HOME", &root);
46
- Self { previous, root }
47
- }
48
- }
49
-
50
- impl Drop for LaneHomeGuard {
51
- fn drop(&mut self) {
52
- match &self.previous {
53
- Some(value) => std::env::set_var("HOME", value),
54
- None => std::env::remove_var("HOME"),
55
- }
56
- let _ = std::fs::remove_dir_all(&self.root);
57
- }
58
- }
59
-
60
- /// Recording transport for Lane-A v2: `list_windows`/`list_targets` answer from a configurable window
61
- /// set (golden's `_tmux_window_exists` primitive = `tmux list-windows`); `kill_window` + spawn_first/into
62
- /// are RECORDED. Every other method returns a benign Ok (never panics) so stop/reset/remove/fork run
63
- /// end-to-end in-process.
64
- pub(super) struct LaneTransport {
65
- session: String,
66
- windows: std::sync::Arc<std::sync::Mutex<Vec<String>>>,
67
- foreign: std::sync::Arc<std::sync::Mutex<Vec<(String, String)>>>,
68
- killed: LaneKills,
69
- spawns: LaneSpawns,
70
- spawn_observed_at: std::sync::Arc<std::sync::Mutex<Vec<String>>>,
71
- stop_preservation: std::sync::Mutex<Vec<(Vec<crate::transport::Target>, Vec<String>)>>,
72
- fail_stop_preservation: bool,
73
- }
74
- impl LaneTransport {
75
- pub(super) fn new(session: &str, windows: &[&str]) -> Self {
76
- Self {
77
- session: session.to_string(),
78
- windows: std::sync::Arc::new(std::sync::Mutex::new(
79
- windows.iter().map(|w| (*w).to_string()).collect(),
80
- )),
81
- foreign: std::sync::Arc::new(std::sync::Mutex::new(Vec::new())),
82
- killed: std::sync::Arc::new(std::sync::Mutex::new(Vec::new())),
83
- spawns: std::sync::Arc::new(std::sync::Mutex::new(Vec::new())),
84
- spawn_observed_at: std::sync::Arc::new(std::sync::Mutex::new(Vec::new())),
85
- stop_preservation: std::sync::Mutex::new(Vec::new()),
86
- fail_stop_preservation: false,
87
- }
88
- }
89
- pub(super) fn killed(&self) -> Vec<String> {
90
- self.killed.lock().unwrap().clone()
91
- }
92
- pub(super) fn spawns(&self) -> Vec<(String, Vec<String>)> {
93
- self.spawns.lock().unwrap().clone()
94
- }
95
- fn spawn_observed_at(&self) -> Vec<String> {
96
- self.spawn_observed_at.lock().unwrap().clone()
97
- }
98
- fn add_foreign(&self, session: &str, window: &str) {
99
- self.foreign
100
- .lock()
101
- .unwrap()
102
- .push((session.to_string(), window.to_string()));
103
- }
104
- }
105
- impl crate::transport::Transport for LaneTransport {
106
- fn kind(&self) -> crate::transport::BackendKind {
107
- crate::transport::BackendKind::Tmux
108
- }
109
- fn spawn_first(
110
- &self,
111
- session: &crate::transport::SessionName,
112
- window: &crate::transport::WindowName,
113
- argv: &[String],
114
- _c: &std::path::Path,
115
- _e: &std::collections::BTreeMap<String, String>,
116
- ) -> Result<crate::transport::SpawnResult, crate::transport::TransportError> {
117
- self.spawn_observed_at
118
- .lock()
119
- .unwrap()
120
- .push(chrono::Utc::now().to_rfc3339());
121
- self.spawns
122
- .lock()
123
- .unwrap()
124
- .push(("spawn_first".to_string(), argv.to_vec()));
125
- if !self
126
- .windows
127
- .lock()
128
- .unwrap()
129
- .iter()
130
- .any(|name| name == window.as_str())
131
- {
132
- self.windows
133
- .lock()
134
- .unwrap()
135
- .push(window.as_str().to_string());
136
- }
137
- Ok(crate::transport::SpawnResult {
138
- pane_id: crate::transport::PaneId::new(format!("%{}", window.as_str())),
139
- session: session.clone(),
140
- window: window.clone(),
141
- child_pid: None,
142
- })
143
- }
144
- fn spawn_into(
145
- &self,
146
- session: &crate::transport::SessionName,
147
- window: &crate::transport::WindowName,
148
- argv: &[String],
149
- _c: &std::path::Path,
150
- _e: &std::collections::BTreeMap<String, String>,
151
- ) -> Result<crate::transport::SpawnResult, crate::transport::TransportError> {
152
- self.spawn_observed_at
153
- .lock()
154
- .unwrap()
155
- .push(chrono::Utc::now().to_rfc3339());
156
- self.spawns
157
- .lock()
158
- .unwrap()
159
- .push(("spawn_into".to_string(), argv.to_vec()));
160
- if !self
161
- .windows
162
- .lock()
163
- .unwrap()
164
- .iter()
165
- .any(|name| name == window.as_str())
166
- {
167
- self.windows
168
- .lock()
169
- .unwrap()
170
- .push(window.as_str().to_string());
171
- }
172
- Ok(crate::transport::SpawnResult {
173
- pane_id: crate::transport::PaneId::new(format!("%{}", window.as_str())),
174
- session: session.clone(),
175
- window: window.clone(),
176
- child_pid: None,
177
- })
178
- }
179
- fn inject(
180
- &self,
181
- _t: &crate::transport::Target,
182
- _p: &crate::transport::InjectPayload,
183
- _s: crate::transport::Key,
184
- _b: bool,
185
- ) -> Result<crate::transport::InjectReport, crate::transport::TransportError> {
186
- unimplemented!("LaneTransport::inject not reached by stop/reset/remove/fork")
187
- }
188
- fn send_keys(
189
- &self,
190
- _t: &crate::transport::Target,
191
- _k: &[crate::transport::Key],
192
- ) -> Result<(), crate::transport::TransportError> {
193
- Ok(())
194
- }
195
- fn capture(
196
- &self,
197
- _t: &crate::transport::Target,
198
- r: crate::transport::CaptureRange,
199
- ) -> Result<crate::transport::CapturedText, crate::transport::TransportError> {
200
- Ok(crate::transport::CapturedText {
201
- // A fresh worker has reached the ready prompt by the time this
202
- // deterministic lifecycle replay observes its pane. Returning
203
- // the stable Copilot ready marker (the remaining legacy provider
204
- // with a startup-prompt handler) keeps the replay focused on the
205
- // single-lock transaction instead of burning the provider's
206
- // bounded startup-prompt polling interval on an unobservable
207
- // empty screen.
208
- text: crate::provider::COPILOT_READY_MARKER.to_string(),
209
- range: r,
210
- })
211
- }
212
- fn query(
213
- &self,
214
- _t: &crate::transport::Target,
215
- _f: crate::transport::PaneField,
216
- ) -> Result<Option<String>, crate::transport::TransportError> {
217
- Ok(None)
218
- }
219
- fn liveness(
220
- &self,
221
- _p: &crate::transport::PaneId,
222
- ) -> Result<crate::model::enums::PaneLiveness, crate::transport::TransportError> {
223
- Ok(crate::model::enums::PaneLiveness::Live)
224
- }
225
- fn list_targets(
226
- &self,
227
- ) -> Result<Vec<crate::transport::PaneInfo>, crate::transport::TransportError> {
228
- let mut panes: Vec<_> = self
229
- .windows
230
- .lock()
231
- .unwrap()
232
- .iter()
233
- .map(|w| crate::transport::PaneInfo {
234
- pane_id: crate::transport::PaneId::new(format!("%{w}")),
235
- session: crate::transport::SessionName::new(&self.session),
236
- window_index: None,
237
- window_name: Some(crate::transport::WindowName::new(w)),
238
- pane_index: None,
239
- tty: None,
240
- current_command: None,
241
- current_path: None,
242
- active: false,
243
- pane_pid: None,
244
- leader_env: std::collections::BTreeMap::new(),
245
- })
246
- .collect();
247
- panes.extend(
248
- self.foreign
249
- .lock()
250
- .unwrap()
251
- .iter()
252
- .map(|(session, window)| crate::transport::PaneInfo {
253
- pane_id: crate::transport::PaneId::new(format!("%{session}-{window}")),
254
- session: crate::transport::SessionName::new(session),
255
- window_index: None,
256
- window_name: Some(crate::transport::WindowName::new(window)),
257
- pane_index: None,
258
- tty: None,
259
- current_command: None,
260
- current_path: None,
261
- active: false,
262
- pane_pid: None,
263
- leader_env: std::collections::BTreeMap::new(),
264
- }),
265
- );
266
- Ok(panes)
267
- }
268
- fn has_session(
269
- &self,
270
- _s: &crate::transport::SessionName,
271
- ) -> Result<bool, crate::transport::TransportError> {
272
- Ok(true)
273
- }
274
- fn list_windows(
275
- &self,
276
- s: &crate::transport::SessionName,
277
- ) -> Result<Vec<crate::transport::WindowName>, crate::transport::TransportError> {
278
- if s.as_str() == self.session {
279
- Ok(self
280
- .windows
281
- .lock()
282
- .unwrap()
283
- .iter()
284
- .map(|w| crate::transport::WindowName::new(w.as_str()))
285
- .collect())
286
- } else {
287
- Ok(Vec::new())
288
- }
289
- }
290
- fn set_session_env(
291
- &self,
292
- _s: &crate::transport::SessionName,
293
- _k: &str,
294
- _v: &str,
295
- ) -> Result<crate::transport::SetEnvOutcome, crate::transport::TransportError> {
296
- Ok(crate::transport::SetEnvOutcome::Applied)
297
- }
298
- fn preserve_session_before_stop(
299
- &self,
300
- session: &crate::transport::SessionName,
301
- targets: &[crate::transport::Target],
302
- ) -> Result<(), crate::transport::TransportError> {
303
- self.stop_preservation
304
- .lock()
305
- .unwrap()
306
- .push((targets.to_vec(), self.killed()));
307
- if self.fail_stop_preservation {
308
- Err(crate::transport::TransportError::TargetNotFound { target: session.as_str().to_string() })
309
- } else {
310
- Ok(())
311
- }
312
- }
313
- fn kill_session(
314
- &self,
315
- _s: &crate::transport::SessionName,
316
- ) -> Result<(), crate::transport::TransportError> {
317
- Ok(())
318
- }
319
- fn kill_window(
320
- &self,
321
- t: &crate::transport::Target,
322
- ) -> Result<(), crate::transport::TransportError> {
323
- let (name, window) = match t {
324
- crate::transport::Target::Pane(p) => (p.as_str().to_string(), None),
325
- crate::transport::Target::SessionWindow { session, window } => (
326
- format!("{}:{}", session.as_str(), window.as_str()),
327
- Some(window.as_str()),
328
- ),
329
- };
330
- self.killed.lock().unwrap().push(name);
331
- if let crate::transport::Target::Pane(pane) = t {
332
- if let Some(window) = pane.as_str().strip_prefix('%') {
333
- self.windows
334
- .lock()
335
- .unwrap()
336
- .retain(|candidate| candidate != window);
337
- self.foreign
338
- .lock()
339
- .unwrap()
340
- .retain(|(session, candidate)| format!("{session}-{candidate}") != window);
341
- }
342
- } else if let Some(window) = window {
343
- self.windows
344
- .lock()
345
- .unwrap()
346
- .retain(|candidate| candidate != window);
347
- }
348
- Ok(())
349
- }
350
- fn attach_session(
351
- &self,
352
- _s: &crate::transport::SessionName,
353
- ) -> Result<crate::transport::AttachOutcome, crate::transport::TransportError> {
354
- Ok(crate::transport::AttachOutcome::Attached)
355
- }
356
- }
357
-
358
- /// 2-agent (alpha, bravo) compiled spec + custom `state.agents` map. session_name = "team-laneateam"
359
- /// (the compiled runtime.session_name). ensure_owner_allowed passes (no team_owner).
360
- fn lanea_ws_agents(agents: serde_json::Value) -> PathBuf {
361
- lanea_ws_agents_at(&temp_ws(), agents)
362
- }
363
-
364
- fn lanea_ws_agents_at(root: &std::path::Path, agents: serde_json::Value) -> PathBuf {
365
- let ws = root.join("laneav2");
366
- std::fs::create_dir_all(ws.join("agents")).unwrap();
367
- std::fs::write(
368
- ws.join("TEAM.md"),
369
- "---\nname: laneateam\nobjective: Lane A v2 probe.\nprovider: codex\n---\n\nteam.\n",
370
- )
371
- .unwrap();
372
- std::fs::write(ws.join("agents").join("alpha.md"), DELEG_ROLE_ALPHA).unwrap();
373
- std::fs::write(ws.join("agents").join("bravo.md"), DELEG_ROLE_BRAVO).unwrap();
374
- let spec = crate::compiler::compile_team(&ws).expect("compile lane-A v2 team");
375
- // Make `alpha` REMOVABLE (golden-valid): compile_team auto-wires EVERY agent into routing/tasks
376
- // (default_assignee + route-<id>.assign_to + task.assignee), but golden remove_agent removes only from
377
- // agents + startup_order then validate_spec RAISES on dangling refs (agents.py:94 / spec.py:341-346) —
378
- // so a routed agent is NOT removable in golden. Re-point the *validated* refs at the STAYING agent
379
- // `bravo`, so removing `alpha` (an unrouted, dynamic-style worker — the real fork->remove case) passes
380
- // validate. (match-block `assignee` lists are not validated, so they may keep referencing alpha.)
381
- let yaml = crate::model::yaml::dumps(&spec)
382
- .replace("default_assignee: \"alpha\"", "default_assignee: \"bravo\"")
383
- .replace("assign_to: \"alpha\"", "assign_to: \"bravo\"")
384
- .replace("assignee: \"alpha\"", "assignee: \"bravo\"");
385
- assert!(
386
- !yaml.contains("default_assignee: \"alpha\""),
387
- "fixture unroute: default_assignee still alpha"
388
- );
389
- assert!(
390
- !yaml.contains("assign_to: \"alpha\""),
391
- "fixture unroute: a routing rule still assign_to alpha"
392
- );
393
- assert!(
394
- !yaml.contains("assignee: \"alpha\""),
395
- "fixture unroute: task still assignee alpha"
396
- );
397
- std::fs::write(ws.join("team.spec.yaml"), yaml).unwrap();
398
- crate::state::persist::save_runtime_state(
399
- &ws,
400
- &json!({ "session_name": "team-laneateam", "agents": agents }),
401
- )
402
- .unwrap();
403
- ws
404
- }
405
-
406
- /// SINGLE-worker compiled spec (alpha only). Removing alpha leaves `agents: []` -> validate_spec FAILS
407
- /// ("/agents: must be a non-empty list", spec.rs:273) -> a deterministic IN-TRY mid-remove failure that
408
- /// drives the rollback path (golden agents.py:110 except).
409
- fn lanea_one_agent_ws(alpha_status: &str) -> PathBuf {
410
- let ws = temp_ws().join("lanea1");
411
- std::fs::create_dir_all(ws.join("agents")).unwrap();
412
- std::fs::write(
413
- ws.join("TEAM.md"),
414
- "---\nname: laneateam\nobjective: Lane A one-agent probe.\nprovider: codex\n---\n\nteam.\n",
415
- )
416
- .unwrap();
417
- std::fs::write(ws.join("agents").join("alpha.md"), DELEG_ROLE_ALPHA).unwrap();
418
- let spec = crate::compiler::compile_team(&ws).expect("compile 1-agent team");
419
- std::fs::write(ws.join("team.spec.yaml"), crate::model::yaml::dumps(&spec)).unwrap();
420
- crate::state::persist::save_runtime_state(&ws, &json!({ "session_name": "team-laneateam", "agents": { "alpha": { "status": alpha_status, "provider": "fake", "window": "alpha" } } })).unwrap();
421
- ws
422
- }
423
-
424
- #[test]
425
- fn stop_session_preservation_runs_before_kill_and_failure_preserves_worker_state() {
426
- for fail in [false, true] {
427
- let ws = lanea_one_agent_ws("running");
428
- let mut tx = LaneTransport::new("team-laneateam", &["alpha"]);
429
- tx.fail_stop_preservation = fail;
430
- let result = stop_agent_with_transport(&ws, &aid("alpha"), None, &tx);
431
- let calls = tx.stop_preservation.lock().unwrap();
432
- assert_eq!(calls.len(), 1);
433
- assert_eq!(calls[0].1, Vec::<String>::new(), "preserve must precede all worker kills");
434
- assert_eq!(calls[0].0, vec![crate::transport::Target::Pane(crate::transport::PaneId::new("%alpha"))]);
435
- let state = crate::state::persist::load_runtime_state(&ws).unwrap();
436
- if fail {
437
- assert!(result.is_err());
438
- assert!(tx.killed().is_empty());
439
- assert_eq!(state["agents"]["alpha"]["status"], "running");
440
- } else {
441
- assert!(result.unwrap().stopped);
442
- assert_eq!(tx.killed(), vec!["%alpha".to_string()]);
443
- assert_eq!(state["agents"]["alpha"]["status"], "stopped");
444
- }
445
- }
446
- }
447
-
448
- fn selected_spec_path(ws: &std::path::Path) -> std::path::PathBuf {
449
- crate::state::selector::resolve_active_team(
450
- ws,
451
- None,
452
- crate::state::selector::SelectorMode::RequireSpec,
453
- )
454
- .unwrap()
455
- .spec_workspace
456
- .unwrap_or_else(|| ws.to_path_buf())
457
- .join("team.spec.yaml")
458
- }
459
-
460
- fn remove_agent_from_fixture_spec(ws: &std::path::Path, agent_id: &str) {
461
- let path = selected_spec_path(ws);
462
- let spec = crate::model::yaml::loads(&std::fs::read_to_string(&path).unwrap()).unwrap();
463
- let removed = crate::lifecycle::restart::remove::spec_without_agent(&spec, &aid(agent_id));
464
- std::fs::write(path, crate::model::yaml::dumps(&removed)).unwrap();
465
- }
466
-
467
- fn remove_agent_from_fixture_state(ws: &std::path::Path, agent_id: &str) {
468
- let mut state = crate::state::persist::load_runtime_state(ws).unwrap();
469
- state
470
- .get_mut("agents")
471
- .and_then(serde_json::Value::as_object_mut)
472
- .unwrap()
473
- .remove(agent_id);
474
- crate::state::persist::save_runtime_state_with_deleted_agents(ws, &state, &[agent_id]).unwrap();
475
- }
476
-
477
- #[test]
478
- fn force_remove_reconciles_all_seat_quadrants_without_cross_team_same_name_kill() {
479
- for quadrant in ["state-only", "spec-only", "physical-only", "mixed"] {
480
- let ws = lanea_ws_agents(json!({
481
- "alpha": { "status": "stopped", "provider": "fake", "window": "alpha" },
482
- "bravo": { "status": "running", "provider": "fake", "window": "bravo" }
483
- }));
484
- let local_physical = matches!(quadrant, "physical-only");
485
- let tx = LaneTransport::new(
486
- "team-laneateam",
487
- if local_physical { &["alpha"][..] } else { &[] },
488
- );
489
- tx.add_foreign("team-other", "alpha");
490
- match quadrant {
491
- "state-only" => remove_agent_from_fixture_spec(&ws, "alpha"),
492
- "spec-only" => remove_agent_from_fixture_state(&ws, "alpha"),
493
- "physical-only" => {
494
- remove_agent_from_fixture_spec(&ws, "alpha");
495
- remove_agent_from_fixture_state(&ws, "alpha");
496
- }
497
- "mixed" => {}
498
- _ => unreachable!(),
499
- }
500
-
501
- for attempt in 0..2 {
502
- let result = remove_agent_with_transport(&ws, &aid("alpha"), true, true, None, &tx);
503
- assert!(
504
- matches!(result, Ok(RemoveAgentOutcome::Removed { .. })),
505
- "{quadrant} force-remove attempt {attempt} must be idempotent: {result:?}"
506
- );
507
- }
508
- let state = crate::state::persist::load_runtime_state(&ws).unwrap();
509
- assert!(
510
- state["agents"].get("alpha").is_none(),
511
- "{quadrant}: state absent"
512
- );
513
- let spec =
514
- crate::model::yaml::loads(&std::fs::read_to_string(selected_spec_path(&ws)).unwrap())
515
- .unwrap();
516
- assert!(
517
- spec.get("agents")
518
- .and_then(crate::model::yaml::Value::as_list)
519
- .is_none_or(|agents| agents.iter().all(|agent| {
520
- agent.get("id").and_then(crate::model::yaml::Value::as_str) != Some("alpha")
521
- })),
522
- "{quadrant}: spec absent"
523
- );
524
- let live = crate::transport::Transport::list_targets(&tx).unwrap();
525
- assert!(
526
- live.iter()
527
- .all(|pane| pane.session.as_str() != "team-laneateam"
528
- || pane
529
- .window_name
530
- .as_ref()
531
- .is_none_or(|window| window.as_str() != "alpha")),
532
- "{quadrant}: selected team physical absent"
533
- );
534
- assert!(
535
- live.iter().any(|pane| pane.session.as_str() == "team-other"
536
- && pane
537
- .window_name
538
- .as_ref()
539
- .is_some_and(|window| window.as_str() == "alpha")),
540
- "{quadrant}: cross-team same-name pane must survive"
541
- );
542
- assert!(
543
- !tx.killed().iter().any(|pane| pane == "%team-other-alpha"),
544
- "{quadrant}: cross-team pane must never be selected"
545
- );
546
- }
547
- }
548
-
549
- #[test]
550
- fn remove_persists_retired_tombstone_and_explicit_readd_clears_it() {
551
- let ws = lanea_ws_agents(json!({
552
- "alpha": { "status": "stopped", "provider": "fake", "window": "alpha" },
553
- "bravo": { "status": "running", "provider": "fake", "window": "bravo" }
554
- }));
555
- let mut seeded = crate::state::persist::load_runtime_state(&ws).unwrap();
556
- seeded["team_key"] = json!("laneateam");
557
- seeded["active_team_key"] = json!("laneateam");
558
- let mut nested = crate::state::projection::compact_team_state(&seeded);
559
- nested["status"] = json!("alive");
560
- seeded["teams"] = json!({
561
- "laneateam": nested,
562
- "sibling": {
563
- "team_key": "sibling",
564
- "status": "shutdown",
565
- "agents": {},
566
- "agent_lifecycle": {
567
- "alpha": {
568
- "state": "retired",
569
- "changed_at": "2026-07-20T00:00:00Z",
570
- "reason": "sibling retirement"
571
- }
572
- }
573
- }
574
- });
575
- crate::state::persist::save_runtime_state(&ws, &seeded).unwrap();
576
- let stale_tick = crate::state::projection::select_runtime_state(&ws, Some("laneateam"))
577
- .expect("capture the coordinator projection from before remove");
578
- let tx = LaneTransport::new("team-laneateam", &[]);
579
- let role = ws.join("agents").join("alpha.md");
580
-
581
- remove_agent_with_transport(&ws, &aid("alpha"), true, true, None, &tx).unwrap();
582
- let removed: serde_json::Value = serde_json::from_str(
583
- &std::fs::read_to_string(crate::state::persist::runtime_state_path(&ws)).unwrap(),
584
- )
585
- .unwrap();
586
- assert_eq!(
587
- removed["teams"]["laneateam"]["agent_lifecycle"]["alpha"]["state"], "retired",
588
- "the first successful remove must directly persist the canonical tombstone"
589
- );
590
- assert!(
591
- removed["teams"]["laneateam"]["agents"]
592
- .get("alpha")
593
- .is_none(),
594
- "the first successful remove must directly delete the canonical agent row"
595
- );
596
- crate::state::repository::StateRepository::new(&ws)
597
- .save(
598
- crate::state::repository::StateWriteIntent::CoordinatorTick {
599
- team_key: "laneateam",
600
- },
601
- &stale_tick,
602
- )
603
- .unwrap();
604
- let after_stale_tick: serde_json::Value = serde_json::from_str(
605
- &std::fs::read_to_string(crate::state::persist::runtime_state_path(&ws)).unwrap(),
606
- )
607
- .unwrap();
608
- assert_eq!(
609
- after_stale_tick["teams"]["laneateam"]["agent_lifecycle"]["alpha"]["state"], "retired",
610
- "a stale coordinator save must not erase the first remove's tombstone"
611
- );
612
- assert!(
613
- after_stale_tick["teams"]["laneateam"]["agents"]
614
- .get("alpha")
615
- .is_none(),
616
- "a stale coordinator save must not resurrect the first removed agent"
617
- );
618
-
619
- crate::lifecycle::add_agent_with_transport(&ws, &aid("alpha"), &role, false, None, &tx)
620
- .unwrap();
621
- let readded = crate::state::persist::load_runtime_state(&ws).unwrap();
622
- assert!(
623
- readded["teams"]["laneateam"]["agent_lifecycle"]
624
- .get("alpha")
625
- .is_none(),
626
- "explicit re-add must consume the retired tombstone"
627
- );
628
- assert!(readded["teams"]["laneateam"]["agents"]
629
- .get("alpha")
630
- .is_some());
631
- assert_eq!(
632
- readded["teams"]["sibling"]["agent_lifecycle"]["alpha"]["state"], "retired",
633
- "selected-team re-add must not clear a sibling team's same-id retirement"
634
- );
635
- }
636
-
637
- /// #391: remove-agent keeps the user's role file and leaves a retired
638
- /// tombstone. `add-agent --force` without `--role-file` must re-adopt that
639
- /// file instead of refusing "role file already exists" forever.
640
- #[test]
641
- #[serial_test::serial(env)]
642
- fn issue391_force_readd_adopts_the_role_file_a_removed_seat_left_behind() {
643
- let ws = lanea_ws_agents(json!({
644
- "alpha": { "status": "stopped", "provider": "fake", "window": "alpha" },
645
- "bravo": { "status": "running", "provider": "fake", "window": "bravo" }
646
- }));
647
- let mut seeded = crate::state::persist::load_runtime_state(&ws).unwrap();
648
- seeded["team_key"] = json!("laneateam");
649
- seeded["active_team_key"] = json!("laneateam");
650
- let mut nested = crate::state::projection::compact_team_state(&seeded);
651
- nested["status"] = json!("alive");
652
- seeded["teams"] = json!({ "laneateam": nested });
653
- crate::state::persist::save_runtime_state(&ws, &seeded).unwrap();
654
- let tx = LaneTransport::new("team-laneateam", &[]);
655
- let role = ws.join("agents").join("alpha.md");
656
- let load = || crate::state::persist::load_runtime_state(&ws).unwrap();
657
- let add = |patch: &crate::lifecycle::role_config::RoleConfigPatch, force: bool| {
658
- crate::lifecycle::role_config::add_agent_from_role_with_transport(
659
- &ws,
660
- &aid("alpha"),
661
- None,
662
- patch,
663
- force,
664
- &tx,
665
- )
666
- };
667
- let same = crate::lifecycle::role_config::RoleConfigPatch {
668
- provider: Some("fake".into()),
669
- bypass: Some(false),
670
- ..Default::default()
671
- };
672
-
673
- remove_agent_with_transport(&ws, &aid("alpha"), true, true, None, &tx).unwrap();
674
- assert_eq!(std::fs::read_to_string(&role).unwrap(), DELEG_ROLE_ALPHA);
675
- assert_eq!(
676
- load()["teams"]["laneateam"]["agent_lifecycle"]["alpha"]["state"],
677
- "retired"
678
- );
679
-
680
- let refused = add(&same, false).unwrap_err().to_string();
681
- assert!(
682
- refused.contains("role file already exists") && refused.contains("--force"),
683
- "without --force the refusal names a real way out: {refused}"
684
- );
685
- assert!(load()["teams"]["laneateam"]["agents"]
686
- .get("alpha")
687
- .is_none());
688
-
689
- add(&same, true).unwrap_or_else(|error| panic!("force re-add failed: {error}"));
690
- let readded = load();
691
- assert!(
692
- readded["teams"]["laneateam"]["agent_lifecycle"]
693
- .get("alpha")
694
- .is_none(),
695
- "force re-add consumes the retired tombstone"
696
- );
697
- assert!(readded["teams"]["laneateam"]["agents"]
698
- .get("alpha")
699
- .is_some());
700
- assert_eq!(
701
- std::fs::read_to_string(&role).unwrap(),
702
- DELEG_ROLE_ALPHA,
703
- "equal CLI values keep the adopted file byte-identical"
704
- );
705
-
706
- // A second removal, then --force with a different model: CLI values
707
- // override the adopted frontmatter and the role body is kept.
708
- remove_agent_with_transport(&ws, &aid("alpha"), true, true, None, &tx).unwrap();
709
- let changed = crate::lifecycle::role_config::RoleConfigPatch {
710
- model: Some("gpt-5.4".into()),
711
- ..same
712
- };
713
- add(&changed, true)
714
- .unwrap_or_else(|error| panic!("force re-add with override failed: {error}"));
715
- let (meta, _) = crate::compiler::read_front_matter(&role).unwrap();
716
- assert_eq!(
717
- meta.get("model")
718
- .and_then(crate::model::yaml::Value::as_str),
719
- Some("gpt-5.4")
720
- );
721
- assert!(std::fs::read_to_string(&role).unwrap().contains("Alpha."));
722
- assert!(load()["teams"]["laneateam"]["agents"]
723
- .get("alpha")
724
- .is_some());
725
- }
726
-
727
- /// Cross-product RED (verifier, slice2b authority leak): the FAILURE dimension
728
- /// (a stale writer whose incoming projection predates a sibling retirement) x the
729
- /// BOUNDARY dimension (a sibling team carrying the SAME agent id). The tracked
730
- /// `remove_persists_..._readd_clears_it` sibling assertion covers only the
731
- /// non-stale corner (sibling tombstone already current in the add's input); it
732
- /// does NOT exercise an incoming sibling projection captured BEFORE the sibling
733
- /// retirement. topology-authority is keyed by bare `agent_id` with no team
734
- /// dimension (repository.rs:277-283 drops team_key; persist.rs iterates every
735
- /// sibling team with the same global id set), so an explicit AddAgent(alpha) in
736
- /// team A exempts alpha in team B too and a stale incoming resurrects B's alpha /
737
- /// erases B's retirement tombstone. Red at da11f98c: teamB.alpha lifecycle Null.
738
- #[test]
739
- fn add_agent_authority_must_not_cross_team_erase_sibling_same_id_retirement() {
740
- // Disk latest: team A alive with alpha; team B alpha ABSENT + retired.
741
- let ws = lanea_ws_agents(json!({
742
- "alpha": { "status": "running", "provider": "fake", "window": "alpha" },
743
- "bravo": { "status": "running", "provider": "fake", "window": "bravo" }
744
- }));
745
- let mut latest = crate::state::persist::load_runtime_state(&ws).unwrap();
746
- latest["team_key"] = json!("laneateam");
747
- latest["active_team_key"] = json!("laneateam");
748
- let mut nested_a = crate::state::projection::compact_team_state(&latest);
749
- nested_a["status"] = json!("alive");
750
- latest["teams"] = json!({
751
- "laneateam": nested_a,
752
- "sibling": {
753
- "team_key": "sibling",
754
- "status": "alive",
755
- "agents": {},
756
- "agent_lifecycle": {
757
- "alpha": {
758
- "state": "retired",
759
- "changed_at": "2026-07-21T00:00:00Z",
760
- "reason": "sibling retirement (newer than the stale incoming)"
761
- }
762
- }
763
- }
764
- });
765
- crate::state::persist::save_runtime_state(&ws, &latest).unwrap();
766
-
767
- // Incoming STALE root: captured BEFORE team B retired alpha, so its sibling
768
- // entry still carries alpha ACTIVE with no tombstone. A concurrent explicit
769
- // AddAgent(alpha) in team A carries this whole stale multi-team projection.
770
- let mut incoming_stale = latest.clone();
771
- incoming_stale["teams"]["sibling"] = json!({
772
- "team_key": "sibling",
773
- "status": "alive",
774
- "agents": { "alpha": { "status": "running", "provider": "fake", "window": "alpha" } },
775
- "agent_lifecycle": {}
776
- });
777
-
778
- crate::state::repository::StateRepository::new(&ws)
779
- .save(
780
- crate::state::repository::StateWriteIntent::AddAgent {
781
- team_key: "laneateam",
782
- agent_id: "alpha",
783
- },
784
- &incoming_stale,
785
- )
786
- .unwrap();
787
-
788
- let after: serde_json::Value = serde_json::from_str(
789
- &std::fs::read_to_string(crate::state::persist::runtime_state_path(&ws)).unwrap(),
790
- )
791
- .unwrap();
792
- // The AddAgent authority is scoped to team A's alpha ONLY; team B's newer
793
- // same-id retirement must survive (the stale incoming must not resurrect it).
794
- assert_eq!(
795
- after["teams"]["sibling"]["agent_lifecycle"]["alpha"]["state"],
796
- json!("retired"),
797
- "selected-team AddAgent authority must not cross team boundary by bare agent id: \
798
- team B's newer same-id retirement was erased by team A's stale re-add"
799
- );
800
- assert!(
801
- after["teams"]["sibling"]["agents"].get("alpha").is_none(),
802
- "a stale incoming must not resurrect the sibling team's retired same-id agent"
803
- );
804
- }
805
-
806
- /// Identity-source boundary (verifier, slice2b authority fix new adjudication
807
- /// face, same family as slice1 empty-current): the legacy top-level scope anchor
808
- /// now prefers `active_team_key`. Verify it does not over-exempt / under-protect
809
- /// when `active_team_key` is a NON-EMPTY but TERMINAL / mismatched value (points
810
- /// at a team not present in `teams`). The AddAgent authority is (laneateam,
811
- /// alpha); with a ghost active_team_key, the top-level filter must resolve NO
812
- /// exemption for the ghost, so a real retirement anywhere is still protected —
813
- /// the anchor must not silently widen authority to a bare id under a dangling
814
- /// active_team_key (that would be the empty-current forgery shape at slice1).
815
- #[test]
816
- fn terminal_active_team_key_does_not_widen_topology_authority_to_bare_id() {
817
- // Disk latest: laneateam alive with alpha; sibling alpha ABSENT + retired.
818
- let ws = lanea_ws_agents(json!({
819
- "alpha": { "status": "running", "provider": "fake", "window": "alpha" },
820
- "bravo": { "status": "running", "provider": "fake", "window": "bravo" }
821
- }));
822
- let mut latest = crate::state::persist::load_runtime_state(&ws).unwrap();
823
- latest["team_key"] = json!("laneateam");
824
- latest["active_team_key"] = json!("laneateam");
825
- let mut nested_a = crate::state::projection::compact_team_state(&latest);
826
- nested_a["status"] = json!("alive");
827
- latest["teams"] = json!({
828
- "laneateam": nested_a,
829
- "sibling": {
830
- "team_key": "sibling",
831
- "status": "alive",
832
- "agents": {},
833
- "agent_lifecycle": {
834
- "alpha": { "state": "retired", "changed_at": "2026-07-21T00:00:00Z", "reason": "sibling" }
835
- }
836
- }
837
- });
838
- crate::state::persist::save_runtime_state(&ws, &latest).unwrap();
839
-
840
- // Incoming STALE root whose active_team_key points at a GHOST team not in
841
- // `teams`, and whose sibling entry is the pre-retire (alpha active) shape.
842
- let mut incoming_stale = latest.clone();
843
- incoming_stale["active_team_key"] = json!("ghostteam-does-not-exist");
844
- incoming_stale["teams"]["sibling"] = json!({
845
- "team_key": "sibling",
846
- "status": "alive",
847
- "agents": { "alpha": { "status": "running", "provider": "fake", "window": "alpha" } },
848
- "agent_lifecycle": {}
849
- });
850
-
851
- crate::state::repository::StateRepository::new(&ws)
852
- .save(
853
- crate::state::repository::StateWriteIntent::AddAgent {
854
- team_key: "laneateam",
855
- agent_id: "alpha",
856
- },
857
- &incoming_stale,
858
- )
859
- .unwrap();
860
-
861
- let after: serde_json::Value = serde_json::from_str(
862
- &std::fs::read_to_string(crate::state::persist::runtime_state_path(&ws)).unwrap(),
863
- )
864
- .unwrap();
865
- // A dangling active_team_key must not widen the (laneateam, alpha) authority
866
- // into a bare `alpha` exemption that reaches the sibling: sibling stays
867
- // retired, not resurrected.
868
- assert_eq!(
869
- after["teams"]["sibling"]["agent_lifecycle"]["alpha"]["state"],
870
- json!("retired"),
871
- "a terminal/ghost active_team_key must not widen topology authority to a bare id \
872
- and erase the sibling's same-id retirement"
873
- );
874
- assert!(
875
- after["teams"]["sibling"]["agents"].get("alpha").is_none(),
876
- "a terminal active_team_key must not let a stale incoming resurrect the sibling agent"
877
- );
878
- }
879
-
880
- /// Cross-product cell (verifier, slice2b current-alias fix): the `current`
881
- /// physical alias dimension x the sibling same-id retirement dimension. The
882
- /// reset fix routes `team == "current"` authority through `top_level_team`
883
- /// (active_team_key). This pins that the alias branch does NOT leak that
884
- /// active-team authority into a REAL sibling that merely shares the agent id:
885
- /// a `current` alias entry (= the active team's physical projection) plus a
886
- /// distinct sibling team both carrying `alpha`, sibling retired, stale incoming
887
- /// resurrecting sibling alpha. The current-alias authority must clear only the
888
- /// active team's own alpha, never the sibling's newer retirement.
889
- #[test]
890
- fn current_alias_authority_does_not_leak_into_real_sibling_same_id_retirement() {
891
- let ws = lanea_ws_agents(json!({
892
- "alpha": { "status": "running", "provider": "fake", "window": "alpha" },
893
- "bravo": { "status": "running", "provider": "fake", "window": "bravo" }
894
- }));
895
- let mut latest = crate::state::persist::load_runtime_state(&ws).unwrap();
896
- latest["team_key"] = json!("laneateam");
897
- latest["active_team_key"] = json!("laneateam");
898
- let mut nested_a = crate::state::projection::compact_team_state(&latest);
899
- nested_a["status"] = json!("alive");
900
- // `current` is the physical alias of the active team (laneateam); a REAL
901
- // sibling team also carries alpha, retired and newer than the stale incoming.
902
- latest["teams"] = json!({
903
- "laneateam": nested_a.clone(),
904
- "current": nested_a,
905
- "sibling": {
906
- "team_key": "sibling",
907
- "status": "alive",
908
- "agents": {},
909
- "agent_lifecycle": {
910
- "alpha": { "state": "retired", "changed_at": "2026-07-21T00:00:00Z", "reason": "sibling" }
911
- }
912
- }
913
- });
914
- crate::state::persist::save_runtime_state(&ws, &latest).unwrap();
915
-
916
- let mut incoming_stale = latest.clone();
917
- incoming_stale["teams"]["sibling"] = json!({
918
- "team_key": "sibling",
919
- "status": "alive",
920
- "agents": { "alpha": { "status": "running", "provider": "fake", "window": "alpha" } },
921
- "agent_lifecycle": {}
922
- });
923
-
924
- crate::state::repository::StateRepository::new(&ws)
925
- .save(
926
- crate::state::repository::StateWriteIntent::AddAgent {
927
- team_key: "laneateam",
928
- agent_id: "alpha",
929
- },
930
- &incoming_stale,
931
- )
932
- .unwrap();
933
-
934
- let after: serde_json::Value = serde_json::from_str(
935
- &std::fs::read_to_string(crate::state::persist::runtime_state_path(&ws)).unwrap(),
936
- )
937
- .unwrap();
938
- // The current-alias authority is the ACTIVE team's; it must not reach the
939
- // real sibling that only shares the id.
940
- assert_eq!(
941
- after["teams"]["sibling"]["agent_lifecycle"]["alpha"]["state"],
942
- json!("retired"),
943
- "current-alias authority must not leak into a real sibling's same-id retirement"
944
- );
945
- assert!(
946
- after["teams"]["sibling"]["agents"].get("alpha").is_none(),
947
- "a stale incoming must not resurrect the real sibling's retired same-id agent \
948
- via the current-alias authority path"
949
- );
950
- }
951
-
952
- const CHARLIE_ROLE: &str = "---\nname: charlie\nrole: Charlie Worker\nprovider: fake\nmodel: fake\nauth_mode: subscription\ndangerously_skip_permissions: false\ntools:\n - mcp_team\n---\n\nCharlie.\n";
953
-
954
- struct HermeticTestEnv {
955
- root: std::path::PathBuf,
956
- }
957
-
958
- impl HermeticTestEnv {
959
- fn enter(tag: &str) -> Self {
960
- let root = temp_ws().join(format!("hermetic-{tag}"));
961
- std::fs::create_dir_all(&root).unwrap();
962
- Self { root }
963
- }
964
-
965
- fn workspace_root(&self) -> &std::path::Path {
966
- &self.root
967
- }
968
- }
969
-
970
- impl Drop for HermeticTestEnv {
971
- fn drop(&mut self) {
972
- let _ = std::fs::remove_dir_all(&self.root);
973
- }
974
- }
975
-
976
- struct ForceRecreateFailureGuard(Option<String>);
977
-
978
- impl ForceRecreateFailureGuard {
979
- fn after_spawn(reason: &str) -> Self {
980
- const KEY: &str = "TEAM_AGENT_TEST_FAIL_FORCE_RECREATE_AFTER_SPAWN";
981
- let previous = std::env::var(KEY).ok();
982
- unsafe { std::env::set_var(KEY, reason) };
983
- Self(previous)
984
- }
985
- }
986
-
987
- impl Drop for ForceRecreateFailureGuard {
988
- fn drop(&mut self) {
989
- const KEY: &str = "TEAM_AGENT_TEST_FAIL_FORCE_RECREATE_AFTER_SPAWN";
990
- unsafe {
991
- if let Some(previous) = self.0.take() {
992
- std::env::set_var(KEY, previous);
993
- } else {
994
- std::env::remove_var(KEY);
995
- }
996
- }
997
- }
998
- }
999
-
1000
- fn seed_agent_health(ws: &std::path::Path, team: &str, agent: &str, status: &str) {
1001
- let store = crate::message_store::MessageStore::open(ws).unwrap();
1002
- let conn = crate::db::schema::open_db(store.db_path()).unwrap();
1003
- conn.execute(
1004
- "insert into agent_health(owner_team_id, agent_id, status, last_output_at, context_usage_pct, current_task_id, updated_at) values (?1, ?2, ?3, 'before-output', 37, 'task-before', '2026-07-19T00:00:00Z')",
1005
- rusqlite::params![team, agent, status],
1006
- )
1007
- .unwrap();
1008
- }
1009
-
1010
- fn seed_charlie(ws: &std::path::Path, tx: &LaneTransport) -> std::path::PathBuf {
1011
- let role_dir = ws.join("role-masters");
1012
- std::fs::create_dir_all(&role_dir).unwrap();
1013
- let role = role_dir.join("charlie.md");
1014
- std::fs::write(&role, CHARLIE_ROLE).unwrap();
1015
- crate::lifecycle::add_agent_with_transport(ws, &aid("charlie"), &role, false, None, tx)
1016
- .unwrap();
1017
- role
1018
- }
1019
-
1020
- #[test]
1021
- #[serial_test::serial(env)]
1022
- fn force_recreate_is_one_lock_transaction_for_all_seat_quadrants_and_rolls_back_failure() {
1023
- for quadrant in ["state-only", "spec-only", "physical-only", "mixed"] {
1024
- let ws = lanea_ws_agents(json!({
1025
- "alpha": { "status": "stopped", "provider": "fake", "window": "alpha" },
1026
- "bravo": { "status": "running", "provider": "fake", "window": "bravo" }
1027
- }));
1028
- let tx = LaneTransport::new("team-laneateam", &[]);
1029
- seed_healthy_coordinator(&ws);
1030
- let role = seed_charlie(&ws, &tx);
1031
- match quadrant {
1032
- "state-only" => {
1033
- remove_agent_from_fixture_spec(&ws, "charlie");
1034
- crate::transport::Transport::kill_pane(
1035
- &tx,
1036
- &crate::transport::PaneId::new("%charlie"),
1037
- )
1038
- .unwrap();
1039
- }
1040
- "spec-only" => {
1041
- remove_agent_from_fixture_state(&ws, "charlie");
1042
- crate::transport::Transport::kill_pane(
1043
- &tx,
1044
- &crate::transport::PaneId::new("%charlie"),
1045
- )
1046
- .unwrap();
1047
- }
1048
- "physical-only" => {
1049
- remove_agent_from_fixture_spec(&ws, "charlie");
1050
- remove_agent_from_fixture_state(&ws, "charlie");
1051
- }
1052
- "mixed" => {
1053
- crate::transport::Transport::kill_pane(
1054
- &tx,
1055
- &crate::transport::PaneId::new("%charlie"),
1056
- )
1057
- .unwrap();
1058
- }
1059
- _ => unreachable!(),
1060
- }
1061
- crate::lifecycle::add_agent_with_transport_force(
1062
- &ws,
1063
- &aid("charlie"),
1064
- &role,
1065
- false,
1066
- None,
1067
- true,
1068
- &tx,
1069
- )
1070
- .unwrap_or_else(|error| panic!("{quadrant} force-recreate failed: {error}"));
1071
- let state = crate::state::persist::load_runtime_state(&ws).unwrap();
1072
- assert!(
1073
- state["agents"].get("charlie").is_some(),
1074
- "{quadrant}: state restored"
1075
- );
1076
- assert!(
1077
- state["agent_lifecycle"].get("charlie").is_none(),
1078
- "{quadrant}: successful force-recreate consumes its interim tombstone"
1079
- );
1080
- let spec_text = std::fs::read_to_string(selected_spec_path(&ws)).unwrap();
1081
- assert_eq!(
1082
- spec_text.matches("id: \"charlie\"").count(),
1083
- 1,
1084
- "{quadrant}: exactly one spec row"
1085
- );
1086
- assert_eq!(
1087
- crate::transport::Transport::list_targets(&tx)
1088
- .unwrap()
1089
- .iter()
1090
- .filter(|pane| pane.session.as_str() == "team-laneateam"
1091
- && pane
1092
- .window_name
1093
- .as_ref()
1094
- .is_some_and(|window| window.as_str() == "charlie"))
1095
- .count(),
1096
- 1,
1097
- "{quadrant}: exactly one live pane"
1098
- );
1099
- assert!(role.exists(), "{quadrant}: external role preserved");
1100
- }
1101
-
1102
- let ws = lanea_ws_agents(json!({
1103
- "alpha": { "status": "stopped", "provider": "fake", "window": "alpha" },
1104
- "bravo": { "status": "running", "provider": "fake", "window": "bravo" }
1105
- }));
1106
- let tx = LaneTransport::new("team-laneateam", &[]);
1107
- seed_healthy_coordinator(&ws);
1108
- let role = seed_charlie(&ws, &tx);
1109
- let missing = ws.join("role-masters").join("missing-charlie.md");
1110
- let error = crate::lifecycle::add_agent_with_transport_force(
1111
- &ws,
1112
- &aid("charlie"),
1113
- &missing,
1114
- false,
1115
- None,
1116
- true,
1117
- &tx,
1118
- )
1119
- .expect_err("missing replacement role must fail and roll back");
1120
- assert!(error.to_string().contains("role file not found"));
1121
- let state = crate::state::persist::load_runtime_state(&ws).unwrap();
1122
- assert!(
1123
- state["agents"].get("charlie").is_some(),
1124
- "rollback restores state"
1125
- );
1126
- assert!(
1127
- state["agent_lifecycle"].get("charlie").is_none(),
1128
- "preflight failure must not create a retirement tombstone"
1129
- );
1130
- assert!(
1131
- std::fs::read_to_string(selected_spec_path(&ws))
1132
- .unwrap()
1133
- .contains("id: \"charlie\""),
1134
- "rollback restores spec"
1135
- );
1136
- assert!(
1137
- crate::transport::Transport::list_targets(&tx)
1138
- .unwrap()
1139
- .iter()
1140
- .any(|pane| {
1141
- pane.session.as_str() == "team-laneateam"
1142
- && pane
1143
- .window_name
1144
- .as_ref()
1145
- .is_some_and(|window| window.as_str() == "charlie")
1146
- }),
1147
- "rollback restores physical seat"
1148
- );
1149
- assert!(role.exists(), "rollback never mutates external role source");
1150
- }
1151
-
1152
- #[test]
1153
- #[serial_test::serial(env)]
1154
- fn force_recreate_post_consumption_failure_restores_before_tuple_and_health() {
1155
- let hermetic = HermeticTestEnv::enter("force-recreate-rollback");
1156
- let ws = lanea_ws_agents_at(
1157
- hermetic.workspace_root(),
1158
- json!({
1159
- "alpha": { "status": "stopped", "provider": "fake", "window": "alpha" },
1160
- "bravo": { "status": "running", "provider": "fake", "window": "bravo" }
1161
- }),
1162
- );
1163
- let tx = LaneTransport::new("team-laneateam", &[]);
1164
- seed_healthy_coordinator(&ws);
1165
- let role = seed_charlie(&ws, &tx);
1166
- seed_agent_health(&ws, "team-laneateam", "charlie", "IDLE");
1167
- seed_agent_health(&ws, "team-other", "charlie", "WORKING");
1168
- let selected_health = crate::db::agent_health_capture::select_agent_health(
1169
- &ws,
1170
- "team-laneateam",
1171
- &aid("charlie"),
1172
- )
1173
- .unwrap();
1174
- let sibling_health =
1175
- crate::db::agent_health_capture::select_agent_health(&ws, "team-other", &aid("charlie"))
1176
- .unwrap();
1177
- let _failure = ForceRecreateFailureGuard::after_spawn("post-consumption seam");
1178
- let error = crate::lifecycle::add_agent_with_transport_force(
1179
- &ws,
1180
- &aid("charlie"),
1181
- &role,
1182
- false,
1183
- None,
1184
- true,
1185
- &tx,
1186
- )
1187
- .expect_err("post-spawn failure must roll back a consumed seat");
1188
- assert!(error.to_string().contains("post-consumption seam"));
1189
- assert_eq!(
1190
- tx.killed()
1191
- .iter()
1192
- .filter(|pane| pane.as_str() == "%charlie")
1193
- .count(),
1194
- 2,
1195
- "rollback kills the old pane during remove and the transaction-created pane before restore"
1196
- );
1197
- assert_eq!(
1198
- crate::transport::Transport::list_targets(&tx)
1199
- .unwrap()
1200
- .iter()
1201
- .filter(|pane| pane.session.as_str() == "team-laneateam"
1202
- && pane
1203
- .window_name
1204
- .as_ref()
1205
- .is_some_and(|window| window.as_str() == "charlie"))
1206
- .count(),
1207
- 1,
1208
- "rollback restores exactly one physical seat; error={error}; spawns={:?}; killed={:?}",
1209
- tx.spawns(),
1210
- tx.killed(),
1211
- );
1212
- assert_eq!(
1213
- crate::db::agent_health_capture::select_agent_health(
1214
- &ws,
1215
- "team-laneateam",
1216
- &aid("charlie"),
1217
- )
1218
- .unwrap(),
1219
- selected_health,
1220
- "rollback restores the selected team's captured health row"
1221
- );
1222
- assert_eq!(
1223
- crate::db::agent_health_capture::select_agent_health(&ws, "team-other", &aid("charlie"),)
1224
- .unwrap(),
1225
- sibling_health,
1226
- "rollback never changes the sibling team's same-agent health row"
1227
- );
1228
- let state = crate::state::persist::load_runtime_state(&ws).unwrap();
1229
- assert!(
1230
- state["agent_lifecycle"].get("charlie").is_none(),
1231
- "post-consumption rollback restores the before-state without a new tombstone"
1232
- );
1233
- }
1234
-
1235
- #[test]
1236
- fn force_remove_scopes_agent_health_to_canonical_team_key() {
1237
- let hermetic = HermeticTestEnv::enter("force-remove-health-scope");
1238
- let ws = lanea_ws_agents_at(
1239
- hermetic.workspace_root(),
1240
- json!({
1241
- "alpha": { "status": "stopped", "provider": "fake", "window": "alpha" },
1242
- "bravo": { "status": "running", "provider": "fake", "window": "bravo" }
1243
- }),
1244
- );
1245
- let tx = LaneTransport::new("team-laneateam", &[]);
1246
- seed_agent_health(&ws, "team-laneateam", "alpha", "IDLE");
1247
- seed_agent_health(&ws, "team-other", "alpha", "WORKING");
1248
- let sibling_before =
1249
- crate::db::agent_health_capture::select_agent_health(&ws, "team-other", &aid("alpha"))
1250
- .unwrap();
1251
-
1252
- remove_agent_with_transport(&ws, &aid("alpha"), true, true, None, &tx).unwrap();
1253
-
1254
- assert!(crate::db::agent_health_capture::select_agent_health(
1255
- &ws,
1256
- "team-laneateam",
1257
- &aid("alpha"),
1258
- )
1259
- .unwrap()
1260
- .is_none());
1261
- assert_eq!(
1262
- crate::db::agent_health_capture::select_agent_health(&ws, "team-other", &aid("alpha"),)
1263
- .unwrap(),
1264
- sibling_before,
1265
- "force-remove must not delete the sibling owner_team_id row"
1266
- );
1267
- }
1268
-
1269
- /// Rewrite the compiled spec's `context.state_file` (default `team_state.md`) to `name`, so the
1270
- /// rollback team-state path divergence (capture honors spec.context.state_file; restore hardcodes
1271
- /// team_state.md) is observable. Asserts the rewrite took, so a format change can't silently mis-test.
1272
- fn set_context_state_file(ws: &std::path::Path, name: &str) {
1273
- let p = ws.join("team.spec.yaml");
1274
- let text = std::fs::read_to_string(&p).unwrap();
1275
- let replaced = text.replace(
1276
- "state_file: \"team_state.md\"",
1277
- &format!("state_file: \"{name}\""),
1278
- );
1279
- assert_ne!(
1280
- replaced, text,
1281
- "expected to rewrite context.state_file in the compiled spec; got:\n{text}"
1282
- );
1283
- std::fs::write(&p, replaced).unwrap();
1284
- }
1285
-
1286
- /// Fork workspace: source `alpha` (role doc = `alpha_role`) + `bravo`, alpha seeded as a RUNNING
1287
- /// Copilot seat with a captured `session_id` — a fork-capable legacy source — so every refusal comes
1288
- /// from the legacy fork entry itself. Seeded-healthy coordinator (no real daemon).
1289
- /// session_name = "team-laneateam".
1290
- pub(super) fn fork_ws(alpha_role: &str) -> PathBuf {
1291
- let ws = temp_ws().join("forkv2");
1292
- std::fs::create_dir_all(ws.join("agents")).unwrap();
1293
- std::fs::write(
1294
- ws.join("TEAM.md"),
1295
- "---\nname: laneateam\nobjective: Fork v2 probe.\nprovider: codex\n---\n\nteam.\n",
1296
- )
1297
- .unwrap();
1298
- std::fs::write(ws.join("agents").join("alpha.md"), alpha_role).unwrap();
1299
- std::fs::write(ws.join("agents").join("bravo.md"), DELEG_ROLE_BRAVO).unwrap();
1300
- let spec = crate::compiler::compile_team(&ws).expect("compile fork team");
1301
- std::fs::write(ws.join("team.spec.yaml"), crate::model::yaml::dumps(&spec)).unwrap();
1302
- crate::state::persist::save_runtime_state(
1303
- &ws,
1304
- &json!({
1305
- "session_name": "team-laneateam",
1306
- "agents": {
1307
- "alpha": {
1308
- "status": "running",
1309
- "provider": "copilot",
1310
- "window": "alpha",
1311
- "session_id": "sess-a",
1312
- "captured_at": "2026-06-25T10:00:00+00:00",
1313
- "captured_via": "session.captured"
1314
- },
1315
- "bravo": { "status": "running", "provider": "fake", "window": "bravo" }
1316
- }
1317
- }),
1318
- )
1319
- .unwrap();
1320
- seed_healthy_coordinator(&ws);
1321
- ws
1322
- }
1323
-
1324
- // ── STOP #1 (stop-window-gate-1) [RED] — window ABSENT => stopped=false + NO kill ────────────────────
1325
- // Golden operations.py:81-99 gates `tmux kill-window` behind `if _tmux_window_exists(session, window)`;
1326
- // an absent window (already-stopped / never-started spec-known agent) skips the kill and returns
1327
- // {ok:true, status:"stopped", stopped:FALSE}. Rust kills UNCONDITIONALLY (restart.rs:181-183) and
1328
- // hardcodes stopped:true (:192). RED: LaneTransport with NO windows -> the porter's list_windows gate
1329
- // must skip the kill (killed empty) and set stopped=false; today kill_window IS called + stopped=true.
1330
- #[test]
1331
- fn lanea_stop_window_absent_returns_stopped_false_no_kill() {
1332
- let ws = lanea_ws_agents(
1333
- json!({ "alpha": { "status": "running", "provider": "fake", "window": "alpha" } }),
1334
- );
1335
- let tx = LaneTransport::new("team-laneateam", &[]); // alpha's window is ABSENT
1336
- let report = stop_agent_with_transport(&ws, &aid("alpha"), None, &tx)
1337
- .expect("window-absent stop is a clean Ok, not an Err (golden returns stopped:false)");
1338
- assert!(
1339
- !report.stopped,
1340
- "golden operations.py:81-99: an ABSENT tmux window => stopped=FALSE (kill skipped); Rust hardcodes stopped:true"
1341
- );
1342
- assert!(
1343
- tx.killed().is_empty(),
1344
- "golden gates kill on _tmux_window_exists; an absent window must NOT be killed; Rust kills unconditionally, killed={:?}",
1345
- tx.killed()
1346
- );
1347
- }
1348
-
1349
- // ── STOP #1 companion [LOCK] — window PRESENT => stopped=true + kill the golden target ───────────────
1350
- // When the selected team's exact `(session, window, pane)` tuple exists, stop kills that pane and
1351
- // returns stopped:true. Pane identity avoids ambiguous same-name windows on shared endpoints.
1352
- #[test]
1353
- fn lanea_stop_window_present_kills_and_stopped_true() {
1354
- let ws = lanea_ws_agents(
1355
- json!({ "alpha": { "status": "running", "provider": "fake", "window": "alpha" } }),
1356
- );
1357
- let tx = LaneTransport::new("team-laneateam", &["alpha"]); // window present
1358
- let report =
1359
- stop_agent_with_transport(&ws, &aid("alpha"), None, &tx).expect("present-window stop ok");
1360
- assert!(
1361
- report.stopped,
1362
- "a present window must be killed => stopped=true"
1363
- );
1364
- assert_eq!(
1365
- tx.killed(),
1366
- vec!["%alpha".to_string()],
1367
- "stop must kill the selected team's exact pane tuple; killed={:?}",
1368
- tx.killed()
1369
- );
1370
- }
1371
-
1372
- // ── RESET #3 (reset-paused-restart-2) [RED] — reset of a PAUSED agent returns ok=true (NOT an Err) ───
1373
- // Golden operations.py:126-140: after discard, reset re-spawns via start_agent(force,allow_fresh).
1374
- // discard does NOT clear `paused`, so start_agent returns the refusal-shaped {ok:False,status:paused,
1375
- // reason:agent_paused} (start.py:101) WITHOUT raising; reset embeds it as `started` and returns the
1376
- // success envelope {ok:True, status:"running", started:{ok:False,...}, coordinator:None}. Rust maps
1377
- // StartAgentOutcome::Paused -> Err(RequirementUnmet "agent ... is paused") (restart.rs:251-253) — a hard
1378
- // error instead of golden's ok=true. RED: reset of a paused agent must be Ok, not Err.
1379
- #[test]
1380
- fn lanea_reset_paused_agent_returns_ok_not_err() {
1381
- let ws = lanea_ws_agents(json!({
1382
- "alpha": { "status": "running", "provider": "fake", "window": "alpha", "paused": true, "session_id": "sess-a" }
1383
- }));
1384
- let tx = LaneTransport::new("team-laneateam", &["alpha"]);
1385
- let result = reset_agent_with_transport(&ws, &aid("alpha"), true, false, None, &tx);
1386
- assert!(
1387
- result.is_ok(),
1388
- "golden operations.py:133-140: reset of a PAUSED agent returns the ok=true success envelope embedding \
1389
- started={{ok:false,status:paused,reason:agent_paused}}; Rust raises RequirementUnmet. Porter must add a \
1390
- ResetAgentOutcome variant carrying the paused `started` result. got {result:?}"
1391
- );
1392
- assert!(
1393
- !matches!(result, Ok(ResetAgentOutcome::Refused { .. })),
1394
- "discard_session=true was passed -> the DiscardSessionRequired refusal must NOT fire; got {result:?}"
1395
- );
1396
- }
1397
-
1398
- // ── REMOVE #4 (remove-dynamic-agent-refused-1) [RED] — dynamic agent removable WITHOUT from_spec ─────
1399
- // Golden agents.py:50-54: dynamic_agent = bool(agent_state.dynamic_role_file OR agent.forked_from);
1400
- // it only refuses when `not dynamic_agent and not (from_spec and confirm)`. A dynamic/forked agent is
1401
- // removable with from_spec=false. Rust unconditionally `if !from_spec -> RefusedFromSpecConfirm`
1402
- // (restart.rs:285) BEFORE even loading the spec/state -> wrongly refuses the dynamic agent. RED.
1403
- #[test]
1404
- fn lanea_remove_dynamic_agent_removable_without_from_spec() {
1405
- let ws = lanea_ws_agents(json!({
1406
- "alpha": { "status": "stopped", "provider": "fake", "window": "alpha", "dynamic_role_file": ".team/dynamic-role-files/alpha.md" },
1407
- "bravo": { "status": "stopped", "provider": "fake", "window": "bravo" }
1408
- }));
1409
- // make the dynamic role file exist (so removal resolves+deletes it cleanly under either path policy).
1410
- let dyn_dir = ws.join(".team").join("dynamic-role-files");
1411
- std::fs::create_dir_all(&dyn_dir).unwrap();
1412
- std::fs::write(dyn_dir.join("alpha.md"), "dynamic alpha role\n").unwrap();
1413
- let tx = LaneTransport::new("team-laneateam", &[]); // alpha not running
1414
- let result = remove_agent_with_transport(&ws, &aid("alpha"), false, true, None, &tx); // from_spec=FALSE
1415
- assert!(
1416
- !matches!(result, Ok(RemoveAgentOutcome::RefusedFromSpecConfirm { .. })),
1417
- "golden agents.py:50-54: a DYNAMIC agent (state.dynamic_role_file) is removable with from_spec=false; \
1418
- Rust wrongly returns RefusedFromSpecConfirm; got {result:?}"
1419
- );
1420
- let state = crate::state::persist::load_runtime_state(&ws).expect("load state");
1421
- assert!(
1422
- state
1423
- .get("agents")
1424
- .and_then(serde_json::Value::as_object)
1425
- .is_some_and(|a| !a.contains_key("alpha")),
1426
- "the dynamic agent must actually be removed from state.agents; got {result:?}"
1427
- );
1428
- }
1429
-
1430
- #[test]
1431
- fn remove_preserves_external_role_source_for_both_flag_forms() {
1432
- for from_spec in [false, true] {
1433
- let ws = lanea_ws_agents(json!({
1434
- "alpha": { "status": "stopped", "provider": "fake", "window": "alpha" },
1435
- "bravo": { "status": "stopped", "provider": "fake", "window": "bravo" }
1436
- }));
1437
- let external_dir = ws.join("role-masters");
1438
- std::fs::create_dir_all(&external_dir).unwrap();
1439
- let external = external_dir.join("alpha.md");
1440
- let original = b"external alpha role\n";
1441
- std::fs::write(&external, original).unwrap();
1442
- let mut state = crate::state::persist::load_runtime_state(&ws).unwrap();
1443
- state["agents"]["alpha"]["dynamic_role_file"] =
1444
- serde_json::json!(external.to_string_lossy());
1445
- crate::state::persist::save_runtime_state(&ws, &state).unwrap();
1446
-
1447
- let result = remove_agent_with_transport(
1448
- &ws,
1449
- &aid("alpha"),
1450
- from_spec,
1451
- true,
1452
- None,
1453
- &LaneTransport::new("team-laneateam", &[]),
1454
- );
1455
- assert!(result.is_ok(), "remove failed: {result:?}");
1456
- assert_eq!(
1457
- std::fs::read(&external).unwrap(),
1458
- original,
1459
- "external role source changed for from_spec={from_spec}"
1460
- );
1461
- }
1462
- }
1463
-
1464
- // A-28 was: default remove must preserve registered managed markdown.
1465
- // ledger.seat-supply-prereq overturned that for files under
1466
- // `.team/dynamic-role-files/` (framework materialization, not user asset).
1467
- // Keep the test name; flip the assertion. External --role-file is covered
1468
- // by `remove_preserves_external_role_source_for_both_flag_forms`.
1469
- #[test]
1470
- fn remove_agent_preserves_registered_role_markdown_by_default() {
1471
- let ws = lanea_ws_agents(json!({
1472
- "alpha": {
1473
- "status": "stopped",
1474
- "provider": "fake",
1475
- "window": "alpha",
1476
- "dynamic_role_file": ".team/dynamic-role-files/alpha.md"
1477
- },
1478
- "bravo": { "status": "stopped", "provider": "fake", "window": "bravo" }
1479
- }));
1480
- let role = ws.join(".team/dynamic-role-files/alpha.md");
1481
- std::fs::create_dir_all(role.parent().unwrap()).unwrap();
1482
- let original = b"user-authored registered role\n";
1483
- std::fs::write(&role, original).unwrap();
1484
-
1485
- let result = remove_agent_with_transport(
1486
- &ws,
1487
- &aid("alpha"),
1488
- false,
1489
- true,
1490
- None,
1491
- &LaneTransport::new("team-laneateam", &[]),
1492
- );
1493
- assert!(
1494
- result.is_ok(),
1495
- "remove-agent should unregister the seat: {result:?}"
1496
- );
1497
- assert!(
1498
- !role.exists(),
1499
- "managed role markdown must be gone after remove-agent so the next same-id clone is not blocked"
1500
- );
1501
- }
1502
-
1503
- #[cfg(unix)]
1504
- #[test]
1505
- fn remove_preserves_managed_path_symlink_escape() {
1506
- use std::os::unix::fs::symlink;
1507
-
1508
- let ws = lanea_ws_agents(json!({
1509
- "alpha": { "status": "stopped", "provider": "fake", "window": "alpha", "dynamic_role_file": ".team/dynamic-role-files/alpha.md" },
1510
- "bravo": { "status": "stopped", "provider": "fake", "window": "bravo" }
1511
- }));
1512
- let external = ws.join("role-masters").join("alpha.md");
1513
- std::fs::create_dir_all(external.parent().unwrap()).unwrap();
1514
- std::fs::write(&external, b"external target\n").unwrap();
1515
- let managed = ws.join(".team").join("dynamic-role-files").join("alpha.md");
1516
- std::fs::create_dir_all(managed.parent().unwrap()).unwrap();
1517
- symlink(&external, &managed).unwrap();
1518
-
1519
- let result = remove_agent_with_transport(
1520
- &ws,
1521
- &aid("alpha"),
1522
- false,
1523
- true,
1524
- None,
1525
- &LaneTransport::new("team-laneateam", &[]),
1526
- );
1527
- assert!(result.is_ok(), "remove failed: {result:?}");
1528
- assert_eq!(std::fs::read(&external).unwrap(), b"external target\n");
1529
- assert!(
1530
- !managed.symlink_metadata().is_ok(),
1531
- "managed symlink must be unlinked; must not follow and delete the external target"
1532
- );
1533
- }
1534
-
1535
- #[test]
1536
- fn remove_agent_deletes_unrecorded_default_managed_role() {
1537
- let ws = lanea_ws_agents(json!({
1538
- "alpha": { "status": "stopped", "provider": "fake", "window": "alpha" },
1539
- "bravo": { "status": "stopped", "provider": "fake", "window": "bravo" }
1540
- }));
1541
- let role = ws.join(".team").join("dynamic-role-files").join("alpha.md");
1542
- std::fs::create_dir_all(role.parent().unwrap()).unwrap();
1543
- std::fs::write(&role, b"unrecorded default managed copy\n").unwrap();
1544
-
1545
- let result = remove_agent_with_transport(
1546
- &ws,
1547
- &aid("alpha"),
1548
- true,
1549
- true,
1550
- None,
1551
- &LaneTransport::new("team-laneateam", &[]),
1552
- );
1553
- assert!(result.is_ok(), "remove failed: {result:?}");
1554
- assert!(
1555
- !role.exists(),
1556
- "default managed path must be cleared even when state.dynamic_role_file is unset"
1557
- );
1558
- }
1559
-
1560
- #[test]
1561
- fn force_remove_state_only_seat_is_idempotent() {
1562
- let ws = lanea_ws_agents(json!({
1563
- "alpha": { "status": "stopped", "provider": "fake", "window": "alpha" },
1564
- "bravo": { "status": "stopped", "provider": "fake", "window": "bravo" }
1565
- }));
1566
- let spec_path = ws.join("team.spec.yaml");
1567
- let spec = crate::model::yaml::loads(&std::fs::read_to_string(&spec_path).unwrap()).unwrap();
1568
- std::fs::write(
1569
- &spec_path,
1570
- crate::model::yaml::dumps(&crate::lifecycle::restart::remove::spec_without_agent(
1571
- &spec,
1572
- &aid("alpha"),
1573
- )),
1574
- )
1575
- .unwrap();
1576
- let transport = LaneTransport::new("team-laneateam", &[]);
1577
- let first = remove_agent_with_transport(&ws, &aid("alpha"), true, true, None, &transport);
1578
- let second = remove_agent_with_transport(&ws, &aid("alpha"), true, true, None, &transport);
1579
- assert!(first.is_ok(), "state-only force-remove failed: {first:?}");
1580
- assert!(
1581
- second.is_ok(),
1582
- "second force-remove must be idempotent: {second:?}"
1583
- );
1584
- }
1585
-
1586
- // ── REMOVE #5 (remove-unknown-precedence-2) [RED] — unknown-worker raised BEFORE from_spec refusal ───
1587
- // Golden agents.py:41-54 loads the spec and runs _find_worker (raising "unknown worker agent id: <id>")
1588
- // BEFORE the from_spec/confirm refusal at :53. Rust checks `!from_spec` FIRST (restart.rs:285) and
1589
- // returns RefusedFromSpecConfirm without ever loading the spec -> a nonexistent agent is mis-reported as
1590
- // a from_spec refusal. RED: an unknown agent with from_spec=false must surface "unknown worker".
1591
- #[test]
1592
- fn lanea_remove_unknown_agent_precedes_from_spec_refusal() {
1593
- let ws = lanea_ws_agents(
1594
- json!({ "alpha": { "status": "stopped", "provider": "fake", "window": "alpha" } }),
1595
- );
1596
- let tx = LaneTransport::new("team-laneateam", &[]);
1597
- let text = format!(
1598
- "{:?}",
1599
- remove_agent_with_transport(&ws, &aid("ghost"), false, false, None, &tx)
1600
- );
1601
- assert!(
1602
- text.contains("unknown worker"),
1603
- "golden agents.py:41-54: the unknown-worker check precedes the from_spec refusal; an unknown agent must \
1604
- raise 'unknown worker agent id: ghost', NOT RefusedFromSpecConfirm; got {text}"
1605
- );
1606
- }
1607
-
1608
- // ── REMOVE #8 (remove-team-state-md-content-5) [RED] — team_state.md is golden MARKDOWN, not JSON ────
1609
- // Golden state.py:625-686 write_team_state builds a Markdown doc ("# Team State", "## Objective",
1610
- // "## Agents" with one "- {id}: {role} on {provider} ({status})" per spec agent, etc.) from removed_spec.
1611
- // Rust write_team_state (restart.rs:925-941) writes serde_json::to_string_pretty(state) — raw JSON — and
1612
- // passes the ORIGINAL spec (so the removed agent would not be excluded). RED: after a successful remove,
1613
- // team_state.md must be the Markdown doc, list the REMAINING agent (bravo) and NOT the removed one.
1614
- #[test]
1615
- fn lanea_remove_writes_markdown_team_state_not_json() {
1616
- let ws = lanea_ws_agents(json!({
1617
- "alpha": { "status": "stopped", "provider": "fake", "window": "alpha" },
1618
- "bravo": { "status": "running", "provider": "fake", "window": "bravo" }
1619
- }));
1620
- let tx = LaneTransport::new("team-laneateam", &[]);
1621
- let _ =
1622
- remove_agent_with_transport(&ws, &aid("alpha"), true, true, None, &tx).expect("remove ok");
1623
- let team_state =
1624
- std::fs::read_to_string(ws.join("team_state.md")).expect("team_state.md written");
1625
- assert!(
1626
- team_state.starts_with("# Team State"),
1627
- "golden write_team_state emits a Markdown document starting '# Team State'; Rust dumps JSON; got:\n{team_state}"
1628
- );
1629
- assert!(
1630
- !team_state.trim_start().starts_with('{'),
1631
- "team_state.md must NOT be a JSON dump of runtime state; got:\n{team_state}"
1632
- );
1633
- assert!(
1634
- team_state.contains("## Agents"),
1635
- "golden has a '## Agents' section; got:\n{team_state}"
1636
- );
1637
- assert!(
1638
- team_state.contains("bravo: Bravo Worker on fake"),
1639
- "the '## Agents' section must list the remaining agent bravo (golden '- {{id}}: {{role}} on {{provider}} ({{status}})'); got:\n{team_state}"
1640
- );
1641
- assert!(
1642
- !team_state.contains("alpha: Alpha Worker"),
1643
- "the removed agent (alpha) must be EXCLUDED — golden writes removed_spec, not the original spec; got:\n{team_state}"
1644
- );
1645
- }
1646
-
1647
- // ── REMOVE #10 (remove-is-running-no-tmux-fallback-7) [RED] — is_running honors the tmux-window fallback
1648
- // Golden agents.py:247-252 _is_running returns True if status in {running,busy} OR
1649
- // (session_name AND _tmux_window_exists(session, window)). Rust agent_is_running (restart.rs:689-700)
1650
- // only checks status -> an agent with a STALE status ('idle') whose tmux window is still live is treated
1651
- // as not-running, so removal without --force is wrongly ALLOWED. RED: such an agent removed without
1652
- // force must be RefusedForceRequired (golden), not Removed.
1653
- #[test]
1654
- fn lanea_remove_is_running_honors_tmux_window_fallback() {
1655
- let ws = lanea_ws_agents(json!({
1656
- "alpha": { "status": "idle", "provider": "fake", "window": "alpha" }, // stale status, but window is live
1657
- "bravo": { "status": "stopped", "provider": "fake", "window": "bravo" }
1658
- }));
1659
- let tx = LaneTransport::new("team-laneateam", &["alpha"]); // alpha's tmux window EXISTS
1660
- let result = remove_agent_with_transport(&ws, &aid("alpha"), true, false, None, &tx); // force=FALSE
1661
- assert!(
1662
- matches!(result, Ok(RemoveAgentOutcome::RefusedForceRequired { .. })),
1663
- "golden agents.py:247-252: a stale-status agent whose tmux window is LIVE counts as running -> removal \
1664
- without --force is RefusedForceRequired; Rust drops the tmux fallback and allows it. Porter must thread \
1665
- the transport into agent_is_running. got {result:?}"
1666
- );
1667
- }
1668
-
1669
- // ── REMOVE #7 (remove-rollback-no-restart-running-4) [RED] — rollback RESTARTS the force-stopped worker
1670
- // Golden agents.py:78,219-223: after force-stopping a running worker, rollback (on any in-try failure)
1671
- // sets restore_running and calls start_agent(force=True, allow_fresh=True) to bring the worker back.
1672
- // Rust rollback (restart.rs:1023-1067) has no restore_running and never restarts -> a force-remove that
1673
- // stops a running agent then fails leaves it DEAD. RED: drive a deterministic in-try failure
1674
- // (1-worker team: removing alpha -> empty agents -> validate_spec fails AFTER the force-stop) and assert
1675
- // the transport recorded a re-spawn during rollback (the golden worker restart). Today: zero spawns.
1676
- #[test]
1677
- fn lanea_remove_rollback_restarts_force_stopped_worker() {
1678
- let ws = lanea_one_agent_ws("running"); // removing alpha -> agents:[] -> validate_spec FAILS post-stop
1679
- let tx = LaneTransport::new("team-laneateam", &["alpha"]);
1680
- let result = remove_agent_with_transport(&ws, &aid("alpha"), true, true, None, &tx); // from_spec+force
1681
- assert!(
1682
- result.is_err(),
1683
- "precondition: removing the only worker makes removed_spec invalid (validate_spec) -> the remove fails \
1684
- after the force-stop, triggering rollback; got {result:?}"
1685
- );
1686
- assert!(
1687
- tx.killed().contains(&"%alpha".to_string()),
1688
- "precondition: the running worker's exact pane was killed before the failure; killed={:?}",
1689
- tx.killed()
1690
- );
1691
- assert!(
1692
- !tx.spawns().is_empty(),
1693
- "golden agents.py:219-223: rollback must RESTART the force-stopped worker (start_agent force=True) -> a \
1694
- re-spawn; Rust rollback never restarts, leaving the worker dead. Porter must thread the transport into \
1695
- RemoveRollback::restore. spawns={:?}",
1696
- tx.spawns()
1697
- );
1698
- let restored = crate::state::persist::load_runtime_state(&ws).unwrap();
1699
- assert!(
1700
- restored["agent_lifecycle"].get("alpha").is_none(),
1701
- "failed remove must roll back the transaction-created tombstone"
1702
- );
1703
- }
1704
-
1705
- // A recorded role path is user-owned input, not a remove-agent precondition.
1706
- // Missing role markdown therefore must not block unregistering the seat.
1707
- #[test]
1708
- fn lanea_remove_dynamic_role_file_missing_does_not_block_unregister() {
1709
- let ws = lanea_ws_agents(json!({
1710
- "alpha": { "status": "stopped", "provider": "fake", "window": "alpha", "dynamic_role_file": ".team/dynamic-role-files/custom.md" }, // file NOT created
1711
- "bravo": { "status": "stopped", "provider": "fake", "window": "bravo" }
1712
- }));
1713
- let tx = LaneTransport::new("team-laneateam", &[]);
1714
- let result = remove_agent_with_transport(&ws, &aid("alpha"), true, true, None, &tx);
1715
- assert!(
1716
- result.is_ok(),
1717
- "remove-agent must unregister even when a recorded role path is missing; got {result:?}"
1718
- );
1719
- }
1720
-
1721
- // ── REMOVE #9 (remove-rollback-team-state-path-6) [RED] — rollback restores via spec.context.state_file
1722
- // Golden agents.py:181-204 derives team_state_path = workspace / spec.context.state_file once and uses
1723
- // it for BOTH capture and restore. Rust capture honors spec.context.state_file (restart.rs:994-999) but
1724
- // restore HARDCODES workspace/team_state.md (:1031). With a custom state_file, rollback writes the
1725
- // captured content to the WRONG file. RED (deterministic in-try failure via the 1-worker validate-fail):
1726
- // after rollback, a SPURIOUS team_state.md must NOT exist (golden restores the custom file, never creates
1727
- // team_state.md). Today the hardcoded restore creates team_state.md.
1728
- #[test]
1729
- fn lanea_remove_rollback_restores_via_spec_state_file_path() {
1730
- let ws = lanea_one_agent_ws("stopped");
1731
- set_context_state_file(&ws, "custom_state.md");
1732
- std::fs::write(ws.join("custom_state.md"), "ORIGINAL CUSTOM TEAM STATE\n").unwrap(); // capture reads this
1733
- let tx = LaneTransport::new("team-laneateam", &[]);
1734
- let result = remove_agent_with_transport(&ws, &aid("alpha"), true, true, None, &tx);
1735
- assert!(
1736
- result.is_err(),
1737
- "precondition: 1-worker removal -> validate_spec fails -> rollback runs; got {result:?}"
1738
- );
1739
- assert!(
1740
- !ws.join("team_state.md").exists(),
1741
- "golden agents.py:200-204: rollback restores the spec-derived state_file (custom_state.md), it must NOT \
1742
- create the hardcoded team_state.md. Porter must capture team_state_path on the rollback struct and reuse \
1743
- it in restore."
1744
- );
1745
- }
1746
-
1747
- // ── FORK (fork-dup-guard-misses-leader) [RED] — forking ONTO the leader id is 'already exists' ───────
1748
- // Golden operations.py:301-302 uses _find_agent (matches agents AND the leader, runtime.py:1055), so
1749
- // forking to as_agent_id == leader.id raises 'agent id already exists: <id>'. Rust find_spec_agent
1750
- // short-circuits to None for the leader id (launch.rs:507-515) -> the duplicate guard is SKIPPED and the
1751
- // fork proceeds against the leader id. RED: fork target == "leader" must be 'already exists'.
1752
- #[test]
1753
- fn lanea_fork_dup_target_leader_id_is_already_exists() {
1754
- let ws = fork_ws(COPILOT_ROLE_ALPHA);
1755
- let tx = LaneTransport::new("team-laneateam", &[]);
1756
- // The legacy fork entry refuses before any target check; the leader-id duplicate is not reached.
1757
- let result =
1758
- fork_agent_with_transport(&ws, &aid("alpha"), &aid("leader"), None, false, None, &tx);
1759
- assert_legacy_fork_unverified(&result, "copilot");
1760
- }
1761
-
1762
- // ── FORK (fork-missing-tmux-window-guard) [RED] — window-already-exists guard BEFORE spec mutation ────
1763
- // Golden operations.py:310-312: after the session_id guard and BEFORE mutating the spec, raise
1764
- // 'tmux window already exists for fork target: {session}:{as_agent_id}' if the window exists. Rust has no
1765
- // such guard (launch.rs:439-440) -> it appends + writes the spec regardless. RED: a pre-existing window
1766
- // for the target must (a) raise that exact message and (b) leave the spec UNMUTATED (no fork agent).
1767
- #[test]
1768
- fn lanea_fork_window_already_exists_guard_before_spec_mutation() {
1769
- let ws = fork_ws(COPILOT_ROLE_ALPHA);
1770
- let tx = LaneTransport::new("team-laneateam", &["newfork"]); // the target window already exists
1771
- // The legacy fork entry refuses before any target check; the window-exists guard is not reached.
1772
- let result =
1773
- fork_agent_with_transport(&ws, &aid("alpha"), &aid("newfork"), None, false, None, &tx);
1774
- assert_legacy_fork_unverified(&result, "copilot");
1775
- let spec_text = std::fs::read_to_string(ws.join("team.spec.yaml")).unwrap();
1776
- assert!(
1777
- !spec_text.contains("newfork"),
1778
- "the guard must fire BEFORE the spec is mutated; the spec must NOT contain the fork agent 'newfork'"
1779
- );
1780
- }
1781
-
1782
- // ── FORK (fork-gate-error-text) [RED] + (fork-incomplete-rollback, adapter arm) — golden gate text + spec rollback
1783
- // Golden operations.py:329-330 raises f"{provider} does not support native session fork" when the native
1784
- // fork gate fails (auth_mode==compatible_api). Rust relies on adapter.fork_plan() -> CapabilityUnsupported
1785
- // ("<provider>:fork") (adapter.rs:310) -> a different observable. AND golden wraps the post-spec-write steps
1786
- // in try/except restoring the spec on ANY failure (operations.py:384-394); Rust writes the spec
1787
- // (launch.rs:443) then errors at adapter.fork_plan (458-460) WITHOUT restoring it. RED on both: the message
1788
- // text AND the spec must be rolled back to not contain the fork agent.
1789
- #[test]
1790
- fn lanea_fork_gate_error_text_and_spec_rollback_on_adapter_arm() {
1791
- let ws = fork_ws(DELEG_ROLE_ALPHA_COMPAT); // source alpha auth_mode=compatible_api
1792
- let tx = LaneTransport::new("team-laneateam", &[]);
1793
- let result =
1794
- fork_agent_with_transport(&ws, &aid("alpha"), &aid("newfork"), None, false, None, &tx);
1795
- // Unverified for any auth mode, never "does not support".
1796
- assert_legacy_fork_unverified(&result, "copilot");
1797
- let spec_text = std::fs::read_to_string(ws.join("team.spec.yaml")).unwrap();
1798
- assert!(
1799
- !spec_text.contains("newfork"),
1800
- "golden operations.py:384-394: on the gate failure the spec must be ROLLED BACK; Rust writes the spec \
1801
- then errors at adapter.fork_plan without restoring it, leaving the fork agent 'newfork' in the spec"
1802
- );
1803
- }
1804
-
1805
- // A fork-capable, fully captured Copilot source gets no legacy fork and no fresh replacement: the
1806
- // refusal performs no spawn and leaves the runtime state untouched.
1807
- #[test]
1808
- fn lanea_fork_captured_copilot_source_spawns_nothing() {
1809
- let ws = fork_ws(COPILOT_ROLE_ALPHA);
1810
- let state_before = crate::state::persist::load_runtime_state(&ws).unwrap();
1811
- let tx = LaneTransport::new("team-laneateam", &[]);
1812
- let result =
1813
- fork_agent_with_transport(&ws, &aid("alpha"), &aid("newfork"), None, false, None, &tx);
1814
- assert_legacy_fork_unverified(&result, "copilot");
1815
- assert!(
1816
- tx.spawns().is_empty(),
1817
- "the refused legacy fork must not spawn a pane; spawns={:?}",
1818
- tx.spawns()
1819
- );
1820
- assert_eq!(
1821
- crate::state::persist::load_runtime_state(&ws).unwrap(),
1822
- state_before,
1823
- "the refused legacy fork must not write runtime state"
1824
- );
1825
- }
1826
-
1827
- #[test]
1828
- fn fresh_start_persists_boundary_from_before_transport_spawn() {
1829
- let ws = lanea_one_agent_ws("stopped");
1830
- let tx = LaneTransport::new("team-laneateam", &[]);
1831
- crate::lifecycle::start_agent_with_transport(&ws, &aid("alpha"), false, false, true, None, &tx)
1832
- .expect("fresh start");
1833
-
1834
- let transport_observed_at = tx
1835
- .spawn_observed_at()
1836
- .into_iter()
1837
- .next()
1838
- .expect("transport spawn observation");
1839
- let transport_observed_at =
1840
- chrono::DateTime::parse_from_rfc3339(&transport_observed_at).unwrap();
1841
- let state = crate::state::persist::load_runtime_state(&ws).unwrap();
1842
- let spawned_at = state["agents"]["alpha"]["spawned_at"]
1843
- .as_str()
1844
- .and_then(|value| chrono::DateTime::parse_from_rfc3339(value).ok())
1845
- .expect("persisted spawn boundary");
1846
- assert!(
1847
- spawned_at <= transport_observed_at,
1848
- "the persisted capture boundary must precede the transport spawn; \
1849
- spawned_at={spawned_at}, transport_observed_at={transport_observed_at}"
1850
- );
1851
- }