fix: 闪退真凶——装载历史缓存后 transInflight 为 nil
crash.log 实锤:panic: assignment to entry in nil map, docTranslation(hover 渲染帧内)。 合并判空是错的:loadTranslations 只装 a.trans,缓存有数据后 a.trans 永远非 nil,跳过了 transInflight 初始化——hover 一个 未缓存符号就往 nil map 写,主线程渲染帧直接炸。两次崩溃同因。 修复:两个 map 分别判空;loadTranslations 同时初始化两个。 回归测试:TestDocTranslationNilInflightWithLoadedCache。
This commit is contained in:
1 parent
665efb6027
commit
e7de0bd93a
2 files changed
+28
No files matched your search
@@ -72,3 +72,25 @@ func TestHoverTranslationInProgress(t *testing.T) {
|
||||
t.Fatalf("翻译中应显示原文, got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestDocTranslationNilInflightWithLoadedCache 复现闪退:启动时装载了历史
|
||||
// 缓存(a.trans 非 nil)但 transInflight 仍为 nil,此时 hover 一个未缓存的
|
||||
// 文档——不得往 nil map 写(crash.log: assignment to entry in nil map)。
|
||||
func TestDocTranslationNilInflightWithLoadedCache(t *testing.T) {
|
||||
a := &App{
|
||||
trans: map[string]string{"cached": "已缓存译文"}, // 只有 trans 被装载
|
||||
set: settings{TranslateDocs: true, AIBaseURL: "x", AIAPIKey: "y", AIModel: "z"},
|
||||
}
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
t.Fatalf("不得 panic: %v", r)
|
||||
}
|
||||
}()
|
||||
got := a.docTranslation("some uncached doc text")
|
||||
if got != "some uncached doc text" {
|
||||
t.Fatalf("未缓存应返回原文, got %q", got)
|
||||
}
|
||||
if a.transInflight == nil {
|
||||
t.Fatal("transInflight 应被初始化")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user