feat(backend,frontend): lot utilisateur #310 #311 #312 #313 — horodatage conversation, stop agent robuste, préférence terminal par défaut, paramètres projet (QA verte)
- #310: horodatage de tous les messages et événements de conversation visibles — composant partagé EntryTimestamp, timestamps propagés dans le transcript chat, les annonces inter-agent et le viewer de conversation, normalisation côté domain/adapters (conversation_log, paginate). - #311: stop d'agent robuste pour PTY non monté, sessions headless et CLI custom — lifecycle/orchestrator durcis, ponts chat app-tauri/web-server alignés, arrêt fiable sans session orpheline. - #312: préférence globale d'interface terminal par défaut — nouveau store settings (domain/application/infrastructure + tests), DTO et commandes backend, adapter frontend userSettings, panneau TerminalSettings dans les paramètres globaux. - #313: Paramètres du projet — contexte de projet éditable et couleur de thème par projet (ProjectSettingsPanel + projectTheme), teinte des onglets projet, persistance via DTO projet. QA verte (GO QA sur feature/batch-310-311-312-313-chat-stop-prefs-theme) — vérifications Git: git diff --cached --check OK; staging borné à crates/ et frontend/ (74 fichiers, +2105/-531), commit unique de lot conforme à la convention des lots (précédents batch-151/158/159, batch-210/211/212) car les fichiers partagés (dto.rs, commands.rs, CustomAgentChatView) entrelacent les 4 tickets. fichiers .ideai/* (agents/test.md, chat-drafts.json, system-permissions.json, tickets/counter.json, tickets/index.json, tickets/308-313/), attachments/ et scripts/ hors périmètre et préservés en worktree ; aucun push. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -48,17 +48,22 @@ fn sid() -> SessionId {
|
||||
}
|
||||
|
||||
fn delta(s: &str) -> ReplyChunk {
|
||||
ReplyChunk::TextDelta { text: s.to_owned() }
|
||||
ReplyChunk::TextDelta {
|
||||
at_ms: None,
|
||||
text: s.to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
fn final_chunk(s: &str) -> ReplyChunk {
|
||||
ReplyChunk::Final {
|
||||
at_ms: None,
|
||||
content: s.to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
fn error_chunk(s: &str) -> ReplyChunk {
|
||||
ReplyChunk::Error {
|
||||
at_ms: None,
|
||||
message: s.to_owned(),
|
||||
}
|
||||
}
|
||||
@ -70,6 +75,7 @@ fn progress_chunk(
|
||||
) -> ReplyChunk {
|
||||
ReplyChunk::Progress {
|
||||
progress: ReplyProgressDto {
|
||||
occurred_at_ms: None,
|
||||
progress_id: None,
|
||||
source: ReplyProgressSourceDto::ProviderNative,
|
||||
kind,
|
||||
@ -91,6 +97,7 @@ fn progress_chunk_with_id(
|
||||
) -> ReplyChunk {
|
||||
ReplyChunk::Progress {
|
||||
progress: ReplyProgressDto {
|
||||
occurred_at_ms: None,
|
||||
progress_id: Some(progress_id.to_owned()),
|
||||
source: ReplyProgressSourceDto::ProviderNative,
|
||||
kind,
|
||||
@ -107,6 +114,7 @@ fn progress_chunk_with_id(
|
||||
fn chunk_bytes(chunk: &ReplyChunk) -> usize {
|
||||
match chunk {
|
||||
ReplyChunk::UserPrompt {
|
||||
at_ms: _,
|
||||
text,
|
||||
attachments,
|
||||
attachment_refs,
|
||||
@ -123,13 +131,13 @@ fn chunk_bytes(chunk: &ReplyChunk) -> usize {
|
||||
})
|
||||
.sum::<usize>()
|
||||
}
|
||||
ReplyChunk::TextDelta { text } => text.len(),
|
||||
ReplyChunk::ToolActivity { label } => label.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(),
|
||||
ReplyChunk::Final { content, .. } => content.len(),
|
||||
ReplyChunk::Error { message, .. } => message.len(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,11 +145,32 @@ fn chunk_bytes(chunk: &ReplyChunk) -> usize {
|
||||
// chunk_from_event — exhaustive mapping (zone 6)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn accepted_reply_events_keep_the_backend_timestamp() {
|
||||
let chunk = app_tauri_lib::chat::chunk_from_event_at(
|
||||
ReplyEvent::Final {
|
||||
content: "done".to_owned(),
|
||||
},
|
||||
Some(42_424),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
chunk,
|
||||
ReplyChunk::Final {
|
||||
at_ms: Some(42_424),
|
||||
content: "done".to_owned()
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn chunk_from_event_maps_text_delta() {
|
||||
assert_eq!(
|
||||
chunk_from_event(ReplyEvent::TextDelta { text: "hi".into() }),
|
||||
Some(ReplyChunk::TextDelta { text: "hi".into() })
|
||||
Some(ReplyChunk::TextDelta {
|
||||
at_ms: None,
|
||||
text: "hi".into()
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@ -202,6 +231,7 @@ fn chunk_from_event_maps_final() {
|
||||
content: "done".into()
|
||||
}),
|
||||
Some(ReplyChunk::Final {
|
||||
at_ms: None,
|
||||
content: "done".into()
|
||||
})
|
||||
);
|
||||
@ -236,7 +266,10 @@ fn pump_turn(bridge: &ChatBridge, session: &SessionId, gen: u64, events: Vec<Rep
|
||||
for event in events {
|
||||
// Mirror the real pump: heartbeats map to no chunk and are skipped.
|
||||
if let Some(chunk) = chunk_from_event(event) {
|
||||
if matches!(chunk, ReplyChunk::Final { .. } | ReplyChunk::Error { .. }) {
|
||||
if matches!(
|
||||
chunk,
|
||||
ReplyChunk::Final { at_ms: None, .. } | ReplyChunk::Error { at_ms: None, .. }
|
||||
) {
|
||||
terminal_visible = true;
|
||||
}
|
||||
let _ = bridge.send_output(session, chunk);
|
||||
@ -277,10 +310,13 @@ fn pump_delivers_deltas_then_exactly_one_final_in_order() {
|
||||
// Exactly one Final, and it is last (deterministic terminal chunk).
|
||||
let finals = got
|
||||
.iter()
|
||||
.filter(|c| matches!(c, ReplyChunk::Final { .. }))
|
||||
.filter(|c| matches!(c, ReplyChunk::Final { at_ms: None, .. }))
|
||||
.count();
|
||||
assert_eq!(finals, 1, "exactly one Final per turn");
|
||||
assert!(matches!(got.last(), Some(ReplyChunk::Final { .. })));
|
||||
assert!(matches!(
|
||||
got.last(),
|
||||
Some(ReplyChunk::Final { at_ms: None, .. })
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -490,6 +526,7 @@ fn scrollback_accumulates_every_routed_chunk_in_order() {
|
||||
.map(|chunk| match chunk {
|
||||
ReplyChunk::Progress { progress } => {
|
||||
ReplyChunk::ToolActivity {
|
||||
at_ms: None,
|
||||
label: progress.label,
|
||||
}
|
||||
}
|
||||
@ -499,6 +536,7 @@ fn scrollback_accumulates_every_routed_chunk_in_order() {
|
||||
vec![
|
||||
delta("x"),
|
||||
ReplyChunk::ToolActivity {
|
||||
at_ms: None,
|
||||
label: "runs".into()
|
||||
},
|
||||
final_chunk("x"),
|
||||
@ -756,15 +794,15 @@ fn scrollback_drops_oldest_whole_chunks_when_byte_cap_is_exceeded() {
|
||||
assert_eq!(scrollback.len(), 4);
|
||||
assert!(matches!(
|
||||
scrollback.first(),
|
||||
Some(ReplyChunk::TextDelta { text }) if text.starts_with("02:")
|
||||
Some(ReplyChunk::TextDelta { text, .. }) if text.starts_with("02:")
|
||||
));
|
||||
assert!(matches!(
|
||||
scrollback.last(),
|
||||
Some(ReplyChunk::TextDelta { text }) if text.starts_with("05:")
|
||||
Some(ReplyChunk::TextDelta { text, .. }) if text.starts_with("05:")
|
||||
));
|
||||
assert!(scrollback.iter().all(|chunk| matches!(
|
||||
chunk,
|
||||
ReplyChunk::TextDelta { text } if text.len() == chunk_size
|
||||
ReplyChunk::TextDelta { text, .. } if text.len() == chunk_size
|
||||
)));
|
||||
}
|
||||
|
||||
@ -781,6 +819,7 @@ fn truncated_scrollback_replays_valid_unmodified_chunks_in_order() {
|
||||
bridge.send_output(
|
||||
&session,
|
||||
ReplyChunk::ToolActivity {
|
||||
at_ms: None,
|
||||
label: "tool".into(),
|
||||
},
|
||||
);
|
||||
@ -793,6 +832,7 @@ fn truncated_scrollback_replays_valid_unmodified_chunks_in_order() {
|
||||
&scrollback[(MAX_CHAT_SCROLLBACK_CHUNKS - 2)..],
|
||||
&[
|
||||
ReplyChunk::ToolActivity {
|
||||
at_ms: None,
|
||||
label: "tool".into()
|
||||
},
|
||||
final_chunk("done")
|
||||
|
||||
@ -444,7 +444,7 @@ fn project_work_state_dto_serialises_conversations_camelcase() {
|
||||
source: TicketWorkSource::Agent {
|
||||
agent_id: requester,
|
||||
},
|
||||
at_ms: 1_700,
|
||||
at_ms: Some(1_700),
|
||||
text_preview: "Analyse le module".to_owned(),
|
||||
text_len: 17,
|
||||
}],
|
||||
@ -715,6 +715,7 @@ fn stop_live_agent_request_deserialises_camelcase() {
|
||||
#[test]
|
||||
fn stop_live_agent_response_serialises_camelcase_with_kind() {
|
||||
use app_tauri_lib::dto::StopLiveAgentResponseDto;
|
||||
use application::terminal::StoppedAgentRuntime;
|
||||
use application::{LiveSessionKind, StopLiveAgentOutput};
|
||||
|
||||
let agent = AgentId::from_uuid(Uuid::from_u128(11));
|
||||
@ -722,17 +723,21 @@ fn stop_live_agent_response_serialises_camelcase_with_kind() {
|
||||
let session = SessionId::from_uuid(Uuid::from_u128(13));
|
||||
let dto = StopLiveAgentResponseDto::from(StopLiveAgentOutput {
|
||||
agent_id: agent,
|
||||
node_id: node,
|
||||
session_id: session,
|
||||
kind: LiveSessionKind::Structured,
|
||||
runtime_state: LiveRuntimeState::Stopped,
|
||||
stopped: vec![StoppedAgentRuntime {
|
||||
agent_id: agent,
|
||||
node_id: node,
|
||||
session_id: session,
|
||||
kind: LiveSessionKind::Structured,
|
||||
state: LiveRuntimeState::Stopped,
|
||||
}],
|
||||
already_stopped: false,
|
||||
});
|
||||
|
||||
let v = serde_json::to_value(&dto).unwrap();
|
||||
assert_eq!(v["agentId"], agent.to_string());
|
||||
assert_eq!(v["sessionId"], session.to_string());
|
||||
assert_eq!(v["kind"], "structured");
|
||||
assert_eq!(v["runtimeState"], "stopped");
|
||||
assert!(v.get("nodeId").is_none());
|
||||
assert_eq!(v["stopped"][0]["sessionId"], session.to_string());
|
||||
assert_eq!(v["stopped"][0]["kind"], "structured");
|
||||
assert_eq!(v["stopped"][0]["runtimeState"], "stopped");
|
||||
assert_eq!(v["alreadyStopped"], false);
|
||||
assert!(v.get("session_id").is_none());
|
||||
}
|
||||
|
||||
@ -26,17 +26,22 @@ use uuid::Uuid;
|
||||
#[test]
|
||||
fn reply_chunk_user_prompt_serialises_exact_camel_case() {
|
||||
let v = serde_json::to_value(ReplyChunk::UserPrompt {
|
||||
at_ms: None,
|
||||
text: "run tests".into(),
|
||||
attachments: Vec::new(),
|
||||
attachment_refs: Vec::new(),
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(v, json!({ "kind": "userPrompt", "text": "run tests" }));
|
||||
assert_eq!(
|
||||
v,
|
||||
json!({ "kind": "userPrompt", "text": "run tests", "atMs": null })
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reply_chunk_user_prompt_serialises_attachment_labels() {
|
||||
let v = serde_json::to_value(ReplyChunk::UserPrompt {
|
||||
at_ms: None,
|
||||
text: "describe this".into(),
|
||||
attachments: vec!["clipboard.png".into()],
|
||||
attachment_refs: vec![ChatPromptAttachmentDto {
|
||||
@ -52,6 +57,7 @@ fn reply_chunk_user_prompt_serialises_attachment_labels() {
|
||||
v,
|
||||
json!({
|
||||
"kind": "userPrompt",
|
||||
"atMs": null,
|
||||
"text": "describe this",
|
||||
"attachments": ["clipboard.png"],
|
||||
"attachmentRefs": [{
|
||||
@ -68,25 +74,50 @@ fn reply_chunk_user_prompt_serialises_attachment_labels() {
|
||||
#[test]
|
||||
fn reply_chunk_text_delta_serialises_exact_camel_case() {
|
||||
let v = serde_json::to_value(ReplyChunk::TextDelta {
|
||||
at_ms: None,
|
||||
text: "hello".into(),
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(v, json!({ "kind": "textDelta", "text": "hello" }));
|
||||
assert_eq!(
|
||||
v,
|
||||
json!({ "kind": "textDelta", "text": "hello", "atMs": null })
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_reply_chunk_without_timestamp_deserialises_as_none() {
|
||||
let chunk: ReplyChunk = serde_json::from_value(json!({
|
||||
"kind": "final",
|
||||
"content": "legacy"
|
||||
}))
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
chunk,
|
||||
ReplyChunk::Final {
|
||||
at_ms: None,
|
||||
content: "legacy".into()
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reply_chunk_tool_activity_serialises_exact_camel_case() {
|
||||
let v = serde_json::to_value(ReplyChunk::ToolActivity {
|
||||
at_ms: None,
|
||||
label: "reads file".into(),
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(v, json!({ "kind": "toolActivity", "label": "reads file" }));
|
||||
assert_eq!(
|
||||
v,
|
||||
json!({ "kind": "toolActivity", "label": "reads file", "atMs": null })
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reply_chunk_progress_serialises_exact_camel_case() {
|
||||
let v = serde_json::to_value(ReplyChunk::Progress {
|
||||
progress: ReplyProgressDto {
|
||||
occurred_at_ms: None,
|
||||
progress_id: Some("codex:item:tool0".into()),
|
||||
source: ReplyProgressSourceDto::IdeaLocal,
|
||||
kind: ReplyProgressKindDto::Mcp,
|
||||
@ -105,6 +136,7 @@ fn reply_chunk_progress_serialises_exact_camel_case() {
|
||||
"kind": "progress",
|
||||
"progress": {
|
||||
"source": "ideaLocal",
|
||||
"occurredAtMs": null,
|
||||
"kind": "mcp",
|
||||
"progressId": "codex:item:tool0",
|
||||
"stage": "started",
|
||||
@ -119,21 +151,26 @@ fn reply_chunk_progress_serialises_exact_camel_case() {
|
||||
#[test]
|
||||
fn reply_chunk_final_serialises_exact_camel_case() {
|
||||
let v = serde_json::to_value(ReplyChunk::Final {
|
||||
at_ms: None,
|
||||
content: "done".into(),
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(v, json!({ "kind": "final", "content": "done" }));
|
||||
assert_eq!(
|
||||
v,
|
||||
json!({ "kind": "final", "content": "done", "atMs": null })
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reply_chunk_error_serialises_exact_camel_case() {
|
||||
let v = serde_json::to_value(ReplyChunk::Error {
|
||||
at_ms: None,
|
||||
message: "Réponse vide du modèle.".into(),
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
v,
|
||||
json!({ "kind": "error", "message": "Réponse vide du modèle." })
|
||||
json!({ "kind": "error", "message": "Réponse vide du modèle.", "atMs": null })
|
||||
);
|
||||
}
|
||||
|
||||
@ -141,6 +178,7 @@ fn reply_chunk_error_serialises_exact_camel_case() {
|
||||
fn reply_chunk_round_trips_through_json_for_every_variant() {
|
||||
for chunk in [
|
||||
ReplyChunk::UserPrompt {
|
||||
at_ms: None,
|
||||
text: "u".into(),
|
||||
attachments: vec!["clipboard.png".into()],
|
||||
attachment_refs: vec![ChatPromptAttachmentDto {
|
||||
@ -152,12 +190,17 @@ fn reply_chunk_round_trips_through_json_for_every_variant() {
|
||||
.into(),
|
||||
}],
|
||||
},
|
||||
ReplyChunk::TextDelta { text: "x".into() },
|
||||
ReplyChunk::TextDelta {
|
||||
at_ms: None,
|
||||
text: "x".into(),
|
||||
},
|
||||
ReplyChunk::ToolActivity {
|
||||
at_ms: None,
|
||||
label: "runs".into(),
|
||||
},
|
||||
ReplyChunk::Progress {
|
||||
progress: ReplyProgressDto {
|
||||
occurred_at_ms: None,
|
||||
progress_id: None,
|
||||
source: ReplyProgressSourceDto::ProviderNative,
|
||||
kind: ReplyProgressKindDto::Turn,
|
||||
@ -170,9 +213,11 @@ fn reply_chunk_round_trips_through_json_for_every_variant() {
|
||||
},
|
||||
},
|
||||
ReplyChunk::Final {
|
||||
at_ms: None,
|
||||
content: "y".into(),
|
||||
},
|
||||
ReplyChunk::Error {
|
||||
at_ms: None,
|
||||
message: "empty".into(),
|
||||
},
|
||||
] {
|
||||
@ -190,6 +235,7 @@ fn reply_chunk_deserialises_from_camel_case_wire_payload() {
|
||||
assert_eq!(
|
||||
back,
|
||||
ReplyChunk::UserPrompt {
|
||||
at_ms: None,
|
||||
text: "hi".into(),
|
||||
attachments: Vec::new(),
|
||||
attachment_refs: Vec::new()
|
||||
@ -366,12 +412,17 @@ fn reattach_chat_dto_serialises_camel_case_with_typed_scrollback() {
|
||||
conversation_id: Some("conv-1".into()),
|
||||
scrollback: vec![
|
||||
ReplyChunk::UserPrompt {
|
||||
at_ms: None,
|
||||
text: "Hi".into(),
|
||||
attachments: Vec::new(),
|
||||
attachment_refs: Vec::new(),
|
||||
},
|
||||
ReplyChunk::TextDelta { text: "Hi".into() },
|
||||
ReplyChunk::TextDelta {
|
||||
at_ms: None,
|
||||
text: "Hi".into(),
|
||||
},
|
||||
ReplyChunk::Final {
|
||||
at_ms: None,
|
||||
content: "Hi".into(),
|
||||
},
|
||||
],
|
||||
@ -383,9 +434,9 @@ fn reattach_chat_dto_serialises_camel_case_with_typed_scrollback() {
|
||||
"sessionId": "sess-1",
|
||||
"conversationId": "conv-1",
|
||||
"scrollback": [
|
||||
{ "kind": "userPrompt", "text": "Hi" },
|
||||
{ "kind": "textDelta", "text": "Hi" },
|
||||
{ "kind": "final", "content": "Hi" },
|
||||
{ "kind": "userPrompt", "text": "Hi", "atMs": null },
|
||||
{ "kind": "textDelta", "text": "Hi", "atMs": null },
|
||||
{ "kind": "final", "content": "Hi", "atMs": null },
|
||||
],
|
||||
})
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user