@team-agent/installer 0.5.122 → 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 CHANGED
@@ -727,7 +727,7 @@ dependencies = [
727
727
 
728
728
  [[package]]
729
729
  name = "team-agent"
730
- version = "0.5.122"
730
+ version = "0.5.123"
731
731
  dependencies = [
732
732
  "anyhow",
733
733
  "chrono",
@@ -755,6 +755,7 @@ dependencies = [
755
755
  "serde",
756
756
  "serde_json",
757
757
  "sha2",
758
+ "unicode-width",
758
759
  ]
759
760
 
760
761
  [[package]]
@@ -789,6 +790,12 @@ version = "1.0.26"
789
790
  source = "registry+https://github.com/rust-lang/crates.io-index"
790
791
  checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954"
791
792
 
793
+ [[package]]
794
+ name = "unicode-width"
795
+ version = "0.2.2"
796
+ source = "registry+https://github.com/rust-lang/crates.io-index"
797
+ checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254"
798
+
792
799
  [[package]]
793
800
  name = "vcpkg"
794
801
  version = "0.2.15"
package/Cargo.toml CHANGED
@@ -11,7 +11,7 @@ exclude = ["crates/team-agent-contract"]
11
11
 
12
12
  [workspace.package]
13
13
  edition = "2021"
14
- version = "0.5.122"
14
+ version = "0.5.123"
15
15
  license = "AGPL-3.0"
16
16
  rust-version = "1.95"
17
17
 
@@ -93,6 +93,79 @@ pub(crate) fn classify_tmux_server_error(error_text: &str) -> &'static str {
93
93
  }
94
94
  }
95
95
 
96
+ fn recorded_mux_pane(agent_state: &Value) -> Option<&str> {
97
+ ["pane_id", "native_pane"].iter().find_map(|key| {
98
+ agent_state
99
+ .get(*key)
100
+ .and_then(Value::as_str)
101
+ .filter(|value| !value.is_empty())
102
+ })
103
+ }
104
+
105
+ fn explicit_window_name(agent_state: &Value) -> Option<&str> {
106
+ ["window", "window_name"].iter().find_map(|key| {
107
+ agent_state
108
+ .get(*key)
109
+ .and_then(Value::as_str)
110
+ .filter(|value| !value.is_empty())
111
+ })
112
+ }
113
+
114
+ fn is_public_window_name(provider: &str, window: &str) -> bool {
115
+ // Contract ids such as grok_build are not legacy Provider aliases, but
116
+ // their tmux title is the public command, not the seat id.
117
+ if provider == "grok_build" && window == "grok" {
118
+ return true;
119
+ }
120
+ parse_provider(provider).is_some_and(|parsed| {
121
+ command_name(parsed) == window
122
+ || crate::layout::worker_window_helpers::provider_window_name(parsed) == window
123
+ })
124
+ }
125
+
126
+ fn window_name_reconciles(
127
+ agent_id: &str,
128
+ agent_state: &Value,
129
+ windows: &[crate::transport::WindowName],
130
+ ) -> bool {
131
+ let explicit = explicit_window_name(agent_state);
132
+ let provider = agent_state
133
+ .get("provider")
134
+ .and_then(Value::as_str)
135
+ .unwrap_or("");
136
+ windows.iter().any(|window| {
137
+ let name = window.as_str();
138
+ explicit.is_some_and(|expected| expected == name)
139
+ || is_public_window_name(provider, name)
140
+ || name == agent_id
141
+ })
142
+ }
143
+
144
+ /// A native CLI owns its window title. Seat presence is the recorded pane id
145
+ /// on this transport; display names are only a fallback.
146
+ fn worker_window_is_missing(
147
+ agent_id: &str,
148
+ agent_state: &Value,
149
+ windows: &[crate::transport::WindowName],
150
+ panes: &[crate::transport::PaneInfo],
151
+ backend: &dyn Transport,
152
+ ) -> bool {
153
+ if let Some(pane_id) = recorded_mux_pane(agent_state) {
154
+ if panes.iter().any(|pane| pane.pane_id.as_str() == pane_id) {
155
+ return false;
156
+ }
157
+ if !panes.is_empty() {
158
+ return true;
159
+ }
160
+ match backend.has_pane(&crate::transport::PaneId::new(pane_id)) {
161
+ Ok(Some(true)) => return false,
162
+ Ok(Some(false)) => return true,
163
+ _ => {}
164
+ }
165
+ }
166
+ !window_name_reconciles(agent_id, agent_state, windows)
167
+ }
168
+
96
169
  pub(crate) fn diagnose_runtime(state: &Value, backend: &dyn Transport) -> (Value, Value) {
97
170
  diagnose_runtime_with_workspace(None, state, backend)
98
171
  }
@@ -244,6 +317,7 @@ fn diagnose_runtime_with_workspace(
244
317
  if let Ok(windows) = backend.list_windows(&crate::transport::SessionName::new(
245
318
  session_name.to_string(),
246
319
  )) {
320
+ let panes = backend.list_targets().unwrap_or_default();
247
321
  if let Some(agents) = state.get("agents").and_then(Value::as_object) {
248
322
  for (agent_id, agent_state) in agents {
249
323
  let provider = agent_state
@@ -290,16 +364,7 @@ fn diagnose_runtime_with_workspace(
290
364
  .map(|path| path.to_string_lossy().to_string()),
291
365
  }));
292
366
  }
293
- let window = ["window", "window_name"]
294
- .iter()
295
- .find_map(|key| {
296
- agent_state
297
- .get(*key)
298
- .and_then(Value::as_str)
299
- .filter(|s| !s.is_empty())
300
- })
301
- .unwrap_or(agent_id);
302
- if !windows.iter().any(|w| w.as_str() == window) {
367
+ if worker_window_is_missing(agent_id, agent_state, &windows, &panes, backend) {
303
368
  issues.push(json!(format!("worker_window_missing:{agent_id}")));
304
369
  }
305
370
  if agent_state
@@ -1309,6 +1374,107 @@ mod tests {
1309
1374
  );
1310
1375
  let _ = std::fs::remove_dir_all(&workspace);
1311
1376
  }
1377
+
1378
+ fn pane(session: &str, pane_id: &str, window: &str) -> crate::transport::PaneInfo {
1379
+ crate::transport::PaneInfo {
1380
+ pane_id: crate::transport::PaneId::new(pane_id),
1381
+ session: crate::transport::SessionName::new(session),
1382
+ window_index: None,
1383
+ window_name: Some(crate::transport::WindowName::new(window)),
1384
+ pane_index: None,
1385
+ tty: None,
1386
+ current_command: Some(window.to_string()),
1387
+ current_path: None,
1388
+ active: true,
1389
+ pane_pid: Some(1),
1390
+ leader_env: Default::default(),
1391
+ }
1392
+ }
1393
+
1394
+ fn has_issue(issues: &Value, issue: &str) -> bool {
1395
+ issues
1396
+ .as_array()
1397
+ .is_some_and(|items| items.iter().any(|item| item.as_str() == Some(issue)))
1398
+ }
1399
+
1400
+ fn grok_state(extra: Value) -> Value {
1401
+ let mut agent = json!({
1402
+ "provider": "grok_build",
1403
+ "status": "running",
1404
+ "runtime_family": "contract",
1405
+ "window": null,
1406
+ "pane_id": null,
1407
+ "session_name": null
1408
+ });
1409
+ if let (Some(agent), Some(extra)) = (agent.as_object_mut(), extra.as_object()) {
1410
+ for (key, value) in extra {
1411
+ agent.insert(key.clone(), value.clone());
1412
+ }
1413
+ }
1414
+ json!({
1415
+ "session_name": "team-current",
1416
+ "agents": { "grok-seat": agent }
1417
+ })
1418
+ }
1419
+
1420
+ #[test]
1421
+ fn doctor_accepts_live_native_pane_when_window_title_is_not_agent_id() {
1422
+ let state = grok_state(json!({"native_pane": "%1"}));
1423
+ let backend = crate::transport::test_support::OfflineTransport::new()
1424
+ .with_session_present(true)
1425
+ .with_windows(vec![crate::transport::WindowName::new("grok")])
1426
+ .with_targets(vec![pane("team-current", "%1", "renamed-by-cli")]);
1427
+ let (issues, _) = diagnose_runtime(&state, &backend);
1428
+ assert!(
1429
+ !has_issue(&issues, "worker_window_missing:grok-seat"),
1430
+ "live pane id must prove the seat without the agent-id window name; issues={issues}"
1431
+ );
1432
+ }
1433
+
1434
+ #[test]
1435
+ fn doctor_does_not_treat_another_public_window_as_a_missing_pane() {
1436
+ let state = grok_state(json!({"native_pane": "%1"}));
1437
+ let backend = crate::transport::test_support::OfflineTransport::new()
1438
+ .with_session_present(true)
1439
+ .with_windows(vec![crate::transport::WindowName::new("grok")])
1440
+ .with_targets(vec![pane("team-current", "%9", "grok")]);
1441
+ let (issues, _) = diagnose_runtime(&state, &backend);
1442
+ assert!(
1443
+ has_issue(&issues, "worker_window_missing:grok-seat"),
1444
+ "a same-named window must not hide a different pane id; issues={issues}"
1445
+ );
1446
+ }
1447
+
1448
+ #[test]
1449
+ fn doctor_accepts_public_window_name_when_no_pane_id_is_recorded() {
1450
+ let state = grok_state(json!({}));
1451
+ let backend = crate::transport::test_support::OfflineTransport::new()
1452
+ .with_session_present(true)
1453
+ .with_windows(vec![crate::transport::WindowName::new("grok")]);
1454
+ let (issues, _) = diagnose_runtime(&state, &backend);
1455
+ assert!(
1456
+ !has_issue(&issues, "worker_window_missing:grok-seat"),
1457
+ "public command title is a valid fallback; issues={issues}"
1458
+ );
1459
+ }
1460
+
1461
+ #[test]
1462
+ fn doctor_still_accepts_legacy_agent_id_window_name() {
1463
+ let state = json!({
1464
+ "session_name": "team-current",
1465
+ "agents": {
1466
+ "worker-a": { "provider": "pi", "status": "running" }
1467
+ }
1468
+ });
1469
+ let backend = crate::transport::test_support::OfflineTransport::new()
1470
+ .with_session_present(true)
1471
+ .with_windows(vec![crate::transport::WindowName::new("worker-a")]);
1472
+ let (issues, _) = diagnose_runtime(&state, &backend);
1473
+ assert!(
1474
+ !has_issue(&issues, "worker_window_missing:worker-a"),
1475
+ "legacy agent-id windows remain present; issues={issues}"
1476
+ );
1477
+ }
1312
1478
  }
1313
1479
 
1314
1480
  pub(crate) fn build_profile_smoke_check_for_team(
@@ -243,6 +243,11 @@ fn check_native_noop_settings(
243
243
  "native launch configuration drift for {id}; stop before applying settings"
244
244
  )));
245
245
  }
246
+ checked(crate::contract_runtime::backend::preflight_start_role(
247
+ &selected.run_workspace,
248
+ &selected.team_key,
249
+ current,
250
+ ))?;
246
251
  }
247
252
  Ok(())
248
253
  }
@@ -294,6 +299,16 @@ fn observe(selected: &SelectedTeam, id: &str, row: &Value) -> Result<Observation
294
299
  if crate::contract_runtime::framework::is_paused_unstarted(row) {
295
300
  return Ok(Observation::Unstarted);
296
301
  }
302
+ if checked(
303
+ crate::contract_runtime::backend::start_needs_reconciliation(
304
+ &selected.run_workspace,
305
+ &selected.team_key,
306
+ &checked(SeatId::new(id))?,
307
+ row,
308
+ ),
309
+ )? {
310
+ return Ok(Observation::NativeReconcile);
311
+ }
297
312
  let backend = checked(crate::contract_runtime::backend::Backend::open_readonly(
298
313
  &selected.run_workspace,
299
314
  &selected.team_key,
@@ -481,7 +496,6 @@ fn preflight_start(
481
496
  ) -> Result<(), CliError> {
482
497
  #[cfg(unix)]
483
498
  if crate::contract_runtime::framework::is_contract(row) {
484
- use team_agent_contract::contract::types::SeatId;
485
499
  let config = checked(crate::contract_runtime::framework::team_config(
486
500
  &selected.run_workspace,
487
501
  &selected.team_dir,
@@ -493,12 +507,17 @@ fn preflight_start(
493
507
  .iter()
494
508
  .find(|r| r.id.as_str() == id)
495
509
  .ok_or_else(|| refusal("missing native role"))?;
496
- checked(crate::contract_runtime::backend::prepare_resume(
497
- &selected.run_workspace,
498
- &selected.team_key,
499
- &checked(SeatId::new(id))?,
500
- Some(role),
501
- ))?;
510
+ if crate::contract_runtime::framework::is_paused_unstarted(row) {
511
+ checked(crate::contract_runtime::backend::preflight(&config))?;
512
+ } else {
513
+ if checked(crate::contract_runtime::backend::preflight_start_role(
514
+ &selected.run_workspace,
515
+ &selected.team_key,
516
+ role,
517
+ ))? {
518
+ checked(crate::contract_runtime::backend::preflight(&config))?;
519
+ }
520
+ }
502
521
  return Ok(());
503
522
  }
504
523
  let provider = crate::provider::wire::parse_provider(provider(row))
@@ -814,47 +833,54 @@ fn plan_with_observer(
814
833
  return Ok(plan);
815
834
  }
816
835
  let spec = selected.spec_path.as_ref().filter(|p| p.is_file());
817
- if spec.is_none() {
818
- if plan.intent.verb == Verb::Restart && target.is_none() {
819
- // Original active restart owns spec reconstruction and pre-destroy validation.
820
- let rows = selected
821
- .state
822
- .get("agents")
823
- .and_then(Value::as_object)
824
- .ok_or_else(|| refusal("missing agents"))?;
825
- let mut active = false;
826
- for (id, row) in rows {
827
- if !paused(row)
828
- && !crate::state::projection::agent_explicit_stop(row)
829
- && !crate::state::projection::agent_stopped_for_restart(row)
830
- {
831
- let obs = observe(&selected, id, row)?;
832
- if obs == Observation::Unknown {
833
- return Err(refusal("unknown physical identity"));
834
- }
835
- active = true;
836
- } else {
837
- plan.skipped.push(json!({"agent":id,"reason":if paused(row){"paused"}else if crate::state::projection::agent_explicit_stop(row){"explicit_stop"}else{"stopped_preserved_by_original_restart"}}));
836
+ let missing_spec = spec.is_none();
837
+ if missing_spec && plan.intent.verb == Verb::Restart && target.is_none() {
838
+ // Keep restart's stopped-roster fence ahead of spec/source admission.
839
+ // Its original locked handler owns reconstruction for active rosters.
840
+ let rows = selected
841
+ .state
842
+ .get("agents")
843
+ .and_then(Value::as_object)
844
+ .ok_or_else(|| refusal("missing agents"))?;
845
+ let mut active = false;
846
+ for (id, row) in rows {
847
+ if !paused(row)
848
+ && !crate::state::projection::agent_explicit_stop(row)
849
+ && !crate::state::projection::agent_stopped_for_restart(row)
850
+ {
851
+ if observe(&selected, id, row)? == Observation::Unknown {
852
+ return Err(refusal("unknown physical identity"));
838
853
  }
854
+ active = true;
855
+ } else {
856
+ plan.skipped.push(json!({"agent":id,"reason":if paused(row){"paused"}else if crate::state::projection::agent_explicit_stop(row){"explicit_stop"}else{"stopped_preserved_by_original_restart"}}));
839
857
  }
840
- if !active {
841
- return Ok(no_eligible(
842
- plan,
843
- "missing spec cannot be rebuilt without an active roster",
844
- ));
845
- }
846
- plan.steps.push(Step::RestartTeam(restart_args(&plan)));
847
- return Ok(plan);
848
858
  }
849
- return Err(refusal(
850
- "runtime spec missing; use explicit team restart to request supported reconstruction",
851
- ));
859
+ if !active {
860
+ return Ok(no_eligible(
861
+ plan,
862
+ "stopped roster requires explicit team start",
863
+ ));
864
+ }
865
+ plan.steps.push(Step::RestartTeam(restart_args(&plan)));
866
+ return Ok(plan);
852
867
  }
853
- let spec = spec.ok_or_else(|| refusal("missing spec"))?;
854
- let spec_value = checked(yaml::loads(&std::fs::read_to_string(spec)?))?;
868
+ let runtime_spec =
869
+ crate::model::paths::runtime_spec_path(&selected.run_workspace, &selected.team_key);
870
+ let spec_value = match spec {
871
+ Some(path) => checked(yaml::loads(&std::fs::read_to_string(path)?))?,
872
+ None if plan.intent.verb != Verb::Stop => checked(
873
+ crate::lifecycle::restart::compile_runtime_spec_from_roles(
874
+ &selected.run_workspace, &selected.team_key, &selected.state,
875
+ ),
876
+ )?,
877
+ None => return Err(refusal("runtime spec missing; team stop can inspect and stop the selected runtime without rebuilding it")),
878
+ };
855
879
  validate_roster(
856
880
  &spec_value,
857
- spec.parent().unwrap_or(&selected.run_workspace),
881
+ spec.unwrap_or(&runtime_spec)
882
+ .parent()
883
+ .unwrap_or(&selected.run_workspace),
858
884
  )?;
859
885
  let spec_ids: BTreeSet<String> = spec_value
860
886
  .get("agents")
@@ -1043,6 +1069,16 @@ fn plan_with_observer(
1043
1069
  {
1044
1070
  return Ok(no_eligible(plan, "no eligible nonpaused roster"));
1045
1071
  }
1072
+ if missing_spec {
1073
+ plan.steps.insert(
1074
+ 0,
1075
+ Step::RestoreSpec {
1076
+ workspace: selected.run_workspace,
1077
+ team: selected.team_key,
1078
+ compiled: spec_value,
1079
+ },
1080
+ );
1081
+ }
1046
1082
  Ok(plan)
1047
1083
  }
1048
1084
  fn restart_args(plan: &Plan) -> RestartArgs {
@@ -54,6 +54,143 @@ fn absent_source_is_one_original_create_not_restart_or_probe() {
54
54
  assert_eq!(actions(&plan), [("quick_start", None)]);
55
55
  assert!(!crate::state::persist::runtime_state_path(root.path()).exists());
56
56
  }
57
+ #[test]
58
+ #[serial_test::serial(env)]
59
+ fn startup_spec_red_stopped_team_uses_start_without_restart_or_planning_writes() {
60
+ let (root, intent) = fixture(&["one", "two"]);
61
+ install(
62
+ root.path(),
63
+ &[("one", "stopped", true), ("two", "stopped", false)],
64
+ );
65
+ let spec = crate::model::paths::runtime_spec_path(root.path(), "fixture");
66
+ std::fs::remove_file(&spec).unwrap();
67
+ let state = crate::state::persist::runtime_state_path(root.path());
68
+ let before = std::fs::read(&state).unwrap();
69
+ let result = plan_with_observer(intent, |_, _, _| Ok(Observation::StoppedVerified));
70
+ assert_eq!(std::fs::read(&state).unwrap(), before);
71
+ assert!(
72
+ !spec.exists(),
73
+ "readonly planning must not rebuild the spec"
74
+ );
75
+ let plan = result.expect("complete roles must provide a noncircular start plan when only the derived spec is missing");
76
+ assert_eq!(
77
+ plan.steps
78
+ .iter()
79
+ .filter_map(|step| match step {
80
+ Step::StartAgent(args) => Some(args.agent.as_str()),
81
+ _ => None,
82
+ })
83
+ .collect::<Vec<_>>(),
84
+ ["one", "two"]
85
+ );
86
+ assert!(!plan
87
+ .steps
88
+ .iter()
89
+ .any(|step| matches!(step, Step::RestartTeam(_) | Step::StopAgent(_))));
90
+ }
91
+
92
+ #[test]
93
+ #[serial_test::serial(env)]
94
+ fn startup_spec_red_live_team_recovers_metadata_without_process_restart() {
95
+ let (root, intent) = fixture(&["one"]);
96
+ install(root.path(), &[("one", "running", false)]);
97
+ let spec = crate::model::paths::runtime_spec_path(root.path(), "fixture");
98
+ std::fs::remove_file(&spec).unwrap();
99
+ let state = crate::state::persist::runtime_state_path(root.path());
100
+ let before = std::fs::read(&state).unwrap();
101
+ let result = plan_with_observer(intent, |_, _, _| Ok(Observation::Live));
102
+ assert_eq!(std::fs::read(&state).unwrap(), before);
103
+ assert!(!spec.exists());
104
+ let plan =
105
+ result.expect("missing derived metadata must not require restarting a verified live seat");
106
+ assert!(!plan.steps.iter().any(|step| matches!(
107
+ step,
108
+ Step::StartAgent(_) | Step::StopAgent(_) | Step::RestartTeam(_) | Step::CreateTeam(_)
109
+ )));
110
+ assert!(plan
111
+ .skipped
112
+ .iter()
113
+ .any(|entry| entry["reason"] == "already_running"));
114
+ }
115
+
116
+ #[test]
117
+ #[serial_test::serial(env)]
118
+ fn startup_spec_repair_executes_only_metadata_and_preserves_seat_identity() {
119
+ let (root, intent) = fixture(&["one"]);
120
+ install(root.path(), &[("one", "stopped", true)]);
121
+ let spec = crate::model::paths::runtime_spec_path(root.path(), "fixture");
122
+ std::fs::remove_file(&spec).unwrap();
123
+ let state = crate::state::persist::runtime_state_path(root.path());
124
+ let before: Value = serde_json::from_slice(&std::fs::read(&state).unwrap()).unwrap();
125
+ let plan = plan_with_observer(intent, |_, _, _| Ok(Observation::StoppedVerified)).unwrap();
126
+ let repair = plan
127
+ .steps
128
+ .iter()
129
+ .find(|step| matches!(step, Step::RestoreSpec { .. }))
130
+ .unwrap();
131
+ for _ in 0..2 {
132
+ recheck(&plan, repair, false).unwrap();
133
+ assert_eq!(repair.execute().unwrap().exit, ExitCode::Ok);
134
+ assert!(spec.is_file());
135
+ let after: Value = serde_json::from_slice(&std::fs::read(&state).unwrap()).unwrap();
136
+ assert_eq!(after["teams"]["fixture"]["spec_path"], json!(spec));
137
+ assert_eq!(
138
+ relevant(&after["teams"]["fixture"]["agents"]["one"]),
139
+ relevant(&before["teams"]["fixture"]["agents"]["one"])
140
+ );
141
+ assert_eq!(
142
+ after["teams"]["fixture"]["agents"]["one"]["explicit_stop"],
143
+ true
144
+ );
145
+ }
146
+ }
147
+
148
+ #[test]
149
+ #[serial_test::serial(env)]
150
+ fn startup_spec_repair_rechecks_source_under_lock_and_unknown_stays_blocked() {
151
+ let (root, intent) = fixture(&["one"]);
152
+ install(root.path(), &[("one", "stopped", true)]);
153
+ let spec = crate::model::paths::runtime_spec_path(root.path(), "fixture");
154
+ std::fs::remove_file(&spec).unwrap();
155
+ assert!(plan_with_observer(intent.clone(), |_, _, _| Ok(Observation::Unknown)).is_err());
156
+ assert!(!spec.exists());
157
+ let plan = plan_with_observer(intent, |_, _, _| Ok(Observation::StoppedVerified)).unwrap();
158
+ let repair = plan
159
+ .steps
160
+ .iter()
161
+ .find(|step| matches!(step, Step::RestoreSpec { .. }))
162
+ .unwrap();
163
+ let state = crate::state::persist::runtime_state_path(root.path());
164
+ let before = std::fs::read(&state).unwrap();
165
+ let role = root.path().join("agents/one.md");
166
+ let changed = std::fs::read_to_string(&role)
167
+ .unwrap()
168
+ .replace("Fixture", "Changed role body");
169
+ std::fs::write(role, changed).unwrap();
170
+ assert!(
171
+ repair.execute().is_err(),
172
+ "the executor must not rely only on the earlier planner recheck"
173
+ );
174
+ assert_eq!(std::fs::read(state).unwrap(), before);
175
+ assert!(!spec.exists());
176
+ }
177
+
178
+ #[test]
179
+ #[serial_test::serial(env)]
180
+ fn startup_spec_missing_restart_still_preserves_explicit_stop() {
181
+ let (root, mut intent) = fixture(&["one"]);
182
+ install(root.path(), &[("one", "stopped", true)]);
183
+ let spec = crate::model::paths::runtime_spec_path(root.path(), "fixture");
184
+ std::fs::remove_file(&spec).unwrap();
185
+ intent.verb = Verb::Restart;
186
+ let plan =
187
+ plan_with_observer(intent, |_, _, _| panic!("held seat must not be probed")).unwrap();
188
+ assert!(plan.steps.is_empty());
189
+ assert!(plan.no_eligible.is_some());
190
+ assert_eq!(plan.skipped[0]["reason"], "explicit_stop");
191
+ assert!(!spec.exists());
192
+ }
193
+
57
194
  #[test]
58
195
  #[serial_test::serial(env)]
59
196
  fn stopped_team_starts_both_and_mixed_start_leaves_live_peer_untouched() {
@@ -25,6 +25,43 @@ impl Drop for Sandbox {
25
25
  }
26
26
  }
27
27
 
28
+ #[test]
29
+ fn native_receipt_reconciliation_is_start_only_not_implicit_stop_or_restart() {
30
+ assert_eq!(
31
+ seat_actions(
32
+ Verb::Start,
33
+ Observation::NativeReconcile,
34
+ false,
35
+ false,
36
+ false,
37
+ true
38
+ )
39
+ .unwrap(),
40
+ vec!["start"]
41
+ );
42
+ for verb in [Verb::Stop, Verb::Restart] {
43
+ assert!(seat_actions(
44
+ verb,
45
+ Observation::NativeReconcile,
46
+ false,
47
+ false,
48
+ false,
49
+ false
50
+ )
51
+ .is_err());
52
+ }
53
+ assert!(seat_actions(
54
+ Verb::Restart,
55
+ Observation::NativeReconcile,
56
+ false,
57
+ true,
58
+ false,
59
+ true
60
+ )
61
+ .unwrap()
62
+ .is_empty());
63
+ }
64
+
28
65
  fn args(values: &[&str]) -> Vec<String> {
29
66
  values.iter().map(|v| v.to_string()).collect()
30
67
  }
@@ -61,10 +61,16 @@ pub(super) enum Observation {
61
61
  Live,
62
62
  StoppedVerified,
63
63
  Unstarted,
64
+ NativeReconcile,
64
65
  Unknown,
65
66
  }
66
67
  #[derive(Clone, Debug)]
67
68
  pub(super) enum Step {
69
+ RestoreSpec {
70
+ workspace: PathBuf,
71
+ team: String,
72
+ compiled: crate::model::yaml::Value,
73
+ },
68
74
  CreateTeam(QuickStartArgs),
69
75
  StartAgent(StartAgentArgs),
70
76
  AddAgent(AddAgentArgs),
@@ -75,6 +81,7 @@ pub(super) enum Step {
75
81
  impl Step {
76
82
  fn name(&self) -> &'static str {
77
83
  match self {
84
+ Self::RestoreSpec { .. } => "restore_runtime_spec",
78
85
  Self::CreateTeam(_) => "quick_start",
79
86
  Self::StartAgent(_) => "start_agent",
80
87
  Self::AddAgent(_) => "add_agent",
@@ -93,6 +100,21 @@ impl Step {
93
100
  }
94
101
  fn execute(&self) -> Result<CmdResult, CliError> {
95
102
  match self {
103
+ Self::RestoreSpec {
104
+ workspace,
105
+ team,
106
+ compiled,
107
+ } => {
108
+ let path = crate::lifecycle::restart::restore_missing_runtime_spec(
109
+ workspace, team, compiled,
110
+ )
111
+ .map_err(|e| CliError::Runtime(e.to_string()))?;
112
+ Ok(CmdResult::from_json(
113
+ json!({"ok":true,"status":"metadata_restored","spec_path":path,
114
+ "effects":{"native_processes":"not_attempted","native_input":"not_attempted"}}),
115
+ true,
116
+ ))
117
+ }
96
118
  Self::CreateTeam(a) => cmd_quick_start(a),
97
119
  Self::StartAgent(a) => cmd_start_agent(a),
98
120
  Self::AddAgent(a) => cmd_add_agent(a),