@team-agent/installer 0.5.126 → 0.5.128
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 +1 -1
- package/Cargo.toml +1 -1
- package/README.md +11 -0
- package/crates/team-agent/src/cli/adapters.rs +3 -13
- package/crates/team-agent/src/cli/arguments.rs +4 -0
- package/crates/team-agent/src/cli/diagnose.rs +68 -91
- package/crates/team-agent/src/cli/emit.rs +61 -28
- package/crates/team-agent/src/cli/grok_slot.rs +88 -3
- package/crates/team-agent/src/cli/intent/runtime.rs +38 -9
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +147 -11
- package/crates/team-agent/src/cli/intent/tests.rs +10 -12
- package/crates/team-agent/src/cli/intent.rs +1 -1
- package/crates/team-agent/src/cli/mod.rs +38 -9
- package/crates/team-agent/src/cli/models.rs +789 -186
- package/crates/team-agent/src/cli/schedule.rs +175 -0
- package/crates/team-agent/src/cli/send/persist.rs +0 -36
- package/crates/team-agent/src/cli/send/presentation.rs +1 -1
- package/crates/team-agent/src/cli/send.rs +108 -110
- package/crates/team-agent/src/cli/spec.rs +6 -0
- package/crates/team-agent/src/cli/status_port/brief.rs +5 -67
- package/crates/team-agent/src/cli/tests/leader_watch.rs +12 -62
- package/crates/team-agent/src/cli/tests/mod.rs +3 -3
- package/crates/team-agent/src/cli/tests/named_address.rs +11 -10
- package/crates/team-agent/src/cli/tests/run_delegation.rs +12 -9
- package/crates/team-agent/src/cli/tests/status_send.rs +70 -273
- package/crates/team-agent/src/compiler/tests.rs +39 -27
- package/crates/team-agent/src/compiler.rs +206 -6
- package/crates/team-agent/src/contract_runtime/backend.rs +181 -11
- package/crates/team-agent/src/contract_runtime/commands.rs +338 -7
- package/crates/team-agent/src/contract_runtime/config.rs +30 -19
- package/crates/team-agent/src/contract_runtime/config_tests.rs +24 -4
- package/crates/team-agent/src/contract_runtime/discovery.rs +12 -1
- package/crates/team-agent/src/contract_runtime/fork.rs +3 -10
- package/crates/team-agent/src/contract_runtime/framework.rs +28 -14
- package/crates/team-agent/src/contract_runtime/mcp.rs +19 -24
- package/crates/team-agent/src/contract_runtime/prompt.rs +2 -2
- package/crates/team-agent/src/contract_runtime/registry.rs +93 -130
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +45 -5
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +8 -29
- package/crates/team-agent/src/coordinator/tests/energy.rs +4 -4
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +44 -2
- package/crates/team-agent/src/coordinator/tests/main_preserved.rs +2 -2
- package/crates/team-agent/src/coordinator/tests/spine.rs +1 -1
- package/crates/team-agent/src/coordinator/tests/takeover.rs +3 -3
- package/crates/team-agent/src/coordinator/tick.rs +1 -89
- package/crates/team-agent/src/db/message_store.rs +7 -65
- package/crates/team-agent/src/direct_delivery.rs +368 -0
- package/crates/team-agent/src/inbox_store.rs +169 -0
- package/crates/team-agent/src/leader/registry.rs +5 -0
- package/crates/team-agent/src/leader/start.rs +2 -1
- package/crates/team-agent/src/leader/tests/lease_api.rs +2 -2
- package/crates/team-agent/src/leader/tests/prompt_contract.rs +1 -0
- package/crates/team-agent/src/lib.rs +2 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +33 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +206 -1
- package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +28 -2
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +36 -179
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +87 -6
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +13 -488
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +351 -81
- package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +3 -4
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +26 -2
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +41 -31
- package/crates/team-agent/src/lifecycle/launch.rs +27 -12
- package/crates/team-agent/src/lifecycle/profile_launch.rs +318 -64
- package/crates/team-agent/src/lifecycle/restart/agent.rs +1 -0
- package/crates/team-agent/src/lifecycle/restart/avatar.rs +1798 -0
- package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +163 -0
- package/crates/team-agent/src/lifecycle/restart/common.rs +298 -133
- package/crates/team-agent/src/lifecycle/restart/remove.rs +129 -0
- package/crates/team-agent/src/lifecycle/restart/selection.rs +5 -5
- package/crates/team-agent/src/lifecycle/restart.rs +4 -0
- package/crates/team-agent/src/lifecycle/role_config.rs +79 -27
- package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +8 -12
- package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +37 -240
- package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +325 -0
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +320 -8
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +329 -70
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +378 -4
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +25 -39
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +7 -11
- package/crates/team-agent/src/lifecycle/tests/core.rs +39 -36
- package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +22 -8
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +2 -1
- package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +15 -133
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +60 -20
- package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +30 -67
- package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +3 -31
- package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +194 -169
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +164 -282
- package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +15 -78
- package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +7 -7
- package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +6 -6
- package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +75 -69
- package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +2 -10
- package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +18 -6
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +70 -52
- package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +210 -0
- package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +157 -4
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +526 -10
- package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +1419 -0
- package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +68 -1
- package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +34 -12
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +94 -2
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +14 -15
- package/crates/team-agent/src/lifecycle/tests/restart.rs +12 -153
- package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +27 -5
- package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +59 -10
- package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +47 -6
- package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +3 -1374
- package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +27 -10
- package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +7 -7
- package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +67 -313
- package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +254 -2
- package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +4 -4
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +74 -19
- package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +38 -39
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +51 -88
- package/crates/team-agent/src/lifecycle/tests.rs +3 -4
- package/crates/team-agent/src/lifecycle/types.rs +18 -5
- package/crates/team-agent/src/lifecycle/worker_command_context.rs +43 -50
- package/crates/team-agent/src/mcp_server/readiness.rs +130 -149
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +86 -109
- package/crates/team-agent/src/mcp_server/tests/scoped.rs +21 -31
- package/crates/team-agent/src/mcp_server/tests/send.rs +72 -107
- package/crates/team-agent/src/mcp_server/tests/tools.rs +10 -12
- package/crates/team-agent/src/mcp_server/tools.rs +70 -196
- package/crates/team-agent/src/messaging/delivery.rs +143 -253
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +5 -5
- package/crates/team-agent/src/messaging/helpers.rs +1 -19
- package/crates/team-agent/src/messaging/mod.rs +1 -0
- package/crates/team-agent/src/messaging/reminders.rs +316 -0
- package/crates/team-agent/src/messaging/scheduler.rs +7 -1
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +255 -150
- package/crates/team-agent/src/messaging/tests/main_preserved.rs +2 -2
- package/crates/team-agent/src/messaging/tests/runtime.rs +9 -115
- package/crates/team-agent/src/messaging/tests/spine.rs +44 -24
- package/crates/team-agent/src/messaging/tests/wave2.rs +13 -20
- package/crates/team-agent/src/messaging/types.rs +1 -0
- package/crates/team-agent/src/provider/adapter.rs +208 -254
- package/crates/team-agent/src/provider/adapters/claude.rs +78 -0
- package/crates/team-agent/src/provider/adapters/claude_fork.rs +131 -0
- package/crates/team-agent/src/provider/adapters/mod.rs +7 -7
- package/crates/team-agent/src/provider/adapters/pi.rs +106 -0
- package/crates/team-agent/src/provider/classify.rs +1 -66
- package/crates/team-agent/src/provider/model_catalog.rs +201 -13
- package/crates/team-agent/src/provider/session/capture.rs +111 -111
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +123 -0
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +10 -18
- package/crates/team-agent/src/provider/session/context_fork.rs +87 -74
- package/crates/team-agent/src/provider/session/mod.rs +2 -3
- package/crates/team-agent/src/provider/session_scan/claude.rs +523 -0
- package/crates/team-agent/src/provider/session_scan/common.rs +47 -47
- package/crates/team-agent/src/provider/session_scan/pi.rs +34 -1
- package/crates/team-agent/src/provider/session_scan.rs +13 -13
- package/crates/team-agent/src/provider/tests/adapter.rs +127 -121
- package/crates/team-agent/src/provider/tests/classify.rs +0 -53
- package/crates/team-agent/src/provider/tests/command_helpers.rs +11 -19
- package/crates/team-agent/src/provider/tests/idle.rs +13 -19
- package/crates/team-agent/src/provider/types.rs +0 -4
- package/crates/team-agent/src/provider/wire.rs +34 -20
- package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +1 -1
- package/crates/team-agent/src/state/persist.rs +6 -6
- package/crates/team-agent/src/state/projection.rs +1 -1
- package/crates/team-agent/src/state/repository/tests.rs +2 -2
- package/crates/team-agent/src/test_support/models_timeout_fixture.rs +144 -0
- package/crates/team-agent/src/tmux_backend/tests.rs +0 -151
- package/crates/team-agent/src/tmux_backend.rs +9 -43
- package/package.json +4 -4
- package/skills/team-agent/SKILL.md +7 -8
- package/skills/team-agent/command-coverage.json +15 -1
- package/skills/team-agent/docs/reference/team-agent-operator.md +5 -3
- package/skills/team-agent/references/team-agent-operator.md +5 -3
- package/crates/team-agent/src/lifecycle/launch/grok_per_seat.rs +0 -260
- package/crates/team-agent/src/lifecycle/tests/codex_weak_window_attribution_red.rs +0 -683
- package/crates/team-agent/src/lifecycle/tests/grok_effort_argv_red.rs +0 -247
- package/crates/team-agent/src/lifecycle/tests/grok_mcp_overlay_red.rs +0 -507
- package/crates/team-agent/src/lifecycle/tests/grok_restart_resume_red.rs +0 -300
- package/crates/team-agent/src/provider/adapters/codex.rs +0 -101
- package/crates/team-agent/src/provider/adapters/grok.rs +0 -67
- package/crates/team-agent/src/provider/session/context_fork/codex.rs +0 -514
- package/crates/team-agent/src/provider/session_scan/codex.rs +0 -326
- package/crates/team-agent/src/provider/session_scan/grok.rs +0 -288
|
@@ -2,14 +2,23 @@
|
|
|
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)]
|
|
5
7
|
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;
|
|
6
15
|
type ModelRecord = crate::provider::model_catalog::ModelRecord;
|
|
7
16
|
|
|
8
17
|
pub fn cmd_models(args: &ModelsArgs) -> Result<CmdResult, CliError> {
|
|
9
18
|
#[cfg(unix)]
|
|
10
|
-
if let Some(descriptor) = crate::contract_runtime::registry::declared(&args.provider
|
|
19
|
+
if let Some(descriptor) = crate::contract_runtime::registry::declared(&args.provider) {
|
|
11
20
|
// A role's provider names its catalog: `agent` or `cursor-agent` is the
|
|
12
|
-
// Cursor leaf; `
|
|
21
|
+
// Cursor leaf; `codex` and `grok` are the Codex and Grok Build leaves.
|
|
13
22
|
let args = ModelsArgs { provider: descriptor.identity.id.into(), ..args.clone() };
|
|
14
23
|
return crate::contract_runtime::discovery::models(&args);
|
|
15
24
|
}
|
|
@@ -34,9 +43,14 @@ fn render_catalog(args: &ModelsArgs, all: Vec<ModelRecord>) -> Result<CmdResult,
|
|
|
34
43
|
.collect()
|
|
35
44
|
},
|
|
36
45
|
);
|
|
46
|
+
let current = if args.provider == "pi" {
|
|
47
|
+
current_role_model(&all.iter().map(|model| model.id.clone()).collect::<Vec<_>>())
|
|
48
|
+
} else {
|
|
49
|
+
None
|
|
50
|
+
};
|
|
37
51
|
let entries: Vec<Value> = visible.iter().map(|model| json!({
|
|
38
52
|
"role_model": model.id,
|
|
39
|
-
"current": Value::Null,
|
|
53
|
+
"current": if args.provider == "pi" { json!(current.as_deref() == Some(model.id.as_str())) } else { Value::Null },
|
|
40
54
|
"provider": model.provider,
|
|
41
55
|
"vendor": model.vendor,
|
|
42
56
|
"model_id": model.id,
|
|
@@ -47,7 +61,7 @@ fn render_catalog(args: &ModelsArgs, all: Vec<ModelRecord>) -> Result<CmdResult,
|
|
|
47
61
|
let provider = args.provider.as_str();
|
|
48
62
|
let value = json!({
|
|
49
63
|
"schema_version": "models.v1", "ok": true, "provider": provider, "models": entries,
|
|
50
|
-
"auth": "ok", "auth_basis": "catalog_visibility", "current_role_model":
|
|
64
|
+
"auth": "ok", "auth_basis": "catalog_visibility", "current_role_model": current, "search": args.search,
|
|
51
65
|
});
|
|
52
66
|
if args.json {
|
|
53
67
|
Ok(CmdResult {
|
|
@@ -68,7 +82,11 @@ fn render_catalog(args: &ModelsArgs, all: Vec<ModelRecord>) -> Result<CmdResult,
|
|
|
68
82
|
model.vendor,
|
|
69
83
|
model.id,
|
|
70
84
|
model.display_name,
|
|
71
|
-
"
|
|
85
|
+
if args.provider == "pi" {
|
|
86
|
+
(current.as_deref() == Some(model.id.as_str())).to_string()
|
|
87
|
+
} else {
|
|
88
|
+
"—".to_string()
|
|
89
|
+
},
|
|
72
90
|
model
|
|
73
91
|
.default
|
|
74
92
|
.map_or_else(|| "—".to_string(), |value| value.to_string()),
|
|
@@ -85,6 +103,44 @@ fn render_catalog(args: &ModelsArgs, all: Vec<ModelRecord>) -> Result<CmdResult,
|
|
|
85
103
|
}
|
|
86
104
|
}
|
|
87
105
|
|
|
106
|
+
#[cfg(test)]
|
|
107
|
+
fn cmd_models_with(
|
|
108
|
+
args: &ModelsArgs,
|
|
109
|
+
program: &Path,
|
|
110
|
+
timeout: Duration,
|
|
111
|
+
max_bytes: u64,
|
|
112
|
+
) -> Result<CmdResult, CliError> {
|
|
113
|
+
let bytes = match run_catalog(program, timeout, max_bytes) {
|
|
114
|
+
Ok(bytes) => bytes,
|
|
115
|
+
Err(message) => return Ok(failure(args, &message)),
|
|
116
|
+
};
|
|
117
|
+
let all = match crate::provider::model_catalog::parse_pi_catalog(&bytes).map_err(|error| error.message("pi")) {
|
|
118
|
+
Ok(models) => models,
|
|
119
|
+
Err(message) => return Ok(failure(args, &message)),
|
|
120
|
+
};
|
|
121
|
+
render_catalog(args, all)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
#[cfg(test)]
|
|
125
|
+
fn model_matches(model: &ModelRecord, search: &str) -> bool {
|
|
126
|
+
crate::provider::model_catalog::model_matches(model, search)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
#[cfg(test)]
|
|
130
|
+
fn failure(args: &ModelsArgs, message: &str) -> CmdResult {
|
|
131
|
+
let action = if message.starts_with("unsupported model provider") {
|
|
132
|
+
"choose a supported provider: pi, codex, claude, or claude_code".to_string()
|
|
133
|
+
} else {
|
|
134
|
+
let executable = match args.provider.as_str() {
|
|
135
|
+
"codex" => "codex",
|
|
136
|
+
"claude" | "claude_code" => "claude",
|
|
137
|
+
_ => "pi",
|
|
138
|
+
};
|
|
139
|
+
format!("install or repair the PATH-first `{executable}` executable, then retry `team-agent models --provider {}`", args.provider)
|
|
140
|
+
};
|
|
141
|
+
failure_with_action(args, message, &action)
|
|
142
|
+
}
|
|
143
|
+
|
|
88
144
|
fn failure_with_action(args: &ModelsArgs, message: &str, action: &str) -> CmdResult {
|
|
89
145
|
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 });
|
|
90
146
|
if args.json {
|
|
@@ -100,11 +156,39 @@ fn failure_with_action(args: &ModelsArgs, message: &str, action: &str) -> CmdRes
|
|
|
100
156
|
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 }
|
|
101
157
|
}
|
|
102
158
|
}
|
|
159
|
+
fn current_role_model(models: &[String]) -> Option<String> {
|
|
160
|
+
current_role_model_from(
|
|
161
|
+
models,
|
|
162
|
+
std::env::var("PI_PROVIDER").ok().as_deref(),
|
|
163
|
+
std::env::var("PI_MODEL").ok().as_deref(),
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
fn current_role_model_from(
|
|
167
|
+
models: &[String],
|
|
168
|
+
provider: Option<&str>,
|
|
169
|
+
model: Option<&str>,
|
|
170
|
+
) -> Option<String> {
|
|
171
|
+
let exact = format!("{}/{}", provider?, model?);
|
|
172
|
+
models
|
|
173
|
+
.iter()
|
|
174
|
+
.any(|candidate| candidate == &exact)
|
|
175
|
+
.then_some(exact)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/// Injectable executable, deadline, and byte-limit boundary for deterministic tests.
|
|
179
|
+
#[cfg(test)]
|
|
180
|
+
fn run_catalog(program: &Path, timeout: Duration, max_bytes: u64) -> Result<Vec<u8>, String> {
|
|
181
|
+
crate::lifecycle::launch::pi_mcp::run_pi_catalog(program, timeout, max_bytes)
|
|
182
|
+
}
|
|
183
|
+
|
|
103
184
|
#[cfg(test)]
|
|
104
185
|
mod tests {
|
|
105
186
|
use super::*;
|
|
106
187
|
#[cfg(unix)]
|
|
188
|
+
use std::io::Write;
|
|
189
|
+
#[cfg(unix)]
|
|
107
190
|
use std::sync::atomic::{AtomicU64, Ordering};
|
|
191
|
+
use std::time::Instant;
|
|
108
192
|
|
|
109
193
|
#[cfg(unix)]
|
|
110
194
|
static FIXTURE_SEQUENCE: AtomicU64 = AtomicU64::new(0);
|
|
@@ -124,6 +208,126 @@ mod tests {
|
|
|
124
208
|
std::process::exit(exit.code());
|
|
125
209
|
}
|
|
126
210
|
|
|
211
|
+
#[cfg(unix)]
|
|
212
|
+
#[test]
|
|
213
|
+
fn real_dispatcher_isolated_success_json_human_and_no_match() {
|
|
214
|
+
let pi = fixture("printf 'provider model\\nopenai-codex gpt-5.6-sol\\n'");
|
|
215
|
+
let dir = pi.parent().unwrap().to_path_buf();
|
|
216
|
+
let run_child = |args: &[&str], model: &str| {
|
|
217
|
+
std::process::Command::new(std::env::current_exe().unwrap())
|
|
218
|
+
.args([
|
|
219
|
+
"--exact",
|
|
220
|
+
"cli::models::tests::real_dispatcher_child_helper",
|
|
221
|
+
"--nocapture",
|
|
222
|
+
])
|
|
223
|
+
.env("TEAM_AGENT_MODELS_CHILD", "1")
|
|
224
|
+
.env(
|
|
225
|
+
"TEAM_AGENT_MODELS_ARGS",
|
|
226
|
+
serde_json::to_string(args).unwrap(),
|
|
227
|
+
)
|
|
228
|
+
.env("PATH", &dir)
|
|
229
|
+
.env("PI_PROVIDER", "openai-codex")
|
|
230
|
+
.env("PI_MODEL", model)
|
|
231
|
+
.output()
|
|
232
|
+
.unwrap()
|
|
233
|
+
};
|
|
234
|
+
let json = run_child(&["models", "--provider", "pi", "--json"], "gpt-5.6-sol");
|
|
235
|
+
assert!(json.status.success());
|
|
236
|
+
let output = String::from_utf8(json.stdout).unwrap();
|
|
237
|
+
let cli_output = output
|
|
238
|
+
.split("__TEAM_AGENT_MODELS_CLI_OUTPUT_v1__\n")
|
|
239
|
+
.nth(1)
|
|
240
|
+
.unwrap();
|
|
241
|
+
let value: Value = serde_json::from_str(cli_output.trim()).unwrap();
|
|
242
|
+
assert_eq!(value["schema_version"], "models.v1");
|
|
243
|
+
assert_eq!(value["models"][0]["role_model"], "openai-codex/gpt-5.6-sol");
|
|
244
|
+
assert_eq!(value["models"][0]["current"], true);
|
|
245
|
+
let human = run_child(
|
|
246
|
+
&["models", "--provider", "pi", "--search", "absent"],
|
|
247
|
+
"missing",
|
|
248
|
+
);
|
|
249
|
+
assert!(human.status.success());
|
|
250
|
+
let human_output = String::from_utf8(human.stdout).unwrap();
|
|
251
|
+
let text = human_output
|
|
252
|
+
.split("__TEAM_AGENT_MODELS_CLI_OUTPUT_v1__\n")
|
|
253
|
+
.nth(1)
|
|
254
|
+
.unwrap();
|
|
255
|
+
assert!(text.contains("No models matched --search") && text.contains("auth: ok"));
|
|
256
|
+
let null = run_child(&["models", "--provider", "pi", "--json"], "missing");
|
|
257
|
+
let null_output = String::from_utf8(null.stdout).unwrap();
|
|
258
|
+
let null_cli = null_output
|
|
259
|
+
.split("__TEAM_AGENT_MODELS_CLI_OUTPUT_v1__\n")
|
|
260
|
+
.nth(1)
|
|
261
|
+
.unwrap();
|
|
262
|
+
let null_value: Value = serde_json::from_str(null_cli.trim()).unwrap();
|
|
263
|
+
assert!(null.status.success() && null_value["current_role_model"].is_null());
|
|
264
|
+
std::fs::write(&pi, "#!/bin/sh\nprintf 'sensitive-stderr' >&2\nexit 7\n").unwrap();
|
|
265
|
+
let failed = run_child(&["models", "--provider", "pi", "--json"], "missing");
|
|
266
|
+
assert!(!failed.status.success());
|
|
267
|
+
let failed_output = String::from_utf8(failed.stdout).unwrap();
|
|
268
|
+
let failed_cli = failed_output
|
|
269
|
+
.split("__TEAM_AGENT_MODELS_CLI_OUTPUT_v1__\n")
|
|
270
|
+
.nth(1)
|
|
271
|
+
.unwrap();
|
|
272
|
+
assert!(!failed_cli.contains("sensitive-stderr"));
|
|
273
|
+
assert_eq!(
|
|
274
|
+
std::fs::read_to_string(pi.with_extension("count"))
|
|
275
|
+
.unwrap()
|
|
276
|
+
.lines()
|
|
277
|
+
.count(),
|
|
278
|
+
3
|
|
279
|
+
);
|
|
280
|
+
cleanup_fixture(&pi);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
#[test]
|
|
284
|
+
fn current_model_is_deterministic() {
|
|
285
|
+
let models = vec!["openai-codex/gpt-5.6-sol".into()];
|
|
286
|
+
assert_eq!(
|
|
287
|
+
current_role_model_from(&models, Some("openai-codex"), Some("gpt-5.6-sol")),
|
|
288
|
+
Some("openai-codex/gpt-5.6-sol".into())
|
|
289
|
+
);
|
|
290
|
+
assert_eq!(
|
|
291
|
+
current_role_model_from(&models, Some("openai-codex"), Some("other")),
|
|
292
|
+
None
|
|
293
|
+
);
|
|
294
|
+
assert_eq!(
|
|
295
|
+
current_role_model_from(&models, None, Some("gpt-5.6-sol")),
|
|
296
|
+
None
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
#[cfg(unix)]
|
|
301
|
+
#[test]
|
|
302
|
+
fn search_survives_unrelated_spaced_model_ids() {
|
|
303
|
+
let catalog =
|
|
304
|
+
include_str!("../lifecycle/tests/fixtures/pi_list_models_spaced_ids.stdout.txt");
|
|
305
|
+
let path = fixture(&format!("printf '%s' '{catalog}'"));
|
|
306
|
+
let result = cmd_models_with(
|
|
307
|
+
&ModelsArgs {
|
|
308
|
+
provider: "pi".into(),
|
|
309
|
+
search: Some("gpt-5.6-luna".into()),
|
|
310
|
+
json: true,
|
|
311
|
+
},
|
|
312
|
+
&path,
|
|
313
|
+
Duration::from_secs(10),
|
|
314
|
+
MAX_CATALOG_BYTES,
|
|
315
|
+
)
|
|
316
|
+
.unwrap();
|
|
317
|
+
cleanup_fixture(&path);
|
|
318
|
+
assert_eq!(result.exit, ExitCode::Ok);
|
|
319
|
+
let CmdOutput::Human(text) = result.output else {
|
|
320
|
+
panic!("expected JSON projection")
|
|
321
|
+
};
|
|
322
|
+
let value: Value = serde_json::from_str(&text).unwrap();
|
|
323
|
+
assert_eq!(value["ok"], true);
|
|
324
|
+
assert_eq!(value["auth"], "ok");
|
|
325
|
+
let models = value["models"].as_array().unwrap();
|
|
326
|
+
assert_eq!(models.len(), 2);
|
|
327
|
+
assert_eq!(models[0]["role_model"], "openai-codex/gpt-5.6-luna");
|
|
328
|
+
assert_eq!(models[1]["role_model"], "team-agent/gpt-5.6-luna");
|
|
329
|
+
}
|
|
330
|
+
|
|
127
331
|
#[cfg(unix)]
|
|
128
332
|
#[test]
|
|
129
333
|
fn cursor_contract_catalog_uses_public_launcher_metadata_then_exact_ids() {
|
|
@@ -157,28 +361,32 @@ esac"#);
|
|
|
157
361
|
#[cfg(unix)]
|
|
158
362
|
#[test]
|
|
159
363
|
fn grok_build_contract_catalog_runs_the_public_grok_found_on_path() {
|
|
160
|
-
|
|
364
|
+
// The public `grok` provider name declares the Grok Build leaf; both
|
|
365
|
+
// names read the same contract catalog.
|
|
366
|
+
for name in ["grok_build", "grok"] {
|
|
367
|
+
let program = fixture_program("grok", r#"
|
|
161
368
|
test "$#" = 1 || exit 9
|
|
162
369
|
case "$1" in
|
|
163
370
|
--version) printf '%s\n' 'grok 1.0.52 (0920c8169e27)' ;;
|
|
164
371
|
models) exec /bin/cat "$TEAM_AGENT_MODELS_FIXTURE" ;;
|
|
165
372
|
*) exit 9 ;;
|
|
166
373
|
esac"#);
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
374
|
+
let mut grok = CliFixture::new(program);
|
|
375
|
+
let response = grok.program.with_extension("stdout");
|
|
376
|
+
std::fs::write(&response, include_bytes!("../provider/testdata/grok-models-authenticated.stdout")).unwrap();
|
|
377
|
+
grok.response = Some(response);
|
|
378
|
+
let output = run_public_models_cli(&grok.program, grok.response.as_deref(),
|
|
379
|
+
&["models", "--provider", name, "--json"]);
|
|
380
|
+
let text = public_cli_text(&output);
|
|
381
|
+
let calls = std::fs::read_to_string(grok.program.with_extension("count")).unwrap_or_default();
|
|
382
|
+
assert!(output.status.success(), "{name}: {text}");
|
|
383
|
+
// Whatever `grok` PATH selects answers every probe; no install path is assumed.
|
|
384
|
+
assert_eq!(calls, "1:--version\n1:models\n", "{name}");
|
|
385
|
+
let value: Value = serde_json::from_str(text.trim()).unwrap();
|
|
386
|
+
assert_eq!(value["provider"], "grok_build", "{name}");
|
|
387
|
+
assert_eq!(value["source"]["executable"], grok.program.to_str().unwrap(), "{name}");
|
|
388
|
+
assert!(value["models"].as_array().unwrap().iter().any(|row| row["model_id"] == "grok-4.7-build-fast"), "{name}");
|
|
389
|
+
}
|
|
182
390
|
}
|
|
183
391
|
|
|
184
392
|
#[cfg(unix)]
|
|
@@ -234,158 +442,6 @@ esac"#));
|
|
|
234
442
|
assert!(value["error"].as_str().unwrap().contains("Cursor release unknown"));
|
|
235
443
|
}
|
|
236
444
|
|
|
237
|
-
#[cfg(unix)]
|
|
238
|
-
#[test]
|
|
239
|
-
fn grok_public_cli_uses_native_catalog_and_keeps_shared_projection() {
|
|
240
|
-
let grok = native_cli_fixture(
|
|
241
|
-
"grok",
|
|
242
|
-
include_bytes!("../provider/testdata/grok-models-authenticated.stdout"),
|
|
243
|
-
);
|
|
244
|
-
let json = run_public_models_cli(
|
|
245
|
-
&grok.program,
|
|
246
|
-
grok.response.as_deref(),
|
|
247
|
-
&["models", "--provider", "grok", "--json"],
|
|
248
|
-
);
|
|
249
|
-
let human = run_public_models_cli(
|
|
250
|
-
&grok.program,
|
|
251
|
-
grok.response.as_deref(),
|
|
252
|
-
&["models", "--provider", "grok", "--search", "BUILD FAST"],
|
|
253
|
-
);
|
|
254
|
-
let no_match = run_public_models_cli(
|
|
255
|
-
&grok.program,
|
|
256
|
-
grok.response.as_deref(),
|
|
257
|
-
&[
|
|
258
|
-
"models",
|
|
259
|
-
"--provider",
|
|
260
|
-
"grok",
|
|
261
|
-
"--search",
|
|
262
|
-
"definitely-absent",
|
|
263
|
-
],
|
|
264
|
-
);
|
|
265
|
-
let json_text = public_cli_text(&json);
|
|
266
|
-
let human_text = public_cli_text(&human);
|
|
267
|
-
let no_match_text = public_cli_text(&no_match);
|
|
268
|
-
let calls =
|
|
269
|
-
std::fs::read_to_string(grok.program.with_extension("count")).unwrap_or_default();
|
|
270
|
-
drop(grok);
|
|
271
|
-
assert!(json.status.success(), "{json_text}");
|
|
272
|
-
assert!(human.status.success(), "{human_text}");
|
|
273
|
-
assert!(no_match.status.success(), "{no_match_text}");
|
|
274
|
-
assert_eq!(calls, "1:models\n".repeat(3));
|
|
275
|
-
let value: Value = serde_json::from_str(json_text.trim()).unwrap();
|
|
276
|
-
assert_eq!(value["schema_version"], "models.v1");
|
|
277
|
-
assert_eq!(value["provider"], "grok");
|
|
278
|
-
assert_eq!(value["auth_basis"], "catalog_visibility");
|
|
279
|
-
let models = value["models"].as_array().unwrap();
|
|
280
|
-
assert_eq!(
|
|
281
|
-
models
|
|
282
|
-
.iter()
|
|
283
|
-
.map(|model| model["model_id"].as_str().unwrap())
|
|
284
|
-
.collect::<Vec<_>>(),
|
|
285
|
-
vec!["grok-4.7", "grok-4.7-build-fast", "grok-4.5", "grok-4.6"]
|
|
286
|
-
);
|
|
287
|
-
assert!(models.iter().all(|model| model["provider"] == "grok"
|
|
288
|
-
&& model["vendor"] == "xai"
|
|
289
|
-
&& model["aliases"] == json!([])));
|
|
290
|
-
assert_eq!(models[0]["default"], false);
|
|
291
|
-
assert_eq!(models[3]["default"], true);
|
|
292
|
-
assert!(human_text.contains("grok-4.7-build-fast"));
|
|
293
|
-
assert!(no_match_text.contains("No models matched --search"));
|
|
294
|
-
assert!(no_match_text.contains("auth: ok (catalog_visibility)"));
|
|
295
|
-
|
|
296
|
-
let grok = native_cli_fixture(
|
|
297
|
-
"grok",
|
|
298
|
-
include_bytes!("../provider/testdata/grok-models-unauthenticated.stdout"),
|
|
299
|
-
);
|
|
300
|
-
let changed_default = run_public_models_cli(
|
|
301
|
-
&grok.program,
|
|
302
|
-
grok.response.as_deref(),
|
|
303
|
-
&["models", "--provider", "grok", "--json"],
|
|
304
|
-
);
|
|
305
|
-
let changed_text = public_cli_text(&changed_default);
|
|
306
|
-
drop(grok);
|
|
307
|
-
assert!(changed_default.status.success(), "{changed_text}");
|
|
308
|
-
let changed: Value = serde_json::from_str(changed_text.trim()).unwrap();
|
|
309
|
-
assert_eq!(changed["models"][0]["model_id"], "grok-4.7");
|
|
310
|
-
assert_eq!(changed["models"][0]["default"], true);
|
|
311
|
-
assert_eq!(changed["models"][1]["default"], false);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
#[cfg(unix)]
|
|
315
|
-
#[test]
|
|
316
|
-
fn grok_invalid_native_catalogs_fail_closed_without_fallback() {
|
|
317
|
-
let cases: [(&str, Vec<u8>); 7] = [
|
|
318
|
-
("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()),
|
|
319
|
-
("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()),
|
|
320
|
-
("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()),
|
|
321
|
-
("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()),
|
|
322
|
-
("empty", b"You are not authenticated.\n\nDefault model: grok-4.6\n\nAvailable models:\n".to_vec()),
|
|
323
|
-
("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()),
|
|
324
|
-
("invalid utf8", vec![b'Y', b'o', b'u', 0xff]),
|
|
325
|
-
];
|
|
326
|
-
let mut outcomes = Vec::new();
|
|
327
|
-
for (name, bytes) in cases {
|
|
328
|
-
let grok = native_cli_fixture("grok", &bytes);
|
|
329
|
-
let output = run_public_models_cli(
|
|
330
|
-
&grok.program,
|
|
331
|
-
grok.response.as_deref(),
|
|
332
|
-
&["models", "--provider", "grok", "--json"],
|
|
333
|
-
);
|
|
334
|
-
let text = public_cli_text(&output);
|
|
335
|
-
let calls =
|
|
336
|
-
std::fs::read_to_string(grok.program.with_extension("count")).unwrap_or_default();
|
|
337
|
-
outcomes.push((name, output.status.success(), text, calls));
|
|
338
|
-
}
|
|
339
|
-
for (name, success, text, calls) in outcomes {
|
|
340
|
-
assert!(!success, "{name} catalog unexpectedly accepted: {text}");
|
|
341
|
-
assert_eq!(calls, "1:models\n", "{name}");
|
|
342
|
-
let value: Value = serde_json::from_str(text.trim()).unwrap();
|
|
343
|
-
assert_eq!(value["schema_version"], "models.v1", "{name}");
|
|
344
|
-
assert_eq!(value["ok"], false, "{name}");
|
|
345
|
-
assert_eq!(value["models"], json!([]), "{name}");
|
|
346
|
-
assert!(
|
|
347
|
-
!value["error"]
|
|
348
|
-
.as_str()
|
|
349
|
-
.unwrap()
|
|
350
|
-
.to_ascii_lowercase()
|
|
351
|
-
.contains("unsupported model provider"),
|
|
352
|
-
"{name}: {text}"
|
|
353
|
-
);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
#[cfg(unix)]
|
|
358
|
-
#[test]
|
|
359
|
-
fn grok_nonzero_native_command_is_not_a_successful_empty_catalog() {
|
|
360
|
-
let grok = CliFixture::new(fixture_program(
|
|
361
|
-
"grok",
|
|
362
|
-
"printf 'private diagnostic' >&2\nexit 7",
|
|
363
|
-
));
|
|
364
|
-
let output = run_public_models_cli(
|
|
365
|
-
&grok.program,
|
|
366
|
-
None,
|
|
367
|
-
&["models", "--provider", "grok", "--json"],
|
|
368
|
-
);
|
|
369
|
-
let text = public_cli_text(&output);
|
|
370
|
-
let calls =
|
|
371
|
-
std::fs::read_to_string(grok.program.with_extension("count")).unwrap_or_default();
|
|
372
|
-
drop(grok);
|
|
373
|
-
assert!(!output.status.success(), "{text}");
|
|
374
|
-
assert_eq!(calls, "1:models\n");
|
|
375
|
-
assert!(!text.contains("private diagnostic"));
|
|
376
|
-
let value: Value = serde_json::from_str(text.trim()).unwrap();
|
|
377
|
-
assert_eq!(value["ok"], false);
|
|
378
|
-
assert_eq!(value["models"], json!([]));
|
|
379
|
-
assert!(
|
|
380
|
-
value["error"]
|
|
381
|
-
.as_str()
|
|
382
|
-
.unwrap()
|
|
383
|
-
.to_ascii_lowercase()
|
|
384
|
-
.contains("grok"),
|
|
385
|
-
"{text}"
|
|
386
|
-
);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
445
|
#[cfg(unix)]
|
|
390
446
|
#[test]
|
|
391
447
|
fn grok_failure_help_and_unsupported_action_are_publicly_diagnostic() {
|
|
@@ -397,7 +453,11 @@ esac"#));
|
|
|
397
453
|
);
|
|
398
454
|
let text = public_cli_text(&output);
|
|
399
455
|
let value: Value = serde_json::from_str(text.trim()).unwrap();
|
|
456
|
+
// `grok` reads the Grok Build leaf catalog; a missing PATH `grok` fails
|
|
457
|
+
// closed there with no legacy catalog fallback.
|
|
400
458
|
assert_eq!(value["ok"], false);
|
|
459
|
+
assert_eq!(value["provider"], "grok_build", "{text}");
|
|
460
|
+
assert_eq!(value["models"], json!([]), "{text}");
|
|
401
461
|
assert!(
|
|
402
462
|
value["error"]
|
|
403
463
|
.as_str()
|
|
@@ -406,7 +466,6 @@ esac"#));
|
|
|
406
466
|
.contains("grok"),
|
|
407
467
|
"{text}"
|
|
408
468
|
);
|
|
409
|
-
assert!(value["action"].as_str().unwrap().contains("grok"), "{text}");
|
|
410
469
|
assert!(crate::cli::emit::default_help().contains("grok"));
|
|
411
470
|
assert!(crate::cli::spec::command_spec("models")
|
|
412
471
|
.unwrap()
|
|
@@ -432,6 +491,11 @@ esac"#));
|
|
|
432
491
|
);
|
|
433
492
|
}
|
|
434
493
|
|
|
494
|
+
#[cfg(unix)]
|
|
495
|
+
fn fixture(body: &str) -> std::path::PathBuf {
|
|
496
|
+
fixture_program("pi", body)
|
|
497
|
+
}
|
|
498
|
+
|
|
435
499
|
#[cfg(unix)]
|
|
436
500
|
fn fixture_program(program: &str, body: &str) -> std::path::PathBuf {
|
|
437
501
|
let sequence = FIXTURE_SEQUENCE.fetch_add(1, Ordering::Relaxed);
|
|
@@ -501,16 +565,6 @@ esac"#));
|
|
|
501
565
|
}
|
|
502
566
|
}
|
|
503
567
|
|
|
504
|
-
#[cfg(unix)]
|
|
505
|
-
fn native_cli_fixture(program: &str, bytes: &[u8]) -> CliFixture {
|
|
506
|
-
let program = fixture_program(program, "exec /bin/cat \"$TEAM_AGENT_MODELS_FIXTURE\"");
|
|
507
|
-
let mut fixture = CliFixture::new(program);
|
|
508
|
-
let response = fixture.program.with_extension("stdout");
|
|
509
|
-
std::fs::write(&response, bytes).unwrap();
|
|
510
|
-
fixture.response = Some(response);
|
|
511
|
-
fixture
|
|
512
|
-
}
|
|
513
|
-
|
|
514
568
|
#[cfg(unix)]
|
|
515
569
|
fn run_public_models_cli(
|
|
516
570
|
path: &Path,
|
|
@@ -549,19 +603,568 @@ esac"#));
|
|
|
549
603
|
.to_string()
|
|
550
604
|
}
|
|
551
605
|
|
|
606
|
+
#[cfg(unix)]
|
|
607
|
+
fn fixture_with_sidecars(body: &str) -> std::path::PathBuf {
|
|
608
|
+
let path = fixture(body);
|
|
609
|
+
let script = std::fs::read_to_string(&path).unwrap();
|
|
610
|
+
let script = script.strip_prefix("#!/bin/sh\n").unwrap();
|
|
611
|
+
let script = format!(
|
|
612
|
+
"#!/bin/sh\nprintf '1\\n' > \"$0.entered\" || :\n{script}body_status=$?\nprintf '1\\n' > \"$0.completed\" || :\nexit \"$body_status\"\n"
|
|
613
|
+
);
|
|
614
|
+
install_executable(&path, &script);
|
|
615
|
+
path
|
|
616
|
+
}
|
|
617
|
+
|
|
552
618
|
#[cfg(unix)]
|
|
553
619
|
fn cleanup_fixture(path: &Path) {
|
|
554
620
|
let _ = std::fs::remove_dir_all(path.parent().unwrap());
|
|
555
621
|
}
|
|
556
622
|
|
|
623
|
+
#[cfg(unix)]
|
|
624
|
+
fn native_timeout_fixture() -> std::path::PathBuf {
|
|
625
|
+
let path = std::path::PathBuf::from(env!("TEAM_AGENT_MODELS_TIMEOUT_FIXTURE"));
|
|
626
|
+
assert!(path.is_file(), "prebuilt models timeout fixture is missing");
|
|
627
|
+
path
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
#[cfg(unix)]
|
|
631
|
+
fn native_timeout_receipt() -> std::path::PathBuf {
|
|
632
|
+
let stamp = std::time::SystemTime::now()
|
|
633
|
+
.duration_since(std::time::UNIX_EPOCH)
|
|
634
|
+
.unwrap()
|
|
635
|
+
.as_nanos();
|
|
636
|
+
std::path::PathBuf::from("/tmp").join(format!(
|
|
637
|
+
"team-agent-models-timeout-{}-{stamp}.receipt",
|
|
638
|
+
std::process::id()
|
|
639
|
+
))
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
#[cfg(unix)]
|
|
643
|
+
fn native_timeout_stage_receipt(receipt: &Path) -> std::path::PathBuf {
|
|
644
|
+
receipt.with_extension("stage")
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
#[cfg(unix)]
|
|
648
|
+
fn parse_native_timeout_receipt(path: &Path) -> Option<BTreeMap<String, String>> {
|
|
649
|
+
let mut fields = BTreeMap::new();
|
|
650
|
+
for line in std::fs::read_to_string(path).ok()?.lines() {
|
|
651
|
+
let (key, value) = line.split_once('=')?;
|
|
652
|
+
if fields.insert(key.to_string(), value.to_string()).is_some() {
|
|
653
|
+
return None;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
let keys = fields.keys().map(String::as_str).collect::<Vec<_>>();
|
|
657
|
+
(keys
|
|
658
|
+
== vec![
|
|
659
|
+
"child_argv_exact",
|
|
660
|
+
"child_pid",
|
|
661
|
+
"child_spawn_attempts",
|
|
662
|
+
"descendant_pid",
|
|
663
|
+
"descendant_started",
|
|
664
|
+
"descendant_stdout_inherited",
|
|
665
|
+
"parent_argv_exact",
|
|
666
|
+
"parent_pid",
|
|
667
|
+
"parent_started_once",
|
|
668
|
+
])
|
|
669
|
+
.then_some(fields)
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
#[cfg(unix)]
|
|
673
|
+
fn wait_native_timeout_receipt(path: &Path) -> BTreeMap<String, String> {
|
|
674
|
+
let deadline = Instant::now() + Duration::from_millis(500);
|
|
675
|
+
loop {
|
|
676
|
+
if let Some(fields) = parse_native_timeout_receipt(path) {
|
|
677
|
+
return fields;
|
|
678
|
+
}
|
|
679
|
+
if Instant::now() >= deadline {
|
|
680
|
+
panic!("native timeout receipt did not become complete after runner return");
|
|
681
|
+
}
|
|
682
|
+
std::thread::sleep(Duration::from_millis(1));
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
#[cfg(unix)]
|
|
687
|
+
fn with_native_mode<T>(
|
|
688
|
+
mode: &str,
|
|
689
|
+
action: impl FnOnce() -> T,
|
|
690
|
+
) -> (
|
|
691
|
+
T,
|
|
692
|
+
crate::lifecycle::launch::pi_mcp::PiCatalogTestObservation,
|
|
693
|
+
) {
|
|
694
|
+
let receipt = native_timeout_receipt();
|
|
695
|
+
assert!(!receipt.exists());
|
|
696
|
+
let result = crate::lifecycle::launch::pi_mcp::with_pi_catalog_test_observation(
|
|
697
|
+
&receipt,
|
|
698
|
+
Some(mode),
|
|
699
|
+
action,
|
|
700
|
+
);
|
|
701
|
+
assert!(!receipt.exists());
|
|
702
|
+
let _ = std::fs::remove_file(format!("{}.sock", receipt.display()));
|
|
703
|
+
result
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
#[cfg(unix)]
|
|
707
|
+
fn safe_fixture_sidecar(path: &Path, expected: &str) -> &'static str {
|
|
708
|
+
match std::fs::read_to_string(path) {
|
|
709
|
+
Ok(text) if text == expected => "present_expected",
|
|
710
|
+
Ok(_) => "present_unexpected",
|
|
711
|
+
Err(error) if error.kind() == std::io::ErrorKind::NotFound => "missing",
|
|
712
|
+
Err(_) => "unavailable",
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
#[cfg(unix)]
|
|
717
|
+
fn safe_runner_fixture_observation(path: &Path) -> String {
|
|
718
|
+
format!(
|
|
719
|
+
"fixture_entered={} fixture_completed={} fixture_count={}",
|
|
720
|
+
safe_fixture_sidecar(&path.with_extension("entered"), "1\n"),
|
|
721
|
+
safe_fixture_sidecar(&path.with_extension("completed"), "1\n"),
|
|
722
|
+
safe_fixture_sidecar(&path.with_extension("count"), "1:--list-models\n"),
|
|
723
|
+
)
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
#[cfg(unix)]
|
|
727
|
+
fn safe_runner_observation(
|
|
728
|
+
elapsed: Duration,
|
|
729
|
+
observation: &crate::lifecycle::launch::pi_mcp::PiCatalogTestObservation,
|
|
730
|
+
) -> String {
|
|
731
|
+
format!(
|
|
732
|
+
"elapsed_ms={} spawn_count={} argv={:?} parent_pid={:?} parent_exit_success={:?} parent_exit_code={:?} reader_timeout={}",
|
|
733
|
+
elapsed.as_millis(),
|
|
734
|
+
observation.spawn_count,
|
|
735
|
+
observation.argv,
|
|
736
|
+
observation.parent_pid,
|
|
737
|
+
observation.parent_exit_success,
|
|
738
|
+
observation.parent_exit_code,
|
|
739
|
+
observation.reader_timeout,
|
|
740
|
+
)
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
#[cfg(unix)]
|
|
744
|
+
fn safe_models_result_class(result: &CmdResult) -> &'static str {
|
|
745
|
+
let CmdOutput::Human(text) = &result.output else {
|
|
746
|
+
return "non_human_output";
|
|
747
|
+
};
|
|
748
|
+
let Ok(value) = serde_json::from_str::<Value>(text) else {
|
|
749
|
+
return "non_json_output";
|
|
750
|
+
};
|
|
751
|
+
match value.get("ok").and_then(Value::as_bool) {
|
|
752
|
+
Some(true) => "success_json",
|
|
753
|
+
Some(false) => match value.get("error").and_then(Value::as_str) {
|
|
754
|
+
Some(error) if error.contains("unavailable") => "runner_unavailable",
|
|
755
|
+
Some(error) if error.contains("timed out") => "runner_timeout",
|
|
756
|
+
Some(error) if error.contains("command failed") => "runner_exit",
|
|
757
|
+
Some(error) if error.contains("could not be read") => "reader_error",
|
|
758
|
+
Some(error) if error.contains("exceeds") => "reader_oversize",
|
|
759
|
+
Some(error) if error.contains("catalog") => "parser_catalog_error",
|
|
760
|
+
Some(_) => "failure_json",
|
|
761
|
+
None => "failure_json_missing_error",
|
|
762
|
+
},
|
|
763
|
+
None => "json_missing_ok",
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
#[cfg(unix)]
|
|
768
|
+
fn safe_models_observation(
|
|
769
|
+
elapsed: Duration,
|
|
770
|
+
result: &CmdResult,
|
|
771
|
+
observation: &crate::lifecycle::launch::pi_mcp::PiCatalogTestObservation,
|
|
772
|
+
) -> String {
|
|
773
|
+
format!(
|
|
774
|
+
"class={} elapsed_ms={} parent_pid={:?} parent_exit_success={:?} parent_exit_code={:?} reader_timeout={}",
|
|
775
|
+
safe_models_result_class(result),
|
|
776
|
+
elapsed.as_millis(),
|
|
777
|
+
observation.parent_pid,
|
|
778
|
+
observation.parent_exit_success,
|
|
779
|
+
observation.parent_exit_code,
|
|
780
|
+
observation.reader_timeout,
|
|
781
|
+
)
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
#[cfg(unix)]
|
|
785
|
+
#[test]
|
|
786
|
+
fn runner_invokes_exact_argv_once_and_drains() {
|
|
787
|
+
let path = fixture_with_sidecars(
|
|
788
|
+
"test \"$1\" = --list-models && echo provider model && echo openai-codex gpt-5.6-sol",
|
|
789
|
+
);
|
|
790
|
+
let receipt = native_timeout_receipt();
|
|
791
|
+
assert!(!receipt.exists());
|
|
792
|
+
let started = Instant::now();
|
|
793
|
+
let (result, observation) =
|
|
794
|
+
crate::lifecycle::launch::pi_mcp::with_pi_catalog_test_observation(
|
|
795
|
+
&receipt,
|
|
796
|
+
None,
|
|
797
|
+
|| run_catalog(&path, Duration::from_secs(1), 1024),
|
|
798
|
+
);
|
|
799
|
+
let elapsed = started.elapsed();
|
|
800
|
+
let fixture_observation = safe_runner_fixture_observation(&path);
|
|
801
|
+
assert!(
|
|
802
|
+
result
|
|
803
|
+
.as_ref()
|
|
804
|
+
.is_ok_and(|bytes| bytes.starts_with(b"provider model")),
|
|
805
|
+
"runner observation: {}; {}",
|
|
806
|
+
safe_runner_observation(elapsed, &observation),
|
|
807
|
+
fixture_observation
|
|
808
|
+
);
|
|
809
|
+
let _ = result.unwrap();
|
|
810
|
+
let _ = std::fs::remove_file(&receipt);
|
|
811
|
+
let _ = std::fs::remove_file(format!("{}.sock", receipt.display()));
|
|
812
|
+
assert_eq!(
|
|
813
|
+
std::fs::read_to_string(path.with_extension("count")).unwrap(),
|
|
814
|
+
"1:--list-models\n"
|
|
815
|
+
);
|
|
816
|
+
cleanup_fixture(&path);
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
#[cfg(unix)]
|
|
820
|
+
const NATIVE_STAGE_KEYS: [&str; 5] = [
|
|
821
|
+
"parent_entry_ms",
|
|
822
|
+
"parent_before_child_spawn_ms",
|
|
823
|
+
"parent_after_child_spawn_ms",
|
|
824
|
+
"parent_before_exit_ms",
|
|
825
|
+
"test_spawn_return_ms",
|
|
826
|
+
];
|
|
827
|
+
|
|
828
|
+
#[cfg(unix)]
|
|
829
|
+
// Match the native helper's UNIX epoch millisecond clock exactly.
|
|
830
|
+
fn append_native_stage(path: &Path, key: &str) {
|
|
831
|
+
if !NATIVE_STAGE_KEYS.contains(&key) {
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
let Some(milliseconds) = std::time::SystemTime::now()
|
|
835
|
+
.duration_since(std::time::UNIX_EPOCH)
|
|
836
|
+
.ok()
|
|
837
|
+
.map(|duration| duration.as_millis())
|
|
838
|
+
else {
|
|
839
|
+
return;
|
|
840
|
+
};
|
|
841
|
+
let Ok(mut file) = std::fs::OpenOptions::new()
|
|
842
|
+
.create(true)
|
|
843
|
+
.append(true)
|
|
844
|
+
.open(path)
|
|
845
|
+
else {
|
|
846
|
+
return;
|
|
847
|
+
};
|
|
848
|
+
let _ = writeln!(file, "{key}={milliseconds}");
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
#[cfg(unix)]
|
|
852
|
+
fn safe_native_stage(path: &Path) -> String {
|
|
853
|
+
let (read_state, text) = match std::fs::read_to_string(path) {
|
|
854
|
+
Ok(text) => ("ok", Some(text)),
|
|
855
|
+
Err(error) if error.kind() == std::io::ErrorKind::NotFound => ("missing", None),
|
|
856
|
+
Err(_) => ("unavailable", None),
|
|
857
|
+
};
|
|
858
|
+
let mut fields = BTreeMap::new();
|
|
859
|
+
if let Some(ref text) = text {
|
|
860
|
+
for line in text.lines() {
|
|
861
|
+
let Some((key, value)) = line.split_once('=') else {
|
|
862
|
+
continue;
|
|
863
|
+
};
|
|
864
|
+
if NATIVE_STAGE_KEYS.contains(&key)
|
|
865
|
+
&& value.len() <= 20
|
|
866
|
+
&& value.bytes().all(|byte| byte.is_ascii_digit())
|
|
867
|
+
{
|
|
868
|
+
fields.entry(key).or_insert(value);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
let field = |key: &str| fields.get(key).copied().unwrap_or("unknown");
|
|
873
|
+
format!(
|
|
874
|
+
"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={}",
|
|
875
|
+
field("parent_entry_ms"),
|
|
876
|
+
field("parent_before_child_spawn_ms"),
|
|
877
|
+
field("parent_after_child_spawn_ms"),
|
|
878
|
+
field("parent_before_exit_ms"),
|
|
879
|
+
field("test_spawn_return_ms"),
|
|
880
|
+
)
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
#[cfg(unix)]
|
|
884
|
+
fn wait_for_native_parent_exit(
|
|
885
|
+
child: &mut std::process::Child,
|
|
886
|
+
stage: &Path,
|
|
887
|
+
) -> std::process::ExitStatus {
|
|
888
|
+
let deadline = Instant::now() + Duration::from_millis(500);
|
|
889
|
+
loop {
|
|
890
|
+
match child.try_wait() {
|
|
891
|
+
Ok(Some(status)) => return status,
|
|
892
|
+
Ok(None) if Instant::now() < deadline => {
|
|
893
|
+
std::thread::sleep(Duration::from_millis(1));
|
|
894
|
+
}
|
|
895
|
+
Ok(None) => {
|
|
896
|
+
let before_kill = safe_native_stage(stage);
|
|
897
|
+
let _ = child.kill();
|
|
898
|
+
let _ = child.wait();
|
|
899
|
+
let after_wait = safe_native_stage(stage);
|
|
900
|
+
panic!(
|
|
901
|
+
"native parent did not exit before test setup deadline; stage_before_kill={before_kill}; stage_after_wait={after_wait}"
|
|
902
|
+
);
|
|
903
|
+
}
|
|
904
|
+
Err(_) => {
|
|
905
|
+
let before_kill = safe_native_stage(stage);
|
|
906
|
+
let _ = child.kill();
|
|
907
|
+
let _ = child.wait();
|
|
908
|
+
let after_wait = safe_native_stage(stage);
|
|
909
|
+
panic!(
|
|
910
|
+
"native parent status could not be observed; stage_before_kill={before_kill}; stage_after_wait={after_wait}"
|
|
911
|
+
);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
/// Read/drain seam only: public `run_catalog` spawn coverage remains in the
|
|
918
|
+
/// normal success and fail-closed tests.
|
|
919
|
+
#[cfg(unix)]
|
|
920
|
+
#[test]
|
|
921
|
+
fn reader_deadline_is_bounded_after_parent_exit_with_descendant_pipe() {
|
|
922
|
+
let path = native_timeout_fixture();
|
|
923
|
+
let receipt = native_timeout_receipt();
|
|
924
|
+
let stage = native_timeout_stage_receipt(&receipt);
|
|
925
|
+
assert!(!receipt.exists());
|
|
926
|
+
assert!(!stage.exists());
|
|
927
|
+
let mut parent = std::process::Command::new(&path)
|
|
928
|
+
.arg("--list-models")
|
|
929
|
+
.env("TEAM_AGENT_MODELS_TIMEOUT_RECEIPT", &receipt)
|
|
930
|
+
.env("TEAM_AGENT_MODELS_TIMEOUT_STAGE_RECEIPT", &stage)
|
|
931
|
+
.env("TEAM_AGENT_MODELS_TIMEOUT_MODE", "descendant")
|
|
932
|
+
.stdin(std::process::Stdio::null())
|
|
933
|
+
.stdout(std::process::Stdio::piped())
|
|
934
|
+
.stderr(std::process::Stdio::null())
|
|
935
|
+
.spawn()
|
|
936
|
+
.unwrap();
|
|
937
|
+
append_native_stage(&stage, "test_spawn_return_ms");
|
|
938
|
+
let parent_pid = parent.id();
|
|
939
|
+
let parent_status = wait_for_native_parent_exit(&mut parent, &stage);
|
|
940
|
+
let stdout = parent.stdout.take().expect("native parent stdout pipe");
|
|
941
|
+
let started = Instant::now();
|
|
942
|
+
let (result, observation) =
|
|
943
|
+
crate::lifecycle::launch::pi_mcp::with_pi_catalog_test_observation(
|
|
944
|
+
&receipt,
|
|
945
|
+
Some("descendant"),
|
|
946
|
+
|| {
|
|
947
|
+
crate::lifecycle::launch::pi_mcp::run_pi_catalog_after_parent_exit_for_test(
|
|
948
|
+
stdout,
|
|
949
|
+
parent_pid,
|
|
950
|
+
parent_status,
|
|
951
|
+
Duration::from_millis(40),
|
|
952
|
+
1024,
|
|
953
|
+
)
|
|
954
|
+
},
|
|
955
|
+
);
|
|
956
|
+
let elapsed = started.elapsed();
|
|
957
|
+
assert!(
|
|
958
|
+
elapsed < Duration::from_millis(500),
|
|
959
|
+
"runner observation: {}",
|
|
960
|
+
safe_runner_observation(elapsed, &observation)
|
|
961
|
+
);
|
|
962
|
+
assert!(result.unwrap_err().contains("timed out"));
|
|
963
|
+
assert_eq!(
|
|
964
|
+
observation.parent_exit_success,
|
|
965
|
+
Some(true),
|
|
966
|
+
"runner observation: {}",
|
|
967
|
+
safe_runner_observation(elapsed, &observation)
|
|
968
|
+
);
|
|
969
|
+
assert_eq!(observation.parent_exit_code, Some(0));
|
|
970
|
+
assert!(observation.reader_timeout);
|
|
971
|
+
|
|
972
|
+
let fields = wait_native_timeout_receipt(&receipt);
|
|
973
|
+
assert_eq!(fields["parent_started_once"], "1");
|
|
974
|
+
assert_eq!(fields["parent_argv_exact"], "1");
|
|
975
|
+
assert_eq!(fields["child_spawn_attempts"], "1");
|
|
976
|
+
assert_eq!(fields["child_argv_exact"], "1");
|
|
977
|
+
assert_eq!(fields["descendant_started"], "1");
|
|
978
|
+
assert_eq!(fields["descendant_stdout_inherited"], "1");
|
|
979
|
+
assert_eq!(
|
|
980
|
+
fields["parent_pid"],
|
|
981
|
+
observation.parent_pid.unwrap().to_string()
|
|
982
|
+
);
|
|
983
|
+
assert_eq!(fields["child_pid"], fields["descendant_pid"]);
|
|
984
|
+
let _ = std::fs::remove_file(&receipt);
|
|
985
|
+
let _ = std::fs::remove_file(&stage);
|
|
986
|
+
let _ = std::fs::remove_file(format!("{}.sock", receipt.display()));
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
#[cfg(unix)]
|
|
990
|
+
#[test]
|
|
991
|
+
#[serial_test::serial(env)]
|
|
992
|
+
fn command_boundary_connects_runner_parser_search_and_contract() {
|
|
993
|
+
let path = fixture(
|
|
994
|
+
"printf 'provider model\\nopenai-codex gpt-5.6-sol\\nopenai-codex gpt-5.6-luna\\n'",
|
|
995
|
+
);
|
|
996
|
+
let args = ModelsArgs {
|
|
997
|
+
provider: "pi".into(),
|
|
998
|
+
search: Some("sol".into()),
|
|
999
|
+
json: true,
|
|
1000
|
+
};
|
|
1001
|
+
let receipt = native_timeout_receipt();
|
|
1002
|
+
assert!(!receipt.exists());
|
|
1003
|
+
let started = Instant::now();
|
|
1004
|
+
let (result, observation) =
|
|
1005
|
+
crate::lifecycle::launch::pi_mcp::with_pi_catalog_test_observation(
|
|
1006
|
+
&receipt,
|
|
1007
|
+
None,
|
|
1008
|
+
|| cmd_models_with(&args, &path, Duration::from_secs(1), 1024),
|
|
1009
|
+
);
|
|
1010
|
+
let elapsed = started.elapsed();
|
|
1011
|
+
let result = match result {
|
|
1012
|
+
Ok(result) => result,
|
|
1013
|
+
Err(_) => panic!(
|
|
1014
|
+
"command boundary returned a CLI error; class=cli_error elapsed_ms={} parent_pid={:?} parent_exit_success={:?} parent_exit_code={:?} reader_timeout={}",
|
|
1015
|
+
elapsed.as_millis(),
|
|
1016
|
+
observation.parent_pid,
|
|
1017
|
+
observation.parent_exit_success,
|
|
1018
|
+
observation.parent_exit_code,
|
|
1019
|
+
observation.reader_timeout,
|
|
1020
|
+
),
|
|
1021
|
+
};
|
|
1022
|
+
let CmdOutput::Human(text) = &result.output else {
|
|
1023
|
+
panic!(
|
|
1024
|
+
"expected JSON projection; {}",
|
|
1025
|
+
safe_models_observation(elapsed, &result, &observation)
|
|
1026
|
+
)
|
|
1027
|
+
};
|
|
1028
|
+
let value: Value = serde_json::from_str(text).unwrap_or_else(|_| {
|
|
1029
|
+
panic!(
|
|
1030
|
+
"expected valid JSON projection; {}",
|
|
1031
|
+
safe_models_observation(elapsed, &result, &observation)
|
|
1032
|
+
)
|
|
1033
|
+
});
|
|
1034
|
+
assert_eq!(
|
|
1035
|
+
value["schema_version"],
|
|
1036
|
+
"models.v1",
|
|
1037
|
+
"{}",
|
|
1038
|
+
safe_models_observation(elapsed, &result, &observation)
|
|
1039
|
+
);
|
|
1040
|
+
assert_eq!(
|
|
1041
|
+
value["models"][0]["role_model"],
|
|
1042
|
+
"openai-codex/gpt-5.6-sol",
|
|
1043
|
+
"{}",
|
|
1044
|
+
safe_models_observation(elapsed, &result, &observation)
|
|
1045
|
+
);
|
|
1046
|
+
assert_eq!(
|
|
1047
|
+
value["models"][0]["current"],
|
|
1048
|
+
false,
|
|
1049
|
+
"{}",
|
|
1050
|
+
safe_models_observation(elapsed, &result, &observation)
|
|
1051
|
+
);
|
|
1052
|
+
assert_eq!(
|
|
1053
|
+
value["auth"],
|
|
1054
|
+
"ok",
|
|
1055
|
+
"{}",
|
|
1056
|
+
safe_models_observation(elapsed, &result, &observation)
|
|
1057
|
+
);
|
|
1058
|
+
let model_count = value["models"].as_array().map(|models| models.len());
|
|
1059
|
+
assert_eq!(
|
|
1060
|
+
model_count,
|
|
1061
|
+
Some(1),
|
|
1062
|
+
"{}",
|
|
1063
|
+
safe_models_observation(elapsed, &result, &observation)
|
|
1064
|
+
);
|
|
1065
|
+
let _ = std::fs::remove_file(&receipt);
|
|
1066
|
+
let _ = std::fs::remove_file(format!("{}.sock", receipt.display()));
|
|
1067
|
+
let human = cmd_models_with(
|
|
1068
|
+
&ModelsArgs {
|
|
1069
|
+
provider: "pi".into(),
|
|
1070
|
+
search: Some("absent".into()),
|
|
1071
|
+
json: false,
|
|
1072
|
+
},
|
|
1073
|
+
&path,
|
|
1074
|
+
Duration::from_secs(1),
|
|
1075
|
+
1024,
|
|
1076
|
+
)
|
|
1077
|
+
.unwrap();
|
|
1078
|
+
let CmdOutput::Human(text) = human.output else {
|
|
1079
|
+
panic!("expected human projection")
|
|
1080
|
+
};
|
|
1081
|
+
assert!(text.contains("No models matched --search") && text.contains("auth: ok"));
|
|
1082
|
+
let refusal = crate::cli::emit::__test_dispatch(
|
|
1083
|
+
"models",
|
|
1084
|
+
&["--provider".into(), "cloud".into()],
|
|
1085
|
+
Path::new("/tmp"),
|
|
1086
|
+
);
|
|
1087
|
+
assert!(matches!(refusal, Ok(ExitCode::Error)));
|
|
1088
|
+
cleanup_fixture(&path);
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
#[cfg(unix)]
|
|
1092
|
+
#[test]
|
|
1093
|
+
fn runner_fails_closed_for_nonzero_oversize_timeout_and_unavailable() {
|
|
1094
|
+
let fail = native_timeout_fixture();
|
|
1095
|
+
let started = Instant::now();
|
|
1096
|
+
let (failed_result, fail_observation) =
|
|
1097
|
+
with_native_mode("exit7", || run_catalog(&fail, Duration::from_secs(1), 1024));
|
|
1098
|
+
let elapsed = started.elapsed();
|
|
1099
|
+
assert_eq!(
|
|
1100
|
+
failed_result.unwrap_err(),
|
|
1101
|
+
"Pi model catalog command failed",
|
|
1102
|
+
"runner observation: {}",
|
|
1103
|
+
safe_runner_observation(elapsed, &fail_observation)
|
|
1104
|
+
);
|
|
1105
|
+
assert_eq!(fail_observation.spawn_count, 1);
|
|
1106
|
+
assert_eq!(fail_observation.argv, vec!["--list-models"]);
|
|
1107
|
+
assert_eq!(fail_observation.parent_exit_success, Some(false));
|
|
1108
|
+
assert_eq!(fail_observation.parent_exit_code, Some(7));
|
|
1109
|
+
assert!(!fail_observation.reader_timeout);
|
|
1110
|
+
let (failed, failed_observation) = with_native_mode("exit7", || {
|
|
1111
|
+
cmd_models_with(
|
|
1112
|
+
&ModelsArgs {
|
|
1113
|
+
provider: "pi".into(),
|
|
1114
|
+
search: None,
|
|
1115
|
+
json: false,
|
|
1116
|
+
},
|
|
1117
|
+
&fail,
|
|
1118
|
+
Duration::from_secs(1),
|
|
1119
|
+
1024,
|
|
1120
|
+
)
|
|
1121
|
+
});
|
|
1122
|
+
let failed = failed.unwrap();
|
|
1123
|
+
assert_eq!(failed_observation.spawn_count, 1);
|
|
1124
|
+
assert_eq!(failed_observation.argv, vec!["--list-models"]);
|
|
1125
|
+
assert_eq!(failed_observation.parent_exit_success, Some(false));
|
|
1126
|
+
assert_eq!(failed_observation.parent_exit_code, Some(7));
|
|
1127
|
+
assert!(!failed_observation.reader_timeout);
|
|
1128
|
+
let CmdOutput::Human(text) = failed.output else {
|
|
1129
|
+
panic!("expected failure projection")
|
|
1130
|
+
};
|
|
1131
|
+
assert_eq!(failed.exit, ExitCode::Error);
|
|
1132
|
+
assert!(!text.contains("sensitive-token"));
|
|
1133
|
+
let big = native_timeout_fixture();
|
|
1134
|
+
let (big_result, big_observation) =
|
|
1135
|
+
with_native_mode("oversize", || run_catalog(&big, Duration::from_secs(1), 8));
|
|
1136
|
+
assert!(big_result.unwrap_err().contains("bounded output"));
|
|
1137
|
+
assert_eq!(big_observation.spawn_count, 1);
|
|
1138
|
+
assert_eq!(big_observation.argv, vec!["--list-models"]);
|
|
1139
|
+
assert_eq!(big_observation.parent_exit_success, Some(true));
|
|
1140
|
+
assert_eq!(big_observation.parent_exit_code, Some(0));
|
|
1141
|
+
assert!(!big_observation.reader_timeout);
|
|
1142
|
+
let slow = native_timeout_fixture();
|
|
1143
|
+
let (slow_result, slow_observation) = with_native_mode("sleep", || {
|
|
1144
|
+
run_catalog(&slow, Duration::from_millis(20), 1024)
|
|
1145
|
+
});
|
|
1146
|
+
assert!(slow_result.unwrap_err().contains("timed out"));
|
|
1147
|
+
assert_eq!(slow_observation.spawn_count, 1);
|
|
1148
|
+
assert_eq!(slow_observation.argv, vec!["--list-models"]);
|
|
1149
|
+
assert_eq!(slow_observation.parent_exit_success, None);
|
|
1150
|
+
assert!(!slow_observation.reader_timeout);
|
|
1151
|
+
assert!(run_catalog(
|
|
1152
|
+
std::path::Path::new("/does/not/exist"),
|
|
1153
|
+
Duration::from_secs(1),
|
|
1154
|
+
1024
|
|
1155
|
+
)
|
|
1156
|
+
.unwrap_err()
|
|
1157
|
+
.contains("unavailable"));
|
|
1158
|
+
}
|
|
1159
|
+
|
|
557
1160
|
#[test]
|
|
558
1161
|
fn public_failure_and_help_contracts_are_versioned() {
|
|
559
1162
|
let args = ModelsArgs {
|
|
560
|
-
provider: "
|
|
1163
|
+
provider: "pi".into(),
|
|
561
1164
|
search: None,
|
|
562
1165
|
json: true,
|
|
563
1166
|
};
|
|
564
|
-
let result =
|
|
1167
|
+
let result = failure(&args, "safe failure");
|
|
565
1168
|
let CmdOutput::Human(text) = result.output else {
|
|
566
1169
|
panic!("json contract must render")
|
|
567
1170
|
};
|