diff --git a/.agents/notes/implemented/bug-fix/2026-11-13-close-tab-test-binding-invalidation.md b/.agents/notes/implemented/bug-fix/2026-11-13-close-tab-test-binding-invalidation.md new file mode 100644 index 0000000000..97bdd1dfbe --- /dev/null +++ b/.agents/notes/implemented/bug-fix/2026-11-13-close-tab-test-binding-invalidation.md @@ -0,0 +1,41 @@ +# Agent 笔记:关闭标签测试的快捷键变更必须请求刷新 + +状态:已实现 + +## 先说结论 + +无头测试直接修改快捷键时,也要像真实设置页一样通知界面刷新。否则输入仍使用上一帧的绑定,后台任务偶然产生的刷新会掩盖问题。关闭标签测试现在明确请求刷新,并在所有平台验证用户新增的绑定,避免 macOS 默认键位掩盖测试缺口。 + +## 问题 + +[#1885](https://github.com/1lck/Lithe-IDEA/issues/1885) 来自 Linux CI:添加 Control-W 后日志页签仍然打开。`6268d92923` 引入的测试只改内存设置,没有真实设置页 `SetKeymap` 的刷新通知;测试驱动的 `Pump` 只在已有唤醒标记时绘制,不保证每次调用都重画。 + +macOS 原测试直接使用初始注册的 Command-W,因此无法覆盖同一缺陷。在 macOS 显式新增 Control-W 的独立探针及正式回归都复现相同失败,排除了 Java 插件的影响。 + +## 决策 + +测试的绑定辅助函数在更新后调用现有刷新接口,下一次输入前由驱动处理刷新;不修改产品逻辑或框架行为。新增跨平台用户绑定回归,先消费已有帧,再修改绑定并立即触发,防止无关后台唤醒提供偶然的刷新。 + +正确做法是“更新测试设置、明确请求刷新、发送按键”。不要只更新字段后靠下一次后台活动、延长等待或重复运行获取绿灯。 + +## 考虑过的备选方案 + +- 每次 Pump 都强制绘制:改变成熟框架的按需绘制语义,掩盖测试与真实设置路径的差异。 +- 加 sleep 或重试按键:依赖后台时序,还可能重复关闭其他标签。 +- 只跑 macOS 默认键位:遗漏用户自定义绑定及其他平台。 + +## 后果 + +测试不再依赖偶然刷新;新增少量测试辅助代码和一项跨平台回归。产品运行时、默认快捷键、资源、性能与插件契约均不改变。 + +## 验证 + +- `scripts/desktop/desktop-go.sh test ./internal/workbench -run '^TestCloseTabUserBindingClosesTheSelectedEditorTab$' -count=1`:未请求刷新时失败,日志页签仍为 1;修复后通过。 +- `scripts/desktop/desktop-go.sh test ./internal/workbench -run '^TestCloseTab' -count=1` 与相同范围的 `-race`。 +- `./scripts/agent-notes/verify-agent-notes.sh` 与测试稳定性静态检查。 +- Linux、Windows 的目标平台结果以配套 PR 的 CI 为准,本地 macOS 回归不能代替它们。 + +## 适用范围 + +- `desktop/internal/workbench/close_tab_shortcut_test.go` +- `desktop/internal/workbench/settings.go` 的真实设置变更刷新顺序。 diff --git a/desktop/internal/workbench/close_tab_shortcut_test.go b/desktop/internal/workbench/close_tab_shortcut_test.go index 958ef07449..c5c7d0a215 100644 --- a/desktop/internal/workbench/close_tab_shortcut_test.go +++ b/desktop/internal/workbench/close_tab_shortcut_test.go @@ -40,10 +40,16 @@ func closeTabChord(t *testing.T, a *App) keymap.Chord { return chord } chord := controlW(t) - a.settings.Keymap = a.settings.Keymap.With(shortcuts.CloseTab, []keymap.Chord{chord}) + bindCloseTab(a, chord) return chord } +func bindCloseTab(a *App, chord keymap.Chord) { + a.settings.Keymap = a.settings.Keymap.With(shortcuts.CloseTab, []keymap.Chord{chord}) + // Match SetKeymap: Pump paints only after an explicit invalidation. + a.invalidator.Invalidate() +} + func controlW(t *testing.T) keymap.Chord { t.Helper() chord, ok := keymap.Parse(gfx.ModifierControl, "w") @@ -85,6 +91,23 @@ func TestCloseTabShortcutClosesTheSelectedEditorTab(t *testing.T) { awaitDocumentState(t, f.h, func() bool { return f.p.docs.find(f.d.id) == nil }) } +// User bindings are installed after the log tab's frame on every platform, +// including macOS where the default Command-W would hide a missing refresh. +func TestCloseTabUserBindingClosesTheSelectedEditorTab(t *testing.T) { + f := newSemanticFixture(t) + openLSPLogFromStatus(f.h) + group := f.p.terms.bench.GroupOf(lspLogMember).ID + chord := controlW(t) + // Consume any pending paint before changing the binding; a background wake + // must not accidentally make the test's direct settings mutation visible. + pressCloseTab(t, f.h, chord) + bindCloseTab(f.h.app, chord) + pressCloseTab(t, f.h, chord) + if lspLogTabs(f.p) != 0 || f.p.selectedDocument(group) != f.d { + t.Fatalf("after the user chord: %d log tabs, the file selected %v", lspLogTabs(f.p), f.p.selectedDocument(group) == f.d) + } +} + // With a terminal focused the chord closes the terminal's tab, not the file's tab in the editor. func TestCloseTabShortcutClosesTheFocusedTerminal(t *testing.T) { h := newHarness(t, &testKernel{Client: core.NewClient()}) diff --git a/shared/platform-feature-matrix/features/keymap-customization.json b/shared/platform-feature-matrix/features/keymap-customization.json index d57973dd41..1b46bcfb3e 100644 --- a/shared/platform-feature-matrix/features/keymap-customization.json +++ b/shared/platform-feature-matrix/features/keymap-customization.json @@ -14,7 +14,8 @@ "desktop/internal/core/keymap_gesture.go", "desktop/internal/core/keymap_gesture_test.go", "desktop/internal/settingswindow/keymap_schemes_view.go", - "desktop/internal/settingswindow/editor_essentials_test.go" + "desktop/internal/settingswindow/editor_essentials_test.go", + "desktop/internal/workbench/close_tab_shortcut_test.go" ] }, "windows": { @@ -28,11 +29,12 @@ "desktop/internal/core/keymap_gesture.go", "desktop/internal/core/keymap_gesture_test.go", "desktop/internal/settingswindow/keymap_schemes_view.go", - "desktop/internal/settingswindow/editor_essentials_test.go" + "desktop/internal/settingswindow/editor_essentials_test.go", + "desktop/internal/workbench/close_tab_shortcut_test.go" ] }, "owner": "Settings", - "verification": "新增范围:运行 desktop/internal/settingswindow/editor_essentials_test.go 和 editor_essentials_visual_test.go,检查持久设置与深色中文、浅色英文。macOS/Windows 原生窗口验收 pending。macOS 使用默认 Command-Shift-A 从编辑器、侧栏及第二个项目窗口打开 Find Action,确认输入聚焦、/ 命令过滤、Return 仅执行一次、Escape 关闭且重新打开无旧查询;弹窗已打开时再次调用应切换到 / 并聚焦。改绑、禁用、恢复及录制时确认菜单与分发使用有效绑定;无工作区或搜索模块不可用时应禁用,激活失败应关闭。IDEA Classic 和 Eclipse 的 Find Action 暂无默认绑定,普通 Search Everywhere 保留双击 Shift 和 Shift-Command-O。macOS 从设置 → 快捷键依次选择 macOS、IntelliJ IDEA Classic、Eclipse,核对运行、调试、查找等操作在界面和实际监听器中的绑定;IDEA Classic 的 Stop Run 应为 Control-F2,Eclipse 的 Resume 应为 F8,继承父 keymap 的命令应使用上游绑定,Find、Replace、GotoImplementation 等显式清空的命令应无绑定;检查分类树初始折叠、全部展开和折叠、分类展开、搜索时自动显示匹配操作、选中行高亮、右侧紧凑键帽及工具栏编辑菜单;通过键帽、工具栏或右键菜单新增、删除与恢复默认,并检查键盘辅助功能;分别修改两套预设的同一命令,切换与重启后确认自定义绑定互不覆盖,并验证旧版单套覆盖迁移到 macOS;按命令名称、ID 和按键搜索,制造冲突并恢复当前预设或应用全部默认;导出再导入 keybindings.json,确认预设与自定义绑定恢复且命令实际执行。Windows 保持现有快捷键编辑、导出和导入验证。", + "verification": "新增范围:运行 desktop/internal/settingswindow/editor_essentials_test.go 和 editor_essentials_visual_test.go,检查持久设置与深色中文、浅色英文。macOS/Windows 原生窗口验收 pending。macOS 使用默认 Command-Shift-A 从编辑器、侧栏及第二个项目窗口打开 Find Action,确认输入聚焦、/ 命令过滤、Return 仅执行一次、Escape 关闭且重新打开无旧查询;弹窗已打开时再次调用应切换到 / 并聚焦。改绑、禁用、恢复及录制时确认菜单与分发使用有效绑定;无工作区或搜索模块不可用时应禁用,激活失败应关闭。IDEA Classic 和 Eclipse 的 Find Action 暂无默认绑定,普通 Search Everywhere 保留双击 Shift 和 Shift-Command-O。macOS 从设置 → 快捷键依次选择 macOS、IntelliJ IDEA Classic、Eclipse,核对运行、调试、查找等操作在界面和实际监听器中的绑定;IDEA Classic 的 Stop Run 应为 Control-F2,Eclipse 的 Resume 应为 F8,继承父 keymap 的命令应使用上游绑定,Find、Replace、GotoImplementation 等显式清空的命令应无绑定;检查分类树初始折叠、全部展开和折叠、分类展开、搜索时自动显示匹配操作、选中行高亮、右侧紧凑键帽及工具栏编辑菜单;通过键帽、工具栏或右键菜单新增、删除与恢复默认,并检查键盘辅助功能;分别修改两套预设的同一命令,切换与重启后确认自定义绑定互不覆盖,并验证旧版单套覆盖迁移到 macOS;按命令名称、ID 和按键搜索,制造冲突并恢复当前预设或应用全部默认;导出再导入 keybindings.json,确认预设与自定义绑定恢复且命令实际执行。Windows 保持现有快捷键编辑、导出和导入验证。 运行 TestCloseTabUserBindingClosesTheSelectedEditorTab,先消费旧帧,再新增用户 Control-W 绑定并立即关闭日志页签;测试设置变更必须像真实设置页一样请求刷新,不能依赖后台唤醒。该回归两端都执行,不以 macOS 默认 Command-W 代替用户绑定验证;原生设置窗口验收仍 pending。", "notes": "Viva:设置 › 快捷键页列出全部动作,可按名称或按键筛选;录制新增组合键、删除单个组合键、单项恢复默认与全部重置,覆盖项存入设置并由 shortcuts 应用到工作台与 Find Action;按键解析由 Core keymap 手势命令完成。keymap_view_test.go 覆盖页面交互;冲突提示与原生窗口验收 pending。 新增命名方案的保存、选择、重命名和删除;Core 保证独立绑定和默认方案保护。页面打开只读取,不自动写入设置。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36",