huskies: merge 735_story_attach_statuseventbuffer_to_each_agent_session_scoped_per_project_reset_on_restart
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
//! Test helpers for the agent pool — in-memory pool construction and assertions.
|
||||
use crate::service::status::buffer::{BufferedItem, StatusEventBuffer};
|
||||
use crate::worktree::WorktreeInfo;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{Arc, Mutex};
|
||||
@@ -36,6 +37,7 @@ impl AgentPool {
|
||||
merge_failure_reported: false,
|
||||
throttled: false,
|
||||
termination_reason: None,
|
||||
status_buffer: None,
|
||||
},
|
||||
);
|
||||
tx
|
||||
@@ -73,6 +75,7 @@ impl AgentPool {
|
||||
merge_failure_reported: false,
|
||||
throttled: false,
|
||||
termination_reason: None,
|
||||
status_buffer: None,
|
||||
},
|
||||
);
|
||||
tx
|
||||
@@ -107,6 +110,7 @@ impl AgentPool {
|
||||
merge_failure_reported: false,
|
||||
throttled: false,
|
||||
termination_reason: None,
|
||||
status_buffer: None,
|
||||
},
|
||||
);
|
||||
tx
|
||||
@@ -140,11 +144,61 @@ impl AgentPool {
|
||||
merge_failure_reported: false,
|
||||
throttled: false,
|
||||
termination_reason: None,
|
||||
status_buffer: None,
|
||||
},
|
||||
);
|
||||
tx
|
||||
}
|
||||
|
||||
/// Test helper: inject an agent whose `status_buffer` is subscribed to the
|
||||
/// pool's [`StatusBroadcaster`]. Use [`drain_agent_status_buffer`] to read
|
||||
/// accumulated events after publishing to `pool.status_broadcaster()`.
|
||||
pub fn inject_test_agent_with_live_buffer(
|
||||
&self,
|
||||
story_id: &str,
|
||||
agent_name: &str,
|
||||
status: AgentStatus,
|
||||
) -> broadcast::Sender<AgentEvent> {
|
||||
let (tx, _) = broadcast::channel::<AgentEvent>(64);
|
||||
let key = composite_key(story_id, agent_name);
|
||||
let mut agents = self.agents.lock().unwrap();
|
||||
agents.insert(
|
||||
key,
|
||||
StoryAgent {
|
||||
agent_name: agent_name.to_string(),
|
||||
status,
|
||||
worktree_info: None,
|
||||
session_id: None,
|
||||
tx: tx.clone(),
|
||||
task_handle: None,
|
||||
event_log: Arc::new(Mutex::new(Vec::new())),
|
||||
completion: None,
|
||||
project_root: None,
|
||||
log_session_id: None,
|
||||
merge_failure_reported: false,
|
||||
throttled: false,
|
||||
termination_reason: None,
|
||||
status_buffer: Some(StatusEventBuffer::new(&self.status_broadcaster)),
|
||||
},
|
||||
);
|
||||
tx
|
||||
}
|
||||
|
||||
/// Test helper: drain all buffered status events from the specified agent's
|
||||
/// [`StatusEventBuffer`]. Returns `None` if the agent does not exist or has
|
||||
/// no buffer attached.
|
||||
pub fn drain_agent_status_buffer(
|
||||
&self,
|
||||
story_id: &str,
|
||||
agent_name: &str,
|
||||
) -> Option<Vec<BufferedItem>> {
|
||||
let agents = self.agents.lock().unwrap();
|
||||
let key = composite_key(story_id, agent_name);
|
||||
agents
|
||||
.get(&key)
|
||||
.and_then(|a| a.status_buffer.as_ref().map(|b| b.drain()))
|
||||
}
|
||||
|
||||
/// Inject a Running agent with a pre-built (possibly finished) task handle.
|
||||
/// Used by watchdog tests to simulate an orphaned agent.
|
||||
pub fn inject_test_agent_with_handle(
|
||||
@@ -173,6 +227,7 @@ impl AgentPool {
|
||||
merge_failure_reported: false,
|
||||
throttled: false,
|
||||
termination_reason: None,
|
||||
status_buffer: None,
|
||||
},
|
||||
);
|
||||
tx
|
||||
|
||||
Reference in New Issue
Block a user