summaryrefslogtreecommitdiff
path: root/src/app
diff options
context:
space:
mode:
Diffstat (limited to 'src/app')
-rw-r--r--src/app/api.rs12
-rw-r--r--src/app/api/agents.rs62
2 files changed, 72 insertions, 2 deletions
diff --git a/src/app/api.rs b/src/app/api.rs
index 9bd02481..30fc3be2 100644
--- a/src/app/api.rs
+++ b/src/app/api.rs
@@ -2067,7 +2067,13 @@ mod tests {
observed_at: std::time::Instant::now(),
});
- assert!(app.state.terminals[&terminal_id].agent_name.is_none());
+ // The release event is this test's subject; the name outliving the
+ // observation is pinned by
+ // `a_process_exit_observation_alone_does_not_free_the_name`.
+ assert_eq!(
+ app.state.terminals[&terminal_id].agent_name.as_deref(),
+ agent_name
+ );
assert!(event_hub.events_after(0).iter().any(|(_, event)| matches!(
&event.data,
crate::api::schema::EventData::PaneAgentDetected {
@@ -2123,7 +2129,9 @@ mod tests {
let terminal = &app.state.terminals[&terminal_id];
assert_eq!(terminal.state, AgentState::Idle);
- assert!(terminal.agent_name.is_none());
+ // Releasing the registration does not free the name yet; a wrong
+ // observation must not cost a live agent the handle its owner gave it.
+ assert_eq!(terminal.agent_name.as_deref(), Some("reviewer"));
assert!(event_hub.events_after(0).iter().any(|(_, event)| matches!(
event.data,
crate::api::schema::EventData::PaneAgentDetected { released: true, .. }
diff --git a/src/app/api/agents.rs b/src/app/api/agents.rs
index 1c0a5369..9289ae02 100644
--- a/src/app/api/agents.rs
+++ b/src/app/api/agents.rs
@@ -473,6 +473,68 @@ mod tests {
}
#[tokio::test]
+ async fn a_false_process_exit_makes_a_named_live_agent_unreachable_by_name() {
+ // Reproduces the registration loss reported on #3225 by rszrszrsz:
+ // a live agent pane with an assigned name stops resolving by that name
+ // while its process keeps running, and renaming is the only recovery.
+ let mut app = app_with_agent();
+ let pane_id = app.state.workspaces[0].tabs[0].root_pane;
+ let terminal_id = app.state.workspaces[0].tabs[0].panes[&pane_id]
+ .attached_terminal_id
+ .clone();
+ let observed_at = std::time::Instant::now();
+ let terminal = app.state.terminals.get_mut(&terminal_id).unwrap();
+ terminal.set_detected_state(Some(Agent::Pi), AgentState::Working);
+ terminal.set_agent_name("reviewer".into());
+
+ let found = app.handle_agent_get(
+ "req:before".into(),
+ AgentTarget {
+ target: "reviewer".into(),
+ },
+ );
+ assert!(
+ serde_json::from_str::<SuccessResponse>(&found).is_ok(),
+ "the assigned name must resolve while the agent is running: {found}"
+ );
+
+ // One process-exit observation, then the same agent is observed alive
+ // again on the next probe - the process never actually went away.
+ app.handle_internal_event(crate::events::AppEvent::StateChanged {
+ pane_id,
+ agent: Some(Agent::Pi),
+ state: AgentState::Idle,
+ visible_blocker: false,
+ visible_working: false,
+ process_exited: true,
+ observed_at,
+ });
+ app.handle_internal_event(crate::events::AppEvent::AgentProcessDetected {
+ pane_id,
+ agent: Agent::Pi,
+ observed_at: observed_at + std::time::Duration::from_secs(1),
+ });
+
+ let terminal = &app.state.terminals[&terminal_id];
+ assert_eq!(
+ terminal.detected_agent,
+ Some(Agent::Pi),
+ "the agent process is still there"
+ );
+
+ let after = app.handle_agent_get(
+ "req:after".into(),
+ AgentTarget {
+ target: "reviewer".into(),
+ },
+ );
+ assert!(
+ serde_json::from_str::<SuccessResponse>(&after).is_ok(),
+ "a live agent must stay reachable by its assigned name: {after}"
+ );
+ }
+
+ #[tokio::test]
async fn agent_prompt_sends_text_then_delays_enter() {
let mut app = app_with_agent();
let pane_id = app.state.workspaces[0].tabs[0].root_pane;