@team-agent/installer 0.5.123 → 0.5.125

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 (107) hide show
  1. package/Cargo.lock +1 -8
  2. package/Cargo.toml +1 -1
  3. package/README.md +2 -2
  4. package/README.zh.md +2 -2
  5. package/crates/team-agent/Cargo.toml +0 -1
  6. package/crates/team-agent/src/cli/diagnose.rs +39 -1
  7. package/crates/team-agent/src/cli/emit.rs +41 -15
  8. package/crates/team-agent/src/cli/intent/runtime.rs +30 -54
  9. package/crates/team-agent/src/cli/intent/runtime_tests.rs +59 -118
  10. package/crates/team-agent/src/cli/leader.rs +2 -3
  11. package/crates/team-agent/src/cli/leader_prompt.rs +1 -1
  12. package/crates/team-agent/src/cli/mod.rs +6 -5
  13. package/crates/team-agent/src/cli/models.rs +93 -128
  14. package/crates/team-agent/src/cli/route.rs +1 -1
  15. package/crates/team-agent/src/cli/send/persist.rs +36 -0
  16. package/crates/team-agent/src/cli/send/presentation.rs +7 -1
  17. package/crates/team-agent/src/cli/send.rs +3 -1
  18. package/crates/team-agent/src/cli/spec.rs +1 -2
  19. package/crates/team-agent/src/cli/status_port/brief.rs +66 -0
  20. package/crates/team-agent/src/cli/tests/base.rs +4 -11
  21. package/crates/team-agent/src/cli/tests/status_send.rs +17 -0
  22. package/crates/team-agent/src/compiler/tests.rs +21 -5
  23. package/crates/team-agent/src/compiler.rs +24 -1
  24. package/crates/team-agent/src/contract_runtime/backend.rs +30 -6
  25. package/crates/team-agent/src/contract_runtime/config.rs +34 -24
  26. package/crates/team-agent/src/contract_runtime/discovery.rs +79 -56
  27. package/crates/team-agent/src/contract_runtime/framework.rs +89 -34
  28. package/crates/team-agent/src/contract_runtime/registry.rs +299 -24
  29. package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -1
  30. package/crates/team-agent/src/coordinator/tick.rs +89 -1
  31. package/crates/team-agent/src/db/message_store.rs +78 -3
  32. package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -1
  33. package/crates/team-agent/src/leader/prompt.rs +1 -2
  34. package/crates/team-agent/src/leader/provider_attribution.rs +0 -52
  35. package/crates/team-agent/src/leader/start.rs +0 -1
  36. package/crates/team-agent/src/leader/tests/prompt_contract.rs +2 -3
  37. package/crates/team-agent/src/lifecycle/launch/add_agent.rs +91 -0
  38. package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +14 -1
  39. package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -9
  40. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -1
  41. package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +2 -2
  42. package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +19 -101
  43. package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -28
  44. package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -1
  45. package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -108
  46. package/crates/team-agent/src/lifecycle/launch.rs +2 -20
  47. package/crates/team-agent/src/lifecycle/profile_launch.rs +11 -39
  48. package/crates/team-agent/src/lifecycle/profile_smoke.rs +1 -2
  49. package/crates/team-agent/src/lifecycle/restart/common.rs +1 -63
  50. package/crates/team-agent/src/lifecycle/role_config.rs +42 -3
  51. package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +43 -13
  52. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +6 -2
  53. package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +1 -3
  54. package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +4 -16
  55. package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +1 -3
  56. package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +84 -53
  57. package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +19 -1
  58. package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +21 -0
  59. package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1
  60. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -137
  61. package/crates/team-agent/src/lifecycle/tests.rs +0 -3
  62. package/crates/team-agent/src/lifecycle/worker_command_context.rs +2 -4
  63. package/crates/team-agent/src/mcp_server/readiness.rs +148 -97
  64. package/crates/team-agent/src/mcp_server/readiness_tests.rs +115 -16
  65. package/crates/team-agent/src/messaging/delivery.rs +186 -38
  66. package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +4 -4
  67. package/crates/team-agent/src/messaging/enter_rescue_tests.rs +1 -1
  68. package/crates/team-agent/src/messaging/helpers.rs +19 -0
  69. package/crates/team-agent/src/messaging/tests/dup_inject.rs +66 -4
  70. package/crates/team-agent/src/messaging/tests/runtime.rs +110 -4
  71. package/crates/team-agent/src/messaging/tests/spine.rs +22 -6
  72. package/crates/team-agent/src/model/enums.rs +1 -8
  73. package/crates/team-agent/src/provider/adapter.rs +1 -67
  74. package/crates/team-agent/src/provider/adapters/mod.rs +0 -1
  75. package/crates/team-agent/src/provider/adapters/pi.rs +4 -4
  76. package/crates/team-agent/src/provider/argv_route.rs +1 -5
  77. package/crates/team-agent/src/provider/bypass_flags.rs +3 -11
  78. package/crates/team-agent/src/provider/classify.rs +68 -3
  79. package/crates/team-agent/src/provider/faults.rs +1 -1
  80. package/crates/team-agent/src/provider/model_catalog.rs +2 -73
  81. package/crates/team-agent/src/provider/session/capture.rs +1 -1
  82. package/crates/team-agent/src/provider/session/context_fork.rs +4 -4
  83. package/crates/team-agent/src/provider/session_scan/common.rs +1 -2
  84. package/crates/team-agent/src/provider/session_scan/pi.rs +32 -19
  85. package/crates/team-agent/src/provider/session_scan.rs +0 -4
  86. package/crates/team-agent/src/provider/submit_now.rs +5 -28
  87. package/crates/team-agent/src/provider/tests/adapter.rs +5 -184
  88. package/crates/team-agent/src/provider/tests/classify.rs +53 -0
  89. package/crates/team-agent/src/provider/tests/command_helpers.rs +3 -6
  90. package/crates/team-agent/src/provider/types.rs +1 -1
  91. package/crates/team-agent/src/provider/wire.rs +48 -8
  92. package/crates/team-agent/src/tmux_backend/native_input_tests.rs +2 -178
  93. package/crates/team-agent/src/tmux_backend/tests.rs +151 -0
  94. package/crates/team-agent/src/tmux_backend.rs +43 -8
  95. package/crates/team-agent/src/transport/native_input.rs +2 -231
  96. package/npm/install.mjs +40 -3
  97. package/package.json +4 -4
  98. package/skills/team-agent/SKILL.md +1 -1
  99. package/crates/team-agent/src/lifecycle/launch/cursor_create_chat.rs +0 -229
  100. package/crates/team-agent/src/lifecycle/launch/cursor_mcp.rs +0 -522
  101. package/crates/team-agent/src/lifecycle/launch/cursor_mcp_iso.rs +0 -282
  102. package/crates/team-agent/src/lifecycle/tests/cursor_mcp_overlay.rs +0 -576
  103. package/crates/team-agent/src/lifecycle/tests/cursor_require_explicit_model_red.rs +0 -222
  104. package/crates/team-agent/src/lifecycle/tests/cursor_restart_resume_red.rs +0 -511
  105. package/crates/team-agent/src/provider/adapters/cursor_agent.rs +0 -44
  106. package/crates/team-agent/src/provider/session_scan/cursor.rs +0 -538
  107. package/crates/team-agent/src/provider/testdata/cursor-list-models-native.stdout +0 -250
@@ -1,576 +0,0 @@
1
- //! purpose: cursor 席位必须把身份写进它实际会读的 mcp.json env
2
- //! contract: 隔离默认开时 overlay 写 per-seat 工程根 `.cursor/mcp.json`(`--workspace` /
3
- //! enable cwd 同一根);关隔离时写 `<workspace>/.cursor/mcp.json`。不是
4
- //! `.team/runtime/mcp/*.json`,也不是靠 pane env 继承。
5
- //! boundary: 只覆盖 cursor launch 产物;不改 claude/codex/copilot/grok 路径
6
- //!
7
- //! 生产侧判据,未经血统审计。
8
-
9
- #![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
10
-
11
- #[path = "../../../tests/support/hermetic.rs"]
12
- mod hermetic_guard;
13
- #[allow(dead_code)]
14
- fn _hermetic_boundary_marker(_: &hermetic_guard::HermeticTestEnv) {}
15
-
16
- use std::path::{Path, PathBuf};
17
- use std::sync::atomic::{AtomicU64, Ordering};
18
-
19
- use serial_test::serial;
20
- use team_agent::lifecycle::quick_start_with_transport_in_workspace;
21
- use team_agent::lifecycle::{
22
- apply_cursor_mcp_overlay, apply_cursor_spawn_workspace_pointers,
23
- apply_cursor_subscription_proxy_env, apply_cursor_workspace_physical_path,
24
- cursor_mcp_enable_argv, cursor_mcp_enable_working_dir, cursor_mcp_json_path,
25
- cursor_mcp_project_dir, physical_workspace_path, prepare_cursor_seat_mcp, LifecycleError,
26
- };
27
- use team_agent::provider::McpConfig;
28
- use team_agent::transport::test_support::OfflineTransport;
29
-
30
- #[test]
31
- fn cursor_overlay_writes_identity_into_mcp_json_env() {
32
- let ws = tmp_dir("cursor-mcp-id");
33
- apply_cursor_mcp_overlay(&ws, &sample_mcp_config("seat-a", &ws.to_string_lossy()))
34
- .expect("overlay write");
35
- let text = std::fs::read_to_string(ws.join(".cursor/mcp.json")).unwrap();
36
- assert!(
37
- text.contains("\"team_orchestrator\""),
38
- "cursor overlay must use the canonical server name"
39
- );
40
- assert!(
41
- text.contains("\"TEAM_AGENT_ID\"") && text.contains("seat-a"),
42
- "cursor must write TEAM_AGENT_ID into json env; pane env is not inherited"
43
- );
44
- assert!(
45
- text.contains("\"TEAM_AGENT_OWNER_TEAM_ID\"") && text.contains("t1"),
46
- "owner team must live in json env"
47
- );
48
- assert!(
49
- text.contains("\"TEAM_AGENT_AUTH_MODE\"") && text.contains("subscription"),
50
- "auth mode must live in json env"
51
- );
52
- assert!(
53
- !text.contains("{workspace}") && !text.contains("{agent_id}"),
54
- "placeholders must already be resolved"
55
- );
56
- assert!(
57
- !text.contains("\"team-agent\""),
58
- "legacy inbound key must not remain as a server name"
59
- );
60
- }
61
-
62
- #[test]
63
- fn cursor_overlay_refuses_missing_identity() {
64
- let ws = tmp_dir("cursor-mcp-missing-id");
65
- let cfg = McpConfig {
66
- raw: serde_json::json!({
67
- "team_orchestrator": {
68
- "command": "/bin/team-agent-test",
69
- "args": ["mcp-server"],
70
- "env": { "TEAM_AGENT_WORKSPACE": "/ws" }
71
- }
72
- }),
73
- };
74
- let err = apply_cursor_mcp_overlay(&ws, &cfg).expect_err("missing TEAM_AGENT_ID must fail");
75
- match err {
76
- LifecycleError::StatePersist(text) => {
77
- assert!(
78
- text.contains("TEAM_AGENT_ID"),
79
- "refusal must name the missing identity key"
80
- );
81
- }
82
- other => panic!("expected StatePersist, got {other:?}"),
83
- }
84
- }
85
-
86
- #[test]
87
- fn cursor_overlay_keeps_unrelated_servers_and_replaces_orchestrator() {
88
- let ws = tmp_dir("cursor-mcp-merge");
89
- let dir = ws.join(".cursor");
90
- std::fs::create_dir_all(&dir).unwrap();
91
- std::fs::write(
92
- dir.join("mcp.json"),
93
- r#"{
94
- "mcpServers": {
95
- "keep-me": { "command": "/bin/keep" },
96
- "team-agent": { "command": "/old/team-agent" },
97
- "team_orchestrator": { "command": "/stale" }
98
- }
99
- }"#,
100
- )
101
- .unwrap();
102
-
103
- apply_cursor_mcp_overlay(&ws, &sample_mcp_config("seat-b", "/ws-b")).expect("overlay merge");
104
- let text = std::fs::read_to_string(dir.join("mcp.json")).unwrap();
105
- assert!(
106
- text.contains("keep-me"),
107
- "unrelated project MCP servers must survive"
108
- );
109
- assert!(
110
- !text.contains("/old/team-agent") && !text.contains("/stale"),
111
- "stale orchestrator/legacy names must be replaced"
112
- );
113
- assert!(
114
- text.contains("seat-b") && text.contains("/ws-b"),
115
- "new identity must land"
116
- );
117
- }
118
-
119
- #[test]
120
- fn cursor_second_seat_overwrites_json_identity_without_exclusive_gate() {
121
- let ws = tmp_dir("cursor-mcp-two");
122
- apply_cursor_mcp_overlay(&ws, &sample_mcp_config("first", "/ws")).expect("first");
123
- apply_cursor_mcp_overlay(&ws, &sample_mcp_config("second", "/ws")).expect("second");
124
- let text = std::fs::read_to_string(ws.join(".cursor/mcp.json")).unwrap();
125
- assert!(
126
- text.contains("second"),
127
- "last writer wins on a shared --workspace; no grok-style exclusive gate"
128
- );
129
- assert!(
130
- !text.contains("\"first\""),
131
- "previous seat identity must not remain in the single json file"
132
- );
133
- }
134
-
135
- #[test]
136
- fn cursor_enable_argv_is_documented_subcommand_without_workspace_flag() {
137
- let argv = cursor_mcp_enable_argv();
138
- assert_eq!(
139
- argv,
140
- vec![
141
- "agent".to_string(),
142
- "mcp".to_string(),
143
- "enable".to_string(),
144
- "team_orchestrator".to_string()
145
- ]
146
- );
147
- }
148
-
149
- #[test]
150
- fn cursor_workspace_flag_is_rewritten_to_physical_path() {
151
- let ws = tmp_dir("cursor-phys");
152
- let mut argv = vec![
153
- "agent".to_string(),
154
- "--workspace".to_string(),
155
- ws.to_string_lossy().into_owned(),
156
- ];
157
- apply_cursor_workspace_physical_path(&mut argv, &ws);
158
- let physical = physical_workspace_path(&ws);
159
- assert_eq!(argv[2], physical.to_string_lossy().as_ref());
160
- }
161
-
162
- #[test]
163
- #[serial(env)]
164
- fn cursor_subscription_proxy_copies_keys_without_requiring_profile() {
165
- let prev = std::env::var("HTTPS_PROXY").ok();
166
- std::env::set_var("HTTPS_PROXY", "http://127.0.0.1:9");
167
- let mut env = std::collections::BTreeMap::new();
168
- let presence = apply_cursor_subscription_proxy_env(&mut env);
169
- let has_key = env.contains_key("HTTPS_PROXY");
170
- let value_len = env.get("HTTPS_PROXY").map(String::len);
171
- match prev {
172
- Some(value) => std::env::set_var("HTTPS_PROXY", value),
173
- None => std::env::remove_var("HTTPS_PROXY"),
174
- }
175
- assert!(
176
- presence.https_proxy,
177
- "presence must be true when the process has HTTPS_PROXY"
178
- );
179
- assert!(has_key, "subscription env must receive the proxy key");
180
- assert_eq!(
181
- value_len,
182
- Some(18),
183
- "copied value length must match the fixture"
184
- );
185
- }
186
-
187
- #[test]
188
- fn cursor_subscription_direct_profile_unsets_only_proxy_url_keys() {
189
- let ws = tmp_dir("cursor-profile-direct");
190
- let profiles = ws.join(".team/current/profiles");
191
- std::fs::create_dir_all(&profiles).unwrap();
192
- std::fs::write(
193
- profiles.join("cursor.env"),
194
- "AUTH_MODE=subscription\nPROFILE_NAME=cursor\nPROXY_MODE=direct\n",
195
- )
196
- .unwrap();
197
-
198
- let launch = crate::lifecycle::profile_launch::prepare_provider_profile_launch_from_json(
199
- &ws,
200
- "cursor",
201
- &serde_json::json!({
202
- "id": "cursor",
203
- "provider": "cursor_agent",
204
- "auth_mode": "subscription",
205
- "profile": "cursor"
206
- }),
207
- None,
208
- )
209
- .expect("direct Cursor profile should prepare");
210
- for key in [
211
- "HTTPS_PROXY",
212
- "HTTP_PROXY",
213
- "ALL_PROXY",
214
- "https_proxy",
215
- "http_proxy",
216
- "all_proxy",
217
- "GLOBAL_AGENT_HTTPS_PROXY",
218
- "GLOBAL_AGENT_HTTP_PROXY",
219
- ] {
220
- assert!(launch.env_unset.contains(key), "direct must unset {key}");
221
- }
222
- assert!(!launch.env_unset.contains("NO_PROXY"));
223
- assert!(!launch.env_unset.contains("no_proxy"));
224
- }
225
-
226
- #[test]
227
- fn cursor_mcp_enable_child_env_applies_direct_profile_unsets() {
228
- let ws = tmp_dir("cursor-profile-enable-env");
229
- let profiles = ws.join(".team/current/profiles");
230
- std::fs::create_dir_all(&profiles).unwrap();
231
- std::fs::write(
232
- profiles.join("cursor.env"),
233
- "AUTH_MODE=subscription\nPROFILE_NAME=cursor\nPROXY_MODE=direct\n",
234
- )
235
- .unwrap();
236
- let launch = crate::lifecycle::profile_launch::prepare_provider_profile_launch_from_json(
237
- &ws,
238
- "cursor",
239
- &serde_json::json!({
240
- "id": "cursor",
241
- "provider": "cursor_agent",
242
- "auth_mode": "subscription",
243
- "profile": "cursor"
244
- }),
245
- None,
246
- )
247
- .expect("direct Cursor profile should prepare");
248
-
249
- let mut command = std::process::Command::new("/usr/bin/env");
250
- command.env_clear();
251
- for key in [
252
- "HTTPS_PROXY",
253
- "HTTP_PROXY",
254
- "ALL_PROXY",
255
- "https_proxy",
256
- "http_proxy",
257
- "all_proxy",
258
- "GLOBAL_AGENT_HTTPS_PROXY",
259
- "GLOBAL_AGENT_HTTP_PROXY",
260
- ] {
261
- command.env(key, "fixture");
262
- }
263
- command.env("NO_PROXY", "fixture");
264
- command.env("no_proxy", "fixture");
265
- crate::lifecycle::launch::apply_cursor_mcp_enable_profile_env(&mut command, Some(&launch));
266
- let output = command.output().expect("env child should run");
267
- assert!(output.status.success());
268
- let text = String::from_utf8(output.stdout).unwrap();
269
- for key in [
270
- "HTTPS_PROXY",
271
- "HTTP_PROXY",
272
- "ALL_PROXY",
273
- "https_proxy",
274
- "http_proxy",
275
- "all_proxy",
276
- "GLOBAL_AGENT_HTTPS_PROXY",
277
- "GLOBAL_AGENT_HTTP_PROXY",
278
- ] {
279
- assert!(
280
- !text
281
- .lines()
282
- .any(|line| line.starts_with(&format!("{key}="))),
283
- "direct MCP child must omit {key}"
284
- );
285
- }
286
- assert!(text.lines().any(|line| line == "NO_PROXY=fixture"));
287
- assert!(text.lines().any(|line| line == "no_proxy=fixture"));
288
- }
289
-
290
- #[test]
291
- #[serial(env)]
292
- fn cursor_spawn_writes_identity_into_project_mcp_json() {
293
- let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("cursor-mcp-spawn");
294
- let ws = tmp_dir("cursor-mcp-spawn");
295
- super::launch_spawn::seed_healthy_coordinator(&ws);
296
- let team = write_cursor_team(&ws, "cursortm", "cursor_writer");
297
- let selected = cursor_mcp_json_path(&ws, "cursor_writer").unwrap();
298
- assert!(
299
- !selected.exists() && !ws.join(".cursor/mcp.json").exists(),
300
- "precondition: selected project and workspace overlay must be absent before spawn"
301
- );
302
-
303
- quick_start_with_transport_in_workspace(
304
- &ws,
305
- &team,
306
- None,
307
- true,
308
- Some("cursortm"),
309
- &OfflineTransport::new(),
310
- )
311
- .expect("cursor quick-start through offline transport should spawn");
312
-
313
- let text = std::fs::read_to_string(&selected).unwrap_or_else(|err| {
314
- panic!(
315
- "cursor spawn must materialize {}; isolation default reads this per-seat file: {err}",
316
- selected.display()
317
- )
318
- });
319
- assert_cursor_identity_overlay(&text, "cursor_writer", &ws);
320
- assert!(
321
- !ws.join(".cursor/mcp.json").exists(),
322
- "default isolation must not dual-write the team workspace overlay"
323
- );
324
- let project = cursor_mcp_project_dir(&ws, "cursor_writer").unwrap();
325
- let enable_cwd = cursor_mcp_enable_working_dir(&ws, Some(&project));
326
- assert_eq!(enable_cwd, physical_workspace_path(&project));
327
- let argv_workspace = spawn_argv_workspace_flag(&ws).expect("spawn argv --workspace");
328
- assert_eq!(
329
- argv_workspace,
330
- physical_workspace_path(&project).to_string_lossy()
331
- );
332
- let state = crate::state::persist::load_runtime_state(&ws).unwrap();
333
- let row = state.pointer("/agents/cursor_writer").unwrap();
334
- assert_eq!(row["spawn_cwd"], project.to_string_lossy().as_ref());
335
- assert_eq!(row["session_id"], serde_json::Value::Null);
336
-
337
- // Measured native layout: the store bucket uses --workspace primary, not
338
- // --add-dir. A decoy in the real project's bucket must never be selected.
339
- let sid = "d298b261-23bb-42bb-bbeb-b2ec08d81ca3";
340
- for (cwd, id) in [(&project, sid), (&ws, "foreign-project-session")] {
341
- let bucket = format!("{:x}", md5::compute(cwd.to_string_lossy().as_bytes()));
342
- let archive = _hermetic.home().join(".cursor/chats").join(bucket).join(id);
343
- std::fs::create_dir_all(&archive).unwrap();
344
- std::fs::write(archive.join("meta.json"), b"{}").unwrap();
345
- }
346
- let mut capture = serde_json::json!({"agents": {"cursor_writer": row.clone()}});
347
- let report = crate::provider::session::capture::capture_missing_provider_sessions_once(
348
- &mut capture,
349
- &mut crate::provider::get_adapter,
350
- false,
351
- 0,
352
- )
353
- .unwrap();
354
- assert_eq!(report.assigned, vec!["cursor_writer"]);
355
- assert_eq!(capture["agents"]["cursor_writer"]["session_id"], sid);
356
- assert_eq!(
357
- capture["agents"]["cursor_writer"]["spawn_cwd"],
358
- project.to_string_lossy().as_ref()
359
- );
360
- }
361
-
362
- #[test]
363
- #[serial(env)]
364
- fn cursor_spawn_isolation_off_writes_workspace_mcp_json() {
365
- let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("cursor-mcp-spawn-legacy");
366
- let key = "TEAM_AGENT_CURSOR_MCP_ISOLATION";
367
- let prev = std::env::var(key).ok();
368
- std::env::set_var(key, "0");
369
- let ws = tmp_dir("cursor-mcp-spawn-legacy");
370
- super::launch_spawn::seed_healthy_coordinator(&ws);
371
- let team = write_cursor_team(&ws, "cursortm", "cursor_writer");
372
- let result = quick_start_with_transport_in_workspace(
373
- &ws,
374
- &team,
375
- None,
376
- true,
377
- Some("cursortm"),
378
- &OfflineTransport::new(),
379
- );
380
- match prev {
381
- Some(value) => std::env::set_var(key, value),
382
- None => std::env::remove_var(key),
383
- }
384
- result.expect("legacy isolation-off cursor spawn");
385
- let config_path = ws.join(".cursor").join("mcp.json");
386
- let text = std::fs::read_to_string(&config_path).unwrap_or_else(|err| {
387
- panic!(
388
- "isolation-off spawn must write {}; cursor --workspace is the team root: {err}",
389
- config_path.display()
390
- )
391
- });
392
- assert_cursor_identity_overlay(&text, "cursor_writer", &ws);
393
- assert!(
394
- !cursor_mcp_json_path(&ws, "cursor_writer").unwrap().exists(),
395
- "isolation-off must not materialize the per-seat project overlay"
396
- );
397
- let argv_workspace = spawn_argv_workspace_flag(&ws).expect("spawn argv --workspace");
398
- assert_eq!(
399
- argv_workspace,
400
- physical_workspace_path(&ws).to_string_lossy()
401
- );
402
- }
403
-
404
- fn assert_cursor_identity_overlay(text: &str, agent_id: &str, workspace: &Path) {
405
- let workspace = workspace.to_string_lossy();
406
- assert!(
407
- text.contains("\"team_orchestrator\""),
408
- "spawned overlay must declare team_orchestrator"
409
- );
410
- assert!(
411
- text.contains("\"mcp-server\"") && text.contains("\"--workspace\""),
412
- "args must launch mcp-server"
413
- );
414
- assert!(
415
- text.contains(workspace.as_ref()),
416
- "TEAM_AGENT_WORKSPACE / mcp args must be the real team path, not a placeholder"
417
- );
418
- assert!(
419
- text.contains("\"TEAM_AGENT_ID\"") && text.contains(agent_id),
420
- "identity must be in json env"
421
- );
422
- assert!(
423
- !text.contains("{workspace}")
424
- && !text.contains("{agent_id}")
425
- && !text.contains("{team_id}"),
426
- "placeholders must be resolved before cursor reads the file"
427
- );
428
- }
429
-
430
- fn spawn_argv_workspace_flag(workspace: &Path) -> Option<String> {
431
- let log = workspace.join(".team").join("logs").join("events.jsonl");
432
- let text = std::fs::read_to_string(log).ok()?;
433
- for line in text.lines().rev() {
434
- let value: serde_json::Value = serde_json::from_str(line).ok()?;
435
- if value.get("event").and_then(serde_json::Value::as_str)
436
- != Some("provider.worker.spawn_argv")
437
- {
438
- continue;
439
- }
440
- let argv = value.get("argv")?.as_array()?;
441
- let mut items = argv.iter().filter_map(serde_json::Value::as_str);
442
- while let Some(item) = items.next() {
443
- if item == "--workspace" {
444
- return items.next().map(str::to_string);
445
- }
446
- }
447
- }
448
- None
449
- }
450
-
451
- fn write_cursor_team(ws: &Path, team_key: &str, agent_id: &str) -> PathBuf {
452
- let team = ws.join(team_key);
453
- std::fs::create_dir_all(team.join("agents")).unwrap();
454
- std::fs::write(
455
- team.join("TEAM.md"),
456
- format!(
457
- "---\nname: {team_key}\nobjective: cursor MCP overlay contract.\nprovider: cursor_agent\ndangerously_skip_permissions: true\n---\n\nTeam.\n"
458
- ),
459
- )
460
- .unwrap();
461
- std::fs::write(
462
- team.join("agents").join(format!("{agent_id}.md")),
463
- format!(
464
- "---\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"
465
- ),
466
- )
467
- .unwrap();
468
- team
469
- }
470
-
471
- fn sample_mcp_config(agent_id: &str, workspace: &str) -> McpConfig {
472
- McpConfig {
473
- raw: serde_json::json!({
474
- "team_orchestrator": {
475
- "command": std::env::current_exe().unwrap(),
476
- "args": ["mcp-server", "--workspace", workspace],
477
- "env": {
478
- "TEAM_AGENT_ID": agent_id,
479
- "TEAM_AGENT_WORKSPACE": workspace,
480
- "TEAM_AGENT_OWNER_TEAM_ID": "t1",
481
- "TEAM_AGENT_AUTH_MODE": "subscription",
482
- }
483
- }
484
- }),
485
- }
486
- }
487
-
488
- #[test]
489
- #[serial(env)]
490
- fn isolated_cursor_prepare_materializes_per_seat_project_not_workspace_overlay() {
491
- let ws = tmp_dir("cursor-iso-clean");
492
- let project = prepare_cursor_seat_mcp(
493
- &ws,
494
- "seat-iso",
495
- &sample_mcp_config("seat-iso", &ws.to_string_lossy()),
496
- )
497
- .expect("prepare isolated cursor")
498
- .expect("isolation defaults on");
499
- assert!(
500
- !project.starts_with(&ws)
501
- && project
502
- .file_name()
503
- .unwrap()
504
- .to_string_lossy()
505
- .starts_with("ta-cursor-"),
506
- "per-seat native project must be outside workspace Git ancestry: {}",
507
- project.display()
508
- );
509
- assert!(project.join(".cursor").is_dir());
510
- let overlay = std::fs::read_to_string(cursor_mcp_json_path(&ws, "seat-iso").unwrap()).unwrap();
511
- assert!(
512
- overlay.contains("seat-iso") && overlay.contains("team_orchestrator"),
513
- "overlay must land in the per-seat mcp.json"
514
- );
515
- assert!(
516
- !ws.join(".cursor/mcp.json").exists(),
517
- "clean workspace overlay must not be written when isolation is on"
518
- );
519
- let enable_cwd = cursor_mcp_enable_working_dir(&ws, Some(&project));
520
- assert_eq!(enable_cwd, physical_workspace_path(&project));
521
- let mut argv = vec![
522
- "agent".to_string(),
523
- "--workspace".to_string(),
524
- ws.to_string_lossy().into_owned(),
525
- ];
526
- apply_cursor_spawn_workspace_pointers(&mut argv, &ws, "seat-iso").unwrap();
527
- let workspace_flag = argv
528
- .windows(2)
529
- .find(|pair| pair[0] == "--workspace")
530
- .map(|pair| pair[1].as_str())
531
- .unwrap();
532
- assert_eq!(
533
- workspace_flag,
534
- physical_workspace_path(&project).to_string_lossy()
535
- );
536
- assert_eq!(
537
- include_str!("../launch/spawn.rs").contains("prepare_cursor_seat_mcp("),
538
- true,
539
- "fresh spawn must call the shared materializer, not only compute the path"
540
- );
541
- assert!(
542
- include_str!("../restart/common.rs").contains("prepare_cursor_seat_mcp("),
543
- "restart spawn_agent_window must use the same materializer"
544
- );
545
- }
546
-
547
- #[test]
548
- fn cursor_enable_working_dir_does_not_depend_on_cfg_test_skip() {
549
- let ws = tmp_dir("cursor-enable-cwd");
550
- let project = ws.join(".team/runtime/provider-config/seat/cursor");
551
- std::fs::create_dir_all(&project).unwrap();
552
- assert_eq!(
553
- cursor_mcp_enable_working_dir(&ws, Some(&project)),
554
- physical_workspace_path(&project)
555
- );
556
- assert_eq!(
557
- cursor_mcp_enable_working_dir(&ws, None),
558
- physical_workspace_path(&ws)
559
- );
560
- }
561
-
562
- fn tmp_dir(tag: &str) -> PathBuf {
563
- static N: AtomicU64 = AtomicU64::new(0);
564
- // 见 gate_fixtures::scratch_dir:⛔ 不硬编码绝对路径,默认标准临时目录。
565
- let root = std::env::var_os("TEAM_AGENT_TEST_TMP")
566
- .map(PathBuf::from)
567
- .unwrap_or_else(std::env::temp_dir);
568
- let dir = root.join(format!(
569
- "ta-rs-cursor-mcp-{tag}-{}-{}",
570
- std::process::id(),
571
- N.fetch_add(1, Ordering::Relaxed)
572
- ));
573
- let _ = std::fs::remove_dir_all(&dir);
574
- std::fs::create_dir_all(&dir).unwrap();
575
- std::fs::canonicalize(dir).unwrap()
576
- }