补充 DirectProject 尾行修复测试

覆盖幂等扫描遇到未完成 JSONL 尾行的追加路径
This commit is contained in:
2026-09-07 11:25:12 +08:00
parent 06911e6f27
commit 330605e682
@@ -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]);
}
}