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

- 缓存缺 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
+20
View File
@@ -53,3 +53,23 @@ func TestRenameSurvivesStaleScan(t *testing.T) {
t.Fatalf("扫描后 session UserTitle 丢失: = %q, 期望 \"我的新名\"", s.UserTitle)
}
}
// TestSetUserTitleBackfillCacheEntry 验证缓存缺 entry 时(缓存文件损坏/
// 新会话未入缓存)重命名会补建 entry,保证标题落盘而非只改内存
func TestSetUserTitleBackfillCacheEntry(t *testing.T) {
m := NewModel()
m.history.Cache = map[string]*cacheEntry{}
m.setUserTitle("missing-session", "新标题")
e, ok := m.history.Cache["missing-session"]
if !ok {
t.Fatal("缓存缺 entry 时应补建")
}
if e.UserTitle != "新标题" {
t.Fatalf("补建 entry 应写入标题, got %q", e.UserTitle)
}
if !m.cacheDirty {
t.Fatal("应置 cacheDirty 调度落盘")
}
}