@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,265 @@
|
|
|
1
|
+
//! Foundation-0 F0-2 RED contract: B0 legacy per-session snapshot non-authority.
|
|
2
|
+
//!
|
|
3
|
+
//! References:
|
|
4
|
+
//! - `.team/artifacts/foundation-0-slice-design.md` §4 B0 target semantics.
|
|
5
|
+
//! - `.team/artifacts/foundation-0-slice-design.md` §5 F0-2 RED design.
|
|
6
|
+
//!
|
|
7
|
+
//! User story: legacy `.team/runtime/teams/<session_name>/state.json`
|
|
8
|
+
//! snapshots are either gone or visibly diagnostic. Root/projection remains the
|
|
9
|
+
//! runtime authority for route/readiness/ok decisions when the legacy snapshot
|
|
10
|
+
//! diverges.
|
|
11
|
+
|
|
12
|
+
#![allow(clippy::expect_used, clippy::panic, clippy::unwrap_used)]
|
|
13
|
+
|
|
14
|
+
#[path = "../../../tests/support/hermetic.rs"]
|
|
15
|
+
mod hermetic_guard;
|
|
16
|
+
|
|
17
|
+
use std::path::{Path, PathBuf};
|
|
18
|
+
|
|
19
|
+
use serde_json::{json, Value};
|
|
20
|
+
use serial_test::serial;
|
|
21
|
+
use team_agent::state::persist::{runtime_state_path, save_runtime_state};
|
|
22
|
+
|
|
23
|
+
const TEAM: &str = "team-a";
|
|
24
|
+
const SESSION: &str = "b0-legacy-session";
|
|
25
|
+
const WORKER: &str = "worker";
|
|
26
|
+
const DIAGNOSTIC_READ_MARKER: &str = "B0_DIAGNOSTIC_LEGACY_SNAPSHOT_READ";
|
|
27
|
+
const DIAGNOSTIC_WRITE_MARKER: &str = "B0_DIAGNOSTIC_LEGACY_SNAPSHOT_WRITE";
|
|
28
|
+
|
|
29
|
+
#[test]
|
|
30
|
+
#[serial(env)]
|
|
31
|
+
fn lifecycle_snapshot_after_operation_is_absent_or_marked_nonauthoritative() {
|
|
32
|
+
let case = B0Case::new("snapshot-after-operation");
|
|
33
|
+
let state = case.state_with_worker("%new", 4201, 1);
|
|
34
|
+
|
|
35
|
+
let path = team_agent::lifecycle::save_team_runtime_snapshot(&case.workspace, &state)
|
|
36
|
+
.expect("F0-2 fixture: lifecycle snapshot save should return a path or no-op cleanly");
|
|
37
|
+
case.env.assert_path_under_root(&path);
|
|
38
|
+
if !path.exists() {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let snapshot = read_json(&path);
|
|
43
|
+
let canonical = runtime_state_path(&case.workspace);
|
|
44
|
+
assert_eq!(
|
|
45
|
+
snapshot
|
|
46
|
+
.get("_not_authoritative")
|
|
47
|
+
.and_then(Value::as_bool),
|
|
48
|
+
Some(true),
|
|
49
|
+
"F0-2 RED1: a retained legacy per-session snapshot must carry `_not_authoritative:true`; raw dual-write snapshots look authoritative. path={} snapshot={snapshot}",
|
|
50
|
+
path.display()
|
|
51
|
+
);
|
|
52
|
+
assert_eq!(
|
|
53
|
+
snapshot
|
|
54
|
+
.get("_canonical_state_path")
|
|
55
|
+
.and_then(Value::as_str),
|
|
56
|
+
Some(canonical.to_string_lossy().as_ref()),
|
|
57
|
+
"F0-2 RED1: retained snapshot must point readers at the canonical root/projection state via `_canonical_state_path`; path={} snapshot={snapshot}",
|
|
58
|
+
path.display()
|
|
59
|
+
);
|
|
60
|
+
for required in ["_derived_from", "_generated_at"] {
|
|
61
|
+
assert!(
|
|
62
|
+
snapshot.get(required).is_some(),
|
|
63
|
+
"F0-2 RED1: retained legacy snapshot must include diagnostic metadata `{required}`; path={} snapshot={snapshot}",
|
|
64
|
+
path.display()
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
#[test]
|
|
70
|
+
fn legacy_snapshot_writes_are_not_reachable_from_authority_save_paths() {
|
|
71
|
+
let offenders = rs_source_lines("src")
|
|
72
|
+
.into_iter()
|
|
73
|
+
.filter(|(rel, line_no, line)| legacy_snapshot_write_reference(rel, *line_no, line))
|
|
74
|
+
.collect::<Vec<_>>();
|
|
75
|
+
|
|
76
|
+
assert!(
|
|
77
|
+
offenders.is_empty(),
|
|
78
|
+
"F0-2 RED2: legacy per-session snapshot writes are allowed only for diagnostic/migration/test paths marked `{DIAGNOSTIC_WRITE_MARKER}`. Product authority saves must not call save_team_runtime_snapshot/write_team_snapshot_atomic or recreate dual-write promises. Offenders (file:line): {offenders:#?}"
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
#[test]
|
|
83
|
+
#[serial(env)]
|
|
84
|
+
fn stale_legacy_snapshot_does_not_drive_route_readiness_or_ok_authority() {
|
|
85
|
+
let case = B0Case::new("stale-snapshot-nonauthority");
|
|
86
|
+
let root = case.state_with_worker("%new", 5101, 1);
|
|
87
|
+
save_runtime_state(&case.workspace, &root).expect("seed canonical root state");
|
|
88
|
+
|
|
89
|
+
let legacy = case.state_with_worker("%old", 9101, 0);
|
|
90
|
+
let legacy_path = team_agent::lifecycle::helpers::team_snapshot_path(&case.workspace, SESSION);
|
|
91
|
+
write_json(&legacy_path, &legacy);
|
|
92
|
+
|
|
93
|
+
let selected = team_agent::state::projection::select_runtime_state(&case.workspace, Some(TEAM))
|
|
94
|
+
.expect("select current team from canonical root/projection state");
|
|
95
|
+
assert_eq!(
|
|
96
|
+
selected.pointer("/agents/worker/pane_id").and_then(Value::as_str),
|
|
97
|
+
Some("%new"),
|
|
98
|
+
"F0-2 RED3: route/readiness selection must use canonical root/projection worker tuple, not divergent legacy snapshot tuple; selected={selected} legacy={legacy}"
|
|
99
|
+
);
|
|
100
|
+
assert_eq!(
|
|
101
|
+
selected
|
|
102
|
+
.pointer("/agents/worker/spawn_epoch")
|
|
103
|
+
.and_then(Value::as_u64),
|
|
104
|
+
Some(1),
|
|
105
|
+
"F0-2 RED3: stale snapshot fields must not lower readiness/route epoch decisions; selected={selected} legacy={legacy}"
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
let offenders = rs_source_lines("src")
|
|
109
|
+
.into_iter()
|
|
110
|
+
.filter(|(rel, line_no, line)| {
|
|
111
|
+
legacy_snapshot_authority_read_reference(rel, *line_no, line)
|
|
112
|
+
})
|
|
113
|
+
.collect::<Vec<_>>();
|
|
114
|
+
assert!(
|
|
115
|
+
offenders.is_empty(),
|
|
116
|
+
"F0-2 RED3: legacy snapshot reads may only be diagnostic/stale display reads marked `{DIAGNOSTIC_READ_MARKER}` and must not feed route/readiness/ok/repair decisions. Offenders (file:line): {offenders:#?}"
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
struct B0Case {
|
|
121
|
+
env: hermetic_guard::HermeticTestEnv,
|
|
122
|
+
workspace: PathBuf,
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
impl B0Case {
|
|
126
|
+
fn new(tag: &str) -> Self {
|
|
127
|
+
let env = hermetic_guard::HermeticTestEnv::enter(tag);
|
|
128
|
+
let workspace = env.workspace(tag);
|
|
129
|
+
Self { env, workspace }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
fn state_with_worker(&self, pane_id: &str, pane_pid: i64, spawn_epoch: u64) -> Value {
|
|
133
|
+
let worker = json!({
|
|
134
|
+
"id": WORKER,
|
|
135
|
+
"pane_id": pane_id,
|
|
136
|
+
"pane_pid": pane_pid,
|
|
137
|
+
"tmux_session": SESSION,
|
|
138
|
+
"tmux_window": format!("{WORKER}-win"),
|
|
139
|
+
"spawn_epoch": spawn_epoch,
|
|
140
|
+
"status": "running"
|
|
141
|
+
});
|
|
142
|
+
let team = json!({
|
|
143
|
+
"session_name": SESSION,
|
|
144
|
+
"team_dir": self.workspace.to_string_lossy().to_string(),
|
|
145
|
+
"status": "alive",
|
|
146
|
+
"agents": {
|
|
147
|
+
WORKER: worker.clone()
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
json!({
|
|
151
|
+
"schema_version": 1,
|
|
152
|
+
"session_name": SESSION,
|
|
153
|
+
"team_dir": self.workspace.to_string_lossy().to_string(),
|
|
154
|
+
"active_team_key": TEAM,
|
|
155
|
+
"agents": {
|
|
156
|
+
WORKER: worker
|
|
157
|
+
},
|
|
158
|
+
"teams": {
|
|
159
|
+
TEAM: team
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
fn write_json(path: &Path, value: &Value) {
|
|
166
|
+
std::fs::create_dir_all(path.parent().expect("json parent")).expect("create json parent");
|
|
167
|
+
std::fs::write(
|
|
168
|
+
path,
|
|
169
|
+
serde_json::to_vec_pretty(value).expect("serialize json"),
|
|
170
|
+
)
|
|
171
|
+
.unwrap_or_else(|error| panic!("write {}: {error}", path.display()));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
fn read_json(path: &Path) -> Value {
|
|
175
|
+
serde_json::from_slice(
|
|
176
|
+
&std::fs::read(path).unwrap_or_else(|error| panic!("read {}: {error}", path.display())),
|
|
177
|
+
)
|
|
178
|
+
.unwrap_or_else(|error| panic!("parse {}: {error}", path.display()))
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
fn legacy_snapshot_write_reference(rel: &str, line_no: usize, line: &str) -> bool {
|
|
182
|
+
let trimmed = line.trim_start();
|
|
183
|
+
if trimmed.starts_with("//") || trimmed.starts_with("///") || trimmed.starts_with("//!") {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
if allowed_test_source(rel) || allowed_diagnostic_or_migration_source(rel, line) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
if rel == "src/lifecycle/helpers.rs"
|
|
190
|
+
&& (line.contains("pub fn save_team_runtime_snapshot")
|
|
191
|
+
|| line.contains("pub(crate) fn save_team_runtime_snapshot")
|
|
192
|
+
|| line.contains("pub fn team_snapshot_path"))
|
|
193
|
+
{
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
let _ = line_no;
|
|
197
|
+
(line.contains("save_team_runtime_snapshot(")
|
|
198
|
+
&& !line.contains("pub fn save_team_runtime_snapshot"))
|
|
199
|
+
|| line.contains("write_team_snapshot_atomic(")
|
|
200
|
+
|| line.contains("fn write_team_snapshot_atomic")
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
fn legacy_snapshot_authority_read_reference(rel: &str, line_no: usize, line: &str) -> bool {
|
|
204
|
+
let trimmed = line.trim_start();
|
|
205
|
+
if trimmed.starts_with("//") || trimmed.starts_with("///") || trimmed.starts_with("//!") {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
if allowed_test_source(rel) || allowed_diagnostic_or_migration_source(rel, line) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
if rel == "src/lifecycle/helpers.rs" {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
let _ = line_no;
|
|
215
|
+
line.contains("team_snapshot_path(")
|
|
216
|
+
|| line.contains("readable_team_snapshot_path(")
|
|
217
|
+
|| line.contains("detect_dual_state_divergence(")
|
|
218
|
+
|| line.contains("\".team/runtime/teams\"")
|
|
219
|
+
|| line.contains("runtime/teams")
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
fn allowed_test_source(rel: &str) -> bool {
|
|
223
|
+
rel.contains("/tests/") || rel.ends_with("/tests.rs")
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
fn allowed_diagnostic_or_migration_source(rel: &str, line: &str) -> bool {
|
|
227
|
+
rel.contains("/migration")
|
|
228
|
+
|| rel.contains("/diagnose")
|
|
229
|
+
|| rel.contains("diagnose")
|
|
230
|
+
|| line.contains(DIAGNOSTIC_READ_MARKER)
|
|
231
|
+
|| line.contains(DIAGNOSTIC_WRITE_MARKER)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
fn rs_source_lines(rel: &str) -> Vec<(String, usize, String)> {
|
|
235
|
+
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join(rel);
|
|
236
|
+
let mut out = Vec::new();
|
|
237
|
+
append_rs_source_lines(&root, Path::new(env!("CARGO_MANIFEST_DIR")), &mut out);
|
|
238
|
+
out
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
fn append_rs_source_lines(path: &Path, base: &Path, out: &mut Vec<(String, usize, String)>) {
|
|
242
|
+
if path.is_dir() {
|
|
243
|
+
let mut entries = std::fs::read_dir(path)
|
|
244
|
+
.expect("read source dir")
|
|
245
|
+
.map(|entry| entry.expect("read source entry").path())
|
|
246
|
+
.collect::<Vec<PathBuf>>();
|
|
247
|
+
entries.sort();
|
|
248
|
+
for entry in entries {
|
|
249
|
+
append_rs_source_lines(&entry, base, out);
|
|
250
|
+
}
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if path.extension().and_then(|v| v.to_str()) != Some("rs") {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
let rel = path
|
|
257
|
+
.strip_prefix(base)
|
|
258
|
+
.unwrap_or(path)
|
|
259
|
+
.to_string_lossy()
|
|
260
|
+
.to_string();
|
|
261
|
+
let text = std::fs::read_to_string(path).expect("read source file");
|
|
262
|
+
for (idx, line) in text.lines().enumerate() {
|
|
263
|
+
out.push((rel.clone(), idx + 1, line.trim().to_string()));
|
|
264
|
+
}
|
|
265
|
+
}
|