@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,428 @@
|
|
|
1
|
+
//! 0.5.26 RED contract: stale team lifecycle must not poison live-team saves.
|
|
2
|
+
//!
|
|
3
|
+
//! References:
|
|
4
|
+
//! - `.team/artifacts/stale-team-saveconflict-locate.md` §8 RED1-RED6.
|
|
5
|
+
//!
|
|
6
|
+
//! User story: after a team is shut down with logs kept, its retained state is
|
|
7
|
+
//! visible as down/diagnostic history, but it is not an alive candidate and its
|
|
8
|
+
//! stopped agents' old pane fields cannot block writes to another live team.
|
|
9
|
+
|
|
10
|
+
#![allow(clippy::expect_used, clippy::panic, clippy::unwrap_used)]
|
|
11
|
+
|
|
12
|
+
#[path = "../../../tests/support/hermetic.rs"]
|
|
13
|
+
mod hermetic_guard;
|
|
14
|
+
|
|
15
|
+
use std::collections::BTreeMap;
|
|
16
|
+
use std::path::{Path, PathBuf};
|
|
17
|
+
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
18
|
+
|
|
19
|
+
use serde_json::{json, Value};
|
|
20
|
+
use serial_test::serial;
|
|
21
|
+
use team_agent::lifecycle::add_agent_with_transport;
|
|
22
|
+
use team_agent::model::ids::AgentId;
|
|
23
|
+
use team_agent::model::paths::runtime_spec_path;
|
|
24
|
+
use team_agent::state::paths::CommandScope;
|
|
25
|
+
use team_agent::state::persist::{load_runtime_state, save_runtime_state};
|
|
26
|
+
use team_agent::state::projection::{
|
|
27
|
+
project_top_level_view, save_team_scoped_state, team_state_candidates,
|
|
28
|
+
};
|
|
29
|
+
use team_agent::transport::{
|
|
30
|
+
AttachOutcome, BackendKind, CaptureRange, CapturedText, InjectPayload, InjectReport,
|
|
31
|
+
InjectStage, InjectVerification, Key, PaneField, PaneId, PaneInfo, PaneLiveness, SessionName,
|
|
32
|
+
SetEnvOutcome, SpawnResult, SubmitVerification, Target, Transport, TransportError,
|
|
33
|
+
TurnVerification, WindowName,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const CURRENT: &str = "current";
|
|
37
|
+
const RESEARCH: &str = "research";
|
|
38
|
+
const CURRENT_SESSION: &str = "team-supermarket-suite";
|
|
39
|
+
const RESEARCH_SESSION: &str = "team-supermarket-research";
|
|
40
|
+
|
|
41
|
+
#[test]
|
|
42
|
+
fn explicit_shutdown_status_is_non_alive_selector_guard() {
|
|
43
|
+
let state = json!({"teams": {
|
|
44
|
+
CURRENT: {"status": "shutdown", "session_name": CURRENT_SESSION, "agents": {"adminweb": agent("adminweb", "stopped", true)}},
|
|
45
|
+
RESEARCH: {"status": "alive", "session_name": RESEARCH_SESSION, "agents": {"researcher": agent("researcher", "running", true)}}
|
|
46
|
+
}});
|
|
47
|
+
assert_eq!(
|
|
48
|
+
keys(&team_state_candidates(&state)),
|
|
49
|
+
vec![RESEARCH],
|
|
50
|
+
"RED1 guard: explicit shutdown team status must be non-alive; state={state}"
|
|
51
|
+
);
|
|
52
|
+
// 0.5.27 locate showed the former source-text scan here was a false green:
|
|
53
|
+
// it never executed scoped shutdown nor reloaded disk state. The behavioral
|
|
54
|
+
// shutdown roundtrip contract lives in `src/cli/tests/shutdown_kill_plan.rs`.
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
#[test]
|
|
58
|
+
#[serial(env)]
|
|
59
|
+
fn legacy_all_stopped_team_is_not_alive_but_empty_bootstrap_remains_alive() {
|
|
60
|
+
let bootstrap = json!({"teams": {
|
|
61
|
+
"bootstrap": {"session_name": "legacy-bootstrap"},
|
|
62
|
+
RESEARCH: {"status": "alive", "session_name": RESEARCH_SESSION}
|
|
63
|
+
}});
|
|
64
|
+
assert!(
|
|
65
|
+
team_state_candidates(&bootstrap).contains_key("bootstrap"),
|
|
66
|
+
"RED2 compatibility guard: missing status remains alive for an empty legacy/bootstrap team"
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
let case = Case::new("legacy-stopped-selector");
|
|
70
|
+
case.write_state(case.root_with_current(Value::Null, "stopped", true));
|
|
71
|
+
let alive = team_state_candidates(&load_runtime_state(&case.workspace).unwrap());
|
|
72
|
+
assert_eq!(
|
|
73
|
+
keys(&alive),
|
|
74
|
+
vec![RESEARCH],
|
|
75
|
+
"RED2: status:null plus all agents stopped is a legacy shutdown residue and must not remain an alive candidate; alive={alive:?}"
|
|
76
|
+
);
|
|
77
|
+
assert!(
|
|
78
|
+
matches!(CommandScope::resolve(&case.workspace, None), CommandScope::Resolved(team) if team == RESEARCH),
|
|
79
|
+
"RED2: bare command scope must resolve to the only live research team, not refuse as ambiguous because current is a stopped residue"
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
#[test]
|
|
84
|
+
#[serial(env)]
|
|
85
|
+
fn dead_sibling_stale_topology_does_not_block_live_team_save_but_running_still_conflicts() {
|
|
86
|
+
let running = Case::new("running-sibling-conflict");
|
|
87
|
+
running.write_state(running.root_with_current(json!("alive"), "running", true));
|
|
88
|
+
let err = save_team_scoped_state(
|
|
89
|
+
&running.workspace,
|
|
90
|
+
&running.incoming_research_without_current_topology(),
|
|
91
|
+
)
|
|
92
|
+
.expect_err("RED3 guard: running sibling with mismatched topology must still SaveConflict");
|
|
93
|
+
assert!(
|
|
94
|
+
err.to_string().contains("SaveConflict") || err.to_string().contains("save conflict"),
|
|
95
|
+
"RED3 guard: live/running topology conflicts must remain protected; err={err}"
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
let stopped = Case::new("stopped-sibling-no-conflict");
|
|
99
|
+
stopped.write_state(stopped.root_with_current(Value::Null, "stopped", true));
|
|
100
|
+
save_team_scoped_state(
|
|
101
|
+
&stopped.workspace,
|
|
102
|
+
&stopped.incoming_research_without_current_topology(),
|
|
103
|
+
)
|
|
104
|
+
.expect("RED3: stopped/dead sibling stale topology must not block a write to live research");
|
|
105
|
+
let saved = load_runtime_state(&stopped.workspace).unwrap();
|
|
106
|
+
assert_eq!(
|
|
107
|
+
saved.pointer("/teams/current/agents/adminweb/status").and_then(Value::as_str),
|
|
108
|
+
Some("stopped"),
|
|
109
|
+
"RED3: dead sibling team must remain as stopped/down diagnostic history after live-team save; saved={saved}"
|
|
110
|
+
);
|
|
111
|
+
assert!(
|
|
112
|
+
saved.pointer("/teams/research/agents/standards").is_some(),
|
|
113
|
+
"RED3: live research update must persist; saved={saved}"
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
#[test]
|
|
118
|
+
#[serial(env)]
|
|
119
|
+
fn add_agent_downstream_failure_rolls_back_spec_and_state_so_retry_is_clean() {
|
|
120
|
+
let case = Case::new("add-agent-rollback");
|
|
121
|
+
case.write_team_docs();
|
|
122
|
+
case.write_state(case.root_with_current(Value::Null, "stopped", true));
|
|
123
|
+
let role = case.write_role_doc("standards");
|
|
124
|
+
let transport = FailingSpawnTransport::new();
|
|
125
|
+
|
|
126
|
+
let first = add_agent_with_transport(
|
|
127
|
+
&case.workspace,
|
|
128
|
+
&AgentId::new("standards"),
|
|
129
|
+
&role,
|
|
130
|
+
false,
|
|
131
|
+
Some(RESEARCH),
|
|
132
|
+
&transport,
|
|
133
|
+
);
|
|
134
|
+
assert!(
|
|
135
|
+
first.is_err(),
|
|
136
|
+
"RED4 setup: fake transport must fail downstream start; first={first:?}"
|
|
137
|
+
);
|
|
138
|
+
assert!(
|
|
139
|
+
transport.spawn_attempts() > 0,
|
|
140
|
+
"RED4 setup: failure must happen after add-agent reaches downstream start/spawn, not before runtime upsert"
|
|
141
|
+
);
|
|
142
|
+
assert_no_standards(&case);
|
|
143
|
+
|
|
144
|
+
let second = add_agent_with_transport(
|
|
145
|
+
&case.workspace,
|
|
146
|
+
&AgentId::new("standards"),
|
|
147
|
+
&role,
|
|
148
|
+
false,
|
|
149
|
+
Some(RESEARCH),
|
|
150
|
+
&transport,
|
|
151
|
+
);
|
|
152
|
+
let second_text = format!("{second:?}");
|
|
153
|
+
assert!(
|
|
154
|
+
!second_text.contains("agent id already exists"),
|
|
155
|
+
"RED4: rollback must remove half-registered state/spec rows so retry is not blocked as already-exists; first={first:?} second={second:?}"
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
#[test]
|
|
160
|
+
#[serial(env)]
|
|
161
|
+
fn purge_agent_help_and_dispatch_are_consistent() {
|
|
162
|
+
let case = Case::new("purge-agent");
|
|
163
|
+
let help = output_text(&case.run(["--help"]));
|
|
164
|
+
let command =
|
|
165
|
+
output_text(&case.run(["purge-agent", "ghost", "--workspace", case.ws(), "--json"]));
|
|
166
|
+
if help.contains("purge-agent") {
|
|
167
|
+
assert!(
|
|
168
|
+
!command.contains("invalid choice") && !command.contains("unknown subcommand") && !command.contains("Commands:"),
|
|
169
|
+
"RED6: help exposes purge-agent, so dispatch must be real or the command must be removed from help; help={help} command={command}"
|
|
170
|
+
);
|
|
171
|
+
} else {
|
|
172
|
+
assert!(
|
|
173
|
+
command.contains("unknown subcommand") || command.contains("invalid choice"),
|
|
174
|
+
"RED6: if purge-agent is not implemented, help and dispatch must agree it is absent; help={help} command={command}"
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
struct Case {
|
|
180
|
+
env: hermetic_guard::HermeticTestEnv,
|
|
181
|
+
workspace: PathBuf,
|
|
182
|
+
workspace_s: String,
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
impl Case {
|
|
186
|
+
fn new(tag: &str) -> Self {
|
|
187
|
+
let env = hermetic_guard::HermeticTestEnv::enter(tag);
|
|
188
|
+
let workspace = env.workspace(tag);
|
|
189
|
+
let workspace_s = workspace.to_string_lossy().to_string();
|
|
190
|
+
Self {
|
|
191
|
+
env,
|
|
192
|
+
workspace,
|
|
193
|
+
workspace_s,
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
fn ws(&self) -> &str {
|
|
198
|
+
&self.workspace_s
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
fn write_state(&self, state: Value) {
|
|
202
|
+
save_runtime_state(&self.workspace, &state).unwrap();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
fn root_with_current(
|
|
206
|
+
&self,
|
|
207
|
+
current_status: Value,
|
|
208
|
+
current_agent_status: &str,
|
|
209
|
+
current_topology: bool,
|
|
210
|
+
) -> Value {
|
|
211
|
+
let research_agent = agent("researcher", "running", true);
|
|
212
|
+
let current = json!({
|
|
213
|
+
"team_key": CURRENT,
|
|
214
|
+
"session_name": CURRENT_SESSION,
|
|
215
|
+
"team_dir": self.workspace_s,
|
|
216
|
+
"status": current_status,
|
|
217
|
+
"agents": {"adminweb": agent("adminweb", current_agent_status, current_topology)}
|
|
218
|
+
});
|
|
219
|
+
let research = json!({
|
|
220
|
+
"team_key": RESEARCH,
|
|
221
|
+
"session_name": RESEARCH_SESSION,
|
|
222
|
+
"team_dir": self.workspace_s,
|
|
223
|
+
"status": "alive",
|
|
224
|
+
"agents": {"researcher": research_agent.clone()},
|
|
225
|
+
"tasks": [{"id": "T", "assignee": "researcher", "status": "pending"}]
|
|
226
|
+
});
|
|
227
|
+
json!({
|
|
228
|
+
"schema_version": 1,
|
|
229
|
+
"active_team_key": RESEARCH,
|
|
230
|
+
"team_key": RESEARCH,
|
|
231
|
+
"session_name": RESEARCH_SESSION,
|
|
232
|
+
"team_dir": self.workspace_s,
|
|
233
|
+
"status": "alive",
|
|
234
|
+
"agents": {"researcher": research_agent},
|
|
235
|
+
"tasks": [{"id": "T", "assignee": "researcher", "status": "pending"}],
|
|
236
|
+
"teams": {CURRENT: current, RESEARCH: research}
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
fn incoming_research_without_current_topology(&self) -> Value {
|
|
241
|
+
let mut state =
|
|
242
|
+
project_top_level_view(&load_runtime_state(&self.workspace).unwrap(), RESEARCH);
|
|
243
|
+
state["agents"]["standards"] = agent("standards", "starting", false);
|
|
244
|
+
state["teams"][RESEARCH]["agents"]["standards"] = agent("standards", "starting", false);
|
|
245
|
+
state["teams"][CURRENT]["agents"]["adminweb"] = agent("adminweb", "stopped", false);
|
|
246
|
+
state
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
fn write_team_docs(&self) {
|
|
250
|
+
std::fs::create_dir_all(self.workspace.join("agents")).unwrap();
|
|
251
|
+
std::fs::write(
|
|
252
|
+
self.workspace.join("TEAM.md"),
|
|
253
|
+
"---\nname: research\nobjective: Supermarket research.\nprovider: fake\n---\n\nResearch team.\n",
|
|
254
|
+
)
|
|
255
|
+
.unwrap();
|
|
256
|
+
std::fs::write(
|
|
257
|
+
self.workspace.join("agents/researcher.md"),
|
|
258
|
+
role_doc("researcher"),
|
|
259
|
+
)
|
|
260
|
+
.unwrap();
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
fn write_role_doc(&self, id: &str) -> PathBuf {
|
|
264
|
+
let path = self.workspace.join(format!("{id}.md"));
|
|
265
|
+
std::fs::write(&path, role_doc(id)).unwrap();
|
|
266
|
+
path
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
fn write_runtime_spec(&self) {
|
|
270
|
+
let spec = team_agent::compiler::compile_team(&self.workspace).unwrap();
|
|
271
|
+
let path = runtime_spec_path(&self.workspace, RESEARCH);
|
|
272
|
+
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
|
|
273
|
+
std::fs::write(path, team_agent::model::yaml::dumps(&spec)).unwrap();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
fn run<const N: usize>(&self, args: [&str; N]) -> std::process::Output {
|
|
277
|
+
self.env.run_cli(&self.workspace, &args)
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
fn agent(id: &str, status: &str, topology: bool) -> Value {
|
|
282
|
+
let mut agent = json!({"agent_id": id, "id": id, "provider": "fake", "auth_mode": "subscription", "status": status});
|
|
283
|
+
if topology {
|
|
284
|
+
agent["window"] = json!(id);
|
|
285
|
+
agent["pane_id"] = json!("%1003");
|
|
286
|
+
agent["pane_pid"] = json!(59756);
|
|
287
|
+
agent["spawned_at"] = json!("2026-07-10T16:43:35.802946+00:00");
|
|
288
|
+
agent["spawn_epoch"] = json!(1);
|
|
289
|
+
}
|
|
290
|
+
agent
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
fn role_doc(id: &str) -> String {
|
|
294
|
+
format!("---\nname: {id}\nrole: {id}\nprovider: fake\nmodel: fake\nauth_mode: subscription\ntools:\n - mcp_team\n---\n\n{id}.\n")
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
fn assert_no_standards(case: &Case) {
|
|
298
|
+
let state = load_runtime_state(&case.workspace).unwrap();
|
|
299
|
+
assert!(
|
|
300
|
+
state.pointer("/agents/standards").is_none()
|
|
301
|
+
&& state.pointer("/teams/research/agents/standards").is_none(),
|
|
302
|
+
"RED4: failed add-agent rollback must remove standards from runtime state; state={state}"
|
|
303
|
+
);
|
|
304
|
+
let spec = runtime_spec_path(&case.workspace, RESEARCH);
|
|
305
|
+
if let Ok(text) = std::fs::read_to_string(&spec) {
|
|
306
|
+
assert!(
|
|
307
|
+
!text.contains("standards"),
|
|
308
|
+
"RED4: failed add-agent rollback must restore spec without standards; spec={text}"
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
struct FailingSpawnTransport {
|
|
314
|
+
attempts: AtomicUsize,
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
impl FailingSpawnTransport {
|
|
318
|
+
fn new() -> Self {
|
|
319
|
+
Self {
|
|
320
|
+
attempts: AtomicUsize::new(0),
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
fn spawn_attempts(&self) -> usize {
|
|
324
|
+
self.attempts.load(Ordering::SeqCst)
|
|
325
|
+
}
|
|
326
|
+
fn fail_spawn(&self) -> Result<SpawnResult, TransportError> {
|
|
327
|
+
self.attempts.fetch_add(1, Ordering::SeqCst);
|
|
328
|
+
Err(TransportError::Spawn {
|
|
329
|
+
backend: BackendKind::Tmux,
|
|
330
|
+
source: std::io::Error::other("forced add-agent downstream start failure"),
|
|
331
|
+
})
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
impl Transport for FailingSpawnTransport {
|
|
336
|
+
fn kind(&self) -> BackendKind {
|
|
337
|
+
BackendKind::Tmux
|
|
338
|
+
}
|
|
339
|
+
fn spawn_first(
|
|
340
|
+
&self,
|
|
341
|
+
_: &SessionName,
|
|
342
|
+
_: &WindowName,
|
|
343
|
+
_: &[String],
|
|
344
|
+
_: &Path,
|
|
345
|
+
_: &BTreeMap<String, String>,
|
|
346
|
+
) -> Result<SpawnResult, TransportError> {
|
|
347
|
+
self.fail_spawn()
|
|
348
|
+
}
|
|
349
|
+
fn spawn_into(
|
|
350
|
+
&self,
|
|
351
|
+
_: &SessionName,
|
|
352
|
+
_: &WindowName,
|
|
353
|
+
_: &[String],
|
|
354
|
+
_: &Path,
|
|
355
|
+
_: &BTreeMap<String, String>,
|
|
356
|
+
) -> Result<SpawnResult, TransportError> {
|
|
357
|
+
self.fail_spawn()
|
|
358
|
+
}
|
|
359
|
+
fn inject(
|
|
360
|
+
&self,
|
|
361
|
+
_: &Target,
|
|
362
|
+
_: &InjectPayload,
|
|
363
|
+
_: Key,
|
|
364
|
+
_: bool,
|
|
365
|
+
) -> Result<InjectReport, TransportError> {
|
|
366
|
+
Ok(InjectReport {
|
|
367
|
+
stage_reached: InjectStage::Submit,
|
|
368
|
+
inject_verification: InjectVerification::EmptyTextSendKeys,
|
|
369
|
+
submit_verification: SubmitVerification::EnterSentWithoutPlaceholderCheck,
|
|
370
|
+
turn_verification: TurnVerification::NotRequired,
|
|
371
|
+
attempts: 1,
|
|
372
|
+
submit_diagnostics: None,
|
|
373
|
+
})
|
|
374
|
+
}
|
|
375
|
+
fn send_keys(&self, _: &Target, _: &[Key]) -> Result<(), TransportError> {
|
|
376
|
+
Ok(())
|
|
377
|
+
}
|
|
378
|
+
fn capture(&self, _: &Target, range: CaptureRange) -> Result<CapturedText, TransportError> {
|
|
379
|
+
Ok(CapturedText {
|
|
380
|
+
text: String::new(),
|
|
381
|
+
range,
|
|
382
|
+
})
|
|
383
|
+
}
|
|
384
|
+
fn query(&self, _: &Target, _: PaneField) -> Result<Option<String>, TransportError> {
|
|
385
|
+
Ok(None)
|
|
386
|
+
}
|
|
387
|
+
fn liveness(&self, _: &PaneId) -> Result<PaneLiveness, TransportError> {
|
|
388
|
+
Ok(PaneLiveness::Live)
|
|
389
|
+
}
|
|
390
|
+
fn list_targets(&self) -> Result<Vec<PaneInfo>, TransportError> {
|
|
391
|
+
Ok(Vec::new())
|
|
392
|
+
}
|
|
393
|
+
fn has_session(&self, _: &SessionName) -> Result<bool, TransportError> {
|
|
394
|
+
Ok(true)
|
|
395
|
+
}
|
|
396
|
+
fn list_windows(&self, _: &SessionName) -> Result<Vec<WindowName>, TransportError> {
|
|
397
|
+
Ok(vec![WindowName::new("researcher")])
|
|
398
|
+
}
|
|
399
|
+
fn set_session_env(
|
|
400
|
+
&self,
|
|
401
|
+
_: &SessionName,
|
|
402
|
+
_: &str,
|
|
403
|
+
_: &str,
|
|
404
|
+
) -> Result<SetEnvOutcome, TransportError> {
|
|
405
|
+
Ok(SetEnvOutcome::Applied)
|
|
406
|
+
}
|
|
407
|
+
fn kill_session(&self, _: &SessionName) -> Result<(), TransportError> {
|
|
408
|
+
Ok(())
|
|
409
|
+
}
|
|
410
|
+
fn kill_window(&self, _: &Target) -> Result<(), TransportError> {
|
|
411
|
+
Ok(())
|
|
412
|
+
}
|
|
413
|
+
fn attach_session(&self, _: &SessionName) -> Result<AttachOutcome, TransportError> {
|
|
414
|
+
Ok(AttachOutcome::Attached)
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
fn keys(map: &serde_json::Map<String, Value>) -> Vec<&str> {
|
|
419
|
+
map.keys().map(String::as_str).collect()
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
fn output_text(output: &std::process::Output) -> String {
|
|
423
|
+
format!(
|
|
424
|
+
"{}{}",
|
|
425
|
+
String::from_utf8_lossy(&output.stdout),
|
|
426
|
+
String::from_utf8_lossy(&output.stderr)
|
|
427
|
+
)
|
|
428
|
+
}
|