修复空 text 短路 content 兜底导致条目丢失

- items.rs:item_text 先判空/全空白再回落 content/summary;此前 Some("") 会短路兜底,末尾非空过滤把整条 message/reasoning 丢掉
- wire/tests.rs:补空 text + 有 content 的回归用例
This commit is contained in:
2026-10-02 22:26:12 +08:00
parent cb13ecf879
commit 25213c9ff7
2 changed files with 25 additions and 2 deletions
@@ -224,6 +224,9 @@ fn item_text(root: &Path, item: &Value) -> Option<String> {
let raw = item
.get("text")
.and_then(Value::as_str)
// 空 / 全空白的 `text` 要在**回落之前**判掉:否则 `Some("")` 会短路 `content` / `summary`
// 兜底,末尾那条非空过滤再把整条条目丢掉(message / reasoning 的正文就此消失)。
.filter(|text| !text.trim().is_empty())
.map(str::to_string)
.or_else(|| {
for key in ["content", "summary"] {
@@ -240,8 +243,7 @@ fn item_text(root: &Path, item: &Value) -> Option<String> {
}
}
None
})
.filter(|text| !text.trim().is_empty())?;
})?;
Some(bounded(
&sanitize_detail_text(root, &raw),
THREAD_TEXT_MAX_CHARS,
@@ -45,6 +45,27 @@ fn app_server_agent_message_defaults_to_assistant_role() {
));
}
#[test]
fn blank_message_text_falls_back_to_content_parts() {
// 空 / 全空白的 `text` 不能短路 `content` 兜底:否则整条条目会被判成"没有正文"直接丢掉。
let item = thread_item_from_value(
root(),
&json!({
"id": "msg-blank-text",
"type": "message",
"role": "assistant",
"text": " ",
"content": [{"type": "output_text", "text": "真实正文"}],
}),
1000,
)
.expect("blank text must still fall back to content");
assert!(matches!(
item,
ThreadItem::Message { text, .. } if text == "真实正文"
));
}
#[test]
fn tool_item_identity_is_normalized_to_one_id() {
let item = thread_item_from_value(