From 330605e682de369fde98c6c1aadfcff72f524dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Mon, 7 Sep 2026 11:25:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=20DirectProject=20=E5=B0=BE?= =?UTF-8?q?=E8=A1=8C=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 覆盖幂等扫描遇到未完成 JSONL 尾行的追加路径 --- .../src/agent/direct_project_history.rs | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/apps/ai-game-creator-shell/src-tauri/src/agent/direct_project_history.rs b/apps/ai-game-creator-shell/src-tauri/src/agent/direct_project_history.rs index 3b67e47eb..531bf5231 100644 --- a/apps/ai-game-creator-shell/src-tauri/src/agent/direct_project_history.rs +++ b/apps/ai-game-creator-shell/src-tauri/src/agent/direct_project_history.rs @@ -304,7 +304,10 @@ pub(crate) fn read_direct_project_chat_history_at( #[cfg(test)] mod tests { - use super::is_direct_project_internal_context_item; + use super::{ + append_direct_project_history_item_at, history_path, + is_direct_project_internal_context_item, read_direct_project_history_items_at, + }; use serde_json::json; #[test] @@ -351,4 +354,28 @@ mod tests { }] }))); } + + #[test] + fn append_repairs_truncated_tail_before_idempotency_scan() { + let root = tempfile::tempdir().expect("temp project"); + crate::init_local_game_project_at(root.path(), "tail-repair", "尾行修复") + .expect("init project"); + let path = history_path(root.path()); + std::fs::create_dir_all(path.parent().expect("history parent")).expect("history dir"); + std::fs::write( + &path, + br#"{"type":"response_item","payload":{"type":"message"}"#, + ) + .expect("write truncated history tail"); + let item = serde_json::json!({ + "type": "message", + "role": "assistant", + "id": "tail-repair-item", + "content": [{"type": "output_text", "text": "已修复"}] + }); + append_direct_project_history_item_at(root.path(), &item).expect("repair and append"); + let items = + read_direct_project_history_items_at(root.path()).expect("read repaired history"); + assert_eq!(items, vec![item]); + } }