修复: 重命名时缓存缺条目补建防标题丢失

- 缓存缺 entry(缓存损坏或新会话未入缓存)时补建,标题才能落盘
- 补缓存补建测试,顺带补齐测试文件缺失的换行
This commit is contained in:
lxy
2026-10-03 10:13:40 +08:00
parent 558b676eea
commit cc58de4661
3 changed files with 29 additions and 4 deletions
+8 -3
View File
@@ -191,10 +191,15 @@ func (m *Model) setUserTitle(sessionID, title string) tea.Cmd {
}
}
if m.history.Cache != nil {
if entry, ok := m.history.Cache[sessionID]; ok {
entry.UserTitle = title
m.cacheDirty = true
entry, ok := m.history.Cache[sessionID]
if !ok {
// 缓存缺 entry(如缓存文件损坏/新会话未入缓存)时补建,
// 否则标题只改内存不落盘,重启后丢失
entry = &cacheEntry{}
m.history.Cache[sessionID] = entry
}
entry.UserTitle = title
m.cacheDirty = true
}
// 调度落盘,避免改名只存在内存、被磁盘旧缓存覆盖
return cacheFlushTick()