feat(backend): modèle unifié streaming/progress/events provider-agnostic + pont app-tauri — foundation #156 (QA verte)

This commit is contained in:
2026-08-06 13:13:17 +02:00
parent 40fa551f32
commit 918116664c
14 changed files with 630 additions and 59 deletions

View File

@ -18,7 +18,9 @@ use app_tauri_lib::chat::{
};
use app_tauri_lib::dto::ReplyChunk;
use domain::ids::SessionId;
use domain::ports::ReplyEvent;
use domain::ports::{
ReplyEvent, ReplyProgress, ReplyProgressKind, ReplyProgressSource, ReplyProgressStage,
};
use uuid::Uuid;
/// Builds a `Channel<ReplyChunk>` whose sent chunks are recorded into `sink`.
@ -62,6 +64,9 @@ fn chunk_bytes(chunk: &ReplyChunk) -> usize {
ReplyChunk::UserPrompt { text } => text.len(),
ReplyChunk::TextDelta { text } => text.len(),
ReplyChunk::ToolActivity { label } => label.len(),
ReplyChunk::Progress { progress } => {
progress.label.len() + progress.text.as_ref().map_or(0, String::len)
}
ReplyChunk::Final { content } => content.len(),
ReplyChunk::Error { message } => message.len(),
}
@ -81,13 +86,41 @@ fn chunk_from_event_maps_text_delta() {
#[test]
fn chunk_from_event_maps_tool_activity() {
let Some(ReplyChunk::Progress { progress }) = chunk_from_event(ReplyEvent::ToolActivity {
label: "reads file".into(),
}) else {
panic!("tool activity must map to canonical progress")
};
assert_eq!(progress.label, "reads file");
assert_eq!(
chunk_from_event(ReplyEvent::ToolActivity {
label: "reads file".into()
}),
Some(ReplyChunk::ToolActivity {
label: "reads file".into()
})
progress.kind,
app_tauri_lib::dto::ReplyProgressKindDto::Tool
);
assert_eq!(
progress.source,
app_tauri_lib::dto::ReplyProgressSourceDto::ProviderNative
);
}
#[test]
fn chunk_from_event_maps_canonical_progress() {
let event = ReplyEvent::Progress {
progress: ReplyProgress::new(
ReplyProgressSource::IdeaLocal,
ReplyProgressKind::Mcp,
ReplyProgressStage::Started,
"idea_ask_agent",
)
.with_tool_name("idea_ask_agent"),
};
let Some(ReplyChunk::Progress { progress }) = chunk_from_event(event) else {
panic!("progress event must map to progress chunk")
};
assert_eq!(progress.label, "idea_ask_agent");
assert_eq!(progress.kind, app_tauri_lib::dto::ReplyProgressKindDto::Mcp);
assert_eq!(
progress.source,
app_tauri_lib::dto::ReplyProgressSourceDto::IdeaLocal
);
}
@ -357,7 +390,18 @@ fn scrollback_accumulates_every_routed_chunk_in_order() {
);
assert_eq!(
bridge.scrollback(&session),
bridge
.scrollback(&session)
.into_iter()
.map(|chunk| match chunk {
ReplyChunk::Progress { progress } => {
ReplyChunk::ToolActivity {
label: progress.label,
}
}
other => other,
})
.collect::<Vec<_>>(),
vec![
delta("x"),
ReplyChunk::ToolActivity {