@team-agent/installer 0.5.128 → 0.6.0
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/README.md +4 -4
- package/README.zh.md +1 -1
- package/package.json +4 -8
- package/skills/team-agent/SKILL.md +37 -20
- package/skills/team-agent/command-coverage.json +169 -183
- package/skills/team-agent/docs/reference/team-agent-operator.md +64 -30
- package/skills/team-agent/references/recovery-runbook.md +1 -1
- package/skills/team-agent/references/team-agent-operator.md +64 -30
- package/templates/team_state.md +1 -1
- package/Cargo.lock +0 -1063
- package/Cargo.toml +0 -36
- package/crates/team-agent/Cargo.toml +0 -69
- package/crates/team-agent/src/app_server_test_support.rs +0 -258
- package/crates/team-agent/src/cli/adapters.rs +0 -1288
- package/crates/team-agent/src/cli/arguments.rs +0 -405
- package/crates/team-agent/src/cli/attach_app_server_leader.rs +0 -98
- package/crates/team-agent/src/cli/diagnose.rs +0 -1721
- package/crates/team-agent/src/cli/emit.rs +0 -2930
- package/crates/team-agent/src/cli/grok_slot.rs +0 -384
- package/crates/team-agent/src/cli/helpers.rs +0 -91
- package/crates/team-agent/src/cli/intent/runtime.rs +0 -1216
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -912
- package/crates/team-agent/src/cli/intent/tests.rs +0 -689
- package/crates/team-agent/src/cli/intent.rs +0 -664
- package/crates/team-agent/src/cli/leader.rs +0 -300
- package/crates/team-agent/src/cli/leader_prompt.rs +0 -261
- package/crates/team-agent/src/cli/leaders.rs +0 -418
- package/crates/team-agent/src/cli/mod.rs +0 -6545
- package/crates/team-agent/src/cli/models.rs +0 -1206
- package/crates/team-agent/src/cli/named_address.rs +0 -1651
- package/crates/team-agent/src/cli/profile.rs +0 -342
- package/crates/team-agent/src/cli/route.rs +0 -212
- package/crates/team-agent/src/cli/schedule.rs +0 -175
- package/crates/team-agent/src/cli/send/coordinator.rs +0 -164
- package/crates/team-agent/src/cli/send/mailbox.rs +0 -145
- package/crates/team-agent/src/cli/send/persist.rs +0 -156
- package/crates/team-agent/src/cli/send/presentation.rs +0 -370
- package/crates/team-agent/src/cli/send/resolve.rs +0 -573
- package/crates/team-agent/src/cli/send.rs +0 -199
- package/crates/team-agent/src/cli/shutdown_socket.rs +0 -288
- package/crates/team-agent/src/cli/spec.rs +0 -165
- package/crates/team-agent/src/cli/status.rs +0 -280
- package/crates/team-agent/src/cli/status_port/agents.rs +0 -358
- package/crates/team-agent/src/cli/status_port/approvals.rs +0 -79
- package/crates/team-agent/src/cli/status_port/brief.rs +0 -1981
- package/crates/team-agent/src/cli/status_port/compact.rs +0 -240
- package/crates/team-agent/src/cli/status_port/format.rs +0 -146
- package/crates/team-agent/src/cli/status_port/inbox.rs +0 -62
- package/crates/team-agent/src/cli/status_port/runtime.rs +0 -197
- package/crates/team-agent/src/cli/status_port/snapshot.rs +0 -208
- package/crates/team-agent/src/cli/status_port/store.rs +0 -416
- package/crates/team-agent/src/cli/status_port/tests.rs +0 -90
- package/crates/team-agent/src/cli/status_port.rs +0 -92
- package/crates/team-agent/src/cli/tests/base.rs +0 -885
- package/crates/team-agent/src/cli/tests/divergence.rs +0 -518
- package/crates/team-agent/src/cli/tests/lane_c.rs +0 -453
- package/crates/team-agent/src/cli/tests/leader_watch.rs +0 -322
- package/crates/team-agent/src/cli/tests/main_preserved.rs +0 -430
- package/crates/team-agent/src/cli/tests/missing_subcommands.rs +0 -336
- package/crates/team-agent/src/cli/tests/mod.rs +0 -137
- package/crates/team-agent/src/cli/tests/named_address.rs +0 -761
- package/crates/team-agent/src/cli/tests/parser_safety.rs +0 -383
- package/crates/team-agent/src/cli/tests/run_delegation.rs +0 -484
- package/crates/team-agent/src/cli/tests/shutdown_kill_plan.rs +0 -2179
- package/crates/team-agent/src/cli/tests/status_brief.rs +0 -1514
- package/crates/team-agent/src/cli/tests/status_send.rs +0 -888
- package/crates/team-agent/src/cli/tests/verb_install_skill.rs +0 -93
- package/crates/team-agent/src/cli/tests/verb_profile.rs +0 -392
- package/crates/team-agent/src/cli/triage.rs +0 -234
- package/crates/team-agent/src/cli/types.rs +0 -591
- package/crates/team-agent/src/codex_app_server.rs +0 -546
- package/crates/team-agent/src/communication_mode/mod.rs +0 -56
- package/crates/team-agent/src/compiler/tests.rs +0 -827
- package/crates/team-agent/src/compiler.rs +0 -890
- package/crates/team-agent/src/conpty/backend.rs +0 -829
- package/crates/team-agent/src/conpty/mod.rs +0 -33
- package/crates/team-agent/src/contract_runtime/backend.rs +0 -1744
- package/crates/team-agent/src/contract_runtime/commands.rs +0 -671
- package/crates/team-agent/src/contract_runtime/config.rs +0 -364
- package/crates/team-agent/src/contract_runtime/config_tests.rs +0 -76
- package/crates/team-agent/src/contract_runtime/discovery.rs +0 -449
- package/crates/team-agent/src/contract_runtime/fork.rs +0 -361
- package/crates/team-agent/src/contract_runtime/forward.rs +0 -288
- package/crates/team-agent/src/contract_runtime/framework.rs +0 -367
- package/crates/team-agent/src/contract_runtime/mcp.rs +0 -394
- package/crates/team-agent/src/contract_runtime/mod.rs +0 -17
- package/crates/team-agent/src/contract_runtime/prompt.rs +0 -216
- package/crates/team-agent/src/contract_runtime/pump.rs +0 -271
- package/crates/team-agent/src/contract_runtime/registry.rs +0 -553
- package/crates/team-agent/src/contract_runtime/workspace.rs +0 -228
- package/crates/team-agent/src/coordinator/backoff.rs +0 -741
- package/crates/team-agent/src/coordinator/conpty_shim.rs +0 -805
- package/crates/team-agent/src/coordinator/health.rs +0 -1185
- package/crates/team-agent/src/coordinator/mod.rs +0 -119
- package/crates/team-agent/src/coordinator/orphan.rs +0 -110
- package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -798
- package/crates/team-agent/src/coordinator/runtime_observation.rs +0 -84
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +0 -2309
- package/crates/team-agent/src/coordinator/steps/delivery.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/health_sync.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/mod.rs +0 -126
- package/crates/team-agent/src/coordinator/steps/persist.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/runtime_prompts.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/session_gate.rs +0 -16
- package/crates/team-agent/src/coordinator/tests/a0_lostupdate.rs +0 -158
- package/crates/team-agent/src/coordinator/tests/abnormal.rs +0 -312
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +0 -300
- package/crates/team-agent/src/coordinator/tests/basics.rs +0 -211
- package/crates/team-agent/src/coordinator/tests/daemon.rs +0 -514
- package/crates/team-agent/src/coordinator/tests/energy.rs +0 -549
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +0 -503
- package/crates/team-agent/src/coordinator/tests/main_preserved.rs +0 -186
- package/crates/team-agent/src/coordinator/tests/mod.rs +0 -295
- package/crates/team-agent/src/coordinator/tests/s3_bounded.rs +0 -207
- package/crates/team-agent/src/coordinator/tests/spine.rs +0 -308
- package/crates/team-agent/src/coordinator/tests/takeover.rs +0 -286
- package/crates/team-agent/src/coordinator/tests/tick_core.rs +0 -237
- package/crates/team-agent/src/coordinator/tick.rs +0 -3024
- package/crates/team-agent/src/coordinator/types.rs +0 -540
- package/crates/team-agent/src/db/agent_health_capture.rs +0 -126
- package/crates/team-agent/src/db/message_store.rs +0 -1527
- package/crates/team-agent/src/db/migration.rs +0 -984
- package/crates/team-agent/src/db/mod.rs +0 -26
- package/crates/team-agent/src/db/schema.rs +0 -663
- package/crates/team-agent/src/diagnose/comms.rs +0 -242
- package/crates/team-agent/src/diagnose/mod.rs +0 -44
- package/crates/team-agent/src/diagnose/orphans.rs +0 -889
- package/crates/team-agent/src/direct_delivery.rs +0 -368
- package/crates/team-agent/src/event_log.rs +0 -502
- package/crates/team-agent/src/fake_worker.rs +0 -303
- package/crates/team-agent/src/inbox_store.rs +0 -169
- package/crates/team-agent/src/kill_audit.rs +0 -106
- package/crates/team-agent/src/layout/manager.rs +0 -248
- package/crates/team-agent/src/layout/mod.rs +0 -36
- package/crates/team-agent/src/layout/overlay.rs +0 -134
- package/crates/team-agent/src/layout/placement.rs +0 -52
- package/crates/team-agent/src/layout/recovery.rs +0 -106
- package/crates/team-agent/src/layout/runtime_sessions.rs +0 -317
- package/crates/team-agent/src/layout/sessions.rs +0 -294
- package/crates/team-agent/src/layout/tmux_endpoint.rs +0 -165
- package/crates/team-agent/src/layout/worker_env.rs +0 -721
- package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -37
- package/crates/team-agent/src/leader/helpers.rs +0 -178
- package/crates/team-agent/src/leader/incident.rs +0 -6
- package/crates/team-agent/src/leader/lease.rs +0 -3356
- package/crates/team-agent/src/leader/mod.rs +0 -104
- package/crates/team-agent/src/leader/owner_bind.rs +0 -400
- package/crates/team-agent/src/leader/prompt.rs +0 -905
- package/crates/team-agent/src/leader/provider_attribution.rs +0 -247
- package/crates/team-agent/src/leader/rediscover/tests.rs +0 -689
- package/crates/team-agent/src/leader/rediscover.rs +0 -1192
- package/crates/team-agent/src/leader/registry.rs +0 -888
- package/crates/team-agent/src/leader/start.rs +0 -4501
- package/crates/team-agent/src/leader/takeover.rs +0 -65
- package/crates/team-agent/src/leader/tests/basics.rs +0 -337
- package/crates/team-agent/src/leader/tests/byte_findings.rs +0 -355
- package/crates/team-agent/src/leader/tests/claim_leader_mailbox_flush_contract.rs +0 -544
- package/crates/team-agent/src/leader/tests/historical_inventory_upgrade_gate_red.rs +0 -624
- package/crates/team-agent/src/leader/tests/identity.rs +0 -465
- package/crates/team-agent/src/leader/tests/identity_session_names.rs +0 -42
- package/crates/team-agent/src/leader/tests/idle.rs +0 -113
- package/crates/team-agent/src/leader/tests/lease_api.rs +0 -520
- package/crates/team-agent/src/leader/tests/lease_claim.rs +0 -629
- package/crates/team-agent/src/leader/tests/mod.rs +0 -106
- package/crates/team-agent/src/leader/tests/prompt_contract.rs +0 -268
- package/crates/team-agent/src/leader/tests/rediscover.rs +0 -403
- package/crates/team-agent/src/leader/tests/rehomed_env.rs +0 -83
- package/crates/team-agent/src/leader/tests/team_in_team_state_scope_red.rs +0 -1273
- package/crates/team-agent/src/leader/tests/terminal_and_replay_vs_rerender_invariants_red.rs +0 -417
- package/crates/team-agent/src/leader/tests/wake_start_owner.rs +0 -168
- package/crates/team-agent/src/leader/types.rs +0 -534
- package/crates/team-agent/src/lib.rs +0 -147
- package/crates/team-agent/src/lifecycle/helpers.rs +0 -212
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +0 -881
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +0 -598
- package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -332
- package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +0 -204
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -107
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +0 -144
- package/crates/team-agent/src/lifecycle/launch/identity.rs +0 -674
- package/crates/team-agent/src/lifecycle/launch/layout.rs +0 -350
- package/crates/team-agent/src/lifecycle/launch/leader_context.rs +0 -589
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +0 -160
- package/crates/team-agent/src/lifecycle/launch/ownership.rs +0 -105
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +0 -899
- package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +0 -225
- package/crates/team-agent/src/lifecycle/launch/plan.rs +0 -269
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -5200
- package/crates/team-agent/src/lifecycle/launch/quick_start_transport.rs +0 -368
- package/crates/team-agent/src/lifecycle/launch/readiness.rs +0 -519
- package/crates/team-agent/src/lifecycle/launch/role_source.rs +0 -287
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -473
- package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -801
- package/crates/team-agent/src/lifecycle/launch/state_projection.rs +0 -624
- package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -558
- package/crates/team-agent/src/lifecycle/launch.rs +0 -557
- package/crates/team-agent/src/lifecycle/lock.rs +0 -350
- package/crates/team-agent/src/lifecycle/mod.rs +0 -79
- package/crates/team-agent/src/lifecycle/pane_input_lock.rs +0 -239
- package/crates/team-agent/src/lifecycle/profile_launch.rs +0 -1067
- package/crates/team-agent/src/lifecycle/profile_smoke.rs +0 -557
- package/crates/team-agent/src/lifecycle/restart/agent.rs +0 -2199
- package/crates/team-agent/src/lifecycle/restart/avatar.rs +0 -1798
- package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +0 -163
- package/crates/team-agent/src/lifecycle/restart/common.rs +0 -2362
- package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +0 -65
- package/crates/team-agent/src/lifecycle/restart/preflight.rs +0 -113
- package/crates/team-agent/src/lifecycle/restart/rebuild.rs +0 -5135
- package/crates/team-agent/src/lifecycle/restart/remove.rs +0 -1504
- package/crates/team-agent/src/lifecycle/restart/selection.rs +0 -559
- package/crates/team-agent/src/lifecycle/restart/team_state.rs +0 -329
- package/crates/team-agent/src/lifecycle/restart.rs +0 -227
- package/crates/team-agent/src/lifecycle/role_config.rs +0 -1230
- package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +0 -1021
- package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +0 -1205
- package/crates/team-agent/src/lifecycle/tests/b0_legacy_snapshot_nonauthority_contract.rs +0 -265
- package/crates/team-agent/src/lifecycle/tests/b0_reader_hideone_audit_contract.rs +0 -490
- package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +0 -656
- package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +0 -325
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +0 -447
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +0 -1638
- package/crates/team-agent/src/lifecycle/tests/clone_agent_preserves_source_tools.rs +0 -427
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +0 -770
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +0 -419
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +0 -2035
- package/crates/team-agent/src/lifecycle/tests/core.rs +0 -1327
- package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +0 -315
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_g0.stdout.txt +0 -222
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_spaced_ids.stdout.txt +0 -9
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +0 -72
- package/crates/team-agent/src/lifecycle/tests/gate_fixtures.rs +0 -562
- package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +0 -110
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +0 -512
- package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +0 -921
- package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +0 -68
- package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +0 -1851
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +0 -3983
- package/crates/team-agent/src/lifecycle/tests/lifecycle_lock.rs +0 -339
- package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +0 -596
- package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +0 -513
- package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +0 -69
- package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +0 -824
- package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +0 -723
- package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +0 -164
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +0 -200
- package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +0 -210
- package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +0 -527
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +0 -1062
- package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +0 -1419
- package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +0 -98
- package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +0 -550
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +0 -226
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +0 -332
- package/crates/team-agent/src/lifecycle/tests/realmachine_clusters_1_6_red.rs +0 -786
- package/crates/team-agent/src/lifecycle/tests/realmachine_residual_g1_g4_red.rs +0 -648
- package/crates/team-agent/src/lifecycle/tests/restart.rs +0 -185
- package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +0 -1053
- package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +0 -679
- package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1126
- package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +0 -153
- package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +0 -427
- package/crates/team-agent/src/lifecycle/tests/stale_team_saveconflict_contract.rs +0 -431
- package/crates/team-agent/src/lifecycle/tests/startup_latency_contract.rs +0 -1066
- package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +0 -876
- package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +0 -1026
- package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +0 -342
- package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +0 -543
- package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +0 -1103
- package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +0 -1276
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_roster_red.rs +0 -145
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +0 -603
- package/crates/team-agent/src/lifecycle/tests/test_isolation_escape_contract.rs +0 -936
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +0 -970
- package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +0 -995
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -836
- package/crates/team-agent/src/lifecycle/tests.rs +0 -105
- package/crates/team-agent/src/lifecycle/types.rs +0 -877
- package/crates/team-agent/src/lifecycle/worker_command_context.rs +0 -363
- package/crates/team-agent/src/main.rs +0 -52
- package/crates/team-agent/src/mcp_server/helpers.rs +0 -510
- package/crates/team-agent/src/mcp_server/lifecycle_tools/mod.rs +0 -6
- package/crates/team-agent/src/mcp_server/lifecycle_tools/state_status.rs +0 -43
- package/crates/team-agent/src/mcp_server/mod.rs +0 -119
- package/crates/team-agent/src/mcp_server/normalize.rs +0 -485
- package/crates/team-agent/src/mcp_server/readiness.rs +0 -527
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +0 -348
- package/crates/team-agent/src/mcp_server/tests/golden.rs +0 -285
- package/crates/team-agent/src/mcp_server/tests/normalize.rs +0 -247
- package/crates/team-agent/src/mcp_server/tests/scoped.rs +0 -158
- package/crates/team-agent/src/mcp_server/tests/send.rs +0 -353
- package/crates/team-agent/src/mcp_server/tests/tools.rs +0 -341
- package/crates/team-agent/src/mcp_server/tests/wire.rs +0 -254
- package/crates/team-agent/src/mcp_server/tests.rs +0 -43
- package/crates/team-agent/src/mcp_server/tools.rs +0 -889
- package/crates/team-agent/src/mcp_server/types.rs +0 -396
- package/crates/team-agent/src/mcp_server/wire.rs +0 -867
- package/crates/team-agent/src/messaging/activity.rs +0 -461
- package/crates/team-agent/src/messaging/address.rs +0 -87
- package/crates/team-agent/src/messaging/delivery.rs +0 -3727
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +0 -234
- package/crates/team-agent/src/messaging/enter_rescue.rs +0 -362
- package/crates/team-agent/src/messaging/enter_rescue_tests.rs +0 -633
- package/crates/team-agent/src/messaging/helpers.rs +0 -336
- package/crates/team-agent/src/messaging/leader_channel.rs +0 -287
- package/crates/team-agent/src/messaging/leader_receiver.rs +0 -786
- package/crates/team-agent/src/messaging/mod.rs +0 -167
- package/crates/team-agent/src/messaging/persist.rs +0 -377
- package/crates/team-agent/src/messaging/presentation.rs +0 -417
- package/crates/team-agent/src/messaging/reminders.rs +0 -316
- package/crates/team-agent/src/messaging/results/collection_tests.rs +0 -719
- package/crates/team-agent/src/messaging/results.rs +0 -1415
- package/crates/team-agent/src/messaging/scheduler.rs +0 -223
- package/crates/team-agent/src/messaging/selftest.rs +0 -315
- package/crates/team-agent/src/messaging/send.rs +0 -981
- package/crates/team-agent/src/messaging/tests/basic.rs +0 -346
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +0 -657
- package/crates/team-agent/src/messaging/tests/e23.rs +0 -49
- package/crates/team-agent/src/messaging/tests/leader_channel.rs +0 -169
- package/crates/team-agent/src/messaging/tests/leader_inject_acceptance.rs +0 -817
- package/crates/team-agent/src/messaging/tests/main_preserved.rs +0 -85
- package/crates/team-agent/src/messaging/tests/mod.rs +0 -306
- package/crates/team-agent/src/messaging/tests/runtime.rs +0 -3549
- package/crates/team-agent/src/messaging/tests/spine.rs +0 -853
- package/crates/team-agent/src/messaging/tests/wave2.rs +0 -381
- package/crates/team-agent/src/messaging/trust.rs +0 -215
- package/crates/team-agent/src/messaging/types.rs +0 -472
- package/crates/team-agent/src/messaging/wait.rs +0 -366
- package/crates/team-agent/src/messaging/watchers.rs +0 -916
- package/crates/team-agent/src/model/enums.rs +0 -356
- package/crates/team-agent/src/model/errors.rs +0 -18
- package/crates/team-agent/src/model/ids.rs +0 -165
- package/crates/team-agent/src/model/mod.rs +0 -29
- package/crates/team-agent/src/model/name_similarity.rs +0 -252
- package/crates/team-agent/src/model/pane_authority_refusal.rs +0 -359
- package/crates/team-agent/src/model/paths.rs +0 -257
- package/crates/team-agent/src/model/routing.rs +0 -387
- package/crates/team-agent/src/model/spec.rs +0 -1184
- package/crates/team-agent/src/model/task_graph.rs +0 -321
- package/crates/team-agent/src/model/testdata/fuzz.golden.yaml +0 -43
- package/crates/team-agent/src/model/testdata/fuzz.yaml +0 -43
- package/crates/team-agent/src/model/testdata/spec_invalid_a.yaml +0 -209
- package/crates/team-agent/src/model/testdata/team.spec.golden.yaml +0 -208
- package/crates/team-agent/src/model/testdata/team.spec.yaml +0 -208
- package/crates/team-agent/src/model/yaml/tests.rs +0 -188
- package/crates/team-agent/src/model/yaml.rs +0 -802
- package/crates/team-agent/src/os_probe.rs +0 -280
- package/crates/team-agent/src/packaging/install.rs +0 -219
- package/crates/team-agent/src/packaging/migrate.rs +0 -38
- package/crates/team-agent/src/packaging/mod.rs +0 -91
- package/crates/team-agent/src/packaging/repair.rs +0 -33
- package/crates/team-agent/src/packaging/tests.rs +0 -822
- package/crates/team-agent/src/packaging/types.rs +0 -417
- package/crates/team-agent/src/platform/argv.rs +0 -331
- package/crates/team-agent/src/platform/errors.rs +0 -104
- package/crates/team-agent/src/platform/file_lock.rs +0 -279
- package/crates/team-agent/src/platform/mod.rs +0 -5
- package/crates/team-agent/src/platform/process.rs +0 -545
- package/crates/team-agent/src/provider/adapter.rs +0 -1150
- package/crates/team-agent/src/provider/adapters/claude.rs +0 -78
- package/crates/team-agent/src/provider/adapters/claude_fork.rs +0 -131
- package/crates/team-agent/src/provider/adapters/copilot.rs +0 -75
- package/crates/team-agent/src/provider/adapters/copilot_fork.rs +0 -307
- package/crates/team-agent/src/provider/adapters/fake.rs +0 -18
- package/crates/team-agent/src/provider/adapters/mod.rs +0 -30
- package/crates/team-agent/src/provider/adapters/pi.rs +0 -106
- package/crates/team-agent/src/provider/approvals/mod.rs +0 -3
- package/crates/team-agent/src/provider/approvals/parsing.rs +0 -586
- package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +0 -205
- package/crates/team-agent/src/provider/argv_route.rs +0 -405
- package/crates/team-agent/src/provider/bypass_flags.rs +0 -116
- package/crates/team-agent/src/provider/classify.rs +0 -708
- package/crates/team-agent/src/provider/command_helpers.rs +0 -45
- package/crates/team-agent/src/provider/faults.rs +0 -165
- package/crates/team-agent/src/provider/helpers.rs +0 -52
- package/crates/team-agent/src/provider/mod.rs +0 -78
- package/crates/team-agent/src/provider/model_catalog.rs +0 -910
- package/crates/team-agent/src/provider/session/capture.rs +0 -2731
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +0 -123
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -172
- package/crates/team-agent/src/provider/session/context_fork.rs +0 -396
- package/crates/team-agent/src/provider/session/mod.rs +0 -36
- package/crates/team-agent/src/provider/session/resume.rs +0 -269
- package/crates/team-agent/src/provider/session_scan/claude.rs +0 -523
- package/crates/team-agent/src/provider/session_scan/common/tests.rs +0 -316
- package/crates/team-agent/src/provider/session_scan/common.rs +0 -654
- package/crates/team-agent/src/provider/session_scan/copilot.rs +0 -280
- package/crates/team-agent/src/provider/session_scan/pi.rs +0 -185
- package/crates/team-agent/src/provider/session_scan.rs +0 -71
- package/crates/team-agent/src/provider/startup_prompt.rs +0 -757
- package/crates/team-agent/src/provider/submit_now.rs +0 -71
- package/crates/team-agent/src/provider/testdata/copilot-ready-marker.txt +0 -5
- package/crates/team-agent/src/provider/testdata/copilot-trust-prompt.txt +0 -19
- package/crates/team-agent/src/provider/testdata/grok-models-authenticated.stdout +0 -9
- package/crates/team-agent/src/provider/testdata/grok-models-unauthenticated.stdout +0 -7
- package/crates/team-agent/src/provider/tests/adapter.rs +0 -441
- package/crates/team-agent/src/provider/tests/classify.rs +0 -148
- package/crates/team-agent/src/provider/tests/command_helpers.rs +0 -35
- package/crates/team-agent/src/provider/tests/copilot_fork.rs +0 -191
- package/crates/team-agent/src/provider/tests/faults.rs +0 -200
- package/crates/team-agent/src/provider/tests/idle.rs +0 -177
- package/crates/team-agent/src/provider/tests/wire.rs +0 -213
- package/crates/team-agent/src/provider/tests.rs +0 -32
- package/crates/team-agent/src/provider/types.rs +0 -529
- package/crates/team-agent/src/provider/wire.rs +0 -394
- package/crates/team-agent/src/redaction.rs +0 -259
- package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +0 -248
- package/crates/team-agent/src/state/abnormal_watch.rs +0 -144
- package/crates/team-agent/src/state/identity.rs +0 -914
- package/crates/team-agent/src/state/identity_keys.rs +0 -132
- package/crates/team-agent/src/state/mod.rs +0 -74
- package/crates/team-agent/src/state/owner_gate.rs +0 -482
- package/crates/team-agent/src/state/ownership.rs +0 -563
- package/crates/team-agent/src/state/paths.rs +0 -395
- package/crates/team-agent/src/state/persist.rs +0 -3811
- package/crates/team-agent/src/state/projection.rs +0 -1508
- package/crates/team-agent/src/state/repository/intent.rs +0 -14
- package/crates/team-agent/src/state/repository/tests.rs +0 -184
- package/crates/team-agent/src/state/repository.rs +0 -866
- package/crates/team-agent/src/state/selector.rs +0 -160
- package/crates/team-agent/src/state/testdata/state-rich.canonical.json +0 -133
- package/crates/team-agent/src/test_support/models_timeout_fixture.rs +0 -144
- package/crates/team-agent/src/tmux_backend/enter_rescue.rs +0 -325
- package/crates/team-agent/src/tmux_backend/enter_rescue_tests.rs +0 -432
- package/crates/team-agent/src/tmux_backend/native_input.rs +0 -513
- package/crates/team-agent/src/tmux_backend/native_input_tests.rs +0 -742
- package/crates/team-agent/src/tmux_backend/tests.rs +0 -4103
- package/crates/team-agent/src/tmux_backend.rs +0 -4492
- package/crates/team-agent/src/topology.rs +0 -537
- package/crates/team-agent/src/transport/enter_rescue.rs +0 -166
- package/crates/team-agent/src/transport/native_input.rs +0 -491
- package/crates/team-agent/src/transport/test_support.rs +0 -743
- package/crates/team-agent/src/transport/tests/behavior.rs +0 -326
- package/crates/team-agent/src/transport/tests/mod.rs +0 -194
- package/crates/team-agent/src/transport/tests/wire.rs +0 -574
- package/crates/team-agent/src/transport.rs +0 -1655
- package/crates/team-agent/src/transport_factory.rs +0 -819
|
@@ -1,1981 +0,0 @@
|
|
|
1
|
-
//! Read-only status: native runtime samples plus accepted launch model/effort.
|
|
2
|
-
//!
|
|
3
|
-
//! This intentionally does not reuse RuntimeSnapshot: the legacy snapshot reads
|
|
4
|
-
//! coordinator/db/history and carries diagnostic fields that are outside the
|
|
5
|
-
//! status brief contract.
|
|
6
|
-
|
|
7
|
-
use serde_json::{json, Map, Value};
|
|
8
|
-
use std::collections::{BTreeMap, BTreeSet};
|
|
9
|
-
use std::path::Path;
|
|
10
|
-
use std::process::Command;
|
|
11
|
-
|
|
12
|
-
#[cfg(test)]
|
|
13
|
-
use serde::Deserialize;
|
|
14
|
-
#[cfg(test)]
|
|
15
|
-
use sha2::{Digest, Sha256};
|
|
16
|
-
#[cfg(test)]
|
|
17
|
-
use std::fs::{File, OpenOptions};
|
|
18
|
-
#[cfg(test)]
|
|
19
|
-
use std::io::Read;
|
|
20
|
-
#[cfg(test)]
|
|
21
|
-
use std::path::PathBuf;
|
|
22
|
-
#[cfg(test)]
|
|
23
|
-
use std::process::{Child, ExitStatus, Stdio};
|
|
24
|
-
#[cfg(test)]
|
|
25
|
-
use std::sync::atomic::{AtomicBool, Ordering};
|
|
26
|
-
#[cfg(test)]
|
|
27
|
-
use std::sync::mpsc;
|
|
28
|
-
#[cfg(test)]
|
|
29
|
-
use std::sync::Arc;
|
|
30
|
-
#[cfg(test)]
|
|
31
|
-
use std::thread;
|
|
32
|
-
#[cfg(test)]
|
|
33
|
-
use std::time::{Duration, Instant};
|
|
34
|
-
|
|
35
|
-
#[cfg(test)]
|
|
36
|
-
const NODEPROBE_TIMEOUT: Duration = Duration::from_secs(2);
|
|
37
|
-
#[cfg(test)]
|
|
38
|
-
const NODEPROBE_OUTPUT_LIMIT: u64 = 1024 * 1024;
|
|
39
|
-
#[cfg(test)]
|
|
40
|
-
const NODEPROBE_KILL_GRACE: Duration = Duration::from_millis(100);
|
|
41
|
-
#[cfg(test)]
|
|
42
|
-
const NODEPROBE_RECEIPT_LIMIT: u64 = 64 * 1024;
|
|
43
|
-
#[cfg(test)]
|
|
44
|
-
const NODEPROBE_BINARY_LIMIT: u64 = 64 * 1024 * 1024;
|
|
45
|
-
#[cfg(test)]
|
|
46
|
-
const NODEPROBE_READ_CHUNK: usize = 64 * 1024;
|
|
47
|
-
#[cfg(test)]
|
|
48
|
-
const NODEPROBE_NAME: &str = "nodeprobe";
|
|
49
|
-
#[cfg(test)]
|
|
50
|
-
const NODEPROBE_RECEIPT_SUFFIX: &str = ".capability.json";
|
|
51
|
-
#[cfg(test)]
|
|
52
|
-
const NODEPROBE_RECEIPT_SCHEMA: &str = "nodeprobe-capability-v1";
|
|
53
|
-
#[cfg(test)]
|
|
54
|
-
const NODEPROBE_SOURCE_REPO: &str = "Florious95/team-agent-scratch/nodeprobe";
|
|
55
|
-
#[cfg(test)]
|
|
56
|
-
const NODEPROBE_SOURCE_COMMIT: &str = "ff316dc0afe8ab280e61d30934e7624579be6224";
|
|
57
|
-
#[cfg(test)]
|
|
58
|
-
const NODEPROBE_SOURCE_TREE: &str = "5217a41aa914ddcb72c27f39f1b4af9ead68b1b6";
|
|
59
|
-
#[cfg(test)]
|
|
60
|
-
const NODEPROBE_REPORT_SCHEMA: u64 = 1;
|
|
61
|
-
#[cfg(test)]
|
|
62
|
-
const NODEPROBE_CAPABILITIES: &[&str] = &["tmux.list-panes", "ps.pid_ppid_stat_comm"];
|
|
63
|
-
#[cfg(test)]
|
|
64
|
-
const NODEPROBE_FORBIDDEN: &[&str] = &[
|
|
65
|
-
"tmux.capture-pane",
|
|
66
|
-
"tmux.attach",
|
|
67
|
-
"tmux.send-keys",
|
|
68
|
-
"process.argv",
|
|
69
|
-
"pane_body",
|
|
70
|
-
];
|
|
71
|
-
|
|
72
|
-
#[cfg(test)]
|
|
73
|
-
thread_local! {
|
|
74
|
-
static TEST_NODEPROBE: std::cell::RefCell<Option<Vec<PathBuf>>> = const { std::cell::RefCell::new(None) };
|
|
75
|
-
static TEST_RESOLVER_DELAY: std::cell::RefCell<Option<TestResolverDelay>> = const { std::cell::RefCell::new(None) };
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
#[cfg(test)]
|
|
79
|
-
static NODEPROBE_RESOLVER_ACTIVE: AtomicBool = AtomicBool::new(false);
|
|
80
|
-
|
|
81
|
-
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
82
|
-
struct RegisteredNode {
|
|
83
|
-
name: String,
|
|
84
|
-
provider: String,
|
|
85
|
-
model: Option<String>,
|
|
86
|
-
effort: Option<String>,
|
|
87
|
-
endpoint: Option<String>,
|
|
88
|
-
session: Option<String>,
|
|
89
|
-
window: Option<String>,
|
|
90
|
-
pane: Option<String>,
|
|
91
|
-
lifecycle: Option<String>,
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
95
|
-
struct ProbeNode {
|
|
96
|
-
socket: String,
|
|
97
|
-
session: String,
|
|
98
|
-
window: String,
|
|
99
|
-
pane: String,
|
|
100
|
-
provider: String,
|
|
101
|
-
activity: String,
|
|
102
|
-
health: String,
|
|
103
|
-
session_name: Option<String>,
|
|
104
|
-
evidence_method: Option<String>,
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
108
|
-
struct BriefNode {
|
|
109
|
-
name: String,
|
|
110
|
-
provider: String,
|
|
111
|
-
model: Option<String>,
|
|
112
|
-
effort: Option<String>,
|
|
113
|
-
runtime_status: String,
|
|
114
|
-
activity: String,
|
|
115
|
-
health: String,
|
|
116
|
-
session_name: Option<String>,
|
|
117
|
-
tmux_command: Option<String>,
|
|
118
|
-
observation_reason: Option<&'static str>,
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
122
|
-
struct AttachContext {
|
|
123
|
-
endpoint: String,
|
|
124
|
-
session: String,
|
|
125
|
-
window: String,
|
|
126
|
-
pane: String,
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
#[derive(Debug, Default)]
|
|
130
|
-
struct ProbeResult {
|
|
131
|
-
nodes: Vec<ProbeNode>,
|
|
132
|
-
exited: BTreeSet<(String, String, String)>,
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
#[derive(Debug, Deserialize)]
|
|
136
|
-
#[cfg(test)]
|
|
137
|
-
struct NodeprobeCapabilityReceipt {
|
|
138
|
-
schema: String,
|
|
139
|
-
binary: String,
|
|
140
|
-
binary_sha256: String,
|
|
141
|
-
source_repo: String,
|
|
142
|
-
source_commit: String,
|
|
143
|
-
source_tree: String,
|
|
144
|
-
target: String,
|
|
145
|
-
report_schema: u64,
|
|
146
|
-
capabilities: Vec<String>,
|
|
147
|
-
forbidden: Vec<String>,
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
enum MatchResult<'a> {
|
|
151
|
-
Missing,
|
|
152
|
-
Unique(&'a ProbeNode),
|
|
153
|
-
Ambiguous,
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/// The CLI's concise JSON projection. `agent` filters the registered list but
|
|
157
|
-
/// never synthesizes an unregistered node.
|
|
158
|
-
pub(crate) fn status_brief_scoped(workspace: &Path, state: &Value, agent: Option<&str>) -> Value {
|
|
159
|
-
let nodes = project_status_nodes(workspace, state, agent);
|
|
160
|
-
json!({
|
|
161
|
-
"nodes": nodes
|
|
162
|
-
.into_iter()
|
|
163
|
-
.map(|(node, _)| scoped_node_json(node, workspace, state))
|
|
164
|
-
.collect::<Vec<_>>()
|
|
165
|
-
})
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/// Human output keeps the legacy single-node form and groups shared attach
|
|
169
|
-
/// context only when multiple nodes make that repetition useful.
|
|
170
|
-
pub(crate) fn format_status_brief(workspace: &Path, state: &Value, agent: Option<&str>) -> String {
|
|
171
|
-
let nodes = project_status_nodes(workspace, state, agent);
|
|
172
|
-
let diagnostics = nodes.iter().filter(|(node, _)| node.observation_reason.is_some())
|
|
173
|
-
.map(|(node, _)| {
|
|
174
|
-
let value = scoped_node_json(node.clone(), workspace, state);
|
|
175
|
-
format!("observation {}: {}; next_action: {}", node.name,
|
|
176
|
-
value["observation_reason"].as_str().unwrap_or("observation_inconclusive"),
|
|
177
|
-
value["next_action"].as_str().unwrap_or(""))
|
|
178
|
-
}).collect::<Vec<_>>();
|
|
179
|
-
let mut output = if nodes.len() <= 1 {
|
|
180
|
-
nodes.into_iter().filter_map(|(node, _)| format_brief_node(&node.into_json()))
|
|
181
|
-
.collect::<Vec<_>>().join("\n")
|
|
182
|
-
} else { format_multi_node_brief(nodes) };
|
|
183
|
-
if !diagnostics.is_empty() {
|
|
184
|
-
output.push('\n');
|
|
185
|
-
output.push_str(&diagnostics.join("\n"));
|
|
186
|
-
}
|
|
187
|
-
output
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
fn project_status_nodes(
|
|
191
|
-
_workspace: &Path,
|
|
192
|
-
state: &Value,
|
|
193
|
-
agent: Option<&str>,
|
|
194
|
-
) -> Vec<(BriefNode, Option<AttachContext>)> {
|
|
195
|
-
let registered = registered_nodes(state, agent);
|
|
196
|
-
let legacy: Vec<_> = registered
|
|
197
|
-
.iter()
|
|
198
|
-
.filter(|_node| {
|
|
199
|
-
#[cfg(unix)]
|
|
200
|
-
if crate::contract_runtime::registry::descriptor(&_node.provider).is_some() {
|
|
201
|
-
return false;
|
|
202
|
-
}
|
|
203
|
-
true
|
|
204
|
-
})
|
|
205
|
-
.cloned()
|
|
206
|
-
.collect();
|
|
207
|
-
let probes = probe_registered_endpoints(&legacy);
|
|
208
|
-
registered
|
|
209
|
-
.iter()
|
|
210
|
-
.map(|node| {
|
|
211
|
-
#[cfg(unix)]
|
|
212
|
-
if crate::contract_runtime::registry::descriptor(&node.provider).is_some() {
|
|
213
|
-
let mut brief = BriefNode::unknown(node).with_reason("native_runtime_projection_unavailable");
|
|
214
|
-
if let Ok(native) = crate::contract_runtime::framework::project_seat(
|
|
215
|
-
_workspace,
|
|
216
|
-
&crate::state::projection::team_state_key(state),
|
|
217
|
-
&node.name,
|
|
218
|
-
) {
|
|
219
|
-
brief.runtime_status = native["status"].as_str().unwrap_or("unknown").into();
|
|
220
|
-
brief.observation_reason = match brief.runtime_status.as_str() {
|
|
221
|
-
"running" => Some("activity_or_health_not_observed"),
|
|
222
|
-
"stopped" => None,
|
|
223
|
-
_ => Some("native_runtime_not_ready"),
|
|
224
|
-
};
|
|
225
|
-
brief.model = native["model"].as_str().map(str::to_owned);
|
|
226
|
-
brief.effort = native["effort"].as_str().map(str::to_owned);
|
|
227
|
-
if brief.runtime_status == "running" {
|
|
228
|
-
brief.tmux_command = native["native_endpoint"].as_str().map(|endpoint| {
|
|
229
|
-
format!("tmux -S {} attach-session", shell_quote(endpoint))
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
// Process alive is T1 only: activity/health remain unknown until
|
|
234
|
-
// independently observed. Never probe a private %0 on old tmux.
|
|
235
|
-
return (brief, None);
|
|
236
|
-
}
|
|
237
|
-
project_node_with_attach(node, probes.get(node.endpoint.as_deref().unwrap_or("")))
|
|
238
|
-
})
|
|
239
|
-
.collect()
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
pub(crate) fn registered_agent_exists(state: &Value, agent: &str) -> bool {
|
|
243
|
-
registered_nodes(state, None)
|
|
244
|
-
.iter()
|
|
245
|
-
.any(|node| node.name == agent)
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
#[cfg(test)]
|
|
249
|
-
pub(crate) fn with_test_nodeprobe<R>(path: PathBuf, func: impl FnOnce() -> R) -> R {
|
|
250
|
-
with_test_nodeprobe_candidates(vec![path], func)
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
#[cfg(test)]
|
|
254
|
-
pub(crate) fn with_test_nodeprobe_unbound<R>(path: PathBuf, func: impl FnOnce() -> R) -> R {
|
|
255
|
-
with_test_nodeprobe_candidate(vec![path], func)
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
#[cfg(test)]
|
|
259
|
-
pub(crate) fn with_test_nodeprobe_candidates<R>(
|
|
260
|
-
paths: Vec<PathBuf>,
|
|
261
|
-
func: impl FnOnce() -> R,
|
|
262
|
-
) -> R {
|
|
263
|
-
for path in &paths {
|
|
264
|
-
write_test_capability_receipt(path);
|
|
265
|
-
}
|
|
266
|
-
with_test_nodeprobe_candidate(paths, func)
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
#[cfg(test)]
|
|
270
|
-
#[derive(Clone)]
|
|
271
|
-
pub(crate) struct ResolverDelaySignal {
|
|
272
|
-
entered: Arc<AtomicBool>,
|
|
273
|
-
finished: Arc<AtomicBool>,
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
#[cfg(test)]
|
|
277
|
-
impl ResolverDelaySignal {
|
|
278
|
-
pub(crate) fn entered(&self) -> bool {
|
|
279
|
-
self.entered.load(Ordering::Acquire)
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
pub(crate) fn finished(&self) -> bool {
|
|
283
|
-
self.finished.load(Ordering::Acquire)
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
#[cfg(test)]
|
|
288
|
-
#[derive(Clone)]
|
|
289
|
-
struct TestResolverDelay {
|
|
290
|
-
delay: Duration,
|
|
291
|
-
signal: ResolverDelaySignal,
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
#[cfg(test)]
|
|
295
|
-
pub(crate) fn with_test_nodeprobe_resolver_delay<R>(
|
|
296
|
-
delay: Duration,
|
|
297
|
-
func: impl FnOnce(&ResolverDelaySignal) -> R,
|
|
298
|
-
) -> R {
|
|
299
|
-
struct Guard(Option<TestResolverDelay>);
|
|
300
|
-
impl Drop for Guard {
|
|
301
|
-
fn drop(&mut self) {
|
|
302
|
-
TEST_RESOLVER_DELAY.with(|slot| *slot.borrow_mut() = self.0.take());
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
let config = TestResolverDelay {
|
|
306
|
-
delay,
|
|
307
|
-
signal: ResolverDelaySignal {
|
|
308
|
-
entered: Arc::new(AtomicBool::new(false)),
|
|
309
|
-
finished: Arc::new(AtomicBool::new(false)),
|
|
310
|
-
},
|
|
311
|
-
};
|
|
312
|
-
let signal = config.signal.clone();
|
|
313
|
-
let previous = TEST_RESOLVER_DELAY.with(|slot| slot.replace(Some(config)));
|
|
314
|
-
let _guard = Guard(previous);
|
|
315
|
-
func(&signal)
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
#[cfg(test)]
|
|
319
|
-
fn with_test_nodeprobe_candidate<R>(paths: Vec<PathBuf>, func: impl FnOnce() -> R) -> R {
|
|
320
|
-
struct Guard(Option<Vec<PathBuf>>);
|
|
321
|
-
impl Drop for Guard {
|
|
322
|
-
fn drop(&mut self) {
|
|
323
|
-
TEST_NODEPROBE.with(|slot| *slot.borrow_mut() = self.0.take());
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
let previous = TEST_NODEPROBE.with(|slot| slot.replace(Some(paths)));
|
|
327
|
-
let _guard = Guard(previous);
|
|
328
|
-
let outcome = std::panic::catch_unwind(std::panic::AssertUnwindSafe(func));
|
|
329
|
-
let deadline = Instant::now() + NODEPROBE_TIMEOUT;
|
|
330
|
-
while NODEPROBE_RESOLVER_ACTIVE.load(Ordering::Acquire) && Instant::now() < deadline {
|
|
331
|
-
thread::yield_now();
|
|
332
|
-
}
|
|
333
|
-
let resolver_idle = !NODEPROBE_RESOLVER_ACTIVE.load(Ordering::Acquire);
|
|
334
|
-
match outcome {
|
|
335
|
-
Ok(result) => {
|
|
336
|
-
assert!(
|
|
337
|
-
resolver_idle,
|
|
338
|
-
"test nodeprobe fixture ended while resolver worker was still active"
|
|
339
|
-
);
|
|
340
|
-
result
|
|
341
|
-
}
|
|
342
|
-
Err(payload) => std::panic::resume_unwind(payload),
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
#[cfg(test)]
|
|
347
|
-
fn write_test_capability_receipt(path: &Path) {
|
|
348
|
-
let binary_sha256 =
|
|
349
|
-
sha256_file(path, Instant::now() + NODEPROBE_TIMEOUT).expect("test nodeprobe fixture hash");
|
|
350
|
-
let receipt = json!({
|
|
351
|
-
"schema": NODEPROBE_RECEIPT_SCHEMA,
|
|
352
|
-
"binary": NODEPROBE_NAME,
|
|
353
|
-
"binary_sha256": binary_sha256,
|
|
354
|
-
"source_repo": NODEPROBE_SOURCE_REPO,
|
|
355
|
-
"source_commit": NODEPROBE_SOURCE_COMMIT,
|
|
356
|
-
"source_tree": NODEPROBE_SOURCE_TREE,
|
|
357
|
-
"target": current_nodeprobe_target().expect("test target"),
|
|
358
|
-
"report_schema": NODEPROBE_REPORT_SCHEMA,
|
|
359
|
-
"capabilities": NODEPROBE_CAPABILITIES,
|
|
360
|
-
"forbidden": NODEPROBE_FORBIDDEN,
|
|
361
|
-
});
|
|
362
|
-
std::fs::write(
|
|
363
|
-
nodeprobe_receipt_path(path),
|
|
364
|
-
serde_json::to_vec(&receipt).unwrap(),
|
|
365
|
-
)
|
|
366
|
-
.expect("write test nodeprobe capability receipt");
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
fn format_brief_node(value: &Value) -> Option<String> {
|
|
370
|
-
Some(format!(
|
|
371
|
-
"name: {} provider: {} model: {} effort: {} runtime_status: {} activity: {} health: {} session_name: {} tmux_command: {}",
|
|
372
|
-
value.get("name")?.as_str()?,
|
|
373
|
-
value.get("provider")?.as_str()?,
|
|
374
|
-
display_optional(value.get("model")?),
|
|
375
|
-
display_optional(value.get("effort")?),
|
|
376
|
-
value.get("runtime_status")?.as_str()?,
|
|
377
|
-
value.get("activity")?.as_str()?,
|
|
378
|
-
value.get("health")?.as_str()?,
|
|
379
|
-
display_optional(value.get("session_name")?),
|
|
380
|
-
display_optional(value.get("tmux_command")?),
|
|
381
|
-
))
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
fn format_multi_node_brief(nodes: Vec<(BriefNode, Option<AttachContext>)>) -> String {
|
|
385
|
-
let mut groups = Vec::<(String, String)>::new();
|
|
386
|
-
for (_, context) in &nodes {
|
|
387
|
-
let Some(context) = context else { continue };
|
|
388
|
-
if !groups
|
|
389
|
-
.iter()
|
|
390
|
-
.any(|(endpoint, session)| endpoint == &context.endpoint && session == &context.session)
|
|
391
|
-
{
|
|
392
|
-
groups.push((context.endpoint.clone(), context.session.clone()));
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
let mut lines = groups
|
|
397
|
-
.iter()
|
|
398
|
-
.enumerate()
|
|
399
|
-
.map(|(index, (endpoint, session))| format_attach_template(index + 1, endpoint, session))
|
|
400
|
-
.collect::<Vec<_>>();
|
|
401
|
-
if !groups.is_empty() {
|
|
402
|
-
lines.push(
|
|
403
|
-
"TMUX templates: replace <target> with the window.pane part of the matching ATTACH value."
|
|
404
|
-
.to_string(),
|
|
405
|
-
);
|
|
406
|
-
}
|
|
407
|
-
lines.push(
|
|
408
|
-
"NAME\tPROVIDER\tMODEL\tEFFORT\tRUNTIME_STATUS\tACTIVITY\tHEALTH\tSESSION_NAME\tATTACH"
|
|
409
|
-
.to_string(),
|
|
410
|
-
);
|
|
411
|
-
for (node, context) in nodes {
|
|
412
|
-
let attach = context
|
|
413
|
-
.as_ref()
|
|
414
|
-
.and_then(|context| {
|
|
415
|
-
groups
|
|
416
|
-
.iter()
|
|
417
|
-
.position(|(endpoint, session)| {
|
|
418
|
-
endpoint == &context.endpoint && session == &context.session
|
|
419
|
-
})
|
|
420
|
-
.map(|index| format!("{}:{}.{}", index + 1, context.window, context.pane))
|
|
421
|
-
})
|
|
422
|
-
.unwrap_or_else(|| "null".to_string());
|
|
423
|
-
lines.push(
|
|
424
|
-
[
|
|
425
|
-
escape_human_cell(&node.name),
|
|
426
|
-
escape_human_cell(&node.provider),
|
|
427
|
-
escape_human_cell(node.model.as_deref().unwrap_or("null")),
|
|
428
|
-
escape_human_cell(node.effort.as_deref().unwrap_or("null")),
|
|
429
|
-
escape_human_cell(&node.runtime_status),
|
|
430
|
-
escape_human_cell(&node.activity),
|
|
431
|
-
escape_human_cell(&node.health),
|
|
432
|
-
escape_human_cell(node.session_name.as_deref().unwrap_or("null")),
|
|
433
|
-
escape_human_cell(&attach),
|
|
434
|
-
]
|
|
435
|
-
.join("\t"),
|
|
436
|
-
);
|
|
437
|
-
}
|
|
438
|
-
lines.join("\n")
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
fn format_attach_template(group: usize, endpoint: &str, session: &str) -> String {
|
|
442
|
-
let flag = if Path::new(endpoint).is_absolute() {
|
|
443
|
-
"-S"
|
|
444
|
-
} else {
|
|
445
|
-
"-L"
|
|
446
|
-
};
|
|
447
|
-
let target = format!("{session}:<target>");
|
|
448
|
-
format!(
|
|
449
|
-
"TMUX[{group}] tmux {flag} {} attach -t {}",
|
|
450
|
-
shell_quote(endpoint),
|
|
451
|
-
shell_quote(&target)
|
|
452
|
-
)
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
fn escape_human_cell(value: &str) -> String {
|
|
456
|
-
value
|
|
457
|
-
.replace('\\', "\\\\")
|
|
458
|
-
.replace('\t', "\\t")
|
|
459
|
-
.replace('\n', "\\n")
|
|
460
|
-
.replace('\r', "\\r")
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
fn display_optional(value: &Value) -> String {
|
|
464
|
-
value
|
|
465
|
-
.as_str()
|
|
466
|
-
.map(|value| value.to_string())
|
|
467
|
-
.unwrap_or_else(|| "null".to_string())
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
fn registered_nodes(state: &Value, selected: Option<&str>) -> Vec<RegisteredNode> {
|
|
471
|
-
// A projected state can still carry stale top-level agents. Once the
|
|
472
|
-
// selector identified a canonical team entry, that entry is authoritative;
|
|
473
|
-
// an empty/missing nested roster must not fall back to the stale projection.
|
|
474
|
-
let canonical_team = state
|
|
475
|
-
.get("active_team_key")
|
|
476
|
-
.and_then(Value::as_str)
|
|
477
|
-
.and_then(|key| state.get("teams").and_then(|teams| teams.get(key)));
|
|
478
|
-
let (agents, lifecycle, defaults) = match canonical_team {
|
|
479
|
-
Some(team) => (
|
|
480
|
-
team.get("agents").and_then(Value::as_object),
|
|
481
|
-
team.get("agent_lifecycle").and_then(Value::as_object),
|
|
482
|
-
team,
|
|
483
|
-
),
|
|
484
|
-
None => (
|
|
485
|
-
state.get("agents").and_then(Value::as_object),
|
|
486
|
-
state.get("agent_lifecycle").and_then(Value::as_object),
|
|
487
|
-
state,
|
|
488
|
-
),
|
|
489
|
-
};
|
|
490
|
-
let Some(agents) = agents else {
|
|
491
|
-
return Vec::new();
|
|
492
|
-
};
|
|
493
|
-
agents
|
|
494
|
-
.iter()
|
|
495
|
-
.filter(|(name, _)| selected.is_none_or(|selected| selected == name.as_str()))
|
|
496
|
-
.filter(|(name, _)| {
|
|
497
|
-
!lifecycle
|
|
498
|
-
.and_then(|entries| entries.get(*name))
|
|
499
|
-
.and_then(|entry| entry.get("state"))
|
|
500
|
-
.and_then(Value::as_str)
|
|
501
|
-
.is_some_and(|state| state == "retired")
|
|
502
|
-
})
|
|
503
|
-
.map(|(name, value)| registered_node(name, value, defaults))
|
|
504
|
-
.collect()
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
fn registered_node(name: &str, value: &Value, state: &Value) -> RegisteredNode {
|
|
508
|
-
let display = value.pointer("/display").unwrap_or(&Value::Null);
|
|
509
|
-
let target = value.pointer("/target").unwrap_or(&Value::Null);
|
|
510
|
-
let provider = string_at(value, &["provider"])
|
|
511
|
-
.or_else(|| string_at(state, &["provider"]))
|
|
512
|
-
.unwrap_or_else(|| "unknown".to_string());
|
|
513
|
-
RegisteredNode {
|
|
514
|
-
name: name.to_string(),
|
|
515
|
-
provider,
|
|
516
|
-
// Accepted launch settings, not pending role-file edits or guessed
|
|
517
|
-
// provider defaults. Runtime liveness remains a separate signal.
|
|
518
|
-
model: string_at(value, &["model"]),
|
|
519
|
-
effort: string_at(value, &["effort"]),
|
|
520
|
-
endpoint: endpoint(value).or_else(|| endpoint(state)),
|
|
521
|
-
session: first_string(value, &["session_name", "session"])
|
|
522
|
-
.or_else(|| {
|
|
523
|
-
first_string(
|
|
524
|
-
display,
|
|
525
|
-
&["target_worker_session", "display_session", "linked_session"],
|
|
526
|
-
)
|
|
527
|
-
})
|
|
528
|
-
.or_else(|| first_string(target, &["session_name", "session"]))
|
|
529
|
-
.or_else(|| first_string(state, &["session_name"])),
|
|
530
|
-
window: first_string(value, &["window_name", "window", "layout_window"])
|
|
531
|
-
.or_else(|| first_string(display, &["window", "window_name", "layout_window"]))
|
|
532
|
-
.or_else(|| first_string(target, &["window_name", "window", "layout_window"])),
|
|
533
|
-
pane: first_string(value, &["pane_id"])
|
|
534
|
-
.or_else(|| first_string(display, &["pane_id"]))
|
|
535
|
-
.or_else(|| first_string(target, &["pane_id"])),
|
|
536
|
-
lifecycle: string_at(value, &["status"]).map(|status| status.to_ascii_lowercase()),
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
fn endpoint(value: &Value) -> Option<String> {
|
|
541
|
-
first_string(value, &["tmux_endpoint", "tmux_socket", "socket"]).or_else(|| {
|
|
542
|
-
first_string(
|
|
543
|
-
value.pointer("/transport").unwrap_or(&Value::Null),
|
|
544
|
-
&["tmux_endpoint", "tmux_socket", "endpoint", "socket"],
|
|
545
|
-
)
|
|
546
|
-
})
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
fn string_at(value: &Value, keys: &[&str]) -> Option<String> {
|
|
550
|
-
first_string(value, keys)
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
fn first_string(value: &Value, keys: &[&str]) -> Option<String> {
|
|
554
|
-
keys.iter().find_map(|key| {
|
|
555
|
-
value
|
|
556
|
-
.get(*key)
|
|
557
|
-
.and_then(Value::as_str)
|
|
558
|
-
.filter(|value| !value.is_empty())
|
|
559
|
-
.map(str::to_string)
|
|
560
|
-
})
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
fn probe_registered_endpoints(nodes: &[RegisteredNode]) -> BTreeMap<String, Option<ProbeResult>> {
|
|
564
|
-
#[cfg(test)]
|
|
565
|
-
{
|
|
566
|
-
// Keep the legacy fixture seam for existing hermetic tests; production
|
|
567
|
-
// status never searches for or executes nodeprobe.
|
|
568
|
-
if TEST_NODEPROBE.with(|slot| slot.borrow().is_some()) {
|
|
569
|
-
return probe_registered_endpoints_with_test_nodeprobe(nodes);
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
let mut endpoints = BTreeMap::new();
|
|
573
|
-
for endpoint in nodes.iter().filter_map(|node| node.endpoint.as_deref()) {
|
|
574
|
-
if endpoints.contains_key(endpoint) {
|
|
575
|
-
continue;
|
|
576
|
-
}
|
|
577
|
-
endpoints.insert(
|
|
578
|
-
endpoint.to_string(),
|
|
579
|
-
sample_native_endpoint(endpoint, nodes),
|
|
580
|
-
);
|
|
581
|
-
}
|
|
582
|
-
endpoints
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
fn sample_native_endpoint(endpoint: &str, registered: &[RegisteredNode]) -> Option<ProbeResult> {
|
|
586
|
-
let output = run_native_tmux_list_panes(endpoint)?;
|
|
587
|
-
Some(sample_native_panes(
|
|
588
|
-
&output,
|
|
589
|
-
endpoint,
|
|
590
|
-
registered,
|
|
591
|
-
process_snapshots,
|
|
592
|
-
))
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
fn sample_native_panes(
|
|
596
|
-
output: &str,
|
|
597
|
-
endpoint: &str,
|
|
598
|
-
registered: &[RegisteredNode],
|
|
599
|
-
snapshots: impl FnOnce(&BTreeSet<u32>) -> BTreeMap<u32, ProcessSnapshot>,
|
|
600
|
-
) -> ProbeResult {
|
|
601
|
-
let panes = output
|
|
602
|
-
.lines()
|
|
603
|
-
.filter_map(native_pane_fields)
|
|
604
|
-
.collect::<Vec<_>>();
|
|
605
|
-
let pids = panes
|
|
606
|
-
.iter()
|
|
607
|
-
.filter_map(|fields| native_pane_pid(fields[3]))
|
|
608
|
-
.collect::<BTreeSet<_>>();
|
|
609
|
-
let processes = if pids.is_empty() {
|
|
610
|
-
BTreeMap::new()
|
|
611
|
-
} else {
|
|
612
|
-
snapshots(&pids)
|
|
613
|
-
};
|
|
614
|
-
let exited = panes.iter().filter(|fields| {
|
|
615
|
-
native_pane_pid(fields[3]).and_then(|pid| processes.get(&pid)).is_some_and(|p| p.zombie)
|
|
616
|
-
}).map(|fields| (fields[0].to_string(), fields[1].to_string(), fields[2].to_string())).collect();
|
|
617
|
-
let nodes = panes
|
|
618
|
-
.into_iter()
|
|
619
|
-
.filter_map(|fields| parse_native_pane(fields, endpoint, registered, &processes))
|
|
620
|
-
.collect();
|
|
621
|
-
ProbeResult { nodes, exited }
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
fn native_pane_fields(line: &str) -> Option<[&str; 5]> {
|
|
625
|
-
let mut fields = line.split('\t');
|
|
626
|
-
let session = fields.next()?;
|
|
627
|
-
let window = fields.next()?;
|
|
628
|
-
let pane = fields.next()?;
|
|
629
|
-
let pid = fields.next().unwrap_or_default();
|
|
630
|
-
let command = fields.next().unwrap_or_default();
|
|
631
|
-
if session.is_empty() || window.is_empty() || pane.is_empty() {
|
|
632
|
-
return None;
|
|
633
|
-
}
|
|
634
|
-
Some([session, window, pane, pid, command])
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
fn native_pane_pid(pid: &str) -> Option<u32> {
|
|
638
|
-
pid.parse::<u32>()
|
|
639
|
-
.ok()
|
|
640
|
-
.filter(|pid| *pid > 0 && *pid <= i32::MAX as u32)
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
fn run_native_tmux_list_panes(endpoint: &str) -> Option<String> {
|
|
644
|
-
const FORMAT: &str =
|
|
645
|
-
"#{session_name}\t#{window_name}\t#{pane_id}\t#{pane_pid}\t#{pane_current_command}";
|
|
646
|
-
let flag = if Path::new(endpoint).is_absolute() {
|
|
647
|
-
"-S"
|
|
648
|
-
} else {
|
|
649
|
-
"-L"
|
|
650
|
-
};
|
|
651
|
-
let output = Command::new("tmux")
|
|
652
|
-
.arg(flag)
|
|
653
|
-
.arg(endpoint)
|
|
654
|
-
.args(["list-panes", "-a", "-F", FORMAT])
|
|
655
|
-
.output()
|
|
656
|
-
.ok()?;
|
|
657
|
-
output
|
|
658
|
-
.status
|
|
659
|
-
.success()
|
|
660
|
-
.then(|| String::from_utf8(output.stdout).ok())?
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
fn parse_native_pane(
|
|
664
|
-
fields: [&str; 5],
|
|
665
|
-
endpoint: &str,
|
|
666
|
-
registered: &[RegisteredNode],
|
|
667
|
-
processes: &BTreeMap<u32, ProcessSnapshot>,
|
|
668
|
-
) -> Option<ProbeNode> {
|
|
669
|
-
let [session, window, pane, pid, command] = fields;
|
|
670
|
-
let session = session.to_string();
|
|
671
|
-
let window = window.to_string();
|
|
672
|
-
let pane = pane.to_string();
|
|
673
|
-
let matched = registered.iter().find(|node| {
|
|
674
|
-
node.endpoint.as_deref() == Some(endpoint)
|
|
675
|
-
&& node.session.as_deref() == Some(session.as_str())
|
|
676
|
-
&& node.window.as_deref().is_none_or(|value| value == window)
|
|
677
|
-
&& node.pane.as_deref() == Some(pane.as_str())
|
|
678
|
-
});
|
|
679
|
-
if !pid.is_empty() {
|
|
680
|
-
let snapshot = processes.get(&native_pane_pid(pid)?)?;
|
|
681
|
-
if snapshot.zombie {
|
|
682
|
-
return None;
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
let provider = matched
|
|
686
|
-
.map(|node| node.provider.clone())
|
|
687
|
-
.unwrap_or_else(|| "unknown".to_string());
|
|
688
|
-
let activity = if command.is_empty() {
|
|
689
|
-
"unknown"
|
|
690
|
-
} else if matches!(command, "bash" | "fish" | "sh" | "zsh" | "-bash" | "-zsh") {
|
|
691
|
-
"idle"
|
|
692
|
-
} else {
|
|
693
|
-
"working"
|
|
694
|
-
};
|
|
695
|
-
Some(ProbeNode {
|
|
696
|
-
socket: endpoint.to_string(),
|
|
697
|
-
session: session.clone(),
|
|
698
|
-
window: window.clone(),
|
|
699
|
-
pane,
|
|
700
|
-
provider,
|
|
701
|
-
activity: activity.to_string(),
|
|
702
|
-
health: "normal".to_string(),
|
|
703
|
-
session_name: Some(session),
|
|
704
|
-
evidence_method: Some("native_tmux".to_string()),
|
|
705
|
-
})
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
struct ProcessSnapshot {
|
|
709
|
-
zombie: bool,
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
fn process_snapshot_command(pids: &BTreeSet<u32>) -> Command {
|
|
713
|
-
let pids = pids
|
|
714
|
-
.iter()
|
|
715
|
-
.map(u32::to_string)
|
|
716
|
-
.collect::<Vec<_>>()
|
|
717
|
-
.join(",");
|
|
718
|
-
let mut command = Command::new("ps");
|
|
719
|
-
command.args(["-o", "pid=,ppid=,stat=,comm=", "-p", &pids]);
|
|
720
|
-
command
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
fn process_snapshots(pids: &BTreeSet<u32>) -> BTreeMap<u32, ProcessSnapshot> {
|
|
724
|
-
if pids.is_empty() {
|
|
725
|
-
return BTreeMap::new();
|
|
726
|
-
}
|
|
727
|
-
let Ok(output) = process_snapshot_command(pids).output() else {
|
|
728
|
-
return BTreeMap::new();
|
|
729
|
-
};
|
|
730
|
-
if !output.status.success() {
|
|
731
|
-
return BTreeMap::new();
|
|
732
|
-
}
|
|
733
|
-
parse_process_snapshots(&output.stdout, pids)
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
fn parse_process_snapshots(
|
|
737
|
-
bytes: &[u8],
|
|
738
|
-
requested: &BTreeSet<u32>,
|
|
739
|
-
) -> BTreeMap<u32, ProcessSnapshot> {
|
|
740
|
-
let mut snapshots = BTreeMap::<u32, ProcessSnapshot>::new();
|
|
741
|
-
let output = String::from_utf8_lossy(bytes);
|
|
742
|
-
for line in output.lines() {
|
|
743
|
-
let mut fields = line.split_whitespace();
|
|
744
|
-
let Some(pid) = fields.next().and_then(native_pane_pid) else {
|
|
745
|
-
continue;
|
|
746
|
-
};
|
|
747
|
-
if !requested.contains(&pid) {
|
|
748
|
-
continue;
|
|
749
|
-
}
|
|
750
|
-
let Some(_ppid) = fields.next() else {
|
|
751
|
-
continue;
|
|
752
|
-
};
|
|
753
|
-
let Some(stat) = fields.next() else {
|
|
754
|
-
continue;
|
|
755
|
-
};
|
|
756
|
-
let zombie = stat.contains('Z');
|
|
757
|
-
snapshots
|
|
758
|
-
.entry(pid)
|
|
759
|
-
.and_modify(|snapshot| snapshot.zombie |= zombie)
|
|
760
|
-
.or_insert(ProcessSnapshot { zombie });
|
|
761
|
-
}
|
|
762
|
-
snapshots
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
#[cfg(test)]
|
|
766
|
-
fn probe_registered_endpoints_with_test_nodeprobe(
|
|
767
|
-
nodes: &[RegisteredNode],
|
|
768
|
-
) -> BTreeMap<String, Option<ProbeResult>> {
|
|
769
|
-
let deadline = Instant::now() + NODEPROBE_TIMEOUT;
|
|
770
|
-
let candidates = nodeprobe_candidates();
|
|
771
|
-
let resolver_options = resolver_options();
|
|
772
|
-
let mut endpoints = BTreeMap::new();
|
|
773
|
-
let mut selected_binary = None;
|
|
774
|
-
let mut resolved = false;
|
|
775
|
-
for endpoint in nodes.iter().filter_map(|node| node.endpoint.as_deref()) {
|
|
776
|
-
if endpoints.contains_key(endpoint) {
|
|
777
|
-
continue;
|
|
778
|
-
}
|
|
779
|
-
if !resolved {
|
|
780
|
-
selected_binary =
|
|
781
|
-
resolve_nodeprobe_binary(candidates.clone(), deadline, resolver_options.clone());
|
|
782
|
-
resolved = true;
|
|
783
|
-
}
|
|
784
|
-
let sampled = selected_binary.as_deref().and_then(|binary| {
|
|
785
|
-
run_nodeprobe(binary, endpoint, deadline)
|
|
786
|
-
.and_then(|bytes| parse_probe(&bytes, endpoint).ok())
|
|
787
|
-
});
|
|
788
|
-
endpoints.insert(endpoint.to_string(), sampled);
|
|
789
|
-
}
|
|
790
|
-
endpoints
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
#[cfg(test)]
|
|
794
|
-
fn run_nodeprobe(binary: &Path, endpoint: &str, deadline: Instant) -> Option<Vec<u8>> {
|
|
795
|
-
if Instant::now() >= deadline {
|
|
796
|
-
return None;
|
|
797
|
-
}
|
|
798
|
-
let mut child = spawn_nodeprobe(binary, endpoint)?;
|
|
799
|
-
let stdout = match child.stdout.take() {
|
|
800
|
-
Some(stdout) => stdout,
|
|
801
|
-
None => {
|
|
802
|
-
terminate_nodeprobe(&mut child);
|
|
803
|
-
return None;
|
|
804
|
-
}
|
|
805
|
-
};
|
|
806
|
-
let (tx, rx) = mpsc::channel();
|
|
807
|
-
thread::spawn(move || {
|
|
808
|
-
let mut bytes = Vec::new();
|
|
809
|
-
let read = stdout
|
|
810
|
-
.take(NODEPROBE_OUTPUT_LIMIT + 1)
|
|
811
|
-
.read_to_end(&mut bytes);
|
|
812
|
-
let _ = tx.send(read.map(|_| bytes));
|
|
813
|
-
});
|
|
814
|
-
loop {
|
|
815
|
-
let now = Instant::now();
|
|
816
|
-
if now >= deadline {
|
|
817
|
-
terminate_nodeprobe(&mut child);
|
|
818
|
-
let _ = rx.recv_timeout(NODEPROBE_KILL_GRACE);
|
|
819
|
-
return None;
|
|
820
|
-
}
|
|
821
|
-
let slice = deadline
|
|
822
|
-
.saturating_duration_since(now)
|
|
823
|
-
.min(Duration::from_millis(20));
|
|
824
|
-
match rx.recv_timeout(slice) {
|
|
825
|
-
Ok(Ok(bytes)) => {
|
|
826
|
-
let status = wait_child_bounded(&mut child, deadline)?;
|
|
827
|
-
if !status.success() || bytes.len() as u64 > NODEPROBE_OUTPUT_LIMIT {
|
|
828
|
-
terminate_nodeprobe(&mut child);
|
|
829
|
-
return None;
|
|
830
|
-
}
|
|
831
|
-
return Some(bytes);
|
|
832
|
-
}
|
|
833
|
-
Ok(Err(_)) => {
|
|
834
|
-
terminate_nodeprobe(&mut child);
|
|
835
|
-
return None;
|
|
836
|
-
}
|
|
837
|
-
Err(mpsc::RecvTimeoutError::Timeout) => match child.try_wait() {
|
|
838
|
-
Ok(Some(status)) => {
|
|
839
|
-
if !status.success() {
|
|
840
|
-
terminate_nodeprobe(&mut child);
|
|
841
|
-
let leftover = deadline.saturating_duration_since(Instant::now());
|
|
842
|
-
let _ = rx.recv_timeout(leftover.min(NODEPROBE_KILL_GRACE));
|
|
843
|
-
return None;
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
Ok(None) => {}
|
|
847
|
-
Err(_) => {
|
|
848
|
-
terminate_nodeprobe(&mut child);
|
|
849
|
-
return None;
|
|
850
|
-
}
|
|
851
|
-
},
|
|
852
|
-
Err(mpsc::RecvTimeoutError::Disconnected) => {
|
|
853
|
-
terminate_nodeprobe(&mut child);
|
|
854
|
-
return None;
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
|
|
860
|
-
#[cfg(test)]
|
|
861
|
-
fn wait_child_bounded(child: &mut Child, deadline: Instant) -> Option<ExitStatus> {
|
|
862
|
-
loop {
|
|
863
|
-
match child.try_wait() {
|
|
864
|
-
Ok(Some(status)) => return Some(status),
|
|
865
|
-
Ok(None) if Instant::now() < deadline => thread::sleep(Duration::from_millis(5)),
|
|
866
|
-
Ok(None) => {
|
|
867
|
-
terminate_nodeprobe(child);
|
|
868
|
-
return None;
|
|
869
|
-
}
|
|
870
|
-
Err(_) => {
|
|
871
|
-
terminate_nodeprobe(child);
|
|
872
|
-
return None;
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
#[cfg(test)]
|
|
879
|
-
fn terminate_nodeprobe(child: &mut Child) {
|
|
880
|
-
#[cfg(unix)]
|
|
881
|
-
{
|
|
882
|
-
let pid = child.id() as i32;
|
|
883
|
-
let _ = unsafe { libc::killpg(pid, libc::SIGKILL) };
|
|
884
|
-
}
|
|
885
|
-
let _ = child.kill();
|
|
886
|
-
let deadline = Instant::now() + NODEPROBE_KILL_GRACE;
|
|
887
|
-
while Instant::now() < deadline {
|
|
888
|
-
match child.try_wait() {
|
|
889
|
-
Ok(Some(_)) | Err(_) => return,
|
|
890
|
-
Ok(None) => thread::sleep(Duration::from_millis(5)),
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
#[cfg(test)]
|
|
896
|
-
fn spawn_nodeprobe(binary: &Path, endpoint: &str) -> Option<Child> {
|
|
897
|
-
let flag = if Path::new(endpoint).is_absolute() {
|
|
898
|
-
"-S"
|
|
899
|
-
} else {
|
|
900
|
-
"-L"
|
|
901
|
-
};
|
|
902
|
-
let mut command = Command::new(binary);
|
|
903
|
-
command.arg(flag).arg(endpoint);
|
|
904
|
-
configure_nodeprobe_command(&mut command);
|
|
905
|
-
command.spawn().ok()
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
#[derive(Clone, Default)]
|
|
909
|
-
#[cfg(test)]
|
|
910
|
-
struct ResolverOptions {
|
|
911
|
-
#[cfg(test)]
|
|
912
|
-
delay_after_selection: Option<TestResolverDelay>,
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
#[cfg(test)]
|
|
916
|
-
fn resolver_options() -> ResolverOptions {
|
|
917
|
-
#[cfg(test)]
|
|
918
|
-
{
|
|
919
|
-
return ResolverOptions {
|
|
920
|
-
delay_after_selection: TEST_RESOLVER_DELAY.with(|slot| slot.borrow().clone()),
|
|
921
|
-
};
|
|
922
|
-
}
|
|
923
|
-
#[cfg(not(test))]
|
|
924
|
-
{
|
|
925
|
-
ResolverOptions::default()
|
|
926
|
-
}
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
// A resolver that is stuck in an uninterruptible filesystem syscall may outlive
|
|
930
|
-
// the caller deadline. It owns only its candidate work; the active gate prevents
|
|
931
|
-
// repeated status calls from accumulating more detached resolver threads.
|
|
932
|
-
#[cfg(test)]
|
|
933
|
-
struct ResolverActiveGuard {
|
|
934
|
-
#[cfg(test)]
|
|
935
|
-
finished_signal: Option<ResolverDelaySignal>,
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
#[cfg(test)]
|
|
939
|
-
impl Drop for ResolverActiveGuard {
|
|
940
|
-
fn drop(&mut self) {
|
|
941
|
-
NODEPROBE_RESOLVER_ACTIVE.store(false, Ordering::Release);
|
|
942
|
-
#[cfg(test)]
|
|
943
|
-
if let Some(signal) = self.finished_signal.take() {
|
|
944
|
-
signal.finished.store(true, Ordering::Release);
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
#[cfg(test)]
|
|
950
|
-
fn resolve_nodeprobe_binary(
|
|
951
|
-
candidates: Vec<PathBuf>,
|
|
952
|
-
deadline: Instant,
|
|
953
|
-
options: ResolverOptions,
|
|
954
|
-
) -> Option<PathBuf> {
|
|
955
|
-
#[cfg(not(test))]
|
|
956
|
-
let _ = options;
|
|
957
|
-
if Instant::now() >= deadline || NODEPROBE_RESOLVER_ACTIVE.swap(true, Ordering::AcqRel) {
|
|
958
|
-
return None;
|
|
959
|
-
}
|
|
960
|
-
let (tx, rx) = mpsc::sync_channel(1);
|
|
961
|
-
let worker = thread::Builder::new()
|
|
962
|
-
.name("team-agent-nodeprobe-resolver".to_string())
|
|
963
|
-
.spawn(move || {
|
|
964
|
-
#[cfg(test)]
|
|
965
|
-
let delay_signal = options
|
|
966
|
-
.delay_after_selection
|
|
967
|
-
.as_ref()
|
|
968
|
-
.map(|config| config.signal.clone());
|
|
969
|
-
let _guard = ResolverActiveGuard {
|
|
970
|
-
#[cfg(test)]
|
|
971
|
-
finished_signal: delay_signal,
|
|
972
|
-
};
|
|
973
|
-
let result = select_nodeprobe_binary(candidates, deadline);
|
|
974
|
-
if result.is_some() {
|
|
975
|
-
#[cfg(test)]
|
|
976
|
-
if let Some(config) = options.delay_after_selection {
|
|
977
|
-
config.signal.entered.store(true, Ordering::Release);
|
|
978
|
-
thread::sleep(config.delay);
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
let _ = tx.send(result);
|
|
982
|
-
});
|
|
983
|
-
if worker.is_err() {
|
|
984
|
-
NODEPROBE_RESOLVER_ACTIVE.store(false, Ordering::Release);
|
|
985
|
-
return None;
|
|
986
|
-
}
|
|
987
|
-
let timeout = deadline.saturating_duration_since(Instant::now());
|
|
988
|
-
// Only the caller may turn a timely result into a child process. A late
|
|
989
|
-
// resolver result is dropped with the receiver and can never spawn probe.
|
|
990
|
-
match rx.recv_timeout(timeout) {
|
|
991
|
-
Ok(Some(binary)) if Instant::now() < deadline => Some(binary),
|
|
992
|
-
Ok(_) | Err(_) => None,
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
#[cfg(test)]
|
|
997
|
-
fn select_nodeprobe_binary(candidates: Vec<PathBuf>, deadline: Instant) -> Option<PathBuf> {
|
|
998
|
-
for candidate in candidates {
|
|
999
|
-
if Instant::now() >= deadline {
|
|
1000
|
-
return None;
|
|
1001
|
-
}
|
|
1002
|
-
if let Some(binary) = validate_nodeprobe_candidate(&candidate, deadline) {
|
|
1003
|
-
return Some(binary);
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
None
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
#[cfg(test)]
|
|
1010
|
-
fn nodeprobe_candidates() -> Vec<PathBuf> {
|
|
1011
|
-
#[cfg(test)]
|
|
1012
|
-
{
|
|
1013
|
-
let override_bins = TEST_NODEPROBE.with(|slot| slot.borrow().clone());
|
|
1014
|
-
if let Some(paths) = override_bins {
|
|
1015
|
-
return paths;
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
let mut candidates = std::env::var_os("PATH")
|
|
1019
|
-
.map(|path| {
|
|
1020
|
-
std::env::split_paths(&path)
|
|
1021
|
-
.map(|entry| entry.join(NODEPROBE_NAME))
|
|
1022
|
-
.collect::<Vec<_>>()
|
|
1023
|
-
})
|
|
1024
|
-
.unwrap_or_default();
|
|
1025
|
-
if let Some(home) = std::env::var_os("HOME") {
|
|
1026
|
-
candidates.push(PathBuf::from(home).join(".local/bin").join(NODEPROBE_NAME));
|
|
1027
|
-
}
|
|
1028
|
-
candidates
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
#[cfg(test)]
|
|
1032
|
-
fn validate_nodeprobe_candidate(path: &Path, deadline: Instant) -> Option<PathBuf> {
|
|
1033
|
-
if Instant::now() >= deadline {
|
|
1034
|
-
return None;
|
|
1035
|
-
}
|
|
1036
|
-
let metadata = std::fs::metadata(path).ok()?;
|
|
1037
|
-
if !metadata.is_file() || !is_executable(&metadata) {
|
|
1038
|
-
return None;
|
|
1039
|
-
}
|
|
1040
|
-
let receipt_path = nodeprobe_receipt_path(path);
|
|
1041
|
-
let receipt_metadata = std::fs::metadata(&receipt_path).ok()?;
|
|
1042
|
-
if !receipt_metadata.is_file() || receipt_metadata.len() > NODEPROBE_RECEIPT_LIMIT {
|
|
1043
|
-
return None;
|
|
1044
|
-
}
|
|
1045
|
-
let receipt: NodeprobeCapabilityReceipt = serde_json::from_slice(&read_bounded_file(
|
|
1046
|
-
&receipt_path,
|
|
1047
|
-
NODEPROBE_RECEIPT_LIMIT,
|
|
1048
|
-
deadline,
|
|
1049
|
-
)?)
|
|
1050
|
-
.ok()?;
|
|
1051
|
-
if !valid_nodeprobe_receipt(&receipt, path) || Instant::now() >= deadline {
|
|
1052
|
-
return None;
|
|
1053
|
-
}
|
|
1054
|
-
let digest = sha256_file(path, deadline)?;
|
|
1055
|
-
(digest == receipt.binary_sha256).then_some(path.to_path_buf())
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
#[cfg(test)]
|
|
1059
|
-
fn valid_nodeprobe_receipt(receipt: &NodeprobeCapabilityReceipt, binary: &Path) -> bool {
|
|
1060
|
-
receipt.schema == NODEPROBE_RECEIPT_SCHEMA
|
|
1061
|
-
&& binary.file_name().and_then(|name| name.to_str()) == Some(NODEPROBE_NAME)
|
|
1062
|
-
&& receipt.binary == NODEPROBE_NAME
|
|
1063
|
-
&& valid_sha256(&receipt.binary_sha256)
|
|
1064
|
-
&& receipt.source_repo == NODEPROBE_SOURCE_REPO
|
|
1065
|
-
&& receipt.source_commit == NODEPROBE_SOURCE_COMMIT
|
|
1066
|
-
&& receipt.source_tree == NODEPROBE_SOURCE_TREE
|
|
1067
|
-
&& current_nodeprobe_target().is_some_and(|target| receipt.target == target)
|
|
1068
|
-
&& receipt.report_schema == NODEPROBE_REPORT_SCHEMA
|
|
1069
|
-
&& same_string_set(&receipt.capabilities, NODEPROBE_CAPABILITIES)
|
|
1070
|
-
&& same_string_set(&receipt.forbidden, NODEPROBE_FORBIDDEN)
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
|
-
#[cfg(test)]
|
|
1074
|
-
fn valid_sha256(value: &str) -> bool {
|
|
1075
|
-
value.len() == 64 && value.bytes().all(|byte| byte.is_ascii_hexdigit())
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
#[cfg(test)]
|
|
1079
|
-
fn same_string_set(actual: &[String], expected: &[&str]) -> bool {
|
|
1080
|
-
let mut actual = actual.to_vec();
|
|
1081
|
-
actual.sort_unstable();
|
|
1082
|
-
let mut expected = expected
|
|
1083
|
-
.iter()
|
|
1084
|
-
.map(|value| (*value).to_string())
|
|
1085
|
-
.collect::<Vec<_>>();
|
|
1086
|
-
expected.sort_unstable();
|
|
1087
|
-
actual == expected
|
|
1088
|
-
}
|
|
1089
|
-
|
|
1090
|
-
#[cfg(test)]
|
|
1091
|
-
fn nodeprobe_receipt_path(binary: &Path) -> PathBuf {
|
|
1092
|
-
let name = binary
|
|
1093
|
-
.file_name()
|
|
1094
|
-
.and_then(|name| name.to_str())
|
|
1095
|
-
.unwrap_or(NODEPROBE_NAME);
|
|
1096
|
-
binary.with_file_name(format!("{name}{NODEPROBE_RECEIPT_SUFFIX}"))
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
|
-
#[cfg(test)]
|
|
1100
|
-
fn read_bounded_file(path: &Path, limit: u64, deadline: Instant) -> Option<Vec<u8>> {
|
|
1101
|
-
let metadata = std::fs::metadata(path).ok()?;
|
|
1102
|
-
if !metadata.is_file() || metadata.len() > limit {
|
|
1103
|
-
return None;
|
|
1104
|
-
}
|
|
1105
|
-
let mut file = open_readonly_nonblocking(path)?;
|
|
1106
|
-
let mut bytes = Vec::with_capacity(metadata.len() as usize);
|
|
1107
|
-
let mut chunk = [0u8; NODEPROBE_READ_CHUNK];
|
|
1108
|
-
loop {
|
|
1109
|
-
if Instant::now() >= deadline {
|
|
1110
|
-
return None;
|
|
1111
|
-
}
|
|
1112
|
-
let read = file.read(&mut chunk).ok()?;
|
|
1113
|
-
if read == 0 {
|
|
1114
|
-
return Some(bytes);
|
|
1115
|
-
}
|
|
1116
|
-
bytes.extend_from_slice(&chunk[..read]);
|
|
1117
|
-
if bytes.len() as u64 > limit {
|
|
1118
|
-
return None;
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
|
-
#[cfg(test)]
|
|
1124
|
-
fn sha256_file(path: &Path, deadline: Instant) -> Option<String> {
|
|
1125
|
-
let metadata = std::fs::metadata(path).ok()?;
|
|
1126
|
-
if !metadata.is_file() || metadata.len() > NODEPROBE_BINARY_LIMIT {
|
|
1127
|
-
return None;
|
|
1128
|
-
}
|
|
1129
|
-
let mut file = open_readonly_nonblocking(path)?;
|
|
1130
|
-
let mut hasher = Sha256::new();
|
|
1131
|
-
let mut chunk = [0u8; NODEPROBE_READ_CHUNK];
|
|
1132
|
-
let mut total = 0u64;
|
|
1133
|
-
loop {
|
|
1134
|
-
if Instant::now() >= deadline {
|
|
1135
|
-
return None;
|
|
1136
|
-
}
|
|
1137
|
-
let read = file.read(&mut chunk).ok()?;
|
|
1138
|
-
if read == 0 {
|
|
1139
|
-
return Some(format!("{:x}", hasher.finalize()));
|
|
1140
|
-
}
|
|
1141
|
-
total = total.saturating_add(read as u64);
|
|
1142
|
-
if total > NODEPROBE_BINARY_LIMIT {
|
|
1143
|
-
return None;
|
|
1144
|
-
}
|
|
1145
|
-
hasher.update(&chunk[..read]);
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
|
-
#[cfg(test)]
|
|
1150
|
-
fn open_readonly_nonblocking(path: &Path) -> Option<File> {
|
|
1151
|
-
let mut options = OpenOptions::new();
|
|
1152
|
-
options.read(true);
|
|
1153
|
-
#[cfg(unix)]
|
|
1154
|
-
{
|
|
1155
|
-
use std::os::unix::fs::OpenOptionsExt;
|
|
1156
|
-
options.custom_flags(libc::O_NONBLOCK);
|
|
1157
|
-
}
|
|
1158
|
-
options.open(path).ok()
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
#[cfg(test)]
|
|
1162
|
-
fn is_executable(metadata: &std::fs::Metadata) -> bool {
|
|
1163
|
-
#[cfg(unix)]
|
|
1164
|
-
{
|
|
1165
|
-
use std::os::unix::fs::PermissionsExt;
|
|
1166
|
-
metadata.permissions().mode() & 0o111 != 0
|
|
1167
|
-
}
|
|
1168
|
-
#[cfg(not(unix))]
|
|
1169
|
-
{
|
|
1170
|
-
let _ = metadata;
|
|
1171
|
-
true
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
|
|
1175
|
-
#[cfg(test)]
|
|
1176
|
-
fn current_nodeprobe_target() -> Option<&'static str> {
|
|
1177
|
-
match (std::env::consts::OS, std::env::consts::ARCH) {
|
|
1178
|
-
("macos", "aarch64") => Some("aarch64-apple-darwin"),
|
|
1179
|
-
("macos", "x86_64") => Some("x86_64-apple-darwin"),
|
|
1180
|
-
("linux", "aarch64") => Some("aarch64-unknown-linux-gnu"),
|
|
1181
|
-
("linux", "x86_64") => Some("x86_64-unknown-linux-gnu"),
|
|
1182
|
-
("windows", "x86_64") => Some("x86_64-pc-windows-msvc"),
|
|
1183
|
-
_ => None,
|
|
1184
|
-
}
|
|
1185
|
-
}
|
|
1186
|
-
|
|
1187
|
-
#[cfg(test)]
|
|
1188
|
-
fn configure_nodeprobe_command(command: &mut Command) {
|
|
1189
|
-
command
|
|
1190
|
-
.stdin(Stdio::null())
|
|
1191
|
-
.stdout(Stdio::piped())
|
|
1192
|
-
.stderr(Stdio::null());
|
|
1193
|
-
#[cfg(unix)]
|
|
1194
|
-
{
|
|
1195
|
-
use std::os::unix::process::CommandExt;
|
|
1196
|
-
command.process_group(0);
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
|
|
1200
|
-
#[cfg(test)]
|
|
1201
|
-
fn parse_probe(bytes: &[u8], requested_endpoint: &str) -> Result<ProbeResult, ()> {
|
|
1202
|
-
let value: Value = serde_json::from_slice(bytes).map_err(|_| ())?;
|
|
1203
|
-
if value.get("schema_version").and_then(Value::as_u64) != Some(1) {
|
|
1204
|
-
return Err(());
|
|
1205
|
-
}
|
|
1206
|
-
if probe_has_error(&value) {
|
|
1207
|
-
return Err(());
|
|
1208
|
-
}
|
|
1209
|
-
let report_socket = value.get("socket").and_then(Value::as_str).ok_or(())?;
|
|
1210
|
-
if report_socket != requested_endpoint {
|
|
1211
|
-
return Err(());
|
|
1212
|
-
}
|
|
1213
|
-
let nodes = value
|
|
1214
|
-
.get("nodes")
|
|
1215
|
-
.and_then(Value::as_array)
|
|
1216
|
-
.ok_or(())?
|
|
1217
|
-
.iter()
|
|
1218
|
-
.filter_map(|node| parse_probe_node(node, report_socket))
|
|
1219
|
-
.collect();
|
|
1220
|
-
Ok(ProbeResult { nodes, ..Default::default() })
|
|
1221
|
-
}
|
|
1222
|
-
|
|
1223
|
-
#[cfg(test)]
|
|
1224
|
-
fn probe_has_error(value: &Value) -> bool {
|
|
1225
|
-
match value.get("error") {
|
|
1226
|
-
None | Some(Value::Null) => false,
|
|
1227
|
-
Some(Value::String(text)) => !text.is_empty(),
|
|
1228
|
-
Some(Value::Array(items)) => !items.is_empty(),
|
|
1229
|
-
Some(Value::Object(map)) => !map.is_empty(),
|
|
1230
|
-
Some(_) => true,
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
#[cfg(test)]
|
|
1235
|
-
fn parse_probe_node(value: &Value, report_socket: &str) -> Option<ProbeNode> {
|
|
1236
|
-
Some(ProbeNode {
|
|
1237
|
-
// The accepted producer binds the socket once at the report envelope
|
|
1238
|
-
// and omits the redundant per-node field. An explicit node socket is
|
|
1239
|
-
// still preserved for strict mismatch rejection below.
|
|
1240
|
-
socket: non_empty(value, "socket").unwrap_or_else(|| report_socket.to_string()),
|
|
1241
|
-
session: non_empty(value, "session")?,
|
|
1242
|
-
window: non_empty(value, "window_name")?,
|
|
1243
|
-
pane: non_empty(value, "pane_id")?,
|
|
1244
|
-
provider: non_empty(value, "provider")?,
|
|
1245
|
-
activity: non_empty(value, "activity")?,
|
|
1246
|
-
health: non_empty(value, "health")?,
|
|
1247
|
-
session_name: value
|
|
1248
|
-
.get("session_name")
|
|
1249
|
-
.and_then(Value::as_str)
|
|
1250
|
-
.filter(|value| !value.is_empty())
|
|
1251
|
-
.map(str::to_string),
|
|
1252
|
-
evidence_method: value
|
|
1253
|
-
.pointer("/evidence/method")
|
|
1254
|
-
.and_then(Value::as_str)
|
|
1255
|
-
.map(str::to_string),
|
|
1256
|
-
})
|
|
1257
|
-
}
|
|
1258
|
-
|
|
1259
|
-
#[cfg(test)]
|
|
1260
|
-
fn non_empty(value: &Value, key: &str) -> Option<String> {
|
|
1261
|
-
value
|
|
1262
|
-
.get(key)
|
|
1263
|
-
.and_then(Value::as_str)
|
|
1264
|
-
.filter(|value| !value.is_empty())
|
|
1265
|
-
.map(str::to_string)
|
|
1266
|
-
}
|
|
1267
|
-
|
|
1268
|
-
#[cfg(test)]
|
|
1269
|
-
fn project_node(node: &RegisteredNode, probe: Option<&Option<ProbeResult>>) -> BriefNode {
|
|
1270
|
-
project_node_with_attach(node, probe).0
|
|
1271
|
-
}
|
|
1272
|
-
|
|
1273
|
-
fn project_node_with_attach(
|
|
1274
|
-
node: &RegisteredNode,
|
|
1275
|
-
probe: Option<&Option<ProbeResult>>,
|
|
1276
|
-
) -> (BriefNode, Option<AttachContext>) {
|
|
1277
|
-
let stopped = matches!(
|
|
1278
|
-
node.lifecycle.as_deref(),
|
|
1279
|
-
Some("stopped" | "done" | "failed" | "error" | "terminated")
|
|
1280
|
-
);
|
|
1281
|
-
let matched = match_result(node, probe);
|
|
1282
|
-
if stopped {
|
|
1283
|
-
let projected = match matched {
|
|
1284
|
-
MatchResult::Missing => BriefNode {
|
|
1285
|
-
name: node.name.clone(),
|
|
1286
|
-
provider: node.provider.clone(),
|
|
1287
|
-
model: node.model.clone(),
|
|
1288
|
-
effort: node.effort.clone(),
|
|
1289
|
-
runtime_status: "stopped".to_string(),
|
|
1290
|
-
activity: "unknown".to_string(),
|
|
1291
|
-
health: "unknown".to_string(),
|
|
1292
|
-
session_name: None,
|
|
1293
|
-
tmux_command: None,
|
|
1294
|
-
observation_reason: None,
|
|
1295
|
-
},
|
|
1296
|
-
MatchResult::Unique(_) | MatchResult::Ambiguous => BriefNode::unknown(node).with_reason("stopped_registration_has_live_pane"),
|
|
1297
|
-
};
|
|
1298
|
-
return (projected, None);
|
|
1299
|
-
}
|
|
1300
|
-
let MatchResult::Unique(observed) = matched else {
|
|
1301
|
-
let reason = if matches!(matched, MatchResult::Ambiguous) {
|
|
1302
|
-
"pane_observation_ambiguous"
|
|
1303
|
-
} else if node.endpoint.is_none() {
|
|
1304
|
-
"endpoint_unregistered"
|
|
1305
|
-
} else if node.session.is_none() || node.pane.is_none() {
|
|
1306
|
-
"pane_binding_incomplete"
|
|
1307
|
-
} else if let Some(sample) = probe.and_then(Option::as_ref) {
|
|
1308
|
-
if sample.exited.iter().any(|(session, window, pane)| {
|
|
1309
|
-
node.session.as_deref() == Some(session.as_str())
|
|
1310
|
-
&& node.window.as_deref().is_none_or(|name| name == window)
|
|
1311
|
-
&& node.pane.as_deref() == Some(pane.as_str())
|
|
1312
|
-
}) { "pane_process_exited" }
|
|
1313
|
-
else if matches!(node.lifecycle.as_deref(), Some("starting" | "launching" | "pending")) { "startup_not_yet_observed" }
|
|
1314
|
-
else { "registered_pane_not_observed" }
|
|
1315
|
-
} else { "endpoint_probe_unavailable" };
|
|
1316
|
-
return (BriefNode::unknown(node).with_reason(reason), None);
|
|
1317
|
-
};
|
|
1318
|
-
if !node.provider.eq_ignore_ascii_case("unknown")
|
|
1319
|
-
&& !node.provider.eq_ignore_ascii_case(&observed.provider)
|
|
1320
|
-
{
|
|
1321
|
-
return (BriefNode::unknown(node).with_reason("provider_observation_mismatch"), None);
|
|
1322
|
-
}
|
|
1323
|
-
let pi_channel = observed.provider.eq_ignore_ascii_case("pi")
|
|
1324
|
-
&& observed.evidence_method.as_deref() == Some("pi_activity_channel");
|
|
1325
|
-
let native_tmux = observed.evidence_method.as_deref() == Some("native_tmux");
|
|
1326
|
-
let activity = if observed.provider.eq_ignore_ascii_case("pi") && !pi_channel && !native_tmux {
|
|
1327
|
-
"unknown"
|
|
1328
|
-
} else {
|
|
1329
|
-
valid_activity(&observed.activity)
|
|
1330
|
-
};
|
|
1331
|
-
let health = if observed.provider.eq_ignore_ascii_case("pi") && !pi_channel && !native_tmux {
|
|
1332
|
-
"unknown"
|
|
1333
|
-
} else {
|
|
1334
|
-
valid_health(&observed.health)
|
|
1335
|
-
};
|
|
1336
|
-
let tmux_command = tmux_command(node, observed);
|
|
1337
|
-
let attach = tmux_command.as_ref().map(|_| AttachContext {
|
|
1338
|
-
endpoint: observed.socket.clone(),
|
|
1339
|
-
session: observed.session.clone(),
|
|
1340
|
-
window: observed.window.clone(),
|
|
1341
|
-
pane: observed.pane.clone(),
|
|
1342
|
-
});
|
|
1343
|
-
(
|
|
1344
|
-
BriefNode {
|
|
1345
|
-
name: node.name.clone(),
|
|
1346
|
-
provider: if node.provider.eq_ignore_ascii_case("unknown") {
|
|
1347
|
-
observed.provider.clone()
|
|
1348
|
-
} else {
|
|
1349
|
-
node.provider.clone()
|
|
1350
|
-
},
|
|
1351
|
-
model: node.model.clone(),
|
|
1352
|
-
effort: node.effort.clone(),
|
|
1353
|
-
runtime_status: "running".to_string(),
|
|
1354
|
-
activity: activity.to_string(),
|
|
1355
|
-
health: health.to_string(),
|
|
1356
|
-
session_name: observed.session_name.clone(),
|
|
1357
|
-
tmux_command,
|
|
1358
|
-
observation_reason: (activity == "unknown" || health == "unknown").then_some("activity_or_health_not_observed"),
|
|
1359
|
-
},
|
|
1360
|
-
attach,
|
|
1361
|
-
)
|
|
1362
|
-
}
|
|
1363
|
-
|
|
1364
|
-
fn match_result<'a>(
|
|
1365
|
-
node: &RegisteredNode,
|
|
1366
|
-
probe: Option<&'a Option<ProbeResult>>,
|
|
1367
|
-
) -> MatchResult<'a> {
|
|
1368
|
-
let Some(probe) = probe.and_then(|probe| probe.as_ref()) else {
|
|
1369
|
-
return MatchResult::Missing;
|
|
1370
|
-
};
|
|
1371
|
-
let mut matches = probe
|
|
1372
|
-
.nodes
|
|
1373
|
-
.iter()
|
|
1374
|
-
.filter(|observed| matches_registered(node, observed));
|
|
1375
|
-
let Some(first) = matches.next() else {
|
|
1376
|
-
return MatchResult::Missing;
|
|
1377
|
-
};
|
|
1378
|
-
if matches.next().is_some() {
|
|
1379
|
-
MatchResult::Ambiguous
|
|
1380
|
-
} else {
|
|
1381
|
-
MatchResult::Unique(first)
|
|
1382
|
-
}
|
|
1383
|
-
}
|
|
1384
|
-
|
|
1385
|
-
fn matches_registered(node: &RegisteredNode, observed: &ProbeNode) -> bool {
|
|
1386
|
-
node.endpoint.as_deref() == Some(observed.socket.as_str())
|
|
1387
|
-
&& node.session.as_deref() == Some(observed.session.as_str())
|
|
1388
|
-
// Older registrations may not persist a window. The endpoint,
|
|
1389
|
-
// session, and pane tuple remains the narrow compatibility key; a
|
|
1390
|
-
// present window is still an exact constraint.
|
|
1391
|
-
&& node
|
|
1392
|
-
.window
|
|
1393
|
-
.as_deref()
|
|
1394
|
-
.is_none_or(|window| window == observed.window)
|
|
1395
|
-
&& node.pane.as_deref() == Some(observed.pane.as_str())
|
|
1396
|
-
}
|
|
1397
|
-
|
|
1398
|
-
fn valid_activity(value: &str) -> &str {
|
|
1399
|
-
match value {
|
|
1400
|
-
"working" | "idle" => value,
|
|
1401
|
-
_ => "unknown",
|
|
1402
|
-
}
|
|
1403
|
-
}
|
|
1404
|
-
|
|
1405
|
-
fn valid_health(value: &str) -> &str {
|
|
1406
|
-
match value {
|
|
1407
|
-
"normal" | "abnormal" | "unknown" => value,
|
|
1408
|
-
_ => "unknown",
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
|
|
1412
|
-
fn tmux_command(node: &RegisteredNode, observed: &ProbeNode) -> Option<String> {
|
|
1413
|
-
let endpoint = node.endpoint.as_deref()?;
|
|
1414
|
-
let target = format!("{}:{}.{}", observed.session, observed.window, observed.pane);
|
|
1415
|
-
let flag = if Path::new(endpoint).is_absolute() {
|
|
1416
|
-
"-S"
|
|
1417
|
-
} else {
|
|
1418
|
-
"-L"
|
|
1419
|
-
};
|
|
1420
|
-
Some(format!(
|
|
1421
|
-
"tmux {flag} {} attach -t {}",
|
|
1422
|
-
shell_quote(endpoint),
|
|
1423
|
-
shell_quote(&target)
|
|
1424
|
-
))
|
|
1425
|
-
}
|
|
1426
|
-
|
|
1427
|
-
fn shell_quote(value: &str) -> String {
|
|
1428
|
-
format!("'{}'", value.replace('\'', "'\\''"))
|
|
1429
|
-
}
|
|
1430
|
-
|
|
1431
|
-
impl BriefNode {
|
|
1432
|
-
fn unknown(node: &RegisteredNode) -> Self {
|
|
1433
|
-
Self {
|
|
1434
|
-
name: node.name.clone(),
|
|
1435
|
-
provider: node.provider.clone(),
|
|
1436
|
-
model: node.model.clone(),
|
|
1437
|
-
effort: node.effort.clone(),
|
|
1438
|
-
runtime_status: "unknown".to_string(),
|
|
1439
|
-
activity: "unknown".to_string(),
|
|
1440
|
-
health: "unknown".to_string(),
|
|
1441
|
-
session_name: None,
|
|
1442
|
-
tmux_command: None,
|
|
1443
|
-
observation_reason: Some("observation_inconclusive"),
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
|
|
1447
|
-
fn with_reason(mut self, reason: &'static str) -> Self {
|
|
1448
|
-
self.observation_reason = Some(reason);
|
|
1449
|
-
self
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
|
-
fn into_json(self) -> Value {
|
|
1453
|
-
let mut object = Map::new();
|
|
1454
|
-
object.insert("name".to_string(), json!(self.name));
|
|
1455
|
-
object.insert("provider".to_string(), json!(self.provider));
|
|
1456
|
-
object.insert("model".to_string(), json!(self.model));
|
|
1457
|
-
object.insert("effort".to_string(), json!(self.effort));
|
|
1458
|
-
object.insert("runtime_status".to_string(), json!(self.runtime_status));
|
|
1459
|
-
object.insert("activity".to_string(), json!(self.activity));
|
|
1460
|
-
object.insert("health".to_string(), json!(self.health));
|
|
1461
|
-
object.insert(
|
|
1462
|
-
"session_name".to_string(),
|
|
1463
|
-
self.session_name.map(Value::String).unwrap_or(Value::Null),
|
|
1464
|
-
);
|
|
1465
|
-
object.insert(
|
|
1466
|
-
"tmux_command".to_string(),
|
|
1467
|
-
self.tmux_command.map(Value::String).unwrap_or(Value::Null),
|
|
1468
|
-
);
|
|
1469
|
-
if let Some(reason) = self.observation_reason {
|
|
1470
|
-
object.insert("observation_reason".into(), json!(reason));
|
|
1471
|
-
}
|
|
1472
|
-
Value::Object(object)
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
fn scoped_node_json(node: BriefNode, workspace: &Path, state: &Value) -> Value {
|
|
1477
|
-
let mut value = node.into_json();
|
|
1478
|
-
if let Some(reason) = value["observation_reason"].as_str() {
|
|
1479
|
-
let guidance = match reason {
|
|
1480
|
-
"pane_process_exited" => "pane process exit confirmed; inspect saved session and Leader binding before explicit start",
|
|
1481
|
-
"startup_not_yet_observed" | "native_runtime_not_ready" => "wait for startup convergence and recheck this scope; do not reset on unknown",
|
|
1482
|
-
_ => "inspect this scope's observation and identity; do not infer process exit or retry lifecycle from unknown alone",
|
|
1483
|
-
};
|
|
1484
|
-
value["next_action"] = json!(format!(
|
|
1485
|
-
"team-agent doctor --workspace {} --team {} --json; {guidance}",
|
|
1486
|
-
shell_quote(&workspace.to_string_lossy()),
|
|
1487
|
-
shell_quote(&crate::state::projection::team_state_key(state)),
|
|
1488
|
-
));
|
|
1489
|
-
}
|
|
1490
|
-
value
|
|
1491
|
-
}
|
|
1492
|
-
|
|
1493
|
-
#[cfg(test)]
|
|
1494
|
-
mod native_ps_batch_regressions {
|
|
1495
|
-
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
|
|
1496
|
-
use super::*;
|
|
1497
|
-
|
|
1498
|
-
fn registered(endpoint: &str, pane: &str) -> RegisteredNode {
|
|
1499
|
-
RegisteredNode {
|
|
1500
|
-
name: format!("{endpoint}-{pane}"),
|
|
1501
|
-
provider: "pi".into(),
|
|
1502
|
-
model: Some("fixture-model".into()),
|
|
1503
|
-
effort: Some("high".into()),
|
|
1504
|
-
endpoint: Some(endpoint.into()),
|
|
1505
|
-
session: Some("hp".into()),
|
|
1506
|
-
window: Some("w".into()),
|
|
1507
|
-
pane: Some(pane.into()),
|
|
1508
|
-
lifecycle: None,
|
|
1509
|
-
}
|
|
1510
|
-
}
|
|
1511
|
-
|
|
1512
|
-
#[test]
|
|
1513
|
-
fn issue338_unknown_status_has_reason_and_same_scope_next_action() {
|
|
1514
|
-
let state = json!({
|
|
1515
|
-
"team_key": "scoped-team", "session_name": "sess",
|
|
1516
|
-
"agents": {"worker": {"provider": "pi", "status": "running"}}
|
|
1517
|
-
});
|
|
1518
|
-
let status = status_brief_scoped(Path::new("/owned/workspace with spaces"), &state, None);
|
|
1519
|
-
let node = &status["nodes"][0];
|
|
1520
|
-
assert_eq!(node["runtime_status"], "unknown");
|
|
1521
|
-
assert_eq!(node["observation_reason"], "endpoint_unregistered");
|
|
1522
|
-
let action = node["next_action"].as_str().unwrap();
|
|
1523
|
-
assert!(action.contains("--workspace '/owned/workspace with spaces'"));
|
|
1524
|
-
assert!(action.contains("--team 'scoped-team'"));
|
|
1525
|
-
assert!(action.contains("doctor"));
|
|
1526
|
-
assert!(!action.contains("restart"));
|
|
1527
|
-
}
|
|
1528
|
-
|
|
1529
|
-
#[test]
|
|
1530
|
-
fn issue338_confirmed_zombie_is_not_reported_as_unexplained_unknown() {
|
|
1531
|
-
let node = registered("e1", "%7");
|
|
1532
|
-
let probe = sample_native_panes("hp\tw\t%7\t123\tpi\n", "e1", &[node.clone()], |_| {
|
|
1533
|
-
BTreeMap::from([(123, ProcessSnapshot { zombie: true })])
|
|
1534
|
-
});
|
|
1535
|
-
let value = project_node(&node, Some(&Some(probe))).into_json();
|
|
1536
|
-
assert_eq!(value["runtime_status"], "unknown");
|
|
1537
|
-
assert_eq!(value["observation_reason"], "pane_process_exited");
|
|
1538
|
-
assert!(value["tmux_command"].is_null());
|
|
1539
|
-
}
|
|
1540
|
-
|
|
1541
|
-
#[test]
|
|
1542
|
-
fn eight_panes_use_one_endpoint_query() {
|
|
1543
|
-
let registered = (0..8)
|
|
1544
|
-
.map(|i| registered("e1", &format!("%{i}")))
|
|
1545
|
-
.collect::<Vec<_>>();
|
|
1546
|
-
let panes = (0..8)
|
|
1547
|
-
.map(|i| format!("hp\tw\t%{i}\t{}\tpi\n", 100 + i))
|
|
1548
|
-
.collect::<String>();
|
|
1549
|
-
let rows = (0..8)
|
|
1550
|
-
.map(|i| format!("{} 1 S pi\n", 100 + i))
|
|
1551
|
-
.collect::<String>();
|
|
1552
|
-
let mut calls = Vec::new();
|
|
1553
|
-
let result = sample_native_panes(&panes, "e1", ®istered, |pids| {
|
|
1554
|
-
calls.push(pids.iter().copied().collect::<Vec<_>>());
|
|
1555
|
-
parse_process_snapshots(rows.as_bytes(), pids)
|
|
1556
|
-
});
|
|
1557
|
-
assert_eq!(calls, vec![(100..108).collect::<Vec<_>>()]);
|
|
1558
|
-
assert_eq!(result.nodes.len(), 8);
|
|
1559
|
-
assert!(result.nodes.iter().all(|node| node.provider == "pi"
|
|
1560
|
-
&& node.activity == "working"
|
|
1561
|
-
&& node.health == "normal"));
|
|
1562
|
-
}
|
|
1563
|
-
|
|
1564
|
-
#[test]
|
|
1565
|
-
fn pid_deduplication_and_command_preserve_the_privacy_whitelist() {
|
|
1566
|
-
let mut calls = Vec::new();
|
|
1567
|
-
let result = sample_native_panes(
|
|
1568
|
-
"hp\tw\t%1\t11\tsh\nhp\tw\t%2\t011\tsh\n",
|
|
1569
|
-
"e1",
|
|
1570
|
-
&[],
|
|
1571
|
-
|pids| {
|
|
1572
|
-
calls.push(pids.iter().copied().collect::<Vec<_>>());
|
|
1573
|
-
parse_process_snapshots(b"11 1 S sh\n", pids)
|
|
1574
|
-
},
|
|
1575
|
-
);
|
|
1576
|
-
assert_eq!(calls, vec![vec![11]]);
|
|
1577
|
-
assert_eq!(result.nodes.len(), 2);
|
|
1578
|
-
let pids = BTreeSet::from([22, 11]);
|
|
1579
|
-
let command = process_snapshot_command(&pids);
|
|
1580
|
-
assert_eq!(command.get_program(), "ps");
|
|
1581
|
-
assert_eq!(
|
|
1582
|
-
command
|
|
1583
|
-
.get_args()
|
|
1584
|
-
.map(|arg| arg.to_string_lossy().into_owned())
|
|
1585
|
-
.collect::<Vec<_>>(),
|
|
1586
|
-
vec!["-o", "pid=,ppid=,stat=,comm=", "-p", "11,22"]
|
|
1587
|
-
);
|
|
1588
|
-
let command = process_snapshot_command(&BTreeSet::from([11]));
|
|
1589
|
-
assert_eq!(command.get_args().last().unwrap(), "11");
|
|
1590
|
-
}
|
|
1591
|
-
|
|
1592
|
-
#[cfg(unix)]
|
|
1593
|
-
#[test]
|
|
1594
|
-
fn native_ps_partial_selection_preserves_a_live_pid() {
|
|
1595
|
-
let pid = std::process::id();
|
|
1596
|
-
// Darwin ps rejects i32::MAX as invalid syntax; use a real exited PID.
|
|
1597
|
-
let mut exited = Command::new("/bin/sh").args(["-c", "exit 0"]).spawn().unwrap();
|
|
1598
|
-
let dead_pid = exited.id();
|
|
1599
|
-
assert!(exited.wait().unwrap().success());
|
|
1600
|
-
let requested = BTreeSet::from([pid, dead_pid]);
|
|
1601
|
-
let command = process_snapshot_command(&requested);
|
|
1602
|
-
// Absolute ps avoids unrelated PATH-fixture mutation in parallel unit tests.
|
|
1603
|
-
let output = Command::new("/bin/ps")
|
|
1604
|
-
.args(command.get_args())
|
|
1605
|
-
.output()
|
|
1606
|
-
.unwrap();
|
|
1607
|
-
assert!(
|
|
1608
|
-
output.status.success(),
|
|
1609
|
-
"partial PID selection must not poison the live row"
|
|
1610
|
-
);
|
|
1611
|
-
let snapshots = parse_process_snapshots(&output.stdout, &requested);
|
|
1612
|
-
assert!(!snapshots.get(&pid).unwrap().zombie);
|
|
1613
|
-
assert!(!snapshots.contains_key(&(i32::MAX as u32)));
|
|
1614
|
-
}
|
|
1615
|
-
|
|
1616
|
-
#[test]
|
|
1617
|
-
fn single_pane_keeps_its_native_health_and_activity() {
|
|
1618
|
-
let registered = vec![registered("e1", "%1")];
|
|
1619
|
-
let result = sample_native_panes("hp\tw\t%1\t11\tsh\n", "e1", ®istered, |pids| {
|
|
1620
|
-
assert_eq!(pids, &BTreeSet::from([11]));
|
|
1621
|
-
parse_process_snapshots(b"11 1 S sh\n", pids)
|
|
1622
|
-
});
|
|
1623
|
-
assert_eq!(result.nodes.len(), 1);
|
|
1624
|
-
assert_eq!(result.nodes[0].provider, "pi");
|
|
1625
|
-
assert_eq!(result.nodes[0].activity, "idle");
|
|
1626
|
-
assert_eq!(result.nodes[0].health, "normal");
|
|
1627
|
-
}
|
|
1628
|
-
|
|
1629
|
-
#[test]
|
|
1630
|
-
fn missing_rows_and_zombies_omit_only_their_panes() {
|
|
1631
|
-
let panes = "hp\tw\t%1\t11\tsh\nhp\tw\t%2\t22\tpi\nhp\tw\t%3\t33\tpi\nhp\tw\t%4\t\tsh\n";
|
|
1632
|
-
let result = sample_native_panes(panes, "e1", &[], |pids| {
|
|
1633
|
-
parse_process_snapshots(b"22 1 Z+ dead\n11 1 S sh\n999 1 S unrelated\n33 1\n", pids)
|
|
1634
|
-
});
|
|
1635
|
-
assert_eq!(
|
|
1636
|
-
result
|
|
1637
|
-
.nodes
|
|
1638
|
-
.iter()
|
|
1639
|
-
.map(|node| node.pane.as_str())
|
|
1640
|
-
.collect::<Vec<_>>(),
|
|
1641
|
-
vec!["%1", "%4"]
|
|
1642
|
-
);
|
|
1643
|
-
assert!(result
|
|
1644
|
-
.nodes
|
|
1645
|
-
.iter()
|
|
1646
|
-
.all(|node| node.activity == "idle" && node.health == "normal"));
|
|
1647
|
-
}
|
|
1648
|
-
|
|
1649
|
-
#[test]
|
|
1650
|
-
fn empty_or_invalid_pid_sets_do_not_run_ps() {
|
|
1651
|
-
let panes = "hp\tw\t%1\t\tsh\nhp\tw\t%2\t0\tsh\nhp\tw\t%3\t1,2\tsh\nhp\tw\t%4\t4294967295\tsh\n\tw\t%5\t99\tsh\n";
|
|
1652
|
-
let result = sample_native_panes(panes, "e1", &[], |_| {
|
|
1653
|
-
panic!("no valid PID means no ps query")
|
|
1654
|
-
});
|
|
1655
|
-
assert_eq!(result.nodes.len(), 1);
|
|
1656
|
-
assert_eq!(result.nodes[0].pane, "%1");
|
|
1657
|
-
assert_eq!(result.nodes[0].health, "normal");
|
|
1658
|
-
}
|
|
1659
|
-
|
|
1660
|
-
#[test]
|
|
1661
|
-
fn snapshot_failure_and_endpoint_results_are_not_shared() {
|
|
1662
|
-
let registered = vec![registered("e1", "%1"), registered("e2", "%1")];
|
|
1663
|
-
let mut calls = Vec::new();
|
|
1664
|
-
let first = sample_native_panes("hp\tw\t%1\t88\tsh\n", "e1", ®istered, |pids| {
|
|
1665
|
-
calls.push(("e1", pids.iter().copied().collect::<Vec<_>>()));
|
|
1666
|
-
BTreeMap::new()
|
|
1667
|
-
});
|
|
1668
|
-
let second = sample_native_panes("hp\tw\t%1\t88\tsh\n", "e2", ®istered, |pids| {
|
|
1669
|
-
calls.push(("e2", pids.iter().copied().collect::<Vec<_>>()));
|
|
1670
|
-
parse_process_snapshots(b"88 1 S sh\n", pids)
|
|
1671
|
-
});
|
|
1672
|
-
assert_eq!(calls, vec![("e1", vec![88]), ("e2", vec![88])]);
|
|
1673
|
-
assert!(first.nodes.is_empty());
|
|
1674
|
-
assert_eq!(second.nodes.len(), 1);
|
|
1675
|
-
let failed = Some(first);
|
|
1676
|
-
assert_eq!(
|
|
1677
|
-
project_node_with_attach(®istered[0], Some(&failed))
|
|
1678
|
-
.0
|
|
1679
|
-
.health,
|
|
1680
|
-
"unknown"
|
|
1681
|
-
);
|
|
1682
|
-
let live = Some(second);
|
|
1683
|
-
assert_eq!(
|
|
1684
|
-
project_node_with_attach(®istered[1], Some(&live))
|
|
1685
|
-
.0
|
|
1686
|
-
.health,
|
|
1687
|
-
"normal"
|
|
1688
|
-
);
|
|
1689
|
-
}
|
|
1690
|
-
|
|
1691
|
-
#[test]
|
|
1692
|
-
fn duplicate_process_rows_cannot_hide_a_zombie() {
|
|
1693
|
-
let requested = BTreeSet::from([11]);
|
|
1694
|
-
for rows in [
|
|
1695
|
-
b"11 1 Z dead\n11 1 S sh\n".as_slice(),
|
|
1696
|
-
b"11 1 S sh\n11 1 Z dead\n".as_slice(),
|
|
1697
|
-
] {
|
|
1698
|
-
assert!(
|
|
1699
|
-
parse_process_snapshots(rows, &requested)
|
|
1700
|
-
.get(&11)
|
|
1701
|
-
.unwrap()
|
|
1702
|
-
.zombie
|
|
1703
|
-
);
|
|
1704
|
-
}
|
|
1705
|
-
assert!(parse_process_snapshots(b"not a process row\n", &requested).is_empty());
|
|
1706
|
-
}
|
|
1707
|
-
|
|
1708
|
-
#[test]
|
|
1709
|
-
fn json_and_human_keep_nine_fields_without_ps_details() {
|
|
1710
|
-
let registered = vec![registered("e1", "%1"), registered("e1", "%2")];
|
|
1711
|
-
let probe = Some(sample_native_panes(
|
|
1712
|
-
"hp\tw\t%1\t11\tsh\nhp\tw\t%2\t22\tpi\n",
|
|
1713
|
-
"e1",
|
|
1714
|
-
®istered,
|
|
1715
|
-
|pids| {
|
|
1716
|
-
parse_process_snapshots(
|
|
1717
|
-
b"22 1 R PRIVATE_COMMAND_DETAIL\n11 1 S PRIVATE_COMMAND_DETAIL\n",
|
|
1718
|
-
pids,
|
|
1719
|
-
)
|
|
1720
|
-
},
|
|
1721
|
-
));
|
|
1722
|
-
let projected = registered
|
|
1723
|
-
.iter()
|
|
1724
|
-
.map(|node| project_node_with_attach(node, Some(&probe)))
|
|
1725
|
-
.collect::<Vec<_>>();
|
|
1726
|
-
let keys = BTreeSet::from([
|
|
1727
|
-
"name",
|
|
1728
|
-
"provider",
|
|
1729
|
-
"model",
|
|
1730
|
-
"effort",
|
|
1731
|
-
"runtime_status",
|
|
1732
|
-
"activity",
|
|
1733
|
-
"health",
|
|
1734
|
-
"session_name",
|
|
1735
|
-
"tmux_command",
|
|
1736
|
-
]);
|
|
1737
|
-
for (node, _) in &projected {
|
|
1738
|
-
let json = node.clone().into_json();
|
|
1739
|
-
assert_eq!(
|
|
1740
|
-
json.as_object()
|
|
1741
|
-
.unwrap()
|
|
1742
|
-
.keys()
|
|
1743
|
-
.map(String::as_str)
|
|
1744
|
-
.collect::<BTreeSet<_>>(),
|
|
1745
|
-
keys
|
|
1746
|
-
);
|
|
1747
|
-
assert_eq!(json["model"], "fixture-model");
|
|
1748
|
-
assert_eq!(json["effort"], "high");
|
|
1749
|
-
assert_eq!(json["runtime_status"], "running");
|
|
1750
|
-
assert_eq!(json["health"], "normal");
|
|
1751
|
-
assert!(!json.to_string().contains("PRIVATE_COMMAND_DETAIL"));
|
|
1752
|
-
}
|
|
1753
|
-
let human = format_multi_node_brief(projected);
|
|
1754
|
-
let mut lines = human.lines().skip_while(|line| !line.starts_with("NAME\t"));
|
|
1755
|
-
assert_eq!(lines.next().unwrap().split('\t').count(), 9);
|
|
1756
|
-
assert!(lines.all(|line| line.split('\t').count() == 9));
|
|
1757
|
-
assert!(!human.contains("PRIVATE_COMMAND_DETAIL"));
|
|
1758
|
-
}
|
|
1759
|
-
}
|
|
1760
|
-
|
|
1761
|
-
#[cfg(test)]
|
|
1762
|
-
mod tests {
|
|
1763
|
-
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
|
|
1764
|
-
use super::*;
|
|
1765
|
-
|
|
1766
|
-
fn registered() -> RegisteredNode {
|
|
1767
|
-
RegisteredNode {
|
|
1768
|
-
name: "worker".to_string(),
|
|
1769
|
-
provider: "pi".to_string(),
|
|
1770
|
-
model: None,
|
|
1771
|
-
effort: None,
|
|
1772
|
-
endpoint: Some("/tmp/tmux socket/o'k".to_string()),
|
|
1773
|
-
session: Some("sess".to_string()),
|
|
1774
|
-
window: Some("win".to_string()),
|
|
1775
|
-
pane: Some("%7".to_string()),
|
|
1776
|
-
lifecycle: None,
|
|
1777
|
-
}
|
|
1778
|
-
}
|
|
1779
|
-
|
|
1780
|
-
fn probe(method: &str) -> ProbeNode {
|
|
1781
|
-
ProbeNode {
|
|
1782
|
-
socket: "/tmp/tmux socket/o'k".to_string(),
|
|
1783
|
-
session: "sess".to_string(),
|
|
1784
|
-
window: "win".to_string(),
|
|
1785
|
-
pane: "%7".to_string(),
|
|
1786
|
-
provider: "pi".to_string(),
|
|
1787
|
-
activity: "idle".to_string(),
|
|
1788
|
-
health: "normal".to_string(),
|
|
1789
|
-
session_name: Some("pi-session".to_string()),
|
|
1790
|
-
evidence_method: Some(method.to_string()),
|
|
1791
|
-
}
|
|
1792
|
-
}
|
|
1793
|
-
|
|
1794
|
-
fn producer_error_envelope() -> &'static [u8] {
|
|
1795
|
-
br#"{"schema_version":1,"socket":"/tmp/sock","sampled_at":"2026-01-01T00:00:00Z","nodes":[],"error":{"kind":"tmux_inventory","message":"missing"}}"#
|
|
1796
|
-
}
|
|
1797
|
-
|
|
1798
|
-
#[test]
|
|
1799
|
-
fn status_model_effort_project_accepted_launch_settings_in_all_runtime_states() {
|
|
1800
|
-
for settings in [(None, None), (Some("openai-codex/gpt-6-luna"), Some("max"))] {
|
|
1801
|
-
let mut node = registered();
|
|
1802
|
-
node.model = settings.0.map(str::to_string);
|
|
1803
|
-
node.effort = settings.1.map(str::to_string);
|
|
1804
|
-
for lifecycle in [None, Some("stopped")] {
|
|
1805
|
-
node.lifecycle = lifecycle.map(str::to_string);
|
|
1806
|
-
for sample in [
|
|
1807
|
-
None,
|
|
1808
|
-
Some(ProbeResult {
|
|
1809
|
-
nodes: vec![probe("pi_activity_channel")],
|
|
1810
|
-
..Default::default()
|
|
1811
|
-
}),
|
|
1812
|
-
] {
|
|
1813
|
-
let value = project_node(&node, Some(&sample)).into_json();
|
|
1814
|
-
assert_eq!(value["model"], json!(settings.0));
|
|
1815
|
-
assert_eq!(value["effort"], json!(settings.1));
|
|
1816
|
-
let human = format_brief_node(&value).unwrap();
|
|
1817
|
-
assert!(human.contains(&format!(
|
|
1818
|
-
"model: {} effort: {}",
|
|
1819
|
-
settings.0.unwrap_or("null"),
|
|
1820
|
-
settings.1.unwrap_or("null")
|
|
1821
|
-
)));
|
|
1822
|
-
let diagnostics = usize::from(value.get("observation_reason").is_some());
|
|
1823
|
-
assert_eq!(value.as_object().unwrap().len(), 9 + diagnostics);
|
|
1824
|
-
if value["runtime_status"] == "unknown" {
|
|
1825
|
-
assert!(!value["observation_reason"].as_str().unwrap().is_empty());
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1828
|
-
}
|
|
1829
|
-
}
|
|
1830
|
-
}
|
|
1831
|
-
|
|
1832
|
-
#[test]
|
|
1833
|
-
fn status_model_effort_use_canonical_runtime_roster_not_stale_projection() {
|
|
1834
|
-
let state = json!({
|
|
1835
|
-
"active_team_key": "selected",
|
|
1836
|
-
"agents": {"worker": {"model": "stale-model", "effort": "low"}},
|
|
1837
|
-
"teams": {"selected": {"agents": {
|
|
1838
|
-
"worker": {"model": "accepted-model", "effort": "max"},
|
|
1839
|
-
"plain": {}
|
|
1840
|
-
}}}
|
|
1841
|
-
});
|
|
1842
|
-
let selected = registered_nodes(&state, Some("worker"));
|
|
1843
|
-
assert_eq!(selected.len(), 1);
|
|
1844
|
-
assert_eq!(selected[0].model.as_deref(), Some("accepted-model"));
|
|
1845
|
-
assert_eq!(selected[0].effort.as_deref(), Some("max"));
|
|
1846
|
-
let plain = registered_nodes(&state, Some("plain"));
|
|
1847
|
-
assert!(plain[0].model.is_none());
|
|
1848
|
-
assert!(plain[0].effort.is_none());
|
|
1849
|
-
}
|
|
1850
|
-
|
|
1851
|
-
#[test]
|
|
1852
|
-
fn pi_pane_title_is_unknown_not_idle() {
|
|
1853
|
-
let node = registered();
|
|
1854
|
-
let observed = probe("pane_title");
|
|
1855
|
-
let projected = project_node(
|
|
1856
|
-
&node,
|
|
1857
|
-
Some(&Some(ProbeResult {
|
|
1858
|
-
nodes: vec![observed],
|
|
1859
|
-
..Default::default()
|
|
1860
|
-
})),
|
|
1861
|
-
);
|
|
1862
|
-
assert_eq!(projected.runtime_status, "running");
|
|
1863
|
-
assert_eq!(projected.activity, "unknown");
|
|
1864
|
-
assert_eq!(projected.health, "unknown");
|
|
1865
|
-
}
|
|
1866
|
-
|
|
1867
|
-
#[test]
|
|
1868
|
-
fn exact_probe_generates_quoted_window_pane_command() {
|
|
1869
|
-
let node = registered();
|
|
1870
|
-
let observed = probe("pi_activity_channel");
|
|
1871
|
-
let projected = project_node(
|
|
1872
|
-
&node,
|
|
1873
|
-
Some(&Some(ProbeResult {
|
|
1874
|
-
nodes: vec![observed],
|
|
1875
|
-
..Default::default()
|
|
1876
|
-
})),
|
|
1877
|
-
);
|
|
1878
|
-
assert_eq!(projected.activity, "idle");
|
|
1879
|
-
assert_eq!(
|
|
1880
|
-
projected.tmux_command.as_deref(),
|
|
1881
|
-
Some("tmux -S '/tmp/tmux socket/o'\\''k' attach -t 'sess:win.%7'"),
|
|
1882
|
-
);
|
|
1883
|
-
}
|
|
1884
|
-
|
|
1885
|
-
#[test]
|
|
1886
|
-
fn stopped_registration_is_retained_without_sample() {
|
|
1887
|
-
let mut node = registered();
|
|
1888
|
-
node.lifecycle = Some("stopped".to_string());
|
|
1889
|
-
let projected = project_node(&node, None);
|
|
1890
|
-
assert_eq!(projected.runtime_status, "stopped");
|
|
1891
|
-
assert_eq!(projected.activity, "unknown");
|
|
1892
|
-
assert!(projected.tmux_command.is_none());
|
|
1893
|
-
}
|
|
1894
|
-
|
|
1895
|
-
#[test]
|
|
1896
|
-
fn stopped_with_live_sample_is_unknown_conflict() {
|
|
1897
|
-
let mut node = registered();
|
|
1898
|
-
node.lifecycle = Some("stopped".to_string());
|
|
1899
|
-
let observed = probe("pi_activity_channel");
|
|
1900
|
-
let projected = project_node(
|
|
1901
|
-
&node,
|
|
1902
|
-
Some(&Some(ProbeResult {
|
|
1903
|
-
nodes: vec![observed],
|
|
1904
|
-
..Default::default()
|
|
1905
|
-
})),
|
|
1906
|
-
);
|
|
1907
|
-
assert_eq!(projected.runtime_status, "unknown");
|
|
1908
|
-
assert!(projected.tmux_command.is_none());
|
|
1909
|
-
}
|
|
1910
|
-
|
|
1911
|
-
#[test]
|
|
1912
|
-
fn stopped_with_duplicate_live_samples_is_unknown_conflict() {
|
|
1913
|
-
let mut node = registered();
|
|
1914
|
-
node.lifecycle = Some("stopped".to_string());
|
|
1915
|
-
let projected = project_node(
|
|
1916
|
-
&node,
|
|
1917
|
-
Some(&Some(ProbeResult {
|
|
1918
|
-
nodes: vec![probe("pi_activity_channel"), probe("pi_activity_channel")],
|
|
1919
|
-
..Default::default()
|
|
1920
|
-
})),
|
|
1921
|
-
);
|
|
1922
|
-
assert_eq!(projected.runtime_status, "unknown");
|
|
1923
|
-
assert!(projected.tmux_command.is_none());
|
|
1924
|
-
}
|
|
1925
|
-
|
|
1926
|
-
#[test]
|
|
1927
|
-
fn zero_matches_is_unknown_not_panic() {
|
|
1928
|
-
let node = registered();
|
|
1929
|
-
let mut observed = probe("pi_activity_channel");
|
|
1930
|
-
observed.pane = "%9".to_string();
|
|
1931
|
-
let projected = project_node(
|
|
1932
|
-
&node,
|
|
1933
|
-
Some(&Some(ProbeResult {
|
|
1934
|
-
nodes: vec![observed],
|
|
1935
|
-
..Default::default()
|
|
1936
|
-
})),
|
|
1937
|
-
);
|
|
1938
|
-
assert_eq!(projected.runtime_status, "unknown");
|
|
1939
|
-
}
|
|
1940
|
-
|
|
1941
|
-
#[test]
|
|
1942
|
-
fn multiple_matches_is_unknown_not_indexed() {
|
|
1943
|
-
let node = registered();
|
|
1944
|
-
let projected = project_node(
|
|
1945
|
-
&node,
|
|
1946
|
-
Some(&Some(ProbeResult {
|
|
1947
|
-
nodes: vec![probe("pi_activity_channel"), probe("pi_activity_channel")],
|
|
1948
|
-
..Default::default()
|
|
1949
|
-
})),
|
|
1950
|
-
);
|
|
1951
|
-
assert_eq!(projected.runtime_status, "unknown");
|
|
1952
|
-
}
|
|
1953
|
-
|
|
1954
|
-
// Frozen 1257e8e3 used `br"{\"error\":\"missing\"}"`, which is not a valid
|
|
1955
|
-
// raw byte string (VERIFY compile gate: unknown start of token `\\`).
|
|
1956
|
-
// Keep that failure as history; this regression uses a real producer envelope.
|
|
1957
|
-
#[test]
|
|
1958
|
-
fn parse_probe_rejects_producer_error_envelope() {
|
|
1959
|
-
assert!(parse_probe(producer_error_envelope(), "/tmp/sock").is_err());
|
|
1960
|
-
}
|
|
1961
|
-
|
|
1962
|
-
#[test]
|
|
1963
|
-
fn parse_probe_rejects_exit_zero_error_with_nodes() {
|
|
1964
|
-
let bytes = br#"{"schema_version":1,"socket":"/tmp/sock","sampled_at":"2026-01-01T00:00:00Z","nodes":[{"socket":"/tmp/sock","session":"sess","window_name":"win","pane_id":"%7","provider":"pi","activity":"idle","health":"normal","evidence":{"method":"pi_activity_channel"}}],"error":{"kind":"corpus_error","message":"providers corpus failed"}}"#;
|
|
1965
|
-
assert!(parse_probe(bytes, "/tmp/sock").is_err());
|
|
1966
|
-
}
|
|
1967
|
-
|
|
1968
|
-
#[test]
|
|
1969
|
-
fn parse_probe_rejects_wrong_report_socket() {
|
|
1970
|
-
let bytes = br#"{"schema_version":1,"socket":"/tmp/other","sampled_at":"2026-01-01T00:00:00Z","nodes":[]}"#;
|
|
1971
|
-
assert!(parse_probe(bytes, "/tmp/sock").is_err());
|
|
1972
|
-
}
|
|
1973
|
-
|
|
1974
|
-
#[test]
|
|
1975
|
-
fn parse_probe_accepts_matching_producer_report() {
|
|
1976
|
-
let bytes = br#"{"schema_version":1,"socket":"/tmp/sock","sampled_at":"2026-01-01T00:00:00Z","nodes":[{"socket":"/tmp/sock","session":"sess","window_name":"win","pane_id":"%7","provider":"pi","activity":"idle","health":"normal","session_name":"pi-session","evidence":{"method":"pi_activity_channel"}}]}"#;
|
|
1977
|
-
let parsed = parse_probe(bytes, "/tmp/sock").expect("valid producer report");
|
|
1978
|
-
assert_eq!(parsed.nodes.len(), 1);
|
|
1979
|
-
assert_eq!(parsed.nodes[0].pane, "%7");
|
|
1980
|
-
}
|
|
1981
|
-
}
|