@team-agent/installer 0.5.61 → 0.5.63
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/crates/team-agent/src/cli/adapters.rs +5 -2
- package/crates/team-agent/src/cli/attach_app_server_leader.rs +1 -0
- package/crates/team-agent/src/cli/diagnose.rs +1 -0
- package/crates/team-agent/src/cli/emit.rs +41 -7
- package/crates/team-agent/src/cli/helpers.rs +1 -0
- package/crates/team-agent/src/cli/leader.rs +6 -1
- package/crates/team-agent/src/cli/leaders.rs +2 -0
- package/crates/team-agent/src/cli/mod.rs +33 -3
- package/crates/team-agent/src/cli/named_address.rs +8 -1
- package/crates/team-agent/src/cli/profile.rs +2 -1
- package/crates/team-agent/src/cli/send/coordinator.rs +1 -0
- package/crates/team-agent/src/cli/send/mailbox.rs +3 -0
- package/crates/team-agent/src/cli/send/persist.rs +1 -0
- package/crates/team-agent/src/cli/send/presentation.rs +1 -0
- package/crates/team-agent/src/cli/send/resolve.rs +206 -1
- package/crates/team-agent/src/cli/send.rs +2 -1
- package/crates/team-agent/src/cli/spec.rs +1 -0
- package/crates/team-agent/src/cli/status.rs +2 -1
- package/crates/team-agent/src/cli/status_port/compact.rs +1 -0
- package/crates/team-agent/src/cli/status_port/format.rs +1 -0
- package/crates/team-agent/src/cli/status_port/inbox.rs +1 -0
- package/crates/team-agent/src/cli/tests/verb_profile.rs +38 -0
- package/crates/team-agent/src/cli/types.rs +3 -2
- package/crates/team-agent/src/communication_mode/mod.rs +1 -0
- package/crates/team-agent/src/compiler.rs +1 -0
- package/crates/team-agent/src/conpty/backend.rs +1 -0
- package/crates/team-agent/src/conpty/mod.rs +1 -0
- package/crates/team-agent/src/coordinator/backoff.rs +5 -8
- package/crates/team-agent/src/coordinator/conpty_shim.rs +3 -2
- package/crates/team-agent/src/coordinator/health.rs +1 -0
- package/crates/team-agent/src/coordinator/mod.rs +2 -2
- package/crates/team-agent/src/coordinator/orphan.rs +4 -116
- package/crates/team-agent/src/coordinator/runtime_detectors.rs +1 -0
- package/crates/team-agent/src/coordinator/runtime_observation.rs +1 -0
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +15 -866
- package/crates/team-agent/src/coordinator/steps/delivery.rs +1 -0
- package/crates/team-agent/src/coordinator/steps/health_sync.rs +1 -0
- package/crates/team-agent/src/coordinator/steps/mod.rs +2 -0
- package/crates/team-agent/src/coordinator/steps/persist.rs +1 -0
- package/crates/team-agent/src/coordinator/steps/runtime_prompts.rs +1 -0
- package/crates/team-agent/src/coordinator/steps/session_gate.rs +1 -0
- package/crates/team-agent/src/coordinator/tests/abnormal.rs +0 -174
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +139 -375
- package/crates/team-agent/src/coordinator/tests/basics.rs +0 -184
- package/crates/team-agent/src/coordinator/tests/mod.rs +2 -17
- package/crates/team-agent/src/coordinator/tests/tick_core.rs +0 -49
- package/crates/team-agent/src/coordinator/tick.rs +23 -40
- package/crates/team-agent/src/coordinator/types.rs +3 -176
- package/crates/team-agent/src/db/agent_health_capture.rs +1 -0
- package/crates/team-agent/src/db/message_store.rs +2 -1
- package/crates/team-agent/src/db/migration.rs +5 -4
- package/crates/team-agent/src/db/mod.rs +1 -0
- package/crates/team-agent/src/db/schema.rs +1 -0
- package/crates/team-agent/src/diagnose/comms.rs +2 -1
- package/crates/team-agent/src/diagnose/mod.rs +1 -0
- package/crates/team-agent/src/diagnose/orphans.rs +1 -0
- package/crates/team-agent/src/layout/manager.rs +3 -7
- package/crates/team-agent/src/layout/mod.rs +2 -2
- package/crates/team-agent/src/layout/overlay.rs +6 -1
- package/crates/team-agent/src/layout/placement.rs +1 -0
- package/crates/team-agent/src/layout/recovery.rs +3 -0
- package/crates/team-agent/src/layout/runtime_sessions.rs +8 -3
- package/crates/team-agent/src/layout/sessions.rs +8 -1
- package/crates/team-agent/src/layout/tmux_endpoint.rs +3 -0
- package/crates/team-agent/src/layout/worker_env.rs +3 -0
- package/crates/team-agent/src/layout/worker_window_helpers.rs +2 -0
- package/crates/team-agent/src/leader/helpers.rs +1 -0
- package/crates/team-agent/src/leader/incident.rs +1 -0
- package/crates/team-agent/src/leader/lease.rs +27 -22
- package/crates/team-agent/src/leader/mod.rs +2 -3
- package/crates/team-agent/src/leader/owner_bind.rs +13 -3
- package/crates/team-agent/src/leader/provider_attribution.rs +1 -0
- package/crates/team-agent/src/leader/rediscover.rs +4 -17
- package/crates/team-agent/src/leader/registry.rs +3 -15
- package/crates/team-agent/src/leader/start.rs +373 -125
- package/crates/team-agent/src/leader/takeover.rs +10 -232
- package/crates/team-agent/src/leader/tests/claim_leader_mailbox_flush_contract.rs +544 -0
- package/crates/team-agent/src/leader/tests/historical_inventory_upgrade_gate_red.rs +624 -0
- package/crates/team-agent/src/leader/tests/identity.rs +7 -2
- package/crates/team-agent/src/leader/tests/idle.rs +0 -193
- package/crates/team-agent/src/leader/tests/lease_api.rs +0 -45
- package/crates/team-agent/src/leader/tests/mod.rs +4 -41
- package/crates/team-agent/src/leader/tests/rehomed_env.rs +83 -0
- package/crates/team-agent/src/leader/tests/team_in_team_state_scope_red.rs +1273 -0
- package/crates/team-agent/src/leader/tests/terminal_and_replay_vs_rerender_invariants_red.rs +417 -0
- package/crates/team-agent/src/leader/tests/wake_start_owner.rs +22 -103
- package/crates/team-agent/src/leader/types.rs +1 -28
- package/crates/team-agent/src/lib.rs +3 -0
- package/crates/team-agent/src/lifecycle/display.rs +7 -1
- package/crates/team-agent/src/lifecycle/helpers.rs +3 -1
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +2 -2
- package/crates/team-agent/src/lifecycle/launch/fork_agent/completion.rs +1 -0
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +1 -0
- package/crates/team-agent/src/lifecycle/launch/fork_finalize.rs +1 -0
- package/crates/team-agent/src/lifecycle/launch/plan.rs +2 -2
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +4 -26
- package/crates/team-agent/src/lifecycle/launch/readiness.rs +0 -27
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +1 -27
- package/crates/team-agent/src/lifecycle/launch/spec_state.rs +4 -32
- package/crates/team-agent/src/lifecycle/launch/state_projection.rs +1 -0
- package/crates/team-agent/src/lifecycle/launch.rs +11 -12
- package/crates/team-agent/src/lifecycle/mod.rs +2 -1
- package/crates/team-agent/src/lifecycle/restart/agent.rs +3 -66
- package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +2 -2
- package/crates/team-agent/src/lifecycle/restart/rebuild.rs +13 -5
- package/crates/team-agent/src/lifecycle/restart/remove.rs +1 -1
- package/crates/team-agent/src/lifecycle/restart/selection.rs +3 -3
- package/crates/team-agent/src/lifecycle/restart.rs +13 -15
- package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +1007 -0
- package/crates/team-agent/src/lifecycle/tests/b0_legacy_snapshot_nonauthority_contract.rs +265 -0
- package/crates/team-agent/src/lifecycle/tests/b0_reader_hideone_audit_contract.rs +459 -0
- package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +849 -0
- package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +323 -0
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +423 -0
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +737 -0
- package/crates/team-agent/src/lifecycle/tests/codex_mcp_approval_inheritance_red.rs +1187 -0
- package/crates/team-agent/src/lifecycle/tests/codex_weak_window_attribution_red.rs +683 -0
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +394 -0
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +1856 -0
- package/crates/team-agent/src/lifecycle/tests/core_034_real_red.rs +917 -0
- package/crates/team-agent/src/lifecycle/tests/display_adaptive_red.rs +481 -0
- package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +301 -0
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +516 -0
- package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +986 -0
- package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +651 -0
- package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +2 -0
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +332 -0
- package/crates/team-agent/src/lifecycle/tests/realmachine_clusters_1_6_red.rs +846 -0
- package/crates/team-agent/src/lifecycle/tests/realmachine_residual_g1_g4_red.rs +648 -0
- package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +910 -0
- package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +630 -0
- package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +1083 -0
- package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +1677 -0
- package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +410 -0
- package/crates/team-agent/src/lifecycle/tests/stale_team_saveconflict_contract.rs +428 -0
- package/crates/team-agent/src/lifecycle/tests/startup_latency_contract.rs +1032 -0
- package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +869 -0
- package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +1249 -0
- package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +342 -0
- package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +542 -0
- package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +1103 -0
- package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +1276 -0
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_roster_red.rs +145 -0
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +603 -0
- package/crates/team-agent/src/lifecycle/tests/test_isolation_escape_contract.rs +837 -0
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +928 -0
- package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +951 -0
- package/crates/team-agent/src/lifecycle/tests/worker_dangerous_bypass_argv_red.rs +327 -0
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +760 -0
- package/crates/team-agent/src/lifecycle/tests.rs +59 -0
- package/crates/team-agent/src/lifecycle/types.rs +0 -9
- package/crates/team-agent/src/mcp_server/helpers.rs +1 -0
- package/crates/team-agent/src/mcp_server/lifecycle_tools/mod.rs +1 -0
- package/crates/team-agent/src/mcp_server/lifecycle_tools/state_status.rs +1 -0
- package/crates/team-agent/src/mcp_server/mod.rs +1 -0
- package/crates/team-agent/src/mcp_server/normalize.rs +4 -3
- package/crates/team-agent/src/mcp_server/tools.rs +1 -0
- package/crates/team-agent/src/mcp_server/types.rs +1 -18
- package/crates/team-agent/src/mcp_server/wire.rs +5 -5
- package/crates/team-agent/src/messaging/activity.rs +1 -0
- package/crates/team-agent/src/messaging/address.rs +1 -0
- package/crates/team-agent/src/messaging/delivery.rs +4 -3
- package/crates/team-agent/src/messaging/helpers.rs +2 -1
- package/crates/team-agent/src/messaging/leader_channel.rs +1 -0
- package/crates/team-agent/src/messaging/leader_receiver.rs +2 -1
- package/crates/team-agent/src/messaging/mod.rs +10 -14
- package/crates/team-agent/src/messaging/peers.rs +2 -0
- package/crates/team-agent/src/messaging/persist.rs +3 -1
- package/crates/team-agent/src/messaging/presentation.rs +2 -1
- package/crates/team-agent/src/messaging/results.rs +1 -0
- package/crates/team-agent/src/messaging/scheduler.rs +1 -0
- package/crates/team-agent/src/messaging/selftest.rs +1 -1
- package/crates/team-agent/src/messaging/send.rs +41 -8
- package/crates/team-agent/src/messaging/tests/mod.rs +5 -0
- package/crates/team-agent/src/messaging/types.rs +2 -2
- package/crates/team-agent/src/messaging/watchers.rs +19 -13
- package/crates/team-agent/src/model/enums.rs +1 -0
- package/crates/team-agent/src/model/errors.rs +1 -0
- package/crates/team-agent/src/model/ids.rs +1 -0
- package/crates/team-agent/src/model/mod.rs +1 -0
- package/crates/team-agent/src/model/name_similarity.rs +1 -0
- package/crates/team-agent/src/model/pane_authority_refusal.rs +1 -0
- package/crates/team-agent/src/model/paths.rs +1 -0
- package/crates/team-agent/src/model/permissions.rs +3 -2
- package/crates/team-agent/src/model/routing.rs +1 -0
- package/crates/team-agent/src/model/spec.rs +1 -0
- package/crates/team-agent/src/model/task_graph.rs +1 -0
- package/crates/team-agent/src/model/yaml/tests.rs +1 -0
- package/crates/team-agent/src/model/yaml.rs +1 -0
- package/crates/team-agent/src/packaging/install.rs +9 -147
- package/crates/team-agent/src/packaging/migrate.rs +2 -0
- package/crates/team-agent/src/packaging/mod.rs +1 -0
- package/crates/team-agent/src/packaging/repair.rs +2 -0
- package/crates/team-agent/src/packaging/tests.rs +29 -218
- package/crates/team-agent/src/packaging/types.rs +8 -15
- package/crates/team-agent/src/platform/argv.rs +4 -0
- package/crates/team-agent/src/platform/errors.rs +10 -1
- package/crates/team-agent/src/platform/file_lock.rs +4 -157
- package/crates/team-agent/src/platform/mod.rs +0 -61
- package/crates/team-agent/src/platform/process.rs +1 -0
- package/crates/team-agent/src/provider/adapter.rs +1 -0
- package/crates/team-agent/src/provider/adapters/claude.rs +1 -0
- package/crates/team-agent/src/provider/adapters/claude_fork.rs +1 -0
- package/crates/team-agent/src/provider/adapters/codex.rs +1 -0
- package/crates/team-agent/src/provider/adapters/copilot.rs +1 -0
- package/crates/team-agent/src/provider/adapters/copilot_fork.rs +1 -0
- package/crates/team-agent/src/provider/adapters/fake.rs +1 -0
- package/crates/team-agent/src/provider/adapters/mod.rs +1 -0
- package/crates/team-agent/src/provider/approvals/mod.rs +1 -0
- package/crates/team-agent/src/provider/approvals/parsing.rs +2 -5
- package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +6 -5
- package/crates/team-agent/src/provider/classify.rs +1 -0
- package/crates/team-agent/src/provider/faults.rs +1 -26
- package/crates/team-agent/src/provider/helpers.rs +1 -0
- package/crates/team-agent/src/provider/mod.rs +1 -1
- package/crates/team-agent/src/provider/session/capture.rs +1 -4
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +1 -0
- package/crates/team-agent/src/provider/session/context_fork/codex.rs +1 -0
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +1 -0
- package/crates/team-agent/src/provider/session/context_fork.rs +1 -0
- package/crates/team-agent/src/provider/session/mod.rs +2 -4
- package/crates/team-agent/src/provider/session/resume.rs +2 -209
- package/crates/team-agent/src/provider/session_scan/claude.rs +1 -0
- package/crates/team-agent/src/provider/session_scan/codex.rs +1 -0
- package/crates/team-agent/src/provider/session_scan/common.rs +1 -0
- package/crates/team-agent/src/provider/session_scan/copilot.rs +1 -0
- package/crates/team-agent/src/provider/session_scan.rs +1 -42
- package/crates/team-agent/src/provider/startup_prompt.rs +1 -0
- package/crates/team-agent/src/provider/types.rs +1 -0
- package/crates/team-agent/src/provider/wire.rs +1 -0
- package/crates/team-agent/src/state/identity.rs +16 -5
- package/crates/team-agent/src/state/identity_keys.rs +1 -0
- package/crates/team-agent/src/state/mod.rs +2 -0
- package/crates/team-agent/src/state/owner_gate.rs +5 -0
- package/crates/team-agent/src/state/ownership.rs +10 -4
- package/crates/team-agent/src/state/paths.rs +12 -0
- package/crates/team-agent/src/state/persist.rs +9 -3
- package/crates/team-agent/src/state/projection.rs +15 -2
- package/crates/team-agent/src/state/repository/intent.rs +1 -0
- package/crates/team-agent/src/state/repository/tests.rs +1 -0
- package/crates/team-agent/src/state/repository.rs +7 -13
- package/crates/team-agent/src/state/selector.rs +1 -0
- package/crates/team-agent/src/tmux_backend/tests.rs +39 -0
- package/crates/team-agent/src/tmux_backend.rs +63 -0
- package/crates/team-agent/src/transport.rs +15 -0
- package/package.json +4 -4
- package/crates/team-agent/src/leader/inject.rs +0 -33
- package/crates/team-agent/src/provider/command.rs +0 -80
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
|
|
2
|
+
|
|
3
|
+
#[path = "../../../tests/support/hermetic.rs"]
|
|
4
|
+
mod hermetic_guard;
|
|
5
|
+
#[allow(dead_code)]
|
|
6
|
+
fn _hermetic_boundary_marker(_: &hermetic_guard::HermeticTestEnv) {}
|
|
7
|
+
|
|
8
|
+
use std::collections::{BTreeMap, VecDeque};
|
|
9
|
+
use std::path::{Path, PathBuf};
|
|
10
|
+
use std::process::Command;
|
|
11
|
+
use std::sync::atomic::{AtomicU64, Ordering};
|
|
12
|
+
use std::sync::{Arc, Mutex};
|
|
13
|
+
|
|
14
|
+
use serde_json::{json, Value};
|
|
15
|
+
use serial_test::file_serial;
|
|
16
|
+
use team_agent::lifecycle::{launch_with_transport, restart_with_transport};
|
|
17
|
+
use team_agent::state::persist::{load_runtime_state, save_runtime_state};
|
|
18
|
+
use team_agent::tmux_backend::TmuxBackend;
|
|
19
|
+
use team_agent::transport::{
|
|
20
|
+
AttachOutcome, BackendKind, CaptureRange, CapturedText, InjectPayload, InjectReport,
|
|
21
|
+
InjectStage, InjectVerification, Key, PaneField, PaneId, PaneInfo, PaneLiveness, SessionName,
|
|
22
|
+
SetEnvOutcome, SpawnResult, SubmitVerification, Target, Transport, TransportError,
|
|
23
|
+
TurnVerification, WindowName,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
#[test]
|
|
27
|
+
#[ignore = "real-machine: restart/session liveness lifecycle gate"]
|
|
28
|
+
fn restart_rechecks_session_liveness_before_spawning_second_worker() {
|
|
29
|
+
let fixture = RestartFixture::new("restart-liveness-recording", &["alpha", "bravo"]);
|
|
30
|
+
fixture.seed_resumable_state_with_stale_receiver();
|
|
31
|
+
let transport = RestartLivenessTransport::new();
|
|
32
|
+
|
|
33
|
+
let result = restart_with_transport(&fixture.team, false, None, &transport);
|
|
34
|
+
let records = transport.spawn_records();
|
|
35
|
+
|
|
36
|
+
assert_eq!(
|
|
37
|
+
records.len(),
|
|
38
|
+
1,
|
|
39
|
+
"after alpha spawn_first reports success but the recreated session disappears, restart must stop before spawning bravo; result={result:?} records={records:?}"
|
|
40
|
+
);
|
|
41
|
+
assert_eq!(
|
|
42
|
+
records[0].kind, "spawn_first",
|
|
43
|
+
"alpha must be the only spawn and must recreate the session; records={records:?}"
|
|
44
|
+
);
|
|
45
|
+
assert!(
|
|
46
|
+
records.iter().all(|record| record.kind != "spawn_into"),
|
|
47
|
+
"restart must not call spawn_into/new-window for bravo against a dead session; result={result:?} records={records:?}"
|
|
48
|
+
);
|
|
49
|
+
let text = format!("{result:?}");
|
|
50
|
+
assert!(
|
|
51
|
+
text.contains("session_disappeared_after_spawn") || text.contains("provider_resume_exited"),
|
|
52
|
+
"restart must fail with an explicit first-agent/session liveness error, not a later tmux no-server error; result={result:?} records={records:?}"
|
|
53
|
+
);
|
|
54
|
+
assert!(
|
|
55
|
+
text.contains("alpha"),
|
|
56
|
+
"restart error must name the first resumed agent whose session disappeared; result={result:?}"
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
#[test]
|
|
61
|
+
#[ignore = "real-machine: restart/session liveness lifecycle gate"]
|
|
62
|
+
fn restart_partial_failure_clears_stale_receiver_and_does_not_claim_running_without_pane() {
|
|
63
|
+
let fixture = RestartFixture::new("restart-liveness-state", &["alpha", "bravo"]);
|
|
64
|
+
fixture.seed_resumable_state_with_stale_receiver();
|
|
65
|
+
let transport = RestartLivenessTransport::new();
|
|
66
|
+
|
|
67
|
+
let _ = restart_with_transport(&fixture.team, false, None, &transport);
|
|
68
|
+
let state = load_runtime_state(&fixture.team).unwrap();
|
|
69
|
+
|
|
70
|
+
assert!(
|
|
71
|
+
state.pointer("/leader_receiver/status").and_then(Value::as_str) != Some("attached"),
|
|
72
|
+
"after restart kills the session and rebuild fails, state must not leave leader_receiver.status=attached to a dead pane; state={state}"
|
|
73
|
+
);
|
|
74
|
+
for agent in ["alpha", "bravo"] {
|
|
75
|
+
let row = state
|
|
76
|
+
.pointer(&format!("/agents/{agent}"))
|
|
77
|
+
.unwrap_or_else(|| panic!("agent row exists for {agent}; state={state}"));
|
|
78
|
+
let has_session = row.get("session_id").and_then(Value::as_str).is_some();
|
|
79
|
+
let running_without_pane = row.get("status").and_then(Value::as_str) == Some("running")
|
|
80
|
+
&& row.get("pane_id").and_then(Value::as_str).is_none();
|
|
81
|
+
assert!(
|
|
82
|
+
!(has_session && running_without_pane),
|
|
83
|
+
"restart must not treat session_id without a live pane binding as successful restart; agent={agent} row={row} state={state}"
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
#[test]
|
|
89
|
+
#[ignore = "real-machine: launch pane identity lifecycle gate"]
|
|
90
|
+
fn launch_persists_real_pane_id_even_when_pane_pid_is_unavailable() {
|
|
91
|
+
let fixture = RestartFixture::new("restart-liveness-pane-id", &["alpha"]);
|
|
92
|
+
let transport = LaunchPaneIdTransport::new();
|
|
93
|
+
|
|
94
|
+
launch_with_transport(
|
|
95
|
+
&fixture.team.join("team.spec.yaml"),
|
|
96
|
+
false,
|
|
97
|
+
true,
|
|
98
|
+
true,
|
|
99
|
+
&transport,
|
|
100
|
+
)
|
|
101
|
+
.expect("launch should reach fake transport spawn");
|
|
102
|
+
|
|
103
|
+
let state = load_runtime_state(&fixture.root).unwrap();
|
|
104
|
+
assert_eq!(
|
|
105
|
+
state.pointer("/agents/alpha/pane_id").and_then(Value::as_str),
|
|
106
|
+
Some("%0"),
|
|
107
|
+
"launch must persist the real %pane_id returned by spawn even when pane_pid/list_targets is unavailable; state={state}"
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
#[test]
|
|
112
|
+
#[ignore = "real-machine: needs real tmux/binary; fake codex exits first resumed worker to reproduce no-server restart"]
|
|
113
|
+
#[file_serial(tmux)]
|
|
114
|
+
fn real_tmux_restart_names_first_resume_agent_when_first_resume_exits_before_second_spawn() {
|
|
115
|
+
let fixture = RestartFixture::new("restart-liveness-real-tmux", &["alpha", "bravo"]);
|
|
116
|
+
fixture.seed_resumable_state_with_stale_receiver();
|
|
117
|
+
let _cleanup = TmuxCleanup::new(&fixture.team);
|
|
118
|
+
let fake_bin = fixture.install_fake_codex_that_exits_alpha_resume();
|
|
119
|
+
|
|
120
|
+
let output = Command::new(crate::lifecycle::tests::test_binary_path())
|
|
121
|
+
.args([
|
|
122
|
+
"restart",
|
|
123
|
+
"--workspace",
|
|
124
|
+
fixture.team.to_str().unwrap(),
|
|
125
|
+
"--json",
|
|
126
|
+
])
|
|
127
|
+
.env(
|
|
128
|
+
"PATH",
|
|
129
|
+
format!(
|
|
130
|
+
"{}:{}",
|
|
131
|
+
fake_bin.display(),
|
|
132
|
+
std::env::var("PATH").unwrap_or_default()
|
|
133
|
+
),
|
|
134
|
+
)
|
|
135
|
+
.env("CODEX_FAKE_LOG", fixture.root.join("fake-codex.log"))
|
|
136
|
+
.output()
|
|
137
|
+
.expect("run team-agent restart");
|
|
138
|
+
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
139
|
+
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
140
|
+
let combined = format!("{stdout}\n{stderr}");
|
|
141
|
+
|
|
142
|
+
assert!(
|
|
143
|
+
!output.status.success(),
|
|
144
|
+
"fixture expects first resumed codex process to exit and restart to fail honestly; stdout={stdout} stderr={stderr}"
|
|
145
|
+
);
|
|
146
|
+
assert!(
|
|
147
|
+
combined.contains("alpha")
|
|
148
|
+
&& (combined.contains("session_disappeared_after_spawn")
|
|
149
|
+
|| combined.contains("provider_resume_exited")),
|
|
150
|
+
"real tmux restart must name first resumed agent/session disappearance, not only a later transport failure; stdout={stdout} stderr={stderr}"
|
|
151
|
+
);
|
|
152
|
+
assert!(
|
|
153
|
+
!(combined.contains("bravo") && combined.contains("no server running")),
|
|
154
|
+
"restart must not continue to bravo new-window against a dead server; stdout={stdout} stderr={stderr}"
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
#[derive(Clone, Debug)]
|
|
159
|
+
#[allow(dead_code)]
|
|
160
|
+
struct SpawnRecord {
|
|
161
|
+
kind: String,
|
|
162
|
+
window: String,
|
|
163
|
+
argv: Vec<String>,
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
#[derive(Clone, Default)]
|
|
167
|
+
struct RestartLivenessTransport {
|
|
168
|
+
inner: Arc<Mutex<RestartTransportState>>,
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
#[derive(Default)]
|
|
172
|
+
struct RestartTransportState {
|
|
173
|
+
has_session_answers: VecDeque<bool>,
|
|
174
|
+
spawns: Vec<SpawnRecord>,
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
impl RestartLivenessTransport {
|
|
178
|
+
fn new() -> Self {
|
|
179
|
+
let mut has_session_answers = VecDeque::new();
|
|
180
|
+
has_session_answers.push_back(true);
|
|
181
|
+
Self {
|
|
182
|
+
inner: Arc::new(Mutex::new(RestartTransportState {
|
|
183
|
+
has_session_answers,
|
|
184
|
+
spawns: Vec::new(),
|
|
185
|
+
})),
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
fn spawn_records(&self) -> Vec<SpawnRecord> {
|
|
190
|
+
self.inner.lock().unwrap().spawns.clone()
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
fn record_spawn(
|
|
194
|
+
&self,
|
|
195
|
+
kind: &str,
|
|
196
|
+
session: &SessionName,
|
|
197
|
+
window: &WindowName,
|
|
198
|
+
argv: &[String],
|
|
199
|
+
) -> Result<SpawnResult, TransportError> {
|
|
200
|
+
let mut inner = self.inner.lock().unwrap();
|
|
201
|
+
inner.spawns.push(SpawnRecord {
|
|
202
|
+
kind: kind.to_string(),
|
|
203
|
+
window: window.as_str().to_string(),
|
|
204
|
+
argv: argv.to_vec(),
|
|
205
|
+
});
|
|
206
|
+
if kind == "spawn_into" {
|
|
207
|
+
return Err(TransportError::MuxUnavailable {
|
|
208
|
+
backend: BackendKind::Tmux,
|
|
209
|
+
detail: format!(
|
|
210
|
+
"session disappeared after alpha resume; attempted new-window for {}",
|
|
211
|
+
window.as_str()
|
|
212
|
+
),
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
Ok(SpawnResult {
|
|
216
|
+
pane_id: PaneId::new("%0"),
|
|
217
|
+
session: session.clone(),
|
|
218
|
+
window: window.clone(),
|
|
219
|
+
child_pid: None,
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
impl Transport for RestartLivenessTransport {
|
|
225
|
+
fn kind(&self) -> BackendKind {
|
|
226
|
+
BackendKind::Tmux
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
fn spawn_first(
|
|
230
|
+
&self,
|
|
231
|
+
session: &SessionName,
|
|
232
|
+
window: &WindowName,
|
|
233
|
+
argv: &[String],
|
|
234
|
+
_cwd: &Path,
|
|
235
|
+
_env: &BTreeMap<String, String>,
|
|
236
|
+
) -> Result<SpawnResult, TransportError> {
|
|
237
|
+
self.record_spawn("spawn_first", session, window, argv)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
fn spawn_into(
|
|
241
|
+
&self,
|
|
242
|
+
session: &SessionName,
|
|
243
|
+
window: &WindowName,
|
|
244
|
+
argv: &[String],
|
|
245
|
+
_cwd: &Path,
|
|
246
|
+
_env: &BTreeMap<String, String>,
|
|
247
|
+
) -> Result<SpawnResult, TransportError> {
|
|
248
|
+
self.record_spawn("spawn_into", session, window, argv)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
fn has_session(&self, _session: &SessionName) -> Result<bool, TransportError> {
|
|
252
|
+
Ok(self
|
|
253
|
+
.inner
|
|
254
|
+
.lock()
|
|
255
|
+
.unwrap()
|
|
256
|
+
.has_session_answers
|
|
257
|
+
.pop_front()
|
|
258
|
+
.unwrap_or(false))
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
fn kill_session(&self, _session: &SessionName) -> Result<(), TransportError> {
|
|
262
|
+
Ok(())
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
fn list_targets(&self) -> Result<Vec<PaneInfo>, TransportError> {
|
|
266
|
+
Ok(Vec::new())
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
fn list_windows(&self, _session: &SessionName) -> Result<Vec<WindowName>, TransportError> {
|
|
270
|
+
Ok(Vec::new())
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
fn query(&self, _target: &Target, field: PaneField) -> Result<Option<String>, TransportError> {
|
|
274
|
+
Ok(match field {
|
|
275
|
+
PaneField::PaneId => Some("%0".to_string()),
|
|
276
|
+
PaneField::SessionName => Some("team-ctxteam".to_string()),
|
|
277
|
+
_ => None,
|
|
278
|
+
})
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
fn liveness(&self, _pane: &PaneId) -> Result<PaneLiveness, TransportError> {
|
|
282
|
+
Ok(PaneLiveness::Live)
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
fn inject(
|
|
286
|
+
&self,
|
|
287
|
+
_target: &Target,
|
|
288
|
+
_payload: &InjectPayload,
|
|
289
|
+
_submit: Key,
|
|
290
|
+
_bracketed: bool,
|
|
291
|
+
) -> Result<InjectReport, TransportError> {
|
|
292
|
+
Ok(inject_report())
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
fn send_keys(&self, _target: &Target, _keys: &[Key]) -> Result<(), TransportError> {
|
|
296
|
+
Ok(())
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
fn capture(
|
|
300
|
+
&self,
|
|
301
|
+
_target: &Target,
|
|
302
|
+
range: CaptureRange,
|
|
303
|
+
) -> Result<CapturedText, TransportError> {
|
|
304
|
+
Ok(CapturedText {
|
|
305
|
+
text: String::new(),
|
|
306
|
+
range,
|
|
307
|
+
})
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
fn set_session_env(
|
|
311
|
+
&self,
|
|
312
|
+
_session: &SessionName,
|
|
313
|
+
_key: &str,
|
|
314
|
+
_value: &str,
|
|
315
|
+
) -> Result<SetEnvOutcome, TransportError> {
|
|
316
|
+
Ok(SetEnvOutcome::Applied)
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
fn kill_window(&self, _target: &Target) -> Result<(), TransportError> {
|
|
320
|
+
Ok(())
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
fn attach_session(&self, _session: &SessionName) -> Result<AttachOutcome, TransportError> {
|
|
324
|
+
Ok(AttachOutcome::Attached)
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
#[derive(Clone, Default)]
|
|
329
|
+
struct LaunchPaneIdTransport {
|
|
330
|
+
spawns: Arc<Mutex<Vec<SpawnRecord>>>,
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
impl LaunchPaneIdTransport {
|
|
334
|
+
fn new() -> Self {
|
|
335
|
+
Self::default()
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
impl Transport for LaunchPaneIdTransport {
|
|
340
|
+
fn kind(&self) -> BackendKind {
|
|
341
|
+
BackendKind::Tmux
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
fn spawn_first(
|
|
345
|
+
&self,
|
|
346
|
+
session: &SessionName,
|
|
347
|
+
window: &WindowName,
|
|
348
|
+
argv: &[String],
|
|
349
|
+
_cwd: &Path,
|
|
350
|
+
_env: &BTreeMap<String, String>,
|
|
351
|
+
) -> Result<SpawnResult, TransportError> {
|
|
352
|
+
self.spawns.lock().unwrap().push(SpawnRecord {
|
|
353
|
+
kind: "spawn_first".to_string(),
|
|
354
|
+
window: window.as_str().to_string(),
|
|
355
|
+
argv: argv.to_vec(),
|
|
356
|
+
});
|
|
357
|
+
Ok(SpawnResult {
|
|
358
|
+
pane_id: PaneId::new("%0"),
|
|
359
|
+
session: session.clone(),
|
|
360
|
+
window: window.clone(),
|
|
361
|
+
child_pid: None,
|
|
362
|
+
})
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
fn spawn_into(
|
|
366
|
+
&self,
|
|
367
|
+
session: &SessionName,
|
|
368
|
+
window: &WindowName,
|
|
369
|
+
argv: &[String],
|
|
370
|
+
_cwd: &Path,
|
|
371
|
+
_env: &BTreeMap<String, String>,
|
|
372
|
+
) -> Result<SpawnResult, TransportError> {
|
|
373
|
+
self.spawns.lock().unwrap().push(SpawnRecord {
|
|
374
|
+
kind: "spawn_into".to_string(),
|
|
375
|
+
window: window.as_str().to_string(),
|
|
376
|
+
argv: argv.to_vec(),
|
|
377
|
+
});
|
|
378
|
+
Ok(SpawnResult {
|
|
379
|
+
pane_id: PaneId::new("%1"),
|
|
380
|
+
session: session.clone(),
|
|
381
|
+
window: window.clone(),
|
|
382
|
+
child_pid: None,
|
|
383
|
+
})
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
fn has_session(&self, _session: &SessionName) -> Result<bool, TransportError> {
|
|
387
|
+
Ok(false)
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
fn list_targets(&self) -> Result<Vec<PaneInfo>, TransportError> {
|
|
391
|
+
Ok(Vec::new())
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
fn list_windows(&self, session: &SessionName) -> Result<Vec<WindowName>, TransportError> {
|
|
395
|
+
let _ = session;
|
|
396
|
+
Ok(self
|
|
397
|
+
.spawns
|
|
398
|
+
.lock()
|
|
399
|
+
.unwrap()
|
|
400
|
+
.iter()
|
|
401
|
+
.map(|record| WindowName::new(record.window.as_str()))
|
|
402
|
+
.collect())
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
fn query(&self, _target: &Target, field: PaneField) -> Result<Option<String>, TransportError> {
|
|
406
|
+
Ok(match field {
|
|
407
|
+
PaneField::PaneId => Some("%0".to_string()),
|
|
408
|
+
PaneField::SessionName => Some("team-ctxteam".to_string()),
|
|
409
|
+
_ => None,
|
|
410
|
+
})
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
fn liveness(&self, _pane: &PaneId) -> Result<PaneLiveness, TransportError> {
|
|
414
|
+
Ok(PaneLiveness::Live)
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
fn inject(
|
|
418
|
+
&self,
|
|
419
|
+
_target: &Target,
|
|
420
|
+
_payload: &InjectPayload,
|
|
421
|
+
_submit: Key,
|
|
422
|
+
_bracketed: bool,
|
|
423
|
+
) -> Result<InjectReport, TransportError> {
|
|
424
|
+
Ok(inject_report())
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
fn send_keys(&self, _target: &Target, _keys: &[Key]) -> Result<(), TransportError> {
|
|
428
|
+
Ok(())
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
fn capture(
|
|
432
|
+
&self,
|
|
433
|
+
_target: &Target,
|
|
434
|
+
range: CaptureRange,
|
|
435
|
+
) -> Result<CapturedText, TransportError> {
|
|
436
|
+
Ok(CapturedText {
|
|
437
|
+
text: String::new(),
|
|
438
|
+
range,
|
|
439
|
+
})
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
fn set_session_env(
|
|
443
|
+
&self,
|
|
444
|
+
_session: &SessionName,
|
|
445
|
+
_key: &str,
|
|
446
|
+
_value: &str,
|
|
447
|
+
) -> Result<SetEnvOutcome, TransportError> {
|
|
448
|
+
Ok(SetEnvOutcome::Applied)
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
fn kill_session(&self, _session: &SessionName) -> Result<(), TransportError> {
|
|
452
|
+
Ok(())
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
fn kill_window(&self, _target: &Target) -> Result<(), TransportError> {
|
|
456
|
+
Ok(())
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
fn attach_session(&self, _session: &SessionName) -> Result<AttachOutcome, TransportError> {
|
|
460
|
+
Ok(AttachOutcome::Attached)
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
fn inject_report() -> InjectReport {
|
|
465
|
+
InjectReport {
|
|
466
|
+
stage_reached: InjectStage::Submit,
|
|
467
|
+
inject_verification: InjectVerification::NoToken,
|
|
468
|
+
submit_verification: SubmitVerification::EnterSentWithoutPlaceholderCheck,
|
|
469
|
+
turn_verification: TurnVerification::NotRequired,
|
|
470
|
+
attempts: 1,
|
|
471
|
+
submit_diagnostics: None,
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
struct RestartFixture {
|
|
476
|
+
root: PathBuf,
|
|
477
|
+
team: PathBuf,
|
|
478
|
+
agents: Vec<String>,
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
impl RestartFixture {
|
|
482
|
+
fn new(tag: &str, agents: &[&str]) -> Self {
|
|
483
|
+
let root = tmp_dir(tag);
|
|
484
|
+
let team = root.join("teamdir");
|
|
485
|
+
std::fs::create_dir_all(team.join("agents")).unwrap();
|
|
486
|
+
std::fs::write(
|
|
487
|
+
team.join("TEAM.md"),
|
|
488
|
+
"---\nname: ctxteam\nobjective: Restart liveness contract.\nprovider: codex\n---\n\nTeam.\n",
|
|
489
|
+
)
|
|
490
|
+
.unwrap();
|
|
491
|
+
for agent in agents {
|
|
492
|
+
std::fs::write(
|
|
493
|
+
team.join("agents").join(format!("{agent}.md")),
|
|
494
|
+
format!(
|
|
495
|
+
"---\nname: {agent}\nrole: Worker {agent}\nprovider: codex\nmodel: gpt-5.5\nauth_mode: subscription\ntools:\n - mcp_team\n---\n\nWorker.\n"
|
|
496
|
+
),
|
|
497
|
+
)
|
|
498
|
+
.unwrap();
|
|
499
|
+
}
|
|
500
|
+
let spec = team_agent::compiler::compile_team(&team).unwrap();
|
|
501
|
+
std::fs::write(
|
|
502
|
+
team.join("team.spec.yaml"),
|
|
503
|
+
team_agent::model::yaml::dumps(&spec),
|
|
504
|
+
)
|
|
505
|
+
.unwrap();
|
|
506
|
+
Self {
|
|
507
|
+
root,
|
|
508
|
+
team,
|
|
509
|
+
agents: agents.iter().map(|agent| (*agent).to_string()).collect(),
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
fn seed_resumable_state_with_stale_receiver(&self) {
|
|
514
|
+
let agents = self
|
|
515
|
+
.agents
|
|
516
|
+
.iter()
|
|
517
|
+
.map(|agent| {
|
|
518
|
+
(
|
|
519
|
+
agent.clone(),
|
|
520
|
+
json!({
|
|
521
|
+
"status": "running",
|
|
522
|
+
"provider": "codex",
|
|
523
|
+
"role": format!("Worker {agent}"),
|
|
524
|
+
"tools": ["mcp_team"],
|
|
525
|
+
"window": agent,
|
|
526
|
+
"owner_team_id": "ctxteam",
|
|
527
|
+
"session_id": format!("session-{agent}"),
|
|
528
|
+
"rollout_path": self.root.join(format!("{agent}.jsonl")).to_string_lossy().to_string(),
|
|
529
|
+
"spawn_cwd": self.team.to_string_lossy().to_string(),
|
|
530
|
+
"spawned_at": "2026-06-08T00:00:00+00:00",
|
|
531
|
+
"first_send_at": "2026-06-08T00:01:00+00:00"
|
|
532
|
+
}),
|
|
533
|
+
)
|
|
534
|
+
})
|
|
535
|
+
.collect::<serde_json::Map<_, _>>();
|
|
536
|
+
for agent in &self.agents {
|
|
537
|
+
std::fs::write(self.root.join(format!("{agent}.jsonl")), "{}\n").unwrap();
|
|
538
|
+
}
|
|
539
|
+
save_runtime_state(
|
|
540
|
+
&self.team,
|
|
541
|
+
&json!({
|
|
542
|
+
"active_team_key": "ctxteam",
|
|
543
|
+
"team_dir": self.team.to_string_lossy().to_string(),
|
|
544
|
+
"spec_path": self.team.join("team.spec.yaml").to_string_lossy().to_string(),
|
|
545
|
+
"session_name": "team-ctxteam",
|
|
546
|
+
"leader_receiver": {
|
|
547
|
+
"mode": "direct_tmux",
|
|
548
|
+
"status": "attached",
|
|
549
|
+
"pane_id": "%leader",
|
|
550
|
+
"provider": "claude",
|
|
551
|
+
"owner_epoch": 7
|
|
552
|
+
},
|
|
553
|
+
"agents": agents
|
|
554
|
+
}),
|
|
555
|
+
)
|
|
556
|
+
.unwrap();
|
|
557
|
+
seed_healthy_coordinator(&self.team);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
fn install_fake_codex_that_exits_alpha_resume(&self) -> PathBuf {
|
|
561
|
+
let bin = self.root.join("fake-bin");
|
|
562
|
+
std::fs::create_dir_all(&bin).unwrap();
|
|
563
|
+
let script = bin.join("codex");
|
|
564
|
+
std::fs::write(
|
|
565
|
+
&script,
|
|
566
|
+
r#"#!/bin/sh
|
|
567
|
+
echo "$@" >> "${CODEX_FAKE_LOG:-/tmp/team-agent-fake-codex.log}"
|
|
568
|
+
case "$*" in
|
|
569
|
+
*session-alpha*) exit 0 ;;
|
|
570
|
+
*) sleep 30 ;;
|
|
571
|
+
esac
|
|
572
|
+
"#,
|
|
573
|
+
)
|
|
574
|
+
.unwrap();
|
|
575
|
+
#[cfg(unix)]
|
|
576
|
+
{
|
|
577
|
+
use std::os::unix::fs::PermissionsExt;
|
|
578
|
+
std::fs::set_permissions(&script, std::fs::Permissions::from_mode(0o755)).unwrap();
|
|
579
|
+
}
|
|
580
|
+
bin
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
struct TmuxCleanup {
|
|
585
|
+
workspace: PathBuf,
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
impl TmuxCleanup {
|
|
589
|
+
fn new(workspace: &Path) -> Self {
|
|
590
|
+
Self {
|
|
591
|
+
workspace: workspace.to_path_buf(),
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
impl Drop for TmuxCleanup {
|
|
597
|
+
fn drop(&mut self) {
|
|
598
|
+
TmuxBackend::for_workspace(&self.workspace).kill_server();
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
fn seed_healthy_coordinator(workspace: &Path) {
|
|
603
|
+
let workspace = team_agent::coordinator::WorkspacePath::new(workspace.to_path_buf());
|
|
604
|
+
std::fs::create_dir_all(team_agent::model::paths::runtime_dir(workspace.as_path())).unwrap();
|
|
605
|
+
let _ = team_agent::message_store::MessageStore::open(workspace.as_path()).unwrap();
|
|
606
|
+
let pid = team_agent::coordinator::Pid::new(std::process::id());
|
|
607
|
+
team_agent::coordinator::write_coordinator_metadata(
|
|
608
|
+
&workspace,
|
|
609
|
+
pid,
|
|
610
|
+
team_agent::coordinator::MetadataSource::Boot,
|
|
611
|
+
)
|
|
612
|
+
.unwrap();
|
|
613
|
+
std::fs::write(
|
|
614
|
+
team_agent::coordinator::coordinator_pid_path(&workspace),
|
|
615
|
+
pid.to_string(),
|
|
616
|
+
)
|
|
617
|
+
.unwrap();
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
fn tmp_dir(tag: &str) -> PathBuf {
|
|
621
|
+
static N: AtomicU64 = AtomicU64::new(0);
|
|
622
|
+
let dir = std::env::temp_dir().join(format!(
|
|
623
|
+
"ta-rs-{tag}-{}-{}",
|
|
624
|
+
std::process::id(),
|
|
625
|
+
N.fetch_add(1, Ordering::Relaxed)
|
|
626
|
+
));
|
|
627
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
628
|
+
std::fs::create_dir_all(&dir).unwrap();
|
|
629
|
+
std::fs::canonicalize(dir).unwrap()
|
|
630
|
+
}
|