fix(runtime): isolate agent state by project (#101)
This commit is contained in:
@ -156,7 +156,8 @@ fn insert_pty(
|
||||
agent_id: AgentId,
|
||||
node_id: NodeId,
|
||||
) {
|
||||
sessions.insert(
|
||||
sessions.insert_in_project(
|
||||
project().id,
|
||||
PtyHandle { session_id },
|
||||
TerminalSession::starting(
|
||||
session_id,
|
||||
@ -175,7 +176,8 @@ fn insert_structured(
|
||||
node_id: NodeId,
|
||||
) -> Arc<AtomicBool> {
|
||||
let flag = Arc::new(AtomicBool::new(false));
|
||||
sessions.insert(
|
||||
sessions.insert_in_project(
|
||||
project().id,
|
||||
Arc::new(FakeSession {
|
||||
id: session_id,
|
||||
shutdown_called: Arc::clone(&flag),
|
||||
@ -210,8 +212,14 @@ fn attach_pty_rebinds_node_without_changing_session() {
|
||||
assert_eq!(out.node_id, nid(200), "view rebound to the new node");
|
||||
assert_eq!(out.kind, LiveSessionKind::Pty);
|
||||
// The registry reflects the new host node, same session.
|
||||
assert_eq!(f.pty.node_for_agent(&a), Some(nid(200)));
|
||||
assert_eq!(f.pty.session_for_agent(&a), Some(sid(1)));
|
||||
assert_eq!(
|
||||
f.pty.node_for_agent_in_project(project().id, &a),
|
||||
Some(nid(200))
|
||||
);
|
||||
assert_eq!(
|
||||
f.pty.session_for_agent_in_project(project().id, &a),
|
||||
Some(sid(1))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -232,7 +240,10 @@ fn attach_structured_rebinds_node() {
|
||||
assert_eq!(out.session_id, sid(2));
|
||||
assert_eq!(out.node_id, nid(300));
|
||||
assert_eq!(out.kind, LiveSessionKind::Structured);
|
||||
assert_eq!(f.structured.node_for_agent(&a), Some(nid(300)));
|
||||
assert_eq!(
|
||||
f.structured.node_for_agent_in_project(project().id, &a),
|
||||
Some(nid(300))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -309,7 +320,7 @@ async fn stop_pty_kills_and_removes_session() {
|
||||
// Delegated to the close primitive: process killed and registry emptied.
|
||||
assert_eq!(f.pty_port.kills(), vec![sid(1)]);
|
||||
assert!(f.pty.is_empty(), "live session removed from the registry");
|
||||
assert_eq!(f.pty.session_for_agent(&a), None);
|
||||
assert_eq!(f.pty.session_for_agent_in_project(project().id, &a), None);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@ -331,7 +342,11 @@ async fn stop_structured_shuts_down_and_removes_session() {
|
||||
assert_eq!(out.kind, LiveSessionKind::Structured);
|
||||
assert!(flag.load(Ordering::SeqCst), "session.shutdown() was called");
|
||||
assert!(f.structured.is_empty(), "live session removed");
|
||||
assert_eq!(f.structured.session_id_for_agent(&a), None);
|
||||
assert_eq!(
|
||||
f.structured
|
||||
.session_id_for_agent_in_project(project().id, &a),
|
||||
None
|
||||
);
|
||||
// No PTY was touched.
|
||||
assert!(f.pty_port.kills().is_empty());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user