@team-agent/installer 0.5.61 → 0.5.62
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 +6 -5
- 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 +0 -9
- 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 -42
- package/crates/team-agent/src/coordinator/tick.rs +24 -28
- 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 -3
- 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 -11
- 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 -0
- 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,910 @@
|
|
|
1
|
+
//! 0.5.40 RED contract: restart builds replacement workers before destroying
|
|
2
|
+
//! the live worker session.
|
|
3
|
+
//!
|
|
4
|
+
//! Reference: `.team/artifacts/tmux-server-death-locate.md` §7 Slice 3.
|
|
5
|
+
|
|
6
|
+
#![cfg(unix)]
|
|
7
|
+
#![allow(clippy::expect_used, clippy::panic, clippy::unwrap_used)]
|
|
8
|
+
|
|
9
|
+
#[path = "../../../tests/support/hermetic.rs"]
|
|
10
|
+
mod hermetic_guard;
|
|
11
|
+
#[allow(dead_code)]
|
|
12
|
+
fn _hermetic_boundary_marker(_: &hermetic_guard::HermeticTestEnv) {}
|
|
13
|
+
|
|
14
|
+
use std::collections::{BTreeMap, BTreeSet};
|
|
15
|
+
use std::fs;
|
|
16
|
+
use std::path::{Path, PathBuf};
|
|
17
|
+
use std::process::Command;
|
|
18
|
+
use std::sync::{Arc, Mutex};
|
|
19
|
+
|
|
20
|
+
use serde_json::{json, Value};
|
|
21
|
+
use serial_test::serial;
|
|
22
|
+
use team_agent::coordinator::{MetadataSource, Pid, WorkspacePath};
|
|
23
|
+
use team_agent::event_log::EventLog;
|
|
24
|
+
use team_agent::lifecycle::{
|
|
25
|
+
restart_with_transport, restart_with_transport_with_readiness_deadline, RestartReport,
|
|
26
|
+
};
|
|
27
|
+
use team_agent::message_store::MessageStore;
|
|
28
|
+
use team_agent::model::paths::{runtime_dir, runtime_spec_path};
|
|
29
|
+
use team_agent::state::persist::{load_runtime_state, save_runtime_state};
|
|
30
|
+
use team_agent::transport::{
|
|
31
|
+
AttachOutcome, BackendKind, CaptureRange, CapturedText, InjectPayload, InjectReport,
|
|
32
|
+
InjectStage, InjectVerification, Key, PaneField, PaneId, PaneInfo, PaneLiveness, SessionName,
|
|
33
|
+
SetEnvOutcome, SpawnResult, SubmitVerification, Target, Transport, TransportError,
|
|
34
|
+
TurnVerification, WindowName,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const TEAM: &str = "current";
|
|
38
|
+
const TEAM_SESSION: &str = "team-current";
|
|
39
|
+
const TMUX_ENDPOINT: &str = "/Volumes/nvme/tmp/ta-0540-build-before-destroy.sock";
|
|
40
|
+
|
|
41
|
+
#[test]
|
|
42
|
+
#[serial(env)]
|
|
43
|
+
fn recording_restart_failure_does_not_kill_live_session_before_replacement_is_viable() {
|
|
44
|
+
let case = RestartCase::new(
|
|
45
|
+
"recording-no-teardown-first",
|
|
46
|
+
worker_ids(3),
|
|
47
|
+
ProviderShape::Fake,
|
|
48
|
+
);
|
|
49
|
+
let transport = BuildBeforeDestroyTransport::recording(worker_ids(3))
|
|
50
|
+
.with_spawn_failure("w1", "injected replacement spawn failure");
|
|
51
|
+
|
|
52
|
+
let report = restart_with_transport(&case.workspace, true, Some(TEAM), &transport)
|
|
53
|
+
.expect("restart should return a typed report");
|
|
54
|
+
|
|
55
|
+
assert_restart_did_not_succeed(&report);
|
|
56
|
+
assert_no_original_session_kill(
|
|
57
|
+
&transport.ops(),
|
|
58
|
+
"R1: restart must not destroy the live worker session before a replacement cohort is minimally viable",
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
#[test]
|
|
63
|
+
#[serial(env)]
|
|
64
|
+
fn real_tmux_restart_failure_keeps_original_session_windows_and_panes_injectable() {
|
|
65
|
+
let case =
|
|
66
|
+
RestartCase::new_unseeded("real-tmux-preserve-old", worker_ids(3), ProviderShape::Fake);
|
|
67
|
+
let tmux = RealTmuxTeam::start(case.env.root(), worker_ids(3));
|
|
68
|
+
case.seed_state_with_panes(ProviderShape::Fake, &tmux.panes_by_worker());
|
|
69
|
+
let transport = BuildBeforeDestroyTransport::real_tmux(tmux.socket.clone(), worker_ids(3))
|
|
70
|
+
.with_spawn_failure("w1", "injected replacement spawn failure");
|
|
71
|
+
|
|
72
|
+
let result = restart_with_transport_with_readiness_deadline(
|
|
73
|
+
&case.workspace,
|
|
74
|
+
true,
|
|
75
|
+
Some(TEAM),
|
|
76
|
+
&transport,
|
|
77
|
+
Some(1),
|
|
78
|
+
);
|
|
79
|
+
if let Ok(report) = result.as_ref() {
|
|
80
|
+
assert_restart_did_not_succeed(report);
|
|
81
|
+
}
|
|
82
|
+
tmux.assert_original_windows_present(&["w1", "w2", "w3"]);
|
|
83
|
+
tmux.assert_original_panes_injectable("TA0540_ORIGINAL_PANE_STILL_INJECTABLE");
|
|
84
|
+
assert_no_original_session_kill(
|
|
85
|
+
&transport.ops(),
|
|
86
|
+
"R2: even with real tmux, a failed replacement spawn must leave the original session untouched",
|
|
87
|
+
);
|
|
88
|
+
assert!(
|
|
89
|
+
result.is_ok(),
|
|
90
|
+
"R2: failed replacement build should return a typed failed/refused report after preserving the original session, not an unstructured readiness error; result={result:?}"
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
#[test]
|
|
95
|
+
#[serial(env)]
|
|
96
|
+
fn server_exited_during_replacement_spawn_does_not_cascade_session_disappeared_against_old_team() {
|
|
97
|
+
let case = RestartCase::new(
|
|
98
|
+
"case-b-no-second-cascade",
|
|
99
|
+
worker_ids(2),
|
|
100
|
+
ProviderShape::CodexResumable,
|
|
101
|
+
);
|
|
102
|
+
let transport =
|
|
103
|
+
BuildBeforeDestroyTransport::recording(worker_ids(2)).with_server_exit_after_first_spawn();
|
|
104
|
+
|
|
105
|
+
let report = restart_with_transport(&case.workspace, false, Some(TEAM), &transport)
|
|
106
|
+
.expect("restart should return a typed report");
|
|
107
|
+
|
|
108
|
+
assert_restart_did_not_succeed(&report);
|
|
109
|
+
let report_text = format!("{report:?}");
|
|
110
|
+
let events = case.events_text();
|
|
111
|
+
assert!(
|
|
112
|
+
!report_text.contains("session_disappeared_after_spawn")
|
|
113
|
+
&& !events.contains("session_disappeared_after_spawn"),
|
|
114
|
+
"R3: server_exited during replacement build should return failed/refused directly, not a second session_disappeared_after_spawn cascade; report={report_text} events={events}"
|
|
115
|
+
);
|
|
116
|
+
assert_no_original_session_kill(
|
|
117
|
+
&transport.ops(),
|
|
118
|
+
"R3: server_exited during replacement build must not first destroy the original session",
|
|
119
|
+
);
|
|
120
|
+
let state = case.read_state();
|
|
121
|
+
assert_eq!(
|
|
122
|
+
state.pointer("/agents/w1/status").and_then(Value::as_str),
|
|
123
|
+
Some("running"),
|
|
124
|
+
"R3: failed replacement build must leave old worker state authoritative; state={state}"
|
|
125
|
+
);
|
|
126
|
+
assert_eq!(
|
|
127
|
+
state.pointer("/agents/w1/pane_id").and_then(Value::as_str),
|
|
128
|
+
Some("%old-w1"),
|
|
129
|
+
"R3: failed replacement build must not overwrite the old worker pane binding; state={state}"
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
struct RestartCase {
|
|
134
|
+
env: hermetic_guard::HermeticTestEnv,
|
|
135
|
+
workspace: PathBuf,
|
|
136
|
+
workers: Vec<String>,
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
impl RestartCase {
|
|
140
|
+
fn new(tag: &str, workers: Vec<String>, provider: ProviderShape) -> Self {
|
|
141
|
+
let case = Self::new_unseeded(tag, workers, provider);
|
|
142
|
+
let panes = case
|
|
143
|
+
.workers
|
|
144
|
+
.iter()
|
|
145
|
+
.map(|worker| (worker.clone(), format!("%old-{worker}")))
|
|
146
|
+
.collect::<BTreeMap<_, _>>();
|
|
147
|
+
case.seed_state_with_panes(provider, &panes);
|
|
148
|
+
case
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
fn new_unseeded(tag: &str, workers: Vec<String>, provider: ProviderShape) -> Self {
|
|
152
|
+
let env = hermetic_guard::HermeticTestEnv::enter(tag);
|
|
153
|
+
env.scrub_tmux();
|
|
154
|
+
env.assert_no_real_tmux();
|
|
155
|
+
let workspace = env.workspace(tag);
|
|
156
|
+
write_team_docs(&workspace, &workers, provider);
|
|
157
|
+
write_runtime_spec(&workspace, &workspace);
|
|
158
|
+
Self {
|
|
159
|
+
env,
|
|
160
|
+
workspace,
|
|
161
|
+
workers,
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
fn seed_state_with_panes(&self, provider: ProviderShape, panes: &BTreeMap<String, String>) {
|
|
166
|
+
seed_restart_state(&self.workspace, &self.workers, provider, panes);
|
|
167
|
+
seed_healthy_coordinator(&self.workspace);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
fn read_state(&self) -> Value {
|
|
171
|
+
load_runtime_state(&self.workspace).expect("load runtime state")
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
fn events_text(&self) -> String {
|
|
175
|
+
EventLog::new(&self.workspace)
|
|
176
|
+
.tail(0)
|
|
177
|
+
.expect("read events")
|
|
178
|
+
.into_iter()
|
|
179
|
+
.map(|event| event.to_string())
|
|
180
|
+
.collect::<Vec<_>>()
|
|
181
|
+
.join("\n")
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
#[derive(Clone, Copy)]
|
|
186
|
+
enum ProviderShape {
|
|
187
|
+
Fake,
|
|
188
|
+
CodexResumable,
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
impl ProviderShape {
|
|
192
|
+
fn provider(self) -> &'static str {
|
|
193
|
+
match self {
|
|
194
|
+
Self::Fake => "fake",
|
|
195
|
+
Self::CodexResumable => "codex",
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
fn model(self) -> &'static str {
|
|
200
|
+
match self {
|
|
201
|
+
Self::Fake => "fake",
|
|
202
|
+
Self::CodexResumable => "gpt-5.5",
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
fn write_team_docs(team_dir: &Path, workers: &[String], provider: ProviderShape) {
|
|
208
|
+
fs::create_dir_all(team_dir.join("agents")).expect("create agents dir");
|
|
209
|
+
fs::write(
|
|
210
|
+
team_dir.join("TEAM.md"),
|
|
211
|
+
format!(
|
|
212
|
+
"---\nname: {TEAM}\nobjective: Restart build-before-destroy contract.\nprovider: {}\n---\n\nTeam.\n",
|
|
213
|
+
provider.provider()
|
|
214
|
+
),
|
|
215
|
+
)
|
|
216
|
+
.expect("write TEAM.md");
|
|
217
|
+
for worker in workers {
|
|
218
|
+
fs::write(
|
|
219
|
+
team_dir.join("agents").join(format!("{worker}.md")),
|
|
220
|
+
format!(
|
|
221
|
+
"---\nname: {worker}\nrole: Worker {worker}\nprovider: {}\nmodel: {}\nauth_mode: subscription\ntools:\n - mcp_team\n---\n\n{worker}.\n",
|
|
222
|
+
provider.provider(),
|
|
223
|
+
provider.model()
|
|
224
|
+
),
|
|
225
|
+
)
|
|
226
|
+
.expect("write role doc");
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
fn write_runtime_spec(workspace: &Path, team_dir: &Path) {
|
|
231
|
+
let spec = team_agent::compiler::compile_team(team_dir).expect("compile team");
|
|
232
|
+
let spec_text = team_agent::model::yaml::dumps(&spec);
|
|
233
|
+
fs::write(team_dir.join("team.spec.yaml"), &spec_text).expect("write legacy spec");
|
|
234
|
+
let runtime_spec = runtime_spec_path(workspace, TEAM);
|
|
235
|
+
fs::create_dir_all(runtime_spec.parent().expect("runtime spec parent"))
|
|
236
|
+
.expect("create runtime spec dir");
|
|
237
|
+
fs::write(runtime_spec, spec_text).expect("write runtime spec");
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
fn seed_restart_state(
|
|
241
|
+
workspace: &Path,
|
|
242
|
+
workers: &[String],
|
|
243
|
+
provider: ProviderShape,
|
|
244
|
+
panes: &BTreeMap<String, String>,
|
|
245
|
+
) {
|
|
246
|
+
let agents = workers
|
|
247
|
+
.iter()
|
|
248
|
+
.map(|worker| {
|
|
249
|
+
let mut row = json!({
|
|
250
|
+
"status": "running",
|
|
251
|
+
"provider": provider.provider(),
|
|
252
|
+
"agent_id": worker,
|
|
253
|
+
"role": format!("Worker {worker}"),
|
|
254
|
+
"model": provider.model(),
|
|
255
|
+
"auth_mode": "subscription",
|
|
256
|
+
"tools": ["mcp_team"],
|
|
257
|
+
"window": worker,
|
|
258
|
+
"pane_id": panes.get(worker).cloned().unwrap_or_else(|| format!("%old-{worker}")),
|
|
259
|
+
"owner_team_id": TEAM,
|
|
260
|
+
"spawn_epoch": 0,
|
|
261
|
+
"spawn_cwd": workspace.to_string_lossy(),
|
|
262
|
+
"spawned_at": "2026-07-14T00:00:00+00:00",
|
|
263
|
+
});
|
|
264
|
+
if matches!(provider, ProviderShape::CodexResumable) {
|
|
265
|
+
let rollout = workspace.join(format!("{worker}.jsonl"));
|
|
266
|
+
fs::write(&rollout, "{}\n").expect("write rollout fixture");
|
|
267
|
+
let row_obj = row.as_object_mut().expect("agent row object");
|
|
268
|
+
row_obj.insert("session_id".to_string(), json!(format!("session-{worker}")));
|
|
269
|
+
row_obj.insert(
|
|
270
|
+
"rollout_path".to_string(),
|
|
271
|
+
json!(rollout.to_string_lossy().to_string()),
|
|
272
|
+
);
|
|
273
|
+
row_obj.insert(
|
|
274
|
+
"first_send_at".to_string(),
|
|
275
|
+
json!("2026-07-14T00:01:00+00:00"),
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
(worker.clone(), row)
|
|
279
|
+
})
|
|
280
|
+
.collect::<serde_json::Map<String, Value>>();
|
|
281
|
+
let spec_path = runtime_spec_path(workspace, TEAM);
|
|
282
|
+
save_runtime_state(
|
|
283
|
+
workspace,
|
|
284
|
+
&json!({
|
|
285
|
+
"active_team_key": TEAM,
|
|
286
|
+
"team_key": TEAM,
|
|
287
|
+
"workspace": workspace.to_string_lossy(),
|
|
288
|
+
"team_dir": workspace.to_string_lossy(),
|
|
289
|
+
"spec_path": spec_path.to_string_lossy(),
|
|
290
|
+
"session_name": TEAM_SESSION,
|
|
291
|
+
"tmux_endpoint": TMUX_ENDPOINT,
|
|
292
|
+
"tmux_socket": TMUX_ENDPOINT,
|
|
293
|
+
"agents": Value::Object(agents.clone()),
|
|
294
|
+
"teams": {
|
|
295
|
+
TEAM: {
|
|
296
|
+
"team_key": TEAM,
|
|
297
|
+
"workspace": workspace.to_string_lossy(),
|
|
298
|
+
"team_dir": workspace.to_string_lossy(),
|
|
299
|
+
"spec_path": spec_path.to_string_lossy(),
|
|
300
|
+
"session_name": TEAM_SESSION,
|
|
301
|
+
"tmux_endpoint": TMUX_ENDPOINT,
|
|
302
|
+
"tmux_socket": TMUX_ENDPOINT,
|
|
303
|
+
"agents": Value::Object(agents),
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}),
|
|
307
|
+
)
|
|
308
|
+
.expect("seed runtime state");
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
fn seed_healthy_coordinator(workspace: &Path) {
|
|
312
|
+
fs::create_dir_all(runtime_dir(workspace)).expect("create runtime dir");
|
|
313
|
+
let _store = MessageStore::open(workspace).expect("create message store schema");
|
|
314
|
+
let wp = WorkspacePath::new(workspace.to_path_buf());
|
|
315
|
+
let pid = Pid::new(std::process::id());
|
|
316
|
+
team_agent::coordinator::write_coordinator_metadata(&wp, pid, MetadataSource::Boot)
|
|
317
|
+
.expect("write coordinator metadata");
|
|
318
|
+
fs::write(
|
|
319
|
+
team_agent::coordinator::coordinator_pid_path(&wp),
|
|
320
|
+
pid.to_string(),
|
|
321
|
+
)
|
|
322
|
+
.expect("write coordinator pid");
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
fn worker_ids(count: usize) -> Vec<String> {
|
|
326
|
+
(1..=count).map(|index| format!("w{index}")).collect()
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
fn assert_restart_did_not_succeed(report: &RestartReport) {
|
|
330
|
+
assert!(
|
|
331
|
+
!matches!(report, RestartReport::Restarted { .. }),
|
|
332
|
+
"fixture injects replacement failure; restart must not report success: {report:?}"
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
fn assert_no_original_session_kill(ops: &[String], context: &str) {
|
|
337
|
+
let forbidden = format!("kill_session:{TEAM_SESSION}");
|
|
338
|
+
assert!(
|
|
339
|
+
!ops.iter().any(|op| op == &forbidden),
|
|
340
|
+
"{context}; ops={ops:?}"
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
#[derive(Clone)]
|
|
345
|
+
struct BuildBeforeDestroyTransport {
|
|
346
|
+
state: Arc<Mutex<TransportState>>,
|
|
347
|
+
real_socket: Option<PathBuf>,
|
|
348
|
+
fail_agent: Option<String>,
|
|
349
|
+
server_exit_after_first_spawn: bool,
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
#[derive(Default)]
|
|
353
|
+
struct TransportState {
|
|
354
|
+
session_present: bool,
|
|
355
|
+
ops: Vec<String>,
|
|
356
|
+
panes: BTreeMap<String, PaneInfo>,
|
|
357
|
+
next_pane: usize,
|
|
358
|
+
spawns: usize,
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
impl BuildBeforeDestroyTransport {
|
|
362
|
+
fn recording(workers: Vec<String>) -> Self {
|
|
363
|
+
Self {
|
|
364
|
+
state: Arc::new(Mutex::new(TransportState {
|
|
365
|
+
session_present: true,
|
|
366
|
+
panes: pane_infos_from_ids(
|
|
367
|
+
workers
|
|
368
|
+
.into_iter()
|
|
369
|
+
.map(|worker| (worker.clone(), format!("%old-{worker}")))
|
|
370
|
+
.collect(),
|
|
371
|
+
),
|
|
372
|
+
next_pane: 1,
|
|
373
|
+
..TransportState::default()
|
|
374
|
+
})),
|
|
375
|
+
real_socket: None,
|
|
376
|
+
fail_agent: None,
|
|
377
|
+
server_exit_after_first_spawn: false,
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
fn real_tmux(socket: PathBuf, workers: Vec<String>) -> Self {
|
|
382
|
+
Self {
|
|
383
|
+
state: Arc::new(Mutex::new(TransportState {
|
|
384
|
+
session_present: true,
|
|
385
|
+
panes: pane_infos_from_ids(
|
|
386
|
+
workers
|
|
387
|
+
.into_iter()
|
|
388
|
+
.map(|worker| (worker.clone(), format!("%old-{worker}")))
|
|
389
|
+
.collect(),
|
|
390
|
+
),
|
|
391
|
+
next_pane: 1,
|
|
392
|
+
..TransportState::default()
|
|
393
|
+
})),
|
|
394
|
+
real_socket: Some(socket),
|
|
395
|
+
fail_agent: None,
|
|
396
|
+
server_exit_after_first_spawn: false,
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
fn with_spawn_failure(mut self, agent: &str, message: &str) -> Self {
|
|
401
|
+
self.fail_agent = Some(format!("{agent}:{message}"));
|
|
402
|
+
self
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
fn with_server_exit_after_first_spawn(mut self) -> Self {
|
|
406
|
+
self.server_exit_after_first_spawn = true;
|
|
407
|
+
self
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
fn ops(&self) -> Vec<String> {
|
|
411
|
+
self.state.lock().unwrap().ops.clone()
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
fn spawn(
|
|
415
|
+
&self,
|
|
416
|
+
kind: &'static str,
|
|
417
|
+
session: &SessionName,
|
|
418
|
+
window: &WindowName,
|
|
419
|
+
) -> Result<SpawnResult, TransportError> {
|
|
420
|
+
let mut state = self.state.lock().unwrap();
|
|
421
|
+
state
|
|
422
|
+
.ops
|
|
423
|
+
.push(format!("{kind}:{}:{}", session.as_str(), window.as_str()));
|
|
424
|
+
state.spawns += 1;
|
|
425
|
+
if let Some(failure) = self.fail_agent.as_deref() {
|
|
426
|
+
if failure.starts_with(&format!("{}:", window.as_str())) {
|
|
427
|
+
return Err(TransportError::Subprocess {
|
|
428
|
+
argv: vec!["tmux".to_string(), kind.to_string()],
|
|
429
|
+
code: Some(1),
|
|
430
|
+
stderr: failure.to_string(),
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
let pane_id = PaneId::new(format!("%new-{}", state.next_pane));
|
|
435
|
+
state.next_pane += 1;
|
|
436
|
+
state.session_present = true;
|
|
437
|
+
state.panes.insert(
|
|
438
|
+
pane_id.as_str().to_string(),
|
|
439
|
+
pane_info(session.clone(), window.clone(), pane_id.clone()),
|
|
440
|
+
);
|
|
441
|
+
if self.server_exit_after_first_spawn && state.spawns == 1 {
|
|
442
|
+
state.session_present = false;
|
|
443
|
+
}
|
|
444
|
+
Ok(SpawnResult {
|
|
445
|
+
pane_id,
|
|
446
|
+
session: session.clone(),
|
|
447
|
+
window: window.clone(),
|
|
448
|
+
child_pid: None,
|
|
449
|
+
})
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
fn real_tmux_has_session(&self, session: &SessionName) -> Result<bool, TransportError> {
|
|
453
|
+
let Some(socket) = self.real_socket.as_ref() else {
|
|
454
|
+
return Ok(self.state.lock().unwrap().session_present);
|
|
455
|
+
};
|
|
456
|
+
Ok(Command::new("tmux")
|
|
457
|
+
.args([
|
|
458
|
+
"-S",
|
|
459
|
+
socket.to_str().unwrap(),
|
|
460
|
+
"has-session",
|
|
461
|
+
"-t",
|
|
462
|
+
session.as_str(),
|
|
463
|
+
])
|
|
464
|
+
.output()
|
|
465
|
+
.map_err(|error| TransportError::MuxUnavailable {
|
|
466
|
+
backend: BackendKind::Tmux,
|
|
467
|
+
detail: error.to_string(),
|
|
468
|
+
})?
|
|
469
|
+
.status
|
|
470
|
+
.success())
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
fn real_tmux_list_panes(&self) -> Result<Vec<PaneInfo>, TransportError> {
|
|
474
|
+
let Some(socket) = self.real_socket.as_ref() else {
|
|
475
|
+
return Ok(self.state.lock().unwrap().panes.values().cloned().collect());
|
|
476
|
+
};
|
|
477
|
+
let output = Command::new("tmux")
|
|
478
|
+
.args([
|
|
479
|
+
"-S",
|
|
480
|
+
socket.to_str().unwrap(),
|
|
481
|
+
"list-panes",
|
|
482
|
+
"-a",
|
|
483
|
+
"-F",
|
|
484
|
+
"#{session_name}\t#{window_name}\t#{pane_id}\t#{pane_pid}",
|
|
485
|
+
])
|
|
486
|
+
.output()
|
|
487
|
+
.map_err(|error| TransportError::MuxUnavailable {
|
|
488
|
+
backend: BackendKind::Tmux,
|
|
489
|
+
detail: error.to_string(),
|
|
490
|
+
})?;
|
|
491
|
+
if !output.status.success() {
|
|
492
|
+
return Ok(Vec::new());
|
|
493
|
+
}
|
|
494
|
+
let text = String::from_utf8_lossy(&output.stdout);
|
|
495
|
+
Ok(text
|
|
496
|
+
.lines()
|
|
497
|
+
.filter_map(|line| {
|
|
498
|
+
let mut fields = line.split('\t');
|
|
499
|
+
let session = fields.next()?;
|
|
500
|
+
let window = fields.next()?;
|
|
501
|
+
let pane = fields.next()?;
|
|
502
|
+
let pid = fields.next().and_then(|raw| raw.parse::<u32>().ok());
|
|
503
|
+
Some(PaneInfo {
|
|
504
|
+
pane_id: PaneId::new(pane),
|
|
505
|
+
session: SessionName::new(session),
|
|
506
|
+
window_index: None,
|
|
507
|
+
window_name: Some(WindowName::new(window)),
|
|
508
|
+
pane_index: None,
|
|
509
|
+
tty: None,
|
|
510
|
+
current_command: None,
|
|
511
|
+
current_path: None,
|
|
512
|
+
active: true,
|
|
513
|
+
pane_pid: pid,
|
|
514
|
+
leader_env: BTreeMap::new(),
|
|
515
|
+
})
|
|
516
|
+
})
|
|
517
|
+
.collect())
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
impl Transport for BuildBeforeDestroyTransport {
|
|
522
|
+
fn kind(&self) -> BackendKind {
|
|
523
|
+
BackendKind::Tmux
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
fn tmux_endpoint(&self) -> Option<String> {
|
|
527
|
+
self.real_socket
|
|
528
|
+
.as_ref()
|
|
529
|
+
.map(|socket| socket.to_string_lossy().to_string())
|
|
530
|
+
.or_else(|| Some(TMUX_ENDPOINT.to_string()))
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
fn spawn_first(
|
|
534
|
+
&self,
|
|
535
|
+
session: &SessionName,
|
|
536
|
+
window: &WindowName,
|
|
537
|
+
_argv: &[String],
|
|
538
|
+
_cwd: &Path,
|
|
539
|
+
_env: &BTreeMap<String, String>,
|
|
540
|
+
) -> Result<SpawnResult, TransportError> {
|
|
541
|
+
self.spawn("spawn_first", session, window)
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
fn spawn_into(
|
|
545
|
+
&self,
|
|
546
|
+
session: &SessionName,
|
|
547
|
+
window: &WindowName,
|
|
548
|
+
_argv: &[String],
|
|
549
|
+
_cwd: &Path,
|
|
550
|
+
_env: &BTreeMap<String, String>,
|
|
551
|
+
) -> Result<SpawnResult, TransportError> {
|
|
552
|
+
self.spawn("spawn_into", session, window)
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
fn inject(
|
|
556
|
+
&self,
|
|
557
|
+
_target: &Target,
|
|
558
|
+
_payload: &InjectPayload,
|
|
559
|
+
_submit: Key,
|
|
560
|
+
_bracketed: bool,
|
|
561
|
+
) -> Result<InjectReport, TransportError> {
|
|
562
|
+
Ok(inject_report())
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
fn send_keys(&self, _target: &Target, _keys: &[Key]) -> Result<(), TransportError> {
|
|
566
|
+
Ok(())
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
fn capture(
|
|
570
|
+
&self,
|
|
571
|
+
_target: &Target,
|
|
572
|
+
range: CaptureRange,
|
|
573
|
+
) -> Result<CapturedText, TransportError> {
|
|
574
|
+
Ok(CapturedText {
|
|
575
|
+
text: String::new(),
|
|
576
|
+
range,
|
|
577
|
+
})
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
fn query(&self, _target: &Target, field: PaneField) -> Result<Option<String>, TransportError> {
|
|
581
|
+
Ok(match field {
|
|
582
|
+
PaneField::PaneId => Some("%new-1".to_string()),
|
|
583
|
+
PaneField::SessionName => Some(TEAM_SESSION.to_string()),
|
|
584
|
+
_ => None,
|
|
585
|
+
})
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
fn liveness(&self, pane: &PaneId) -> Result<PaneLiveness, TransportError> {
|
|
589
|
+
Ok(
|
|
590
|
+
if self
|
|
591
|
+
.real_tmux_list_panes()?
|
|
592
|
+
.iter()
|
|
593
|
+
.any(|info| info.pane_id.as_str() == pane.as_str())
|
|
594
|
+
|| self.state.lock().unwrap().panes.contains_key(pane.as_str())
|
|
595
|
+
{
|
|
596
|
+
PaneLiveness::Live
|
|
597
|
+
} else {
|
|
598
|
+
PaneLiveness::Dead
|
|
599
|
+
},
|
|
600
|
+
)
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
fn has_pane(&self, pane: &PaneId) -> Result<Option<bool>, TransportError> {
|
|
604
|
+
Ok(Some(
|
|
605
|
+
self.real_tmux_list_panes()?
|
|
606
|
+
.iter()
|
|
607
|
+
.any(|info| info.pane_id.as_str() == pane.as_str())
|
|
608
|
+
|| self.state.lock().unwrap().panes.contains_key(pane.as_str()),
|
|
609
|
+
))
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
fn list_targets(&self) -> Result<Vec<PaneInfo>, TransportError> {
|
|
613
|
+
self.real_tmux_list_panes()
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
fn has_session(&self, session: &SessionName) -> Result<bool, TransportError> {
|
|
617
|
+
let live = self.real_tmux_has_session(session)?;
|
|
618
|
+
self.state
|
|
619
|
+
.lock()
|
|
620
|
+
.unwrap()
|
|
621
|
+
.ops
|
|
622
|
+
.push(format!("has_session:{}={live}", session.as_str()));
|
|
623
|
+
Ok(live)
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
fn list_windows(&self, session: &SessionName) -> Result<Vec<WindowName>, TransportError> {
|
|
627
|
+
if self.real_socket.is_some() {
|
|
628
|
+
let mut windows = BTreeSet::new();
|
|
629
|
+
for pane in self.real_tmux_list_panes()? {
|
|
630
|
+
if pane.session.as_str() == session.as_str() {
|
|
631
|
+
if let Some(window) = pane.window_name {
|
|
632
|
+
windows.insert(window);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
return Ok(windows.into_iter().collect());
|
|
637
|
+
}
|
|
638
|
+
let state = self.state.lock().unwrap();
|
|
639
|
+
if !state.session_present {
|
|
640
|
+
return Ok(Vec::new());
|
|
641
|
+
}
|
|
642
|
+
let mut windows = BTreeSet::new();
|
|
643
|
+
for pane in state.panes.values() {
|
|
644
|
+
if let Some(window) = pane.window_name.as_ref() {
|
|
645
|
+
windows.insert(window.clone());
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
Ok(windows.into_iter().collect())
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
fn set_session_env(
|
|
652
|
+
&self,
|
|
653
|
+
_session: &SessionName,
|
|
654
|
+
_key: &str,
|
|
655
|
+
_value: &str,
|
|
656
|
+
) -> Result<SetEnvOutcome, TransportError> {
|
|
657
|
+
Ok(SetEnvOutcome::Applied)
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
fn kill_session(&self, session: &SessionName) -> Result<(), TransportError> {
|
|
661
|
+
self.state
|
|
662
|
+
.lock()
|
|
663
|
+
.unwrap()
|
|
664
|
+
.ops
|
|
665
|
+
.push(format!("kill_session:{}", session.as_str()));
|
|
666
|
+
if session.as_str() == TEAM_SESSION {
|
|
667
|
+
self.state.lock().unwrap().session_present = false;
|
|
668
|
+
self.state.lock().unwrap().panes.clear();
|
|
669
|
+
if let Some(socket) = self.real_socket.as_ref() {
|
|
670
|
+
let status = Command::new("tmux")
|
|
671
|
+
.args([
|
|
672
|
+
"-S",
|
|
673
|
+
socket.to_str().unwrap(),
|
|
674
|
+
"kill-session",
|
|
675
|
+
"-t",
|
|
676
|
+
session.as_str(),
|
|
677
|
+
])
|
|
678
|
+
.status()
|
|
679
|
+
.map_err(|error| TransportError::MuxUnavailable {
|
|
680
|
+
backend: BackendKind::Tmux,
|
|
681
|
+
detail: error.to_string(),
|
|
682
|
+
})?;
|
|
683
|
+
if !status.success() {
|
|
684
|
+
return Err(TransportError::Subprocess {
|
|
685
|
+
argv: vec![
|
|
686
|
+
"tmux".to_string(),
|
|
687
|
+
"-S".to_string(),
|
|
688
|
+
socket.to_string_lossy().to_string(),
|
|
689
|
+
"kill-session".to_string(),
|
|
690
|
+
"-t".to_string(),
|
|
691
|
+
session.as_str().to_string(),
|
|
692
|
+
],
|
|
693
|
+
code: status.code(),
|
|
694
|
+
stderr: "kill-session failed".to_string(),
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
Ok(())
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
fn kill_window(&self, target: &Target) -> Result<(), TransportError> {
|
|
703
|
+
if let Target::Pane(pane) = target {
|
|
704
|
+
self.state.lock().unwrap().panes.remove(pane.as_str());
|
|
705
|
+
}
|
|
706
|
+
Ok(())
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
fn attach_session(&self, _session: &SessionName) -> Result<AttachOutcome, TransportError> {
|
|
710
|
+
Ok(AttachOutcome::Attached)
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
fn pane_infos_from_ids(ids: BTreeMap<String, String>) -> BTreeMap<String, PaneInfo> {
|
|
715
|
+
ids.into_iter()
|
|
716
|
+
.map(|(worker, pane)| {
|
|
717
|
+
let pane_id = PaneId::new(pane);
|
|
718
|
+
(
|
|
719
|
+
pane_id.as_str().to_string(),
|
|
720
|
+
pane_info(
|
|
721
|
+
SessionName::new(TEAM_SESSION),
|
|
722
|
+
WindowName::new(worker),
|
|
723
|
+
pane_id,
|
|
724
|
+
),
|
|
725
|
+
)
|
|
726
|
+
})
|
|
727
|
+
.collect()
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
fn pane_info(session: SessionName, window: WindowName, pane_id: PaneId) -> PaneInfo {
|
|
731
|
+
PaneInfo {
|
|
732
|
+
pane_id,
|
|
733
|
+
session,
|
|
734
|
+
window_index: None,
|
|
735
|
+
window_name: Some(window),
|
|
736
|
+
pane_index: None,
|
|
737
|
+
tty: None,
|
|
738
|
+
current_command: Some("team-agent-worker".to_string()),
|
|
739
|
+
current_path: None,
|
|
740
|
+
active: true,
|
|
741
|
+
pane_pid: Some(10_000),
|
|
742
|
+
leader_env: BTreeMap::new(),
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
fn inject_report() -> InjectReport {
|
|
747
|
+
InjectReport {
|
|
748
|
+
stage_reached: InjectStage::Submit,
|
|
749
|
+
inject_verification: InjectVerification::NoToken,
|
|
750
|
+
submit_verification: SubmitVerification::EnterSentWithoutPlaceholderCheck,
|
|
751
|
+
turn_verification: TurnVerification::NotRequired,
|
|
752
|
+
attempts: 1,
|
|
753
|
+
submit_diagnostics: None,
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
struct RealTmuxTeam {
|
|
758
|
+
socket: PathBuf,
|
|
759
|
+
panes: BTreeMap<String, String>,
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
impl RealTmuxTeam {
|
|
763
|
+
fn start(root: &Path, workers: Vec<String>) -> Self {
|
|
764
|
+
// 0.5.43 debt-sweep (§4.2): use the short_tmux_socket helper
|
|
765
|
+
// so tests stay green when TMPDIR is macOS default
|
|
766
|
+
// /var/folders/... > 104 bytes. `root` is kept as the parameter
|
|
767
|
+
// shape but is intentionally unused now — the socket lives at
|
|
768
|
+
// /private/tmp/ta43-*.sock and its Drop cleans it up.
|
|
769
|
+
let _ = root;
|
|
770
|
+
let socket = hermetic_guard::short_tmux_socket("0540-real-tmux");
|
|
771
|
+
let _ = Command::new("tmux")
|
|
772
|
+
.args(["-S", socket.to_str().unwrap(), "kill-server"])
|
|
773
|
+
.output();
|
|
774
|
+
let mut iter = workers.into_iter();
|
|
775
|
+
let first = iter.next().expect("at least one worker");
|
|
776
|
+
run_tmux(
|
|
777
|
+
&socket,
|
|
778
|
+
&[
|
|
779
|
+
"new-session",
|
|
780
|
+
"-d",
|
|
781
|
+
"-s",
|
|
782
|
+
TEAM_SESSION,
|
|
783
|
+
"-n",
|
|
784
|
+
&first,
|
|
785
|
+
"while :; do sleep 60; done",
|
|
786
|
+
],
|
|
787
|
+
);
|
|
788
|
+
for worker in iter {
|
|
789
|
+
run_tmux(
|
|
790
|
+
&socket,
|
|
791
|
+
&[
|
|
792
|
+
"new-window",
|
|
793
|
+
"-t",
|
|
794
|
+
TEAM_SESSION,
|
|
795
|
+
"-n",
|
|
796
|
+
&worker,
|
|
797
|
+
"while :; do sleep 60; done",
|
|
798
|
+
],
|
|
799
|
+
);
|
|
800
|
+
}
|
|
801
|
+
let panes = list_tmux_panes_by_worker(&socket);
|
|
802
|
+
Self { socket, panes }
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
fn panes_by_worker(&self) -> BTreeMap<String, String> {
|
|
806
|
+
self.panes.clone()
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
fn assert_original_windows_present(&self, expected: &[&str]) {
|
|
810
|
+
let output = Command::new("tmux")
|
|
811
|
+
.args([
|
|
812
|
+
"-S",
|
|
813
|
+
self.socket.to_str().unwrap(),
|
|
814
|
+
"list-windows",
|
|
815
|
+
"-t",
|
|
816
|
+
TEAM_SESSION,
|
|
817
|
+
"-F",
|
|
818
|
+
"#{window_name}",
|
|
819
|
+
])
|
|
820
|
+
.output()
|
|
821
|
+
.expect("list real tmux windows");
|
|
822
|
+
assert!(
|
|
823
|
+
output.status.success(),
|
|
824
|
+
"original tmux session must still exist after failed restart; stderr={}",
|
|
825
|
+
String::from_utf8_lossy(&output.stderr)
|
|
826
|
+
);
|
|
827
|
+
let actual = String::from_utf8_lossy(&output.stdout)
|
|
828
|
+
.lines()
|
|
829
|
+
.map(str::to_string)
|
|
830
|
+
.collect::<BTreeSet<_>>();
|
|
831
|
+
for window in expected {
|
|
832
|
+
assert!(
|
|
833
|
+
actual.contains(*window),
|
|
834
|
+
"original tmux window `{window}` missing after failed restart; actual={actual:?}"
|
|
835
|
+
);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
fn assert_original_panes_injectable(&self, token: &str) {
|
|
840
|
+
for (worker, pane) in &self.panes {
|
|
841
|
+
let status = Command::new("tmux")
|
|
842
|
+
.args([
|
|
843
|
+
"-S",
|
|
844
|
+
self.socket.to_str().unwrap(),
|
|
845
|
+
"send-keys",
|
|
846
|
+
"-t",
|
|
847
|
+
pane,
|
|
848
|
+
&format!("printf {token}_{worker}"),
|
|
849
|
+
"Enter",
|
|
850
|
+
])
|
|
851
|
+
.status()
|
|
852
|
+
.expect("send keys to original pane");
|
|
853
|
+
assert!(
|
|
854
|
+
status.success(),
|
|
855
|
+
"original pane {pane} for {worker} must remain addressable/injectable"
|
|
856
|
+
);
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
impl Drop for RealTmuxTeam {
|
|
862
|
+
fn drop(&mut self) {
|
|
863
|
+
let _ = Command::new("tmux")
|
|
864
|
+
.args(["-S", self.socket.to_str().unwrap(), "kill-server"])
|
|
865
|
+
.output();
|
|
866
|
+
let _ = fs::remove_file(&self.socket);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
fn run_tmux(socket: &Path, args: &[&str]) {
|
|
871
|
+
let output = Command::new("tmux")
|
|
872
|
+
.arg("-S")
|
|
873
|
+
.arg(socket)
|
|
874
|
+
.args(args)
|
|
875
|
+
.output()
|
|
876
|
+
.expect("run tmux");
|
|
877
|
+
assert!(
|
|
878
|
+
output.status.success(),
|
|
879
|
+
"tmux {:?} failed: stdout={} stderr={}",
|
|
880
|
+
args,
|
|
881
|
+
String::from_utf8_lossy(&output.stdout),
|
|
882
|
+
String::from_utf8_lossy(&output.stderr)
|
|
883
|
+
);
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
fn list_tmux_panes_by_worker(socket: &Path) -> BTreeMap<String, String> {
|
|
887
|
+
let output = Command::new("tmux")
|
|
888
|
+
.args([
|
|
889
|
+
"-S",
|
|
890
|
+
socket.to_str().unwrap(),
|
|
891
|
+
"list-panes",
|
|
892
|
+
"-a",
|
|
893
|
+
"-F",
|
|
894
|
+
"#{window_name}\t#{pane_id}",
|
|
895
|
+
])
|
|
896
|
+
.output()
|
|
897
|
+
.expect("list tmux panes");
|
|
898
|
+
assert!(
|
|
899
|
+
output.status.success(),
|
|
900
|
+
"list-panes failed: stderr={}",
|
|
901
|
+
String::from_utf8_lossy(&output.stderr)
|
|
902
|
+
);
|
|
903
|
+
String::from_utf8_lossy(&output.stdout)
|
|
904
|
+
.lines()
|
|
905
|
+
.filter_map(|line| {
|
|
906
|
+
let mut fields = line.split('\t');
|
|
907
|
+
Some((fields.next()?.to_string(), fields.next()?.to_string()))
|
|
908
|
+
})
|
|
909
|
+
.collect()
|
|
910
|
+
}
|