feat(backend,application,frontend,domain,web-server,app-tauri): bouton Redémarrer l'agent dans la barre supérieure des cellules — #317 (QA verte)
La cellule expose un bouton Redémarrer l'agent valable pour les trois modes de présentation (headless, TUI native, CLI custom), sans jamais prendre la présentation pour vérité runtime. - Application: use case RestartCellAgentRuntime validant le binding exact cellule/runtime via les snapshots live (RestartRuntimeNotFound, ConflictAgentVisibleElsewhere, AgentNotBoundToCell) puis déléguant au scheduler self-restart existant (schedule_cell); CellAgentPresentation purement informationnelle. - Backend/app-tauri/web-server: commande restart_cell_agent sur contrat DTO identique Tauri/HTTP, stop borné par timeout typé (RestartStopTimeout), relance préservant routage TUI natif, géométrie de cellule (node/rows/cols) et conversation; évenements domaine enrichis. - Frontend: bouton dans la barre de cellule avec confirmation, overlay d'état Redémarrage…/échec (libellés par code d'erreur, Fermer/ Réessayer), gardes d'identité de cellule et de restarts externes, gateway/mock/http adapters et ports alignés. - Tests: dto_agents, workstate_actions, contrats web-server, LayoutGrid.cellControlsLayering, adapters agent/mock/http. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -11,9 +11,10 @@ use std::sync::{Arc, Mutex};
|
||||
use async_trait::async_trait;
|
||||
|
||||
use application::{
|
||||
AttachLiveAgent, AttachLiveAgentInput, CloseTerminal, LiveRuntimeState, LiveSessionKind,
|
||||
LiveSessions, StopAgentExecutionCascade, StopLiveAgent, StopLiveAgentInput, StructuredSessions,
|
||||
TerminalSessions,
|
||||
AgentRestartScheduled, AgentSelfRestartScheduler, AppError, AttachLiveAgent,
|
||||
AttachLiveAgentInput, CellAgentPresentation, CloseTerminal, LiveRuntimeState, LiveSessionKind,
|
||||
LiveSessions, RestartCellAgentRuntime, RestartCellAgentRuntimeInput, StopAgentExecutionCascade,
|
||||
StopLiveAgent, StopLiveAgentInput, StructuredSessions, TerminalSessions,
|
||||
};
|
||||
use domain::ports::{
|
||||
AgentSession, AgentSessionError, ExitStatus, OutputStream, PtyError, PtyHandle, PtyPort,
|
||||
@ -21,7 +22,7 @@ use domain::ports::{
|
||||
};
|
||||
use domain::Project;
|
||||
use domain::{
|
||||
AgentId, NodeId, ProjectId, ProjectPath, PtySize, RemoteRef, SessionId, SessionKind,
|
||||
AgentId, LayoutId, NodeId, ProjectId, ProjectPath, PtySize, RemoteRef, SessionId, SessionKind,
|
||||
TerminalSession,
|
||||
};
|
||||
use uuid::Uuid;
|
||||
@ -131,6 +132,35 @@ struct FakeCascade {
|
||||
calls: Mutex<Vec<(ProjectId, AgentId)>>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct FakeRestartScheduler {
|
||||
calls: Mutex<Vec<(ProjectId, AgentId, NodeId)>>,
|
||||
}
|
||||
|
||||
impl AgentSelfRestartScheduler for FakeRestartScheduler {
|
||||
fn schedule(
|
||||
&self,
|
||||
_project: &Project,
|
||||
_agent: AgentId,
|
||||
_reason: Option<String>,
|
||||
) -> Result<AgentRestartScheduled, AppError> {
|
||||
unreachable!("cell restart must use the cell-aware scheduler seam")
|
||||
}
|
||||
|
||||
fn schedule_cell(
|
||||
&self,
|
||||
project: &Project,
|
||||
agent: AgentId,
|
||||
node: NodeId,
|
||||
_reason: Option<String>,
|
||||
) -> Result<AgentRestartScheduled, AppError> {
|
||||
self.calls.lock().unwrap().push((project.id, agent, node));
|
||||
Ok(AgentRestartScheduled {
|
||||
restart_id: "restart-cell-test".to_owned(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl StopAgentExecutionCascade for FakeCascade {
|
||||
async fn stop_agent_execution_children(&self, project: &Project, agent_id: AgentId) {
|
||||
@ -148,6 +178,8 @@ struct Fixture {
|
||||
pty: Arc<TerminalSessions>,
|
||||
structured: Arc<StructuredSessions>,
|
||||
pty_port: Arc<FakePty>,
|
||||
restart: RestartCellAgentRuntime,
|
||||
restart_scheduler: Arc<FakeRestartScheduler>,
|
||||
}
|
||||
|
||||
fn fixture() -> Fixture {
|
||||
@ -159,12 +191,32 @@ fn fixture() -> Fixture {
|
||||
Arc::clone(&pty_port) as Arc<dyn PtyPort>,
|
||||
Arc::clone(&pty),
|
||||
));
|
||||
let restart_scheduler = Arc::new(FakeRestartScheduler::default());
|
||||
Fixture {
|
||||
attach: AttachLiveAgent::new(Arc::clone(&live)),
|
||||
stop: StopLiveAgent::new(Arc::clone(&live), close),
|
||||
pty,
|
||||
structured,
|
||||
pty_port,
|
||||
restart: RestartCellAgentRuntime::new(
|
||||
Arc::clone(&live),
|
||||
Arc::clone(&restart_scheduler) as Arc<dyn AgentSelfRestartScheduler>,
|
||||
),
|
||||
restart_scheduler,
|
||||
}
|
||||
}
|
||||
|
||||
fn restart_input(
|
||||
agent_id: AgentId,
|
||||
node_id: NodeId,
|
||||
presentation: CellAgentPresentation,
|
||||
) -> RestartCellAgentRuntimeInput {
|
||||
RestartCellAgentRuntimeInput {
|
||||
project: project(),
|
||||
node_id,
|
||||
agent_id,
|
||||
presentation,
|
||||
layout_id: Some(LayoutId::from_uuid(Uuid::from_u128(500))),
|
||||
}
|
||||
}
|
||||
|
||||
@ -315,6 +367,106 @@ fn attach_same_node_is_idempotent() {
|
||||
assert_eq!(f.pty.len(), 1, "no extra session created");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RestartCellAgentRuntime
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn restart_cell_accepts_tui_and_preserves_exact_binding() {
|
||||
let f = fixture();
|
||||
let agent = aid(10);
|
||||
let node = nid(100);
|
||||
insert_pty(&f.pty, sid(1), agent, node);
|
||||
|
||||
let out = f
|
||||
.restart
|
||||
.execute(restart_input(agent, node, CellAgentPresentation::Tui))
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(out.restart_id, "restart-cell-test");
|
||||
assert_eq!(out.agent_id, agent);
|
||||
assert_eq!(out.node_id, node);
|
||||
assert_eq!(out.kind, LiveSessionKind::Pty);
|
||||
assert_eq!(out.presentation, CellAgentPresentation::Tui);
|
||||
assert_eq!(
|
||||
*f.restart_scheduler.calls.lock().unwrap(),
|
||||
vec![(project().id, agent, node)]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restart_cell_accepts_structured_custom_cli_and_headless_hints() {
|
||||
for presentation in [
|
||||
CellAgentPresentation::CustomCli,
|
||||
CellAgentPresentation::Headless,
|
||||
] {
|
||||
let f = fixture();
|
||||
let agent = aid(10);
|
||||
let node = nid(100);
|
||||
insert_structured(&f.structured, sid(2), agent, node);
|
||||
|
||||
let out = f
|
||||
.restart
|
||||
.execute(restart_input(agent, node, presentation))
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(out.kind, LiveSessionKind::Structured);
|
||||
assert_eq!(out.presentation, presentation);
|
||||
assert_eq!(f.restart_scheduler.calls.lock().unwrap().len(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restart_cell_rejects_stale_agent_or_node_without_scheduling() {
|
||||
let f = fixture();
|
||||
let agent = aid(10);
|
||||
insert_pty(&f.pty, sid(1), agent, nid(100));
|
||||
|
||||
let error = f
|
||||
.restart
|
||||
.execute(restart_input(
|
||||
agent,
|
||||
nid(999),
|
||||
CellAgentPresentation::Unknown,
|
||||
))
|
||||
.unwrap_err();
|
||||
|
||||
assert_eq!(error.code(), "AGENT_NOT_BOUND_TO_CELL");
|
||||
assert!(f.restart_scheduler.calls.lock().unwrap().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restart_cell_rejects_missing_runtime_without_scheduling() {
|
||||
let f = fixture();
|
||||
let error = f
|
||||
.restart
|
||||
.execute(restart_input(
|
||||
aid(999),
|
||||
nid(100),
|
||||
CellAgentPresentation::Unknown,
|
||||
))
|
||||
.unwrap_err();
|
||||
|
||||
assert_eq!(error.code(), "RUNTIME_NOT_FOUND");
|
||||
assert!(f.restart_scheduler.calls.lock().unwrap().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restart_cell_rejects_agent_visible_in_multiple_live_cells() {
|
||||
let f = fixture();
|
||||
let agent = aid(10);
|
||||
insert_pty(&f.pty, sid(1), agent, nid(100));
|
||||
insert_structured(&f.structured, sid(2), agent, nid(200));
|
||||
|
||||
let error = f
|
||||
.restart
|
||||
.execute(restart_input(agent, nid(100), CellAgentPresentation::Tui))
|
||||
.unwrap_err();
|
||||
|
||||
assert_eq!(error.code(), "CONFLICT_AGENT_VISIBLE_ELSEWHERE");
|
||||
assert!(f.restart_scheduler.calls.lock().unwrap().is_empty());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// StopLiveAgent
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user