@team-agent/installer 0.5.121 → 0.5.123
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.
- package/Cargo.lock +8 -1
- package/Cargo.toml +1 -1
- package/crates/team-agent/src/cli/diagnose.rs +176 -10
- package/crates/team-agent/src/cli/intent/runtime.rs +78 -42
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +137 -0
- package/crates/team-agent/src/cli/intent/tests.rs +37 -0
- package/crates/team-agent/src/cli/intent.rs +22 -0
- package/crates/team-agent/src/contract_runtime/backend.rs +490 -2
- package/crates/team-agent/src/contract_runtime/commands.rs +38 -24
- package/crates/team-agent/src/contract_runtime/forward.rs +59 -0
- package/crates/team-agent/src/contract_runtime/framework.rs +23 -17
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +27 -8
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +6 -17
- package/crates/team-agent/src/lifecycle/launch/quick_start_transport.rs +26 -19
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +19 -2
- package/crates/team-agent/src/lifecycle/restart/agent.rs +3 -0
- package/crates/team-agent/src/lifecycle/restart/common.rs +3 -0
- package/crates/team-agent/src/lifecycle/restart/rebuild.rs +100 -31
- package/crates/team-agent/src/lifecycle/restart.rs +1 -0
- package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +16 -3
- package/crates/team-agent/src/lifecycle/tests/cursor_restart_resume_red.rs +132 -1
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +7 -5
- package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +8 -2
- package/crates/team-agent/src/mcp_server/readiness.rs +66 -3
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +30 -0
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +12 -1
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +48 -4
- package/crates/team-agent/src/messaging/tests/spine.rs +45 -14
- package/crates/team-agent/src/provider/wire.rs +2 -1
- package/npm/install.mjs +17 -97
- package/package.json +4 -4
|
@@ -320,27 +320,15 @@ pub(crate) fn restart_with_transport_with_session_convergence_deadline(
|
|
|
320
320
|
crate::model::paths::runtime_dir(&resolved_ws).display()
|
|
321
321
|
)));
|
|
322
322
|
}
|
|
323
|
-
//
|
|
324
|
-
//
|
|
325
|
-
//
|
|
326
|
-
|
|
327
|
-
let selected = crate::state::selector::resolve_active_team(
|
|
323
|
+
// The spec is derived. Select runtime identity first; the locked owner/source
|
|
324
|
+
// admission below rebuilds it before any teardown. Requiring it here made
|
|
325
|
+
// the advertised missing-spec recovery command reject its own prerequisite.
|
|
326
|
+
let selected = crate::state::selector::resolve_active_team_readonly(
|
|
328
327
|
workspace,
|
|
329
328
|
team,
|
|
330
|
-
crate::state::selector::SelectorMode::
|
|
329
|
+
crate::state::selector::SelectorMode::RuntimeOnly,
|
|
331
330
|
)
|
|
332
331
|
.map_err(|e| LifecycleError::TeamSelect(e.to_string()))?;
|
|
333
|
-
// 显式存在性门(下移后):selected.spec_path 经读序 B 已定位 runtime/legacy spec。
|
|
334
|
-
// 缺(空目录 restart 等)→ 报真实期望路径,不误导去用户目录找。
|
|
335
|
-
if !selected.spec_path.as_ref().is_some_and(|p| p.exists()) {
|
|
336
|
-
let expected = selected.spec_path.clone().unwrap_or_else(|| {
|
|
337
|
-
crate::model::paths::runtime_spec_path(&selected.run_workspace, &selected.team_key)
|
|
338
|
-
});
|
|
339
|
-
return Err(LifecycleError::TeamSelect(format!(
|
|
340
|
-
"missing spec for restart: {} (run `team-agent quick-start <teamdir>` first, or restore the team's role docs)",
|
|
341
|
-
expected.display()
|
|
342
|
-
)));
|
|
343
|
-
}
|
|
344
332
|
restart_with_selected_team_and_transport(
|
|
345
333
|
selected,
|
|
346
334
|
allow_fresh,
|
|
@@ -373,10 +361,10 @@ fn restart_with_selected_team_and_transport(
|
|
|
373
361
|
})?;
|
|
374
362
|
// Selection happened before the lifecycle lock. A stop-agent that won the
|
|
375
363
|
// lock must not be undone by the old running snapshot used by restart.
|
|
376
|
-
let mut state = crate::state::selector::
|
|
364
|
+
let mut state = crate::state::selector::resolve_active_team_readonly(
|
|
377
365
|
&selected.run_workspace,
|
|
378
366
|
Some(selected.team_key.as_str()),
|
|
379
|
-
crate::state::selector::SelectorMode::
|
|
367
|
+
crate::state::selector::SelectorMode::RuntimeOnly,
|
|
380
368
|
)
|
|
381
369
|
.map_err(|error| LifecycleError::TeamSelect(error.to_string()))?
|
|
382
370
|
.state;
|
|
@@ -581,9 +569,18 @@ fn restart_with_selected_team_and_transport(
|
|
|
581
569
|
// no authoritative live agents, the previous behavior (pre-spawn
|
|
582
570
|
// teardown of a stale empty session) is preserved so tests that
|
|
583
571
|
// seed a fake-live session without live agent rows still work.
|
|
572
|
+
#[cfg(unix)]
|
|
573
|
+
let shared_native_windows = crate::contract_runtime::backend::has_shared_windows(
|
|
574
|
+
&selected.run_workspace, &selected.team_key,
|
|
575
|
+
).map_err(|error| LifecycleError::RequirementUnmet(error.to_string()))?;
|
|
576
|
+
#[cfg(not(unix))]
|
|
577
|
+
let shared_native_windows = false;
|
|
578
|
+
// Canonical windows share this session but are NOT legacy restart targets.
|
|
579
|
+
// Keep the session, and retire only each successful legacy replacement's
|
|
580
|
+
// exact old pane through the existing build-before-destroy path.
|
|
584
581
|
let live_worker_session_deferred_teardown =
|
|
585
582
|
session_live_or_default(transport, &session_name, false)
|
|
586
|
-
&& !collect_live_agents_from_state(&state).is_empty();
|
|
583
|
+
&& (shared_native_windows || !collect_live_agents_from_state(&state).is_empty());
|
|
587
584
|
let inherited_generation =
|
|
588
585
|
crate::state::projection::session_generation(&state).map(str::to_string);
|
|
589
586
|
let same_role_cohort_targets =
|
|
@@ -598,8 +595,8 @@ fn restart_with_selected_team_and_transport(
|
|
|
598
595
|
} else {
|
|
599
596
|
std::collections::BTreeSet::new()
|
|
600
597
|
};
|
|
601
|
-
if session_live_or_default(transport, &session_name, false)
|
|
602
|
-
|
|
598
|
+
if destroy_stale_worker_session(session_live_or_default(transport, &session_name, false),
|
|
599
|
+
live_worker_session_deferred_teardown, shared_native_windows)
|
|
603
600
|
{
|
|
604
601
|
eprintln!(
|
|
605
602
|
"team_agent::layout restart_precondition_warning worker_session=`{}` action=killing \
|
|
@@ -2480,6 +2477,9 @@ fn mark_agent_respawned(
|
|
|
2480
2477
|
"spawn_cwd".to_string(),
|
|
2481
2478
|
serde_json::json!(spawn.spawn_cwd.to_string_lossy().to_string()),
|
|
2482
2479
|
);
|
|
2480
|
+
if let Some(path) = &spawn.mcp_config_path {
|
|
2481
|
+
agent.insert("mcp_config".to_string(), serde_json::json!(path));
|
|
2482
|
+
}
|
|
2483
2483
|
// 0.5.38 (`.team/artifacts/startup-latency-locate.md` §7): every
|
|
2484
2484
|
// multi-worker restart respawn is a fresh process cohort. The
|
|
2485
2485
|
// pre-0.5.38 code only wrote `spawned_at` here and left `spawn_epoch`
|
|
@@ -2968,6 +2968,7 @@ impl Clone for ParallelSpawnResult {
|
|
|
2968
2968
|
profile_launch: self.spawn.profile_launch.clone(),
|
|
2969
2969
|
layout_placement: self.spawn.layout_placement.clone(),
|
|
2970
2970
|
spawn_cwd: self.spawn.spawn_cwd.clone(),
|
|
2971
|
+
mcp_config_path: self.spawn.mcp_config_path.clone(),
|
|
2971
2972
|
owner_team_id: self.spawn.owner_team_id.clone(),
|
|
2972
2973
|
},
|
|
2973
2974
|
spawn_start: self.spawn_start,
|
|
@@ -3694,6 +3695,26 @@ fn rebuild_runtime_spec_from_roles(
|
|
|
3694
3695
|
run_workspace: &Path,
|
|
3695
3696
|
team_key: &str,
|
|
3696
3697
|
state: &serde_json::Value,
|
|
3698
|
+
) -> Result<YamlValue, LifecycleError> {
|
|
3699
|
+
let spec = compile_runtime_spec_from_roles(run_workspace, team_key, state)?;
|
|
3700
|
+
let spec_path = crate::model::paths::runtime_spec_path(run_workspace, team_key);
|
|
3701
|
+
crate::lifecycle::launch::write_spec_atomic(&spec_path, &spec)?;
|
|
3702
|
+
let team_dir = state.get("team_dir").and_then(serde_json::Value::as_str)
|
|
3703
|
+
.filter(|s| !s.is_empty()).map(std::path::PathBuf::from)
|
|
3704
|
+
.unwrap_or_else(|| run_workspace.to_path_buf());
|
|
3705
|
+
let legacy_spec = team_dir.join("team.spec.yaml");
|
|
3706
|
+
if legacy_spec.exists() && legacy_spec != spec_path {
|
|
3707
|
+
let _ = std::fs::remove_file(&legacy_spec);
|
|
3708
|
+
}
|
|
3709
|
+
Ok(spec)
|
|
3710
|
+
}
|
|
3711
|
+
|
|
3712
|
+
/// Read-only counterpart of restart's existing compiler. It preserves dynamic
|
|
3713
|
+
/// role sources, retired-seat filtering and the established session override.
|
|
3714
|
+
pub(crate) fn compile_runtime_spec_from_roles(
|
|
3715
|
+
run_workspace: &Path,
|
|
3716
|
+
team_key: &str,
|
|
3717
|
+
state: &serde_json::Value,
|
|
3697
3718
|
) -> Result<YamlValue, LifecycleError> {
|
|
3698
3719
|
// team_dir(角色定义源)优先取 state.team_dir;缺则回落 run_workspace(自含 team-dir 布局,
|
|
3699
3720
|
// run_workspace 本身即角色目录)。两者都无角色定义则下面的齐全性检查会显式拒。
|
|
@@ -3754,18 +3775,52 @@ fn rebuild_runtime_spec_from_roles(
|
|
|
3754
3775
|
// 三行式,不静默 prune 已 live 的 helper(persist SaveConflict 保护继续生效)。
|
|
3755
3776
|
merge_state_dynamic_role_files(&mut spec, run_workspace, &team_dir, team_key, state)?;
|
|
3756
3777
|
filter_retired_agents_from_spec(&mut spec, &retired_agent_ids(state));
|
|
3757
|
-
// 写 runtime spec(覆盖,原子 tmp+rename;Bug2)。
|
|
3758
|
-
let spec_path = crate::model::paths::runtime_spec_path(run_workspace, team_key);
|
|
3759
|
-
crate::lifecycle::launch::write_spec_atomic(&spec_path, &spec)?;
|
|
3760
|
-
// RC-A6a:重建成功后清理用户目录的 legacy spec(中间产物不该留在角色目录)。
|
|
3761
|
-
// 仅删 team_dir 下的 team.spec.yaml(角色定义 TEAM.md/agents 不动);失败不致命(best-effort)。
|
|
3762
|
-
let legacy_spec = team_dir.join("team.spec.yaml");
|
|
3763
|
-
if legacy_spec.exists() && legacy_spec != spec_path {
|
|
3764
|
-
let _ = std::fs::remove_file(&legacy_spec);
|
|
3765
|
-
}
|
|
3766
3778
|
Ok(spec)
|
|
3767
3779
|
}
|
|
3768
3780
|
|
|
3781
|
+
/// Repair only derived metadata. The caller's readonly plan is checked again
|
|
3782
|
+
/// under lifecycle ownership; no process/session/control action is performed.
|
|
3783
|
+
pub(crate) fn restore_missing_runtime_spec(
|
|
3784
|
+
workspace: &Path,
|
|
3785
|
+
team: &str,
|
|
3786
|
+
expected: &YamlValue,
|
|
3787
|
+
) -> Result<std::path::PathBuf, LifecycleError> {
|
|
3788
|
+
let run_workspace = crate::model::paths::canonical_run_workspace(workspace)
|
|
3789
|
+
.map_err(|e| LifecycleError::StatePersist(e.to_string()))?;
|
|
3790
|
+
let _lock = acquire_agent_lifecycle_lock(LifecycleLockRequest {
|
|
3791
|
+
workspace: &run_workspace, operation: "restore-runtime-spec", team: Some(team), agent_id: None,
|
|
3792
|
+
})?;
|
|
3793
|
+
let selected = crate::state::selector::resolve_active_team_readonly(
|
|
3794
|
+
&run_workspace, Some(team), crate::state::selector::SelectorMode::RuntimeOnly,
|
|
3795
|
+
).map_err(|e| LifecycleError::TeamSelect(e.to_string()))?;
|
|
3796
|
+
crate::lifecycle::launch::ensure_owner_allowed_for_state(&selected.state, None)?;
|
|
3797
|
+
if selected.run_workspace != run_workspace || selected.team_key != team {
|
|
3798
|
+
return Err(LifecycleError::TeamSelect("runtime spec repair scope changed".into()));
|
|
3799
|
+
}
|
|
3800
|
+
let spec_path = crate::model::paths::runtime_spec_path(&run_workspace, team);
|
|
3801
|
+
let current = compile_runtime_spec_from_roles(&run_workspace, team, &selected.state)?;
|
|
3802
|
+
if ¤t != expected {
|
|
3803
|
+
return Err(LifecycleError::TeamSelect("role/source changed since runtime spec repair planning".into()));
|
|
3804
|
+
}
|
|
3805
|
+
if spec_path.exists() {
|
|
3806
|
+
let text = std::fs::read_to_string(&spec_path)
|
|
3807
|
+
.map_err(|e| LifecycleError::StatePersist(e.to_string()))?;
|
|
3808
|
+
if yaml::loads(&text).map_err(|e| LifecycleError::Compile(e.to_string()))? != current {
|
|
3809
|
+
return Err(LifecycleError::TeamSelect("runtime spec changed since repair planning".into()));
|
|
3810
|
+
}
|
|
3811
|
+
} else {
|
|
3812
|
+
crate::lifecycle::launch::write_spec_atomic(&spec_path, ¤t)?;
|
|
3813
|
+
}
|
|
3814
|
+
let mut state = selected.state;
|
|
3815
|
+
state["spec_path"] = serde_json::json!(spec_path);
|
|
3816
|
+
crate::state::repository::StateRepository::new(&run_workspace).save(
|
|
3817
|
+
crate::state::repository::StateWriteIntent::RestartTeam {
|
|
3818
|
+
team_key: team, topology_authority_agent_ids: &[], skip_capture_backfill_agent_ids: &[],
|
|
3819
|
+
}, &state,
|
|
3820
|
+
).map_err(|e| LifecycleError::StatePersist(e.to_string()))?;
|
|
3821
|
+
Ok(spec_path)
|
|
3822
|
+
}
|
|
3823
|
+
|
|
3769
3824
|
fn filter_retired_agents_from_spec(
|
|
3770
3825
|
spec: &mut YamlValue,
|
|
3771
3826
|
retired: &std::collections::BTreeSet<String>,
|
|
@@ -3965,8 +4020,21 @@ fn restart_candidate_has_context(state: &serde_json::Value) -> bool {
|
|
|
3965
4020
|
})
|
|
3966
4021
|
}
|
|
3967
4022
|
|
|
4023
|
+
// Never let a legacy session-wide kill bypass canonical native teardown.
|
|
4024
|
+
fn destroy_stale_worker_session(live: bool, deferred: bool, shared_native: bool) -> bool {
|
|
4025
|
+
live && !deferred && !shared_native
|
|
4026
|
+
}
|
|
4027
|
+
|
|
3968
4028
|
#[cfg(test)]
|
|
3969
4029
|
mod tests {
|
|
4030
|
+
#[test]
|
|
4031
|
+
fn startup_shared_session_never_bulk_kills_contract_windows() {
|
|
4032
|
+
assert!(!super::destroy_stale_worker_session(true, false, true));
|
|
4033
|
+
assert!(!super::destroy_stale_worker_session(true, true, true));
|
|
4034
|
+
assert!(super::destroy_stale_worker_session(true, false, false));
|
|
4035
|
+
assert!(!super::destroy_stale_worker_session(false, false, false));
|
|
4036
|
+
}
|
|
4037
|
+
|
|
3970
4038
|
use super::*;
|
|
3971
4039
|
use std::collections::BTreeMap;
|
|
3972
4040
|
use std::path::Path;
|
|
@@ -4232,6 +4300,7 @@ tasks:
|
|
|
4232
4300
|
profile_launch: crate::provider::ProviderProfileLaunch::default(),
|
|
4233
4301
|
layout_placement: None,
|
|
4234
4302
|
spawn_cwd: std::path::PathBuf::from("/tmp/team-epoch"),
|
|
4303
|
+
mcp_config_path: None,
|
|
4235
4304
|
owner_team_id: None,
|
|
4236
4305
|
};
|
|
4237
4306
|
mark_agent_respawned(
|
|
@@ -96,6 +96,7 @@ pub(crate) use common::{
|
|
|
96
96
|
};
|
|
97
97
|
pub(crate) use orchestrator::{halt_plan, plan_status};
|
|
98
98
|
pub(crate) use rebuild::restart_with_transport_with_session_convergence_deadline;
|
|
99
|
+
pub(crate) use rebuild::{compile_runtime_spec_from_roles, restore_missing_runtime_spec};
|
|
99
100
|
// 0.5.38 (`.team/artifacts/startup-latency-locate.md` §5): expose the phase
|
|
100
101
|
// timer + worker timing writer so `lifecycle::launch::launch_with_transport_in_workspace`
|
|
101
102
|
// can emit the same instrumentation event family with `source="launch"`.
|
|
@@ -59,6 +59,14 @@ fn b4_monitor_step_failure_does_not_block_deliver_pending() {
|
|
|
59
59
|
let _g = EnvGuard::set(&[(ANCESTRY_KEY, NEUTRAL_ANCESTRY)]);
|
|
60
60
|
let ws = tmp_ws("b4-monitor");
|
|
61
61
|
seed_copilot_team_state(&ws, "cp1", true);
|
|
62
|
+
let mut state = team_agent::state::persist::load_runtime_state(&ws).unwrap();
|
|
63
|
+
#[cfg(unix)]
|
|
64
|
+
let targets = vec![crate::mcp_server::readiness::test_ready_worker(
|
|
65
|
+
&ws, &mut state, "team-b4", "cp1", "%41",
|
|
66
|
+
)];
|
|
67
|
+
#[cfg(not(unix))]
|
|
68
|
+
let targets = Vec::new();
|
|
69
|
+
save_runtime_state(&ws, &state).unwrap();
|
|
62
70
|
let store = MessageStore::open(&ws).unwrap();
|
|
63
71
|
store
|
|
64
72
|
.create_message(
|
|
@@ -68,14 +76,17 @@ fn b4_monitor_step_failure_does_not_block_deliver_pending() {
|
|
|
68
76
|
"do the thing",
|
|
69
77
|
None,
|
|
70
78
|
false,
|
|
71
|
-
|
|
79
|
+
Some("team-b4"),
|
|
72
80
|
)
|
|
73
81
|
.unwrap();
|
|
74
82
|
|
|
75
83
|
let coord = Coordinator::new(
|
|
76
84
|
WorkspacePath::new(ws.clone()),
|
|
77
85
|
Box::new(RealRegistry),
|
|
78
|
-
Box::new(MonitorFailTransport
|
|
86
|
+
Box::new(MonitorFailTransport {
|
|
87
|
+
targets,
|
|
88
|
+
..MonitorFailTransport::new()
|
|
89
|
+
}),
|
|
79
90
|
);
|
|
80
91
|
let report = coord.tick();
|
|
81
92
|
|
|
@@ -603,11 +614,13 @@ fn attach_socket_path(command: &str) -> Option<PathBuf> {
|
|
|
603
614
|
/// (B-4). Sessions/windows present so the tick proceeds to the monitor steps.
|
|
604
615
|
struct MonitorFailTransport {
|
|
605
616
|
session: Mutex<bool>,
|
|
617
|
+
targets: Vec<PaneInfo>,
|
|
606
618
|
}
|
|
607
619
|
impl MonitorFailTransport {
|
|
608
620
|
fn new() -> Self {
|
|
609
621
|
Self {
|
|
610
622
|
session: Mutex::new(true),
|
|
623
|
+
targets: Vec::new(),
|
|
611
624
|
}
|
|
612
625
|
}
|
|
613
626
|
}
|
|
@@ -688,7 +701,7 @@ impl Transport for MonitorFailTransport {
|
|
|
688
701
|
}
|
|
689
702
|
}
|
|
690
703
|
fn list_targets(&self) -> Result<Vec<PaneInfo>, TransportError> {
|
|
691
|
-
Ok(
|
|
704
|
+
Ok(self.targets.clone())
|
|
692
705
|
}
|
|
693
706
|
fn list_windows(&self, _s: &SessionName) -> Result<Vec<WindowName>, TransportError> {
|
|
694
707
|
Ok(vec![WindowName::new("cp1")])
|
|
@@ -36,6 +36,112 @@ use team_agent::lifecycle::{
|
|
|
36
36
|
};
|
|
37
37
|
use team_agent::transport::test_support::OfflineTransport;
|
|
38
38
|
|
|
39
|
+
#[test]
|
|
40
|
+
#[serial(env)]
|
|
41
|
+
fn issue345_dynamic_cursor_start_persists_its_generated_mcp_path() {
|
|
42
|
+
let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("cursor-dynamic-mcp");
|
|
43
|
+
let (ws, _home, _guard, team) = seed_cursor("dynamic-mcp");
|
|
44
|
+
std::fs::write(
|
|
45
|
+
team.join("agents/cursor_writer.md"),
|
|
46
|
+
"---\nprovider: fake\ndangerously_skip_permissions: true\n---\nControl seat.\n",
|
|
47
|
+
)
|
|
48
|
+
.unwrap();
|
|
49
|
+
let transport = OfflineTransport::new();
|
|
50
|
+
quick_start_with_transport_in_workspace(&ws, &team, None, true, Some("cursortm"), &transport)
|
|
51
|
+
.unwrap();
|
|
52
|
+
let role = team.join("cursor_dynamic.md");
|
|
53
|
+
std::fs::write(&role, "---\nprovider: cursor_agent\nmodel: grok-4.7-high\nauth_mode: subscription\ndangerously_skip_permissions: true\n---\nDynamic Cursor seat.\n").unwrap();
|
|
54
|
+
crate::lifecycle::add_agent_with_transport(
|
|
55
|
+
&team,
|
|
56
|
+
&AgentId::new("cursor_dynamic"),
|
|
57
|
+
&role,
|
|
58
|
+
false,
|
|
59
|
+
Some("cursortm"),
|
|
60
|
+
&transport,
|
|
61
|
+
)
|
|
62
|
+
.unwrap();
|
|
63
|
+
let state = load_runtime_state(&ws).unwrap();
|
|
64
|
+
let expected = ws.join(".team/runtime/mcp/cursor_dynamic.json");
|
|
65
|
+
assert!(
|
|
66
|
+
expected.is_file(),
|
|
67
|
+
"positive control: spawn generated the real config"
|
|
68
|
+
);
|
|
69
|
+
assert_eq!(
|
|
70
|
+
state["agents"]["cursor_dynamic"]["mcp_config"].as_str(),
|
|
71
|
+
expected.to_str()
|
|
72
|
+
);
|
|
73
|
+
assert_eq!(
|
|
74
|
+
state["teams"]["cursortm"]["agents"]["cursor_dynamic"]["mcp_config"].as_str(),
|
|
75
|
+
expected.to_str()
|
|
76
|
+
);
|
|
77
|
+
let config: serde_json::Value =
|
|
78
|
+
serde_json::from_slice(&std::fs::read(&expected).unwrap()).unwrap();
|
|
79
|
+
assert_eq!(
|
|
80
|
+
config["mcpServers"]["team_orchestrator"]["env"]["TEAM_AGENT_ID"],
|
|
81
|
+
"cursor_dynamic"
|
|
82
|
+
);
|
|
83
|
+
assert_eq!(
|
|
84
|
+
config["mcpServers"]["team_orchestrator"]["env"]["TEAM_AGENT_OWNER_TEAM_ID"],
|
|
85
|
+
"cursortm"
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
#[test]
|
|
90
|
+
#[serial(env)]
|
|
91
|
+
fn issue345_cursor_wakeup_restores_missing_derived_mcp_path() {
|
|
92
|
+
let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("cursor-wakeup-mcp");
|
|
93
|
+
let (ws, _home, _guard, team) = seed_cursor("wakeup-mcp");
|
|
94
|
+
let transport = OfflineTransport::new();
|
|
95
|
+
quick_start_with_transport_in_workspace(&ws, &team, None, true, Some("cursortm"), &transport)
|
|
96
|
+
.unwrap();
|
|
97
|
+
crate::lifecycle::restart::stop_agent_with_transport(
|
|
98
|
+
&ws,
|
|
99
|
+
&AgentId::new("cursor_writer"),
|
|
100
|
+
Some("cursortm"),
|
|
101
|
+
&transport,
|
|
102
|
+
)
|
|
103
|
+
.unwrap();
|
|
104
|
+
let mut state = load_runtime_state(&ws).unwrap();
|
|
105
|
+
state["agents"]["cursor_writer"]
|
|
106
|
+
.as_object_mut()
|
|
107
|
+
.unwrap()
|
|
108
|
+
.remove("mcp_config");
|
|
109
|
+
state["teams"]["cursortm"]["agents"]["cursor_writer"]
|
|
110
|
+
.as_object_mut()
|
|
111
|
+
.unwrap()
|
|
112
|
+
.remove("mcp_config");
|
|
113
|
+
// Plant an actual legacy row; ordinary state saves intentionally backfill fields.
|
|
114
|
+
std::fs::write(
|
|
115
|
+
crate::state::persist::runtime_state_path(&ws),
|
|
116
|
+
serde_json::to_vec(&state).unwrap(),
|
|
117
|
+
)
|
|
118
|
+
.unwrap();
|
|
119
|
+
assert!(load_runtime_state(&ws).unwrap()["agents"]["cursor_writer"]
|
|
120
|
+
.get("mcp_config")
|
|
121
|
+
.is_none());
|
|
122
|
+
crate::lifecycle::restart::start_agent_with_transport(
|
|
123
|
+
&ws,
|
|
124
|
+
&AgentId::new("cursor_writer"),
|
|
125
|
+
false,
|
|
126
|
+
false,
|
|
127
|
+
true,
|
|
128
|
+
Some("cursortm"),
|
|
129
|
+
&transport,
|
|
130
|
+
)
|
|
131
|
+
.unwrap();
|
|
132
|
+
let after = load_runtime_state(&ws).unwrap();
|
|
133
|
+
let expected = ws.join(".team/runtime/mcp/cursor_writer.json");
|
|
134
|
+
assert!(expected.is_file());
|
|
135
|
+
assert_eq!(
|
|
136
|
+
after["agents"]["cursor_writer"]["mcp_config"].as_str(),
|
|
137
|
+
expected.to_str()
|
|
138
|
+
);
|
|
139
|
+
assert_eq!(
|
|
140
|
+
after["teams"]["cursortm"]["agents"]["cursor_writer"]["mcp_config"].as_str(),
|
|
141
|
+
expected.to_str()
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
39
145
|
#[test]
|
|
40
146
|
#[serial(env)]
|
|
41
147
|
fn cursor_fresh_spawn_does_not_invent_session_id() {
|
|
@@ -109,7 +215,23 @@ fn cursor_restart_uses_resume_when_session_captured_and_archive_present() {
|
|
|
109
215
|
primary.to_string_lossy().as_ref()
|
|
110
216
|
);
|
|
111
217
|
patch_cursor_writer(&mut state, sid, &dir, &primary);
|
|
112
|
-
|
|
218
|
+
state["agents"]["cursor_writer"]
|
|
219
|
+
.as_object_mut()
|
|
220
|
+
.unwrap()
|
|
221
|
+
.remove("mcp_config");
|
|
222
|
+
state["teams"]["cursortm"]["agents"]["cursor_writer"]
|
|
223
|
+
.as_object_mut()
|
|
224
|
+
.unwrap()
|
|
225
|
+
.remove("mcp_config");
|
|
226
|
+
// Preserve the real captured SID while removing only the derived config path.
|
|
227
|
+
std::fs::write(
|
|
228
|
+
crate::state::persist::runtime_state_path(&ws),
|
|
229
|
+
serde_json::to_vec(&state).unwrap(),
|
|
230
|
+
)
|
|
231
|
+
.unwrap();
|
|
232
|
+
assert!(load_runtime_state(&ws).unwrap()["agents"]["cursor_writer"]
|
|
233
|
+
.get("mcp_config")
|
|
234
|
+
.is_none());
|
|
113
235
|
|
|
114
236
|
seed_healthy_coordinator(&ws);
|
|
115
237
|
|
|
@@ -135,6 +257,15 @@ fn cursor_restart_uses_resume_when_session_captured_and_archive_present() {
|
|
|
135
257
|
primary.to_string_lossy().as_ref()
|
|
136
258
|
);
|
|
137
259
|
assert_eq!(after["agents"]["cursor_writer"]["session_id"], sid);
|
|
260
|
+
let expected_config = ws.join(".team/runtime/mcp/cursor_writer.json");
|
|
261
|
+
assert_eq!(
|
|
262
|
+
after["agents"]["cursor_writer"]["mcp_config"].as_str(),
|
|
263
|
+
expected_config.to_str()
|
|
264
|
+
);
|
|
265
|
+
assert_eq!(
|
|
266
|
+
after["teams"]["cursortm"]["agents"]["cursor_writer"]["mcp_config"].as_str(),
|
|
267
|
+
expected_config.to_str()
|
|
268
|
+
);
|
|
138
269
|
assert_eq!(
|
|
139
270
|
cursor_mcp_project_dir(&ws, "cursor_writer").unwrap(),
|
|
140
271
|
primary_before
|
|
@@ -1546,9 +1546,10 @@ fn quick_start_persists_selected_tmux_endpoint_and_attach_commands() {
|
|
|
1546
1546
|
"attach commands must use the selected socket endpoint: {attach_commands:?}"
|
|
1547
1547
|
);
|
|
1548
1548
|
assert!(
|
|
1549
|
-
attach_commands.iter().any(|cmd| cmd.contains(":leader")),
|
|
1550
|
-
"
|
|
1549
|
+
!attach_commands.iter().any(|cmd| cmd.contains(":leader")),
|
|
1550
|
+
"managed metadata does not prove an unreported leader window exists: {attach_commands:?}"
|
|
1551
1551
|
);
|
|
1552
|
+
assert!(attach_commands.iter().any(|cmd| cmd.ends_with(":implementer")));
|
|
1552
1553
|
let (_raw, state) = raw_runtime_state(workspace);
|
|
1553
1554
|
assert_eq!(state["tmux_endpoint"], json!(endpoint));
|
|
1554
1555
|
assert_eq!(state["tmux_socket"], json!(endpoint));
|
|
@@ -1583,7 +1584,7 @@ fn annotate_runtime_tmux_endpoint_persists_workspace_socket_as_full_path() {
|
|
|
1583
1584
|
|
|
1584
1585
|
#[test]
|
|
1585
1586
|
#[serial(env)]
|
|
1586
|
-
fn
|
|
1587
|
+
fn quick_start_preserves_managed_leader_topology_without_inventing_a_leader_window() {
|
|
1587
1588
|
let hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("launch-spawn-managed-leader");
|
|
1588
1589
|
let workspace = hermetic.root();
|
|
1589
1590
|
let team = workspace.join("teamdir");
|
|
@@ -1641,9 +1642,10 @@ fn quick_start_preserves_managed_leader_topology_and_emits_leader_attach_command
|
|
|
1641
1642
|
};
|
|
1642
1643
|
|
|
1643
1644
|
assert!(
|
|
1644
|
-
attach_commands.iter().any(|cmd| cmd.contains(":leader")),
|
|
1645
|
-
"managed
|
|
1645
|
+
!attach_commands.iter().any(|cmd| cmd.contains(":leader")),
|
|
1646
|
+
"managed ownership must survive, but a missing physical leader window is not an attach target: {attach_commands:?}"
|
|
1646
1647
|
);
|
|
1648
|
+
assert!(attach_commands.iter().any(|cmd| cmd.ends_with(":implementer")));
|
|
1647
1649
|
let (_raw, state) = raw_runtime_state(workspace);
|
|
1648
1650
|
assert_eq!(state["is_external_leader"], json!(false));
|
|
1649
1651
|
assert_eq!(state["leader_client"]["diagnostic_only"], json!(true));
|
|
@@ -651,10 +651,10 @@ fn contract_b_delivery_gate_trusts_startup_handled_state_over_pane_scrollback()
|
|
|
651
651
|
"SUB step2 probe: handled startup trust must deliver despite scrollback residue.",
|
|
652
652
|
None,
|
|
653
653
|
true,
|
|
654
|
-
|
|
654
|
+
Some("subprep-scrollback"),
|
|
655
655
|
)
|
|
656
656
|
.unwrap();
|
|
657
|
-
let handled_state = json!({
|
|
657
|
+
let mut handled_state = json!({
|
|
658
658
|
"session_name": "team-ta-subroot-SUB-PROBE-2-send-turn-idle",
|
|
659
659
|
"agents": {
|
|
660
660
|
"w1": {
|
|
@@ -670,9 +670,15 @@ fn contract_b_delivery_gate_trusts_startup_handled_state_over_pane_scrollback()
|
|
|
670
670
|
}
|
|
671
671
|
}
|
|
672
672
|
});
|
|
673
|
+
#[cfg(unix)]
|
|
674
|
+
let pane = crate::mcp_server::readiness::test_ready_worker(
|
|
675
|
+
&handled_ws, &mut handled_state, "subprep-scrollback", "w1", "%7",
|
|
676
|
+
);
|
|
673
677
|
team_agent::state::persist::save_runtime_state(&handled_ws, &handled_state).unwrap();
|
|
674
678
|
let handled_transport =
|
|
675
679
|
RecordingTransport::new(vec![SUBROOT_FULL_TRUST_PANE_AFTER_QUICKSTART.to_string()]);
|
|
680
|
+
#[cfg(unix)]
|
|
681
|
+
{ handled_transport.state.lock().unwrap().carrier = pane.pane_pid; }
|
|
676
682
|
let handled_log = EventLog::new(&handled_ws);
|
|
677
683
|
let handled = deliver_pending_message(
|
|
678
684
|
&handled_ws,
|
|
@@ -273,9 +273,6 @@ pub(crate) fn preflight(
|
|
|
273
273
|
let Some(agent) = state.get("agents").and_then(|agents| agents.get(agent_id)) else {
|
|
274
274
|
return Ok(None);
|
|
275
275
|
};
|
|
276
|
-
let Some(config) = agent.get("mcp_config").and_then(Value::as_str) else {
|
|
277
|
-
return Ok(None);
|
|
278
|
-
};
|
|
279
276
|
let provider = agent
|
|
280
277
|
.get("provider")
|
|
281
278
|
.and_then(Value::as_str)
|
|
@@ -284,6 +281,11 @@ pub(crate) fn preflight(
|
|
|
284
281
|
if !crate::provider::get_adapter(provider).requires_worker_mcp_handshake() {
|
|
285
282
|
return Ok(None);
|
|
286
283
|
}
|
|
284
|
+
let config = agent
|
|
285
|
+
.get("mcp_config")
|
|
286
|
+
.and_then(Value::as_str)
|
|
287
|
+
.filter(|path| !path.trim().is_empty())
|
|
288
|
+
.ok_or("mcp_handshake_config_missing")?;
|
|
287
289
|
let owner = owner
|
|
288
290
|
.filter(|s| !s.is_empty())
|
|
289
291
|
.ok_or("mcp_handshake_scope_missing")?;
|
|
@@ -427,6 +429,67 @@ pub(crate) fn test_carrier_pid() -> Option<u32> {
|
|
|
427
429
|
crate::platform::process::current_parent_pid()
|
|
428
430
|
}
|
|
429
431
|
|
|
432
|
+
/// Bind a controlled live test helper through the real receipt publisher. This
|
|
433
|
+
/// does not bypass preflight or fabricate a process/image/ancestry receipt.
|
|
434
|
+
#[cfg(test)]
|
|
435
|
+
pub(crate) fn test_ready_worker(
|
|
436
|
+
workspace: &Path,
|
|
437
|
+
state: &mut Value,
|
|
438
|
+
owner: &str,
|
|
439
|
+
agent: &str,
|
|
440
|
+
pane: &str,
|
|
441
|
+
) -> PaneInfo {
|
|
442
|
+
let workspace = workspace.canonicalize().unwrap();
|
|
443
|
+
let carrier = test_carrier_pid().unwrap();
|
|
444
|
+
let config = workspace
|
|
445
|
+
.join(".team/runtime/mcp")
|
|
446
|
+
.join(format!("{agent}.json"));
|
|
447
|
+
std::fs::create_dir_all(config.parent().unwrap()).unwrap();
|
|
448
|
+
std::fs::write(&config, serde_json::to_vec(&serde_json::json!({
|
|
449
|
+
"mcpServers": {"team_orchestrator": {
|
|
450
|
+
"command": std::env::current_exe().unwrap().canonicalize().unwrap(),
|
|
451
|
+
"env": {"TEAM_AGENT_WORKSPACE": workspace, "TEAM_AGENT_ID": agent, "TEAM_AGENT_OWNER_TEAM_ID": owner}
|
|
452
|
+
}}
|
|
453
|
+
})).unwrap()).unwrap();
|
|
454
|
+
state["team_key"] = serde_json::json!(owner);
|
|
455
|
+
state["active_team_key"] = serde_json::json!(owner);
|
|
456
|
+
let row = &mut state["agents"][agent];
|
|
457
|
+
row["mcp_config"] = serde_json::json!(config);
|
|
458
|
+
row["pane_id"] = serde_json::json!(pane);
|
|
459
|
+
row["pane_pid"] = serde_json::json!(carrier);
|
|
460
|
+
row["spawned_at"] =
|
|
461
|
+
serde_json::json!((Utc::now() - chrono::Duration::seconds(10)).to_rfc3339());
|
|
462
|
+
let window = row["window"].as_str().unwrap_or(agent).to_string();
|
|
463
|
+
let session = state["session_name"].as_str().unwrap().to_string();
|
|
464
|
+
if state["teams"][owner].is_object() {
|
|
465
|
+
state["teams"][owner]["agents"][agent] = state["agents"][agent].clone();
|
|
466
|
+
}
|
|
467
|
+
publish(&workspace, owner, agent, Utc::now()).unwrap();
|
|
468
|
+
let target = PaneInfo {
|
|
469
|
+
pane_id: crate::transport::PaneId::new(pane),
|
|
470
|
+
session: crate::transport::SessionName::new(session),
|
|
471
|
+
window_index: None,
|
|
472
|
+
window_name: Some(crate::transport::WindowName::new(window)),
|
|
473
|
+
pane_index: None,
|
|
474
|
+
tty: None,
|
|
475
|
+
current_command: None,
|
|
476
|
+
current_path: Some(workspace.clone()),
|
|
477
|
+
active: true,
|
|
478
|
+
pane_pid: Some(carrier),
|
|
479
|
+
leader_env: Default::default(),
|
|
480
|
+
};
|
|
481
|
+
let admission = preflight(&workspace, Some(owner), agent, state)
|
|
482
|
+
.unwrap()
|
|
483
|
+
.unwrap();
|
|
484
|
+
revalidate(
|
|
485
|
+
&admission,
|
|
486
|
+
&Target::Pane(target.pane_id.clone()),
|
|
487
|
+
std::slice::from_ref(&target),
|
|
488
|
+
)
|
|
489
|
+
.unwrap();
|
|
490
|
+
target
|
|
491
|
+
}
|
|
492
|
+
|
|
430
493
|
#[cfg(test)]
|
|
431
494
|
#[path = "readiness_tests.rs"]
|
|
432
495
|
mod tests;
|
|
@@ -94,6 +94,29 @@ impl Drop for Case {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
#[test]
|
|
98
|
+
fn issue345_missing_mcp_config_does_not_disable_eager_admission() {
|
|
99
|
+
for provider in ["cursor_agent", "codex", "claude"] {
|
|
100
|
+
let mut case = Case::new();
|
|
101
|
+
case.state["agents"]["worker"]["provider"] = json!(provider);
|
|
102
|
+
case.state["agents"]["worker"]
|
|
103
|
+
.as_object_mut()
|
|
104
|
+
.unwrap()
|
|
105
|
+
.remove("mcp_config");
|
|
106
|
+
assert!(
|
|
107
|
+
case.admission().is_err(),
|
|
108
|
+
"missing config cannot disable {provider} admission"
|
|
109
|
+
);
|
|
110
|
+
for value in [Value::Null, json!(false), json!(""), json!(" ")] {
|
|
111
|
+
case.state["agents"]["worker"]["mcp_config"] = value;
|
|
112
|
+
assert!(
|
|
113
|
+
case.admission().is_err(),
|
|
114
|
+
"invalid config cannot disable {provider} admission"
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
97
120
|
#[test]
|
|
98
121
|
fn missing_handshake_defers_then_a_live_scoped_receipt_admits() {
|
|
99
122
|
let case = Case::new();
|
|
@@ -238,5 +261,12 @@ fn fake_and_pi_keep_their_existing_non_eager_or_runtime_registry_admission() {
|
|
|
238
261
|
assert!(preflight(&case.ws, Some("owner"), "worker", &state)
|
|
239
262
|
.unwrap()
|
|
240
263
|
.is_none());
|
|
264
|
+
state["agents"]["worker"]
|
|
265
|
+
.as_object_mut()
|
|
266
|
+
.unwrap()
|
|
267
|
+
.remove("mcp_config");
|
|
268
|
+
assert!(preflight(&case.ws, Some("owner"), "worker", &state)
|
|
269
|
+
.unwrap()
|
|
270
|
+
.is_none());
|
|
241
271
|
}
|
|
242
272
|
}
|
|
@@ -122,9 +122,20 @@ fn successful_transport_report_does_not_override_unconsumed_composer() {
|
|
|
122
122
|
"[Pasted text #1 +25 lines]",
|
|
123
123
|
"foreign draft",
|
|
124
124
|
] {
|
|
125
|
-
let f = Fixture::new("cursor_agent");
|
|
125
|
+
let mut f = Fixture::new("cursor_agent");
|
|
126
|
+
#[cfg(unix)]
|
|
127
|
+
let panes = vec![crate::mcp_server::readiness::test_ready_worker(
|
|
128
|
+
&f.workspace,
|
|
129
|
+
&mut f.state,
|
|
130
|
+
"team",
|
|
131
|
+
"worker",
|
|
132
|
+
"%1",
|
|
133
|
+
)];
|
|
134
|
+
#[cfg(not(unix))]
|
|
135
|
+
let panes = f.transport().list_targets().unwrap();
|
|
126
136
|
let t = f
|
|
127
137
|
.transport()
|
|
138
|
+
.with_targets(panes)
|
|
128
139
|
.with_native_input_observation(frame(composer, ""));
|
|
129
140
|
let out = f.deliver(&t);
|
|
130
141
|
assert!(!out.ok, "composer={composer}");
|