@team-agent/installer 0.5.127 → 0.6.0

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 (421) hide show
  1. package/README.md +15 -4
  2. package/README.zh.md +1 -1
  3. package/package.json +4 -8
  4. package/skills/team-agent/SKILL.md +41 -26
  5. package/skills/team-agent/command-coverage.json +170 -184
  6. package/skills/team-agent/docs/reference/team-agent-operator.md +66 -32
  7. package/skills/team-agent/references/recovery-runbook.md +1 -1
  8. package/skills/team-agent/references/team-agent-operator.md +66 -32
  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 -1298
  15. package/crates/team-agent/src/cli/arguments.rs +0 -401
  16. package/crates/team-agent/src/cli/attach_app_server_leader.rs +0 -98
  17. package/crates/team-agent/src/cli/diagnose.rs +0 -1675
  18. package/crates/team-agent/src/cli/emit.rs +0 -2898
  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 -1189
  22. package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -821
  23. package/crates/team-agent/src/cli/intent/tests.rs +0 -691
  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 -6528
  29. package/crates/team-agent/src/cli/models.rs +0 -449
  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/send/coordinator.rs +0 -164
  34. package/crates/team-agent/src/cli/send/mailbox.rs +0 -145
  35. package/crates/team-agent/src/cli/send/persist.rs +0 -192
  36. package/crates/team-agent/src/cli/send/presentation.rs +0 -370
  37. package/crates/team-agent/src/cli/send/resolve.rs +0 -573
  38. package/crates/team-agent/src/cli/send.rs +0 -201
  39. package/crates/team-agent/src/cli/shutdown_socket.rs +0 -288
  40. package/crates/team-agent/src/cli/spec.rs +0 -159
  41. package/crates/team-agent/src/cli/status.rs +0 -280
  42. package/crates/team-agent/src/cli/status_port/agents.rs +0 -358
  43. package/crates/team-agent/src/cli/status_port/approvals.rs +0 -79
  44. package/crates/team-agent/src/cli/status_port/brief.rs +0 -2043
  45. package/crates/team-agent/src/cli/status_port/compact.rs +0 -240
  46. package/crates/team-agent/src/cli/status_port/format.rs +0 -146
  47. package/crates/team-agent/src/cli/status_port/inbox.rs +0 -62
  48. package/crates/team-agent/src/cli/status_port/runtime.rs +0 -197
  49. package/crates/team-agent/src/cli/status_port/snapshot.rs +0 -208
  50. package/crates/team-agent/src/cli/status_port/store.rs +0 -416
  51. package/crates/team-agent/src/cli/status_port/tests.rs +0 -90
  52. package/crates/team-agent/src/cli/status_port.rs +0 -92
  53. package/crates/team-agent/src/cli/tests/base.rs +0 -885
  54. package/crates/team-agent/src/cli/tests/divergence.rs +0 -518
  55. package/crates/team-agent/src/cli/tests/lane_c.rs +0 -453
  56. package/crates/team-agent/src/cli/tests/leader_watch.rs +0 -372
  57. package/crates/team-agent/src/cli/tests/main_preserved.rs +0 -430
  58. package/crates/team-agent/src/cli/tests/missing_subcommands.rs +0 -336
  59. package/crates/team-agent/src/cli/tests/mod.rs +0 -137
  60. package/crates/team-agent/src/cli/tests/named_address.rs +0 -760
  61. package/crates/team-agent/src/cli/tests/parser_safety.rs +0 -383
  62. package/crates/team-agent/src/cli/tests/run_delegation.rs +0 -481
  63. package/crates/team-agent/src/cli/tests/shutdown_kill_plan.rs +0 -2179
  64. package/crates/team-agent/src/cli/tests/status_brief.rs +0 -1514
  65. package/crates/team-agent/src/cli/tests/status_send.rs +0 -1091
  66. package/crates/team-agent/src/cli/tests/verb_install_skill.rs +0 -93
  67. package/crates/team-agent/src/cli/tests/verb_profile.rs +0 -392
  68. package/crates/team-agent/src/cli/triage.rs +0 -234
  69. package/crates/team-agent/src/cli/types.rs +0 -591
  70. package/crates/team-agent/src/codex_app_server.rs +0 -546
  71. package/crates/team-agent/src/communication_mode/mod.rs +0 -56
  72. package/crates/team-agent/src/compiler/tests.rs +0 -842
  73. package/crates/team-agent/src/compiler.rs +0 -691
  74. package/crates/team-agent/src/conpty/backend.rs +0 -829
  75. package/crates/team-agent/src/conpty/mod.rs +0 -33
  76. package/crates/team-agent/src/contract_runtime/backend.rs +0 -1610
  77. package/crates/team-agent/src/contract_runtime/commands.rs +0 -671
  78. package/crates/team-agent/src/contract_runtime/config.rs +0 -354
  79. package/crates/team-agent/src/contract_runtime/config_tests.rs +0 -56
  80. package/crates/team-agent/src/contract_runtime/discovery.rs +0 -438
  81. package/crates/team-agent/src/contract_runtime/fork.rs +0 -368
  82. package/crates/team-agent/src/contract_runtime/forward.rs +0 -288
  83. package/crates/team-agent/src/contract_runtime/framework.rs +0 -350
  84. package/crates/team-agent/src/contract_runtime/mcp.rs +0 -399
  85. package/crates/team-agent/src/contract_runtime/mod.rs +0 -17
  86. package/crates/team-agent/src/contract_runtime/prompt.rs +0 -216
  87. package/crates/team-agent/src/contract_runtime/pump.rs +0 -271
  88. package/crates/team-agent/src/contract_runtime/registry.rs +0 -589
  89. package/crates/team-agent/src/contract_runtime/workspace.rs +0 -228
  90. package/crates/team-agent/src/coordinator/backoff.rs +0 -741
  91. package/crates/team-agent/src/coordinator/conpty_shim.rs +0 -805
  92. package/crates/team-agent/src/coordinator/health.rs +0 -1185
  93. package/crates/team-agent/src/coordinator/mod.rs +0 -119
  94. package/crates/team-agent/src/coordinator/orphan.rs +0 -110
  95. package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -798
  96. package/crates/team-agent/src/coordinator/runtime_observation.rs +0 -84
  97. package/crates/team-agent/src/coordinator/steps/abnormal.rs +0 -2309
  98. package/crates/team-agent/src/coordinator/steps/delivery.rs +0 -15
  99. package/crates/team-agent/src/coordinator/steps/health_sync.rs +0 -15
  100. package/crates/team-agent/src/coordinator/steps/mod.rs +0 -126
  101. package/crates/team-agent/src/coordinator/steps/persist.rs +0 -15
  102. package/crates/team-agent/src/coordinator/steps/runtime_prompts.rs +0 -15
  103. package/crates/team-agent/src/coordinator/steps/session_gate.rs +0 -16
  104. package/crates/team-agent/src/coordinator/tests/a0_lostupdate.rs +0 -158
  105. package/crates/team-agent/src/coordinator/tests/abnormal.rs +0 -312
  106. package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +0 -338
  107. package/crates/team-agent/src/coordinator/tests/basics.rs +0 -211
  108. package/crates/team-agent/src/coordinator/tests/daemon.rs +0 -514
  109. package/crates/team-agent/src/coordinator/tests/energy.rs +0 -549
  110. package/crates/team-agent/src/coordinator/tests/health_sync.rs +0 -461
  111. package/crates/team-agent/src/coordinator/tests/main_preserved.rs +0 -186
  112. package/crates/team-agent/src/coordinator/tests/mod.rs +0 -295
  113. package/crates/team-agent/src/coordinator/tests/s3_bounded.rs +0 -207
  114. package/crates/team-agent/src/coordinator/tests/spine.rs +0 -308
  115. package/crates/team-agent/src/coordinator/tests/takeover.rs +0 -286
  116. package/crates/team-agent/src/coordinator/tests/tick_core.rs +0 -237
  117. package/crates/team-agent/src/coordinator/tick.rs +0 -3112
  118. package/crates/team-agent/src/coordinator/types.rs +0 -540
  119. package/crates/team-agent/src/db/agent_health_capture.rs +0 -126
  120. package/crates/team-agent/src/db/message_store.rs +0 -1585
  121. package/crates/team-agent/src/db/migration.rs +0 -984
  122. package/crates/team-agent/src/db/mod.rs +0 -26
  123. package/crates/team-agent/src/db/schema.rs +0 -663
  124. package/crates/team-agent/src/diagnose/comms.rs +0 -242
  125. package/crates/team-agent/src/diagnose/mod.rs +0 -44
  126. package/crates/team-agent/src/diagnose/orphans.rs +0 -889
  127. package/crates/team-agent/src/event_log.rs +0 -502
  128. package/crates/team-agent/src/fake_worker.rs +0 -303
  129. package/crates/team-agent/src/kill_audit.rs +0 -106
  130. package/crates/team-agent/src/layout/manager.rs +0 -248
  131. package/crates/team-agent/src/layout/mod.rs +0 -36
  132. package/crates/team-agent/src/layout/overlay.rs +0 -134
  133. package/crates/team-agent/src/layout/placement.rs +0 -52
  134. package/crates/team-agent/src/layout/recovery.rs +0 -106
  135. package/crates/team-agent/src/layout/runtime_sessions.rs +0 -317
  136. package/crates/team-agent/src/layout/sessions.rs +0 -294
  137. package/crates/team-agent/src/layout/tmux_endpoint.rs +0 -165
  138. package/crates/team-agent/src/layout/worker_env.rs +0 -721
  139. package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -37
  140. package/crates/team-agent/src/leader/helpers.rs +0 -178
  141. package/crates/team-agent/src/leader/incident.rs +0 -6
  142. package/crates/team-agent/src/leader/lease.rs +0 -3356
  143. package/crates/team-agent/src/leader/mod.rs +0 -104
  144. package/crates/team-agent/src/leader/owner_bind.rs +0 -400
  145. package/crates/team-agent/src/leader/prompt.rs +0 -905
  146. package/crates/team-agent/src/leader/provider_attribution.rs +0 -247
  147. package/crates/team-agent/src/leader/rediscover/tests.rs +0 -689
  148. package/crates/team-agent/src/leader/rediscover.rs +0 -1192
  149. package/crates/team-agent/src/leader/registry.rs +0 -883
  150. package/crates/team-agent/src/leader/start.rs +0 -4500
  151. package/crates/team-agent/src/leader/takeover.rs +0 -65
  152. package/crates/team-agent/src/leader/tests/basics.rs +0 -337
  153. package/crates/team-agent/src/leader/tests/byte_findings.rs +0 -355
  154. package/crates/team-agent/src/leader/tests/claim_leader_mailbox_flush_contract.rs +0 -544
  155. package/crates/team-agent/src/leader/tests/historical_inventory_upgrade_gate_red.rs +0 -624
  156. package/crates/team-agent/src/leader/tests/identity.rs +0 -465
  157. package/crates/team-agent/src/leader/tests/identity_session_names.rs +0 -42
  158. package/crates/team-agent/src/leader/tests/idle.rs +0 -113
  159. package/crates/team-agent/src/leader/tests/lease_api.rs +0 -520
  160. package/crates/team-agent/src/leader/tests/lease_claim.rs +0 -629
  161. package/crates/team-agent/src/leader/tests/mod.rs +0 -106
  162. package/crates/team-agent/src/leader/tests/prompt_contract.rs +0 -267
  163. package/crates/team-agent/src/leader/tests/rediscover.rs +0 -403
  164. package/crates/team-agent/src/leader/tests/rehomed_env.rs +0 -83
  165. package/crates/team-agent/src/leader/tests/team_in_team_state_scope_red.rs +0 -1273
  166. package/crates/team-agent/src/leader/tests/terminal_and_replay_vs_rerender_invariants_red.rs +0 -417
  167. package/crates/team-agent/src/leader/tests/wake_start_owner.rs +0 -168
  168. package/crates/team-agent/src/leader/types.rs +0 -534
  169. package/crates/team-agent/src/lib.rs +0 -145
  170. package/crates/team-agent/src/lifecycle/helpers.rs +0 -212
  171. package/crates/team-agent/src/lifecycle/launch/add_agent.rs +0 -848
  172. package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +0 -393
  173. package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -332
  174. package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +0 -178
  175. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -82
  176. package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +0 -63
  177. package/crates/team-agent/src/lifecycle/launch/identity.rs +0 -674
  178. package/crates/team-agent/src/lifecycle/launch/layout.rs +0 -350
  179. package/crates/team-agent/src/lifecycle/launch/leader_context.rs +0 -589
  180. package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +0 -152
  181. package/crates/team-agent/src/lifecycle/launch/ownership.rs +0 -105
  182. package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +0 -629
  183. package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +0 -226
  184. package/crates/team-agent/src/lifecycle/launch/plan.rs +0 -269
  185. package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -5176
  186. package/crates/team-agent/src/lifecycle/launch/quick_start_transport.rs +0 -368
  187. package/crates/team-agent/src/lifecycle/launch/readiness.rs +0 -519
  188. package/crates/team-agent/src/lifecycle/launch/role_source.rs +0 -287
  189. package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -450
  190. package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -801
  191. package/crates/team-agent/src/lifecycle/launch/state_projection.rs +0 -624
  192. package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -558
  193. package/crates/team-agent/src/lifecycle/launch.rs +0 -534
  194. package/crates/team-agent/src/lifecycle/lock.rs +0 -350
  195. package/crates/team-agent/src/lifecycle/mod.rs +0 -79
  196. package/crates/team-agent/src/lifecycle/pane_input_lock.rs +0 -239
  197. package/crates/team-agent/src/lifecycle/profile_launch.rs +0 -757
  198. package/crates/team-agent/src/lifecycle/profile_smoke.rs +0 -557
  199. package/crates/team-agent/src/lifecycle/restart/agent.rs +0 -2198
  200. package/crates/team-agent/src/lifecycle/restart/common.rs +0 -2052
  201. package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +0 -65
  202. package/crates/team-agent/src/lifecycle/restart/preflight.rs +0 -113
  203. package/crates/team-agent/src/lifecycle/restart/rebuild.rs +0 -5135
  204. package/crates/team-agent/src/lifecycle/restart/remove.rs +0 -1504
  205. package/crates/team-agent/src/lifecycle/restart/selection.rs +0 -559
  206. package/crates/team-agent/src/lifecycle/restart/team_state.rs +0 -329
  207. package/crates/team-agent/src/lifecycle/restart.rs +0 -223
  208. package/crates/team-agent/src/lifecycle/role_config.rs +0 -1205
  209. package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +0 -1021
  210. package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +0 -1205
  211. package/crates/team-agent/src/lifecycle/tests/b0_legacy_snapshot_nonauthority_contract.rs +0 -265
  212. package/crates/team-agent/src/lifecycle/tests/b0_reader_hideone_audit_contract.rs +0 -490
  213. package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +0 -656
  214. package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +0 -135
  215. package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +0 -1415
  216. package/crates/team-agent/src/lifecycle/tests/clone_agent_preserves_source_tools.rs +0 -427
  217. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +0 -396
  218. package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +0 -418
  219. package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +0 -2039
  220. package/crates/team-agent/src/lifecycle/tests/core.rs +0 -1298
  221. package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +0 -315
  222. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_g0.stdout.txt +0 -222
  223. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_spaced_ids.stdout.txt +0 -9
  224. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +0 -71
  225. package/crates/team-agent/src/lifecycle/tests/gate_fixtures.rs +0 -562
  226. package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +0 -110
  227. package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +0 -472
  228. package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +0 -921
  229. package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +0 -68
  230. package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +0 -1851
  231. package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +0 -3981
  232. package/crates/team-agent/src/lifecycle/tests/lifecycle_lock.rs +0 -339
  233. package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +0 -596
  234. package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +0 -513
  235. package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +0 -69
  236. package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +0 -824
  237. package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +0 -723
  238. package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +0 -152
  239. package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +0 -182
  240. package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +0 -374
  241. package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +0 -546
  242. package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +0 -31
  243. package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +0 -528
  244. package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +0 -134
  245. package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +0 -333
  246. package/crates/team-agent/src/lifecycle/tests/realmachine_clusters_1_6_red.rs +0 -786
  247. package/crates/team-agent/src/lifecycle/tests/realmachine_residual_g1_g4_red.rs +0 -648
  248. package/crates/team-agent/src/lifecycle/tests/restart.rs +0 -185
  249. package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +0 -1053
  250. package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +0 -679
  251. package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1126
  252. package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +0 -153
  253. package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +0 -427
  254. package/crates/team-agent/src/lifecycle/tests/stale_team_saveconflict_contract.rs +0 -431
  255. package/crates/team-agent/src/lifecycle/tests/startup_latency_contract.rs +0 -1066
  256. package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +0 -876
  257. package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +0 -1026
  258. package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +0 -90
  259. package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +0 -543
  260. package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +0 -1103
  261. package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +0 -1276
  262. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_roster_red.rs +0 -145
  263. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +0 -603
  264. package/crates/team-agent/src/lifecycle/tests/test_isolation_escape_contract.rs +0 -936
  265. package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +0 -970
  266. package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +0 -996
  267. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -827
  268. package/crates/team-agent/src/lifecycle/tests.rs +0 -102
  269. package/crates/team-agent/src/lifecycle/types.rs +0 -861
  270. package/crates/team-agent/src/lifecycle/worker_command_context.rs +0 -370
  271. package/crates/team-agent/src/main.rs +0 -52
  272. package/crates/team-agent/src/mcp_server/helpers.rs +0 -510
  273. package/crates/team-agent/src/mcp_server/lifecycle_tools/mod.rs +0 -6
  274. package/crates/team-agent/src/mcp_server/lifecycle_tools/state_status.rs +0 -43
  275. package/crates/team-agent/src/mcp_server/mod.rs +0 -119
  276. package/crates/team-agent/src/mcp_server/normalize.rs +0 -485
  277. package/crates/team-agent/src/mcp_server/readiness.rs +0 -546
  278. package/crates/team-agent/src/mcp_server/readiness_tests.rs +0 -369
  279. package/crates/team-agent/src/mcp_server/tests/golden.rs +0 -285
  280. package/crates/team-agent/src/mcp_server/tests/normalize.rs +0 -247
  281. package/crates/team-agent/src/mcp_server/tests/scoped.rs +0 -168
  282. package/crates/team-agent/src/mcp_server/tests/send.rs +0 -388
  283. package/crates/team-agent/src/mcp_server/tests/tools.rs +0 -343
  284. package/crates/team-agent/src/mcp_server/tests/wire.rs +0 -254
  285. package/crates/team-agent/src/mcp_server/tests.rs +0 -43
  286. package/crates/team-agent/src/mcp_server/tools.rs +0 -1015
  287. package/crates/team-agent/src/mcp_server/types.rs +0 -396
  288. package/crates/team-agent/src/mcp_server/wire.rs +0 -867
  289. package/crates/team-agent/src/messaging/activity.rs +0 -461
  290. package/crates/team-agent/src/messaging/address.rs +0 -87
  291. package/crates/team-agent/src/messaging/delivery.rs +0 -3785
  292. package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +0 -234
  293. package/crates/team-agent/src/messaging/enter_rescue.rs +0 -362
  294. package/crates/team-agent/src/messaging/enter_rescue_tests.rs +0 -633
  295. package/crates/team-agent/src/messaging/helpers.rs +0 -354
  296. package/crates/team-agent/src/messaging/leader_channel.rs +0 -287
  297. package/crates/team-agent/src/messaging/leader_receiver.rs +0 -786
  298. package/crates/team-agent/src/messaging/mod.rs +0 -166
  299. package/crates/team-agent/src/messaging/persist.rs +0 -377
  300. package/crates/team-agent/src/messaging/presentation.rs +0 -417
  301. package/crates/team-agent/src/messaging/results/collection_tests.rs +0 -719
  302. package/crates/team-agent/src/messaging/results.rs +0 -1415
  303. package/crates/team-agent/src/messaging/scheduler.rs +0 -217
  304. package/crates/team-agent/src/messaging/selftest.rs +0 -315
  305. package/crates/team-agent/src/messaging/send.rs +0 -981
  306. package/crates/team-agent/src/messaging/tests/basic.rs +0 -346
  307. package/crates/team-agent/src/messaging/tests/dup_inject.rs +0 -551
  308. package/crates/team-agent/src/messaging/tests/e23.rs +0 -49
  309. package/crates/team-agent/src/messaging/tests/leader_channel.rs +0 -169
  310. package/crates/team-agent/src/messaging/tests/leader_inject_acceptance.rs +0 -817
  311. package/crates/team-agent/src/messaging/tests/main_preserved.rs +0 -85
  312. package/crates/team-agent/src/messaging/tests/mod.rs +0 -306
  313. package/crates/team-agent/src/messaging/tests/runtime.rs +0 -3655
  314. package/crates/team-agent/src/messaging/tests/spine.rs +0 -837
  315. package/crates/team-agent/src/messaging/tests/wave2.rs +0 -381
  316. package/crates/team-agent/src/messaging/trust.rs +0 -215
  317. package/crates/team-agent/src/messaging/types.rs +0 -471
  318. package/crates/team-agent/src/messaging/wait.rs +0 -366
  319. package/crates/team-agent/src/messaging/watchers.rs +0 -916
  320. package/crates/team-agent/src/model/enums.rs +0 -356
  321. package/crates/team-agent/src/model/errors.rs +0 -18
  322. package/crates/team-agent/src/model/ids.rs +0 -165
  323. package/crates/team-agent/src/model/mod.rs +0 -29
  324. package/crates/team-agent/src/model/name_similarity.rs +0 -252
  325. package/crates/team-agent/src/model/pane_authority_refusal.rs +0 -359
  326. package/crates/team-agent/src/model/paths.rs +0 -257
  327. package/crates/team-agent/src/model/routing.rs +0 -387
  328. package/crates/team-agent/src/model/spec.rs +0 -1184
  329. package/crates/team-agent/src/model/task_graph.rs +0 -321
  330. package/crates/team-agent/src/model/testdata/fuzz.golden.yaml +0 -43
  331. package/crates/team-agent/src/model/testdata/fuzz.yaml +0 -43
  332. package/crates/team-agent/src/model/testdata/spec_invalid_a.yaml +0 -209
  333. package/crates/team-agent/src/model/testdata/team.spec.golden.yaml +0 -208
  334. package/crates/team-agent/src/model/testdata/team.spec.yaml +0 -208
  335. package/crates/team-agent/src/model/yaml/tests.rs +0 -188
  336. package/crates/team-agent/src/model/yaml.rs +0 -802
  337. package/crates/team-agent/src/os_probe.rs +0 -280
  338. package/crates/team-agent/src/packaging/install.rs +0 -219
  339. package/crates/team-agent/src/packaging/migrate.rs +0 -38
  340. package/crates/team-agent/src/packaging/mod.rs +0 -91
  341. package/crates/team-agent/src/packaging/repair.rs +0 -33
  342. package/crates/team-agent/src/packaging/tests.rs +0 -822
  343. package/crates/team-agent/src/packaging/types.rs +0 -417
  344. package/crates/team-agent/src/platform/argv.rs +0 -331
  345. package/crates/team-agent/src/platform/errors.rs +0 -104
  346. package/crates/team-agent/src/platform/file_lock.rs +0 -279
  347. package/crates/team-agent/src/platform/mod.rs +0 -5
  348. package/crates/team-agent/src/platform/process.rs +0 -545
  349. package/crates/team-agent/src/provider/adapter.rs +0 -898
  350. package/crates/team-agent/src/provider/adapters/copilot.rs +0 -75
  351. package/crates/team-agent/src/provider/adapters/copilot_fork.rs +0 -307
  352. package/crates/team-agent/src/provider/adapters/fake.rs +0 -18
  353. package/crates/team-agent/src/provider/adapters/mod.rs +0 -28
  354. package/crates/team-agent/src/provider/approvals/mod.rs +0 -3
  355. package/crates/team-agent/src/provider/approvals/parsing.rs +0 -586
  356. package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +0 -205
  357. package/crates/team-agent/src/provider/argv_route.rs +0 -405
  358. package/crates/team-agent/src/provider/bypass_flags.rs +0 -116
  359. package/crates/team-agent/src/provider/classify.rs +0 -773
  360. package/crates/team-agent/src/provider/command_helpers.rs +0 -45
  361. package/crates/team-agent/src/provider/faults.rs +0 -165
  362. package/crates/team-agent/src/provider/helpers.rs +0 -52
  363. package/crates/team-agent/src/provider/mod.rs +0 -78
  364. package/crates/team-agent/src/provider/model_catalog.rs +0 -722
  365. package/crates/team-agent/src/provider/session/capture.rs +0 -2631
  366. package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -168
  367. package/crates/team-agent/src/provider/session/context_fork.rs +0 -264
  368. package/crates/team-agent/src/provider/session/mod.rs +0 -36
  369. package/crates/team-agent/src/provider/session/resume.rs +0 -269
  370. package/crates/team-agent/src/provider/session_scan/common/tests.rs +0 -316
  371. package/crates/team-agent/src/provider/session_scan/common.rs +0 -618
  372. package/crates/team-agent/src/provider/session_scan/copilot.rs +0 -280
  373. package/crates/team-agent/src/provider/session_scan/pi.rs +0 -152
  374. package/crates/team-agent/src/provider/session_scan.rs +0 -61
  375. package/crates/team-agent/src/provider/startup_prompt.rs +0 -757
  376. package/crates/team-agent/src/provider/submit_now.rs +0 -71
  377. package/crates/team-agent/src/provider/testdata/copilot-ready-marker.txt +0 -5
  378. package/crates/team-agent/src/provider/testdata/copilot-trust-prompt.txt +0 -19
  379. package/crates/team-agent/src/provider/testdata/grok-models-authenticated.stdout +0 -9
  380. package/crates/team-agent/src/provider/testdata/grok-models-unauthenticated.stdout +0 -7
  381. package/crates/team-agent/src/provider/tests/adapter.rs +0 -354
  382. package/crates/team-agent/src/provider/tests/classify.rs +0 -201
  383. package/crates/team-agent/src/provider/tests/command_helpers.rs +0 -26
  384. package/crates/team-agent/src/provider/tests/copilot_fork.rs +0 -191
  385. package/crates/team-agent/src/provider/tests/faults.rs +0 -200
  386. package/crates/team-agent/src/provider/tests/idle.rs +0 -140
  387. package/crates/team-agent/src/provider/tests/wire.rs +0 -213
  388. package/crates/team-agent/src/provider/tests.rs +0 -32
  389. package/crates/team-agent/src/provider/types.rs +0 -529
  390. package/crates/team-agent/src/provider/wire.rs +0 -406
  391. package/crates/team-agent/src/redaction.rs +0 -259
  392. package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +0 -248
  393. package/crates/team-agent/src/state/abnormal_watch.rs +0 -144
  394. package/crates/team-agent/src/state/identity.rs +0 -914
  395. package/crates/team-agent/src/state/identity_keys.rs +0 -132
  396. package/crates/team-agent/src/state/mod.rs +0 -74
  397. package/crates/team-agent/src/state/owner_gate.rs +0 -482
  398. package/crates/team-agent/src/state/ownership.rs +0 -563
  399. package/crates/team-agent/src/state/paths.rs +0 -395
  400. package/crates/team-agent/src/state/persist.rs +0 -3811
  401. package/crates/team-agent/src/state/projection.rs +0 -1508
  402. package/crates/team-agent/src/state/repository/intent.rs +0 -14
  403. package/crates/team-agent/src/state/repository/tests.rs +0 -184
  404. package/crates/team-agent/src/state/repository.rs +0 -866
  405. package/crates/team-agent/src/state/selector.rs +0 -160
  406. package/crates/team-agent/src/state/testdata/state-rich.canonical.json +0 -133
  407. package/crates/team-agent/src/tmux_backend/enter_rescue.rs +0 -325
  408. package/crates/team-agent/src/tmux_backend/enter_rescue_tests.rs +0 -432
  409. package/crates/team-agent/src/tmux_backend/native_input.rs +0 -513
  410. package/crates/team-agent/src/tmux_backend/native_input_tests.rs +0 -742
  411. package/crates/team-agent/src/tmux_backend/tests.rs +0 -4254
  412. package/crates/team-agent/src/tmux_backend.rs +0 -4527
  413. package/crates/team-agent/src/topology.rs +0 -537
  414. package/crates/team-agent/src/transport/enter_rescue.rs +0 -166
  415. package/crates/team-agent/src/transport/native_input.rs +0 -491
  416. package/crates/team-agent/src/transport/test_support.rs +0 -743
  417. package/crates/team-agent/src/transport/tests/behavior.rs +0 -326
  418. package/crates/team-agent/src/transport/tests/mod.rs +0 -194
  419. package/crates/team-agent/src/transport/tests/wire.rs +0 -574
  420. package/crates/team-agent/src/transport.rs +0 -1655
  421. 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
- }