fix(background-task): découpler la détection de fin de tâche du drain output PTY (#2)
Le runner de tâches de fond détectait la fin d'un process via l'EOF du drain de sortie PTY, couplant le cycle de vie du process au flux d'output. Un output encore ouvert (ou drainé ailleurs) pouvait masquer ou retarder la détection de fin. Ajoute wait/try_wait au port figé PtyPort : - wait : bloquant, rend un ExitStatus idempotent ; - try_wait : non bloquant, rend Option<ExitStatus> ; - exit status mémorisé pour garder wait/try_wait/kill cohérents. Implémentation dans PortablePtyAdapter (état d'exit mémorisé). Le CommandBackgroundRunner détecte désormais la fin via pty.wait (select sur cancel/deadline) au lieu de l'EOF du drain. Tous les fakes PtyPort du workspace sont complétés en conséquence. Le tee live UI reste hors périmètre (traité en #58). Aucun breaking IPC/front. Tests : infrastructure/tests/background_task_runner.rs (nouveau) + pty_adapter.rs verts, non-régression application/app-tauri OK (hors échecs réseau du sandbox). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -988,8 +988,32 @@ pub trait PtyPort: Send + Sync {
|
||||
/// [`PtyError`] if the handle is unknown.
|
||||
fn scrollback(&self, handle: &PtyHandle) -> Result<Vec<u8>, PtyError>;
|
||||
|
||||
/// Waits for the PTY process to finish naturally and returns its exit status.
|
||||
///
|
||||
/// Idempotent while the session remains registered: the first waiter records
|
||||
/// the process status, and subsequent calls return that memorized status.
|
||||
///
|
||||
/// # Errors
|
||||
/// [`PtyError`] if the handle is unknown.
|
||||
async fn wait(&self, handle: &PtyHandle) -> Result<ExitStatus, PtyError>;
|
||||
|
||||
/// Non-blocking process status check.
|
||||
///
|
||||
/// Returns `Ok(None)` while the process is still alive and `Ok(Some(status))`
|
||||
/// once it has exited. Like [`wait`](Self::wait), the observed exit status is
|
||||
/// memorized until the session is purged.
|
||||
///
|
||||
/// # Errors
|
||||
/// [`PtyError`] if the handle is unknown.
|
||||
fn try_wait(&self, handle: &PtyHandle) -> Result<Option<ExitStatus>, PtyError>;
|
||||
|
||||
/// Kills the PTY's process, returning its exit status.
|
||||
///
|
||||
/// Idempotent while the session remains registered: if the process has
|
||||
/// already exited, returns the memorized status. Implementations may purge
|
||||
/// the session as part of kill/cleanup; after purge, calls return
|
||||
/// [`PtyError::NotFound`].
|
||||
///
|
||||
/// # Errors
|
||||
/// [`PtyError`] on failure.
|
||||
async fn kill(&self, handle: &PtyHandle) -> Result<ExitStatus, PtyError>;
|
||||
|
||||
Reference in New Issue
Block a user