@team-agent/installer 0.5.125 → 0.5.127

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 (144) hide show
  1. package/Cargo.lock +1 -1
  2. package/Cargo.toml +1 -1
  3. package/crates/team-agent/src/cli/diagnose.rs +0 -137
  4. package/crates/team-agent/src/cli/emit.rs +13 -8
  5. package/crates/team-agent/src/cli/grok_slot.rs +88 -3
  6. package/crates/team-agent/src/cli/intent/runtime.rs +6 -4
  7. package/crates/team-agent/src/cli/intent/runtime_tests.rs +55 -10
  8. package/crates/team-agent/src/cli/mod.rs +35 -29
  9. package/crates/team-agent/src/cli/models.rs +33 -944
  10. package/crates/team-agent/src/cli/tests/leader_watch.rs +1 -1
  11. package/crates/team-agent/src/cli/tests/mod.rs +3 -3
  12. package/crates/team-agent/src/cli/tests/run_delegation.rs +8 -7
  13. package/crates/team-agent/src/cli/tests/status_send.rs +2 -2
  14. package/crates/team-agent/src/compiler/tests.rs +54 -12
  15. package/crates/team-agent/src/compiler.rs +7 -205
  16. package/crates/team-agent/src/contract_runtime/backend.rs +97 -38
  17. package/crates/team-agent/src/contract_runtime/commands.rs +335 -4
  18. package/crates/team-agent/src/contract_runtime/config.rs +12 -8
  19. package/crates/team-agent/src/contract_runtime/fork.rs +368 -0
  20. package/crates/team-agent/src/contract_runtime/framework.rs +8 -13
  21. package/crates/team-agent/src/contract_runtime/mod.rs +1 -0
  22. package/crates/team-agent/src/contract_runtime/registry.rs +100 -60
  23. package/crates/team-agent/src/coordinator/steps/abnormal.rs +45 -5
  24. package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +54 -16
  25. package/crates/team-agent/src/coordinator/tests/energy.rs +4 -4
  26. package/crates/team-agent/src/coordinator/tests/health_sync.rs +2 -44
  27. package/crates/team-agent/src/coordinator/tests/main_preserved.rs +2 -2
  28. package/crates/team-agent/src/coordinator/tests/spine.rs +1 -1
  29. package/crates/team-agent/src/coordinator/tests/takeover.rs +3 -3
  30. package/crates/team-agent/src/leader/start.rs +1 -1
  31. package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +2 -195
  32. package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +11 -27
  33. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +22 -200
  34. package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +6 -87
  35. package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +5 -496
  36. package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +74 -244
  37. package/crates/team-agent/src/lifecycle/launch/quick_start.rs +2 -26
  38. package/crates/team-agent/src/lifecycle/launch/role_source.rs +5 -0
  39. package/crates/team-agent/src/lifecycle/launch/spawn.rs +26 -51
  40. package/crates/team-agent/src/lifecycle/launch.rs +3 -34
  41. package/crates/team-agent/src/lifecycle/profile_launch.rs +18 -373
  42. package/crates/team-agent/src/lifecycle/restart/common.rs +45 -463
  43. package/crates/team-agent/src/lifecycle/restart/remove.rs +129 -0
  44. package/crates/team-agent/src/lifecycle/restart/selection.rs +5 -5
  45. package/crates/team-agent/src/lifecycle/restart.rs +0 -2
  46. package/crates/team-agent/src/lifecycle/role_config.rs +40 -13
  47. package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +1 -1
  48. package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +8 -12
  49. package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +38 -236
  50. package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +8 -320
  51. package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +106 -186
  52. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +4 -334
  53. package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +19 -15
  54. package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +2 -2
  55. package/crates/team-agent/src/lifecycle/tests/core.rs +33 -58
  56. package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +22 -8
  57. package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +15 -133
  58. package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +3 -51
  59. package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +30 -67
  60. package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +3 -31
  61. package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +194 -169
  62. package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +162 -284
  63. package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +15 -78
  64. package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +7 -7
  65. package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +75 -69
  66. package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +2 -10
  67. package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +6 -18
  68. package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +52 -70
  69. package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +4 -157
  70. package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +10 -302
  71. package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +1 -68
  72. package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +1 -19
  73. package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +2 -100
  74. package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +15 -14
  75. package/crates/team-agent/src/lifecycle/tests/restart.rs +12 -153
  76. package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +27 -5
  77. package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +59 -10
  78. package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +47 -6
  79. package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +3 -1478
  80. package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +27 -10
  81. package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +7 -7
  82. package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +67 -313
  83. package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +2 -254
  84. package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +2 -2
  85. package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +1 -1
  86. package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +2 -2
  87. package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +4 -4
  88. package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +74 -19
  89. package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +39 -38
  90. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +42 -97
  91. package/crates/team-agent/src/lifecycle/tests.rs +0 -7
  92. package/crates/team-agent/src/lifecycle/types.rs +2 -21
  93. package/crates/team-agent/src/mcp_server/readiness_tests.rs +15 -17
  94. package/crates/team-agent/src/messaging/delivery.rs +14 -195
  95. package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +5 -5
  96. package/crates/team-agent/src/messaging/tests/dup_inject.rs +68 -69
  97. package/crates/team-agent/src/messaging/tests/main_preserved.rs +2 -2
  98. package/crates/team-agent/src/messaging/tests/runtime.rs +5 -5
  99. package/crates/team-agent/src/messaging/tests/spine.rs +30 -32
  100. package/crates/team-agent/src/messaging/tests/wave2.rs +13 -20
  101. package/crates/team-agent/src/provider/adapter.rs +71 -572
  102. package/crates/team-agent/src/provider/adapters/mod.rs +6 -8
  103. package/crates/team-agent/src/provider/model_catalog.rs +13 -201
  104. package/crates/team-agent/src/provider/session/capture.rs +11 -211
  105. package/crates/team-agent/src/provider/session/context_fork/outcome.rs +8 -24
  106. package/crates/team-agent/src/provider/session/context_fork.rs +29 -240
  107. package/crates/team-agent/src/provider/session/mod.rs +2 -3
  108. package/crates/team-agent/src/provider/session_scan/common.rs +27 -87
  109. package/crates/team-agent/src/provider/session_scan/pi.rs +1 -34
  110. package/crates/team-agent/src/provider/session_scan.rs +7 -23
  111. package/crates/team-agent/src/provider/tests/adapter.rs +66 -204
  112. package/crates/team-agent/src/provider/tests/command_helpers.rs +3 -29
  113. package/crates/team-agent/src/provider/tests/idle.rs +0 -68
  114. package/crates/team-agent/src/provider/types.rs +0 -4
  115. package/crates/team-agent/src/provider/wire.rs +77 -23
  116. package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +1 -1
  117. package/crates/team-agent/src/state/persist.rs +6 -6
  118. package/crates/team-agent/src/state/repository/tests.rs +2 -2
  119. package/crates/team-agent/src/tmux_backend.rs +4 -3
  120. package/package.json +4 -4
  121. package/skills/team-agent/SKILL.md +8 -5
  122. package/skills/team-agent/command-coverage.json +29 -1
  123. package/skills/team-agent/docs/reference/team-agent-operator.md +7 -3
  124. package/skills/team-agent/references/team-agent-operator.md +7 -3
  125. package/crates/team-agent/src/lifecycle/launch/grok_per_seat.rs +0 -260
  126. package/crates/team-agent/src/lifecycle/restart/avatar.rs +0 -1805
  127. package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +0 -325
  128. package/crates/team-agent/src/lifecycle/tests/codex_weak_window_attribution_red.rs +0 -683
  129. package/crates/team-agent/src/lifecycle/tests/grok_effort_argv_red.rs +0 -247
  130. package/crates/team-agent/src/lifecycle/tests/grok_mcp_overlay_red.rs +0 -507
  131. package/crates/team-agent/src/lifecycle/tests/grok_restart_resume_red.rs +0 -300
  132. package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +0 -210
  133. package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +0 -1409
  134. package/crates/team-agent/src/provider/adapters/claude.rs +0 -78
  135. package/crates/team-agent/src/provider/adapters/claude_fork.rs +0 -131
  136. package/crates/team-agent/src/provider/adapters/codex.rs +0 -101
  137. package/crates/team-agent/src/provider/adapters/grok.rs +0 -67
  138. package/crates/team-agent/src/provider/adapters/pi.rs +0 -100
  139. package/crates/team-agent/src/provider/session/context_fork/claude.rs +0 -123
  140. package/crates/team-agent/src/provider/session/context_fork/codex.rs +0 -514
  141. package/crates/team-agent/src/provider/session_scan/claude.rs +0 -523
  142. package/crates/team-agent/src/provider/session_scan/codex.rs +0 -326
  143. package/crates/team-agent/src/provider/session_scan/grok.rs +0 -288
  144. package/crates/team-agent/src/test_support/models_timeout_fixture.rs +0 -144
@@ -2,22 +2,15 @@
2
2
  use super::{CliError, CmdOutput, CmdResult, ExitCode, ModelsArgs};
3
3
  use serde_json::{json, Value};
4
4
  #[cfg(test)]
5
- use std::collections::BTreeMap;
6
- #[cfg(test)]
7
5
  use std::path::Path;
8
- #[cfg(test)]
9
- use std::time::Duration;
10
-
11
- #[cfg(test)]
12
- const CATALOG_TIMEOUT: Duration = Duration::from_secs(10);
13
- #[cfg(test)]
14
- const MAX_CATALOG_BYTES: u64 = 1024 * 1024;
15
6
  type ModelRecord = crate::provider::model_catalog::ModelRecord;
16
7
 
17
8
  pub fn cmd_models(args: &ModelsArgs) -> Result<CmdResult, CliError> {
18
9
  #[cfg(unix)]
19
- if let Some(descriptor) = crate::contract_runtime::registry::declared(&args.provider, false) {
20
- // A role's provider names its catalog: `agent` or `cursor-agent` is the Cursor leaf.
10
+ if let Some(descriptor) = crate::contract_runtime::registry::declared(&args.provider) {
11
+ // A role's provider names its catalog: `agent` or `cursor-agent` is the
12
+ // Cursor leaf; `claude`/`claude_code`, `codex`, `grok` and `pi` are the
13
+ // Claude Code, Codex, Grok Build and Pi leaves.
21
14
  let args = ModelsArgs { provider: descriptor.identity.id.into(), ..args.clone() };
22
15
  return crate::contract_runtime::discovery::models(&args);
23
16
  }
@@ -42,14 +35,9 @@ fn render_catalog(args: &ModelsArgs, all: Vec<ModelRecord>) -> Result<CmdResult,
42
35
  .collect()
43
36
  },
44
37
  );
45
- let current = if args.provider == "pi" {
46
- current_role_model(&all.iter().map(|model| model.id.clone()).collect::<Vec<_>>())
47
- } else {
48
- None
49
- };
50
38
  let entries: Vec<Value> = visible.iter().map(|model| json!({
51
39
  "role_model": model.id,
52
- "current": if args.provider == "pi" { json!(current.as_deref() == Some(model.id.as_str())) } else { Value::Null },
40
+ "current": Value::Null,
53
41
  "provider": model.provider,
54
42
  "vendor": model.vendor,
55
43
  "model_id": model.id,
@@ -60,7 +48,7 @@ fn render_catalog(args: &ModelsArgs, all: Vec<ModelRecord>) -> Result<CmdResult,
60
48
  let provider = args.provider.as_str();
61
49
  let value = json!({
62
50
  "schema_version": "models.v1", "ok": true, "provider": provider, "models": entries,
63
- "auth": "ok", "auth_basis": "catalog_visibility", "current_role_model": current, "search": args.search,
51
+ "auth": "ok", "auth_basis": "catalog_visibility", "current_role_model": Value::Null, "search": args.search,
64
52
  });
65
53
  if args.json {
66
54
  Ok(CmdResult {
@@ -81,11 +69,7 @@ fn render_catalog(args: &ModelsArgs, all: Vec<ModelRecord>) -> Result<CmdResult,
81
69
  model.vendor,
82
70
  model.id,
83
71
  model.display_name,
84
- if args.provider == "pi" {
85
- (current.as_deref() == Some(model.id.as_str())).to_string()
86
- } else {
87
- "—".to_string()
88
- },
72
+ "—",
89
73
  model
90
74
  .default
91
75
  .map_or_else(|| "—".to_string(), |value| value.to_string()),
@@ -102,44 +86,6 @@ fn render_catalog(args: &ModelsArgs, all: Vec<ModelRecord>) -> Result<CmdResult,
102
86
  }
103
87
  }
104
88
 
105
- #[cfg(test)]
106
- fn cmd_models_with(
107
- args: &ModelsArgs,
108
- program: &Path,
109
- timeout: Duration,
110
- max_bytes: u64,
111
- ) -> Result<CmdResult, CliError> {
112
- let bytes = match run_catalog(program, timeout, max_bytes) {
113
- Ok(bytes) => bytes,
114
- Err(message) => return Ok(failure(args, &message)),
115
- };
116
- let all = match crate::provider::model_catalog::parse_pi_catalog(&bytes).map_err(|error| error.message("pi")) {
117
- Ok(models) => models,
118
- Err(message) => return Ok(failure(args, &message)),
119
- };
120
- render_catalog(args, all)
121
- }
122
-
123
- #[cfg(test)]
124
- fn model_matches(model: &ModelRecord, search: &str) -> bool {
125
- crate::provider::model_catalog::model_matches(model, search)
126
- }
127
-
128
- #[cfg(test)]
129
- fn failure(args: &ModelsArgs, message: &str) -> CmdResult {
130
- let action = if message.starts_with("unsupported model provider") {
131
- "choose a supported provider: pi, codex, claude, or claude_code".to_string()
132
- } else {
133
- let executable = match args.provider.as_str() {
134
- "codex" => "codex",
135
- "claude" | "claude_code" => "claude",
136
- _ => "pi",
137
- };
138
- format!("install or repair the PATH-first `{executable}` executable, then retry `team-agent models --provider {}`", args.provider)
139
- };
140
- failure_with_action(args, message, &action)
141
- }
142
-
143
89
  fn failure_with_action(args: &ModelsArgs, message: &str, action: &str) -> CmdResult {
144
90
  let value = json!({ "schema_version": "models.v1", "ok": false, "provider": args.provider, "auth": "not_ready", "auth_basis": "catalog_visibility", "models": Value::Array(Vec::new()), "current_role_model": Value::Null, "error": message, "action": action });
145
91
  if args.json {
@@ -155,39 +101,11 @@ fn failure_with_action(args: &ModelsArgs, message: &str, action: &str) -> CmdRes
155
101
  CmdResult { output: CmdOutput::Human(format!("models.v1 | error: {message}\naction: {action}\nauth: not_ready (catalog_visibility)")), exit: ExitCode::Error, as_json: false, preserve_json_order: false }
156
102
  }
157
103
  }
158
- fn current_role_model(models: &[String]) -> Option<String> {
159
- current_role_model_from(
160
- models,
161
- std::env::var("PI_PROVIDER").ok().as_deref(),
162
- std::env::var("PI_MODEL").ok().as_deref(),
163
- )
164
- }
165
- fn current_role_model_from(
166
- models: &[String],
167
- provider: Option<&str>,
168
- model: Option<&str>,
169
- ) -> Option<String> {
170
- let exact = format!("{}/{}", provider?, model?);
171
- models
172
- .iter()
173
- .any(|candidate| candidate == &exact)
174
- .then_some(exact)
175
- }
176
-
177
- /// Injectable executable, deadline, and byte-limit boundary for deterministic tests.
178
- #[cfg(test)]
179
- fn run_catalog(program: &Path, timeout: Duration, max_bytes: u64) -> Result<Vec<u8>, String> {
180
- crate::lifecycle::launch::pi_mcp::run_pi_catalog(program, timeout, max_bytes)
181
- }
182
-
183
104
  #[cfg(test)]
184
105
  mod tests {
185
106
  use super::*;
186
107
  #[cfg(unix)]
187
- use std::io::Write;
188
- #[cfg(unix)]
189
108
  use std::sync::atomic::{AtomicU64, Ordering};
190
- use std::time::Instant;
191
109
 
192
110
  #[cfg(unix)]
193
111
  static FIXTURE_SEQUENCE: AtomicU64 = AtomicU64::new(0);
@@ -207,126 +125,6 @@ mod tests {
207
125
  std::process::exit(exit.code());
208
126
  }
209
127
 
210
- #[cfg(unix)]
211
- #[test]
212
- fn real_dispatcher_isolated_success_json_human_and_no_match() {
213
- let pi = fixture("printf 'provider model\\nopenai-codex gpt-5.6-sol\\n'");
214
- let dir = pi.parent().unwrap().to_path_buf();
215
- let run_child = |args: &[&str], model: &str| {
216
- std::process::Command::new(std::env::current_exe().unwrap())
217
- .args([
218
- "--exact",
219
- "cli::models::tests::real_dispatcher_child_helper",
220
- "--nocapture",
221
- ])
222
- .env("TEAM_AGENT_MODELS_CHILD", "1")
223
- .env(
224
- "TEAM_AGENT_MODELS_ARGS",
225
- serde_json::to_string(args).unwrap(),
226
- )
227
- .env("PATH", &dir)
228
- .env("PI_PROVIDER", "openai-codex")
229
- .env("PI_MODEL", model)
230
- .output()
231
- .unwrap()
232
- };
233
- let json = run_child(&["models", "--provider", "pi", "--json"], "gpt-5.6-sol");
234
- assert!(json.status.success());
235
- let output = String::from_utf8(json.stdout).unwrap();
236
- let cli_output = output
237
- .split("__TEAM_AGENT_MODELS_CLI_OUTPUT_v1__\n")
238
- .nth(1)
239
- .unwrap();
240
- let value: Value = serde_json::from_str(cli_output.trim()).unwrap();
241
- assert_eq!(value["schema_version"], "models.v1");
242
- assert_eq!(value["models"][0]["role_model"], "openai-codex/gpt-5.6-sol");
243
- assert_eq!(value["models"][0]["current"], true);
244
- let human = run_child(
245
- &["models", "--provider", "pi", "--search", "absent"],
246
- "missing",
247
- );
248
- assert!(human.status.success());
249
- let human_output = String::from_utf8(human.stdout).unwrap();
250
- let text = human_output
251
- .split("__TEAM_AGENT_MODELS_CLI_OUTPUT_v1__\n")
252
- .nth(1)
253
- .unwrap();
254
- assert!(text.contains("No models matched --search") && text.contains("auth: ok"));
255
- let null = run_child(&["models", "--provider", "pi", "--json"], "missing");
256
- let null_output = String::from_utf8(null.stdout).unwrap();
257
- let null_cli = null_output
258
- .split("__TEAM_AGENT_MODELS_CLI_OUTPUT_v1__\n")
259
- .nth(1)
260
- .unwrap();
261
- let null_value: Value = serde_json::from_str(null_cli.trim()).unwrap();
262
- assert!(null.status.success() && null_value["current_role_model"].is_null());
263
- std::fs::write(&pi, "#!/bin/sh\nprintf 'sensitive-stderr' >&2\nexit 7\n").unwrap();
264
- let failed = run_child(&["models", "--provider", "pi", "--json"], "missing");
265
- assert!(!failed.status.success());
266
- let failed_output = String::from_utf8(failed.stdout).unwrap();
267
- let failed_cli = failed_output
268
- .split("__TEAM_AGENT_MODELS_CLI_OUTPUT_v1__\n")
269
- .nth(1)
270
- .unwrap();
271
- assert!(!failed_cli.contains("sensitive-stderr"));
272
- assert_eq!(
273
- std::fs::read_to_string(pi.with_extension("count"))
274
- .unwrap()
275
- .lines()
276
- .count(),
277
- 3
278
- );
279
- cleanup_fixture(&pi);
280
- }
281
-
282
- #[test]
283
- fn current_model_is_deterministic() {
284
- let models = vec!["openai-codex/gpt-5.6-sol".into()];
285
- assert_eq!(
286
- current_role_model_from(&models, Some("openai-codex"), Some("gpt-5.6-sol")),
287
- Some("openai-codex/gpt-5.6-sol".into())
288
- );
289
- assert_eq!(
290
- current_role_model_from(&models, Some("openai-codex"), Some("other")),
291
- None
292
- );
293
- assert_eq!(
294
- current_role_model_from(&models, None, Some("gpt-5.6-sol")),
295
- None
296
- );
297
- }
298
-
299
- #[cfg(unix)]
300
- #[test]
301
- fn search_survives_unrelated_spaced_model_ids() {
302
- let catalog =
303
- include_str!("../lifecycle/tests/fixtures/pi_list_models_spaced_ids.stdout.txt");
304
- let path = fixture(&format!("printf '%s' '{catalog}'"));
305
- let result = cmd_models_with(
306
- &ModelsArgs {
307
- provider: "pi".into(),
308
- search: Some("gpt-5.6-luna".into()),
309
- json: true,
310
- },
311
- &path,
312
- Duration::from_secs(10),
313
- MAX_CATALOG_BYTES,
314
- )
315
- .unwrap();
316
- cleanup_fixture(&path);
317
- assert_eq!(result.exit, ExitCode::Ok);
318
- let CmdOutput::Human(text) = result.output else {
319
- panic!("expected JSON projection")
320
- };
321
- let value: Value = serde_json::from_str(&text).unwrap();
322
- assert_eq!(value["ok"], true);
323
- assert_eq!(value["auth"], "ok");
324
- let models = value["models"].as_array().unwrap();
325
- assert_eq!(models.len(), 2);
326
- assert_eq!(models[0]["role_model"], "openai-codex/gpt-5.6-luna");
327
- assert_eq!(models[1]["role_model"], "team-agent/gpt-5.6-luna");
328
- }
329
-
330
128
  #[cfg(unix)]
331
129
  #[test]
332
130
  fn cursor_contract_catalog_uses_public_launcher_metadata_then_exact_ids() {
@@ -360,28 +158,32 @@ esac"#);
360
158
  #[cfg(unix)]
361
159
  #[test]
362
160
  fn grok_build_contract_catalog_runs_the_public_grok_found_on_path() {
363
- let program = fixture_program("grok", r#"
161
+ // The public `grok` provider name declares the Grok Build leaf; both
162
+ // names read the same contract catalog.
163
+ for name in ["grok_build", "grok"] {
164
+ let program = fixture_program("grok", r#"
364
165
  test "$#" = 1 || exit 9
365
166
  case "$1" in
366
167
  --version) printf '%s\n' 'grok 1.0.52 (0920c8169e27)' ;;
367
168
  models) exec /bin/cat "$TEAM_AGENT_MODELS_FIXTURE" ;;
368
169
  *) exit 9 ;;
369
170
  esac"#);
370
- let mut grok = CliFixture::new(program);
371
- let response = grok.program.with_extension("stdout");
372
- std::fs::write(&response, include_bytes!("../provider/testdata/grok-models-authenticated.stdout")).unwrap();
373
- grok.response = Some(response);
374
- let output = run_public_models_cli(&grok.program, grok.response.as_deref(),
375
- &["models", "--provider", "grok_build", "--json"]);
376
- let text = public_cli_text(&output);
377
- let calls = std::fs::read_to_string(grok.program.with_extension("count")).unwrap_or_default();
378
- assert!(output.status.success(), "{text}");
379
- // Whatever `grok` PATH selects answers every probe; no install path is assumed.
380
- assert_eq!(calls, "1:--version\n1:models\n");
381
- let value: Value = serde_json::from_str(text.trim()).unwrap();
382
- assert_eq!(value["provider"], "grok_build");
383
- assert_eq!(value["source"]["executable"], grok.program.to_str().unwrap());
384
- assert!(value["models"].as_array().unwrap().iter().any(|row| row["model_id"] == "grok-4.7-build-fast"));
171
+ let mut grok = CliFixture::new(program);
172
+ let response = grok.program.with_extension("stdout");
173
+ std::fs::write(&response, include_bytes!("../provider/testdata/grok-models-authenticated.stdout")).unwrap();
174
+ grok.response = Some(response);
175
+ let output = run_public_models_cli(&grok.program, grok.response.as_deref(),
176
+ &["models", "--provider", name, "--json"]);
177
+ let text = public_cli_text(&output);
178
+ let calls = std::fs::read_to_string(grok.program.with_extension("count")).unwrap_or_default();
179
+ assert!(output.status.success(), "{name}: {text}");
180
+ // Whatever `grok` PATH selects answers every probe; no install path is assumed.
181
+ assert_eq!(calls, "1:--version\n1:models\n", "{name}");
182
+ let value: Value = serde_json::from_str(text.trim()).unwrap();
183
+ assert_eq!(value["provider"], "grok_build", "{name}");
184
+ assert_eq!(value["source"]["executable"], grok.program.to_str().unwrap(), "{name}");
185
+ assert!(value["models"].as_array().unwrap().iter().any(|row| row["model_id"] == "grok-4.7-build-fast"), "{name}");
186
+ }
385
187
  }
386
188
 
387
189
  #[cfg(unix)]
@@ -437,158 +239,6 @@ esac"#));
437
239
  assert!(value["error"].as_str().unwrap().contains("Cursor release unknown"));
438
240
  }
439
241
 
440
- #[cfg(unix)]
441
- #[test]
442
- fn grok_public_cli_uses_native_catalog_and_keeps_shared_projection() {
443
- let grok = native_cli_fixture(
444
- "grok",
445
- include_bytes!("../provider/testdata/grok-models-authenticated.stdout"),
446
- );
447
- let json = run_public_models_cli(
448
- &grok.program,
449
- grok.response.as_deref(),
450
- &["models", "--provider", "grok", "--json"],
451
- );
452
- let human = run_public_models_cli(
453
- &grok.program,
454
- grok.response.as_deref(),
455
- &["models", "--provider", "grok", "--search", "BUILD FAST"],
456
- );
457
- let no_match = run_public_models_cli(
458
- &grok.program,
459
- grok.response.as_deref(),
460
- &[
461
- "models",
462
- "--provider",
463
- "grok",
464
- "--search",
465
- "definitely-absent",
466
- ],
467
- );
468
- let json_text = public_cli_text(&json);
469
- let human_text = public_cli_text(&human);
470
- let no_match_text = public_cli_text(&no_match);
471
- let calls =
472
- std::fs::read_to_string(grok.program.with_extension("count")).unwrap_or_default();
473
- drop(grok);
474
- assert!(json.status.success(), "{json_text}");
475
- assert!(human.status.success(), "{human_text}");
476
- assert!(no_match.status.success(), "{no_match_text}");
477
- assert_eq!(calls, "1:models\n".repeat(3));
478
- let value: Value = serde_json::from_str(json_text.trim()).unwrap();
479
- assert_eq!(value["schema_version"], "models.v1");
480
- assert_eq!(value["provider"], "grok");
481
- assert_eq!(value["auth_basis"], "catalog_visibility");
482
- let models = value["models"].as_array().unwrap();
483
- assert_eq!(
484
- models
485
- .iter()
486
- .map(|model| model["model_id"].as_str().unwrap())
487
- .collect::<Vec<_>>(),
488
- vec!["grok-4.7", "grok-4.7-build-fast", "grok-4.5", "grok-4.6"]
489
- );
490
- assert!(models.iter().all(|model| model["provider"] == "grok"
491
- && model["vendor"] == "xai"
492
- && model["aliases"] == json!([])));
493
- assert_eq!(models[0]["default"], false);
494
- assert_eq!(models[3]["default"], true);
495
- assert!(human_text.contains("grok-4.7-build-fast"));
496
- assert!(no_match_text.contains("No models matched --search"));
497
- assert!(no_match_text.contains("auth: ok (catalog_visibility)"));
498
-
499
- let grok = native_cli_fixture(
500
- "grok",
501
- include_bytes!("../provider/testdata/grok-models-unauthenticated.stdout"),
502
- );
503
- let changed_default = run_public_models_cli(
504
- &grok.program,
505
- grok.response.as_deref(),
506
- &["models", "--provider", "grok", "--json"],
507
- );
508
- let changed_text = public_cli_text(&changed_default);
509
- drop(grok);
510
- assert!(changed_default.status.success(), "{changed_text}");
511
- let changed: Value = serde_json::from_str(changed_text.trim()).unwrap();
512
- assert_eq!(changed["models"][0]["model_id"], "grok-4.7");
513
- assert_eq!(changed["models"][0]["default"], true);
514
- assert_eq!(changed["models"][1]["default"], false);
515
- }
516
-
517
- #[cfg(unix)]
518
- #[test]
519
- fn grok_invalid_native_catalogs_fail_closed_without_fallback() {
520
- let cases: [(&str, Vec<u8>); 7] = [
521
- ("unknown row", b"You are logged in with grok.com.\n\nDefault model: grok-4.6\n\nAvailable models:\n - grok-4.6\n ? grok-4.5\n".to_vec()),
522
- ("duplicate", b"You are logged in with grok.com.\n\nDefault model: grok-4.6\n\nAvailable models:\n - grok-4.6\n - grok-4.6\n".to_vec()),
523
- ("invalid id", b"You are logged in with grok.com.\n\nDefault model: grok-4.6\n\nAvailable models:\n * grok bad (default)\n".to_vec()),
524
- ("control id", b"You are logged in with grok.com.\n\nDefault model: grok-4.6\n\nAvailable models:\n * grok-\x01evil (default)\n".to_vec()),
525
- ("empty", b"You are not authenticated.\n\nDefault model: grok-4.6\n\nAvailable models:\n".to_vec()),
526
- ("contradictory default", b"You are not authenticated.\n\nDefault model: grok-4.6\n\nAvailable models:\n * grok-4.7 (default)\n - grok-4.6\n".to_vec()),
527
- ("invalid utf8", vec![b'Y', b'o', b'u', 0xff]),
528
- ];
529
- let mut outcomes = Vec::new();
530
- for (name, bytes) in cases {
531
- let grok = native_cli_fixture("grok", &bytes);
532
- let output = run_public_models_cli(
533
- &grok.program,
534
- grok.response.as_deref(),
535
- &["models", "--provider", "grok", "--json"],
536
- );
537
- let text = public_cli_text(&output);
538
- let calls =
539
- std::fs::read_to_string(grok.program.with_extension("count")).unwrap_or_default();
540
- outcomes.push((name, output.status.success(), text, calls));
541
- }
542
- for (name, success, text, calls) in outcomes {
543
- assert!(!success, "{name} catalog unexpectedly accepted: {text}");
544
- assert_eq!(calls, "1:models\n", "{name}");
545
- let value: Value = serde_json::from_str(text.trim()).unwrap();
546
- assert_eq!(value["schema_version"], "models.v1", "{name}");
547
- assert_eq!(value["ok"], false, "{name}");
548
- assert_eq!(value["models"], json!([]), "{name}");
549
- assert!(
550
- !value["error"]
551
- .as_str()
552
- .unwrap()
553
- .to_ascii_lowercase()
554
- .contains("unsupported model provider"),
555
- "{name}: {text}"
556
- );
557
- }
558
- }
559
-
560
- #[cfg(unix)]
561
- #[test]
562
- fn grok_nonzero_native_command_is_not_a_successful_empty_catalog() {
563
- let grok = CliFixture::new(fixture_program(
564
- "grok",
565
- "printf 'private diagnostic' >&2\nexit 7",
566
- ));
567
- let output = run_public_models_cli(
568
- &grok.program,
569
- None,
570
- &["models", "--provider", "grok", "--json"],
571
- );
572
- let text = public_cli_text(&output);
573
- let calls =
574
- std::fs::read_to_string(grok.program.with_extension("count")).unwrap_or_default();
575
- drop(grok);
576
- assert!(!output.status.success(), "{text}");
577
- assert_eq!(calls, "1:models\n");
578
- assert!(!text.contains("private diagnostic"));
579
- let value: Value = serde_json::from_str(text.trim()).unwrap();
580
- assert_eq!(value["ok"], false);
581
- assert_eq!(value["models"], json!([]));
582
- assert!(
583
- value["error"]
584
- .as_str()
585
- .unwrap()
586
- .to_ascii_lowercase()
587
- .contains("grok"),
588
- "{text}"
589
- );
590
- }
591
-
592
242
  #[cfg(unix)]
593
243
  #[test]
594
244
  fn grok_failure_help_and_unsupported_action_are_publicly_diagnostic() {
@@ -600,7 +250,11 @@ esac"#));
600
250
  );
601
251
  let text = public_cli_text(&output);
602
252
  let value: Value = serde_json::from_str(text.trim()).unwrap();
253
+ // `grok` reads the Grok Build leaf catalog; a missing PATH `grok` fails
254
+ // closed there with no legacy catalog fallback.
603
255
  assert_eq!(value["ok"], false);
256
+ assert_eq!(value["provider"], "grok_build", "{text}");
257
+ assert_eq!(value["models"], json!([]), "{text}");
604
258
  assert!(
605
259
  value["error"]
606
260
  .as_str()
@@ -609,7 +263,6 @@ esac"#));
609
263
  .contains("grok"),
610
264
  "{text}"
611
265
  );
612
- assert!(value["action"].as_str().unwrap().contains("grok"), "{text}");
613
266
  assert!(crate::cli::emit::default_help().contains("grok"));
614
267
  assert!(crate::cli::spec::command_spec("models")
615
268
  .unwrap()
@@ -635,11 +288,6 @@ esac"#));
635
288
  );
636
289
  }
637
290
 
638
- #[cfg(unix)]
639
- fn fixture(body: &str) -> std::path::PathBuf {
640
- fixture_program("pi", body)
641
- }
642
-
643
291
  #[cfg(unix)]
644
292
  fn fixture_program(program: &str, body: &str) -> std::path::PathBuf {
645
293
  let sequence = FIXTURE_SEQUENCE.fetch_add(1, Ordering::Relaxed);
@@ -709,16 +357,6 @@ esac"#));
709
357
  }
710
358
  }
711
359
 
712
- #[cfg(unix)]
713
- fn native_cli_fixture(program: &str, bytes: &[u8]) -> CliFixture {
714
- let program = fixture_program(program, "exec /bin/cat \"$TEAM_AGENT_MODELS_FIXTURE\"");
715
- let mut fixture = CliFixture::new(program);
716
- let response = fixture.program.with_extension("stdout");
717
- std::fs::write(&response, bytes).unwrap();
718
- fixture.response = Some(response);
719
- fixture
720
- }
721
-
722
360
  #[cfg(unix)]
723
361
  fn run_public_models_cli(
724
362
  path: &Path,
@@ -757,568 +395,19 @@ esac"#));
757
395
  .to_string()
758
396
  }
759
397
 
760
- #[cfg(unix)]
761
- fn fixture_with_sidecars(body: &str) -> std::path::PathBuf {
762
- let path = fixture(body);
763
- let script = std::fs::read_to_string(&path).unwrap();
764
- let script = script.strip_prefix("#!/bin/sh\n").unwrap();
765
- let script = format!(
766
- "#!/bin/sh\nprintf '1\\n' > \"$0.entered\" || :\n{script}body_status=$?\nprintf '1\\n' > \"$0.completed\" || :\nexit \"$body_status\"\n"
767
- );
768
- install_executable(&path, &script);
769
- path
770
- }
771
-
772
398
  #[cfg(unix)]
773
399
  fn cleanup_fixture(path: &Path) {
774
400
  let _ = std::fs::remove_dir_all(path.parent().unwrap());
775
401
  }
776
402
 
777
- #[cfg(unix)]
778
- fn native_timeout_fixture() -> std::path::PathBuf {
779
- let path = std::path::PathBuf::from(env!("TEAM_AGENT_MODELS_TIMEOUT_FIXTURE"));
780
- assert!(path.is_file(), "prebuilt models timeout fixture is missing");
781
- path
782
- }
783
-
784
- #[cfg(unix)]
785
- fn native_timeout_receipt() -> std::path::PathBuf {
786
- let stamp = std::time::SystemTime::now()
787
- .duration_since(std::time::UNIX_EPOCH)
788
- .unwrap()
789
- .as_nanos();
790
- std::path::PathBuf::from("/tmp").join(format!(
791
- "team-agent-models-timeout-{}-{stamp}.receipt",
792
- std::process::id()
793
- ))
794
- }
795
-
796
- #[cfg(unix)]
797
- fn native_timeout_stage_receipt(receipt: &Path) -> std::path::PathBuf {
798
- receipt.with_extension("stage")
799
- }
800
-
801
- #[cfg(unix)]
802
- fn parse_native_timeout_receipt(path: &Path) -> Option<BTreeMap<String, String>> {
803
- let mut fields = BTreeMap::new();
804
- for line in std::fs::read_to_string(path).ok()?.lines() {
805
- let (key, value) = line.split_once('=')?;
806
- if fields.insert(key.to_string(), value.to_string()).is_some() {
807
- return None;
808
- }
809
- }
810
- let keys = fields.keys().map(String::as_str).collect::<Vec<_>>();
811
- (keys
812
- == vec![
813
- "child_argv_exact",
814
- "child_pid",
815
- "child_spawn_attempts",
816
- "descendant_pid",
817
- "descendant_started",
818
- "descendant_stdout_inherited",
819
- "parent_argv_exact",
820
- "parent_pid",
821
- "parent_started_once",
822
- ])
823
- .then_some(fields)
824
- }
825
-
826
- #[cfg(unix)]
827
- fn wait_native_timeout_receipt(path: &Path) -> BTreeMap<String, String> {
828
- let deadline = Instant::now() + Duration::from_millis(500);
829
- loop {
830
- if let Some(fields) = parse_native_timeout_receipt(path) {
831
- return fields;
832
- }
833
- if Instant::now() >= deadline {
834
- panic!("native timeout receipt did not become complete after runner return");
835
- }
836
- std::thread::sleep(Duration::from_millis(1));
837
- }
838
- }
839
-
840
- #[cfg(unix)]
841
- fn with_native_mode<T>(
842
- mode: &str,
843
- action: impl FnOnce() -> T,
844
- ) -> (
845
- T,
846
- crate::lifecycle::launch::pi_mcp::PiCatalogTestObservation,
847
- ) {
848
- let receipt = native_timeout_receipt();
849
- assert!(!receipt.exists());
850
- let result = crate::lifecycle::launch::pi_mcp::with_pi_catalog_test_observation(
851
- &receipt,
852
- Some(mode),
853
- action,
854
- );
855
- assert!(!receipt.exists());
856
- let _ = std::fs::remove_file(format!("{}.sock", receipt.display()));
857
- result
858
- }
859
-
860
- #[cfg(unix)]
861
- fn safe_fixture_sidecar(path: &Path, expected: &str) -> &'static str {
862
- match std::fs::read_to_string(path) {
863
- Ok(text) if text == expected => "present_expected",
864
- Ok(_) => "present_unexpected",
865
- Err(error) if error.kind() == std::io::ErrorKind::NotFound => "missing",
866
- Err(_) => "unavailable",
867
- }
868
- }
869
-
870
- #[cfg(unix)]
871
- fn safe_runner_fixture_observation(path: &Path) -> String {
872
- format!(
873
- "fixture_entered={} fixture_completed={} fixture_count={}",
874
- safe_fixture_sidecar(&path.with_extension("entered"), "1\n"),
875
- safe_fixture_sidecar(&path.with_extension("completed"), "1\n"),
876
- safe_fixture_sidecar(&path.with_extension("count"), "1:--list-models\n"),
877
- )
878
- }
879
-
880
- #[cfg(unix)]
881
- fn safe_runner_observation(
882
- elapsed: Duration,
883
- observation: &crate::lifecycle::launch::pi_mcp::PiCatalogTestObservation,
884
- ) -> String {
885
- format!(
886
- "elapsed_ms={} spawn_count={} argv={:?} parent_pid={:?} parent_exit_success={:?} parent_exit_code={:?} reader_timeout={}",
887
- elapsed.as_millis(),
888
- observation.spawn_count,
889
- observation.argv,
890
- observation.parent_pid,
891
- observation.parent_exit_success,
892
- observation.parent_exit_code,
893
- observation.reader_timeout,
894
- )
895
- }
896
-
897
- #[cfg(unix)]
898
- fn safe_models_result_class(result: &CmdResult) -> &'static str {
899
- let CmdOutput::Human(text) = &result.output else {
900
- return "non_human_output";
901
- };
902
- let Ok(value) = serde_json::from_str::<Value>(text) else {
903
- return "non_json_output";
904
- };
905
- match value.get("ok").and_then(Value::as_bool) {
906
- Some(true) => "success_json",
907
- Some(false) => match value.get("error").and_then(Value::as_str) {
908
- Some(error) if error.contains("unavailable") => "runner_unavailable",
909
- Some(error) if error.contains("timed out") => "runner_timeout",
910
- Some(error) if error.contains("command failed") => "runner_exit",
911
- Some(error) if error.contains("could not be read") => "reader_error",
912
- Some(error) if error.contains("exceeds") => "reader_oversize",
913
- Some(error) if error.contains("catalog") => "parser_catalog_error",
914
- Some(_) => "failure_json",
915
- None => "failure_json_missing_error",
916
- },
917
- None => "json_missing_ok",
918
- }
919
- }
920
-
921
- #[cfg(unix)]
922
- fn safe_models_observation(
923
- elapsed: Duration,
924
- result: &CmdResult,
925
- observation: &crate::lifecycle::launch::pi_mcp::PiCatalogTestObservation,
926
- ) -> String {
927
- format!(
928
- "class={} elapsed_ms={} parent_pid={:?} parent_exit_success={:?} parent_exit_code={:?} reader_timeout={}",
929
- safe_models_result_class(result),
930
- elapsed.as_millis(),
931
- observation.parent_pid,
932
- observation.parent_exit_success,
933
- observation.parent_exit_code,
934
- observation.reader_timeout,
935
- )
936
- }
937
-
938
- #[cfg(unix)]
939
- #[test]
940
- fn runner_invokes_exact_argv_once_and_drains() {
941
- let path = fixture_with_sidecars(
942
- "test \"$1\" = --list-models && echo provider model && echo openai-codex gpt-5.6-sol",
943
- );
944
- let receipt = native_timeout_receipt();
945
- assert!(!receipt.exists());
946
- let started = Instant::now();
947
- let (result, observation) =
948
- crate::lifecycle::launch::pi_mcp::with_pi_catalog_test_observation(
949
- &receipt,
950
- None,
951
- || run_catalog(&path, Duration::from_secs(1), 1024),
952
- );
953
- let elapsed = started.elapsed();
954
- let fixture_observation = safe_runner_fixture_observation(&path);
955
- assert!(
956
- result
957
- .as_ref()
958
- .is_ok_and(|bytes| bytes.starts_with(b"provider model")),
959
- "runner observation: {}; {}",
960
- safe_runner_observation(elapsed, &observation),
961
- fixture_observation
962
- );
963
- let _ = result.unwrap();
964
- let _ = std::fs::remove_file(&receipt);
965
- let _ = std::fs::remove_file(format!("{}.sock", receipt.display()));
966
- assert_eq!(
967
- std::fs::read_to_string(path.with_extension("count")).unwrap(),
968
- "1:--list-models\n"
969
- );
970
- cleanup_fixture(&path);
971
- }
972
-
973
- #[cfg(unix)]
974
- const NATIVE_STAGE_KEYS: [&str; 5] = [
975
- "parent_entry_ms",
976
- "parent_before_child_spawn_ms",
977
- "parent_after_child_spawn_ms",
978
- "parent_before_exit_ms",
979
- "test_spawn_return_ms",
980
- ];
981
-
982
- #[cfg(unix)]
983
- // Match the native helper's UNIX epoch millisecond clock exactly.
984
- fn append_native_stage(path: &Path, key: &str) {
985
- if !NATIVE_STAGE_KEYS.contains(&key) {
986
- return;
987
- }
988
- let Some(milliseconds) = std::time::SystemTime::now()
989
- .duration_since(std::time::UNIX_EPOCH)
990
- .ok()
991
- .map(|duration| duration.as_millis())
992
- else {
993
- return;
994
- };
995
- let Ok(mut file) = std::fs::OpenOptions::new()
996
- .create(true)
997
- .append(true)
998
- .open(path)
999
- else {
1000
- return;
1001
- };
1002
- let _ = writeln!(file, "{key}={milliseconds}");
1003
- }
1004
-
1005
- #[cfg(unix)]
1006
- fn safe_native_stage(path: &Path) -> String {
1007
- let (read_state, text) = match std::fs::read_to_string(path) {
1008
- Ok(text) => ("ok", Some(text)),
1009
- Err(error) if error.kind() == std::io::ErrorKind::NotFound => ("missing", None),
1010
- Err(_) => ("unavailable", None),
1011
- };
1012
- let mut fields = BTreeMap::new();
1013
- if let Some(ref text) = text {
1014
- for line in text.lines() {
1015
- let Some((key, value)) = line.split_once('=') else {
1016
- continue;
1017
- };
1018
- if NATIVE_STAGE_KEYS.contains(&key)
1019
- && value.len() <= 20
1020
- && value.bytes().all(|byte| byte.is_ascii_digit())
1021
- {
1022
- fields.entry(key).or_insert(value);
1023
- }
1024
- }
1025
- }
1026
- let field = |key: &str| fields.get(key).copied().unwrap_or("unknown");
1027
- format!(
1028
- "stage_read={read_state} parent_entry_ms={} parent_before_child_spawn_ms={} parent_after_child_spawn_ms={} parent_before_exit_ms={} test_spawn_return_ms={}",
1029
- field("parent_entry_ms"),
1030
- field("parent_before_child_spawn_ms"),
1031
- field("parent_after_child_spawn_ms"),
1032
- field("parent_before_exit_ms"),
1033
- field("test_spawn_return_ms"),
1034
- )
1035
- }
1036
-
1037
- #[cfg(unix)]
1038
- fn wait_for_native_parent_exit(
1039
- child: &mut std::process::Child,
1040
- stage: &Path,
1041
- ) -> std::process::ExitStatus {
1042
- let deadline = Instant::now() + Duration::from_millis(500);
1043
- loop {
1044
- match child.try_wait() {
1045
- Ok(Some(status)) => return status,
1046
- Ok(None) if Instant::now() < deadline => {
1047
- std::thread::sleep(Duration::from_millis(1));
1048
- }
1049
- Ok(None) => {
1050
- let before_kill = safe_native_stage(stage);
1051
- let _ = child.kill();
1052
- let _ = child.wait();
1053
- let after_wait = safe_native_stage(stage);
1054
- panic!(
1055
- "native parent did not exit before test setup deadline; stage_before_kill={before_kill}; stage_after_wait={after_wait}"
1056
- );
1057
- }
1058
- Err(_) => {
1059
- let before_kill = safe_native_stage(stage);
1060
- let _ = child.kill();
1061
- let _ = child.wait();
1062
- let after_wait = safe_native_stage(stage);
1063
- panic!(
1064
- "native parent status could not be observed; stage_before_kill={before_kill}; stage_after_wait={after_wait}"
1065
- );
1066
- }
1067
- }
1068
- }
1069
- }
1070
-
1071
- /// Read/drain seam only: public `run_catalog` spawn coverage remains in the
1072
- /// normal success and fail-closed tests.
1073
- #[cfg(unix)]
1074
- #[test]
1075
- fn reader_deadline_is_bounded_after_parent_exit_with_descendant_pipe() {
1076
- let path = native_timeout_fixture();
1077
- let receipt = native_timeout_receipt();
1078
- let stage = native_timeout_stage_receipt(&receipt);
1079
- assert!(!receipt.exists());
1080
- assert!(!stage.exists());
1081
- let mut parent = std::process::Command::new(&path)
1082
- .arg("--list-models")
1083
- .env("TEAM_AGENT_MODELS_TIMEOUT_RECEIPT", &receipt)
1084
- .env("TEAM_AGENT_MODELS_TIMEOUT_STAGE_RECEIPT", &stage)
1085
- .env("TEAM_AGENT_MODELS_TIMEOUT_MODE", "descendant")
1086
- .stdin(std::process::Stdio::null())
1087
- .stdout(std::process::Stdio::piped())
1088
- .stderr(std::process::Stdio::null())
1089
- .spawn()
1090
- .unwrap();
1091
- append_native_stage(&stage, "test_spawn_return_ms");
1092
- let parent_pid = parent.id();
1093
- let parent_status = wait_for_native_parent_exit(&mut parent, &stage);
1094
- let stdout = parent.stdout.take().expect("native parent stdout pipe");
1095
- let started = Instant::now();
1096
- let (result, observation) =
1097
- crate::lifecycle::launch::pi_mcp::with_pi_catalog_test_observation(
1098
- &receipt,
1099
- Some("descendant"),
1100
- || {
1101
- crate::lifecycle::launch::pi_mcp::run_pi_catalog_after_parent_exit_for_test(
1102
- stdout,
1103
- parent_pid,
1104
- parent_status,
1105
- Duration::from_millis(40),
1106
- 1024,
1107
- )
1108
- },
1109
- );
1110
- let elapsed = started.elapsed();
1111
- assert!(
1112
- elapsed < Duration::from_millis(500),
1113
- "runner observation: {}",
1114
- safe_runner_observation(elapsed, &observation)
1115
- );
1116
- assert!(result.unwrap_err().contains("timed out"));
1117
- assert_eq!(
1118
- observation.parent_exit_success,
1119
- Some(true),
1120
- "runner observation: {}",
1121
- safe_runner_observation(elapsed, &observation)
1122
- );
1123
- assert_eq!(observation.parent_exit_code, Some(0));
1124
- assert!(observation.reader_timeout);
1125
-
1126
- let fields = wait_native_timeout_receipt(&receipt);
1127
- assert_eq!(fields["parent_started_once"], "1");
1128
- assert_eq!(fields["parent_argv_exact"], "1");
1129
- assert_eq!(fields["child_spawn_attempts"], "1");
1130
- assert_eq!(fields["child_argv_exact"], "1");
1131
- assert_eq!(fields["descendant_started"], "1");
1132
- assert_eq!(fields["descendant_stdout_inherited"], "1");
1133
- assert_eq!(
1134
- fields["parent_pid"],
1135
- observation.parent_pid.unwrap().to_string()
1136
- );
1137
- assert_eq!(fields["child_pid"], fields["descendant_pid"]);
1138
- let _ = std::fs::remove_file(&receipt);
1139
- let _ = std::fs::remove_file(&stage);
1140
- let _ = std::fs::remove_file(format!("{}.sock", receipt.display()));
1141
- }
1142
-
1143
- #[cfg(unix)]
1144
- #[test]
1145
- #[serial_test::serial(env)]
1146
- fn command_boundary_connects_runner_parser_search_and_contract() {
1147
- let path = fixture(
1148
- "printf 'provider model\\nopenai-codex gpt-5.6-sol\\nopenai-codex gpt-5.6-luna\\n'",
1149
- );
1150
- let args = ModelsArgs {
1151
- provider: "pi".into(),
1152
- search: Some("sol".into()),
1153
- json: true,
1154
- };
1155
- let receipt = native_timeout_receipt();
1156
- assert!(!receipt.exists());
1157
- let started = Instant::now();
1158
- let (result, observation) =
1159
- crate::lifecycle::launch::pi_mcp::with_pi_catalog_test_observation(
1160
- &receipt,
1161
- None,
1162
- || cmd_models_with(&args, &path, Duration::from_secs(1), 1024),
1163
- );
1164
- let elapsed = started.elapsed();
1165
- let result = match result {
1166
- Ok(result) => result,
1167
- Err(_) => panic!(
1168
- "command boundary returned a CLI error; class=cli_error elapsed_ms={} parent_pid={:?} parent_exit_success={:?} parent_exit_code={:?} reader_timeout={}",
1169
- elapsed.as_millis(),
1170
- observation.parent_pid,
1171
- observation.parent_exit_success,
1172
- observation.parent_exit_code,
1173
- observation.reader_timeout,
1174
- ),
1175
- };
1176
- let CmdOutput::Human(text) = &result.output else {
1177
- panic!(
1178
- "expected JSON projection; {}",
1179
- safe_models_observation(elapsed, &result, &observation)
1180
- )
1181
- };
1182
- let value: Value = serde_json::from_str(text).unwrap_or_else(|_| {
1183
- panic!(
1184
- "expected valid JSON projection; {}",
1185
- safe_models_observation(elapsed, &result, &observation)
1186
- )
1187
- });
1188
- assert_eq!(
1189
- value["schema_version"],
1190
- "models.v1",
1191
- "{}",
1192
- safe_models_observation(elapsed, &result, &observation)
1193
- );
1194
- assert_eq!(
1195
- value["models"][0]["role_model"],
1196
- "openai-codex/gpt-5.6-sol",
1197
- "{}",
1198
- safe_models_observation(elapsed, &result, &observation)
1199
- );
1200
- assert_eq!(
1201
- value["models"][0]["current"],
1202
- false,
1203
- "{}",
1204
- safe_models_observation(elapsed, &result, &observation)
1205
- );
1206
- assert_eq!(
1207
- value["auth"],
1208
- "ok",
1209
- "{}",
1210
- safe_models_observation(elapsed, &result, &observation)
1211
- );
1212
- let model_count = value["models"].as_array().map(|models| models.len());
1213
- assert_eq!(
1214
- model_count,
1215
- Some(1),
1216
- "{}",
1217
- safe_models_observation(elapsed, &result, &observation)
1218
- );
1219
- let _ = std::fs::remove_file(&receipt);
1220
- let _ = std::fs::remove_file(format!("{}.sock", receipt.display()));
1221
- let human = cmd_models_with(
1222
- &ModelsArgs {
1223
- provider: "pi".into(),
1224
- search: Some("absent".into()),
1225
- json: false,
1226
- },
1227
- &path,
1228
- Duration::from_secs(1),
1229
- 1024,
1230
- )
1231
- .unwrap();
1232
- let CmdOutput::Human(text) = human.output else {
1233
- panic!("expected human projection")
1234
- };
1235
- assert!(text.contains("No models matched --search") && text.contains("auth: ok"));
1236
- let refusal = crate::cli::emit::__test_dispatch(
1237
- "models",
1238
- &["--provider".into(), "cloud".into()],
1239
- Path::new("/tmp"),
1240
- );
1241
- assert!(matches!(refusal, Ok(ExitCode::Error)));
1242
- cleanup_fixture(&path);
1243
- }
1244
-
1245
- #[cfg(unix)]
1246
- #[test]
1247
- fn runner_fails_closed_for_nonzero_oversize_timeout_and_unavailable() {
1248
- let fail = native_timeout_fixture();
1249
- let started = Instant::now();
1250
- let (failed_result, fail_observation) =
1251
- with_native_mode("exit7", || run_catalog(&fail, Duration::from_secs(1), 1024));
1252
- let elapsed = started.elapsed();
1253
- assert_eq!(
1254
- failed_result.unwrap_err(),
1255
- "Pi model catalog command failed",
1256
- "runner observation: {}",
1257
- safe_runner_observation(elapsed, &fail_observation)
1258
- );
1259
- assert_eq!(fail_observation.spawn_count, 1);
1260
- assert_eq!(fail_observation.argv, vec!["--list-models"]);
1261
- assert_eq!(fail_observation.parent_exit_success, Some(false));
1262
- assert_eq!(fail_observation.parent_exit_code, Some(7));
1263
- assert!(!fail_observation.reader_timeout);
1264
- let (failed, failed_observation) = with_native_mode("exit7", || {
1265
- cmd_models_with(
1266
- &ModelsArgs {
1267
- provider: "pi".into(),
1268
- search: None,
1269
- json: false,
1270
- },
1271
- &fail,
1272
- Duration::from_secs(1),
1273
- 1024,
1274
- )
1275
- });
1276
- let failed = failed.unwrap();
1277
- assert_eq!(failed_observation.spawn_count, 1);
1278
- assert_eq!(failed_observation.argv, vec!["--list-models"]);
1279
- assert_eq!(failed_observation.parent_exit_success, Some(false));
1280
- assert_eq!(failed_observation.parent_exit_code, Some(7));
1281
- assert!(!failed_observation.reader_timeout);
1282
- let CmdOutput::Human(text) = failed.output else {
1283
- panic!("expected failure projection")
1284
- };
1285
- assert_eq!(failed.exit, ExitCode::Error);
1286
- assert!(!text.contains("sensitive-token"));
1287
- let big = native_timeout_fixture();
1288
- let (big_result, big_observation) =
1289
- with_native_mode("oversize", || run_catalog(&big, Duration::from_secs(1), 8));
1290
- assert!(big_result.unwrap_err().contains("bounded output"));
1291
- assert_eq!(big_observation.spawn_count, 1);
1292
- assert_eq!(big_observation.argv, vec!["--list-models"]);
1293
- assert_eq!(big_observation.parent_exit_success, Some(true));
1294
- assert_eq!(big_observation.parent_exit_code, Some(0));
1295
- assert!(!big_observation.reader_timeout);
1296
- let slow = native_timeout_fixture();
1297
- let (slow_result, slow_observation) = with_native_mode("sleep", || {
1298
- run_catalog(&slow, Duration::from_millis(20), 1024)
1299
- });
1300
- assert!(slow_result.unwrap_err().contains("timed out"));
1301
- assert_eq!(slow_observation.spawn_count, 1);
1302
- assert_eq!(slow_observation.argv, vec!["--list-models"]);
1303
- assert_eq!(slow_observation.parent_exit_success, None);
1304
- assert!(!slow_observation.reader_timeout);
1305
- assert!(run_catalog(
1306
- std::path::Path::new("/does/not/exist"),
1307
- Duration::from_secs(1),
1308
- 1024
1309
- )
1310
- .unwrap_err()
1311
- .contains("unavailable"));
1312
- }
1313
-
1314
403
  #[test]
1315
404
  fn public_failure_and_help_contracts_are_versioned() {
1316
405
  let args = ModelsArgs {
1317
- provider: "pi".into(),
406
+ provider: "codex".into(),
1318
407
  search: None,
1319
408
  json: true,
1320
409
  };
1321
- let result = failure(&args, "safe failure");
410
+ let result = failure_with_action(&args, "safe failure", "safe action");
1322
411
  let CmdOutput::Human(text) = result.output else {
1323
412
  panic!("json contract must render")
1324
413
  };