@team-agent/installer 0.5.65 → 0.5.68

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 (208) hide show
  1. package/Cargo.lock +8 -1
  2. package/Cargo.toml +1 -1
  3. package/crates/team-agent/Cargo.toml +6 -0
  4. package/crates/team-agent/src/cli/adapters.rs +6 -1
  5. package/crates/team-agent/src/cli/diagnose.rs +82 -0
  6. package/crates/team-agent/src/cli/emit.rs +3 -3
  7. package/crates/team-agent/src/cli/grok_slot.rs +299 -0
  8. package/crates/team-agent/src/cli/leader.rs +21 -7
  9. package/crates/team-agent/src/cli/leaders.rs +125 -1
  10. package/crates/team-agent/src/cli/mod.rs +20 -0
  11. package/crates/team-agent/src/cli/send/presentation.rs +7 -1
  12. package/crates/team-agent/src/cli/spec.rs +2 -0
  13. package/crates/team-agent/src/cli/status_port/compact.rs +28 -0
  14. package/crates/team-agent/src/cli/status_port/snapshot.rs +25 -1
  15. package/crates/team-agent/src/cli/tests/base.rs +26 -3
  16. package/crates/team-agent/src/cli/tests/compile.rs +1 -1
  17. package/crates/team-agent/src/cli/tests/missing_subcommands.rs +129 -19
  18. package/crates/team-agent/src/cli/tests/mod.rs +2 -2
  19. package/crates/team-agent/src/cli/tests/run_delegation.rs +1 -1
  20. package/crates/team-agent/src/cli/tests/shutdown_kill_plan.rs +387 -6
  21. package/crates/team-agent/src/cli/tests/status_send.rs +79 -10
  22. package/crates/team-agent/src/cli/tests/verb_validate.rs +1 -1
  23. package/crates/team-agent/src/communication_mode/mod.rs +6 -4
  24. package/crates/team-agent/src/compiler/tests.rs +23 -20
  25. package/crates/team-agent/src/compiler.rs +84 -5
  26. package/crates/team-agent/src/conpty/backend.rs +16 -0
  27. package/crates/team-agent/src/coordinator/backoff.rs +55 -0
  28. package/crates/team-agent/src/coordinator/conpty_shim.rs +82 -0
  29. package/crates/team-agent/src/coordinator/health.rs +173 -0
  30. package/crates/team-agent/src/coordinator/mod.rs +31 -0
  31. package/crates/team-agent/src/coordinator/orphan.rs +31 -0
  32. package/crates/team-agent/src/coordinator/runtime_detectors.rs +30 -0
  33. package/crates/team-agent/src/coordinator/runtime_observation.rs +25 -0
  34. package/crates/team-agent/src/coordinator/steps/abnormal.rs +59 -0
  35. package/crates/team-agent/src/coordinator/steps/delivery.rs +10 -0
  36. package/crates/team-agent/src/coordinator/steps/health_sync.rs +10 -0
  37. package/crates/team-agent/src/coordinator/steps/mod.rs +22 -0
  38. package/crates/team-agent/src/coordinator/steps/persist.rs +10 -0
  39. package/crates/team-agent/src/coordinator/steps/runtime_prompts.rs +10 -0
  40. package/crates/team-agent/src/coordinator/steps/session_gate.rs +10 -0
  41. package/crates/team-agent/src/coordinator/tick.rs +133 -22
  42. package/crates/team-agent/src/coordinator/types.rs +49 -0
  43. package/crates/team-agent/src/db/message_store.rs +39 -5
  44. package/crates/team-agent/src/layout/worker_env.rs +20 -3
  45. package/crates/team-agent/src/layout/worker_window_helpers.rs +2 -0
  46. package/crates/team-agent/src/leader/provider_attribution.rs +53 -0
  47. package/crates/team-agent/src/leader/registry.rs +65 -0
  48. package/crates/team-agent/src/leader/start.rs +1080 -58
  49. package/crates/team-agent/src/leader/tests/team_in_team_state_scope_red.rs +1 -1
  50. package/crates/team-agent/src/lifecycle/display.rs +56 -0
  51. package/crates/team-agent/src/lifecycle/helpers.rs +57 -0
  52. package/crates/team-agent/src/lifecycle/launch/add_agent.rs +332 -14
  53. package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +69 -2
  54. package/crates/team-agent/src/lifecycle/launch/agent_state.rs +196 -2
  55. package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +101 -11
  56. package/crates/team-agent/src/lifecycle/launch/cursor_create_chat.rs +229 -0
  57. package/crates/team-agent/src/lifecycle/launch/cursor_mcp.rs +332 -0
  58. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +204 -457
  59. package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +24 -0
  60. package/crates/team-agent/src/lifecycle/launch/grok_per_seat.rs +260 -0
  61. package/crates/team-agent/src/lifecycle/launch/identity.rs +146 -0
  62. package/crates/team-agent/src/lifecycle/launch/layout.rs +60 -0
  63. package/crates/team-agent/src/lifecycle/launch/leader_context.rs +112 -0
  64. package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +530 -0
  65. package/crates/team-agent/src/lifecycle/launch/ownership.rs +40 -0
  66. package/crates/team-agent/src/lifecycle/launch/plan.rs +31 -0
  67. package/crates/team-agent/src/lifecycle/launch/quick_start.rs +66 -0
  68. package/crates/team-agent/src/lifecycle/launch/quick_start_transport.rs +78 -0
  69. package/crates/team-agent/src/lifecycle/launch/readiness.rs +85 -38
  70. package/crates/team-agent/src/lifecycle/launch/role_source.rs +44 -44
  71. package/crates/team-agent/src/lifecycle/launch/spawn.rs +101 -4
  72. package/crates/team-agent/src/lifecycle/launch/spec_state.rs +244 -48
  73. package/crates/team-agent/src/lifecycle/launch/state_projection.rs +109 -2
  74. package/crates/team-agent/src/lifecycle/launch/worker_env.rs +214 -1
  75. package/crates/team-agent/src/lifecycle/launch.rs +209 -43
  76. package/crates/team-agent/src/lifecycle/lock.rs +42 -1
  77. package/crates/team-agent/src/lifecycle/mod.rs +11 -0
  78. package/crates/team-agent/src/lifecycle/pane_input_lock.rs +161 -0
  79. package/crates/team-agent/src/lifecycle/profile_launch.rs +98 -0
  80. package/crates/team-agent/src/lifecycle/profile_smoke.rs +51 -1
  81. package/crates/team-agent/src/lifecycle/restart/agent.rs +213 -3
  82. package/crates/team-agent/src/lifecycle/restart/common.rs +373 -18
  83. package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +27 -0
  84. package/crates/team-agent/src/lifecycle/restart/preflight.rs +25 -0
  85. package/crates/team-agent/src/lifecycle/restart/rebuild.rs +165 -15
  86. package/crates/team-agent/src/lifecycle/restart/remove.rs +196 -5
  87. package/crates/team-agent/src/lifecycle/restart/selection.rs +72 -0
  88. package/crates/team-agent/src/lifecycle/restart/team_state.rs +22 -0
  89. package/crates/team-agent/src/lifecycle/restart.rs +29 -0
  90. package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +1 -1
  91. package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +3 -4
  92. package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +1 -1
  93. package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +2 -2
  94. package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +4 -4
  95. package/crates/team-agent/src/lifecycle/tests/clone_agent_preserves_source_tools.rs +309 -0
  96. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +159 -174
  97. package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +2 -2
  98. package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +15 -13
  99. package/crates/team-agent/src/lifecycle/tests/core.rs +4 -18
  100. package/crates/team-agent/src/lifecycle/tests/core_034_real_red.rs +1 -1
  101. package/crates/team-agent/src/lifecycle/tests/cursor_mcp_overlay.rs +287 -0
  102. package/crates/team-agent/src/lifecycle/tests/cursor_require_explicit_model_red.rs +229 -0
  103. package/crates/team-agent/src/lifecycle/tests/cursor_restart_resume_red.rs +353 -0
  104. package/crates/team-agent/src/lifecycle/tests/display_adaptive_red.rs +1 -1
  105. package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +1 -1
  106. package/crates/team-agent/src/lifecycle/tests/g1_silent_faces.rs +784 -0
  107. package/crates/team-agent/src/lifecycle/tests/gate_fixtures.rs +562 -0
  108. package/crates/team-agent/src/lifecycle/tests/grok_effort_argv_red.rs +239 -0
  109. package/crates/team-agent/src/lifecycle/tests/grok_mcp_overlay_red.rs +498 -0
  110. package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +250 -0
  111. package/crates/team-agent/src/lifecycle/tests/grok_restart_resume_red.rs +293 -0
  112. package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +3 -0
  113. package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +3 -3
  114. package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +65 -40
  115. package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +20 -32
  116. package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +17 -9
  117. package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +69 -0
  118. package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +24 -23
  119. package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +98 -62
  120. package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +2 -2
  121. package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +1 -1
  122. package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +1 -1
  123. package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +3 -1
  124. package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +2 -2
  125. package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +1 -1
  126. package/crates/team-agent/src/lifecycle/tests/stale_team_saveconflict_contract.rs +1 -1
  127. package/crates/team-agent/src/lifecycle/tests/startup_latency_contract.rs +41 -8
  128. package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +3 -3
  129. package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +1 -1
  130. package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +1 -1
  131. package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +1 -1
  132. package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +1 -1
  133. package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +1 -1
  134. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +1 -1
  135. package/crates/team-agent/src/lifecycle/tests/test_isolation_escape_contract.rs +60 -2
  136. package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +1 -1
  137. package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +2 -2
  138. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +69 -26
  139. package/crates/team-agent/src/lifecycle/tests.rs +23 -15
  140. package/crates/team-agent/src/lifecycle/types.rs +61 -2
  141. package/crates/team-agent/src/lifecycle/worker_command_context.rs +200 -33
  142. package/crates/team-agent/src/mcp_server/tests/scoped.rs +100 -1
  143. package/crates/team-agent/src/mcp_server/tests.rs +196 -2
  144. package/crates/team-agent/src/messaging/delivery.rs +405 -40
  145. package/crates/team-agent/src/messaging/helpers.rs +2 -0
  146. package/crates/team-agent/src/messaging/leader_receiver.rs +53 -1
  147. package/crates/team-agent/src/messaging/results.rs +4 -0
  148. package/crates/team-agent/src/messaging/send.rs +34 -0
  149. package/crates/team-agent/src/messaging/tests/dup_inject.rs +406 -0
  150. package/crates/team-agent/src/messaging/tests/e23.rs +9 -0
  151. package/crates/team-agent/src/messaging/tests/leader_inject_acceptance.rs +66 -0
  152. package/crates/team-agent/src/messaging/tests/main_preserved.rs +1 -1
  153. package/crates/team-agent/src/messaging/tests/mod.rs +1 -0
  154. package/crates/team-agent/src/messaging/types.rs +4 -1
  155. package/crates/team-agent/src/model/enums.rs +14 -5
  156. package/crates/team-agent/src/model/permissions.rs +3 -0
  157. package/crates/team-agent/src/model/spec.rs +129 -6
  158. package/crates/team-agent/src/model/testdata/spec_invalid_a.yaml +3 -1
  159. package/crates/team-agent/src/model/testdata/team.spec.golden.yaml +3 -1
  160. package/crates/team-agent/src/model/testdata/team.spec.yaml +3 -1
  161. package/crates/team-agent/src/os_probe.rs +73 -2
  162. package/crates/team-agent/src/provider/adapter.rs +231 -4
  163. package/crates/team-agent/src/provider/adapters/claude.rs +5 -2
  164. package/crates/team-agent/src/provider/adapters/codex.rs +5 -2
  165. package/crates/team-agent/src/provider/adapters/copilot.rs +5 -2
  166. package/crates/team-agent/src/provider/adapters/cursor_agent.rs +86 -0
  167. package/crates/team-agent/src/provider/adapters/grok.rs +157 -0
  168. package/crates/team-agent/src/provider/adapters/mod.rs +2 -0
  169. package/crates/team-agent/src/provider/bypass_flags.rs +124 -0
  170. package/crates/team-agent/src/provider/classify.rs +4 -2
  171. package/crates/team-agent/src/provider/faults.rs +2 -1
  172. package/crates/team-agent/src/provider/mod.rs +13 -0
  173. package/crates/team-agent/src/provider/session/capture.rs +158 -20
  174. package/crates/team-agent/src/provider/session/context_fork/claude.rs +38 -1
  175. package/crates/team-agent/src/provider/session/context_fork/codex.rs +72 -1
  176. package/crates/team-agent/src/provider/session/context_fork/outcome.rs +57 -1
  177. package/crates/team-agent/src/provider/session/context_fork.rs +77 -3
  178. package/crates/team-agent/src/provider/session/mod.rs +18 -0
  179. package/crates/team-agent/src/provider/session/resume.rs +57 -0
  180. package/crates/team-agent/src/provider/session_scan/claude.rs +125 -1
  181. package/crates/team-agent/src/provider/session_scan/codex.rs +94 -1
  182. package/crates/team-agent/src/provider/session_scan/common.rs +204 -2
  183. package/crates/team-agent/src/provider/session_scan/copilot.rs +33 -1
  184. package/crates/team-agent/src/provider/session_scan/cursor.rs +538 -0
  185. package/crates/team-agent/src/provider/session_scan/grok.rs +288 -0
  186. package/crates/team-agent/src/provider/session_scan.rs +8 -0
  187. package/crates/team-agent/src/provider/submit_now.rs +94 -0
  188. package/crates/team-agent/src/provider/tests/adapter.rs +304 -0
  189. package/crates/team-agent/src/provider/types.rs +4 -2
  190. package/crates/team-agent/src/provider/wire.rs +23 -1
  191. package/crates/team-agent/src/state/persist.rs +301 -8
  192. package/crates/team-agent/src/state/repository.rs +5 -0
  193. package/crates/team-agent/src/tmux_backend/tests.rs +1737 -42
  194. package/crates/team-agent/src/tmux_backend.rs +1083 -75
  195. package/crates/team-agent/src/transport/test_support.rs +20 -0
  196. package/crates/team-agent/src/transport/tests/wire.rs +28 -2
  197. package/crates/team-agent/src/transport.rs +265 -1
  198. package/npm/install.mjs +129 -73
  199. package/package.json +4 -4
  200. package/skills/team-agent/SKILL.md +33 -238
  201. package/skills/team-agent/command-coverage.json +31 -0
  202. package/crates/team-agent/src/lifecycle/launch/approval.rs +0 -134
  203. package/crates/team-agent/src/lifecycle/launch/fork_agent/completion.rs +0 -59
  204. package/crates/team-agent/src/lifecycle/launch/fork_finalize.rs +0 -483
  205. package/crates/team-agent/src/lifecycle/launch/fork_pending.rs +0 -109
  206. package/crates/team-agent/src/lifecycle/launch/fork_state.rs +0 -447
  207. package/crates/team-agent/src/lifecycle/tests/codex_mcp_approval_inheritance_red.rs +0 -1187
  208. package/crates/team-agent/src/lifecycle/tests/worker_dangerous_bypass_argv_red.rs +0 -327
@@ -0,0 +1,287 @@
1
+ //! purpose: cursor 席位必须把身份写进它实际会读的 mcp.json env
2
+ //! contract: overlay 后 `<workspace>/.cursor/mcp.json` 含 team_orchestrator.env.TEAM_AGENT_ID
3
+ //! (不是 `.team/runtime/mcp/*.json`,也不是靠 pane env 继承)
4
+ //! boundary: 只覆盖 cursor launch 产物;不改 claude/codex/copilot/grok 路径
5
+ //!
6
+ //! 生产侧判据,未经血统审计。
7
+
8
+ #![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
9
+
10
+ #[path = "../../../tests/support/hermetic.rs"]
11
+ mod hermetic_guard;
12
+ #[allow(dead_code)]
13
+ fn _hermetic_boundary_marker(_: &hermetic_guard::HermeticTestEnv) {}
14
+
15
+ use std::path::{Path, PathBuf};
16
+ use std::sync::atomic::{AtomicU64, Ordering};
17
+
18
+ use serial_test::serial;
19
+ use team_agent::lifecycle::quick_start_with_transport_in_workspace;
20
+ use team_agent::lifecycle::{
21
+ apply_cursor_mcp_overlay, apply_cursor_subscription_proxy_env,
22
+ apply_cursor_workspace_physical_path, cursor_mcp_enable_argv, physical_workspace_path,
23
+ LifecycleError,
24
+ };
25
+ use team_agent::provider::McpConfig;
26
+ use team_agent::transport::test_support::OfflineTransport;
27
+
28
+ #[test]
29
+ fn cursor_overlay_writes_identity_into_mcp_json_env() {
30
+ let ws = tmp_dir("cursor-mcp-id");
31
+ apply_cursor_mcp_overlay(&ws, &sample_mcp_config("seat-a", &ws.to_string_lossy()))
32
+ .expect("overlay write");
33
+ let text = std::fs::read_to_string(ws.join(".cursor/mcp.json")).unwrap();
34
+ assert!(
35
+ text.contains("\"team_orchestrator\""),
36
+ "cursor overlay must use the canonical server name"
37
+ );
38
+ assert!(
39
+ text.contains("\"TEAM_AGENT_ID\"") && text.contains("seat-a"),
40
+ "cursor must write TEAM_AGENT_ID into json env; pane env is not inherited"
41
+ );
42
+ assert!(
43
+ text.contains("\"TEAM_AGENT_OWNER_TEAM_ID\"") && text.contains("t1"),
44
+ "owner team must live in json env"
45
+ );
46
+ assert!(
47
+ text.contains("\"TEAM_AGENT_AUTH_MODE\"") && text.contains("subscription"),
48
+ "auth mode must live in json env"
49
+ );
50
+ assert!(
51
+ !text.contains("{workspace}") && !text.contains("{agent_id}"),
52
+ "placeholders must already be resolved"
53
+ );
54
+ assert!(
55
+ !text.contains("\"team-agent\""),
56
+ "legacy inbound key must not remain as a server name"
57
+ );
58
+ }
59
+
60
+ #[test]
61
+ fn cursor_overlay_refuses_missing_identity() {
62
+ let ws = tmp_dir("cursor-mcp-missing-id");
63
+ let cfg = McpConfig {
64
+ raw: serde_json::json!({
65
+ "team_orchestrator": {
66
+ "command": "/bin/team-agent-test",
67
+ "args": ["mcp-server"],
68
+ "env": { "TEAM_AGENT_WORKSPACE": "/ws" }
69
+ }
70
+ }),
71
+ };
72
+ let err = apply_cursor_mcp_overlay(&ws, &cfg).expect_err("missing TEAM_AGENT_ID must fail");
73
+ match err {
74
+ LifecycleError::StatePersist(text) => {
75
+ assert!(
76
+ text.contains("TEAM_AGENT_ID"),
77
+ "refusal must name the missing identity key"
78
+ );
79
+ }
80
+ other => panic!("expected StatePersist, got {other:?}"),
81
+ }
82
+ }
83
+
84
+ #[test]
85
+ fn cursor_overlay_keeps_unrelated_servers_and_replaces_orchestrator() {
86
+ let ws = tmp_dir("cursor-mcp-merge");
87
+ let dir = ws.join(".cursor");
88
+ std::fs::create_dir_all(&dir).unwrap();
89
+ std::fs::write(
90
+ dir.join("mcp.json"),
91
+ r#"{
92
+ "mcpServers": {
93
+ "keep-me": { "command": "/bin/keep" },
94
+ "team-agent": { "command": "/old/team-agent" },
95
+ "team_orchestrator": { "command": "/stale" }
96
+ }
97
+ }"#,
98
+ )
99
+ .unwrap();
100
+
101
+ apply_cursor_mcp_overlay(&ws, &sample_mcp_config("seat-b", "/ws-b")).expect("overlay merge");
102
+ let text = std::fs::read_to_string(dir.join("mcp.json")).unwrap();
103
+ assert!(
104
+ text.contains("keep-me"),
105
+ "unrelated project MCP servers must survive"
106
+ );
107
+ assert!(
108
+ !text.contains("/old/team-agent") && !text.contains("/stale"),
109
+ "stale orchestrator/legacy names must be replaced"
110
+ );
111
+ assert!(
112
+ text.contains("seat-b") && text.contains("/ws-b"),
113
+ "new identity must land"
114
+ );
115
+ }
116
+
117
+ #[test]
118
+ fn cursor_second_seat_overwrites_json_identity_without_exclusive_gate() {
119
+ let ws = tmp_dir("cursor-mcp-two");
120
+ apply_cursor_mcp_overlay(&ws, &sample_mcp_config("first", "/ws")).expect("first");
121
+ apply_cursor_mcp_overlay(&ws, &sample_mcp_config("second", "/ws")).expect("second");
122
+ let text = std::fs::read_to_string(ws.join(".cursor/mcp.json")).unwrap();
123
+ assert!(
124
+ text.contains("second"),
125
+ "last writer wins on a shared --workspace; no grok-style exclusive gate"
126
+ );
127
+ assert!(
128
+ !text.contains("\"first\""),
129
+ "previous seat identity must not remain in the single json file"
130
+ );
131
+ }
132
+
133
+ #[test]
134
+ fn cursor_enable_argv_is_documented_subcommand_without_workspace_flag() {
135
+ let argv = cursor_mcp_enable_argv();
136
+ assert_eq!(
137
+ argv,
138
+ vec![
139
+ "agent".to_string(),
140
+ "mcp".to_string(),
141
+ "enable".to_string(),
142
+ "team_orchestrator".to_string()
143
+ ]
144
+ );
145
+ }
146
+
147
+ #[test]
148
+ fn cursor_workspace_flag_is_rewritten_to_physical_path() {
149
+ let ws = tmp_dir("cursor-phys");
150
+ let mut argv = vec![
151
+ "agent".to_string(),
152
+ "--workspace".to_string(),
153
+ ws.to_string_lossy().into_owned(),
154
+ ];
155
+ apply_cursor_workspace_physical_path(&mut argv, &ws);
156
+ let physical = physical_workspace_path(&ws);
157
+ assert_eq!(argv[2], physical.to_string_lossy().as_ref());
158
+ }
159
+
160
+ #[test]
161
+ #[serial(env)]
162
+ fn cursor_subscription_proxy_copies_keys_without_requiring_profile() {
163
+ let prev = std::env::var("HTTPS_PROXY").ok();
164
+ std::env::set_var("HTTPS_PROXY", "http://127.0.0.1:9");
165
+ let mut env = std::collections::BTreeMap::new();
166
+ let presence = apply_cursor_subscription_proxy_env(&mut env);
167
+ let has_key = env.contains_key("HTTPS_PROXY");
168
+ let value_len = env.get("HTTPS_PROXY").map(String::len);
169
+ match prev {
170
+ Some(value) => std::env::set_var("HTTPS_PROXY", value),
171
+ None => std::env::remove_var("HTTPS_PROXY"),
172
+ }
173
+ assert!(
174
+ presence.https_proxy,
175
+ "presence must be true when the process has HTTPS_PROXY"
176
+ );
177
+ assert!(has_key, "subscription env must receive the proxy key");
178
+ assert_eq!(
179
+ value_len,
180
+ Some(18),
181
+ "copied value length must match the fixture"
182
+ );
183
+ }
184
+
185
+ #[test]
186
+ fn cursor_spawn_writes_identity_into_project_mcp_json() {
187
+ let ws = tmp_dir("cursor-mcp-spawn");
188
+ let team = write_cursor_team(&ws, "cursortm", "cursor_writer");
189
+ let config_path = ws.join(".cursor").join("mcp.json");
190
+ assert!(
191
+ !config_path.exists(),
192
+ "precondition: project cursor mcp.json must be absent before spawn"
193
+ );
194
+
195
+ quick_start_with_transport_in_workspace(
196
+ &ws,
197
+ &team,
198
+ None,
199
+ true,
200
+ Some("cursortm"),
201
+ &OfflineTransport::new(),
202
+ )
203
+ .expect("cursor quick-start through offline transport should spawn");
204
+
205
+ let text = std::fs::read_to_string(&config_path).unwrap_or_else(|err| {
206
+ panic!(
207
+ "cursor spawn must materialize {}; cursor only reads this workspace file: {err}",
208
+ config_path.display()
209
+ )
210
+ });
211
+ let workspace = ws.to_string_lossy();
212
+ assert!(
213
+ text.contains("\"team_orchestrator\""),
214
+ "spawned overlay must declare team_orchestrator"
215
+ );
216
+ assert!(
217
+ text.contains("\"mcp-server\"") && text.contains("\"--workspace\""),
218
+ "args must launch mcp-server"
219
+ );
220
+ assert!(
221
+ text.contains(workspace.as_ref()),
222
+ "workspace must be the real path, not a placeholder"
223
+ );
224
+ assert!(
225
+ text.contains("\"TEAM_AGENT_ID\"") && text.contains("cursor_writer"),
226
+ "identity must be in json env"
227
+ );
228
+ assert!(
229
+ !text.contains("{workspace}")
230
+ && !text.contains("{agent_id}")
231
+ && !text.contains("{team_id}"),
232
+ "placeholders must be resolved before cursor reads the file"
233
+ );
234
+ }
235
+
236
+ fn write_cursor_team(ws: &Path, team_key: &str, agent_id: &str) -> PathBuf {
237
+ let team = ws.join(team_key);
238
+ std::fs::create_dir_all(team.join("agents")).unwrap();
239
+ std::fs::write(
240
+ team.join("TEAM.md"),
241
+ format!(
242
+ "---\nname: {team_key}\nobjective: cursor MCP overlay contract.\nprovider: cursor_agent\ndangerously_skip_permissions: true\n---\n\nTeam.\n"
243
+ ),
244
+ )
245
+ .unwrap();
246
+ std::fs::write(
247
+ team.join("agents").join(format!("{agent_id}.md")),
248
+ format!(
249
+ "---\nname: {agent_id}\nrole: Cursor Writer\nprovider: cursor_agent\nmodel: sonnet-4-thinking\nauth_mode: subscription\ndangerously_skip_permissions: true\ntools:\n - mcp_team\n---\n\nWorker.\n"
250
+ ),
251
+ )
252
+ .unwrap();
253
+ team
254
+ }
255
+
256
+ fn sample_mcp_config(agent_id: &str, workspace: &str) -> McpConfig {
257
+ McpConfig {
258
+ raw: serde_json::json!({
259
+ "team_orchestrator": {
260
+ "command": "/bin/team-agent-test",
261
+ "args": ["mcp-server", "--workspace", workspace],
262
+ "env": {
263
+ "TEAM_AGENT_ID": agent_id,
264
+ "TEAM_AGENT_WORKSPACE": workspace,
265
+ "TEAM_AGENT_OWNER_TEAM_ID": "t1",
266
+ "TEAM_AGENT_AUTH_MODE": "subscription",
267
+ }
268
+ }
269
+ }),
270
+ }
271
+ }
272
+
273
+ fn tmp_dir(tag: &str) -> PathBuf {
274
+ static N: AtomicU64 = AtomicU64::new(0);
275
+ // 见 gate_fixtures::scratch_dir:⛔ 不硬编码绝对路径,默认标准临时目录。
276
+ let root = std::env::var_os("TEAM_AGENT_TEST_TMP")
277
+ .map(PathBuf::from)
278
+ .unwrap_or_else(std::env::temp_dir);
279
+ let dir = root.join(format!(
280
+ "ta-rs-cursor-mcp-{tag}-{}-{}",
281
+ std::process::id(),
282
+ N.fetch_add(1, Ordering::Relaxed)
283
+ ));
284
+ let _ = std::fs::remove_dir_all(&dir);
285
+ std::fs::create_dir_all(&dir).unwrap();
286
+ std::fs::canonicalize(dir).unwrap()
287
+ }
@@ -0,0 +1,229 @@
1
+ //! ---
2
+ //! purpose: cursor 席位角色必须显式写 model;写了 effort 必须编译失败
3
+ //! contract:
4
+ //! provides:
5
+ //! - name: cursor-missing-model-refuses
6
+ //! what: 缺 model 的 cursor 角色启动失败(错误含 model)
7
+ //! - name: cursor-explicit-model-reaches-argv
8
+ //! what: 写了 model 则该值进入 `--model <值>`
9
+ //! - name: cursor-effort-refuses-compile
10
+ //! what: 角色写 effort 则失败,不得丢掉后仍起席
11
+ //! - name: cursor-second-seat-refuses
12
+ //! what: 同 workspace 第二 CursorAgent 拒绝,文案含 TEAM_AGENT_ID/mcp.json
13
+ //! boundary:
14
+ //! - 只钉 Provider::CursorAgent;不改 grok/claude 路径
15
+ //! maturity: wired
16
+ //! ---
17
+
18
+ #![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
19
+
20
+ #[path = "../../../tests/support/hermetic.rs"]
21
+ mod hermetic_guard;
22
+ #[allow(dead_code)]
23
+ fn _hermetic_boundary_marker(_: &hermetic_guard::HermeticTestEnv) {}
24
+
25
+ use std::path::{Path, PathBuf};
26
+ use std::sync::atomic::{AtomicU64, Ordering};
27
+
28
+ use serial_test::serial;
29
+ use team_agent::lifecycle::quick_start_with_transport_in_workspace;
30
+ use team_agent::transport::test_support::OfflineTransport;
31
+
32
+ #[test]
33
+ #[serial(env)]
34
+ fn cursor_role_missing_model_refuses_to_start() {
35
+ let ws = tmp_dir("cursor-no-model");
36
+ let team = write_role_team(&ws, "cursortm", "cursor_writer", None, None);
37
+ let transport = OfflineTransport::new();
38
+ let result = quick_start_with_transport_in_workspace(
39
+ &ws,
40
+ &team,
41
+ None,
42
+ true,
43
+ Some("cursortm"),
44
+ &transport,
45
+ );
46
+ let err = match result {
47
+ Ok(report) => panic!("cursor role without model must refuse; report={report:?}"),
48
+ Err(error) => error.to_string(),
49
+ };
50
+ let lower = err.to_ascii_lowercase();
51
+ assert!(
52
+ lower.contains("model"),
53
+ "error must name the missing field; err={err}"
54
+ );
55
+ assert!(
56
+ lower.contains("built-in") || lower.contains("builtin") || err.contains("内建"),
57
+ "error must name the built-in default; err={err}"
58
+ );
59
+ assert!(
60
+ transport.spawn_records().is_empty(),
61
+ "refusal must happen before spawn; records={:?}",
62
+ transport.spawn_records()
63
+ );
64
+ }
65
+
66
+ #[test]
67
+ #[serial(env)]
68
+ fn cursor_role_explicit_model_reaches_argv() {
69
+ let ws = tmp_dir("cursor-with-model");
70
+ let team = write_role_team(
71
+ &ws,
72
+ "cursortm",
73
+ "cursor_writer",
74
+ Some("sonnet-4-thinking"),
75
+ None,
76
+ );
77
+ let transport = OfflineTransport::new();
78
+ quick_start_with_transport_in_workspace(&ws, &team, None, true, Some("cursortm"), &transport)
79
+ .expect("cursor role with explicit model must start");
80
+ let argv = first_spawn_argv(&transport);
81
+ assert!(
82
+ argv_contains_adjacent(&argv, &["--model", "sonnet-4-thinking"]),
83
+ "declared model must appear; argv={argv:?}"
84
+ );
85
+ assert!(
86
+ argv_contains_adjacent(&argv, &["--trust"]),
87
+ "argv must keep --trust; argv={argv:?}"
88
+ );
89
+ }
90
+
91
+ #[test]
92
+ #[serial(env)]
93
+ fn cursor_role_with_effort_refuses_to_start() {
94
+ let ws = tmp_dir("cursor-effort");
95
+ let team = write_role_team(
96
+ &ws,
97
+ "cursortm",
98
+ "cursor_writer",
99
+ Some("sonnet-4-thinking"),
100
+ Some("high"),
101
+ );
102
+ let transport = OfflineTransport::new();
103
+ let result = quick_start_with_transport_in_workspace(
104
+ &ws,
105
+ &team,
106
+ None,
107
+ true,
108
+ Some("cursortm"),
109
+ &transport,
110
+ );
111
+ let err = match result {
112
+ Ok(report) => panic!("cursor role with effort must refuse; report={report:?}"),
113
+ Err(error) => error.to_string(),
114
+ };
115
+ let lower = err.to_ascii_lowercase();
116
+ assert!(
117
+ lower.contains("effort"),
118
+ "error must name effort; err={err}"
119
+ );
120
+ assert!(
121
+ transport.spawn_records().is_empty(),
122
+ "must refuse before spawn; records={:?}",
123
+ transport.spawn_records()
124
+ );
125
+ }
126
+
127
+ #[test]
128
+ #[serial(env)]
129
+ fn cursor_second_seat_in_same_workspace_is_refused() {
130
+ let ws = tmp_dir("cursor-two");
131
+ let team = ws.join("cursortm");
132
+ std::fs::create_dir_all(team.join("agents")).unwrap();
133
+ std::fs::write(
134
+ team.join("TEAM.md"),
135
+ "---\nname: cursortm\nobjective: two cursor seats.\nprovider: cursor_agent\ndangerously_skip_permissions: true\n---\n\nTeam.\n",
136
+ )
137
+ .unwrap();
138
+ for id in ["cursor_a", "cursor_b"] {
139
+ std::fs::write(
140
+ team.join("agents").join(format!("{id}.md")),
141
+ format!(
142
+ "---\nname: {id}\nrole: Cursor Writer\nprovider: cursor_agent\nmodel: sonnet-4-thinking\nauth_mode: subscription\ndangerously_skip_permissions: true\ntools:\n - mcp_team\n---\n\nWorker.\n"
143
+ ),
144
+ )
145
+ .unwrap();
146
+ }
147
+ let transport = OfflineTransport::new();
148
+ let result = quick_start_with_transport_in_workspace(
149
+ &ws,
150
+ &team,
151
+ None,
152
+ true,
153
+ Some("cursortm"),
154
+ &transport,
155
+ );
156
+ let err = match result {
157
+ Ok(report) => panic!("second cursor seat must refuse; report={report:?}"),
158
+ Err(error) => error.to_string(),
159
+ };
160
+ assert!(
161
+ err.contains("TEAM_AGENT_ID") && err.contains("mcp.json"),
162
+ "error must name the last-writer identity file; err={err}"
163
+ );
164
+ assert!(
165
+ transport.spawn_records().is_empty(),
166
+ "must refuse before any cursor spawn; records={:?}",
167
+ transport.spawn_records()
168
+ );
169
+ }
170
+
171
+ fn first_spawn_argv(transport: &OfflineTransport) -> Vec<String> {
172
+ let records = transport.spawn_records();
173
+ assert!(
174
+ !records.is_empty(),
175
+ "expected a worker spawn; records={records:?}"
176
+ );
177
+ records[0].1.clone()
178
+ }
179
+
180
+ fn argv_contains_adjacent(hay: &[String], needle: &[&str]) -> bool {
181
+ hay.windows(needle.len())
182
+ .any(|window| window.iter().map(String::as_str).eq(needle.iter().copied()))
183
+ }
184
+
185
+ fn write_role_team(
186
+ ws: &Path,
187
+ team_key: &str,
188
+ agent_id: &str,
189
+ model: Option<&str>,
190
+ effort: Option<&str>,
191
+ ) -> PathBuf {
192
+ let team = ws.join(team_key);
193
+ std::fs::create_dir_all(team.join("agents")).unwrap();
194
+ std::fs::write(
195
+ team.join("TEAM.md"),
196
+ format!(
197
+ "---\nname: {team_key}\nobjective: cursor model contract.\nprovider: cursor_agent\ndangerously_skip_permissions: true\n---\n\nTeam.\n"
198
+ ),
199
+ )
200
+ .unwrap();
201
+ let model_line = match model {
202
+ Some(value) => format!("model: {value}\n"),
203
+ None => String::new(),
204
+ };
205
+ let effort_line = match effort {
206
+ Some(value) => format!("effort: {value}\n"),
207
+ None => String::new(),
208
+ };
209
+ std::fs::write(
210
+ team.join("agents").join(format!("{agent_id}.md")),
211
+ format!(
212
+ "---\nname: {agent_id}\nrole: Cursor Writer\nprovider: cursor_agent\n{model_line}{effort_line}auth_mode: subscription\ndangerously_skip_permissions: true\ntools:\n - mcp_team\n---\n\nWorker.\n"
213
+ ),
214
+ )
215
+ .unwrap();
216
+ team
217
+ }
218
+
219
+ fn tmp_dir(tag: &str) -> PathBuf {
220
+ static N: AtomicU64 = AtomicU64::new(0);
221
+ let dir = std::env::temp_dir().join(format!(
222
+ "ta-rs-cursor-model-{tag}-{}-{}",
223
+ std::process::id(),
224
+ N.fetch_add(1, Ordering::Relaxed)
225
+ ));
226
+ let _ = std::fs::remove_dir_all(&dir);
227
+ std::fs::create_dir_all(&dir).unwrap();
228
+ std::fs::canonicalize(dir).unwrap()
229
+ }