@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,4103 +0,0 @@
|
|
|
1
|
-
//! TMUX-BACKEND RED โ every `Transport` method is `unimplemented!()` today, so these PANIC (RED)
|
|
2
|
-
//! until the porter wires the bodies + `RealCommandRunner`. The OS edge is mocked by
|
|
3
|
-
//! `MockCommandRunner` (records each argv; returns canned `CommandOutput`/io::Error you stage).
|
|
4
|
-
//! Each test asserts (1) the recorded argv == the golden-locked `transport::tmux_*_argv` builder
|
|
5
|
-
//! (or the golden command form for builder-less ops) and (2) the parsed typed return. Golden:
|
|
6
|
-
//! runtime.py (has-session/spawn/kill), leader/__init__.py:335 (set-environment), state.py:341
|
|
7
|
-
//! (_tmux_pane_liveness three-state, ยงbug-085 unknown != dead), transport.rs argv-builders.
|
|
8
|
-
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
|
|
9
|
-
|
|
10
|
-
use std::collections::{BTreeMap, VecDeque};
|
|
11
|
-
use std::os::unix::net::UnixListener;
|
|
12
|
-
use std::path::Path;
|
|
13
|
-
use std::sync::atomic::{AtomicBool, Ordering};
|
|
14
|
-
use std::sync::{Arc, Mutex};
|
|
15
|
-
use std::time::{Duration, Instant};
|
|
16
|
-
|
|
17
|
-
use super::{
|
|
18
|
-
current_paste_to_submit_floor, observe_turn_from_capture,
|
|
19
|
-
sleep_remaining_paste_to_submit_floor, worker_shell_wrapper_command,
|
|
20
|
-
with_cursor_single_enter, with_paste_to_submit_floor, CommandOutput, CommandRunner,
|
|
21
|
-
RealCommandRunner, TmuxBackend, PANE_BINDING_NONCE_METADATA_KEY,
|
|
22
|
-
};
|
|
23
|
-
use crate::layout::worker_env::{
|
|
24
|
-
caller_provider_resolution_from_values, inject_current_caller_provider,
|
|
25
|
-
isolate_worker_spawn_env, worker_spawn_env, CallerProviderResolution, CALLER_ENDPOINT_ENV,
|
|
26
|
-
CALLER_PANE_ENV, CALLER_PROVIDER_ENV,
|
|
27
|
-
};
|
|
28
|
-
use crate::model::enums::{PaneLiveness, Provider};
|
|
29
|
-
use crate::transport::{
|
|
30
|
-
command_basename, normalize_capture, tmux_capture_argv, tmux_query_argv, tmux_send_keys_argv,
|
|
31
|
-
tmux_spawn_argv, tmux_submit_key_name, AttachOutcome, BusySignalKind, CaptureRange,
|
|
32
|
-
CaptureSampleOutcome, InjectPayload, InjectStage, InjectVerification, InputSurfaceProbe, Key,
|
|
33
|
-
PaneField, PaneId, QueryOutcome, SessionName, SetEnvOutcome, SubmitConsumptionReason,
|
|
34
|
-
SubmitVerification, Target, Transport, TransportError, TurnVerification, WindowName,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
type RecordedArgv = Arc<Mutex<Vec<Vec<String>>>>;
|
|
38
|
-
type RecordedStdin = Arc<Mutex<Vec<String>>>;
|
|
39
|
-
|
|
40
|
-
/// A staged runner response: a canned `CommandOutput`, or an io::Error (kind) for the error path.
|
|
41
|
-
#[derive(Clone)]
|
|
42
|
-
enum MockResp {
|
|
43
|
-
Out(CommandOutput),
|
|
44
|
-
Io(std::io::ErrorKind),
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/// Records every argv it is asked to run; replays staged responses (then a default).
|
|
48
|
-
struct MockCommandRunner {
|
|
49
|
-
recorded: RecordedArgv,
|
|
50
|
-
stdin_recorded: RecordedStdin,
|
|
51
|
-
queue: Mutex<VecDeque<MockResp>>,
|
|
52
|
-
default: MockResp,
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/// Models the real build-before-destroy overlap: the spawn command creates `%new`, while a
|
|
56
|
-
/// name-based lookup still resolves the same-named old window `%old`.
|
|
57
|
-
struct SameNameSpawnRunner {
|
|
58
|
-
recorded: RecordedArgv,
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
impl CommandRunner for SameNameSpawnRunner {
|
|
62
|
-
fn run(&self, argv: &[String]) -> Result<CommandOutput, std::io::Error> {
|
|
63
|
-
self.recorded.lock().unwrap().push(argv.to_vec());
|
|
64
|
-
let output = match argv.get(1).map(String::as_str) {
|
|
65
|
-
Some("new-window") => ok("%new\n"),
|
|
66
|
-
Some("display-message") => ok("%old\n"),
|
|
67
|
-
Some("list-panes") => ok(
|
|
68
|
-
"%old\tteamsess\t0\tdeveloper\t0\t/dev/ttys001\tnode\t1\t/work/dir\t1\t0\t101\n\
|
|
69
|
-
%new\tteamsess\t1\tdeveloper\t0\t/dev/ttys002\tnode\t1\t/work/dir\t1\t0\t202\n",
|
|
70
|
-
),
|
|
71
|
-
_ => fail(64, "unexpected scripted tmux command"),
|
|
72
|
-
};
|
|
73
|
-
Ok(output)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
fn run_with_stdin(
|
|
77
|
-
&self,
|
|
78
|
-
argv: &[String],
|
|
79
|
-
_stdin: &str,
|
|
80
|
-
) -> Result<CommandOutput, std::io::Error> {
|
|
81
|
-
self.run(argv)
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
impl CommandRunner for MockCommandRunner {
|
|
86
|
-
fn run(&self, argv: &[String]) -> Result<CommandOutput, std::io::Error> {
|
|
87
|
-
self.recorded.lock().unwrap().push(argv.to_vec());
|
|
88
|
-
let resp = self
|
|
89
|
-
.queue
|
|
90
|
-
.lock()
|
|
91
|
-
.unwrap()
|
|
92
|
-
.pop_front()
|
|
93
|
-
.unwrap_or_else(|| self.default.clone());
|
|
94
|
-
match resp {
|
|
95
|
-
MockResp::Out(o) => Ok(o),
|
|
96
|
-
MockResp::Io(kind) => Err(std::io::Error::new(kind, "mock runner io error")),
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
fn run_with_stdin(
|
|
101
|
-
&self,
|
|
102
|
-
argv: &[String],
|
|
103
|
-
stdin: &str,
|
|
104
|
-
) -> Result<CommandOutput, std::io::Error> {
|
|
105
|
-
self.stdin_recorded.lock().unwrap().push(stdin.to_string());
|
|
106
|
-
self.run(argv)
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
fn ok(stdout: &str) -> CommandOutput {
|
|
111
|
-
CommandOutput {
|
|
112
|
-
success: true,
|
|
113
|
-
code: Some(0),
|
|
114
|
-
stdout: stdout.to_string(),
|
|
115
|
-
stderr: String::new(),
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
fn fail(code: i32, stderr: &str) -> CommandOutput {
|
|
119
|
-
CommandOutput {
|
|
120
|
-
success: false,
|
|
121
|
-
code: Some(code),
|
|
122
|
-
stdout: String::new(),
|
|
123
|
-
stderr: stderr.to_string(),
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
fn spawned_caller_env() -> (BTreeMap<String, String>, Vec<String>) {
|
|
128
|
-
let mut env = worker_spawn_env(
|
|
129
|
-
vec![
|
|
130
|
-
(CALLER_PROVIDER_ENV.to_string(), "claude".to_string()),
|
|
131
|
-
(CALLER_PANE_ENV.to_string(), "%old".to_string()),
|
|
132
|
-
(CALLER_ENDPOINT_ENV.to_string(), "/tmp/old.sock".to_string()),
|
|
133
|
-
(
|
|
134
|
-
"TEAM_AGENT_LEADER_PROVIDER".to_string(),
|
|
135
|
-
"claude".to_string(),
|
|
136
|
-
),
|
|
137
|
-
("TMUX".to_string(), "/tmp/parent.sock,1,0".to_string()),
|
|
138
|
-
("TMUX_PANE".to_string(), "%parent".to_string()),
|
|
139
|
-
],
|
|
140
|
-
Path::new("/tmp/worker"),
|
|
141
|
-
"child",
|
|
142
|
-
Some("team"),
|
|
143
|
-
None,
|
|
144
|
-
);
|
|
145
|
-
assert!(
|
|
146
|
-
!env.keys().any(|key| key.starts_with("TEAM_AGENT_CALLER_")),
|
|
147
|
-
"inherited caller namespace must be stripped before inject: {env:?}"
|
|
148
|
-
);
|
|
149
|
-
assert!(!env.contains_key("TEAM_AGENT_LEADER_PROVIDER"));
|
|
150
|
-
let env_unset = isolate_worker_spawn_env(Provider::Pi, &mut env, Vec::<String>::new());
|
|
151
|
-
inject_current_caller_provider(&mut env, Provider::Pi);
|
|
152
|
-
(env, env_unset)
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
fn assert_caller_unset_and_assignment_once(command: &str) {
|
|
156
|
-
assert_eq!(command.matches("unset TEAM_AGENT_CALLER_PROVIDER").count(), 1);
|
|
157
|
-
assert_eq!(command.matches("unset TEAM_AGENT_CALLER_PANE_ID").count(), 1);
|
|
158
|
-
assert_eq!(
|
|
159
|
-
command
|
|
160
|
-
.matches("unset TEAM_AGENT_CALLER_TMUX_ENDPOINT")
|
|
161
|
-
.count(),
|
|
162
|
-
1
|
|
163
|
-
);
|
|
164
|
-
assert_eq!(command.matches("TEAM_AGENT_CALLER_PROVIDER=pi").count(), 1);
|
|
165
|
-
assert_eq!(command.matches("TEAM_AGENT_CALLER_PANE_ID=").count(), 1);
|
|
166
|
-
assert_eq!(
|
|
167
|
-
command.matches("TEAM_AGENT_CALLER_TMUX_ENDPOINT=").count(),
|
|
168
|
-
1
|
|
169
|
-
);
|
|
170
|
-
assert!(command.contains("TEAM_AGENT_CALLER_PANE_ID=\"${TMUX_PANE-}\""));
|
|
171
|
-
assert!(command.contains("TEAM_AGENT_CALLER_TMUX_ENDPOINT=\"${TMUX%%,*}\""));
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
fn assignment_token<'a>(command: &'a str, key: &str) -> &'a str {
|
|
175
|
-
let prefix = format!("{key}=");
|
|
176
|
-
command
|
|
177
|
-
.split_whitespace()
|
|
178
|
-
.find(|token| token.starts_with(&prefix))
|
|
179
|
-
.unwrap_or_else(|| panic!("missing {key} assignment in {command}"))
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
fn expand_caller_allowlist(command: &str, tmux: &str, pane: &str) -> (String, String, String) {
|
|
183
|
-
let script = format!(
|
|
184
|
-
"{}; {}; {}; printf '%s\\n%s\\n%s\\n' \"${{{}}}\" \"${{{}}}\" \"${{{}}}\"",
|
|
185
|
-
assignment_token(command, CALLER_PROVIDER_ENV),
|
|
186
|
-
assignment_token(command, CALLER_PANE_ENV),
|
|
187
|
-
assignment_token(command, CALLER_ENDPOINT_ENV),
|
|
188
|
-
CALLER_PROVIDER_ENV,
|
|
189
|
-
CALLER_PANE_ENV,
|
|
190
|
-
CALLER_ENDPOINT_ENV,
|
|
191
|
-
);
|
|
192
|
-
let output = std::process::Command::new("sh")
|
|
193
|
-
.arg("-c")
|
|
194
|
-
.arg(&script)
|
|
195
|
-
.env("TMUX", tmux)
|
|
196
|
-
.env("TMUX_PANE", pane)
|
|
197
|
-
.env_remove(CALLER_PROVIDER_ENV)
|
|
198
|
-
.env_remove(CALLER_PANE_ENV)
|
|
199
|
-
.env_remove(CALLER_ENDPOINT_ENV)
|
|
200
|
-
.output()
|
|
201
|
-
.expect("expand caller allowlist through sh");
|
|
202
|
-
assert!(
|
|
203
|
-
output.status.success(),
|
|
204
|
-
"sh expand failed: status={:?} stderr={} script={script}",
|
|
205
|
-
output.status.code(),
|
|
206
|
-
String::from_utf8_lossy(&output.stderr)
|
|
207
|
-
);
|
|
208
|
-
let stdout = String::from_utf8(output.stdout).expect("caller allowlist stdout utf8");
|
|
209
|
-
let mut lines = stdout.lines();
|
|
210
|
-
let provider = lines.next().unwrap_or("").to_string();
|
|
211
|
-
let pane = lines.next().unwrap_or("").to_string();
|
|
212
|
-
let endpoint = lines.next().unwrap_or("").to_string();
|
|
213
|
-
(provider, pane, endpoint)
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
fn resolve_expanded_caller(
|
|
217
|
-
command: &str,
|
|
218
|
-
tmux: &str,
|
|
219
|
-
pane: &str,
|
|
220
|
-
scoped: Option<&str>,
|
|
221
|
-
) -> CallerProviderResolution {
|
|
222
|
-
let (provider, context_pane, context_endpoint) = expand_caller_allowlist(command, tmux, pane);
|
|
223
|
-
let current_endpoint = tmux.split(',').next().unwrap_or(tmux);
|
|
224
|
-
caller_provider_resolution_from_values(
|
|
225
|
-
Some(provider.as_str()),
|
|
226
|
-
Some(context_pane.as_str()),
|
|
227
|
-
Some(context_endpoint.as_str()),
|
|
228
|
-
None,
|
|
229
|
-
None,
|
|
230
|
-
Some(pane),
|
|
231
|
-
Some(current_endpoint),
|
|
232
|
-
scoped.or(Some(current_endpoint)),
|
|
233
|
-
)
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
#[test]
|
|
237
|
-
fn worker_caller_provider_is_generated_and_scoped_to_provider_invocation() {
|
|
238
|
-
let (env, env_unset) = spawned_caller_env();
|
|
239
|
-
let argv = ["pi".to_string(), "--help".to_string()];
|
|
240
|
-
let cwd = Path::new("/tmp/worker");
|
|
241
|
-
let wrapper = worker_shell_wrapper_command(&argv, cwd, &env, &env_unset, "pi");
|
|
242
|
-
let cold_start = super::shell_command(&argv, cwd, &env, &env_unset);
|
|
243
|
-
assert_eq!(env.get(CALLER_PROVIDER_ENV).map(String::as_str), Some("pi"));
|
|
244
|
-
assert!(!env.contains_key(CALLER_PANE_ENV));
|
|
245
|
-
assert!(!env.contains_key(CALLER_ENDPOINT_ENV));
|
|
246
|
-
assert_caller_unset_and_assignment_once(&wrapper);
|
|
247
|
-
assert_caller_unset_and_assignment_once(&cold_start);
|
|
248
|
-
assert!(
|
|
249
|
-
cold_start.contains("exec"),
|
|
250
|
-
"cold-start shell_command must exec the provider: {cold_start}"
|
|
251
|
-
);
|
|
252
|
-
let wrapper_tail = wrapper.split_once("; rc=$?").map(|(_, tail)| tail).unwrap_or("");
|
|
253
|
-
assert!(
|
|
254
|
-
!wrapper_tail.contains("TEAM_AGENT_CALLER_"),
|
|
255
|
-
"provider-exit tail must not retain caller context: {wrapper_tail}"
|
|
256
|
-
);
|
|
257
|
-
assert!(
|
|
258
|
-
!cold_start.contains("; rc=$?"),
|
|
259
|
-
"cold-start exec path has no inert tail: {cold_start}"
|
|
260
|
-
);
|
|
261
|
-
let tmux = "/tmp/tmux.sock,123,0";
|
|
262
|
-
let pane = "%1";
|
|
263
|
-
assert_eq!(
|
|
264
|
-
resolve_expanded_caller(&wrapper, tmux, pane, Some("/tmp/tmux.sock")),
|
|
265
|
-
CallerProviderResolution::Valid(Provider::Pi)
|
|
266
|
-
);
|
|
267
|
-
assert_eq!(
|
|
268
|
-
resolve_expanded_caller(&cold_start, tmux, pane, Some("/tmp/tmux.sock")),
|
|
269
|
-
CallerProviderResolution::Valid(Provider::Pi)
|
|
270
|
-
);
|
|
271
|
-
// Preserve the context generated in pane %1; only the caller moves to %2.
|
|
272
|
-
let (provider, context_pane, context_endpoint) = expand_caller_allowlist(&wrapper, tmux, pane);
|
|
273
|
-
assert_eq!(context_pane, "%1");
|
|
274
|
-
assert_eq!(
|
|
275
|
-
caller_provider_resolution_from_values(
|
|
276
|
-
Some(&provider),
|
|
277
|
-
Some(&context_pane),
|
|
278
|
-
Some(&context_endpoint),
|
|
279
|
-
None,
|
|
280
|
-
None,
|
|
281
|
-
Some("%2"),
|
|
282
|
-
Some("/tmp/tmux.sock"),
|
|
283
|
-
Some("/tmp/tmux.sock"),
|
|
284
|
-
),
|
|
285
|
-
CallerProviderResolution::Invalid
|
|
286
|
-
);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
#[test]
|
|
290
|
-
fn worker_caller_context_is_rewritten_per_spawn_and_not_inherited() {
|
|
291
|
-
let (parent_env, parent_unset) = spawned_caller_env();
|
|
292
|
-
let parent_cmd = worker_shell_wrapper_command(
|
|
293
|
-
&["pi".to_string()],
|
|
294
|
-
Path::new("/tmp/parent-worker"),
|
|
295
|
-
&parent_env,
|
|
296
|
-
&parent_unset,
|
|
297
|
-
"pi",
|
|
298
|
-
);
|
|
299
|
-
assert_eq!(
|
|
300
|
-
resolve_expanded_caller(&parent_cmd, "/tmp/current.sock,1,0", "%4", None),
|
|
301
|
-
CallerProviderResolution::Valid(Provider::Pi)
|
|
302
|
-
);
|
|
303
|
-
|
|
304
|
-
let mut child_parent = parent_env
|
|
305
|
-
.iter()
|
|
306
|
-
.map(|(key, value)| (key.clone(), value.clone()))
|
|
307
|
-
.collect::<Vec<_>>();
|
|
308
|
-
child_parent.push((CALLER_PROVIDER_ENV.to_string(), "pi".to_string()));
|
|
309
|
-
child_parent.push((CALLER_PANE_ENV.to_string(), "%4".to_string()));
|
|
310
|
-
child_parent.push((
|
|
311
|
-
CALLER_ENDPOINT_ENV.to_string(),
|
|
312
|
-
"/tmp/current.sock".to_string(),
|
|
313
|
-
));
|
|
314
|
-
let mut child_env = worker_spawn_env(
|
|
315
|
-
child_parent,
|
|
316
|
-
Path::new("/tmp/child-worker"),
|
|
317
|
-
"grandchild",
|
|
318
|
-
Some("child-team"),
|
|
319
|
-
None,
|
|
320
|
-
);
|
|
321
|
-
assert!(
|
|
322
|
-
!child_env
|
|
323
|
-
.keys()
|
|
324
|
-
.any(|key| key.starts_with("TEAM_AGENT_CALLER_")),
|
|
325
|
-
"child spawn must strip the current worker caller namespace: {child_env:?}"
|
|
326
|
-
);
|
|
327
|
-
let child_unset = isolate_worker_spawn_env(Provider::Codex, &mut child_env, Vec::<String>::new());
|
|
328
|
-
inject_current_caller_provider(&mut child_env, Provider::Codex);
|
|
329
|
-
let child_cmd = worker_shell_wrapper_command(
|
|
330
|
-
&["codex".to_string()],
|
|
331
|
-
Path::new("/tmp/child-worker"),
|
|
332
|
-
&child_env,
|
|
333
|
-
&child_unset,
|
|
334
|
-
"codex",
|
|
335
|
-
);
|
|
336
|
-
assert!(child_cmd.contains("TEAM_AGENT_CALLER_PROVIDER=codex"));
|
|
337
|
-
assert!(!child_cmd.contains("TEAM_AGENT_CALLER_PROVIDER=pi"));
|
|
338
|
-
assert_eq!(
|
|
339
|
-
resolve_expanded_caller(&child_cmd, "/tmp/child.sock,1,0", "%8", None),
|
|
340
|
-
CallerProviderResolution::Valid(Provider::Codex)
|
|
341
|
-
);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/// Build a backend over a mock runner: `default` answers every un-queued call; `queued` is drained
|
|
345
|
-
/// first. Returns the backend + the shared recorded-argv handle (read AFTER the call).
|
|
346
|
-
fn backend_with(default: MockResp, queued: Vec<MockResp>) -> (TmuxBackend, RecordedArgv) {
|
|
347
|
-
let recorded = Arc::new(Mutex::new(Vec::new()));
|
|
348
|
-
let stdin_recorded = Arc::new(Mutex::new(Vec::new()));
|
|
349
|
-
let runner = MockCommandRunner {
|
|
350
|
-
recorded: Arc::clone(&recorded),
|
|
351
|
-
stdin_recorded,
|
|
352
|
-
queue: Mutex::new(queued.into_iter().collect()),
|
|
353
|
-
default,
|
|
354
|
-
};
|
|
355
|
-
(TmuxBackend::with_runner(Box::new(runner)), recorded)
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
#[test]
|
|
359
|
-
fn pane_dead_observation_requires_native_boolean_receipt() {
|
|
360
|
-
for (text, expected) in [("1\n", Some(true)), ("0\n", Some(false)), ("", None), ("dead", None), ("2", None)] {
|
|
361
|
-
let (backend, recorded) = backend_with(MockResp::Out(ok(text)), Vec::new());
|
|
362
|
-
assert_eq!(backend.pane_is_dead(&PaneId::new("%47")).unwrap(), expected);
|
|
363
|
-
assert_eq!(recorded.lock().unwrap()[0], svec(&[
|
|
364
|
-
"tmux", "display-message", "-p", "-t", "%47", "#{pane_dead}",
|
|
365
|
-
]));
|
|
366
|
-
}
|
|
367
|
-
let (backend, _) = backend_with(MockResp::Out(fail(1, "pane unavailable")), Vec::new());
|
|
368
|
-
assert_eq!(backend.pane_is_dead(&PaneId::new("%47")).unwrap(), None);
|
|
369
|
-
let (backend, _) = backend_with(MockResp::Io(std::io::ErrorKind::TimedOut), Vec::new());
|
|
370
|
-
assert!(backend.pane_is_dead(&PaneId::new("%47")).is_err());
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
#[test]
|
|
374
|
-
fn provider_exit_receipt_accepts_only_shell_exit_status() {
|
|
375
|
-
for (text, expected) in [
|
|
376
|
-
("", None),
|
|
377
|
-
("running", None),
|
|
378
|
-
("[team-agent] pi exited with 0", None),
|
|
379
|
-
("256", None),
|
|
380
|
-
("0\n", Some(0)),
|
|
381
|
-
("17\n", Some(17)),
|
|
382
|
-
("143\n", Some(143)),
|
|
383
|
-
] {
|
|
384
|
-
let (backend, recorded) = backend_with(MockResp::Out(ok(text)), Vec::new());
|
|
385
|
-
assert_eq!(
|
|
386
|
-
backend.provider_exit_status(&PaneId::new("%47")).unwrap(),
|
|
387
|
-
expected
|
|
388
|
-
);
|
|
389
|
-
let calls = recorded.lock().unwrap();
|
|
390
|
-
assert_eq!(calls.len(), 1);
|
|
391
|
-
assert_eq!(calls[0][4], "%47");
|
|
392
|
-
assert_eq!(calls[0][5], "#{@team-agent-provider-exit-status}");
|
|
393
|
-
}
|
|
394
|
-
let (backend, _) = backend_with(MockResp::Out(fail(1, "pane unavailable")), Vec::new());
|
|
395
|
-
assert_eq!(
|
|
396
|
-
backend.provider_exit_status(&PaneId::new("%47")).unwrap(),
|
|
397
|
-
None
|
|
398
|
-
);
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
fn backend_with_stdin(
|
|
402
|
-
default: MockResp,
|
|
403
|
-
queued: Vec<MockResp>,
|
|
404
|
-
) -> (TmuxBackend, RecordedArgv, RecordedStdin) {
|
|
405
|
-
let recorded = Arc::new(Mutex::new(Vec::new()));
|
|
406
|
-
let stdin_recorded = Arc::new(Mutex::new(Vec::new()));
|
|
407
|
-
let runner = MockCommandRunner {
|
|
408
|
-
recorded: Arc::clone(&recorded),
|
|
409
|
-
stdin_recorded: Arc::clone(&stdin_recorded),
|
|
410
|
-
queue: Mutex::new(queued.into_iter().collect()),
|
|
411
|
-
default,
|
|
412
|
-
};
|
|
413
|
-
(
|
|
414
|
-
TmuxBackend::with_runner(Box::new(runner)),
|
|
415
|
-
recorded,
|
|
416
|
-
stdin_recorded,
|
|
417
|
-
)
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
#[test]
|
|
421
|
-
fn a21_spawn_command_too_long_is_structured_before_transport() {
|
|
422
|
-
let (backend, recorded) = backend_with(MockResp::Out(ok("%0\n")), Vec::new());
|
|
423
|
-
let session = SessionName::new("a21-session");
|
|
424
|
-
let window = WindowName::new("worker-long-role");
|
|
425
|
-
let argv = vec!["codex".to_string(), "x".repeat(20_000)];
|
|
426
|
-
|
|
427
|
-
let error = backend
|
|
428
|
-
.spawn_first(
|
|
429
|
-
&session,
|
|
430
|
-
&window,
|
|
431
|
-
&argv,
|
|
432
|
-
Path::new("/tmp/a21-workspace"),
|
|
433
|
-
&BTreeMap::new(),
|
|
434
|
-
)
|
|
435
|
-
.expect_err("oversized spawn must fail before tmux transport");
|
|
436
|
-
let text = error.to_string();
|
|
437
|
-
assert!(
|
|
438
|
-
text.contains("command_too_long"),
|
|
439
|
-
"structured error: {text}"
|
|
440
|
-
);
|
|
441
|
-
assert!(
|
|
442
|
-
text.contains("worker-long-role"),
|
|
443
|
-
"seat must be named: {text}"
|
|
444
|
-
);
|
|
445
|
-
assert!(
|
|
446
|
-
text.contains("actual_bytes="),
|
|
447
|
-
"actual length must be visible: {text}"
|
|
448
|
-
);
|
|
449
|
-
assert!(
|
|
450
|
-
text.contains("limit_bytes="),
|
|
451
|
-
"limit must be visible: {text}"
|
|
452
|
-
);
|
|
453
|
-
assert!(
|
|
454
|
-
recorded.lock().unwrap().is_empty(),
|
|
455
|
-
"tmux must not be called: {text}"
|
|
456
|
-
);
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
fn svec(items: &[&str]) -> Vec<String> {
|
|
460
|
-
items.iter().map(|s| (*s).to_string()).collect()
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
struct EnvGuard {
|
|
464
|
-
saved: Vec<(String, Option<String>)>,
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
impl EnvGuard {
|
|
468
|
-
fn apply(vars: &[(&str, Option<&str>)]) -> Self {
|
|
469
|
-
let saved = vars
|
|
470
|
-
.iter()
|
|
471
|
-
.map(|(k, _)| ((*k).to_string(), std::env::var(k).ok()))
|
|
472
|
-
.collect();
|
|
473
|
-
for (k, v) in vars {
|
|
474
|
-
match v {
|
|
475
|
-
Some(val) => std::env::set_var(k, val),
|
|
476
|
-
None => std::env::remove_var(k),
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
Self { saved }
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
impl Drop for EnvGuard {
|
|
484
|
-
fn drop(&mut self) {
|
|
485
|
-
for (k, v) in &self.saved {
|
|
486
|
-
match v {
|
|
487
|
-
Some(val) => std::env::set_var(k, val),
|
|
488
|
-
None => std::env::remove_var(k),
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
#[test]
|
|
495
|
-
#[serial_test::serial(env)]
|
|
496
|
-
fn leader_receiver_endpoint_from_tmux_env_preserves_full_socket_path() {
|
|
497
|
-
let leader_socket = "/tmp/ta-leader-root/tmux-501/dl2f";
|
|
498
|
-
let _env = EnvGuard::apply(&[
|
|
499
|
-
("TMUX", Some("/tmp/ta-leader-root/tmux-501/dl2f,12345,0")),
|
|
500
|
-
("TMUX_TMPDIR", Some("/tmp/ta-coordinator-root")),
|
|
501
|
-
]);
|
|
502
|
-
|
|
503
|
-
assert_eq!(
|
|
504
|
-
super::socket_name_from_tmux_env().as_deref(),
|
|
505
|
-
Some(leader_socket),
|
|
506
|
-
"leader receivers must persist the exact tmux endpoint from $TMUX; a short -L socket \
|
|
507
|
-
name is re-rooted under the coordinator's TMUX_TMPDIR and cannot reach an external \
|
|
508
|
-
leader pane"
|
|
509
|
-
);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
#[test]
|
|
513
|
-
#[serial_test::serial(env)]
|
|
514
|
-
fn leader_receiver_endpoint_from_tmux_env_rejects_short_socket_name() {
|
|
515
|
-
let _env = EnvGuard::apply(&[
|
|
516
|
-
("TMUX", Some("dl9aa40c88,12345,0")),
|
|
517
|
-
("TMUX_TMPDIR", Some("/tmp/ta-coordinator-root")),
|
|
518
|
-
]);
|
|
519
|
-
|
|
520
|
-
assert_eq!(
|
|
521
|
-
super::socket_name_from_tmux_env(),
|
|
522
|
-
None,
|
|
523
|
-
"leader_receiver.tmux_socket is a durable physical endpoint: a short socket name from \
|
|
524
|
-
$TMUX must not be persisted because tmux -L <short> is re-rooted under the coordinator"
|
|
525
|
-
);
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
#[test]
|
|
529
|
-
fn leader_receiver_delivery_uses_full_socket_endpoint_not_short_l_reconstruction() {
|
|
530
|
-
let manifest = Path::new(env!("CARGO_MANIFEST_DIR"));
|
|
531
|
-
let delivery = std::fs::read_to_string(manifest.join("src/messaging/delivery.rs")).unwrap();
|
|
532
|
-
let leader_receiver =
|
|
533
|
-
std::fs::read_to_string(manifest.join("src/messaging/leader_receiver.rs")).unwrap();
|
|
534
|
-
let tmux_backend = std::fs::read_to_string(manifest.join("src/tmux_backend.rs")).unwrap();
|
|
535
|
-
|
|
536
|
-
assert!(
|
|
537
|
-
tmux_backend.contains("\"-S\""),
|
|
538
|
-
"tmux backend must support `tmux -S <full-socket-path>` for persisted external leader \
|
|
539
|
-
endpoints; `-L <short-name>` is not enough when leader and coordinator TMUX_TMPDIR differ"
|
|
540
|
-
);
|
|
541
|
-
assert!(
|
|
542
|
-
!delivery.contains("TmuxBackend::for_socket_name(socket)"),
|
|
543
|
-
"worker->leader delivery must not reconstruct an external leader endpoint with \
|
|
544
|
-
`tmux -L <short-name>`; it must use the persisted full socket path endpoint"
|
|
545
|
-
);
|
|
546
|
-
assert!(
|
|
547
|
-
!leader_receiver.contains("TmuxBackend::for_socket_name(socket)"),
|
|
548
|
-
"leader_receiver live checks must verify the same full socket endpoint used by delivery, \
|
|
549
|
-
not a short socket name resolved under the coordinator's socket root"
|
|
550
|
-
);
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
#[test]
|
|
554
|
-
fn leader_receiver_full_endpoint_liveness_list_and_inject_use_s_path_command_shape() {
|
|
555
|
-
let endpoint = "/private/tmp/tmux-501/default";
|
|
556
|
-
let stdout = "%7\tteam-x\t0\tleader\t0\t/dev/ttys003\tbash\t1\t/Users/me/work\t1\t0\n";
|
|
557
|
-
let (be, rec, _stdin) = {
|
|
558
|
-
let recorded = Arc::new(Mutex::new(Vec::new()));
|
|
559
|
-
let stdin_recorded = Arc::new(Mutex::new(Vec::new()));
|
|
560
|
-
let runner = MockCommandRunner {
|
|
561
|
-
recorded: Arc::clone(&recorded),
|
|
562
|
-
stdin_recorded: Arc::clone(&stdin_recorded),
|
|
563
|
-
queue: Mutex::new(
|
|
564
|
-
vec![
|
|
565
|
-
MockResp::Out(ok(stdout)),
|
|
566
|
-
MockResp::Out(ok("%7\n")),
|
|
567
|
-
MockResp::Out(ok("")),
|
|
568
|
-
MockResp::Out(ok("")),
|
|
569
|
-
MockResp::Out(ok("")),
|
|
570
|
-
]
|
|
571
|
-
.into_iter()
|
|
572
|
-
.collect(),
|
|
573
|
-
),
|
|
574
|
-
default: MockResp::Out(ok("")),
|
|
575
|
-
};
|
|
576
|
-
(
|
|
577
|
-
TmuxBackend::with_runner_for_tmux_endpoint(Box::new(runner), endpoint),
|
|
578
|
-
recorded,
|
|
579
|
-
stdin_recorded,
|
|
580
|
-
)
|
|
581
|
-
};
|
|
582
|
-
|
|
583
|
-
let _ = be.list_targets().expect("list_targets via endpoint");
|
|
584
|
-
let _ = be
|
|
585
|
-
.liveness(&PaneId::new("%7"))
|
|
586
|
-
.expect("liveness via endpoint");
|
|
587
|
-
let _ = be
|
|
588
|
-
.inject(
|
|
589
|
-
&Target::Pane(PaneId::new("%7")),
|
|
590
|
-
&InjectPayload::Text("hello leader".to_string()),
|
|
591
|
-
Key::Enter,
|
|
592
|
-
true,
|
|
593
|
-
)
|
|
594
|
-
.expect("inject via endpoint");
|
|
595
|
-
|
|
596
|
-
let calls = rec.lock().unwrap().clone();
|
|
597
|
-
assert!(
|
|
598
|
-
calls.len() >= 5,
|
|
599
|
-
"fixture must exercise list-panes, display-message, buffer/paste, and send-keys; got {calls:?}"
|
|
600
|
-
);
|
|
601
|
-
for call in &calls {
|
|
602
|
-
assert!(
|
|
603
|
-
call.starts_with(&["tmux".to_string(), "-S".to_string(), endpoint.to_string()]),
|
|
604
|
-
"leader receiver list/liveness/inject must use tmux -S <full socket path>; got {call:?}"
|
|
605
|
-
);
|
|
606
|
-
assert!(
|
|
607
|
-
!call
|
|
608
|
-
.windows(2)
|
|
609
|
-
.any(|w| w == ["-L".to_string(), endpoint.to_string()]),
|
|
610
|
-
"leader receiver full endpoint must never be reconstructed with -L; got {call:?}"
|
|
611
|
-
);
|
|
612
|
-
}
|
|
613
|
-
assert!(
|
|
614
|
-
calls
|
|
615
|
-
.iter()
|
|
616
|
-
.any(|call| call.iter().any(|arg| arg == "list-panes"))
|
|
617
|
-
&& calls
|
|
618
|
-
.iter()
|
|
619
|
-
.any(|call| call.iter().any(|arg| arg == "display-message"))
|
|
620
|
-
&& calls
|
|
621
|
-
.iter()
|
|
622
|
-
.any(|call| call.iter().any(|arg| arg == "paste-buffer"))
|
|
623
|
-
&& calls
|
|
624
|
-
.iter()
|
|
625
|
-
.any(|call| call.iter().any(|arg| arg == "send-keys")),
|
|
626
|
-
"contract must cover liveness/list/inject command shapes; got {calls:?}"
|
|
627
|
-
);
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
#[test]
|
|
631
|
-
#[serial_test::serial(env)]
|
|
632
|
-
fn leader_receiver_short_endpoint_must_not_reconstruct_tmux_l_socket() {
|
|
633
|
-
let endpoint = "dl9aa40c88";
|
|
634
|
-
let uid = unsafe { libc::geteuid() };
|
|
635
|
-
let tmp = std::env::temp_dir().join(format!("ta-tmux-short-endpoint-{}", std::process::id()));
|
|
636
|
-
let root = tmp.join(format!("tmux-{uid}"));
|
|
637
|
-
std::fs::create_dir_all(&root).unwrap();
|
|
638
|
-
let socket_path = root.join(endpoint);
|
|
639
|
-
let _listener = UnixListener::bind(&socket_path).unwrap();
|
|
640
|
-
let socket_path = socket_path.canonicalize().unwrap();
|
|
641
|
-
let _env = EnvGuard::apply(&[("TMPDIR", Some(tmp.to_str().unwrap()))]);
|
|
642
|
-
let (be, rec) = {
|
|
643
|
-
let recorded = Arc::new(Mutex::new(Vec::new()));
|
|
644
|
-
let runner = MockCommandRunner {
|
|
645
|
-
recorded: Arc::clone(&recorded),
|
|
646
|
-
stdin_recorded: Arc::new(Mutex::new(Vec::new())),
|
|
647
|
-
queue: Mutex::new(vec![MockResp::Out(ok(""))].into_iter().collect()),
|
|
648
|
-
default: MockResp::Out(ok("")),
|
|
649
|
-
};
|
|
650
|
-
(
|
|
651
|
-
TmuxBackend::with_runner_for_tmux_endpoint(Box::new(runner), endpoint),
|
|
652
|
-
recorded,
|
|
653
|
-
)
|
|
654
|
-
};
|
|
655
|
-
|
|
656
|
-
let _ = be
|
|
657
|
-
.list_targets()
|
|
658
|
-
.expect("short endpoint should not become -L");
|
|
659
|
-
|
|
660
|
-
let calls = rec.lock().unwrap().clone();
|
|
661
|
-
assert!(
|
|
662
|
-
calls.iter().all(|call| !call
|
|
663
|
-
.windows(2)
|
|
664
|
-
.any(|w| w == ["-L".to_string(), endpoint.to_string()])),
|
|
665
|
-
"non-canonical leader endpoints must be rejected or left unbound, never reconstructed as \
|
|
666
|
-
tmux -L <short> under the coordinator socket root; calls={calls:?}"
|
|
667
|
-
);
|
|
668
|
-
assert!(
|
|
669
|
-
calls.iter().all(|call| call.starts_with(&[
|
|
670
|
-
"tmux".to_string(),
|
|
671
|
-
"-S".to_string(),
|
|
672
|
-
socket_path.to_string_lossy().to_string()
|
|
673
|
-
])),
|
|
674
|
-
"short leader endpoints must resolve to the existing physical socket path with -S; calls={calls:?}"
|
|
675
|
-
);
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
// โโ 1. has_session: exit 0 -> true, exit 1 -> false; argv = `tmux has-session -t <s>` โโโโโโโโโโ
|
|
679
|
-
#[test]
|
|
680
|
-
fn has_session_argv_and_exit_code_maps_to_bool() {
|
|
681
|
-
let (be, rec) = backend_with(MockResp::Out(ok("")), vec![]);
|
|
682
|
-
assert!(
|
|
683
|
-
be.has_session(&SessionName::new("sess"))
|
|
684
|
-
.expect("has_session"),
|
|
685
|
-
"exit 0 -> true"
|
|
686
|
-
);
|
|
687
|
-
assert_eq!(
|
|
688
|
-
rec.lock().unwrap()[0],
|
|
689
|
-
svec(&["tmux", "has-session", "-t", "sess"])
|
|
690
|
-
);
|
|
691
|
-
|
|
692
|
-
let (be, rec) = backend_with(MockResp::Out(fail(1, "can't find session: sess")), vec![]);
|
|
693
|
-
assert!(
|
|
694
|
-
!be.has_session(&SessionName::new("sess"))
|
|
695
|
-
.expect("has_session"),
|
|
696
|
-
"exit 1 -> false"
|
|
697
|
-
);
|
|
698
|
-
assert_eq!(
|
|
699
|
-
rec.lock().unwrap()[0],
|
|
700
|
-
svec(&["tmux", "has-session", "-t", "sess"])
|
|
701
|
-
);
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
// โโ 2. spawn_first / spawn_into frame via tmux_spawn_argv; canned output parses pane id โโโโโโโโ
|
|
705
|
-
#[test]
|
|
706
|
-
fn spawn_first_frames_via_new_session_builder_and_parses_pane_id() {
|
|
707
|
-
let pane_inventory = "%3\tteamsess\t0\tw1\t0\t/dev/ttys003\tnode\t1\t/work/dir\t1\t0\t123\n";
|
|
708
|
-
let (be, rec) = backend_with(
|
|
709
|
-
MockResp::Out(ok("")),
|
|
710
|
-
vec![MockResp::Out(ok("%3\n")), MockResp::Out(ok(pane_inventory))],
|
|
711
|
-
);
|
|
712
|
-
let s = SessionName::new("teamsess");
|
|
713
|
-
let w = WindowName::new("w1");
|
|
714
|
-
let env = BTreeMap::from([("TEAM_AGENT_ID".to_string(), "w1".to_string())]);
|
|
715
|
-
let result = be
|
|
716
|
-
.spawn_first(
|
|
717
|
-
&s,
|
|
718
|
-
&w,
|
|
719
|
-
&svec(&["provider-bin", "--flag"]),
|
|
720
|
-
Path::new("/work/dir"),
|
|
721
|
-
&env,
|
|
722
|
-
)
|
|
723
|
-
.expect("spawn_first");
|
|
724
|
-
let calls = rec.lock().unwrap().clone();
|
|
725
|
-
let argv = calls[0].clone();
|
|
726
|
-
let cmd = argv.last().expect("the sh -lc command string").clone();
|
|
727
|
-
assert_eq!(
|
|
728
|
-
argv,
|
|
729
|
-
tmux_spawn_argv(&s, &w, &cmd, true),
|
|
730
|
-
"spawn_first must frame via tmux_spawn_argv (new-session -d -s <s> -n <w> sh -lc <cmd>)"
|
|
731
|
-
);
|
|
732
|
-
assert!(
|
|
733
|
-
cmd.contains("provider-bin"),
|
|
734
|
-
"the provider argv must be in the sh -lc command; got {cmd}"
|
|
735
|
-
);
|
|
736
|
-
assert_eq!(
|
|
737
|
-
result.pane_id.as_str(),
|
|
738
|
-
"%3",
|
|
739
|
-
"SpawnResult.pane_id must parse from the tmux output"
|
|
740
|
-
);
|
|
741
|
-
assert_eq!(result.child_pid, Some(123));
|
|
742
|
-
assert!(
|
|
743
|
-
calls
|
|
744
|
-
.iter()
|
|
745
|
-
.all(|call| call.get(1).is_none_or(|arg| arg != "display-message")),
|
|
746
|
-
"spawn_first identity must come from new-session stdout, never a display-message lookup; calls={calls:?}"
|
|
747
|
-
);
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
#[test]
|
|
751
|
-
fn spawn_into_frames_via_new_window_builder() {
|
|
752
|
-
let pane_inventory = "%4\tteamsess\t1\tw2\t0\t/dev/ttys004\tnode\t1\t/work/dir\t1\t0\t124\n";
|
|
753
|
-
let (be, rec) = backend_with(
|
|
754
|
-
MockResp::Out(ok("")),
|
|
755
|
-
vec![MockResp::Out(ok("%4\n")), MockResp::Out(ok(pane_inventory))],
|
|
756
|
-
);
|
|
757
|
-
let s = SessionName::new("teamsess");
|
|
758
|
-
let w = WindowName::new("w2");
|
|
759
|
-
let result = be
|
|
760
|
-
.spawn_into(
|
|
761
|
-
&s,
|
|
762
|
-
&w,
|
|
763
|
-
&svec(&["provider-bin"]),
|
|
764
|
-
Path::new("/work/dir"),
|
|
765
|
-
&BTreeMap::new(),
|
|
766
|
-
)
|
|
767
|
-
.expect("spawn_into");
|
|
768
|
-
let calls = rec.lock().unwrap().clone();
|
|
769
|
-
let argv = calls[0].clone();
|
|
770
|
-
let cmd = argv.last().expect("the sh -lc command string").clone();
|
|
771
|
-
assert_eq!(
|
|
772
|
-
argv,
|
|
773
|
-
tmux_spawn_argv(&s, &w, &cmd, false),
|
|
774
|
-
"spawn_into must frame via tmux_spawn_argv first=false (new-window -t <s> -n <w> sh -lc <cmd>)"
|
|
775
|
-
);
|
|
776
|
-
assert_eq!(result.pane_id.as_str(), "%4");
|
|
777
|
-
assert!(
|
|
778
|
-
calls
|
|
779
|
-
.iter()
|
|
780
|
-
.all(|call| call.get(1).is_none_or(|arg| arg != "display-message")),
|
|
781
|
-
"spawn_into identity must come from new-window stdout, never a display-message lookup; calls={calls:?}"
|
|
782
|
-
);
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
#[test]
|
|
786
|
-
fn spawn_into_same_named_replacement_returns_identity_created_by_spawn_command() {
|
|
787
|
-
let recorded = Arc::new(Mutex::new(Vec::new()));
|
|
788
|
-
let be = TmuxBackend::with_runner(Box::new(SameNameSpawnRunner {
|
|
789
|
-
recorded: Arc::clone(&recorded),
|
|
790
|
-
}));
|
|
791
|
-
|
|
792
|
-
let result = be
|
|
793
|
-
.spawn_into(
|
|
794
|
-
&SessionName::new("teamsess"),
|
|
795
|
-
&WindowName::new("developer"),
|
|
796
|
-
&svec(&["provider-bin"]),
|
|
797
|
-
Path::new("/work/dir"),
|
|
798
|
-
&BTreeMap::new(),
|
|
799
|
-
)
|
|
800
|
-
.expect("same-name replacement spawn");
|
|
801
|
-
let calls = recorded.lock().unwrap().clone();
|
|
802
|
-
let name_based_identity_lookup = calls.iter().any(|call| {
|
|
803
|
-
call.get(1).is_some_and(|arg| arg == "display-message")
|
|
804
|
-
&& call
|
|
805
|
-
.iter()
|
|
806
|
-
.position(|arg| arg == "-t")
|
|
807
|
-
.and_then(|index| call.get(index + 1))
|
|
808
|
-
.is_some_and(|target| target == "teamsess:developer")
|
|
809
|
-
});
|
|
810
|
-
|
|
811
|
-
assert_eq!(
|
|
812
|
-
result.pane_id.as_str(),
|
|
813
|
-
"%new",
|
|
814
|
-
"spawn_into must return the pane identity atomically emitted by this new-window command, not the same-named old window; calls={calls:?}"
|
|
815
|
-
);
|
|
816
|
-
assert!(
|
|
817
|
-
!name_based_identity_lookup,
|
|
818
|
-
"spawn identity must not be re-derived through ambiguous session:window display-message; calls={calls:?}"
|
|
819
|
-
);
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
#[test]
|
|
823
|
-
fn spawn_with_command_refuses_and_rolls_back_spawn_pane_owned_by_other_window() {
|
|
824
|
-
let pane_inventory = "%5\tteamsess\t1\tw2\t0\t/dev/ttys005\tnode\t1\t/work/dir\t1\t0\t125\n";
|
|
825
|
-
let (be, rec) = backend_with(
|
|
826
|
-
MockResp::Out(ok("")),
|
|
827
|
-
vec![MockResp::Out(ok("%5\n")), MockResp::Out(ok(pane_inventory))],
|
|
828
|
-
);
|
|
829
|
-
let err = be
|
|
830
|
-
.spawn_into(
|
|
831
|
-
&SessionName::new("teamsess"),
|
|
832
|
-
&WindowName::new("w1"),
|
|
833
|
-
&svec(&["provider-bin"]),
|
|
834
|
-
Path::new("/work/dir"),
|
|
835
|
-
&BTreeMap::new(),
|
|
836
|
-
)
|
|
837
|
-
.expect_err("spawn stdout pane owned by w2 must fail closed");
|
|
838
|
-
let msg = err.to_string();
|
|
839
|
-
assert!(
|
|
840
|
-
msg.contains("requested=teamsess:w1")
|
|
841
|
-
&& msg.contains("observed_pane=%5")
|
|
842
|
-
&& msg.contains("observed=teamsess:w2"),
|
|
843
|
-
"error must include requested/observed ownership evidence, got {msg}"
|
|
844
|
-
);
|
|
845
|
-
let calls = rec.lock().unwrap().clone();
|
|
846
|
-
assert!(
|
|
847
|
-
calls
|
|
848
|
-
.iter()
|
|
849
|
-
.any(|call| call == &svec(&["tmux", "kill-pane", "-t", "%5"])),
|
|
850
|
-
"identity mismatch must roll back the exact pane created by this spawn; calls={calls:?}"
|
|
851
|
-
);
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
#[test]
|
|
855
|
-
fn spawn_with_command_retries_until_spawn_pane_is_visible() {
|
|
856
|
-
let pane_inventory = "%6\tteamsess\t1\tw1\t0\t/dev/ttys006\tnode\t1\t/work/dir\t1\t0\t126\n";
|
|
857
|
-
let (be, rec) = backend_with(
|
|
858
|
-
MockResp::Out(ok(pane_inventory)),
|
|
859
|
-
vec![MockResp::Out(ok("%6\n")), MockResp::Out(ok(""))],
|
|
860
|
-
);
|
|
861
|
-
let result = be
|
|
862
|
-
.spawn_into(
|
|
863
|
-
&SessionName::new("teamsess"),
|
|
864
|
-
&WindowName::new("w1"),
|
|
865
|
-
&svec(&["provider-bin"]),
|
|
866
|
-
Path::new("/work/dir"),
|
|
867
|
-
&BTreeMap::new(),
|
|
868
|
-
)
|
|
869
|
-
.expect("spawn pane must tolerate bounded tmux inventory lag");
|
|
870
|
-
let calls = rec.lock().unwrap().clone();
|
|
871
|
-
|
|
872
|
-
assert_eq!(result.pane_id.as_str(), "%6");
|
|
873
|
-
assert_eq!(
|
|
874
|
-
calls
|
|
875
|
-
.iter()
|
|
876
|
-
.filter(|call| call.get(1).is_some_and(|arg| arg == "list-panes"))
|
|
877
|
-
.count(),
|
|
878
|
-
2,
|
|
879
|
-
"spawn identity must retry the same pane id until it becomes visible; calls={calls:?}"
|
|
880
|
-
);
|
|
881
|
-
assert!(
|
|
882
|
-
calls
|
|
883
|
-
.iter()
|
|
884
|
-
.all(|call| call.get(1).is_none_or(|arg| arg != "kill-pane")),
|
|
885
|
-
"a delayed but valid identity must not be rolled back; calls={calls:?}"
|
|
886
|
-
);
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
#[test]
|
|
890
|
-
fn spawn_with_command_empty_stdout_fails_closed_without_identity_fallback() {
|
|
891
|
-
let (be, rec) = backend_with(MockResp::Out(ok("")), vec![MockResp::Out(ok(""))]);
|
|
892
|
-
let err = be
|
|
893
|
-
.spawn_into(
|
|
894
|
-
&SessionName::new("teamsess"),
|
|
895
|
-
&WindowName::new("developer"),
|
|
896
|
-
&svec(&["provider-bin"]),
|
|
897
|
-
Path::new("/work/dir"),
|
|
898
|
-
&BTreeMap::new(),
|
|
899
|
-
)
|
|
900
|
-
.expect_err("empty new-window stdout must fail closed");
|
|
901
|
-
let msg = err.to_string().to_ascii_lowercase();
|
|
902
|
-
let calls = rec.lock().unwrap().clone();
|
|
903
|
-
let used_identity_fallback = calls
|
|
904
|
-
.iter()
|
|
905
|
-
.any(|call| call.get(1).is_some_and(|arg| arg == "display-message"));
|
|
906
|
-
|
|
907
|
-
assert!(
|
|
908
|
-
msg.contains("spawn") && (msg.contains("empty") || msg.contains("no pane id")),
|
|
909
|
-
"empty spawn stdout error must name the missing spawn identity; error={err}; calls={calls:?}"
|
|
910
|
-
);
|
|
911
|
-
assert!(
|
|
912
|
-
!used_identity_fallback,
|
|
913
|
-
"empty spawn stdout must not fall back to ambiguous display-message identity lookup; calls={calls:?}"
|
|
914
|
-
);
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
#[test]
|
|
918
|
-
fn spawn_split_selects_even_horizontal_not_tiled() {
|
|
919
|
-
let (be, rec) = backend_with(
|
|
920
|
-
MockResp::Out(ok("")),
|
|
921
|
-
vec![MockResp::Out(ok("%5")), MockResp::Out(ok(""))],
|
|
922
|
-
);
|
|
923
|
-
let s = SessionName::new("teamsess");
|
|
924
|
-
let w = WindowName::new("team-w1");
|
|
925
|
-
let result = be
|
|
926
|
-
.spawn_split_with_env_unset(
|
|
927
|
-
&s,
|
|
928
|
-
&w,
|
|
929
|
-
&svec(&["provider-bin"]),
|
|
930
|
-
Path::new("/work/dir"),
|
|
931
|
-
&BTreeMap::new(),
|
|
932
|
-
&[],
|
|
933
|
-
)
|
|
934
|
-
.expect("spawn_split");
|
|
935
|
-
assert_eq!(result.pane_id.as_str(), "%5");
|
|
936
|
-
let calls = rec.lock().unwrap().clone();
|
|
937
|
-
// E53 (0.3.26): split-window now carries `-d` (no focus steal).
|
|
938
|
-
assert_eq!(
|
|
939
|
-
calls[0][0..5],
|
|
940
|
-
svec(&["tmux", "split-window", "-d", "-t", "teamsess:team-w1"])
|
|
941
|
-
);
|
|
942
|
-
assert_eq!(
|
|
943
|
-
calls[1],
|
|
944
|
-
svec(&[
|
|
945
|
-
"tmux",
|
|
946
|
-
"select-layout",
|
|
947
|
-
"-t",
|
|
948
|
-
"teamsess:team-w1",
|
|
949
|
-
"even-horizontal",
|
|
950
|
-
])
|
|
951
|
-
);
|
|
952
|
-
assert!(
|
|
953
|
-
!calls.iter().flatten().any(|arg| arg == "tiled"),
|
|
954
|
-
"adaptive split must not leave tmux tiled layout in the command stream: {calls:?}"
|
|
955
|
-
);
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
#[test]
|
|
959
|
-
fn configure_adaptive_pane_title_sets_border_and_pane_title() {
|
|
960
|
-
let (be, rec) = backend_with(MockResp::Out(ok("")), vec![]);
|
|
961
|
-
be.configure_adaptive_pane_title(
|
|
962
|
-
&SessionName::new("teamsess"),
|
|
963
|
-
&WindowName::new("team-w1"),
|
|
964
|
-
&PaneId::new("%7"),
|
|
965
|
-
"builder",
|
|
966
|
-
)
|
|
967
|
-
.expect("configure title");
|
|
968
|
-
let calls = rec.lock().unwrap().clone();
|
|
969
|
-
assert_eq!(
|
|
970
|
-
calls,
|
|
971
|
-
vec![
|
|
972
|
-
svec(&[
|
|
973
|
-
"tmux",
|
|
974
|
-
"set-window-option",
|
|
975
|
-
"-t",
|
|
976
|
-
"teamsess:team-w1",
|
|
977
|
-
"pane-border-status",
|
|
978
|
-
"bottom",
|
|
979
|
-
]),
|
|
980
|
-
svec(&[
|
|
981
|
-
"tmux",
|
|
982
|
-
"set-window-option",
|
|
983
|
-
"-t",
|
|
984
|
-
"teamsess:team-w1",
|
|
985
|
-
"pane-border-format",
|
|
986
|
-
" #{pane_title} ",
|
|
987
|
-
]),
|
|
988
|
-
svec(&["tmux", "select-pane", "-t", "%7", "-T", "builder"]),
|
|
989
|
-
]
|
|
990
|
-
);
|
|
991
|
-
}
|
|
992
|
-
|
|
993
|
-
// โโ 3. set_session_env: argv = `tmux set-environment -t <s> <k> <v>`; success -> Applied โโโโโโโ
|
|
994
|
-
#[test]
|
|
995
|
-
fn set_session_env_argv_and_applied_outcome() {
|
|
996
|
-
let (be, rec) = backend_with(MockResp::Out(ok("")), vec![]);
|
|
997
|
-
let outcome = be
|
|
998
|
-
.set_session_env(&SessionName::new("sess"), "KEY", "VAL")
|
|
999
|
-
.expect("set env");
|
|
1000
|
-
assert_eq!(
|
|
1001
|
-
rec.lock().unwrap()[0],
|
|
1002
|
-
svec(&["tmux", "set-environment", "-t", "sess", "KEY", "VAL"])
|
|
1003
|
-
);
|
|
1004
|
-
assert_eq!(
|
|
1005
|
-
outcome,
|
|
1006
|
-
SetEnvOutcome::Applied,
|
|
1007
|
-
"tmux set-environment success -> SetEnvOutcome::Applied"
|
|
1008
|
-
);
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
// โโ 4. capture: argv = tmux_capture_argv; canned scrollback -> normalize_capture -> CapturedText โ
|
|
1012
|
-
#[test]
|
|
1013
|
-
fn capture_argv_and_normalizes_scrollback() {
|
|
1014
|
-
let scroll = "line one \nbusy\u{a0}marker \n \n";
|
|
1015
|
-
let (be, rec) = backend_with(MockResp::Out(ok(scroll)), vec![]);
|
|
1016
|
-
let pane = PaneId::new("%7");
|
|
1017
|
-
let captured = be
|
|
1018
|
-
.capture(&Target::Pane(pane.clone()), CaptureRange::Tail(40))
|
|
1019
|
-
.expect("capture");
|
|
1020
|
-
assert_eq!(
|
|
1021
|
-
rec.lock().unwrap()[0],
|
|
1022
|
-
tmux_capture_argv(&pane, CaptureRange::Tail(40))
|
|
1023
|
-
);
|
|
1024
|
-
assert_eq!(
|
|
1025
|
-
captured.text,
|
|
1026
|
-
normalize_capture(scroll),
|
|
1027
|
-
"capture output must be normalize_capture'd"
|
|
1028
|
-
);
|
|
1029
|
-
assert_eq!(captured.range, CaptureRange::Tail(40));
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
|
-
// โโ 5a. send_keys: argv = tmux_send_keys_argv โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
1033
|
-
#[test]
|
|
1034
|
-
fn send_keys_argv_matches_builder() {
|
|
1035
|
-
let (be, rec) = backend_with(MockResp::Out(ok("0\n")), vec![]);
|
|
1036
|
-
let pane = PaneId::new("%7");
|
|
1037
|
-
be.send_keys(&Target::Pane(pane.clone()), &[Key::Enter])
|
|
1038
|
-
.expect("send_keys");
|
|
1039
|
-
let calls = rec.lock().unwrap().clone();
|
|
1040
|
-
let submit = calls.iter().find(|argv| {
|
|
1041
|
-
argv.get(1).map(String::as_str) == Some("send-keys")
|
|
1042
|
-
&& argv.iter().any(|a| a == "Enter")
|
|
1043
|
-
&& !argv.iter().any(|a| a == "-l")
|
|
1044
|
-
});
|
|
1045
|
-
assert_eq!(
|
|
1046
|
-
submit.cloned().as_ref(),
|
|
1047
|
-
Some(&tmux_send_keys_argv(&pane, &[Key::Enter])),
|
|
1048
|
-
"Enter ้ฎ็ปไป่ตฐ tmux_send_keys_argv๏ผprepare ๅชๅ
่ฎธๅ็ผ mode-query/201~; calls={calls:?}"
|
|
1049
|
-
);
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
|
-
// โโ 5b. inject (text): set/load-buffer(text) -> paste-buffer -p -> submit send-keys; report Submit โ
|
|
1053
|
-
#[test]
|
|
1054
|
-
fn inject_text_runs_buffer_paste_submit_sequence_and_reports_submit() {
|
|
1055
|
-
let (be, rec) = backend_with(MockResp::Out(ok("hello")), vec![]);
|
|
1056
|
-
let pane = PaneId::new("%7");
|
|
1057
|
-
let report = be
|
|
1058
|
-
.inject(
|
|
1059
|
-
&Target::Pane(pane.clone()),
|
|
1060
|
-
&InjectPayload::Text("hello".to_string()),
|
|
1061
|
-
Key::Enter,
|
|
1062
|
-
true,
|
|
1063
|
-
)
|
|
1064
|
-
.expect("inject");
|
|
1065
|
-
let calls = rec.lock().unwrap().clone();
|
|
1066
|
-
let is = |a: &[String], sub: &str| a.get(1).map(String::as_str) == Some(sub);
|
|
1067
|
-
assert!(
|
|
1068
|
-
calls
|
|
1069
|
-
.iter()
|
|
1070
|
-
.any(|a| (is(a, "set-buffer") || is(a, "load-buffer"))
|
|
1071
|
-
&& a.iter().any(|x| x.contains("hello"))),
|
|
1072
|
-
"inject must stage the text into a tmux buffer (set-buffer/load-buffer); got {calls:?}"
|
|
1073
|
-
);
|
|
1074
|
-
assert!(
|
|
1075
|
-
calls.iter().any(|a| is(a, "paste-buffer")
|
|
1076
|
-
&& a.contains(&"-p".to_string())
|
|
1077
|
-
&& a.contains(&"%7".to_string())),
|
|
1078
|
-
"inject must bracketed-paste (-p) the buffer to the pane; got {calls:?}"
|
|
1079
|
-
);
|
|
1080
|
-
assert!(
|
|
1081
|
-
calls.iter().any(
|
|
1082
|
-
|a| is(a, "send-keys") && a.contains(&tmux_submit_key_name(Key::Enter).to_string())
|
|
1083
|
-
),
|
|
1084
|
-
"inject must send the submit key (Enter) last; got {calls:?}"
|
|
1085
|
-
);
|
|
1086
|
-
assert_eq!(
|
|
1087
|
-
report.stage_reached,
|
|
1088
|
-
InjectStage::Submit,
|
|
1089
|
-
"a fully-applied inject reaches the Submit stage"
|
|
1090
|
-
);
|
|
1091
|
-
assert_eq!(report.inject_verification, InjectVerification::NoToken);
|
|
1092
|
-
assert_eq!(
|
|
1093
|
-
report.submit_verification,
|
|
1094
|
-
SubmitVerification::EnterSentWithoutPlaceholderCheck
|
|
1095
|
-
);
|
|
1096
|
-
assert_eq!(report.turn_verification, TurnVerification::NotYetObserved);
|
|
1097
|
-
let diagnostics = report.submit_diagnostics.expect("diagnostics");
|
|
1098
|
-
assert_eq!(
|
|
1099
|
-
diagnostics.consumption_reason,
|
|
1100
|
-
SubmitConsumptionReason::NoMarker
|
|
1101
|
-
);
|
|
1102
|
-
assert_eq!(diagnostics.busy_signal_kind, None);
|
|
1103
|
-
assert_eq!(diagnostics.current_marker_in_bottom_15, None);
|
|
1104
|
-
assert_eq!(diagnostics.paste_identity_in_composer, None);
|
|
1105
|
-
assert_eq!(diagnostics.consumption_from_capture_result, None);
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
#[test]
|
|
1109
|
-
fn inject_large_text_load_buffer_writes_stdin_and_token_report() {
|
|
1110
|
-
let text = format!("{}{}", "x".repeat(16 * 1024), " [team-agent-token:abc]");
|
|
1111
|
-
// U1 #7: the pre-submit readback captures the pane; a pane that ECHOES the token
|
|
1112
|
-
// back (default capture returns the text) โ CaptureContainsToken (true positive).
|
|
1113
|
-
let (be, rec, stdin_rec) = backend_with_stdin(MockResp::Out(ok(&text)), vec![]);
|
|
1114
|
-
let report = be
|
|
1115
|
-
.inject(
|
|
1116
|
-
&Target::Pane(PaneId::new("%7")),
|
|
1117
|
-
&InjectPayload::Text(text.clone()),
|
|
1118
|
-
Key::Down,
|
|
1119
|
-
true,
|
|
1120
|
-
)
|
|
1121
|
-
.expect("inject large text");
|
|
1122
|
-
|
|
1123
|
-
assert_eq!(
|
|
1124
|
-
report.inject_verification,
|
|
1125
|
-
InjectVerification::CaptureContainsToken
|
|
1126
|
-
);
|
|
1127
|
-
assert_eq!(
|
|
1128
|
-
report.submit_verification,
|
|
1129
|
-
SubmitVerification::KeySentAfterVisibleToken { key: Key::Down }
|
|
1130
|
-
);
|
|
1131
|
-
let calls = rec.lock().unwrap().clone();
|
|
1132
|
-
assert_eq!(
|
|
1133
|
-
calls[0],
|
|
1134
|
-
svec(&["tmux", "load-buffer", "-b", "team-agent-send-abc", "-"])
|
|
1135
|
-
);
|
|
1136
|
-
assert_eq!(stdin_rec.lock().unwrap()[0], text);
|
|
1137
|
-
}
|
|
1138
|
-
|
|
1139
|
-
// U1 #7 (REDโGREEN) โ pre-submit pane readback: a token payload whose token is NOT
|
|
1140
|
-
// visible in the pane before submit (paste silently dropped) must report
|
|
1141
|
-
// CaptureMissingToken, not the static false-positive CaptureContainsToken.
|
|
1142
|
-
#[test]
|
|
1143
|
-
fn inject_token_not_visible_in_pane_reports_capture_missing_token() {
|
|
1144
|
-
let text = format!("{}{}", "x".repeat(16 * 1024), " [team-agent-token:zzz]");
|
|
1145
|
-
// default capture returns empty โ token not visible โ readback says missing.
|
|
1146
|
-
let (be, _rec, _stdin) = backend_with_stdin(MockResp::Out(ok("")), vec![]);
|
|
1147
|
-
let report = be
|
|
1148
|
-
.inject(
|
|
1149
|
-
&Target::Pane(PaneId::new("%9")),
|
|
1150
|
-
&InjectPayload::Text(text),
|
|
1151
|
-
Key::Down,
|
|
1152
|
-
true,
|
|
1153
|
-
)
|
|
1154
|
-
.expect("inject runs");
|
|
1155
|
-
assert_eq!(
|
|
1156
|
-
report.inject_verification,
|
|
1157
|
-
InjectVerification::CaptureMissingToken,
|
|
1158
|
-
"U1 #7: a token that never appeared in the pane must read back as \
|
|
1159
|
-
CaptureMissingToken, not the static CaptureContainsToken false-positive"
|
|
1160
|
-
);
|
|
1161
|
-
let diag = report
|
|
1162
|
-
.submit_diagnostics
|
|
1163
|
-
.as_ref()
|
|
1164
|
-
.expect("token inject records readback diagnostics");
|
|
1165
|
-
assert_eq!(diag.last_capture_outcome, CaptureSampleOutcome::OkTokenMissing);
|
|
1166
|
-
assert_eq!(diag.token_seen_after_paste, Some(false));
|
|
1167
|
-
assert!(diag.capture_ok_count >= 1);
|
|
1168
|
-
assert_eq!(diag.capture_err_count, 0);
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1171
|
-
#[test]
|
|
1172
|
-
fn command_basename_drops_argv_and_path() {
|
|
1173
|
-
assert_eq!(
|
|
1174
|
-
command_basename("/usr/bin/grok --help --model x").as_deref(),
|
|
1175
|
-
Some("grok")
|
|
1176
|
-
);
|
|
1177
|
-
assert_eq!(command_basename("node").as_deref(), Some("node"));
|
|
1178
|
-
assert_eq!(command_basename("").as_deref(), None);
|
|
1179
|
-
assert_eq!(command_basename(" ").as_deref(), None);
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
struct InjectProbeRunner {
|
|
1183
|
-
recorded: RecordedArgv,
|
|
1184
|
-
capture: MockResp,
|
|
1185
|
-
command: String,
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
impl CommandRunner for InjectProbeRunner {
|
|
1189
|
-
fn run(&self, argv: &[String]) -> Result<CommandOutput, std::io::Error> {
|
|
1190
|
-
self.recorded.lock().unwrap().push(argv.to_vec());
|
|
1191
|
-
if argv.iter().any(|arg| arg.contains("#{pane_current_command}")) {
|
|
1192
|
-
return Ok(ok(&format!("{}\n", self.command)));
|
|
1193
|
-
}
|
|
1194
|
-
if argv.iter().any(|arg| arg.contains("#{pane_id}")) {
|
|
1195
|
-
return Ok(ok("%9\n"));
|
|
1196
|
-
}
|
|
1197
|
-
if argv.get(1).map(String::as_str) == Some("capture-pane") {
|
|
1198
|
-
return match &self.capture {
|
|
1199
|
-
MockResp::Out(output) => Ok(output.clone()),
|
|
1200
|
-
MockResp::Io(kind) => Err(std::io::Error::new(*kind, "capture unavailable")),
|
|
1201
|
-
};
|
|
1202
|
-
}
|
|
1203
|
-
Ok(ok(""))
|
|
1204
|
-
}
|
|
1205
|
-
|
|
1206
|
-
fn run_with_stdin(
|
|
1207
|
-
&self,
|
|
1208
|
-
argv: &[String],
|
|
1209
|
-
_stdin: &str,
|
|
1210
|
-
) -> Result<CommandOutput, std::io::Error> {
|
|
1211
|
-
self.run(argv)
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
|
|
1215
|
-
fn inject_probe_backend(
|
|
1216
|
-
capture: MockResp,
|
|
1217
|
-
command: &str,
|
|
1218
|
-
) -> (TmuxBackend, RecordedArgv) {
|
|
1219
|
-
let recorded = Arc::new(Mutex::new(Vec::new()));
|
|
1220
|
-
let runner = InjectProbeRunner {
|
|
1221
|
-
recorded: Arc::clone(&recorded),
|
|
1222
|
-
capture,
|
|
1223
|
-
command: command.to_string(),
|
|
1224
|
-
};
|
|
1225
|
-
(TmuxBackend::with_runner(Box::new(runner)), recorded)
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
#[test]
|
|
1229
|
-
fn inject_capture_failure_is_distinct_from_token_missing_and_does_not_pass() {
|
|
1230
|
-
let (be, _rec) = inject_probe_backend(MockResp::Io(std::io::ErrorKind::Other), "");
|
|
1231
|
-
let report = be
|
|
1232
|
-
.inject(
|
|
1233
|
-
&Target::Pane(PaneId::new("%9")),
|
|
1234
|
-
&InjectPayload::Text("hello [team-agent-token:zzz]".to_string()),
|
|
1235
|
-
Key::Down,
|
|
1236
|
-
true,
|
|
1237
|
-
)
|
|
1238
|
-
.expect("inject runs");
|
|
1239
|
-
assert_eq!(
|
|
1240
|
-
report.inject_verification,
|
|
1241
|
-
InjectVerification::CaptureMissingToken,
|
|
1242
|
-
"capture failure must not loosen CaptureMissingToken"
|
|
1243
|
-
);
|
|
1244
|
-
let diag = report.submit_diagnostics.as_ref().expect("diag");
|
|
1245
|
-
assert_eq!(diag.last_capture_outcome, CaptureSampleOutcome::Failed);
|
|
1246
|
-
assert_eq!(diag.token_seen_after_paste, None);
|
|
1247
|
-
assert!(diag.capture_err_count >= 1);
|
|
1248
|
-
assert_eq!(diag.capture_ok_count, 0);
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
#[test]
|
|
1252
|
-
fn inject_records_command_basename_without_argv() {
|
|
1253
|
-
let (be, _rec) = inject_probe_backend(
|
|
1254
|
-
MockResp::Out(ok("")),
|
|
1255
|
-
"/usr/bin/grok --help --model grok-4.6",
|
|
1256
|
-
);
|
|
1257
|
-
let report = be
|
|
1258
|
-
.inject(
|
|
1259
|
-
&Target::Pane(PaneId::new("%9")),
|
|
1260
|
-
&InjectPayload::Text("hello [team-agent-token:zzz]".to_string()),
|
|
1261
|
-
Key::Down,
|
|
1262
|
-
true,
|
|
1263
|
-
)
|
|
1264
|
-
.expect("inject runs");
|
|
1265
|
-
let diag = report.submit_diagnostics.as_ref().expect("diag");
|
|
1266
|
-
assert_eq!(diag.pane_command_basename.as_deref(), Some("grok"));
|
|
1267
|
-
assert_eq!(diag.pane_command_query, QueryOutcome::Observed);
|
|
1268
|
-
assert_eq!(diag.input_surface, InputSurfaceProbe::Input);
|
|
1269
|
-
assert_eq!(diag.target_pane_id.as_deref(), Some("%9"));
|
|
1270
|
-
assert_eq!(diag.target_pane_query_matched, Some(true));
|
|
1271
|
-
let blob = format!("{diag:?}");
|
|
1272
|
-
assert!(
|
|
1273
|
-
!blob.contains("--help") && !blob.contains("grok-4.6"),
|
|
1274
|
-
"argv must not leak into diagnostics: {blob}"
|
|
1275
|
-
);
|
|
1276
|
-
assert_eq!(
|
|
1277
|
-
report.inject_verification,
|
|
1278
|
-
InjectVerification::CaptureMissingToken
|
|
1279
|
-
);
|
|
1280
|
-
}
|
|
1281
|
-
|
|
1282
|
-
#[test]
|
|
1283
|
-
fn inject_waits_for_token_visibility_before_enter() {
|
|
1284
|
-
let text = "hello [team-agent-token:e31]".to_string();
|
|
1285
|
-
let marker_visible = format!("{text}\n");
|
|
1286
|
-
let (be, rec) = backend_with(
|
|
1287
|
-
MockResp::Out(ok("")),
|
|
1288
|
-
vec![
|
|
1289
|
-
MockResp::Out(ok("")), // set-buffer
|
|
1290
|
-
MockResp::Out(ok("")), // paste-buffer
|
|
1291
|
-
MockResp::Out(ok("")), // delete-buffer
|
|
1292
|
-
MockResp::Out(ok("")), // pasted-content prompt poll 1
|
|
1293
|
-
MockResp::Out(ok("")), // pasted-content prompt poll 2
|
|
1294
|
-
MockResp::Out(ok("")), // pasted-content prompt poll 3
|
|
1295
|
-
MockResp::Out(ok("")), // pasted-content prompt poll 4
|
|
1296
|
-
MockResp::Out(ok("")), // pasted-content prompt poll 5
|
|
1297
|
-
MockResp::Out(ok("")), // token gate: not visible yet
|
|
1298
|
-
MockResp::Out(ok("")), // token gate: still not visible
|
|
1299
|
-
MockResp::Out(ok(&marker_visible)), // token gate: visible, Enter may fire
|
|
1300
|
-
MockResp::Out(ok("")), // send-keys Enter
|
|
1301
|
-
],
|
|
1302
|
-
);
|
|
1303
|
-
|
|
1304
|
-
let report = be
|
|
1305
|
-
.inject(
|
|
1306
|
-
&Target::Pane(PaneId::new("%7")),
|
|
1307
|
-
&InjectPayload::Text(text),
|
|
1308
|
-
Key::Enter,
|
|
1309
|
-
true,
|
|
1310
|
-
)
|
|
1311
|
-
.expect("inject");
|
|
1312
|
-
let calls = rec.lock().unwrap().clone();
|
|
1313
|
-
let submit_index = calls
|
|
1314
|
-
.iter()
|
|
1315
|
-
.position(|argv| argv.get(1).map(String::as_str) == Some("send-keys"))
|
|
1316
|
-
.expect("inject must eventually send Enter");
|
|
1317
|
-
let captures_before_submit = calls[..submit_index]
|
|
1318
|
-
.iter()
|
|
1319
|
-
.filter(|argv| argv.get(1).map(String::as_str) == Some("capture-pane"))
|
|
1320
|
-
.count();
|
|
1321
|
-
|
|
1322
|
-
assert!(
|
|
1323
|
-
captures_before_submit >= super::PASTED_CONTENT_APPEAR_POLLS as usize + 3,
|
|
1324
|
-
"Enter must wait until the pasted token is visible; calls={calls:?}"
|
|
1325
|
-
);
|
|
1326
|
-
assert_eq!(
|
|
1327
|
-
report.inject_verification,
|
|
1328
|
-
InjectVerification::CaptureContainsToken
|
|
1329
|
-
);
|
|
1330
|
-
assert_eq!(
|
|
1331
|
-
report.submit_verification,
|
|
1332
|
-
SubmitVerification::EnterSentWithoutPlaceholderCheck
|
|
1333
|
-
);
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
#[test]
|
|
1337
|
-
fn paste_to_submit_floor_default_is_zero_even_if_test_tmp_is_set() {
|
|
1338
|
-
assert_eq!(
|
|
1339
|
-
current_paste_to_submit_floor(),
|
|
1340
|
-
Duration::ZERO,
|
|
1341
|
-
"default floor must be ZERO; TEAM_AGENT_TEST_TMP is not this switch"
|
|
1342
|
-
);
|
|
1343
|
-
}
|
|
1344
|
-
|
|
1345
|
-
#[test]
|
|
1346
|
-
fn paste_to_submit_nonzero_floor_is_actually_slept() {
|
|
1347
|
-
let start = Instant::now();
|
|
1348
|
-
sleep_remaining_paste_to_submit_floor(start, Duration::from_millis(40));
|
|
1349
|
-
let elapsed = start.elapsed();
|
|
1350
|
-
assert!(
|
|
1351
|
-
elapsed >= Duration::from_millis(40),
|
|
1352
|
-
"non-zero floor must sleep the remaining time; elapsed={elapsed:?}"
|
|
1353
|
-
);
|
|
1354
|
-
}
|
|
1355
|
-
|
|
1356
|
-
#[test]
|
|
1357
|
-
fn paste_to_submit_zero_floor_does_not_sleep() {
|
|
1358
|
-
let start = Instant::now();
|
|
1359
|
-
sleep_remaining_paste_to_submit_floor(start, Duration::ZERO);
|
|
1360
|
-
let elapsed = start.elapsed();
|
|
1361
|
-
assert!(
|
|
1362
|
-
elapsed < Duration::from_millis(20),
|
|
1363
|
-
"ZERO floor must be free for claude/codex/grok; elapsed={elapsed:?}"
|
|
1364
|
-
);
|
|
1365
|
-
}
|
|
1366
|
-
|
|
1367
|
-
#[test]
|
|
1368
|
-
fn inject_honors_injected_nonzero_paste_to_submit_floor() {
|
|
1369
|
-
let (be, _) = backend_with(MockResp::Out(ok("hello")), vec![]);
|
|
1370
|
-
let start = Instant::now();
|
|
1371
|
-
with_paste_to_submit_floor(Duration::from_millis(40), || {
|
|
1372
|
-
be.inject(
|
|
1373
|
-
&Target::Pane(PaneId::new("%7")),
|
|
1374
|
-
&InjectPayload::Text("hello".to_string()),
|
|
1375
|
-
Key::Enter,
|
|
1376
|
-
true,
|
|
1377
|
-
)
|
|
1378
|
-
.expect("inject");
|
|
1379
|
-
});
|
|
1380
|
-
let elapsed = start.elapsed();
|
|
1381
|
-
assert!(
|
|
1382
|
-
elapsed >= Duration::from_millis(40),
|
|
1383
|
-
"inject must take the injected cursor floor; elapsed={elapsed:?}"
|
|
1384
|
-
);
|
|
1385
|
-
}
|
|
1386
|
-
|
|
1387
|
-
#[test]
|
|
1388
|
-
fn inject_skip_consumption_payload_sends_enter_without_phase2_poll() {
|
|
1389
|
-
let text = "hello leader [team-agent-token:skip]";
|
|
1390
|
-
let (be, rec) = backend_with(MockResp::Out(ok(text)), vec![]);
|
|
1391
|
-
let report = be
|
|
1392
|
-
.inject(
|
|
1393
|
-
&Target::Pane(PaneId::new("%7")),
|
|
1394
|
-
&InjectPayload::TextSkipConsumptionPoll(text.to_string()),
|
|
1395
|
-
Key::Enter,
|
|
1396
|
-
true,
|
|
1397
|
-
)
|
|
1398
|
-
.expect("inject");
|
|
1399
|
-
let calls = rec.lock().unwrap().clone();
|
|
1400
|
-
|
|
1401
|
-
assert_eq!(
|
|
1402
|
-
report.submit_verification,
|
|
1403
|
-
SubmitVerification::EnterSentWithoutPlaceholderCheck
|
|
1404
|
-
);
|
|
1405
|
-
assert_eq!(report.attempts, 1);
|
|
1406
|
-
assert!(
|
|
1407
|
-
calls.iter().any(|argv| {
|
|
1408
|
-
argv.get(1).map(String::as_str) == Some("send-keys")
|
|
1409
|
-
&& argv.contains(&tmux_submit_key_name(Key::Enter).to_string())
|
|
1410
|
-
}),
|
|
1411
|
-
"skip-consumption payload must still submit once; calls={calls:?}"
|
|
1412
|
-
);
|
|
1413
|
-
assert!(
|
|
1414
|
-
!calls
|
|
1415
|
-
.iter()
|
|
1416
|
-
.any(|argv| { argv == &tmux_capture_argv(&PaneId::new("%7"), CaptureRange::Tail(40)) }),
|
|
1417
|
-
"leader-bound skip payload must not run Phase 2 consumption polls; calls={calls:?}"
|
|
1418
|
-
);
|
|
1419
|
-
}
|
|
1420
|
-
|
|
1421
|
-
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
1422
|
-
// E46 0.3.24 task#327 P0 โ submit verification false-positive / false-negative.
|
|
1423
|
-
//
|
|
1424
|
-
// Architect + Workflow C1: do NOT flip `EnterSentWithoutPlaceholderCheck =>
|
|
1425
|
-
// false` (breaks MUST-10 in provider_submit_verification_red.rs:113-159).
|
|
1426
|
-
// Instead introduce SubmitConsumptionUnverified and only emit it from the
|
|
1427
|
-
// bracketed-paste / Enter path when post-Enter input consumption is NOT
|
|
1428
|
-
// observed within a bounded resend cap.
|
|
1429
|
-
//
|
|
1430
|
-
// Real-machine truth source (macmini): a fresh claude TUI's bracketed
|
|
1431
|
-
// paste swallows the framework's Enter as paste content; the framework
|
|
1432
|
-
// must (a) send Escape first to exit the paste bracket and (b) verify
|
|
1433
|
-
// post-Enter consumption by structural input-empty probe (token marker
|
|
1434
|
-
// no longer in the bottom 5 lines of the pane = composer cleared).
|
|
1435
|
-
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
1436
|
-
|
|
1437
|
-
/// ledger.inject-fix: paste landing is not submit. Token still in the
|
|
1438
|
-
/// composer and no Working signal โ SubmitConsumptionUnverified.
|
|
1439
|
-
#[test]
|
|
1440
|
-
fn e46_post_submit_matched_token_without_scroll_is_unverified() {
|
|
1441
|
-
let token_text = "Team Agent message from leader:\n\nhi\n\n[team-agent-token:msg_red1]";
|
|
1442
|
-
let (be, _rec) = backend_with(MockResp::Out(ok(token_text)), vec![]);
|
|
1443
|
-
let report = be
|
|
1444
|
-
.inject(
|
|
1445
|
-
&Target::Pane(PaneId::new("%7")),
|
|
1446
|
-
&InjectPayload::Text(token_text.to_string()),
|
|
1447
|
-
Key::Enter,
|
|
1448
|
-
true,
|
|
1449
|
-
)
|
|
1450
|
-
.expect("inject runs");
|
|
1451
|
-
assert_eq!(
|
|
1452
|
-
report.submit_verification,
|
|
1453
|
-
SubmitVerification::SubmitConsumptionUnverified,
|
|
1454
|
-
"token still in composer and no Working signal must be unverified, \
|
|
1455
|
-
not EnterSentWithoutPlaceholderCheck. Got {:?}",
|
|
1456
|
-
report.submit_verification
|
|
1457
|
-
);
|
|
1458
|
-
assert_eq!(
|
|
1459
|
-
report.turn_verification,
|
|
1460
|
-
TurnVerification::LeaderNewTurnBoundaryMissing,
|
|
1461
|
-
"token still in composer and no busy must report ๆฒกๅผ่ท, not unknown/started"
|
|
1462
|
-
);
|
|
1463
|
-
let diagnostics = report.submit_diagnostics.expect("diagnostics");
|
|
1464
|
-
assert_eq!(diagnostics.busy_signal_kind, None);
|
|
1465
|
-
assert_eq!(diagnostics.current_marker_in_bottom_15, Some(true));
|
|
1466
|
-
assert_eq!(diagnostics.paste_identity_in_composer, None);
|
|
1467
|
-
assert_eq!(diagnostics.consumption_from_capture_result, Some(false));
|
|
1468
|
-
assert!(
|
|
1469
|
-
diagnostics.attempts_detail.iter().any(|obs| obs.matched),
|
|
1470
|
-
"the unverified verdict must still record that paste landed"
|
|
1471
|
-
);
|
|
1472
|
-
assert_eq!(
|
|
1473
|
-
diagnostics.consumption_reason,
|
|
1474
|
-
SubmitConsumptionReason::Unverified
|
|
1475
|
-
);
|
|
1476
|
-
}
|
|
1477
|
-
|
|
1478
|
-
#[test]
|
|
1479
|
-
fn e46_unconsumed_token_with_live_busy_state_is_treated_as_processing() {
|
|
1480
|
-
let token_text = "Team Agent message from leader:\n\nhi\n\n[team-agent-token:msg_busy]";
|
|
1481
|
-
let busy_tail = format!("{token_text}\nโ Working (1s ยท esc to interrupt)\n");
|
|
1482
|
-
let (be, _rec) = backend_with(MockResp::Out(ok(&busy_tail)), vec![]);
|
|
1483
|
-
let report = be
|
|
1484
|
-
.inject(
|
|
1485
|
-
&Target::Pane(PaneId::new("%7")),
|
|
1486
|
-
&InjectPayload::Text(token_text.to_string()),
|
|
1487
|
-
Key::Enter,
|
|
1488
|
-
true,
|
|
1489
|
-
)
|
|
1490
|
-
.expect("inject runs");
|
|
1491
|
-
assert_eq!(
|
|
1492
|
-
report.submit_verification,
|
|
1493
|
-
SubmitVerification::EnterSentWithoutPlaceholderCheck,
|
|
1494
|
-
"busy provider state means the turn is being processed even if \
|
|
1495
|
-
the token has not yet scrolled out of the bottom capture"
|
|
1496
|
-
);
|
|
1497
|
-
assert_eq!(
|
|
1498
|
-
report.turn_verification,
|
|
1499
|
-
TurnVerification::LeaderNewTurnBoundaryVerified,
|
|
1500
|
-
"live Working signal is ๅผ่ท; must not stay not_yet_observed"
|
|
1501
|
-
);
|
|
1502
|
-
let diagnostics = report.submit_diagnostics.expect("diagnostics");
|
|
1503
|
-
assert!(
|
|
1504
|
-
diagnostics
|
|
1505
|
-
.attempts_detail
|
|
1506
|
-
.last()
|
|
1507
|
-
.map(|obs| obs
|
|
1508
|
-
.pane_tail_excerpt
|
|
1509
|
-
.to_ascii_lowercase()
|
|
1510
|
-
.contains("working"))
|
|
1511
|
-
.unwrap_or(false),
|
|
1512
|
-
"busy-state capture should be recorded in attempts_detail: {:?}",
|
|
1513
|
-
diagnostics.attempts_detail
|
|
1514
|
-
);
|
|
1515
|
-
assert_eq!(
|
|
1516
|
-
diagnostics.consumption_reason,
|
|
1517
|
-
SubmitConsumptionReason::FallbackBusy
|
|
1518
|
-
);
|
|
1519
|
-
assert_eq!(diagnostics.before_busy_signal_kind, None);
|
|
1520
|
-
assert_eq!(diagnostics.busy_signal_kind, Some(BusySignalKind::Working));
|
|
1521
|
-
assert_eq!(diagnostics.busy_line_from_bottom, Some(0));
|
|
1522
|
-
assert_eq!(diagnostics.current_marker_in_bottom_15, Some(true));
|
|
1523
|
-
assert_eq!(diagnostics.paste_identity_in_composer, None);
|
|
1524
|
-
assert_eq!(diagnostics.consumption_from_capture_result, Some(false));
|
|
1525
|
-
}
|
|
1526
|
-
|
|
1527
|
-
#[test]
|
|
1528
|
-
fn e46_capture_error_clears_previous_consumption_observation() {
|
|
1529
|
-
let token_text = "Team Agent message from leader:\n\nhi\n\n[team-agent-token:msg_capture_error]";
|
|
1530
|
-
let busy_tail = format!("{token_text}\nโ Working (1s ยท esc to interrupt)\n");
|
|
1531
|
-
let visible = ok(token_text);
|
|
1532
|
-
let queued = vec![
|
|
1533
|
-
MockResp::Out(ok("")), // set-buffer
|
|
1534
|
-
MockResp::Out(ok("")), // paste-buffer
|
|
1535
|
-
MockResp::Out(ok("")), // delete-buffer
|
|
1536
|
-
MockResp::Out(visible.clone()), // pasted-content prompt: continue
|
|
1537
|
-
MockResp::Out(visible), // pre-submit token visibility
|
|
1538
|
-
MockResp::Out(ok("")), // Escape
|
|
1539
|
-
MockResp::Out(ok("")), // Enter
|
|
1540
|
-
MockResp::Out(ok(&busy_tail)), // first post-Enter capture: busy
|
|
1541
|
-
// Default capture error forces the next poll/fallback/resend reads to fail.
|
|
1542
|
-
];
|
|
1543
|
-
let (be, _rec) = backend_with(MockResp::Io(std::io::ErrorKind::Other), queued);
|
|
1544
|
-
let report = be
|
|
1545
|
-
.inject(
|
|
1546
|
-
&Target::Pane(PaneId::new("%7")),
|
|
1547
|
-
&InjectPayload::Text(token_text.to_string()),
|
|
1548
|
-
Key::Enter,
|
|
1549
|
-
true,
|
|
1550
|
-
)
|
|
1551
|
-
.expect("inject runs through capture failure");
|
|
1552
|
-
let diagnostics = report.submit_diagnostics.expect("diagnostics");
|
|
1553
|
-
assert_eq!(
|
|
1554
|
-
report.submit_verification,
|
|
1555
|
-
SubmitVerification::SubmitConsumptionUnverified
|
|
1556
|
-
);
|
|
1557
|
-
assert_eq!(diagnostics.consumption_reason, SubmitConsumptionReason::Unverified);
|
|
1558
|
-
assert!(diagnostics.capture_err_count > 0);
|
|
1559
|
-
assert_eq!(diagnostics.before_busy_signal_kind, None);
|
|
1560
|
-
assert_eq!(diagnostics.busy_signal_kind, None);
|
|
1561
|
-
assert_eq!(diagnostics.busy_line_from_bottom, None);
|
|
1562
|
-
assert_eq!(diagnostics.current_marker_in_bottom_15, None);
|
|
1563
|
-
assert_eq!(diagnostics.paste_identity_in_composer, None);
|
|
1564
|
-
assert_eq!(diagnostics.consumption_from_capture_result, None);
|
|
1565
|
-
}
|
|
1566
|
-
|
|
1567
|
-
/// NeverSeen + ๆ ๅ ไฝ็ฌฆ๏ผ็ฉบ pane ไธๅพๅๆใtoken ไธๅจๅบ้จใๅๆ consumedใ
|
|
1568
|
-
/// ๆง้ป่ฎค EnterSentWithoutPlaceholderCheck ๅฐฑๆฏๆๅ ๆ็็ๅๆใ
|
|
1569
|
-
#[test]
|
|
1570
|
-
fn e46_inject_text_with_empty_pane_is_unverified() {
|
|
1571
|
-
let token_text = "Team Agent message from leader:\n\nhi\n\n[team-agent-token:msg_empty]";
|
|
1572
|
-
let (be, _rec) = backend_with(MockResp::Out(ok("")), vec![]);
|
|
1573
|
-
let report = be
|
|
1574
|
-
.inject(
|
|
1575
|
-
&Target::Pane(PaneId::new("%7")),
|
|
1576
|
-
&InjectPayload::Text(token_text.to_string()),
|
|
1577
|
-
Key::Enter,
|
|
1578
|
-
true,
|
|
1579
|
-
)
|
|
1580
|
-
.expect("inject runs");
|
|
1581
|
-
assert_eq!(
|
|
1582
|
-
report.submit_verification,
|
|
1583
|
-
SubmitVerification::SubmitConsumptionUnverified,
|
|
1584
|
-
"empty pane / token never visible / no pasted #N โ unverified, \
|
|
1585
|
-
not EnterSentWithoutPlaceholderCheck. Got {:?}",
|
|
1586
|
-
report.submit_verification
|
|
1587
|
-
);
|
|
1588
|
-
}
|
|
1589
|
-
|
|
1590
|
-
/// **E46 RED-2 (ๆญฃๅๆถ่ดน็กฎ่ฎค โ delivered)**: token-bearing Text + Enter +
|
|
1591
|
-
/// bracketed paste. Token VISIBLE on first capture (pre/post-submit token
|
|
1592
|
-
/// readback) BUT then GONE from the post-submit input-consumption probe
|
|
1593
|
-
/// (composer cleared after Enter). Submit must report
|
|
1594
|
-
/// `EnterSentWithoutPlaceholderCheck` (MUST-10 path) โ delivery proceeds
|
|
1595
|
-
/// to delivered. Guards against regression on crd's existing-worker path.
|
|
1596
|
-
#[test]
|
|
1597
|
-
fn e46_inject_text_with_token_consumed_after_enter_keeps_enter_sent_without_placeholder_check() {
|
|
1598
|
-
let token_text = "Team Agent message from leader:\n\nhi\n\n[team-agent-token:msg_red2]";
|
|
1599
|
-
// First captures (token visibility probes pre/post-Enter) return text
|
|
1600
|
-
// with token; the LAST capture (consumption probe) returns text WITHOUT
|
|
1601
|
-
// the token in the tail (composer cleared). MockCommandRunner drains
|
|
1602
|
-
// `queued` first then defaults โ we queue the early "token visible"
|
|
1603
|
-
// captures, then drop to the empty default for the consumption probe.
|
|
1604
|
-
let visible = ok(token_text);
|
|
1605
|
-
let queued = vec![
|
|
1606
|
-
MockResp::Out(ok("")), // set-buffer
|
|
1607
|
-
MockResp::Out(ok("")), // paste-buffer
|
|
1608
|
-
MockResp::Out(ok("")), // delete-buffer
|
|
1609
|
-
MockResp::Out(visible.clone()), // pasted-content prompt poll: none โ continue
|
|
1610
|
-
MockResp::Out(visible.clone()), // pre-submit token visibility: visible
|
|
1611
|
-
MockResp::Out(ok("")), // Escape send-keys (no stdout needed)
|
|
1612
|
-
MockResp::Out(ok("")), // Enter send-keys
|
|
1613
|
-
// From here on, the default response is `ok("")` (empty pane tail) so
|
|
1614
|
-
// post-Enter consumption probe sees no token in tail โ consumed=true.
|
|
1615
|
-
];
|
|
1616
|
-
let (be, _rec) = backend_with(MockResp::Out(ok("")), queued);
|
|
1617
|
-
let report = be
|
|
1618
|
-
.inject(
|
|
1619
|
-
&Target::Pane(PaneId::new("%7")),
|
|
1620
|
-
&InjectPayload::Text(token_text.to_string()),
|
|
1621
|
-
Key::Enter,
|
|
1622
|
-
true,
|
|
1623
|
-
)
|
|
1624
|
-
.expect("inject runs");
|
|
1625
|
-
assert_eq!(
|
|
1626
|
-
report.submit_verification,
|
|
1627
|
-
SubmitVerification::EnterSentWithoutPlaceholderCheck,
|
|
1628
|
-
"E46 RED-2: when post-Enter consumption is observed (token gone \
|
|
1629
|
-
from input region tail), submit must report the canonical \
|
|
1630
|
-
EnterSentWithoutPlaceholderCheck so MUST-10 delivery semantics \
|
|
1631
|
-
hold (provider_submit_verification_red.rs:113-159). Got {:?}",
|
|
1632
|
-
report.submit_verification
|
|
1633
|
-
);
|
|
1634
|
-
let diagnostics = report.submit_diagnostics.expect("diagnostics");
|
|
1635
|
-
assert_eq!(
|
|
1636
|
-
diagnostics.consumption_reason,
|
|
1637
|
-
SubmitConsumptionReason::ConsumptionFromCapture
|
|
1638
|
-
);
|
|
1639
|
-
assert_eq!(diagnostics.busy_signal_kind, None);
|
|
1640
|
-
assert_eq!(diagnostics.current_marker_in_bottom_15, Some(false));
|
|
1641
|
-
assert_eq!(diagnostics.consumption_from_capture_result, Some(true));
|
|
1642
|
-
}
|
|
1643
|
-
|
|
1644
|
-
/// **E46 RED-3 (resend-to-cap, no double-submit)**: when the FIRST Enter
|
|
1645
|
-
/// landed on the composer but our readback was slow, the re-check BEFORE
|
|
1646
|
-
/// resend must observe the now-empty input and STOP โ must NOT fire a
|
|
1647
|
-
/// second Enter into an empty composer (would open an empty turn).
|
|
1648
|
-
#[test]
|
|
1649
|
-
fn e46_inject_text_resend_rechecks_input_before_resending_to_avoid_double_submit() {
|
|
1650
|
-
// Same mock as RED-2: post-Enter consumption probe sees empty tail.
|
|
1651
|
-
// The implementation should issue only ONE Enter (no resend) once
|
|
1652
|
-
// consumption is observed.
|
|
1653
|
-
let token_text = "Team Agent message from leader:\n\nhi\n\n[team-agent-token:msg_red3]";
|
|
1654
|
-
let queued = vec![
|
|
1655
|
-
MockResp::Out(ok("")), // set-buffer
|
|
1656
|
-
MockResp::Out(ok("")), // paste-buffer
|
|
1657
|
-
MockResp::Out(ok("")), // delete-buffer
|
|
1658
|
-
MockResp::Out(ok(token_text)), // pasted-content prompt: not matched
|
|
1659
|
-
MockResp::Out(ok(token_text)), // pre-submit token visibility
|
|
1660
|
-
MockResp::Out(ok("")), // Escape
|
|
1661
|
-
MockResp::Out(ok("")), // Enter
|
|
1662
|
-
];
|
|
1663
|
-
let (be, rec) = backend_with(MockResp::Out(ok("")), queued);
|
|
1664
|
-
let _report = be
|
|
1665
|
-
.inject(
|
|
1666
|
-
&Target::Pane(PaneId::new("%7")),
|
|
1667
|
-
&InjectPayload::Text(token_text.to_string()),
|
|
1668
|
-
Key::Enter,
|
|
1669
|
-
true,
|
|
1670
|
-
)
|
|
1671
|
-
.expect("inject runs");
|
|
1672
|
-
let calls = rec.lock().unwrap().clone();
|
|
1673
|
-
// Count `send-keys ... Enter` invocations. There must be EXACTLY ONE
|
|
1674
|
-
// (the canonical submit). A second one indicates the resend loop
|
|
1675
|
-
// didn't honour C3 (re-check input before resend).
|
|
1676
|
-
let enter_count = calls
|
|
1677
|
-
.iter()
|
|
1678
|
-
.filter(|argv| {
|
|
1679
|
-
argv.get(1).map(String::as_str) == Some("send-keys")
|
|
1680
|
-
&& argv.contains(&tmux_submit_key_name(Key::Enter).to_string())
|
|
1681
|
-
})
|
|
1682
|
-
.count();
|
|
1683
|
-
assert_eq!(
|
|
1684
|
-
enter_count, 1,
|
|
1685
|
-
"E46 RED-3: when consumption is observed (or already happened \
|
|
1686
|
-
between Enter and probe), the resend loop must STOP and NOT \
|
|
1687
|
-
issue a second Enter. Got {enter_count} Enter sends. \
|
|
1688
|
-
calls={calls:?}"
|
|
1689
|
-
);
|
|
1690
|
-
}
|
|
1691
|
-
|
|
1692
|
-
/// **E46 RED-5 (provider-agnostic detector)**: the consumption probe must
|
|
1693
|
-
/// NOT hard-code provider UI strings (claude `>`, codex `โฐ`, ...). It uses
|
|
1694
|
-
/// the token marker absence in the bottom of the pane โ works for any
|
|
1695
|
-
/// provider. Here we run a non-claude-shaped pane (no claude markers) and
|
|
1696
|
-
/// confirm the same delivered semantics when consumption happens.
|
|
1697
|
-
#[test]
|
|
1698
|
-
fn e46_consumption_detector_works_on_codex_shaped_pane_without_provider_strings() {
|
|
1699
|
-
// Codex-shaped fake: prompt looks like `codex>` with no claude markers.
|
|
1700
|
-
// After Enter, the composer clears (empty default returns ok("")).
|
|
1701
|
-
let token_text = "Team Agent message from leader:\n\ncodex msg\n\n[team-agent-token:msg_red5]";
|
|
1702
|
-
let queued = vec![
|
|
1703
|
-
MockResp::Out(ok("")), // set-buffer
|
|
1704
|
-
MockResp::Out(ok("")), // paste-buffer
|
|
1705
|
-
MockResp::Out(ok("")), // delete-buffer
|
|
1706
|
-
MockResp::Out(ok("codex>\n")), // pasted-content prompt: no match
|
|
1707
|
-
MockResp::Out(ok(token_text)), // pre-submit token visibility
|
|
1708
|
-
MockResp::Out(ok("")), // Escape
|
|
1709
|
-
MockResp::Out(ok("")), // Enter
|
|
1710
|
-
// post-Enter: default returns ok("") (composer cleared) โ token gone
|
|
1711
|
-
];
|
|
1712
|
-
let (be, _rec) = backend_with(MockResp::Out(ok("")), queued);
|
|
1713
|
-
let report = be
|
|
1714
|
-
.inject(
|
|
1715
|
-
&Target::Pane(PaneId::new("%7")),
|
|
1716
|
-
&InjectPayload::Text(token_text.to_string()),
|
|
1717
|
-
Key::Enter,
|
|
1718
|
-
true,
|
|
1719
|
-
)
|
|
1720
|
-
.expect("inject runs");
|
|
1721
|
-
assert_eq!(
|
|
1722
|
-
report.submit_verification,
|
|
1723
|
-
SubmitVerification::EnterSentWithoutPlaceholderCheck,
|
|
1724
|
-
"E46 RED-5: provider-agnostic detector โ codex-shaped pane (no \
|
|
1725
|
-
claude UI string) where composer clears post-Enter must still \
|
|
1726
|
-
report EnterSentWithoutPlaceholderCheck via structural \
|
|
1727
|
-
input-empty check. Got {:?}",
|
|
1728
|
-
report.submit_verification
|
|
1729
|
-
);
|
|
1730
|
-
}
|
|
1731
|
-
|
|
1732
|
-
/// **E46 Escape pre-Enter**: when bracketed=true + Text payload + submit=Enter,
|
|
1733
|
-
/// the inject must send Escape BEFORE the Enter (exits bracketed-paste
|
|
1734
|
-
/// mode on stuck composer). Non-Enter submits (e.g. Key::Down for codex
|
|
1735
|
-
/// menu) must NOT receive the Escape pre-step.
|
|
1736
|
-
#[test]
|
|
1737
|
-
/// 0.3.27 amendment: Escape is now RETRY-ONLY (attempt > 0). The first
|
|
1738
|
-
/// attempt sends Enter directly (Python parity โ Python never sends Escape).
|
|
1739
|
-
/// Escape fires only if the first Enter failed to consume the token and a
|
|
1740
|
-
/// retry is needed. This test now asserts the first attempt has NO Escape.
|
|
1741
|
-
fn e46_inject_text_first_attempt_no_escape_retry_only() {
|
|
1742
|
-
let token_text = "Team Agent message from leader:\n\nhi\n\n[team-agent-token:msg_esc]";
|
|
1743
|
-
// Mock returns empty โ token not in tail โ consumed=true on first attempt.
|
|
1744
|
-
let (be, rec) = backend_with(MockResp::Out(ok("")), vec![]);
|
|
1745
|
-
let _report = be
|
|
1746
|
-
.inject(
|
|
1747
|
-
&Target::Pane(PaneId::new("%7")),
|
|
1748
|
-
&InjectPayload::Text(token_text.to_string()),
|
|
1749
|
-
Key::Enter,
|
|
1750
|
-
true,
|
|
1751
|
-
)
|
|
1752
|
-
.expect("inject runs");
|
|
1753
|
-
let calls = rec.lock().unwrap().clone();
|
|
1754
|
-
let enter_count = calls
|
|
1755
|
-
.iter()
|
|
1756
|
-
.filter(|argv| {
|
|
1757
|
-
argv.get(1).map(String::as_str) == Some("send-keys")
|
|
1758
|
-
&& argv.contains(&tmux_submit_key_name(Key::Enter).to_string())
|
|
1759
|
-
})
|
|
1760
|
-
.count();
|
|
1761
|
-
let escape_count = calls
|
|
1762
|
-
.iter()
|
|
1763
|
-
.filter(|argv| {
|
|
1764
|
-
argv.get(1).map(String::as_str) == Some("send-keys")
|
|
1765
|
-
&& argv.contains(&"Escape".to_string())
|
|
1766
|
-
})
|
|
1767
|
-
.count();
|
|
1768
|
-
assert!(
|
|
1769
|
-
enter_count >= 1,
|
|
1770
|
-
"0.3.27: first attempt must send Enter; calls={calls:?}"
|
|
1771
|
-
);
|
|
1772
|
-
assert_eq!(
|
|
1773
|
-
escape_count, 0,
|
|
1774
|
-
"0.3.27: first attempt (consumed=true) must NOT send Escape \
|
|
1775
|
-
(Escape is retry-only); calls={calls:?}"
|
|
1776
|
-
);
|
|
1777
|
-
}
|
|
1778
|
-
|
|
1779
|
-
/// **E46 regression guard**: non-Enter submit (codex menu navigation,
|
|
1780
|
-
/// `Key::Down`) does NOT trigger the Escape pre-step (would interfere
|
|
1781
|
-
/// with the menu).
|
|
1782
|
-
#[test]
|
|
1783
|
-
fn e46_inject_text_non_enter_submit_does_not_emit_escape_prestep() {
|
|
1784
|
-
let token_text = "menu interaction\n[team-agent-token:msg_down]";
|
|
1785
|
-
let (be, rec) = backend_with(MockResp::Out(ok("")), vec![]);
|
|
1786
|
-
let _report = be
|
|
1787
|
-
.inject(
|
|
1788
|
-
&Target::Pane(PaneId::new("%7")),
|
|
1789
|
-
&InjectPayload::Text(token_text.to_string()),
|
|
1790
|
-
Key::Down,
|
|
1791
|
-
true,
|
|
1792
|
-
)
|
|
1793
|
-
.expect("inject runs");
|
|
1794
|
-
let calls = rec.lock().unwrap().clone();
|
|
1795
|
-
let escape_count = calls
|
|
1796
|
-
.iter()
|
|
1797
|
-
.filter(|argv| {
|
|
1798
|
-
argv.get(1).map(String::as_str) == Some("send-keys")
|
|
1799
|
-
&& argv.contains(&"Escape".to_string())
|
|
1800
|
-
})
|
|
1801
|
-
.count();
|
|
1802
|
-
assert_eq!(
|
|
1803
|
-
escape_count, 0,
|
|
1804
|
-
"E46 regression guard: Key::Down submits (codex menu navigation) \
|
|
1805
|
-
must NOT receive Escape pre-step. Got {escape_count}. \
|
|
1806
|
-
calls={calls:?}"
|
|
1807
|
-
);
|
|
1808
|
-
}
|
|
1809
|
-
|
|
1810
|
-
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
1811
|
-
// E50 PR-1 (0.3.24 P0, pasted-prompt ๅ้ด่ฏๆญ) โ InjectReport.submit_diagnostics
|
|
1812
|
-
// is populated for paste-prompt loops, and `pasted_prompt_match` / scrubbing
|
|
1813
|
-
// helpers are pure functions safe to test deterministically.
|
|
1814
|
-
//
|
|
1815
|
-
// Architect verdict (Workflow forensic): the pre-fix
|
|
1816
|
-
// `capture_has_pasted_content_prompt` matched ANY `pasted content` /
|
|
1817
|
-
// `pasted text` token in the full Tail(80), including scrolled-off
|
|
1818
|
-
// submitted blocks. PR-1 just adds the diagnostics; PR-2 will USE
|
|
1819
|
-
// `where_in_tail` to fix the criterion. These tests pin the data shape.
|
|
1820
|
-
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
1821
|
-
|
|
1822
|
-
/// **E50 RED-1 (ๅคๆฎ่ฏฏๅค, pure function)**: `pasted_prompt_match` must
|
|
1823
|
-
/// distinguish bottom-region (composer) from scrollback (line 6+ from
|
|
1824
|
-
/// bottom). Pre-fix `capture_has_pasted_content_prompt` returned `true`
|
|
1825
|
-
/// for BOTH; the new tuple-returning helper surfaces the offset so PR-2
|
|
1826
|
-
/// can fix the criterion.
|
|
1827
|
-
#[test]
|
|
1828
|
-
fn e50_pasted_prompt_match_reports_where_in_tail_for_scrollback_vs_composer() {
|
|
1829
|
-
use super::pasted_prompt_match;
|
|
1830
|
-
|
|
1831
|
-
// Composer (bottom) match.
|
|
1832
|
-
let composer_only = "some output\n\
|
|
1833
|
-
[Pasted content 1.2k]\n\
|
|
1834
|
-
โฏ ";
|
|
1835
|
-
// The match is "pasted content" in the line at index 1 from bottom
|
|
1836
|
-
// among non-empty lines (`[Pasted content...]`, `โฏ ` is at idx 0).
|
|
1837
|
-
let m = pasted_prompt_match(composer_only).expect("match");
|
|
1838
|
-
assert_eq!(m.0, "pasted content");
|
|
1839
|
-
assert_eq!(
|
|
1840
|
-
m.1, 1,
|
|
1841
|
-
"E50: where_in_tail must reflect bottom offset (idx 1 = above the \
|
|
1842
|
-
`โฏ` composer line); got {m:?}"
|
|
1843
|
-
);
|
|
1844
|
-
|
|
1845
|
-
// Scrollback (top) match โ 8 lines from bottom.
|
|
1846
|
-
let scrollback_only = "[Pasted content 5.0k]\n\
|
|
1847
|
-
assistant reply line 1\n\
|
|
1848
|
-
assistant reply line 2\n\
|
|
1849
|
-
assistant reply line 3\n\
|
|
1850
|
-
assistant reply line 4\n\
|
|
1851
|
-
assistant reply line 5\n\
|
|
1852
|
-
assistant reply line 6\n\
|
|
1853
|
-
assistant reply line 7\n\
|
|
1854
|
-
โฏ ";
|
|
1855
|
-
let m2 = pasted_prompt_match(scrollback_only).expect("match");
|
|
1856
|
-
assert_eq!(m2.0, "pasted content");
|
|
1857
|
-
assert!(
|
|
1858
|
-
m2.1 >= 6,
|
|
1859
|
-
"E50: scrollback `Pasted content` must report where_in_tail >= 6 \
|
|
1860
|
-
(clearly above the bottom composer region); got {m2:?}. PR-2 \
|
|
1861
|
-
will use this offset to distinguish live composer vs scrollback \
|
|
1862
|
-
residue."
|
|
1863
|
-
);
|
|
1864
|
-
|
|
1865
|
-
// No match.
|
|
1866
|
-
assert!(pasted_prompt_match("nothing here\nโฏ ").is_none());
|
|
1867
|
-
}
|
|
1868
|
-
|
|
1869
|
-
/// **E50 PR-2 Fix-B (amends PR-1 RED-2)**: with Fix-B, token-bearing
|
|
1870
|
-
/// payloads SKIP the paste-prompt weak loop and fall through to the E46
|
|
1871
|
-
/// token consumption gate. The `submit_diagnostics` still records the
|
|
1872
|
-
/// appear-gate timing (was `saw_pasted_prompt` matched?), but
|
|
1873
|
-
/// `attempts_detail` is populated by the E46 consumption gate path, not
|
|
1874
|
-
/// the deleted weak loop. This test pins the NEW shape: `appear_gate_matched`
|
|
1875
|
-
/// may be false (mock default returns the pasted-content text, but the
|
|
1876
|
-
/// appear-gate polls 5 times with 25ms sleep and the mock answers the SAME
|
|
1877
|
-
/// text every time โ appear-gate DOES match). However, the `has_token` guard
|
|
1878
|
-
/// skips the weak loop body โ the token path's diagnostics fill in instead.
|
|
1879
|
-
#[test]
|
|
1880
|
-
fn e50_inject_paste_prompt_path_populates_submit_diagnostics_per_attempt() {
|
|
1881
|
-
let token_text = "Team Agent message from leader:\n\nhello\n\n[team-agent-token:msg_pr1]";
|
|
1882
|
-
// Mock keeps returning the pasted-content placeholder. With Fix-B,
|
|
1883
|
-
// the token path takes over: post_submit_input_consumed checks
|
|
1884
|
-
// bottom 5 lines for the token marker. The mock returns the pasted
|
|
1885
|
-
// placeholder text (without the token) โ token NOT in tail โ consumed
|
|
1886
|
-
// = Some(true) โ EnterSentWithoutPlaceholderCheck.
|
|
1887
|
-
// We test: (a) diagnostics present (b) submit verification reflects
|
|
1888
|
-
// the E46 token path, not the deleted weak loop.
|
|
1889
|
-
let pasted = "[Pasted content 1.2k]";
|
|
1890
|
-
let (be, _rec) = backend_with(MockResp::Out(ok(pasted)), vec![]);
|
|
1891
|
-
let report = be
|
|
1892
|
-
.inject(
|
|
1893
|
-
&Target::Pane(PaneId::new("%7")),
|
|
1894
|
-
&InjectPayload::Text(token_text.to_string()),
|
|
1895
|
-
Key::Enter,
|
|
1896
|
-
true,
|
|
1897
|
-
)
|
|
1898
|
-
.expect("inject");
|
|
1899
|
-
// token ไปๆชๅฏ่ง + composer ้ไปๆ pasted content๏ผๆ #N๏ผโ ไธๅพๆฅๅทฒๆถ่ดนใ
|
|
1900
|
-
assert_eq!(
|
|
1901
|
-
report.submit_verification,
|
|
1902
|
-
SubmitVerification::SubmitConsumptionUnverified,
|
|
1903
|
-
"folded placeholder still in composer (no #N, token never seen) \
|
|
1904
|
-
must be unverified, not vacuous EnterSentWithoutPlaceholderCheck; \
|
|
1905
|
-
got {:?}",
|
|
1906
|
-
report.submit_verification
|
|
1907
|
-
);
|
|
1908
|
-
let diagnostics = report.submit_diagnostics.expect("diagnostics");
|
|
1909
|
-
assert!(
|
|
1910
|
-
!diagnostics.attempts_detail.is_empty(),
|
|
1911
|
-
"E50: E46 consumption gate must preserve per-capture diagnostics"
|
|
1912
|
-
);
|
|
1913
|
-
assert_eq!(diagnostics.attempts_detail[0].attempt_index, 1);
|
|
1914
|
-
assert!(
|
|
1915
|
-
diagnostics.attempts_detail[0]
|
|
1916
|
-
.pane_tail_excerpt
|
|
1917
|
-
.contains("Pasted content"),
|
|
1918
|
-
"E50: recorded pane tail should contain the post-submit capture; got {:?}",
|
|
1919
|
-
diagnostics.attempts_detail[0]
|
|
1920
|
-
);
|
|
1921
|
-
}
|
|
1922
|
-
|
|
1923
|
-
/// **E50 PR-1 secret scrubbing**: `scrub_pane_excerpt` must strip ANSI
|
|
1924
|
-
/// + redact common secret shapes so emitted events.jsonl doesn't leak.
|
|
1925
|
-
#[test]
|
|
1926
|
-
fn e50_scrub_pane_excerpt_strips_ansi_and_redacts_secret_shapes() {
|
|
1927
|
-
use super::scrub_pane_excerpt;
|
|
1928
|
-
let raw = "\x1b[31merror\x1b[0m: sk-abcdef123ghi\n\
|
|
1929
|
-
token Bearer abc.def.ghi\n\
|
|
1930
|
-
key AKIAIOSFODNN7EXAMPLE\n\
|
|
1931
|
-
ghp_1234567890abcdef\n\
|
|
1932
|
-
hex deadbeefdeadbeefdeadbeefdeadbeefcafebabe\n\
|
|
1933
|
-
plain text below";
|
|
1934
|
-
let (out, lines) = scrub_pane_excerpt(raw, 20);
|
|
1935
|
-
assert!(lines >= 5, "E50: at least 5 non-empty lines; got {lines}");
|
|
1936
|
-
assert!(
|
|
1937
|
-
!out.contains("\x1b"),
|
|
1938
|
-
"E50: ANSI escape stripped; got {out:?}"
|
|
1939
|
-
);
|
|
1940
|
-
assert!(
|
|
1941
|
-
!out.contains("sk-abcdef123ghi"),
|
|
1942
|
-
"E50: sk- secret must be redacted; got {out:?}"
|
|
1943
|
-
);
|
|
1944
|
-
assert!(
|
|
1945
|
-
!out.contains("ghp_1234567890abcdef"),
|
|
1946
|
-
"E50: ghp_ secret must be redacted; got {out:?}"
|
|
1947
|
-
);
|
|
1948
|
-
assert!(
|
|
1949
|
-
!out.contains("AKIAIOSFODNN7EXAMPLE"),
|
|
1950
|
-
"E50: AKIA secret must be redacted; got {out:?}"
|
|
1951
|
-
);
|
|
1952
|
-
assert!(
|
|
1953
|
-
!out.contains("abc.def.ghi"),
|
|
1954
|
-
"E50: Bearer secret token must be redacted; got {out:?}"
|
|
1955
|
-
);
|
|
1956
|
-
assert!(
|
|
1957
|
-
!out.contains("deadbeefdeadbeefdeadbeefdeadbeefcafebabe"),
|
|
1958
|
-
"E50: 32+ hex run must be redacted; got {out:?}"
|
|
1959
|
-
);
|
|
1960
|
-
assert!(
|
|
1961
|
-
out.contains("REDACTED"),
|
|
1962
|
-
"E50: redactions visible; got {out:?}"
|
|
1963
|
-
);
|
|
1964
|
-
assert!(
|
|
1965
|
-
out.contains("plain text below"),
|
|
1966
|
-
"E50: non-secret content preserved; got {out:?}"
|
|
1967
|
-
);
|
|
1968
|
-
}
|
|
1969
|
-
|
|
1970
|
-
/// **E50 PR-1 byte-identical legacy matcher**: `capture_has_pasted_content_prompt`
|
|
1971
|
-
/// wrapper must still return the same bool the 3 legacy callers depend on
|
|
1972
|
-
/// (the bool-returning fn shape is the contract for byte-locked behaviour).
|
|
1973
|
-
#[test]
|
|
1974
|
-
fn e50_capture_has_pasted_content_prompt_byte_identical_wrapper() {
|
|
1975
|
-
use super::capture_has_pasted_content_prompt;
|
|
1976
|
-
assert!(capture_has_pasted_content_prompt("[Pasted content 1k]"));
|
|
1977
|
-
assert!(capture_has_pasted_content_prompt("[Pasted text foo]"));
|
|
1978
|
-
assert!(!capture_has_pasted_content_prompt("just composer text"));
|
|
1979
|
-
assert!(!capture_has_pasted_content_prompt(""));
|
|
1980
|
-
}
|
|
1981
|
-
|
|
1982
|
-
#[test]
|
|
1983
|
-
fn send_keys_cancel_mode_queries_mode_and_dispatches_cancel_argv() {
|
|
1984
|
-
let (be, rec) = backend_with(
|
|
1985
|
-
MockResp::Out(ok("")),
|
|
1986
|
-
vec![MockResp::Out(ok("tree-mode\n")), MockResp::Out(ok(""))],
|
|
1987
|
-
);
|
|
1988
|
-
be.send_keys(&Target::Pane(PaneId::new("%7")), &[Key::CancelMode])
|
|
1989
|
-
.expect("cancel mode");
|
|
1990
|
-
|
|
1991
|
-
let calls = rec.lock().unwrap().clone();
|
|
1992
|
-
assert_eq!(
|
|
1993
|
-
calls[0],
|
|
1994
|
-
svec(&["tmux", "display-message", "-p", "-t", "%7", "#{pane_mode}"])
|
|
1995
|
-
);
|
|
1996
|
-
assert_eq!(calls[1], svec(&["tmux", "send-keys", "-t", "%7", "q"]));
|
|
1997
|
-
}
|
|
1998
|
-
|
|
1999
|
-
#[test]
|
|
2000
|
-
fn cancel_mode_numeric_zero_is_input_ready_and_does_not_send_cancel() {
|
|
2001
|
-
// Golden /tmp/transport_golden_probe.py:
|
|
2002
|
-
// `_normalize_pane_mode("0") == ""`; `_prepare_tmux_pane_for_input` returns
|
|
2003
|
-
// pane_input_ready and does NOT call `_pane_mode_cancel`.
|
|
2004
|
-
// RED: pane_mode_from_raw("0") maps to Unknown, so Rust sends `-X cancel`.
|
|
2005
|
-
let (be, rec) = backend_with(MockResp::Out(ok("")), vec![MockResp::Out(ok("0\n"))]);
|
|
2006
|
-
be.send_keys(&Target::Pane(PaneId::new("%7")), &[Key::CancelMode])
|
|
2007
|
-
.expect("cancel mode input-ready no-op");
|
|
2008
|
-
|
|
2009
|
-
let calls = rec.lock().unwrap().clone();
|
|
2010
|
-
assert_eq!(
|
|
2011
|
-
calls,
|
|
2012
|
-
vec![svec(&["tmux", "display-message", "-p", "-t", "%7", "#{pane_mode}"])],
|
|
2013
|
-
"pane_mode='0' is Python input-ready; CancelMode must stop after the mode query, got {calls:?}"
|
|
2014
|
-
);
|
|
2015
|
-
}
|
|
2016
|
-
|
|
2017
|
-
#[test]
|
|
2018
|
-
fn inject_text_uses_message_id_scoped_buffer_from_token() {
|
|
2019
|
-
// Golden delivery.py:109-114 passes buffer_name = `team-agent-send-{message_id}` into
|
|
2020
|
-
// `_tmux_inject_text`; tmux_io.py then uses that exact name for set/load, paste, delete.
|
|
2021
|
-
// This prevents interleaved sends from sharing a stale global tmux buffer.
|
|
2022
|
-
// RED: Rust currently hard-codes `team-agent-buf`.
|
|
2023
|
-
let (be, rec) = backend_with(MockResp::Out(ok("")), vec![]);
|
|
2024
|
-
let text =
|
|
2025
|
-
"Team Agent message from leader:\n\nhello\n\n[team-agent-token:msg_abc123]".to_string();
|
|
2026
|
-
be.inject(
|
|
2027
|
-
&Target::Pane(PaneId::new("%7")),
|
|
2028
|
-
&InjectPayload::Text(text),
|
|
2029
|
-
Key::Enter,
|
|
2030
|
-
true,
|
|
2031
|
-
)
|
|
2032
|
-
.expect("inject");
|
|
2033
|
-
|
|
2034
|
-
let calls = rec.lock().unwrap().clone();
|
|
2035
|
-
let buffer_args: Vec<String> = calls
|
|
2036
|
-
.iter()
|
|
2037
|
-
.filter(|argv| {
|
|
2038
|
-
matches!(
|
|
2039
|
-
argv.get(1).map(String::as_str),
|
|
2040
|
-
Some("set-buffer" | "load-buffer" | "paste-buffer" | "delete-buffer")
|
|
2041
|
-
)
|
|
2042
|
-
})
|
|
2043
|
-
.filter_map(|argv| {
|
|
2044
|
-
argv.iter()
|
|
2045
|
-
.position(|arg| arg == "-b")
|
|
2046
|
-
.and_then(|i| argv.get(i + 1))
|
|
2047
|
-
.cloned()
|
|
2048
|
-
})
|
|
2049
|
-
.collect();
|
|
2050
|
-
assert_eq!(
|
|
2051
|
-
buffer_args,
|
|
2052
|
-
vec![
|
|
2053
|
-
"team-agent-send-msg_abc123".to_string(),
|
|
2054
|
-
"team-agent-send-msg_abc123".to_string(),
|
|
2055
|
-
"team-agent-send-msg_abc123".to_string(),
|
|
2056
|
-
],
|
|
2057
|
-
"every tmux buffer operation must use the message-id-scoped golden buffer name; calls={calls:?}"
|
|
2058
|
-
);
|
|
2059
|
-
}
|
|
2060
|
-
|
|
2061
|
-
// โโ 6. liveness three-state (ยงbug-085): exit 0 -> Live; "can't find โฆ" -> Dead; else -> Unknown โ
|
|
2062
|
-
#[test]
|
|
2063
|
-
fn liveness_is_three_state_unknown_is_not_dead() {
|
|
2064
|
-
let (be, rec) = backend_with(MockResp::Out(ok("%7")), vec![]);
|
|
2065
|
-
assert_eq!(
|
|
2066
|
-
be.liveness(&PaneId::new("%7")).expect("liveness"),
|
|
2067
|
-
PaneLiveness::Live
|
|
2068
|
-
);
|
|
2069
|
-
let argv0 = rec.lock().unwrap()[0].clone();
|
|
2070
|
-
assert!(
|
|
2071
|
-
argv0.contains(&"display-message".to_string())
|
|
2072
|
-
&& argv0.iter().any(|x| x.contains("#{pane_id}"))
|
|
2073
|
-
&& argv0.contains(&"%7".to_string()),
|
|
2074
|
-
"liveness must probe the pane via display-message #{{pane_id}}; got {argv0:?}"
|
|
2075
|
-
);
|
|
2076
|
-
|
|
2077
|
-
let (be, _r) = backend_with(MockResp::Out(fail(1, "can't find pane %7")), vec![]);
|
|
2078
|
-
assert_eq!(
|
|
2079
|
-
be.liveness(&PaneId::new("%7")).expect("liveness"),
|
|
2080
|
-
PaneLiveness::Dead,
|
|
2081
|
-
"a 'can't find pane' failure -> Dead"
|
|
2082
|
-
);
|
|
2083
|
-
|
|
2084
|
-
let (be, _r) = backend_with(
|
|
2085
|
-
MockResp::Out(fail(
|
|
2086
|
-
1,
|
|
2087
|
-
"error connecting to server: No such file or directory",
|
|
2088
|
-
)),
|
|
2089
|
-
vec![],
|
|
2090
|
-
);
|
|
2091
|
-
assert_eq!(
|
|
2092
|
-
be.liveness(&PaneId::new("%7")).expect("liveness"),
|
|
2093
|
-
PaneLiveness::Unknown,
|
|
2094
|
-
"a NON-'can't find' failure is UNKNOWN, not DEAD (ยงbug-085 three-state)"
|
|
2095
|
-
);
|
|
2096
|
-
}
|
|
2097
|
-
|
|
2098
|
-
#[test]
|
|
2099
|
-
fn has_pane_is_direct_existence_probe_not_liveness_guess() {
|
|
2100
|
-
let (be, rec) = backend_with(MockResp::Out(ok("%7")), vec![]);
|
|
2101
|
-
assert_eq!(
|
|
2102
|
-
be.has_pane(&PaneId::new("%7")).expect("has_pane"),
|
|
2103
|
-
Some(true)
|
|
2104
|
-
);
|
|
2105
|
-
let argv0 = rec.lock().unwrap()[0].clone();
|
|
2106
|
-
assert!(
|
|
2107
|
-
argv0.contains(&"display-message".to_string())
|
|
2108
|
-
&& argv0.iter().any(|x| x.contains("#{pane_id}"))
|
|
2109
|
-
&& argv0.contains(&"%7".to_string()),
|
|
2110
|
-
"has_pane must use the cheap display-message #{{pane_id}} probe; got {argv0:?}"
|
|
2111
|
-
);
|
|
2112
|
-
|
|
2113
|
-
let (be, _r) = backend_with(MockResp::Out(ok("")), vec![]);
|
|
2114
|
-
assert_eq!(
|
|
2115
|
-
be.has_pane(&PaneId::new("%9999")).expect("has_pane"),
|
|
2116
|
-
Some(false),
|
|
2117
|
-
"real tmux can report a missing pane as exit 0 with empty stdout"
|
|
2118
|
-
);
|
|
2119
|
-
|
|
2120
|
-
let (be, _r) = backend_with(MockResp::Out(fail(1, "can't find pane: %9999")), vec![]);
|
|
2121
|
-
assert_eq!(
|
|
2122
|
-
be.has_pane(&PaneId::new("%9999")).expect("has_pane"),
|
|
2123
|
-
Some(false)
|
|
2124
|
-
);
|
|
2125
|
-
|
|
2126
|
-
let (be, _r) = backend_with(MockResp::Out(ok("%8")), vec![]);
|
|
2127
|
-
assert_eq!(
|
|
2128
|
-
be.has_pane(&PaneId::new("%7")).expect("has_pane"),
|
|
2129
|
-
None,
|
|
2130
|
-
"a successful but mismatched pane id is not proof that the requested pane exists"
|
|
2131
|
-
);
|
|
2132
|
-
|
|
2133
|
-
let (be, _r) = backend_with(MockResp::Out(ok("not-a-pane")), vec![]);
|
|
2134
|
-
assert_eq!(
|
|
2135
|
-
be.has_pane(&PaneId::new("%7")).expect("has_pane"),
|
|
2136
|
-
None,
|
|
2137
|
-
"a successful but invalid pane id stays Unknown"
|
|
2138
|
-
);
|
|
2139
|
-
|
|
2140
|
-
let (be, _r) = backend_with(
|
|
2141
|
-
MockResp::Out(fail(
|
|
2142
|
-
1,
|
|
2143
|
-
"error connecting to server: No such file or directory",
|
|
2144
|
-
)),
|
|
2145
|
-
vec![],
|
|
2146
|
-
);
|
|
2147
|
-
assert_eq!(
|
|
2148
|
-
be.has_pane(&PaneId::new("%7")).expect("has_pane"),
|
|
2149
|
-
None,
|
|
2150
|
-
"server/probe errors remain Unknown, not absent"
|
|
2151
|
-
);
|
|
2152
|
-
}
|
|
2153
|
-
|
|
2154
|
-
// โโ CP-1: per-team socket โ for_workspace injects `-L ta-<hash>` at the run chokepoint; new() does NOT โ
|
|
2155
|
-
#[test]
|
|
2156
|
-
fn for_workspace_backend_injects_per_team_socket_but_default_backend_does_not() {
|
|
2157
|
-
use super::socket_name_for_workspace;
|
|
2158
|
-
let ws = Path::new("/tmp/ta-cp1-socket-test-ws");
|
|
2159
|
-
let socket = socket_name_for_workspace(ws);
|
|
2160
|
-
assert!(
|
|
2161
|
-
socket.starts_with("ta-") && socket.len() == 15,
|
|
2162
|
-
"socket name must be short + deterministic `ta-<12 hex>`; got {socket:?}"
|
|
2163
|
-
);
|
|
2164
|
-
// deterministic: the SAME workspace path always derives the SAME socket (CLI == daemon == ops).
|
|
2165
|
-
assert_eq!(
|
|
2166
|
-
socket,
|
|
2167
|
-
socket_name_for_workspace(ws),
|
|
2168
|
-
"socket derivation must be deterministic"
|
|
2169
|
-
);
|
|
2170
|
-
|
|
2171
|
-
// workspace-bound backend: every executed `tmux` argv gets `-L <socket>` after the leading token.
|
|
2172
|
-
let recorded = Arc::new(Mutex::new(Vec::new()));
|
|
2173
|
-
let runner = MockCommandRunner {
|
|
2174
|
-
recorded: Arc::clone(&recorded),
|
|
2175
|
-
stdin_recorded: Arc::new(Mutex::new(Vec::new())),
|
|
2176
|
-
queue: Mutex::new(VecDeque::new()),
|
|
2177
|
-
default: MockResp::Out(ok("")),
|
|
2178
|
-
};
|
|
2179
|
-
let be = TmuxBackend::with_runner_for_workspace(Box::new(runner), ws);
|
|
2180
|
-
be.has_session(&SessionName::new("sess"))
|
|
2181
|
-
.expect("has_session");
|
|
2182
|
-
let argv = recorded.lock().unwrap()[0].clone();
|
|
2183
|
-
assert_eq!(
|
|
2184
|
-
argv,
|
|
2185
|
-
svec(&["tmux", "-L", &socket, "has-session", "-t", "sess"]),
|
|
2186
|
-
"for_workspace backend must inject `-L <socket>` right after `tmux`; got {argv:?}"
|
|
2187
|
-
);
|
|
2188
|
-
|
|
2189
|
-
// default backend (new()/with_runner): NO `-L` โ argv stays the golden-locked builder form.
|
|
2190
|
-
let (be, rec) = backend_with(MockResp::Out(ok("")), vec![]);
|
|
2191
|
-
be.has_session(&SessionName::new("sess"))
|
|
2192
|
-
.expect("has_session");
|
|
2193
|
-
assert_eq!(
|
|
2194
|
-
rec.lock().unwrap()[0],
|
|
2195
|
-
svec(&["tmux", "has-session", "-t", "sess"]),
|
|
2196
|
-
"the default-socket backend must NOT inject `-L` (existing tests + non-team callers unaffected)"
|
|
2197
|
-
);
|
|
2198
|
-
}
|
|
2199
|
-
|
|
2200
|
-
// โโ 7. kill_session / kill_window: golden argv; success -> Ok(()) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
2201
|
-
#[test]
|
|
2202
|
-
fn kill_session_and_kill_window_argv() {
|
|
2203
|
-
let (be, rec) = backend_with(MockResp::Out(ok("")), vec![]);
|
|
2204
|
-
be.kill_session(&SessionName::new("sess"))
|
|
2205
|
-
.expect("kill_session");
|
|
2206
|
-
assert_eq!(
|
|
2207
|
-
rec.lock().unwrap()[0],
|
|
2208
|
-
svec(&["tmux", "kill-session", "-t", "sess"])
|
|
2209
|
-
);
|
|
2210
|
-
|
|
2211
|
-
let (be, rec) = backend_with(MockResp::Out(ok("")), vec![]);
|
|
2212
|
-
be.kill_window(&Target::Pane(PaneId::new("%7")))
|
|
2213
|
-
.expect("kill_window");
|
|
2214
|
-
assert_eq!(
|
|
2215
|
-
rec.lock().unwrap()[0],
|
|
2216
|
-
svec(&["tmux", "kill-window", "-t", "%7"])
|
|
2217
|
-
);
|
|
2218
|
-
}
|
|
2219
|
-
|
|
2220
|
-
#[test]
|
|
2221
|
-
fn issue336_session_listing_accepts_tab_and_literal_escape_without_rewriting_names() {
|
|
2222
|
-
for separator in ["\t", "\\t"] {
|
|
2223
|
-
let (backend, calls) = backend_with(
|
|
2224
|
-
MockResp::Out(ok("")),
|
|
2225
|
-
vec![
|
|
2226
|
-
MockResp::Out(ok(&format!("%7{separator}worker\\tname\n"))),
|
|
2227
|
-
MockResp::Out(ok("%8\n")),
|
|
2228
|
-
],
|
|
2229
|
-
);
|
|
2230
|
-
backend.preserve_session_before_stop(
|
|
2231
|
-
&SessionName::new("sess"),
|
|
2232
|
-
&[Target::SessionWindow {
|
|
2233
|
-
session: SessionName::new("sess"),
|
|
2234
|
-
window: WindowName::new("worker\\tname"),
|
|
2235
|
-
}],
|
|
2236
|
-
).unwrap();
|
|
2237
|
-
assert_eq!(calls.lock().unwrap().len(), 4, "separator={separator:?}");
|
|
2238
|
-
}
|
|
2239
|
-
}
|
|
2240
|
-
|
|
2241
|
-
#[test]
|
|
2242
|
-
fn issue336_escaped_listing_keeps_survivors_and_malformed_rows_fail_closed() {
|
|
2243
|
-
let (backend, calls) = backend_with(MockResp::Out(ok("%7\\tworker\n%8\\tleader\n")), vec![]);
|
|
2244
|
-
backend.preserve_session_before_stop(
|
|
2245
|
-
&SessionName::new("sess"), &[Target::Pane(PaneId::new("%7"))],
|
|
2246
|
-
).unwrap();
|
|
2247
|
-
assert_eq!(calls.lock().unwrap().len(), 1);
|
|
2248
|
-
for row in ["%7 worker", "%7", ""] {
|
|
2249
|
-
let (backend, calls) = backend_with(MockResp::Out(ok(row)), vec![]);
|
|
2250
|
-
assert!(backend.preserve_session_before_stop(
|
|
2251
|
-
&SessionName::new("sess"), &[Target::Pane(PaneId::new("%7"))],
|
|
2252
|
-
).is_err());
|
|
2253
|
-
assert_eq!(calls.lock().unwrap().len(), 1);
|
|
2254
|
-
}
|
|
2255
|
-
}
|
|
2256
|
-
|
|
2257
|
-
#[test]
|
|
2258
|
-
fn stop_session_preservation_creates_processless_anchor_by_exact_pane_id() {
|
|
2259
|
-
let (be, rec) = backend_with(
|
|
2260
|
-
MockResp::Out(ok("")),
|
|
2261
|
-
vec![MockResp::Out(ok("%7\tworker\n")), MockResp::Out(ok("%8\n"))],
|
|
2262
|
-
);
|
|
2263
|
-
be.preserve_session_before_stop(
|
|
2264
|
-
&SessionName::new("sess"),
|
|
2265
|
-
&[Target::Pane(PaneId::new("%7"))],
|
|
2266
|
-
).unwrap();
|
|
2267
|
-
let calls = rec.lock().unwrap();
|
|
2268
|
-
assert_eq!(calls.len(), 4);
|
|
2269
|
-
assert_eq!(calls[0], svec(&[
|
|
2270
|
-
"tmux", "list-panes", "-s", "-t", "=sess", "-F", "#{pane_id}\t#{window_name}",
|
|
2271
|
-
]));
|
|
2272
|
-
assert_eq!(calls[1], tmux_spawn_argv(
|
|
2273
|
-
&SessionName::new("=sess"), &WindowName::new("[team-agent keepalive]"),
|
|
2274
|
-
"exec sleep 86400", false,
|
|
2275
|
-
));
|
|
2276
|
-
assert_eq!(calls[2], svec(&[
|
|
2277
|
-
"tmux", "set-window-option", "-t", "%8", "remain-on-exit", "on",
|
|
2278
|
-
]));
|
|
2279
|
-
assert_eq!(calls[3], svec(&["tmux", "respawn-pane", "-k", "-t", "%8", "exit 0"]));
|
|
2280
|
-
}
|
|
2281
|
-
|
|
2282
|
-
#[test]
|
|
2283
|
-
fn stop_session_preservation_skips_surviving_workers_leaders_and_anchors() {
|
|
2284
|
-
for survivor in ["other-worker", "leader", "[team-agent keepalive]", "worker"] {
|
|
2285
|
-
let (be, rec) = backend_with(
|
|
2286
|
-
MockResp::Out(ok(&format!("%7\tworker\n%8\t{survivor}\n"))), vec![],
|
|
2287
|
-
);
|
|
2288
|
-
be.preserve_session_before_stop(
|
|
2289
|
-
&SessionName::new("sess"), &[Target::Pane(PaneId::new("%7"))],
|
|
2290
|
-
).unwrap();
|
|
2291
|
-
assert_eq!(rec.lock().unwrap().len(), 1, "survivor={survivor}");
|
|
2292
|
-
}
|
|
2293
|
-
}
|
|
2294
|
-
|
|
2295
|
-
#[test]
|
|
2296
|
-
fn stop_session_preservation_covers_duplicate_panes_and_legacy_window_targets() {
|
|
2297
|
-
for targets in [
|
|
2298
|
-
vec![Target::Pane(PaneId::new("%7")), Target::Pane(PaneId::new("%8"))],
|
|
2299
|
-
vec![Target::SessionWindow { session: SessionName::new("sess"), window: WindowName::new("worker") }],
|
|
2300
|
-
] {
|
|
2301
|
-
let (be, rec) = backend_with(MockResp::Out(ok("")), vec![
|
|
2302
|
-
MockResp::Out(ok("%7\tworker\n%8\tworker\n")), MockResp::Out(ok("%9\n")),
|
|
2303
|
-
]);
|
|
2304
|
-
be.preserve_session_before_stop(&SessionName::new("sess"), &targets).unwrap();
|
|
2305
|
-
assert_eq!(rec.lock().unwrap().len(), 4);
|
|
2306
|
-
}
|
|
2307
|
-
}
|
|
2308
|
-
|
|
2309
|
-
#[test]
|
|
2310
|
-
fn stop_session_preservation_refuses_unknown_listing_and_rolls_back_failed_anchor() {
|
|
2311
|
-
for response in [fail(1, "listing failed"), ok(""), ok("malformed")] {
|
|
2312
|
-
let (be, rec) = backend_with(MockResp::Out(response), vec![]);
|
|
2313
|
-
assert!(be.preserve_session_before_stop(
|
|
2314
|
-
&SessionName::new("sess"), &[Target::Pane(PaneId::new("%7"))],
|
|
2315
|
-
).is_err());
|
|
2316
|
-
assert_eq!(rec.lock().unwrap().len(), 1);
|
|
2317
|
-
}
|
|
2318
|
-
for failed_step in ["new-window", "set-window-option", "respawn-pane"] {
|
|
2319
|
-
let mut queued = vec![MockResp::Out(ok("%7\tworker\n"))];
|
|
2320
|
-
if failed_step != "new-window" { queued.push(MockResp::Out(ok("%8\n"))); }
|
|
2321
|
-
if failed_step == "respawn-pane" { queued.push(MockResp::Out(ok(""))); }
|
|
2322
|
-
queued.push(MockResp::Out(fail(1, "anchor failed")));
|
|
2323
|
-
let (be, rec) = backend_with(MockResp::Out(ok("")), queued);
|
|
2324
|
-
assert!(be.preserve_session_before_stop(
|
|
2325
|
-
&SessionName::new("sess"), &[Target::Pane(PaneId::new("%7"))],
|
|
2326
|
-
).is_err());
|
|
2327
|
-
let calls = rec.lock().unwrap();
|
|
2328
|
-
assert!(!calls.iter().any(|argv| argv.get(1).is_some_and(|op| op == "kill-window")));
|
|
2329
|
-
if failed_step != "new-window" {
|
|
2330
|
-
assert_eq!(calls.last().unwrap(), &svec(&["tmux", "kill-pane", "-t", "%8"]));
|
|
2331
|
-
}
|
|
2332
|
-
assert!(!calls.iter().any(|argv| argv.get(1).is_some_and(|op| op == "kill-pane") && argv.contains(&"%7".to_string())));
|
|
2333
|
-
}
|
|
2334
|
-
}
|
|
2335
|
-
|
|
2336
|
-
#[test]
|
|
2337
|
-
#[ignore = "isolated native tmux: executed explicitly on the remote test host"]
|
|
2338
|
-
fn stop_session_preservation_native_tmux_stop_start_and_shutdown() {
|
|
2339
|
-
let tmp = std::env::temp_dir().join(format!(
|
|
2340
|
-
"ta-preserve-{}-{}", std::process::id(), chrono::Utc::now().timestamp_nanos_opt().unwrap(),
|
|
2341
|
-
));
|
|
2342
|
-
std::fs::create_dir(&tmp).unwrap();
|
|
2343
|
-
let endpoint = tmp.join("tmux.sock");
|
|
2344
|
-
let be = TmuxBackend::with_runner_for_tmux_endpoint(Box::new(RealCommandRunner), endpoint.to_str().unwrap());
|
|
2345
|
-
let session = SessionName::new("preserve-test");
|
|
2346
|
-
struct Cleanup<'a>(&'a TmuxBackend, &'a SessionName, &'a Path);
|
|
2347
|
-
impl Drop for Cleanup<'_> {
|
|
2348
|
-
fn drop(&mut self) {
|
|
2349
|
-
let _ = self.0.kill_session(self.1);
|
|
2350
|
-
let _ = std::fs::remove_dir_all(self.2);
|
|
2351
|
-
}
|
|
2352
|
-
}
|
|
2353
|
-
let _cleanup = Cleanup(&be, &session, &tmp);
|
|
2354
|
-
let argv = svec(&["sleep", "86400"]);
|
|
2355
|
-
let env = BTreeMap::new();
|
|
2356
|
-
let mut worker = be.spawn_first(&session, &WindowName::new("worker"), &argv, &tmp, &env).unwrap();
|
|
2357
|
-
for _ in 0..3 {
|
|
2358
|
-
be.preserve_session_before_stop(&session, &[Target::Pane(worker.pane_id.clone())]).unwrap();
|
|
2359
|
-
be.kill_pane(&worker.pane_id).unwrap();
|
|
2360
|
-
assert!(be.has_session(&session).unwrap());
|
|
2361
|
-
assert_eq!(be.has_pane(&worker.pane_id).unwrap(), Some(false));
|
|
2362
|
-
assert_eq!(be.list_windows(&session).unwrap(), vec![WindowName::new("[team-agent keepalive]")]);
|
|
2363
|
-
let anchor = be.list_targets().unwrap().into_iter().find(|pane| pane.session == session).unwrap();
|
|
2364
|
-
let deadline = Instant::now() + Duration::from_secs(2);
|
|
2365
|
-
loop {
|
|
2366
|
-
let dead = be.runner.run(&be.tmux_argv(&svec(&[
|
|
2367
|
-
"tmux", "display-message", "-p", "-t", anchor.pane_id.as_str(), "#{pane_dead}",
|
|
2368
|
-
]))).unwrap();
|
|
2369
|
-
if dead.success && dead.stdout.trim() == "1" { break; }
|
|
2370
|
-
assert!(Instant::now() < deadline, "keepalive must have no running process: {dead:?}");
|
|
2371
|
-
std::thread::sleep(Duration::from_millis(20));
|
|
2372
|
-
}
|
|
2373
|
-
worker = be.spawn_into(&session, &WindowName::new("worker"), &argv, &tmp, &env).unwrap();
|
|
2374
|
-
}
|
|
2375
|
-
be.kill_session(&session).unwrap();
|
|
2376
|
-
assert!(!be.has_session(&session).unwrap());
|
|
2377
|
-
}
|
|
2378
|
-
|
|
2379
|
-
// โโ 8. ERROR MAPPING: non-zero tmux exit -> TransportError::Subprocess; runner io::Error -> Err โโ
|
|
2380
|
-
#[test]
|
|
2381
|
-
fn error_paths_map_to_transport_error_not_panic() {
|
|
2382
|
-
// tmux cli non-zero exit (the Subprocess variant's documented purpose).
|
|
2383
|
-
let (be, _r) = backend_with(
|
|
2384
|
-
MockResp::Out(fail(1, "no server running on /tmp/tmux-x/default")),
|
|
2385
|
-
vec![],
|
|
2386
|
-
);
|
|
2387
|
-
let err = be
|
|
2388
|
-
.kill_session(&SessionName::new("sess"))
|
|
2389
|
-
.expect_err("kill_session must error on non-zero exit");
|
|
2390
|
-
assert!(
|
|
2391
|
-
matches!(err, TransportError::Subprocess { code: Some(1), .. }),
|
|
2392
|
-
"a non-zero tmux exit must map to TransportError::Subprocess{{code,stderr}}; got {err:?}"
|
|
2393
|
-
);
|
|
2394
|
-
|
|
2395
|
-
// a runner io::Error (e.g. tmux not on PATH) must surface as a TransportError, never a panic.
|
|
2396
|
-
let (be, _r) = backend_with(MockResp::Io(std::io::ErrorKind::NotFound), vec![]);
|
|
2397
|
-
let err = be
|
|
2398
|
-
.capture(&Target::Pane(PaneId::new("%7")), CaptureRange::Full)
|
|
2399
|
-
.expect_err("capture must surface the runner io error");
|
|
2400
|
-
assert!(
|
|
2401
|
-
matches!(err, TransportError::Capture { .. } | TransportError::Io(_)),
|
|
2402
|
-
"a runner io error must map to a TransportError (not panic); got {err:?}"
|
|
2403
|
-
);
|
|
2404
|
-
}
|
|
2405
|
-
|
|
2406
|
-
// โโ 9. RealCommandRunner GOLDEN 5s TIMEOUT (rt-host-b transient-session race) โโโโโโโโโโโโโโโโโโโโ
|
|
2407
|
-
// GOLDEN: terminal.py:12-13 `run_cmd(args, timeout=timeout, check=False)`; runtime.py:1010-1014
|
|
2408
|
-
// `_tmux_session_exists` runs `tmux has-session -t <s>` with timeout=5. A has-session that outlives
|
|
2409
|
-
// 5s raises `subprocess.TimeoutExpired`, which the coordinator daemon CATCHES
|
|
2410
|
-
// (coordinator/__main__.py:60-90 `except Exception`) and treats as a TOLERATED transient
|
|
2411
|
-
// (exponential backoff + retry next tick) โ it is NEVER read as a definitive "session gone".
|
|
2412
|
-
// The 5s subprocess timeout is golden's ONLY tolerance for a slow/hung probe.
|
|
2413
|
-
//
|
|
2414
|
-
// RUST GAP (THE BUG): `RealCommandRunner::run` (tmux_backend.rs:52) calls
|
|
2415
|
-
// `std::process::Command::output()` with NO timeout, so a slow/hung tmux blocks indefinitely.
|
|
2416
|
-
// On the (slow) mac mini this is the ~17% single-round-trip flake: a transient slow has-session
|
|
2417
|
-
// tears down a healthy team. This is rt-host-b's deterministic 5/5 anchor โ `run` on a HUNG
|
|
2418
|
-
// command must abandon at the golden 5s and surface `Err(TimedOut)`, NOT block on the full
|
|
2419
|
-
// subprocess.
|
|
2420
|
-
//
|
|
2421
|
-
// RED today: there is no timeout, so `run(["sleep","30"])` blocks ~30s and the `< 6s` bound fails.
|
|
2422
|
-
// #[ignore] real-machine: this is the only test here that spawns a real subprocess.
|
|
2423
|
-
// PORTER SEAM: add a 5s timeout inside `RealCommandRunner::run` (spawn child + wait-with-timeout
|
|
2424
|
-
// via a thread/channel + kill the child on expiry), returning `Err(io::Error, kind TimedOut)` โ
|
|
2425
|
-
// NO new crate dependency. Keep the existing `CommandRunner::run(&[String]) -> Result<โฆ, io::Error>`
|
|
2426
|
-
// signature (the timeout is internal; do not add a parameter).
|
|
2427
|
-
#[test]
|
|
2428
|
-
#[ignore = "real-machine: spawns a real sleeping subprocess; asserts RealCommandRunner enforces \
|
|
2429
|
-
the golden 5s timeout (terminal.py run_cmd timeout / runtime.py:1013 \
|
|
2430
|
-
_tmux_session_exists timeout=5)"]
|
|
2431
|
-
fn real_command_runner_enforces_golden_5s_timeout_on_hang() {
|
|
2432
|
-
use std::time::{Duration, Instant};
|
|
2433
|
-
let runner = RealCommandRunner;
|
|
2434
|
-
let started = Instant::now();
|
|
2435
|
-
let result = runner.run(&svec(&["sleep", "30"]));
|
|
2436
|
-
let elapsed = started.elapsed();
|
|
2437
|
-
assert!(
|
|
2438
|
-
elapsed < Duration::from_secs(6),
|
|
2439
|
-
"RealCommandRunner::run must abandon a hung command at the golden 5s timeout, not block on \
|
|
2440
|
-
the full subprocess (terminal.py run_cmd timeout / runtime.py:1013 timeout=5); blocked {elapsed:?}"
|
|
2441
|
-
);
|
|
2442
|
-
let err = result.expect_err(
|
|
2443
|
-
"a command outliving the 5s timeout must surface as Err (subprocess.TimeoutExpired analog) so \
|
|
2444
|
-
the daemon backoff path tolerates it, instead of yielding a bogus has-session bool",
|
|
2445
|
-
);
|
|
2446
|
-
assert_eq!(
|
|
2447
|
-
err.kind(),
|
|
2448
|
-
std::io::ErrorKind::TimedOut,
|
|
2449
|
-
"the timeout must be io::ErrorKind::TimedOut (golden: TimeoutExpired -> daemon except -> backoff/retry)"
|
|
2450
|
-
);
|
|
2451
|
-
}
|
|
2452
|
-
|
|
2453
|
-
// โโ 10. query (TRANSPORT TRIO) โ single-field display-message; nonzero -> None โโโโโโโโโโโโโโโโโโ
|
|
2454
|
-
// Golden _legacy_pane_discovery.py:35-39 _tmux_pane_info: `tmux display-message -p -t <target> -F
|
|
2455
|
-
// <fmt>` (returncode != 0 -> None), single-field reads at state.py:346 (#{pane_id}) / delivery.py:34
|
|
2456
|
-
// (#{pane_width}). The argv is exactly `transport::tmux_query_argv(pane, field)` (the golden-locked
|
|
2457
|
-
// builder). RED today: `query` is unimplemented!() -> PANIC. Porter: pane_from_target(target) ->
|
|
2458
|
-
// tmux_query_argv -> run; success => Some(stdout.trim()); nonzero => None (never Err).
|
|
2459
|
-
#[test]
|
|
2460
|
-
fn query_single_field_argv_and_nonzero_maps_to_none() {
|
|
2461
|
-
// PaneId field: argv == the golden builder; present value parsed (trimmed) into Some.
|
|
2462
|
-
let (be, rec) = backend_with(MockResp::Out(ok("%7\n")), vec![]);
|
|
2463
|
-
let got = be
|
|
2464
|
-
.query(&Target::Pane(PaneId::new("%7")), PaneField::PaneId)
|
|
2465
|
-
.expect("query ok");
|
|
2466
|
-
assert_eq!(
|
|
2467
|
-
rec.lock().unwrap()[0],
|
|
2468
|
-
tmux_query_argv(&PaneId::new("%7"), PaneField::PaneId),
|
|
2469
|
-
"query must build the golden single-field `display-message -p -t <t> -F #{{pane_id}}` argv"
|
|
2470
|
-
);
|
|
2471
|
-
assert_eq!(
|
|
2472
|
-
got,
|
|
2473
|
-
Some("%7".to_string()),
|
|
2474
|
-
"a present field value is parsed (stripped) into Some"
|
|
2475
|
-
);
|
|
2476
|
-
|
|
2477
|
-
// PaneWidth uses -F too; lock argv + the parsed numeric-as-string field.
|
|
2478
|
-
let (be, rec) = backend_with(MockResp::Out(ok("180\n")), vec![]);
|
|
2479
|
-
let got = be
|
|
2480
|
-
.query(&Target::Pane(PaneId::new("%7")), PaneField::PaneWidth)
|
|
2481
|
-
.expect("query ok");
|
|
2482
|
-
assert_eq!(
|
|
2483
|
-
rec.lock().unwrap()[0],
|
|
2484
|
-
tmux_query_argv(&PaneId::new("%7"), PaneField::PaneWidth)
|
|
2485
|
-
);
|
|
2486
|
-
assert_eq!(got, Some("180".to_string()));
|
|
2487
|
-
|
|
2488
|
-
// nonzero exit (pane gone) -> None, NOT an Err (golden _tmux_pane_info: returncode != 0 -> None).
|
|
2489
|
-
let (be, _r) = backend_with(MockResp::Out(fail(1, "can't find pane %7")), vec![]);
|
|
2490
|
-
assert_eq!(
|
|
2491
|
-
be.query(&Target::Pane(PaneId::new("%7")), PaneField::PaneId)
|
|
2492
|
-
.expect("query ok on nonzero"),
|
|
2493
|
-
None,
|
|
2494
|
-
"a nonzero / pane-gone query must map to None (not Err)"
|
|
2495
|
-
);
|
|
2496
|
-
}
|
|
2497
|
-
|
|
2498
|
-
// โโ 11. list_targets (TRANSPORT TRIO) โ `list-panes -a -F TMUX_PANE_FORMAT` + per-line parse โโโโ
|
|
2499
|
-
// Golden _legacy_pane_discovery.py:29-33 _tmux_list_panes: `tmux list-panes -a -F <TMUX_PANE_FORMAT>`.
|
|
2500
|
-
// The Rust backend uses the printable separator locked below so the 12-field frame stays explicit
|
|
2501
|
-
// in argv/log evidence, while retaining the golden nonzero -> empty inventory behavior. P5 (C-P5-3) appends
|
|
2502
|
-
// `#{pane_pid}` as field 12 so pane pids ride the single list-panes call (the per-pane
|
|
2503
|
-
// display-message N+1 fallback is gone). leader_env stays the reverse-env real-machine bit.
|
|
2504
|
-
#[test]
|
|
2505
|
-
fn list_targets_argv_and_parses_tmux_pane_format() {
|
|
2506
|
-
const FMT: &str = "#{pane_id}__TA_FIELD__#{session_name}__TA_FIELD__#{window_index}__TA_FIELD__#{window_name}__TA_FIELD__#{pane_index}__TA_FIELD__#{pane_tty}__TA_FIELD__#{pane_current_command}__TA_FIELD__#{pane_active}__TA_FIELD__#{pane_current_path}__TA_FIELD__#{session_attached}__TA_FIELD__#{pane_in_mode}__TA_FIELD__#{pane_pid}__TA_FIELD__#{@team_agent_pane_binding_nonce}";
|
|
2507
|
-
let stdout = "%7__TA_FIELD__team-x__TA_FIELD__0__TA_FIELD__win0__TA_FIELD__0__TA_FIELD__/dev/ttys003__TA_FIELD__codex__TA_FIELD__1__TA_FIELD__/Users/me/work__TA_FIELD__1__TA_FIELD__0__TA_FIELD__41001__TA_FIELD__nonce-7\n\
|
|
2508
|
-
%8__TA_FIELD__team-x__TA_FIELD__1__TA_FIELD__win1__TA_FIELD__0__TA_FIELD__/dev/ttys004__TA_FIELD__node__TA_FIELD__0__TA_FIELD__/Users/me/other__TA_FIELD__0__TA_FIELD__0__TA_FIELD__41002__TA_FIELD__\n";
|
|
2509
|
-
let (be, rec) = backend_with(MockResp::Out(ok(stdout)), vec![]);
|
|
2510
|
-
let panes = be.list_targets().expect("list_targets ok");
|
|
2511
|
-
assert_eq!(
|
|
2512
|
-
rec.lock().unwrap()[0],
|
|
2513
|
-
svec(&["tmux", "list-panes", "-a", "-F", FMT]),
|
|
2514
|
-
"list_targets must run `tmux list-panes -a -F <TMUX_PANE_FORMAT>` (golden _legacy_pane_discovery.py:29)"
|
|
2515
|
-
);
|
|
2516
|
-
assert_eq!(panes.len(), 2, "one PaneInfo per output line");
|
|
2517
|
-
let p = &panes[0];
|
|
2518
|
-
assert_eq!(p.pane_id.as_str(), "%7", "field[0] -> pane_id");
|
|
2519
|
-
assert_eq!(p.session.as_str(), "team-x", "field[1] -> session_name");
|
|
2520
|
-
assert_eq!(
|
|
2521
|
-
p.window_index,
|
|
2522
|
-
Some(0),
|
|
2523
|
-
"field[2] -> window_index (parsed u32)"
|
|
2524
|
-
);
|
|
2525
|
-
assert_eq!(
|
|
2526
|
-
p.window_name.as_ref().map(|w| w.as_str().to_string()),
|
|
2527
|
-
Some("win0".to_string()),
|
|
2528
|
-
"field[3] -> window_name"
|
|
2529
|
-
);
|
|
2530
|
-
assert_eq!(p.pane_index, Some(0), "field[4] -> pane_index (parsed u32)");
|
|
2531
|
-
assert_eq!(
|
|
2532
|
-
p.tty.as_deref(),
|
|
2533
|
-
Some("/dev/ttys003"),
|
|
2534
|
-
"field[5] -> pane_tty"
|
|
2535
|
-
);
|
|
2536
|
-
assert_eq!(
|
|
2537
|
-
p.current_command.as_deref(),
|
|
2538
|
-
Some("codex"),
|
|
2539
|
-
"field[6] -> pane_current_command"
|
|
2540
|
-
);
|
|
2541
|
-
assert!(p.active, "field[7] pane_active='1' -> active=true");
|
|
2542
|
-
assert_eq!(
|
|
2543
|
-
p.current_path
|
|
2544
|
-
.as_ref()
|
|
2545
|
-
.map(|x| x.to_string_lossy().to_string()),
|
|
2546
|
-
Some("/Users/me/work".to_string()),
|
|
2547
|
-
"field[8] -> pane_current_path"
|
|
2548
|
-
);
|
|
2549
|
-
assert!(!panes[1].active, "field[7] pane_active='0' -> active=false");
|
|
2550
|
-
assert_eq!(
|
|
2551
|
-
p.pane_pid,
|
|
2552
|
-
Some(41001),
|
|
2553
|
-
"field[11] -> pane_pid (P5 C-P5-3, no N+1 fallback)"
|
|
2554
|
-
);
|
|
2555
|
-
assert_eq!(
|
|
2556
|
-
panes[1].pane_pid,
|
|
2557
|
-
Some(41002),
|
|
2558
|
-
"field[11] -> pane_pid (second pane)"
|
|
2559
|
-
);
|
|
2560
|
-
assert_eq!(
|
|
2561
|
-
p.leader_env
|
|
2562
|
-
.get(PANE_BINDING_NONCE_METADATA_KEY)
|
|
2563
|
-
.map(String::as_str),
|
|
2564
|
-
Some("nonce-7"),
|
|
2565
|
-
"field[12] pane option -> pane-instance binding metadata"
|
|
2566
|
-
);
|
|
2567
|
-
assert!(
|
|
2568
|
-
!panes[1]
|
|
2569
|
-
.leader_env
|
|
2570
|
-
.contains_key(PANE_BINDING_NONCE_METADATA_KEY),
|
|
2571
|
-
"an empty pane option must remain absent"
|
|
2572
|
-
);
|
|
2573
|
-
|
|
2574
|
-
// nonzero exit -> empty vec (golden returncode != 0 -> []).
|
|
2575
|
-
let (be, _r) = backend_with(
|
|
2576
|
-
MockResp::Out(fail(1, "no server running on /tmp/tmux-x/default")),
|
|
2577
|
-
vec![],
|
|
2578
|
-
);
|
|
2579
|
-
assert!(
|
|
2580
|
-
be.list_targets()
|
|
2581
|
-
.expect("list_targets ok on nonzero")
|
|
2582
|
-
.is_empty(),
|
|
2583
|
-
"a nonzero list-panes must map to an EMPTY Vec (not Err)"
|
|
2584
|
-
);
|
|
2585
|
-
}
|
|
2586
|
-
|
|
2587
|
-
#[test]
|
|
2588
|
-
fn set_pane_binding_nonce_is_socket_scoped_and_pane_local() {
|
|
2589
|
-
let rec = Arc::new(Mutex::new(Vec::new()));
|
|
2590
|
-
let runner = MockCommandRunner {
|
|
2591
|
-
recorded: Arc::clone(&rec),
|
|
2592
|
-
stdin_recorded: Arc::new(Mutex::new(Vec::new())),
|
|
2593
|
-
queue: Mutex::new(VecDeque::new()),
|
|
2594
|
-
default: MockResp::Out(ok("")),
|
|
2595
|
-
};
|
|
2596
|
-
let be =
|
|
2597
|
-
TmuxBackend::with_runner_for_tmux_endpoint(Box::new(runner), "/tmp/ta-pane-binding.sock");
|
|
2598
|
-
be.set_pane_binding_nonce(&PaneId::new("%7"), "nonce-7")
|
|
2599
|
-
.expect("set pane binding nonce");
|
|
2600
|
-
assert_eq!(
|
|
2601
|
-
rec.lock().unwrap()[0],
|
|
2602
|
-
svec(&[
|
|
2603
|
-
"tmux",
|
|
2604
|
-
"-S",
|
|
2605
|
-
"/tmp/ta-pane-binding.sock",
|
|
2606
|
-
"set-option",
|
|
2607
|
-
"-p",
|
|
2608
|
-
"-t",
|
|
2609
|
-
"%7",
|
|
2610
|
-
"@team_agent_pane_binding_nonce",
|
|
2611
|
-
"nonce-7",
|
|
2612
|
-
])
|
|
2613
|
-
);
|
|
2614
|
-
}
|
|
2615
|
-
|
|
2616
|
-
#[test]
|
|
2617
|
-
fn set_pane_binding_nonce_if_unset_reads_existing_winner() {
|
|
2618
|
-
let rec = Arc::new(Mutex::new(Vec::new()));
|
|
2619
|
-
let runner = MockCommandRunner {
|
|
2620
|
-
recorded: Arc::clone(&rec),
|
|
2621
|
-
stdin_recorded: Arc::new(Mutex::new(Vec::new())),
|
|
2622
|
-
queue: Mutex::new(
|
|
2623
|
-
vec![
|
|
2624
|
-
MockResp::Out(fail(1, "already set: @team_agent_pane_binding_nonce")),
|
|
2625
|
-
MockResp::Out(ok("winner-nonce\n")),
|
|
2626
|
-
]
|
|
2627
|
-
.into_iter()
|
|
2628
|
-
.collect(),
|
|
2629
|
-
),
|
|
2630
|
-
default: MockResp::Out(ok("")),
|
|
2631
|
-
};
|
|
2632
|
-
let be =
|
|
2633
|
-
TmuxBackend::with_runner_for_tmux_endpoint(Box::new(runner), "/tmp/ta-pane-binding.sock");
|
|
2634
|
-
assert_eq!(
|
|
2635
|
-
be.set_pane_binding_nonce_if_unset(&PaneId::new("%7"), "loser-nonce")
|
|
2636
|
-
.expect("read the conditional-write winner"),
|
|
2637
|
-
"winner-nonce"
|
|
2638
|
-
);
|
|
2639
|
-
assert_eq!(
|
|
2640
|
-
rec.lock().unwrap().as_slice(),
|
|
2641
|
-
vec![
|
|
2642
|
-
svec(&[
|
|
2643
|
-
"tmux",
|
|
2644
|
-
"-S",
|
|
2645
|
-
"/tmp/ta-pane-binding.sock",
|
|
2646
|
-
"set-option",
|
|
2647
|
-
"-p",
|
|
2648
|
-
"-o",
|
|
2649
|
-
"-t",
|
|
2650
|
-
"%7",
|
|
2651
|
-
"@team_agent_pane_binding_nonce",
|
|
2652
|
-
"loser-nonce",
|
|
2653
|
-
]),
|
|
2654
|
-
svec(&[
|
|
2655
|
-
"tmux",
|
|
2656
|
-
"-S",
|
|
2657
|
-
"/tmp/ta-pane-binding.sock",
|
|
2658
|
-
"show-options",
|
|
2659
|
-
"-p",
|
|
2660
|
-
"-v",
|
|
2661
|
-
"-t",
|
|
2662
|
-
"%7",
|
|
2663
|
-
"@team_agent_pane_binding_nonce",
|
|
2664
|
-
]),
|
|
2665
|
-
]
|
|
2666
|
-
);
|
|
2667
|
-
}
|
|
2668
|
-
|
|
2669
|
-
#[test]
|
|
2670
|
-
fn set_pane_binding_nonce_if_unset_rejects_write_or_read_failure() {
|
|
2671
|
-
let (be, _rec) = backend_with(
|
|
2672
|
-
MockResp::Out(fail(1, "already set: @team_agent_pane_binding_nonce")),
|
|
2673
|
-
vec![MockResp::Out(fail(1, "pane disappeared"))],
|
|
2674
|
-
);
|
|
2675
|
-
assert!(be
|
|
2676
|
-
.set_pane_binding_nonce_if_unset(&PaneId::new("%7"), "nonce-7")
|
|
2677
|
-
.is_err());
|
|
2678
|
-
}
|
|
2679
|
-
|
|
2680
|
-
// โโ 12. attach_session (TRANSPORT TRIO) โ `tmux attach-session -t <s>` -> Attached โโโโโโโโโโโโโโ
|
|
2681
|
-
// Golden tmux attach is `tmux attach-session -t <session>`; a successful attach -> AttachOutcome::
|
|
2682
|
-
// Attached. RED today: attach_session is unimplemented!() -> PANIC. The in-process lock asserts the
|
|
2683
|
-
// argv + outcome via the recording runner; the REAL attach is interactive (takes over the terminal)
|
|
2684
|
-
// โ that is the real-machine boundary, not unit-testable.
|
|
2685
|
-
#[test]
|
|
2686
|
-
fn attach_session_argv_and_attached_outcome() {
|
|
2687
|
-
let (be, rec) = backend_with(MockResp::Out(ok("")), vec![]);
|
|
2688
|
-
let outcome = be
|
|
2689
|
-
.attach_session(&SessionName::new("sess"))
|
|
2690
|
-
.expect("attach ok");
|
|
2691
|
-
assert_eq!(
|
|
2692
|
-
rec.lock().unwrap()[0],
|
|
2693
|
-
svec(&["tmux", "attach-session", "-t", "sess"]),
|
|
2694
|
-
"attach_session must run `tmux attach-session -t <session>`"
|
|
2695
|
-
);
|
|
2696
|
-
assert_eq!(
|
|
2697
|
-
outcome,
|
|
2698
|
-
AttachOutcome::Attached,
|
|
2699
|
-
"a successful tmux attach -> AttachOutcome::Attached"
|
|
2700
|
-
);
|
|
2701
|
-
}
|
|
2702
|
-
|
|
2703
|
-
// โโ 13. TARGET-SCAN WIRING (a): list_targets is the LIVE pane-discovery primitive โโโโโโโโโโโโโโโ
|
|
2704
|
-
// WAVE-2 Lane C. `list_targets` (the `tmux list-panes -a` scan, locked argv/parse in test #11) has
|
|
2705
|
-
// ZERO production callers today โ it is dead code. Golden wires pane discovery on top of it: status
|
|
2706
|
-
// (_capture_missing_sessions / _tmux_session_exists, queries.py:46,52) and doctor (coordinator_health)
|
|
2707
|
-
// consume the live scan. The in-process wiring obligation is exercised at the status level by
|
|
2708
|
-
// cli::tests::status_tmux_session_present_uses_live_tmux_probe_not_is_some (RED). This #[ignore]
|
|
2709
|
-
// real-machine seam locks that a LIVE `list_targets` actually enumerates the running panes, proving
|
|
2710
|
-
// the primitive is usable by the status/doctor discovery the porter must wire.
|
|
2711
|
-
#[test]
|
|
2712
|
-
#[ignore = "real-machine: needs a live tmux server+session; asserts list_targets() (the dangling \
|
|
2713
|
-
pane-discovery primitive, zero production callers) enumerates live panes so status/doctor \
|
|
2714
|
-
discovery can consume it (golden _legacy_pane_discovery list-panes -a)"]
|
|
2715
|
-
fn list_targets_is_live_pane_discovery_primitive_for_status_doctor() {
|
|
2716
|
-
let be = TmuxBackend::with_runner(Box::new(RealCommandRunner));
|
|
2717
|
-
let panes = be.list_targets().expect("live list_targets must not error");
|
|
2718
|
-
assert!(
|
|
2719
|
-
!panes.is_empty(),
|
|
2720
|
-
"a live `tmux list-panes -a` must surface the running panes; status/doctor pane discovery \
|
|
2721
|
-
is wired on top of this scan (currently dead code โ zero production callers)"
|
|
2722
|
-
);
|
|
2723
|
-
}
|
|
2724
|
-
|
|
2725
|
-
// โโ 14. TARGET-SCAN WIRING (b): R1 โ caller_target.uuid is FIRST leader_session_uuid precedence โโ
|
|
2726
|
-
// WAVE-2 Lane C / wave2-laneB-rereview PROBE-D. When the caller-target scan lands, golden
|
|
2727
|
-
// claim_lease_no_incident threads `_target_leader_session_uuid(caller_target)` as the FIRST
|
|
2728
|
-
// leader_session_uuid precedence (leader/__init__.py:679-684): caller_target.uuid BEFORE
|
|
2729
|
-
// owner.uuid / receiver.uuid / derived. A DIFFERENT live pane reclaiming a DEAD owner must persist
|
|
2730
|
-
// the CALLER's uuid, not the dead owner's (PROBE-D: PY "NEWUUID" / RUST persists "OLD"). The
|
|
2731
|
-
// caller-target uuid is read from the caller pane's INJECTED TEAM_AGENT_LEADER_SESSION_UUID via a
|
|
2732
|
-
// per-pane env query (NOT a TMUX_PANE_FORMAT field), so the live scan is the dependency this seam
|
|
2733
|
-
// marks. SCOPE NOTE: the decisive IN-PROCESS claim-path R1 RED belongs in leader/tests.rs, which is
|
|
2734
|
-
// outside this task's (cli + tmux_backend) editor scope โ flagged to the leader for the
|
|
2735
|
-
// leader-contracts agent to graduate R1 to its own claim-path RED.
|
|
2736
|
-
#[test]
|
|
2737
|
-
#[ignore = "real-machine + SCOPE: R1 (PROBE-D) caller_target.uuid is FIRST leader_session_uuid \
|
|
2738
|
-
precedence (leader/__init__.py:679-684); the in-process claim-path assertion lives in \
|
|
2739
|
-
leader/tests.rs (out of cli+tmux_backend scope) โ this seam marks the live caller-target \
|
|
2740
|
-
env-scan dependency"]
|
|
2741
|
-
fn r1_caller_target_uuid_is_first_leader_session_uuid_precedence_seam() {
|
|
2742
|
-
// The caller-target scan (reading the caller pane's injected TEAM_AGENT_LEADER_SESSION_UUID)
|
|
2743
|
-
// is the live precursor to R1's uuid precedence. The full uuid-persistence assertion is the
|
|
2744
|
-
// leader claim path's obligation (see report). Here we only confirm the scan is reachable.
|
|
2745
|
-
let be = TmuxBackend::with_runner(Box::new(RealCommandRunner));
|
|
2746
|
-
let _panes = be
|
|
2747
|
-
.list_targets()
|
|
2748
|
-
.expect("live list_targets (caller-target scan precursor)");
|
|
2749
|
-
}
|
|
2750
|
-
|
|
2751
|
-
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
2752
|
-
// pasted-signal: ๆๅ ๅ ไฝ็ฌฆๆญฃไฟกๅท + token NeverSeen ไธๆ
|
|
2753
|
-
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
2754
|
-
|
|
2755
|
-
struct FoldedPasteRunner {
|
|
2756
|
-
recorded: RecordedArgv,
|
|
2757
|
-
pre_submit: String,
|
|
2758
|
-
post_submit: String,
|
|
2759
|
-
submitted: AtomicBool,
|
|
2760
|
-
}
|
|
2761
|
-
|
|
2762
|
-
impl CommandRunner for FoldedPasteRunner {
|
|
2763
|
-
fn run(&self, argv: &[String]) -> Result<CommandOutput, std::io::Error> {
|
|
2764
|
-
self.recorded.lock().unwrap().push(argv.to_vec());
|
|
2765
|
-
// ๆ้ๆไบค้ฎๆฏ C-m๏ผtmux_send_submit_argv๏ผ๏ผไธๆฏๅญ้ข้ Enterใ
|
|
2766
|
-
if argv.get(1).map(String::as_str) == Some("send-keys")
|
|
2767
|
-
&& argv.iter().any(|a| a == "C-m" || a == "Enter")
|
|
2768
|
-
{
|
|
2769
|
-
self.submitted.store(true, Ordering::SeqCst);
|
|
2770
|
-
}
|
|
2771
|
-
let stdout = match argv.get(1).map(String::as_str) {
|
|
2772
|
-
Some("capture-pane") => {
|
|
2773
|
-
if self.submitted.load(Ordering::SeqCst) {
|
|
2774
|
-
self.post_submit.clone()
|
|
2775
|
-
} else {
|
|
2776
|
-
self.pre_submit.clone()
|
|
2777
|
-
}
|
|
2778
|
-
}
|
|
2779
|
-
Some("display-message") => "0\n".to_string(),
|
|
2780
|
-
_ => String::new(),
|
|
2781
|
-
};
|
|
2782
|
-
Ok(ok(&stdout))
|
|
2783
|
-
}
|
|
2784
|
-
|
|
2785
|
-
fn run_with_stdin(
|
|
2786
|
-
&self,
|
|
2787
|
-
argv: &[String],
|
|
2788
|
-
_stdin: &str,
|
|
2789
|
-
) -> Result<CommandOutput, std::io::Error> {
|
|
2790
|
-
self.run(argv)
|
|
2791
|
-
}
|
|
2792
|
-
}
|
|
2793
|
-
|
|
2794
|
-
fn backend_folded(pre_submit: &str, post_submit: &str) -> (TmuxBackend, RecordedArgv) {
|
|
2795
|
-
let recorded = Arc::new(Mutex::new(Vec::new()));
|
|
2796
|
-
let runner = FoldedPasteRunner {
|
|
2797
|
-
recorded: Arc::clone(&recorded),
|
|
2798
|
-
pre_submit: pre_submit.to_string(),
|
|
2799
|
-
post_submit: post_submit.to_string(),
|
|
2800
|
-
submitted: AtomicBool::new(false),
|
|
2801
|
-
};
|
|
2802
|
-
(TmuxBackend::with_runner(Box::new(runner)), recorded)
|
|
2803
|
-
}
|
|
2804
|
-
|
|
2805
|
-
/// ไฟฎๅคๅๅฐบๅญ๏ผtoken ไธๅจๅบ้จ 15 ่ก โ consumedใๆๅ ๅ ไฝ็ฌฆไผๆไธญ่ฟๆกๆ็ใ
|
|
2806
|
-
fn unfixed_vacuous_consumed(text: &str, marker: &str) -> bool {
|
|
2807
|
-
!super::token_in_bottom_n(text, marker, 15)
|
|
2808
|
-
}
|
|
2809
|
-
|
|
2810
|
-
#[test]
|
|
2811
|
-
fn pasted_signal_unfixed_predicate_treats_folded_placeholder_as_consumed() {
|
|
2812
|
-
let folded = "โฏ [Pasted text #1 +8 lines]\n";
|
|
2813
|
-
let marker = "[team-agent-token:msg_fold]";
|
|
2814
|
-
assert!(
|
|
2815
|
-
unfixed_vacuous_consumed(folded, marker),
|
|
2816
|
-
"causal: pre-fix !token_in_bottom_n is vacuously true on a folded composer"
|
|
2817
|
-
);
|
|
2818
|
-
}
|
|
2819
|
-
|
|
2820
|
-
#[test]
|
|
2821
|
-
fn pasted_signal_token_sighting_table() {
|
|
2822
|
-
use super::TokenSighting::{Gone, NeverSeen, Visible};
|
|
2823
|
-
let cases = [
|
|
2824
|
-
("never_seen", false, false, NeverSeen),
|
|
2825
|
-
("gone", false, true, Gone),
|
|
2826
|
-
("visible", true, true, Visible),
|
|
2827
|
-
("gone_grok", false, true, Gone),
|
|
2828
|
-
];
|
|
2829
|
-
for (id, visible, seen, expected) in cases {
|
|
2830
|
-
assert_eq!(super::token_sighting(visible, seen), expected, "{id}");
|
|
2831
|
-
}
|
|
2832
|
-
}
|
|
2833
|
-
|
|
2834
|
-
#[test]
|
|
2835
|
-
fn pasted_signal_consumption_table() {
|
|
2836
|
-
use super::PasteLatch::{GrokLineCount, HashId};
|
|
2837
|
-
// Input: capture, marker, previously seen, tracked paste. Expected is Some(bool),
|
|
2838
|
-
// not a truthiness check: None must still fail these consumption contracts.
|
|
2839
|
-
type Input<'a> = (&'a str, &'a str, bool, Option<super::PasteLatch>);
|
|
2840
|
-
let marker = "[team-agent-token:msg_short]";
|
|
2841
|
-
let still = format!("โฏ ping {marker}\n");
|
|
2842
|
-
let cases: &[(&str, Input<'_>, bool, &str)] = &[
|
|
2843
|
-
("folded_hash_stays",
|
|
2844
|
-
("โฏ [Pasted text #1 +8 lines]\n", "[team-agent-token:msg_fold]", false, Some(HashId(1))), false,
|
|
2845
|
-
"post-fix NeverSeen + #1 still in composer must NOT be consumed"),
|
|
2846
|
-
("never_seen_empty",
|
|
2847
|
-
("", "[team-agent-token:msg_empty]", false, None), false, ""),
|
|
2848
|
-
("hash_id_gone",
|
|
2849
|
-
("assistant reply\nโฏ \n", "[team-agent-token:msg_fold]", false, Some(HashId(7))), true,
|
|
2850
|
-
"NeverSeen but latched #7 left composer โ consumed (positive signal)"),
|
|
2851
|
-
("hash_id_replaced",
|
|
2852
|
-
("โฏ [Pasted text #2 +3 lines]\n", "[team-agent-token:msg_fold]", false, Some(HashId(1))), true,
|
|
2853
|
-
"our #1 gone, a later #2 in composer still means ours submitted"),
|
|
2854
|
-
("no_hash_latch",
|
|
2855
|
-
("โฏ \n", "[team-agent-token:msg_fold]", false, None), false,
|
|
2856
|
-
"no #N latched: disappearance is unverified, not consumed"),
|
|
2857
|
-
("seen_token_gone",
|
|
2858
|
-
("โฏ \n", "[team-agent-token:msg_short]", true, None), true, ""),
|
|
2859
|
-
("seen_token_visible",
|
|
2860
|
-
(&still, "[team-agent-token:msg_short]", true, None), false, ""),
|
|
2861
|
-
("grok_lines_stay",
|
|
2862
|
-
(GROK_INCIDENT_LINE, "[team-agent-token:msg_grok]", false, Some(GrokLineCount(42))), false, ""),
|
|
2863
|
-
("grok_lines_gone",
|
|
2864
|
-
("Waiting for response\nโฏ \n", "[team-agent-token:msg_grok]", false, Some(GrokLineCount(42))), true, ""),
|
|
2865
|
-
("grok_lines_mismatch",
|
|
2866
|
-
("โ โฏ [Pasted: 10 lines] โ", "[team-agent-token:msg_grok]", false, Some(GrokLineCount(42))), false,
|
|
2867
|
-
"different N must not claim the latched paste consumed"),
|
|
2868
|
-
// ๆฌๆกB๏ผGone ไปๆ grok ๅ ไฝ็ฌฆ๏ผไฟฎๅ Gone ๆ ๆกไปถ Some(true)ใ
|
|
2869
|
-
("gone_grok_lines_stay",
|
|
2870
|
-
("some transcript line\n> [Pasted: 27 lines]\nEnter:send Esc:cancel\n", "[team-agent-token:deadbeef]", true, Some(GrokLineCount(27))), false,
|
|
2871
|
-
"Gone must re-check PasteLatch: placeholder still in composer must not be consumed, got {got:?}"),
|
|
2872
|
-
("gone_grok_kb_stay",
|
|
2873
|
-
("โ โฏ [Pasted: 13 KB] โ\n Enter:send\n", "[team-agent-token:kbform]", true, Some(GrokLineCount(13))), false,
|
|
2874
|
-
"Gone + [Pasted: 13 KB] still in composer must not be consumed, got {got:?}"),
|
|
2875
|
-
];
|
|
2876
|
-
for &(id, (text, marker, seen, tracked), expected, note) in cases {
|
|
2877
|
-
let got = super::consumption_from_capture(text, marker, seen, tracked);
|
|
2878
|
-
assert_eq!(got, Some(expected), "{id}: {note}; got={got:?}");
|
|
2879
|
-
}
|
|
2880
|
-
}
|
|
2881
|
-
|
|
2882
|
-
#[test]
|
|
2883
|
-
fn pasted_signal_marker_some_observation_records_composer_placeholder() {
|
|
2884
|
-
use crate::transport::CapturedText;
|
|
2885
|
-
let cap = CapturedText {
|
|
2886
|
-
text: "โฏ [Pasted text #4 +12 lines]\n".to_string(),
|
|
2887
|
-
range: CaptureRange::Tail(40),
|
|
2888
|
-
};
|
|
2889
|
-
let obs = super::submit_attempt_observation(1, &cap, Some("[team-agent-token:msg_x]"), 10);
|
|
2890
|
-
assert!(
|
|
2891
|
-
obs.matched,
|
|
2892
|
-
"marker Some must still walk pasted_prompt_match / composer placeholder; obs={obs:?}"
|
|
2893
|
-
);
|
|
2894
|
-
assert_eq!(obs.matched_literal.as_deref(), Some("pasted text"));
|
|
2895
|
-
}
|
|
2896
|
-
|
|
2897
|
-
#[test]
|
|
2898
|
-
fn pasted_signal_submit_verification_table() {
|
|
2899
|
-
use SubmitVerification::{EnterSentWithoutPlaceholderCheck, SubmitConsumptionUnverified};
|
|
2900
|
-
struct Case {
|
|
2901
|
-
id: &'static str,
|
|
2902
|
-
// Payload, pre-submit capture, post-submit capture, clear-after-N-enters.
|
|
2903
|
-
// None uses FoldedPasteRunner; Some(N) uses NthEnterClearRunner.
|
|
2904
|
-
input: (String, String, String, Option<u32>),
|
|
2905
|
-
// Verification, Enter count, paste-buffer count. None preserves no assertion.
|
|
2906
|
-
expected: (SubmitVerification, Option<usize>, Option<usize>),
|
|
2907
|
-
notes: [&'static str; 3],
|
|
2908
|
-
}
|
|
2909
|
-
let placeholder = "โฏ [Pasted text #4 +6 lines]\n";
|
|
2910
|
-
let short_ok = "ping [team-agent-token:msg_short_ok]";
|
|
2911
|
-
let short_stay = "ping [team-agent-token:msg_short_stay]";
|
|
2912
|
-
let marker = "[team-agent-token:msg_wrap_ok]";
|
|
2913
|
-
let wrapped_payload = format!("Team Agent message from leader:\nline1\n\n{marker}");
|
|
2914
|
-
let wrapped = wrapped_identity_with_skin(marker, "> ");
|
|
2915
|
-
let marker = "[team-agent-token:msg_cap_lock]";
|
|
2916
|
-
let cap_lock_payload = format!("Team Agent message from leader:\nline1\n\n{marker}");
|
|
2917
|
-
let cap_lock = wrapped_identity_with_skin(marker, "ready.");
|
|
2918
|
-
let marker = "[team-agent-token:msg_busy_nodup]";
|
|
2919
|
-
let busy_payload = format!("Team Agent message from leader:\nline1 composer> โฏ\n\n{marker}");
|
|
2920
|
-
let busy = "STARTED\nsleep holds pty\ncomposer>\nโฏ\n>\n";
|
|
2921
|
-
let marker = "[team-agent-token:msg_payload_glyph]";
|
|
2922
|
-
let glyphs_payload = format!("Team Agent message from leader:\ncomposer> โฏ\n\n{marker}");
|
|
2923
|
-
let glyphs = "output\ncomposer> leftover from payload\nโฏ quoted\n";
|
|
2924
|
-
let mut cases = vec![
|
|
2925
|
-
Case { id: "folded_stays",
|
|
2926
|
-
input: ("Team Agent message from leader:\nline1\nline2\nline3\nline4\nline5\n\n[team-agent-token:msg_fold_stay]".into(), placeholder.into(), placeholder.into(), None),
|
|
2927
|
-
expected: (SubmitConsumptionUnverified, None, None),
|
|
2928
|
-
notes: ["folded + Enter not effective (#4 stays) must be unverified; got {:?}", "", ""] },
|
|
2929
|
-
// ๅชๆ #4 ็ฆปๅผ composer๏ผไธๅ Working๏ผๅฆๅ busy ๅ็บงไผ่ฎฉๅไธไธ็ปๆญฃไฟกๅทๅฐฑ็ปฟใ
|
|
2930
|
-
Case { id: "folded_gone",
|
|
2931
|
-
input: ("Team Agent message from leader:\nline1\nline2\nline3\nline4\nline5\n\n[team-agent-token:msg_fold_go]".into(), placeholder.into(), "assistant reply\nโฏ \n".into(), None),
|
|
2932
|
-
expected: (EnterSentWithoutPlaceholderCheck, None, None),
|
|
2933
|
-
notes: ["folded + Enter effective (#4 left composer) must be consumed; got {:?}", "", ""] },
|
|
2934
|
-
Case { id: "short_gone",
|
|
2935
|
-
input: (short_ok.into(), short_ok.into(), "โฏ \n".into(), None),
|
|
2936
|
-
expected: (EnterSentWithoutPlaceholderCheck, None, None),
|
|
2937
|
-
notes: ["short visible token then gone must stay consumed; got {:?}", "", ""] },
|
|
2938
|
-
Case { id: "short_visible",
|
|
2939
|
-
input: (short_stay.into(), short_stay.into(), short_stay.into(), None),
|
|
2940
|
-
expected: (SubmitConsumptionUnverified, None, None),
|
|
2941
|
-
notes: ["short visible token still in composer must stay unverified; got {:?}", "", ""] },
|
|
2942
|
-
Case { id: "grok_stays",
|
|
2943
|
-
input: ("Team Agent message from leader:\nline1\n\n[team-agent-token:msg_grok_stay]".into(), GROK_INCIDENT_LINE.into(), GROK_INCIDENT_LINE.into(), None),
|
|
2944
|
-
expected: (SubmitConsumptionUnverified, Some(3), None),
|
|
2945
|
-
notes: ["", "same grok N still in composer must retry Enter up to cap=3; Unverified B must not add a 4th; invert wrap-gap guard must turn this red; calls={calls:?}", ""] },
|
|
2946
|
-
Case { id: "grok_gone",
|
|
2947
|
-
input: ("Team Agent message from leader:\nline1\n\n[team-agent-token:msg_grok_go]".into(), GROK_INCIDENT_LINE.into(), "Waiting for response\nโฏ \n".into(), None),
|
|
2948
|
-
expected: (EnterSentWithoutPlaceholderCheck, Some(1), None),
|
|
2949
|
-
notes: ["", "fold left composer after one Enter; no empty-composer hammer; calls={calls:?}", ""] },
|
|
2950
|
-
Case { id: "wrapped_resend_consumes",
|
|
2951
|
-
input: (wrapped_payload, wrapped, "> \n".into(), Some(2)),
|
|
2952
|
-
expected: (EnterSentWithoutPlaceholderCheck, Some(2), Some(1)),
|
|
2953
|
-
notes: ["Unverified + wrapped identity must resend one C-m then consume; got {:?}", "exactly one extra C-m after Unverified; calls={calls:?}", "must not re-paste; paste-buffer count={pastes}"] },
|
|
2954
|
-
Case { id: "identity_absent",
|
|
2955
|
-
input: (busy_payload, busy.into(), busy.into(), Some(99)),
|
|
2956
|
-
expected: (SubmitConsumptionUnverified, Some(1), None),
|
|
2957
|
-
notes: ["identity absent must stay Unverified, no extra Enter; got {:?}", "no this-paste identity โ no Unverified resend; commenting the identity gate must turn this red (2+ C-m); calls={calls:?}", ""] },
|
|
2958
|
-
Case { id: "identity_resend_cap",
|
|
2959
|
-
input: (cap_lock_payload, cap_lock.clone(), cap_lock, Some(u32::MAX)),
|
|
2960
|
-
expected: (SubmitConsumptionUnverified, Some(2), Some(1)),
|
|
2961
|
-
notes: ["never-clear identity must not fake-consume; got {:?}", "cap must be exactly one extra C-m (1 inject + 1 resend); raising UNVERIFIED_COMPOSER_RESEND_MAX must turn this red; calls={calls:?}", "must not re-paste; paste-buffer count={pastes}"] },
|
|
2962
|
-
Case { id: "payload_glyphs",
|
|
2963
|
-
input: (glyphs_payload, glyphs.into(), glyphs.into(), Some(99)),
|
|
2964
|
-
expected: (SubmitConsumptionUnverified, Some(1), None),
|
|
2965
|
-
notes: ["", "glyphs in payload must not cause extra C-m when token identity is gone; calls={calls:?}", ""] },
|
|
2966
|
-
];
|
|
2967
|
-
for (id, skin) in [
|
|
2968
|
-
("skin_arrow", "โฏ "),
|
|
2969
|
-
("skin_greater_than", "> "),
|
|
2970
|
-
("skin_ready", "ready."),
|
|
2971
|
-
] {
|
|
2972
|
-
let marker = format!("[team-agent-token:msg_skin_{}]", skin.chars().next().unwrap() as u32);
|
|
2973
|
-
cases.push(Case {
|
|
2974
|
-
id,
|
|
2975
|
-
input: (format!("Team Agent message from leader:\nline1\n\n{marker}"),
|
|
2976
|
-
wrapped_identity_with_skin(&marker, skin), format!("{skin}\n"), Some(2)),
|
|
2977
|
-
expected: (EnterSentWithoutPlaceholderCheck, Some(2), None),
|
|
2978
|
-
notes: ["skin {skin:?} must consume after one extra C-m", "skin {skin:?} extra C-m; got {n}", ""],
|
|
2979
|
-
});
|
|
2980
|
-
}
|
|
2981
|
-
for case in cases {
|
|
2982
|
-
let (payload, pre, post, clear_after) = case.input;
|
|
2983
|
-
let (be, rec) = match clear_after {
|
|
2984
|
-
Some(n) => backend_clears_after_n_enters(&pre, &post, n),
|
|
2985
|
-
None => backend_folded(&pre, &post),
|
|
2986
|
-
};
|
|
2987
|
-
let report = be.inject(
|
|
2988
|
-
&Target::Pane(PaneId::new("%7")), &InjectPayload::Text(payload), Key::Enter, true,
|
|
2989
|
-
).expect("inject");
|
|
2990
|
-
let (verification, enters, pastes) = case.expected;
|
|
2991
|
-
assert_eq!(report.submit_verification, verification,
|
|
2992
|
-
"{}: {}; pre={pre:?}", case.id, case.notes[0]);
|
|
2993
|
-
if enters.is_some() || pastes.is_some() {
|
|
2994
|
-
let calls = rec.lock().unwrap().clone();
|
|
2995
|
-
if let Some(enters) = enters {
|
|
2996
|
-
assert_eq!(count_submit_enters(&calls), enters,
|
|
2997
|
-
"{}: {}; calls={calls:?}", case.id, case.notes[1]);
|
|
2998
|
-
}
|
|
2999
|
-
if let Some(pastes) = pastes {
|
|
3000
|
-
let actual = calls.iter()
|
|
3001
|
-
.filter(|argv| argv.get(1).map(String::as_str) == Some("paste-buffer"))
|
|
3002
|
-
.count();
|
|
3003
|
-
assert_eq!(actual, pastes, "{}: {}; calls={calls:?}", case.id, case.notes[2]);
|
|
3004
|
-
}
|
|
3005
|
-
}
|
|
3006
|
-
}
|
|
3007
|
-
}
|
|
3008
|
-
|
|
3009
|
-
fn count_submit_enters(calls: &[Vec<String>]) -> usize {
|
|
3010
|
-
calls
|
|
3011
|
-
.iter()
|
|
3012
|
-
.filter(|argv| {
|
|
3013
|
-
argv.get(1).map(String::as_str) == Some("send-keys")
|
|
3014
|
-
&& argv.iter().any(|a| a == "C-m" || a == "Enter")
|
|
3015
|
-
})
|
|
3016
|
-
.count()
|
|
3017
|
-
}
|
|
3018
|
-
|
|
3019
|
-
fn count_paste_stage(calls: &[Vec<String>]) -> usize {
|
|
3020
|
-
calls
|
|
3021
|
-
.iter()
|
|
3022
|
-
.filter(|argv| {
|
|
3023
|
-
matches!(
|
|
3024
|
-
argv.get(1).map(String::as_str),
|
|
3025
|
-
Some("load-buffer") | Some("set-buffer") | Some("paste-buffer")
|
|
3026
|
-
)
|
|
3027
|
-
})
|
|
3028
|
-
.count()
|
|
3029
|
-
}
|
|
3030
|
-
|
|
3031
|
-
/// Inject runner that reports a fixed `#{pane_mode}` and a token that disappears after C-m.
|
|
3032
|
-
struct ModePasteRunner {
|
|
3033
|
-
recorded: RecordedArgv,
|
|
3034
|
-
pre_submit: String,
|
|
3035
|
-
post_submit: String,
|
|
3036
|
-
submitted: AtomicBool,
|
|
3037
|
-
pane_mode: String,
|
|
3038
|
-
}
|
|
3039
|
-
|
|
3040
|
-
impl CommandRunner for ModePasteRunner {
|
|
3041
|
-
fn run(&self, argv: &[String]) -> Result<CommandOutput, std::io::Error> {
|
|
3042
|
-
self.recorded.lock().unwrap().push(argv.to_vec());
|
|
3043
|
-
if argv.get(1).map(String::as_str) == Some("send-keys")
|
|
3044
|
-
&& argv.iter().any(|a| a == "C-m" || a == "Enter")
|
|
3045
|
-
{
|
|
3046
|
-
self.submitted.store(true, Ordering::SeqCst);
|
|
3047
|
-
}
|
|
3048
|
-
let stdout = match argv.get(1).map(String::as_str) {
|
|
3049
|
-
Some("capture-pane") => {
|
|
3050
|
-
if self.submitted.load(Ordering::SeqCst) {
|
|
3051
|
-
self.post_submit.clone()
|
|
3052
|
-
} else {
|
|
3053
|
-
self.pre_submit.clone()
|
|
3054
|
-
}
|
|
3055
|
-
}
|
|
3056
|
-
Some("display-message") => format!("{}\n", self.pane_mode),
|
|
3057
|
-
_ => String::new(),
|
|
3058
|
-
};
|
|
3059
|
-
Ok(ok(&stdout))
|
|
3060
|
-
}
|
|
3061
|
-
|
|
3062
|
-
fn run_with_stdin(
|
|
3063
|
-
&self,
|
|
3064
|
-
argv: &[String],
|
|
3065
|
-
_stdin: &str,
|
|
3066
|
-
) -> Result<CommandOutput, std::io::Error> {
|
|
3067
|
-
self.run(argv)
|
|
3068
|
-
}
|
|
3069
|
-
}
|
|
3070
|
-
|
|
3071
|
-
fn backend_mode(pane_mode: &str, token_text: &str) -> (TmuxBackend, RecordedArgv) {
|
|
3072
|
-
let recorded = Arc::new(Mutex::new(Vec::new()));
|
|
3073
|
-
let runner = ModePasteRunner {
|
|
3074
|
-
recorded: Arc::clone(&recorded),
|
|
3075
|
-
pre_submit: token_text.to_string(),
|
|
3076
|
-
post_submit: "โฏ \n".to_string(),
|
|
3077
|
-
submitted: AtomicBool::new(false),
|
|
3078
|
-
pane_mode: pane_mode.to_string(),
|
|
3079
|
-
};
|
|
3080
|
-
(TmuxBackend::with_runner(Box::new(runner)), recorded)
|
|
3081
|
-
}
|
|
3082
|
-
|
|
3083
|
-
fn first_submit_index(calls: &[Vec<String>]) -> Option<usize> {
|
|
3084
|
-
calls.iter().position(|argv| {
|
|
3085
|
-
argv.get(1).map(String::as_str) == Some("send-keys")
|
|
3086
|
-
&& argv.iter().any(|a| a == "C-m" || a == "Enter")
|
|
3087
|
-
})
|
|
3088
|
-
}
|
|
3089
|
-
|
|
3090
|
-
fn inject_send_keys_before_first_enter(calls: &[Vec<String>]) -> Vec<Vec<String>> {
|
|
3091
|
-
let Some(i) = first_submit_index(calls) else {
|
|
3092
|
-
return Vec::new();
|
|
3093
|
-
};
|
|
3094
|
-
calls[..i]
|
|
3095
|
-
.iter()
|
|
3096
|
-
.filter(|argv| argv.get(1).map(String::as_str) == Some("send-keys"))
|
|
3097
|
-
.cloned()
|
|
3098
|
-
.collect()
|
|
3099
|
-
}
|
|
3100
|
-
|
|
3101
|
-
fn assert_no_e55_keys(calls: &[Vec<String>]) {
|
|
3102
|
-
for argv in calls {
|
|
3103
|
-
if argv.get(1).map(String::as_str) != Some("send-keys") {
|
|
3104
|
-
continue;
|
|
3105
|
-
}
|
|
3106
|
-
assert!(
|
|
3107
|
-
!argv
|
|
3108
|
-
.iter()
|
|
3109
|
-
.any(|a| a == "Escape" || a == "C-c" || a == "C-C"),
|
|
3110
|
-
"E55: inject must not send Escape/C-c; argv={argv:?}"
|
|
3111
|
-
);
|
|
3112
|
-
}
|
|
3113
|
-
}
|
|
3114
|
-
|
|
3115
|
-
fn inject_token_for(tag: &str) -> String {
|
|
3116
|
-
format!("ping [team-agent-token:msg_{tag}]")
|
|
3117
|
-
}
|
|
3118
|
-
|
|
3119
|
-
/// PR-18: tree-mode ๅฟ
้กปๅจ็ฌฌไธๆฌก Enter ๅ send-keys qใไฟฎๅ๏ผๅชๅฏน Copy|Unknown cancelใ
|
|
3120
|
-
#[test]
|
|
3121
|
-
fn inject_cancels_tree_mode_with_q_before_enter() {
|
|
3122
|
-
let token = inject_token_for("tree_q");
|
|
3123
|
-
let (be, rec) = backend_mode("tree-mode", &token);
|
|
3124
|
-
with_paste_to_submit_floor(Duration::ZERO, || {
|
|
3125
|
-
be.inject(
|
|
3126
|
-
&Target::Pane(PaneId::new("%7")),
|
|
3127
|
-
&InjectPayload::Text(token.clone()),
|
|
3128
|
-
Key::Enter,
|
|
3129
|
-
false,
|
|
3130
|
-
)
|
|
3131
|
-
})
|
|
3132
|
-
.expect("inject");
|
|
3133
|
-
let calls = rec.lock().unwrap().clone();
|
|
3134
|
-
assert_no_e55_keys(&calls);
|
|
3135
|
-
let before = inject_send_keys_before_first_enter(&calls);
|
|
3136
|
-
assert!(
|
|
3137
|
-
before
|
|
3138
|
-
.iter()
|
|
3139
|
-
.any(|argv| argv.iter().any(|a| a == "q") && !argv.iter().any(|a| a == "-X")),
|
|
3140
|
-
"tree-mode must send-keys q before first Enter; before={before:?} calls={calls:?}"
|
|
3141
|
-
);
|
|
3142
|
-
assert!(
|
|
3143
|
-
!before.iter().any(|argv| argv.iter().any(|a| a == "-X")),
|
|
3144
|
-
"tree-mode must not use copy-mode -X cancel; before={before:?}"
|
|
3145
|
-
);
|
|
3146
|
-
assert_eq!(
|
|
3147
|
-
count_submit_enters(&calls),
|
|
3148
|
-
1,
|
|
3149
|
-
"consumed after cancel+Enter; calls={calls:?}"
|
|
3150
|
-
);
|
|
3151
|
-
}
|
|
3152
|
-
|
|
3153
|
-
/// copy-mode ๅๅฝ๏ผไป่ตฐ -X cancel๏ผไธๅพๆนๆ qใ
|
|
3154
|
-
#[test]
|
|
3155
|
-
fn inject_cancels_copy_mode_with_x_cancel_before_enter() {
|
|
3156
|
-
let token = inject_token_for("copy_x");
|
|
3157
|
-
let (be, rec) = backend_mode("copy-mode", &token);
|
|
3158
|
-
with_paste_to_submit_floor(Duration::ZERO, || {
|
|
3159
|
-
be.inject(
|
|
3160
|
-
&Target::Pane(PaneId::new("%7")),
|
|
3161
|
-
&InjectPayload::Text(token.clone()),
|
|
3162
|
-
Key::Enter,
|
|
3163
|
-
false,
|
|
3164
|
-
)
|
|
3165
|
-
})
|
|
3166
|
-
.expect("inject");
|
|
3167
|
-
let calls = rec.lock().unwrap().clone();
|
|
3168
|
-
assert_no_e55_keys(&calls);
|
|
3169
|
-
let before = inject_send_keys_before_first_enter(&calls);
|
|
3170
|
-
assert!(
|
|
3171
|
-
before
|
|
3172
|
-
.iter()
|
|
3173
|
-
.any(|argv| argv.iter().any(|a| a == "-X") && argv.iter().any(|a| a == "cancel")),
|
|
3174
|
-
"copy-mode must keep -X cancel before Enter; before={before:?} calls={calls:?}"
|
|
3175
|
-
);
|
|
3176
|
-
}
|
|
3177
|
-
|
|
3178
|
-
/// pane_mode=0 ๆฏ่พๅ
ฅๅฐฑ็ปช๏ผไธๅพ cancelใ
|
|
3179
|
-
#[test]
|
|
3180
|
-
fn inject_skips_cancel_when_pane_mode_is_zero() {
|
|
3181
|
-
let token = inject_token_for("mode0");
|
|
3182
|
-
let (be, rec) = backend_mode("0", &token);
|
|
3183
|
-
with_paste_to_submit_floor(Duration::ZERO, || {
|
|
3184
|
-
be.inject(
|
|
3185
|
-
&Target::Pane(PaneId::new("%7")),
|
|
3186
|
-
&InjectPayload::Text(token.clone()),
|
|
3187
|
-
Key::Enter,
|
|
3188
|
-
false,
|
|
3189
|
-
)
|
|
3190
|
-
})
|
|
3191
|
-
.expect("inject");
|
|
3192
|
-
let calls = rec.lock().unwrap().clone();
|
|
3193
|
-
assert_no_e55_keys(&calls);
|
|
3194
|
-
let before = inject_send_keys_before_first_enter(&calls);
|
|
3195
|
-
assert!(
|
|
3196
|
-
!before
|
|
3197
|
-
.iter()
|
|
3198
|
-
.any(|argv| argv.iter().any(|a| a == "q" || a == "-X")),
|
|
3199
|
-
"pane_mode=0 must not send mode-cancel; before={before:?}"
|
|
3200
|
-
);
|
|
3201
|
-
// ็จๆท่ฃๅฎ 2026-08-23๏ผไธๅ ESC๏ผไนไธๅ ESC ็ๆฟไปฃๅ๏ผๅซๅญ้ข CSI 201~๏ผใ็ฟป้ขๅไธใ
|
|
3202
|
-
assert!(
|
|
3203
|
-
!before
|
|
3204
|
-
.iter()
|
|
3205
|
-
.any(|argv| argv.iter().any(|a| a.contains('\u{1b}'))),
|
|
3206
|
-
"mode=0 must not send any ESC/CSI byte before Enter; before={before:?}"
|
|
3207
|
-
);
|
|
3208
|
-
}
|
|
3209
|
-
|
|
3210
|
-
#[test]
|
|
3211
|
-
fn inject_cancels_view_mode_with_q_before_enter() {
|
|
3212
|
-
let token = inject_token_for("view_q");
|
|
3213
|
-
let (be, rec) = backend_mode("view-mode", &token);
|
|
3214
|
-
with_paste_to_submit_floor(Duration::ZERO, || {
|
|
3215
|
-
be.inject(
|
|
3216
|
-
&Target::Pane(PaneId::new("%7")),
|
|
3217
|
-
&InjectPayload::Text(token.clone()),
|
|
3218
|
-
Key::Enter,
|
|
3219
|
-
false,
|
|
3220
|
-
)
|
|
3221
|
-
})
|
|
3222
|
-
.expect("inject");
|
|
3223
|
-
let calls = rec.lock().unwrap().clone();
|
|
3224
|
-
assert_no_e55_keys(&calls);
|
|
3225
|
-
let before = inject_send_keys_before_first_enter(&calls);
|
|
3226
|
-
assert!(
|
|
3227
|
-
before
|
|
3228
|
-
.iter()
|
|
3229
|
-
.any(|argv| argv.last().map(String::as_str) == Some("q")),
|
|
3230
|
-
"view-mode must send-keys q before Enter; before={before:?}"
|
|
3231
|
-
);
|
|
3232
|
-
}
|
|
3233
|
-
|
|
3234
|
-
#[test]
|
|
3235
|
-
fn inject_cancels_client_mode_with_d_before_enter() {
|
|
3236
|
-
let token = inject_token_for("client_d");
|
|
3237
|
-
let (be, rec) = backend_mode("client-mode", &token);
|
|
3238
|
-
with_paste_to_submit_floor(Duration::ZERO, || {
|
|
3239
|
-
be.inject(
|
|
3240
|
-
&Target::Pane(PaneId::new("%7")),
|
|
3241
|
-
&InjectPayload::Text(token.clone()),
|
|
3242
|
-
Key::Enter,
|
|
3243
|
-
false,
|
|
3244
|
-
)
|
|
3245
|
-
})
|
|
3246
|
-
.expect("inject");
|
|
3247
|
-
let calls = rec.lock().unwrap().clone();
|
|
3248
|
-
assert_no_e55_keys(&calls);
|
|
3249
|
-
let before = inject_send_keys_before_first_enter(&calls);
|
|
3250
|
-
assert!(
|
|
3251
|
-
before
|
|
3252
|
-
.iter()
|
|
3253
|
-
.any(|argv| argv.last().map(String::as_str) == Some("d")),
|
|
3254
|
-
"client-mode must send-keys d before Enter; before={before:?}"
|
|
3255
|
-
);
|
|
3256
|
-
}
|
|
3257
|
-
|
|
3258
|
-
/// ็จๆท่ฃๅฎ 2026-08-23๏ผไธๅ ESC๏ผไนไธๅ ESC ็ๆฟไปฃๅ๏ผๅซๅญ้ข CSI 201~๏ผใ
|
|
3259
|
-
/// ๅ ESC/CSI ็ๅฏไธๅฅฝๅคๆฏ่ฎฉๆถๆฏๅฝๅบ็ดๆฅไธๅฑ๏ผๆฌ้กน็ฎๅช่ฆๆฑใไธไธๆฌกๅทฅๅ
ท่ฐ็จๆถ่ฝไธๅฑใ
|
|
3260
|
-
/// โ ไธๅญๅจ้่ฆๅฎๆ่ฝๆปก่ถณ็ๅบๆฏ๏ผๅๅฎๆฒกๆๆถ็๏ผๅชๆๆฑกๆ composer ่พๅ
ฅ็้ฃ้ฉใ
|
|
3261
|
-
/// ๆฌๅคๆฎ็ฑใๅฟ
้กปๅ 201~ใ็ฟป้ขไธบใEnter ๅไธๅพๅไปปไฝ ESC/CSI ๅญ่ใใ
|
|
3262
|
-
#[test]
|
|
3263
|
-
fn inject_sends_no_escape_bytes_before_enter() {
|
|
3264
|
-
let token = inject_token_for("paste201");
|
|
3265
|
-
let (be, rec) = backend_mode("0", &token);
|
|
3266
|
-
with_paste_to_submit_floor(Duration::ZERO, || {
|
|
3267
|
-
be.inject(
|
|
3268
|
-
&Target::Pane(PaneId::new("%7")),
|
|
3269
|
-
&InjectPayload::Text(token.clone()),
|
|
3270
|
-
Key::Enter,
|
|
3271
|
-
true,
|
|
3272
|
-
)
|
|
3273
|
-
})
|
|
3274
|
-
.expect("inject");
|
|
3275
|
-
let calls = rec.lock().unwrap().clone();
|
|
3276
|
-
assert_no_e55_keys(&calls);
|
|
3277
|
-
let before = inject_send_keys_before_first_enter(&calls);
|
|
3278
|
-
assert!(
|
|
3279
|
-
!before
|
|
3280
|
-
.iter()
|
|
3281
|
-
.any(|argv| argv.iter().any(|a| a.contains('\u{1b}'))),
|
|
3282
|
-
"no ESC/CSI byte may be sent before Enter; before={before:?}"
|
|
3283
|
-
);
|
|
3284
|
-
}
|
|
3285
|
-
|
|
3286
|
-
/// A1 Empty / trust ่ทฏๅพไนๅฟ
้กป็ป่ฟ prepareใ
|
|
3287
|
-
#[test]
|
|
3288
|
-
fn empty_inject_cancels_tree_mode_before_cm() {
|
|
3289
|
-
let (be, rec) = backend_mode("tree-mode", "");
|
|
3290
|
-
be.inject(
|
|
3291
|
-
&Target::Pane(PaneId::new("%7")),
|
|
3292
|
-
&InjectPayload::Empty,
|
|
3293
|
-
Key::Enter,
|
|
3294
|
-
false,
|
|
3295
|
-
)
|
|
3296
|
-
.expect("empty inject");
|
|
3297
|
-
let calls = rec.lock().unwrap().clone();
|
|
3298
|
-
assert_no_e55_keys(&calls);
|
|
3299
|
-
let before = inject_send_keys_before_first_enter(&calls);
|
|
3300
|
-
assert!(
|
|
3301
|
-
before
|
|
3302
|
-
.iter()
|
|
3303
|
-
.any(|argv| argv.last().map(String::as_str) == Some("q")),
|
|
3304
|
-
"A1 Empty must cancel tree-mode before C-m; before={before:?} calls={calls:?}"
|
|
3305
|
-
);
|
|
3306
|
-
}
|
|
3307
|
-
|
|
3308
|
-
/// A3 skip-consumption๏ผleader ๆ้๏ผไนๅฟ
้กป็ป่ฟ prepareใ
|
|
3309
|
-
#[test]
|
|
3310
|
-
fn skip_consumption_cancels_tree_mode_before_cm() {
|
|
3311
|
-
let token = inject_token_for("skip_tree");
|
|
3312
|
-
let (be, rec) = backend_mode("tree-mode", &token);
|
|
3313
|
-
with_paste_to_submit_floor(Duration::ZERO, || {
|
|
3314
|
-
be.inject(
|
|
3315
|
-
&Target::Pane(PaneId::new("%7")),
|
|
3316
|
-
&InjectPayload::TextSkipConsumptionPoll(token.clone()),
|
|
3317
|
-
Key::Enter,
|
|
3318
|
-
false,
|
|
3319
|
-
)
|
|
3320
|
-
})
|
|
3321
|
-
.expect("skip inject");
|
|
3322
|
-
let calls = rec.lock().unwrap().clone();
|
|
3323
|
-
assert_no_e55_keys(&calls);
|
|
3324
|
-
let before = inject_send_keys_before_first_enter(&calls);
|
|
3325
|
-
assert!(
|
|
3326
|
-
before
|
|
3327
|
-
.iter()
|
|
3328
|
-
.any(|argv| argv.last().map(String::as_str) == Some("q")),
|
|
3329
|
-
"A3 skip-poll must cancel tree-mode before C-m; before={before:?}"
|
|
3330
|
-
);
|
|
3331
|
-
}
|
|
3332
|
-
|
|
3333
|
-
/// A6 send_keys([Enter]) ไธ C ๅ 8 ไธช่ฐ็จๆน๏ผๅซ Enter ็้ฎ็ปๅ
prepareใ
|
|
3334
|
-
#[test]
|
|
3335
|
-
fn send_keys_enter_cancels_tree_mode_before_enter() {
|
|
3336
|
-
let (be, rec) = backend_mode("tree-mode", "");
|
|
3337
|
-
be.send_keys(&Target::Pane(PaneId::new("%7")), &[Key::Enter])
|
|
3338
|
-
.expect("send_keys");
|
|
3339
|
-
let calls = rec.lock().unwrap().clone();
|
|
3340
|
-
assert_no_e55_keys(&calls);
|
|
3341
|
-
let before = inject_send_keys_before_first_enter(&calls);
|
|
3342
|
-
assert!(
|
|
3343
|
-
before
|
|
3344
|
-
.iter()
|
|
3345
|
-
.any(|argv| argv.last().map(String::as_str) == Some("q")),
|
|
3346
|
-
"send_keys(Enter) must cancel tree-mode first; before={before:?} calls={calls:?}"
|
|
3347
|
-
);
|
|
3348
|
-
}
|
|
3349
|
-
|
|
3350
|
-
#[test]
|
|
3351
|
-
fn send_keys_down_enter_cancels_tree_mode_before_group() {
|
|
3352
|
-
let (be, rec) = backend_mode("tree-mode", "");
|
|
3353
|
-
be.send_keys(&Target::Pane(PaneId::new("%7")), &[Key::Down, Key::Enter])
|
|
3354
|
-
.expect("send_keys");
|
|
3355
|
-
let calls = rec.lock().unwrap().clone();
|
|
3356
|
-
assert_no_e55_keys(&calls);
|
|
3357
|
-
let before = inject_send_keys_before_first_enter(&calls);
|
|
3358
|
-
assert!(
|
|
3359
|
-
before
|
|
3360
|
-
.iter()
|
|
3361
|
-
.any(|argv| argv.last().map(String::as_str) == Some("q")),
|
|
3362
|
-
"Down+Enter must cancel tree-mode before the key group; before={before:?}"
|
|
3363
|
-
);
|
|
3364
|
-
}
|
|
3365
|
-
|
|
3366
|
-
/// ๅค้จ้ 2026-08-19 ๅฑ้ขๅๆ๏ผไธๅญไธๆนใ
|
|
3367
|
-
const GROK_INCIDENT_LINE: &str = "โ โฏ [Pasted: 42 lines] โ";
|
|
3368
|
-
|
|
3369
|
-
fn grok_raw_unfolded_paste(marker: &str) -> String {
|
|
3370
|
-
let mut lines = Vec::new();
|
|
3371
|
-
for i in 0..20 {
|
|
3372
|
-
lines.push(format!("payload line {i}"));
|
|
3373
|
-
}
|
|
3374
|
-
lines.push(format!("token {marker}"));
|
|
3375
|
-
lines.join("\n")
|
|
3376
|
-
}
|
|
3377
|
-
|
|
3378
|
-
struct RawThenFoldRunner {
|
|
3379
|
-
recorded: RecordedArgv,
|
|
3380
|
-
raw: String,
|
|
3381
|
-
folded: String,
|
|
3382
|
-
after_submit: String,
|
|
3383
|
-
captures: Mutex<u32>,
|
|
3384
|
-
fold_after: u32,
|
|
3385
|
-
submitted: AtomicBool,
|
|
3386
|
-
}
|
|
3387
|
-
|
|
3388
|
-
impl CommandRunner for RawThenFoldRunner {
|
|
3389
|
-
fn run(&self, argv: &[String]) -> Result<CommandOutput, std::io::Error> {
|
|
3390
|
-
self.recorded.lock().unwrap().push(argv.to_vec());
|
|
3391
|
-
if argv.get(1).map(String::as_str) == Some("send-keys")
|
|
3392
|
-
&& argv.iter().any(|a| a == "C-m" || a == "Enter")
|
|
3393
|
-
{
|
|
3394
|
-
self.submitted.store(true, Ordering::SeqCst);
|
|
3395
|
-
}
|
|
3396
|
-
let stdout = match argv.get(1).map(String::as_str) {
|
|
3397
|
-
Some("capture-pane") => {
|
|
3398
|
-
if self.submitted.load(Ordering::SeqCst) {
|
|
3399
|
-
self.after_submit.clone()
|
|
3400
|
-
} else {
|
|
3401
|
-
let mut n = self.captures.lock().unwrap();
|
|
3402
|
-
*n = n.saturating_add(1);
|
|
3403
|
-
if *n > self.fold_after {
|
|
3404
|
-
self.folded.clone()
|
|
3405
|
-
} else {
|
|
3406
|
-
self.raw.clone()
|
|
3407
|
-
}
|
|
3408
|
-
}
|
|
3409
|
-
}
|
|
3410
|
-
Some("display-message") => "0\n".to_string(),
|
|
3411
|
-
_ => String::new(),
|
|
3412
|
-
};
|
|
3413
|
-
Ok(ok(&stdout))
|
|
3414
|
-
}
|
|
3415
|
-
|
|
3416
|
-
fn run_with_stdin(
|
|
3417
|
-
&self,
|
|
3418
|
-
argv: &[String],
|
|
3419
|
-
_stdin: &str,
|
|
3420
|
-
) -> Result<CommandOutput, std::io::Error> {
|
|
3421
|
-
self.run(argv)
|
|
3422
|
-
}
|
|
3423
|
-
}
|
|
3424
|
-
|
|
3425
|
-
fn backend_raw_then_fold(
|
|
3426
|
-
raw: &str,
|
|
3427
|
-
folded: &str,
|
|
3428
|
-
after_submit: &str,
|
|
3429
|
-
fold_after: u32,
|
|
3430
|
-
) -> (TmuxBackend, RecordedArgv) {
|
|
3431
|
-
let recorded = Arc::new(Mutex::new(Vec::new()));
|
|
3432
|
-
let runner = RawThenFoldRunner {
|
|
3433
|
-
recorded: Arc::clone(&recorded),
|
|
3434
|
-
raw: raw.to_string(),
|
|
3435
|
-
folded: folded.to_string(),
|
|
3436
|
-
after_submit: after_submit.to_string(),
|
|
3437
|
-
captures: Mutex::new(0),
|
|
3438
|
-
fold_after,
|
|
3439
|
-
submitted: AtomicBool::new(false),
|
|
3440
|
-
};
|
|
3441
|
-
(TmuxBackend::with_runner(Box::new(runner)), recorded)
|
|
3442
|
-
}
|
|
3443
|
-
|
|
3444
|
-
#[test]
|
|
3445
|
-
fn grok_fold_literal_locks_external_team_line() {
|
|
3446
|
-
let prompt =
|
|
3447
|
-
super::pasted_prompt_in_composer(GROK_INCIDENT_LINE, 15).expect("lock grok incident line");
|
|
3448
|
-
assert_eq!(prompt.literal, "pasted:");
|
|
3449
|
-
assert_eq!(prompt.id, None, "grok fold has no #N");
|
|
3450
|
-
assert_eq!(prompt.line_count, Some(42));
|
|
3451
|
-
let matched = super::pasted_prompt_match(GROK_INCIDENT_LINE).expect("match");
|
|
3452
|
-
assert_eq!(matched.0, "pasted:");
|
|
3453
|
-
}
|
|
3454
|
-
|
|
3455
|
-
#[test]
|
|
3456
|
-
fn grok_fold_three_tui_literals_lock() {
|
|
3457
|
-
let grok = super::pasted_prompt_in_composer(GROK_INCIDENT_LINE, 15).unwrap();
|
|
3458
|
-
let claude = super::pasted_prompt_in_composer("โฏ [Pasted text #4 +12 lines]\n", 15).unwrap();
|
|
3459
|
-
let codex = super::pasted_prompt_in_composer("โฏ [Pasted content #2 +3 lines]\n", 15).unwrap();
|
|
3460
|
-
assert_eq!(grok.literal, "pasted:");
|
|
3461
|
-
assert_eq!(claude.literal, "pasted text");
|
|
3462
|
-
assert_eq!(claude.id, Some(4));
|
|
3463
|
-
assert_eq!(codex.literal, "pasted content");
|
|
3464
|
-
assert_eq!(codex.id, Some(2));
|
|
3465
|
-
}
|
|
3466
|
-
|
|
3467
|
-
#[test]
|
|
3468
|
-
fn grok_fold_different_n_is_not_same_paste() {
|
|
3469
|
-
let marker = "[team-agent-token:msg_grok]";
|
|
3470
|
-
let other = "โ โฏ [Pasted: 10 lines] โ";
|
|
3471
|
-
assert!(
|
|
3472
|
-
!super::should_resubmit_enter(other, marker, Some(super::PasteLatch::GrokLineCount(42))),
|
|
3473
|
-
"different N is not the same paste; do not hammer Enter"
|
|
3474
|
-
);
|
|
3475
|
-
}
|
|
3476
|
-
|
|
3477
|
-
/// 2026-08-21 ็ๆบๅฑๅฐพ๏ผๆๅ ๅ ไฝ็ฌฆ่ฟๅจ transcript๏ผWorking ๅทฒๅผใ
|
|
3478
|
-
/// ้ cursor ่ทฏๅพไผๆ pasted #N ๅฝๆๆชๆถ่ดน่่ฟๆ Enterใ
|
|
3479
|
-
const CURSOR_BUSY_AFTER_SUBMIT: &str = "\
|
|
3480
|
-
[Pasted text #1 +46 lines]\n\
|
|
3481
|
-
\n\
|
|
3482
|
-
T126S-34701-OK\n\
|
|
3483
|
-
\n\
|
|
3484
|
-
โ ฐโ ฐ Working 37 tokens\n\
|
|
3485
|
-
Tip: Use /plan to plan execution and reach the right outcome faster.\n\
|
|
3486
|
-
\n\
|
|
3487
|
-
โ Add a follow-up ctrl+c to stop\n\
|
|
3488
|
-
\n\
|
|
3489
|
-
Cursor Grok 4.6 Extra High Run Everything\n";
|
|
3490
|
-
|
|
3491
|
-
#[test]
|
|
3492
|
-
fn cursor_single_enter_busy_transcript_placeholder_does_not_retry() {
|
|
3493
|
-
let token_text = "Team Agent message from leader:\nline1\n\n[team-agent-token:msg_cur_busy]";
|
|
3494
|
-
let (be, rec) = backend_folded("[Pasted text #1 +46 lines]\n", CURSOR_BUSY_AFTER_SUBMIT);
|
|
3495
|
-
let report = with_cursor_single_enter(true, || {
|
|
3496
|
-
be.inject(
|
|
3497
|
-
&Target::Pane(PaneId::new("%7")),
|
|
3498
|
-
&InjectPayload::Text(token_text.to_string()),
|
|
3499
|
-
Key::Enter,
|
|
3500
|
-
true,
|
|
3501
|
-
)
|
|
3502
|
-
})
|
|
3503
|
-
.expect("inject");
|
|
3504
|
-
assert_eq!(
|
|
3505
|
-
report.submit_verification,
|
|
3506
|
-
SubmitVerification::EnterSentWithoutPlaceholderCheck,
|
|
3507
|
-
"busy after first Enter is consumption for cursor; got {:?}",
|
|
3508
|
-
report.submit_verification
|
|
3509
|
-
);
|
|
3510
|
-
let diagnostics = report.submit_diagnostics.expect("diagnostics");
|
|
3511
|
-
assert_eq!(
|
|
3512
|
-
diagnostics.consumption_reason,
|
|
3513
|
-
SubmitConsumptionReason::CursorPollingBusy
|
|
3514
|
-
);
|
|
3515
|
-
assert_eq!(diagnostics.busy_signal_kind, Some(BusySignalKind::Working));
|
|
3516
|
-
assert!(diagnostics.busy_line_from_bottom.is_some());
|
|
3517
|
-
assert!(diagnostics.current_marker_in_bottom_15.is_some());
|
|
3518
|
-
assert!(diagnostics.consumption_from_capture_result.is_some());
|
|
3519
|
-
let calls = rec.lock().unwrap().clone();
|
|
3520
|
-
assert_eq!(
|
|
3521
|
-
count_submit_enters(&calls),
|
|
3522
|
-
1,
|
|
3523
|
-
"cursor busy: at most one Enter; extra Enter interrupts. calls={calls:?}"
|
|
3524
|
-
);
|
|
3525
|
-
}
|
|
3526
|
-
|
|
3527
|
-
#[test]
|
|
3528
|
-
fn cursor_single_enter_off_still_retries_on_transcript_placeholder() {
|
|
3529
|
-
let token_text = "Team Agent message from leader:\nline1\n\n[team-agent-token:msg_cur_ctrl]";
|
|
3530
|
-
let (be, rec) = backend_folded("[Pasted text #1 +46 lines]\n", CURSOR_BUSY_AFTER_SUBMIT);
|
|
3531
|
-
let _report = be
|
|
3532
|
-
.inject(
|
|
3533
|
-
&Target::Pane(PaneId::new("%7")),
|
|
3534
|
-
&InjectPayload::Text(token_text.to_string()),
|
|
3535
|
-
Key::Enter,
|
|
3536
|
-
true,
|
|
3537
|
-
)
|
|
3538
|
-
.expect("inject");
|
|
3539
|
-
let calls = rec.lock().unwrap().clone();
|
|
3540
|
-
assert_eq!(
|
|
3541
|
-
count_submit_enters(&calls),
|
|
3542
|
-
3,
|
|
3543
|
-
"default path (claude/grok/codex) must keep retry cap; calls={calls:?}"
|
|
3544
|
-
);
|
|
3545
|
-
}
|
|
3546
|
-
|
|
3547
|
-
#[test]
|
|
3548
|
-
fn cursor_single_enter_retries_only_if_token_still_in_input() {
|
|
3549
|
-
let marker = "[team-agent-token:msg_cur_idle]";
|
|
3550
|
-
let token_text = format!("Team Agent message from leader:\nline1\n\n{marker}");
|
|
3551
|
-
let still_in_input = format!("{marker}\nโ \n");
|
|
3552
|
-
let (be, rec) = backend_folded(still_in_input.as_str(), still_in_input.as_str());
|
|
3553
|
-
let _report = with_cursor_single_enter(true, || {
|
|
3554
|
-
be.inject(
|
|
3555
|
-
&Target::Pane(PaneId::new("%7")),
|
|
3556
|
-
&InjectPayload::Text(token_text),
|
|
3557
|
-
Key::Enter,
|
|
3558
|
-
true,
|
|
3559
|
-
)
|
|
3560
|
-
})
|
|
3561
|
-
.expect("inject");
|
|
3562
|
-
let calls = rec.lock().unwrap().clone();
|
|
3563
|
-
let n = count_submit_enters(&calls);
|
|
3564
|
-
assert!(
|
|
3565
|
-
n >= 2,
|
|
3566
|
-
"token still in cursor input box (no busy) may retry Enter; got {n} calls={calls:?}"
|
|
3567
|
-
);
|
|
3568
|
-
}
|
|
3569
|
-
|
|
3570
|
-
#[test]
|
|
3571
|
-
fn cursor_should_resubmit_false_when_busy_even_if_paste_placeholder_visible() {
|
|
3572
|
-
let marker = "[team-agent-token:msg_cur_gate]";
|
|
3573
|
-
assert!(
|
|
3574
|
-
!super::should_resubmit_enter_cursor(CURSOR_BUSY_AFTER_SUBMIT, marker),
|
|
3575
|
-
"busy + transcript placeholder must not resubmit on cursor"
|
|
3576
|
-
);
|
|
3577
|
-
assert!(
|
|
3578
|
-
super::should_resubmit_enter(
|
|
3579
|
-
CURSOR_BUSY_AFTER_SUBMIT,
|
|
3580
|
-
marker,
|
|
3581
|
-
Some(super::PasteLatch::HashId(1))
|
|
3582
|
-
),
|
|
3583
|
-
"non-cursor detector still sees latched #1 as resubmit"
|
|
3584
|
-
);
|
|
3585
|
-
}
|
|
3586
|
-
|
|
3587
|
-
#[test]
|
|
3588
|
-
fn grok_fold_unverified_without_identity_one_enter() {
|
|
3589
|
-
let token_text = "Team Agent message from leader:\nhi\n\n[team-agent-token:msg_grok_empty]";
|
|
3590
|
-
let (be, rec) = backend_with(MockResp::Out(ok("")), vec![]);
|
|
3591
|
-
let report = be
|
|
3592
|
-
.inject(
|
|
3593
|
-
&Target::Pane(PaneId::new("%7")),
|
|
3594
|
-
&InjectPayload::Text(token_text.to_string()),
|
|
3595
|
-
Key::Enter,
|
|
3596
|
-
true,
|
|
3597
|
-
)
|
|
3598
|
-
.expect("inject");
|
|
3599
|
-
assert_eq!(
|
|
3600
|
-
report.submit_verification,
|
|
3601
|
-
SubmitVerification::SubmitConsumptionUnverified
|
|
3602
|
-
);
|
|
3603
|
-
let calls = rec.lock().unwrap().clone();
|
|
3604
|
-
assert_eq!(
|
|
3605
|
-
count_submit_enters(&calls),
|
|
3606
|
-
1,
|
|
3607
|
-
"no latch / empty composer: one Enter then stop; calls={calls:?}"
|
|
3608
|
-
);
|
|
3609
|
-
}
|
|
3610
|
-
|
|
3611
|
-
#[test]
|
|
3612
|
-
fn grok_fold_does_not_enter_before_fold_on_raw_tall_paste() {
|
|
3613
|
-
let marker = "[team-agent-token:msg_grok_early]";
|
|
3614
|
-
let token_text = format!(
|
|
3615
|
-
"Team Agent message from leader:\n{}\n\n{marker}",
|
|
3616
|
-
"x\n".repeat(20)
|
|
3617
|
-
);
|
|
3618
|
-
let raw = grok_raw_unfolded_paste(marker);
|
|
3619
|
-
assert!(
|
|
3620
|
-
!super::paste_ready_for_enter(&raw, marker),
|
|
3621
|
-
"raw tall paste with token is not ready"
|
|
3622
|
-
);
|
|
3623
|
-
assert!(super::paste_ready_for_enter(GROK_INCIDENT_LINE, marker));
|
|
3624
|
-
let (be, rec) =
|
|
3625
|
-
backend_raw_then_fold(&raw, GROK_INCIDENT_LINE, "Waiting for response\nโฏ \n", 2);
|
|
3626
|
-
let report = be
|
|
3627
|
-
.inject(
|
|
3628
|
-
&Target::Pane(PaneId::new("%7")),
|
|
3629
|
-
&InjectPayload::Text(token_text),
|
|
3630
|
-
Key::Enter,
|
|
3631
|
-
true,
|
|
3632
|
-
)
|
|
3633
|
-
.expect("inject");
|
|
3634
|
-
assert_eq!(
|
|
3635
|
-
report.submit_verification,
|
|
3636
|
-
SubmitVerification::EnterSentWithoutPlaceholderCheck
|
|
3637
|
-
);
|
|
3638
|
-
let calls = rec.lock().unwrap().clone();
|
|
3639
|
-
let submit_index = calls
|
|
3640
|
-
.iter()
|
|
3641
|
-
.position(|argv| {
|
|
3642
|
-
argv.get(1).map(String::as_str) == Some("send-keys")
|
|
3643
|
-
&& argv.iter().any(|a| a == "C-m" || a == "Enter")
|
|
3644
|
-
})
|
|
3645
|
-
.expect("must submit");
|
|
3646
|
-
let captures_before: Vec<&Vec<String>> = calls[..submit_index]
|
|
3647
|
-
.iter()
|
|
3648
|
-
.filter(|argv| argv.get(1).map(String::as_str) == Some("capture-pane"))
|
|
3649
|
-
.collect();
|
|
3650
|
-
assert!(
|
|
3651
|
-
captures_before.len() > 2,
|
|
3652
|
-
"must keep polling until fold, not Enter on first token; calls={calls:?}"
|
|
3653
|
-
);
|
|
3654
|
-
assert_eq!(count_submit_enters(&calls), 1);
|
|
3655
|
-
}
|
|
3656
|
-
|
|
3657
|
-
#[test]
|
|
3658
|
-
fn grok_kb_placeholder_parser_preserves_literal_and_line_count() {
|
|
3659
|
-
let cap = "โ โฏ [Pasted: 13 KB] โ\n Enter:send\n";
|
|
3660
|
-
let prompt = super::pasted_prompt_in_composer(cap, 15).expect("KB form is grok fold");
|
|
3661
|
-
assert_eq!(prompt.literal, "pasted:");
|
|
3662
|
-
assert_eq!(prompt.line_count, Some(13));
|
|
3663
|
-
}
|
|
3664
|
-
|
|
3665
|
-
/// ๆ ทๆฌ#5 ๅฝๅ ้๏ผ้่ฏๅช้ๆ Enter๏ผไธๅพๅ load/set/paste-bufferใ
|
|
3666
|
-
#[test]
|
|
3667
|
-
fn grok_fold_raw_then_fold_placeholder_stays_retries_enter_not_repaste() {
|
|
3668
|
-
let marker = "[team-agent-token:msg_grok_reappear]";
|
|
3669
|
-
let token_text = format!(
|
|
3670
|
-
"Team Agent message from leader:\n{}\n\n{marker}",
|
|
3671
|
-
"x\n".repeat(20)
|
|
3672
|
-
);
|
|
3673
|
-
let raw = grok_raw_unfolded_paste(&marker);
|
|
3674
|
-
let (be, rec) = backend_raw_then_fold(&raw, GROK_INCIDENT_LINE, GROK_INCIDENT_LINE, 2);
|
|
3675
|
-
let report = be
|
|
3676
|
-
.inject(
|
|
3677
|
-
&Target::Pane(PaneId::new("%7")),
|
|
3678
|
-
&InjectPayload::Text(token_text),
|
|
3679
|
-
Key::Enter,
|
|
3680
|
-
true,
|
|
3681
|
-
)
|
|
3682
|
-
.expect("inject");
|
|
3683
|
-
assert_eq!(
|
|
3684
|
-
report.submit_verification,
|
|
3685
|
-
SubmitVerification::SubmitConsumptionUnverified,
|
|
3686
|
-
"raw visible then folded, placeholder stays: must not false-green delivered; got {:?}",
|
|
3687
|
-
report.submit_verification
|
|
3688
|
-
);
|
|
3689
|
-
let calls = rec.lock().unwrap().clone();
|
|
3690
|
-
let enters = count_submit_enters(&calls);
|
|
3691
|
-
assert!(
|
|
3692
|
-
enters >= 2,
|
|
3693
|
-
"placeholder still in composer must retry Enter; got {enters} calls={calls:?}"
|
|
3694
|
-
);
|
|
3695
|
-
let paste_n = count_paste_stage(&calls);
|
|
3696
|
-
let first_enter = calls.iter().position(|argv| {
|
|
3697
|
-
argv.get(1).map(String::as_str) == Some("send-keys")
|
|
3698
|
-
&& argv.iter().any(|a| a == "C-m" || a == "Enter")
|
|
3699
|
-
});
|
|
3700
|
-
let paste_after_enter = first_enter.map(|i| {
|
|
3701
|
-
calls[i + 1..]
|
|
3702
|
-
.iter()
|
|
3703
|
-
.filter(|argv| {
|
|
3704
|
-
matches!(
|
|
3705
|
-
argv.get(1).map(String::as_str),
|
|
3706
|
-
Some("load-buffer") | Some("set-buffer") | Some("paste-buffer")
|
|
3707
|
-
)
|
|
3708
|
-
})
|
|
3709
|
-
.count()
|
|
3710
|
-
});
|
|
3711
|
-
assert_eq!(
|
|
3712
|
-
paste_after_enter,
|
|
3713
|
-
Some(0),
|
|
3714
|
-
"retry must not re-paste (inject contract); paste_n={paste_n} calls={calls:?}"
|
|
3715
|
-
);
|
|
3716
|
-
}
|
|
3717
|
-
|
|
3718
|
-
#[test]
|
|
3719
|
-
fn grok_fold_worker_text_payload_polls_consumption() {
|
|
3720
|
-
assert!(
|
|
3721
|
-
!InjectPayload::Text("worker [team-agent-token:x]".to_string()).skip_consumption_poll(),
|
|
3722
|
-
"worker Text path poll_consumption=true; submit_attempt_limit is 3 not 1"
|
|
3723
|
-
);
|
|
3724
|
-
assert!(
|
|
3725
|
-
InjectPayload::TextSkipConsumptionPoll("leader [team-agent-token:x]".to_string())
|
|
3726
|
-
.skip_consumption_poll(),
|
|
3727
|
-
"leader skip path is the only poll_consumption=false arm"
|
|
3728
|
-
);
|
|
3729
|
-
}
|
|
3730
|
-
|
|
3731
|
-
#[test]
|
|
3732
|
-
fn provider_busy_signal_match_preserves_category_priority_and_tail_boundary() {
|
|
3733
|
-
let cases = [
|
|
3734
|
-
("working", BusySignalKind::Working),
|
|
3735
|
-
("thinking", BusySignalKind::Thinking),
|
|
3736
|
-
("processing", BusySignalKind::Processing),
|
|
3737
|
-
("esc to interrupt", BusySignalKind::EscToInterrupt),
|
|
3738
|
-
("โ ", BusySignalKind::SpinnerGlyph),
|
|
3739
|
-
("working โ ", BusySignalKind::Working),
|
|
3740
|
-
];
|
|
3741
|
-
for (text, expected) in cases {
|
|
3742
|
-
let matched = super::provider_busy_signal_match(text).expect("busy match");
|
|
3743
|
-
assert_eq!(matched.kind, expected, "text={text:?}");
|
|
3744
|
-
assert_eq!(matched.line_from_bottom, 0, "text={text:?}");
|
|
3745
|
-
assert!(super::provider_busy_signal_in_tail(text));
|
|
3746
|
-
}
|
|
3747
|
-
|
|
3748
|
-
let inside_bottom_15 = std::iter::once("working".to_string())
|
|
3749
|
-
.chain((0..14).map(|index| format!("tail-{index}")))
|
|
3750
|
-
.collect::<Vec<_>>()
|
|
3751
|
-
.join("\n");
|
|
3752
|
-
let matched = super::provider_busy_signal_match(&inside_bottom_15).expect("15th line");
|
|
3753
|
-
assert_eq!(matched.kind, BusySignalKind::Working);
|
|
3754
|
-
assert_eq!(matched.line_from_bottom, 14);
|
|
3755
|
-
|
|
3756
|
-
let outside_bottom_15 = std::iter::once("working".to_string())
|
|
3757
|
-
.chain((0..15).map(|index| format!("tail-{index}")))
|
|
3758
|
-
.collect::<Vec<_>>()
|
|
3759
|
-
.join("\n");
|
|
3760
|
-
assert!(super::provider_busy_signal_match(&outside_bottom_15).is_none());
|
|
3761
|
-
assert!(!super::provider_busy_signal_in_tail(&outside_bottom_15));
|
|
3762
|
-
}
|
|
3763
|
-
|
|
3764
|
-
const G4_TOKEN: &str = "[team-agent-token:msg_g4]";
|
|
3765
|
-
|
|
3766
|
-
#[test]
|
|
3767
|
-
fn g4_turn_verification_table() {
|
|
3768
|
-
use TurnVerification::{LeaderNewTurnBoundaryMissing, LeaderNewTurnBoundaryVerified, NotYetObserved};
|
|
3769
|
-
let cursor = format!("โฏ {G4_TOKEN}");
|
|
3770
|
-
let cases = [
|
|
3771
|
-
("grok_pending", "โ โฏ [Pasted: 42 lines] โ", LeaderNewTurnBoundaryMissing, ""),
|
|
3772
|
-
("claude_pending", "โฏ pasted text #4 +12 lines", LeaderNewTurnBoundaryMissing, ""),
|
|
3773
|
-
("cursor_pending", cursor.as_str(), LeaderNewTurnBoundaryMissing, ""),
|
|
3774
|
-
("claude_busy", "โถ Thinkingโฆ\nesc to interrupt", LeaderNewTurnBoundaryVerified, ""),
|
|
3775
|
-
("cursor_busy", "processing\nโฏ ", LeaderNewTurnBoundaryVerified, ""),
|
|
3776
|
-
("grok_busy", "working\nโฏ ", LeaderNewTurnBoundaryVerified, ""),
|
|
3777
|
-
("empty_unknown", "โฏ ", NotYetObserved, "empty composer and no busy is ไธ็ฅ้, never ๅผ่ท"),
|
|
3778
|
-
];
|
|
3779
|
-
for (id, text, expected, note) in cases {
|
|
3780
|
-
assert_eq!(observe_turn_from_capture(text, Some(G4_TOKEN)), expected, "{id}: {note}");
|
|
3781
|
-
}
|
|
3782
|
-
}
|
|
3783
|
-
|
|
3784
|
-
#[test]
|
|
3785
|
-
fn g4_turn_inject_grok_incident_line_does_not_report_started() {
|
|
3786
|
-
let token_text = "Team Agent message from leader:\n\nhi\n\n[team-agent-token:msg_g4_inject]";
|
|
3787
|
-
let (be, _rec) = backend_with(MockResp::Out(ok(GROK_INCIDENT_LINE)), vec![]);
|
|
3788
|
-
let report = be
|
|
3789
|
-
.inject(
|
|
3790
|
-
&Target::Pane(PaneId::new("%7")),
|
|
3791
|
-
&InjectPayload::Text(token_text.to_string()),
|
|
3792
|
-
Key::Enter,
|
|
3793
|
-
true,
|
|
3794
|
-
)
|
|
3795
|
-
.expect("inject runs");
|
|
3796
|
-
assert_ne!(
|
|
3797
|
-
report.turn_verification,
|
|
3798
|
-
TurnVerification::LeaderNewTurnBoundaryVerified,
|
|
3799
|
-
"unsubmitted grok paste must not report ๅผ่ท"
|
|
3800
|
-
);
|
|
3801
|
-
assert_eq!(
|
|
3802
|
-
report.turn_verification,
|
|
3803
|
-
TurnVerification::LeaderNewTurnBoundaryMissing
|
|
3804
|
-
);
|
|
3805
|
-
assert_eq!(
|
|
3806
|
-
report.submit_verification,
|
|
3807
|
-
SubmitVerification::SubmitConsumptionUnverified
|
|
3808
|
-
);
|
|
3809
|
-
}
|
|
3810
|
-
|
|
3811
|
-
#[test]
|
|
3812
|
-
fn g4_turn_inject_consumed_without_busy_is_unknown() {
|
|
3813
|
-
let token_text = "Team Agent message from leader:\n\nhi\n\n[team-agent-token:msg_g4_gone]";
|
|
3814
|
-
let visible = ok(token_text);
|
|
3815
|
-
let queued = vec![
|
|
3816
|
-
MockResp::Out(ok("")),
|
|
3817
|
-
MockResp::Out(ok("")),
|
|
3818
|
-
MockResp::Out(ok("")),
|
|
3819
|
-
MockResp::Out(visible.clone()),
|
|
3820
|
-
MockResp::Out(visible),
|
|
3821
|
-
MockResp::Out(ok("")),
|
|
3822
|
-
MockResp::Out(ok("")),
|
|
3823
|
-
];
|
|
3824
|
-
let (be, _rec) = backend_with(MockResp::Out(ok("โฏ ")), queued);
|
|
3825
|
-
let report = be
|
|
3826
|
-
.inject(
|
|
3827
|
-
&Target::Pane(PaneId::new("%7")),
|
|
3828
|
-
&InjectPayload::Text(token_text.to_string()),
|
|
3829
|
-
Key::Enter,
|
|
3830
|
-
true,
|
|
3831
|
-
)
|
|
3832
|
-
.expect("inject runs");
|
|
3833
|
-
assert_eq!(
|
|
3834
|
-
report.submit_verification,
|
|
3835
|
-
SubmitVerification::EnterSentWithoutPlaceholderCheck,
|
|
3836
|
-
"token gone is still consumed/delivered; that is not ๅผ่ท"
|
|
3837
|
-
);
|
|
3838
|
-
assert_eq!(
|
|
3839
|
-
report.turn_verification,
|
|
3840
|
-
TurnVerification::NotYetObserved,
|
|
3841
|
-
"composer empty without busy is ไธ็ฅ้, not ๅผ่ท"
|
|
3842
|
-
);
|
|
3843
|
-
}
|
|
3844
|
-
|
|
3845
|
-
/// capture-pane ไธๅพๅคฑ่ดฅ๏ผๅ
ถๅฎ tmux ๅฝไปคๆๅใ็จไบใ่ฏปๆฐๆฟไธๅฐใ่ไธๆฏใ่ฏปๆฐไธไธๆ ทใใ
|
|
3846
|
-
struct CapturePaneFailRunner {
|
|
3847
|
-
recorded: RecordedArgv,
|
|
3848
|
-
}
|
|
3849
|
-
|
|
3850
|
-
impl CommandRunner for CapturePaneFailRunner {
|
|
3851
|
-
fn run(&self, argv: &[String]) -> Result<CommandOutput, std::io::Error> {
|
|
3852
|
-
self.recorded.lock().unwrap().push(argv.to_vec());
|
|
3853
|
-
if argv.get(1).map(String::as_str) == Some("capture-pane") {
|
|
3854
|
-
return Err(std::io::Error::new(
|
|
3855
|
-
std::io::ErrorKind::Other,
|
|
3856
|
-
"mock capture missing",
|
|
3857
|
-
));
|
|
3858
|
-
}
|
|
3859
|
-
Ok(ok(""))
|
|
3860
|
-
}
|
|
3861
|
-
|
|
3862
|
-
fn run_with_stdin(
|
|
3863
|
-
&self,
|
|
3864
|
-
argv: &[String],
|
|
3865
|
-
_stdin: &str,
|
|
3866
|
-
) -> Result<CommandOutput, std::io::Error> {
|
|
3867
|
-
self.run(argv)
|
|
3868
|
-
}
|
|
3869
|
-
}
|
|
3870
|
-
|
|
3871
|
-
fn backend_capture_pane_fail() -> (TmuxBackend, RecordedArgv) {
|
|
3872
|
-
let recorded = Arc::new(Mutex::new(Vec::new()));
|
|
3873
|
-
let runner = CapturePaneFailRunner {
|
|
3874
|
-
recorded: Arc::clone(&recorded),
|
|
3875
|
-
};
|
|
3876
|
-
(TmuxBackend::with_runner(Box::new(runner)), recorded)
|
|
3877
|
-
}
|
|
3878
|
-
|
|
3879
|
-
/// P0 unknown-not-success: capture() Err ๆฏใๆฒก่ฝๅคๆญใ๏ผไธๅพไธ Some(true) ๅๅผใ
|
|
3880
|
-
/// ้ฝฟ่ฆ็ใ่ฏปๆฐๆฟไธๅฐใ๏ผไธๆฏใ่ฏปๆฐไธไธๆ ทใใ
|
|
3881
|
-
#[test]
|
|
3882
|
-
fn p0_capture_failure_is_unverified_not_enter_sent() {
|
|
3883
|
-
let token_text = "Team Agent message from leader:\n\nhi\n\n[team-agent-token:msg_cap_fail]";
|
|
3884
|
-
let (be, rec) = backend_capture_pane_fail();
|
|
3885
|
-
let report = be
|
|
3886
|
-
.inject(
|
|
3887
|
-
&Target::Pane(PaneId::new("%7")),
|
|
3888
|
-
&InjectPayload::Text(token_text.to_string()),
|
|
3889
|
-
Key::Enter,
|
|
3890
|
-
true,
|
|
3891
|
-
)
|
|
3892
|
-
.expect("inject runs");
|
|
3893
|
-
assert_eq!(
|
|
3894
|
-
report.submit_verification,
|
|
3895
|
-
SubmitVerification::SubmitConsumptionUnverified,
|
|
3896
|
-
"consumed=None (capture missing) must not share \
|
|
3897
|
-
EnterSentWithoutPlaceholderCheck with Some(true); got {:?}",
|
|
3898
|
-
report.submit_verification
|
|
3899
|
-
);
|
|
3900
|
-
assert!(
|
|
3901
|
-
!crate::messaging::delivery::inject_submit_verified(&report),
|
|
3902
|
-
"no positive consumption signal โ submit_verified must be false; report={report:?}"
|
|
3903
|
-
);
|
|
3904
|
-
let calls = rec.lock().unwrap().clone();
|
|
3905
|
-
assert_eq!(
|
|
3906
|
-
count_submit_enters(&calls),
|
|
3907
|
-
1,
|
|
3908
|
-
"capture retry must not send extra Enter; calls={calls:?}"
|
|
3909
|
-
);
|
|
3910
|
-
}
|
|
3911
|
-
|
|
3912
|
-
/// P0: capture ๅคฑ่ดฅๅ
้่ฏปๅๅค๏ผ้่ฏ่ฎกๅ
ฅ attempts๏ผไธ้็ฒๆๆฌใ
|
|
3913
|
-
#[test]
|
|
3914
|
-
fn p0_capture_failure_retries_read_and_counts_attempts() {
|
|
3915
|
-
let token_text = "Team Agent message from leader:\n\nhi\n\n[team-agent-token:msg_cap_retry]";
|
|
3916
|
-
let (be, rec) = backend_capture_pane_fail();
|
|
3917
|
-
let report = be
|
|
3918
|
-
.inject(
|
|
3919
|
-
&Target::Pane(PaneId::new("%7")),
|
|
3920
|
-
&InjectPayload::Text(token_text.to_string()),
|
|
3921
|
-
Key::Enter,
|
|
3922
|
-
true,
|
|
3923
|
-
)
|
|
3924
|
-
.expect("inject runs");
|
|
3925
|
-
assert!(
|
|
3926
|
-
report.attempts > 1,
|
|
3927
|
-
"capture failure must retry the read and count it in attempts; got attempts={}",
|
|
3928
|
-
report.attempts
|
|
3929
|
-
);
|
|
3930
|
-
let calls = rec.lock().unwrap().clone();
|
|
3931
|
-
let captures = calls
|
|
3932
|
-
.iter()
|
|
3933
|
-
.filter(|argv| argv.get(1).map(String::as_str) == Some("capture-pane"))
|
|
3934
|
-
.count();
|
|
3935
|
-
assert!(
|
|
3936
|
-
captures >= 2,
|
|
3937
|
-
"must re-read capture after failure; capture-pane count={captures} calls={calls:?}"
|
|
3938
|
-
);
|
|
3939
|
-
assert_eq!(
|
|
3940
|
-
count_submit_enters(&calls),
|
|
3941
|
-
1,
|
|
3942
|
-
"retry is capture-only; extra Enter is forbidden; calls={calls:?}"
|
|
3943
|
-
);
|
|
3944
|
-
let pastes = calls
|
|
3945
|
-
.iter()
|
|
3946
|
-
.filter(|argv| argv.get(1).map(String::as_str) == Some("paste-buffer"))
|
|
3947
|
-
.count();
|
|
3948
|
-
assert_eq!(
|
|
3949
|
-
pastes, 1,
|
|
3950
|
-
"must not re-paste on capture failure; paste-buffer count={pastes}"
|
|
3951
|
-
);
|
|
3952
|
-
}
|
|
3953
|
-
|
|
3954
|
-
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
3955
|
-
// Unverified ไนๅ่กฅไธ้ข C-m๏ผTUI composer ๆฎ็ / ๆ่ก๏ผ๏ผbusy-shell ไธ่กฅ
|
|
3956
|
-
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
3957
|
-
|
|
3958
|
-
struct NthEnterClearRunner {
|
|
3959
|
-
recorded: RecordedArgv,
|
|
3960
|
-
pending: String,
|
|
3961
|
-
cleared: String,
|
|
3962
|
-
enters: std::sync::atomic::AtomicU32,
|
|
3963
|
-
clear_after: u32,
|
|
3964
|
-
}
|
|
3965
|
-
|
|
3966
|
-
impl CommandRunner for NthEnterClearRunner {
|
|
3967
|
-
fn run(&self, argv: &[String]) -> Result<CommandOutput, std::io::Error> {
|
|
3968
|
-
self.recorded.lock().unwrap().push(argv.to_vec());
|
|
3969
|
-
if argv.get(1).map(String::as_str) == Some("send-keys")
|
|
3970
|
-
&& argv.iter().any(|a| a == "C-m" || a == "Enter")
|
|
3971
|
-
{
|
|
3972
|
-
self.enters.fetch_add(1, Ordering::SeqCst);
|
|
3973
|
-
}
|
|
3974
|
-
let stdout = match argv.get(1).map(String::as_str) {
|
|
3975
|
-
Some("capture-pane") => {
|
|
3976
|
-
if self.enters.load(Ordering::SeqCst) >= self.clear_after {
|
|
3977
|
-
self.cleared.clone()
|
|
3978
|
-
} else {
|
|
3979
|
-
self.pending.clone()
|
|
3980
|
-
}
|
|
3981
|
-
}
|
|
3982
|
-
Some("display-message") => "0\n".to_string(),
|
|
3983
|
-
_ => String::new(),
|
|
3984
|
-
};
|
|
3985
|
-
Ok(ok(&stdout))
|
|
3986
|
-
}
|
|
3987
|
-
|
|
3988
|
-
fn run_with_stdin(
|
|
3989
|
-
&self,
|
|
3990
|
-
argv: &[String],
|
|
3991
|
-
_stdin: &str,
|
|
3992
|
-
) -> Result<CommandOutput, std::io::Error> {
|
|
3993
|
-
self.run(argv)
|
|
3994
|
-
}
|
|
3995
|
-
}
|
|
3996
|
-
|
|
3997
|
-
fn backend_clears_after_n_enters(
|
|
3998
|
-
pending: &str,
|
|
3999
|
-
cleared: &str,
|
|
4000
|
-
clear_after: u32,
|
|
4001
|
-
) -> (TmuxBackend, RecordedArgv) {
|
|
4002
|
-
let recorded = Arc::new(Mutex::new(Vec::new()));
|
|
4003
|
-
let runner = NthEnterClearRunner {
|
|
4004
|
-
recorded: Arc::clone(&recorded),
|
|
4005
|
-
pending: pending.to_string(),
|
|
4006
|
-
cleared: cleared.to_string(),
|
|
4007
|
-
enters: std::sync::atomic::AtomicU32::new(0),
|
|
4008
|
-
clear_after,
|
|
4009
|
-
};
|
|
4010
|
-
(TmuxBackend::with_runner(Box::new(runner)), recorded)
|
|
4011
|
-
}
|
|
4012
|
-
|
|
4013
|
-
fn wrapped_identity_with_skin(marker: &str, skin: &str) -> String {
|
|
4014
|
-
// tmux 80 ๅๆ่ก๏ผๅ่กไธๅซๅฎๆด token๏ผๆผๆฅๅๆๅซใ
|
|
4015
|
-
let split_at = marker.len() / 2;
|
|
4016
|
-
format!("{skin}\n{}\n{}\n", &marker[..split_at], &marker[split_at..])
|
|
4017
|
-
}
|
|
4018
|
-
|
|
4019
|
-
fn wrapped_unverified_composer(marker: &str) -> String {
|
|
4020
|
-
wrapped_identity_with_skin(marker, "tui-ready composer>")
|
|
4021
|
-
}
|
|
4022
|
-
|
|
4023
|
-
#[test]
|
|
4024
|
-
fn should_resend_enter_after_unverified_true_on_wrapped_tui_token() {
|
|
4025
|
-
let marker = "[team-agent-token:msg_wrap_gate]";
|
|
4026
|
-
let text = wrapped_unverified_composer(marker);
|
|
4027
|
-
assert!(
|
|
4028
|
-
!super::should_resubmit_enter(&text, marker, None),
|
|
4029
|
-
"per-line token_in_bottom_n must stay false on wrap"
|
|
4030
|
-
);
|
|
4031
|
-
assert!(
|
|
4032
|
-
super::should_resend_enter_after_unverified(&text, marker, None),
|
|
4033
|
-
"joined token identity must allow the one Unverified resend"
|
|
4034
|
-
);
|
|
4035
|
-
}
|
|
4036
|
-
|
|
4037
|
-
#[test]
|
|
4038
|
-
fn should_resend_wrapped_identity_on_three_tui_skins() {
|
|
4039
|
-
let marker = "[team-agent-token:msg_skins]";
|
|
4040
|
-
for skin in ["โฏ ", "> ", "ready."] {
|
|
4041
|
-
let text = wrapped_identity_with_skin(marker, skin);
|
|
4042
|
-
assert!(
|
|
4043
|
-
super::should_resend_enter_after_unverified(&text, marker, None),
|
|
4044
|
-
"skin {skin:?} with this-paste token must resend"
|
|
4045
|
-
);
|
|
4046
|
-
}
|
|
4047
|
-
}
|
|
4048
|
-
|
|
4049
|
-
#[test]
|
|
4050
|
-
fn should_resend_false_when_payload_has_prompt_glyphs_but_identity_absent() {
|
|
4051
|
-
let marker = "[team-agent-token:msg_glyph_fp]";
|
|
4052
|
-
let text = "STARTED\nsleep holds pty\nsee composer> and โฏ in the payload\n>\n";
|
|
4053
|
-
assert!(
|
|
4054
|
-
!super::this_paste_identity_in_composer(text, marker, None),
|
|
4055
|
-
"glyphs in payload are not this-paste identity"
|
|
4056
|
-
);
|
|
4057
|
-
assert!(
|
|
4058
|
-
!super::should_resend_enter_after_unverified(text, marker, None),
|
|
4059
|
-
"payload composer>/โฏ must not by themselves trigger resend"
|
|
4060
|
-
);
|
|
4061
|
-
}
|
|
4062
|
-
|
|
4063
|
-
#[test]
|
|
4064
|
-
fn should_resend_enter_after_unverified_true_when_unwrapped_token_still_in_tui() {
|
|
4065
|
-
let marker = "[team-agent-token:msg_still_tui]";
|
|
4066
|
-
let text = format!("> {marker}\n");
|
|
4067
|
-
assert!(super::should_resubmit_enter(&text, marker, None));
|
|
4068
|
-
assert!(
|
|
4069
|
-
super::should_resend_enter_after_unverified(&text, marker, None),
|
|
4070
|
-
"bare > skin with token identity still in composer must resend"
|
|
4071
|
-
);
|
|
4072
|
-
}
|
|
4073
|
-
|
|
4074
|
-
#[test]
|
|
4075
|
-
fn wrap_gap_false_when_a_already_sees_grok_latch() {
|
|
4076
|
-
let marker = "[team-agent-token:msg_grok_stay]";
|
|
4077
|
-
let tracked = Some(super::PasteLatch::GrokLineCount(42));
|
|
4078
|
-
assert!(super::should_resubmit_enter(
|
|
4079
|
-
GROK_INCIDENT_LINE,
|
|
4080
|
-
marker,
|
|
4081
|
-
tracked
|
|
4082
|
-
));
|
|
4083
|
-
assert!(super::should_resend_enter_after_unverified(
|
|
4084
|
-
GROK_INCIDENT_LINE,
|
|
4085
|
-
marker,
|
|
4086
|
-
tracked
|
|
4087
|
-
));
|
|
4088
|
-
assert!(
|
|
4089
|
-
!super::should_resend_unverified_wrap_gap(GROK_INCIDENT_LINE, marker, tracked),
|
|
4090
|
-
"A latch path already covers grok-fold stay; invert wrap-gap must turn this red"
|
|
4091
|
-
);
|
|
4092
|
-
}
|
|
4093
|
-
|
|
4094
|
-
#[test]
|
|
4095
|
-
fn wrap_gap_true_on_joined_token_a_cannot_see() {
|
|
4096
|
-
let marker = "[team-agent-token:msg_wrap_gate]";
|
|
4097
|
-
let text = wrapped_unverified_composer(marker);
|
|
4098
|
-
assert!(!super::should_resubmit_enter(&text, marker, None));
|
|
4099
|
-
assert!(
|
|
4100
|
-
super::should_resend_unverified_wrap_gap(&text, marker, None),
|
|
4101
|
-
"B must still cover the wrap gap A cannot see"
|
|
4102
|
-
);
|
|
4103
|
-
}
|