sidePaneTerminalWindowsIme.test.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { readFileSync } from "node:fs";
  2. import { resolve } from "node:path";
  3. import { describe, expect, it } from "vitest";
  4. function readSource(path: string) {
  5. return readFileSync(resolve(process.cwd(), path), "utf8");
  6. }
  7. /**
  8. * side pane terminal 的 Windows IME 兜底契约。
  9. *
  10. * Bug 原因(2026-08-12 定位):
  11. * WorkspaceShellLayout 渲染 AnimatedSidePanePanel 时漏传 isWindowsDesktop,
  12. * 链路 AnimatedSidePanePanel(undefined) → SidePaneTerminalPane(默认 false)
  13. * → TerminalSession.isWindowsDesktop=false → textarea 兜底
  14. * (`isWindowsDesktop && (term as ...)._core?.textarea`)整段不绑定。
  15. * 后果:中文输入法 composition(如输入 asdf)被 Shift 中断切换英文时,
  16. * xterm 对 composed text "只处理到一半",兜底缺失导致文本丢失(asdf 没进终端)。
  17. * 下侧 Terminal 一直传 isWindowsDesktop=true,兜底绑定,故正常。
  18. *
  19. * 修复:WorkspaceShellLayout 给 AnimatedSidePanePanel 补传 isWindowsDesktop。
  20. * 本测试为回归守卫,防止再次漏传。
  21. */
  22. describe("side pane terminal Windows IME 兜底契约", () => {
  23. it("WorkspaceShellLayout 必须把 isWindowsDesktop 传给 AnimatedSidePanePanel", () => {
  24. const source = readSource("packages/ui/src/app-shell/WorkspaceShellLayout.tsx");
  25. // 定位 AnimatedSidePanePanel 调用块(取足够长的片段覆盖其 props 区)
  26. const idx = source.indexOf("<AnimatedSidePanePanel");
  27. expect(idx).toBeGreaterThan(-1);
  28. const block = source.slice(idx, idx + 3000);
  29. // 回归守卫:禁止再漏传 isWindowsDesktop。漏传会让 textarea 兜底失效,
  30. // 中文 composition 被 Shift 中断时文本丢失。
  31. expect(block).toContain("isWindowsDesktop={isWindowsDesktop}");
  32. });
  33. it("AnimatedSidePanePanel 透传 isWindowsDesktop 给 SidePaneTerminalPane", () => {
  34. const source = readSource("packages/ui/src/app-shell/AnimatedSidePanePanel.tsx");
  35. const idx = source.indexOf("<SidePaneTerminalPane");
  36. expect(idx).toBeGreaterThan(-1);
  37. const block = source.slice(idx, idx + 800);
  38. expect(block).toContain("isWindowsDesktop={isWindowsDesktop}");
  39. });
  40. it("SidePaneTerminalPane 透传 isWindowsDesktop 给 TerminalSession", () => {
  41. const source = readSource("packages/ui/src/SidePaneTerminalPane.tsx");
  42. const idx = source.indexOf("<TerminalSession");
  43. expect(idx).toBeGreaterThan(-1);
  44. const block = source.slice(idx, idx + 800);
  45. expect(block).toContain("isWindowsDesktop={isWindowsDesktop}");
  46. });
  47. });