Skip to content

test(e2e): run the four surfaces on Windows and add manual Windows jobs - #5397

Closed
RealKai42 wants to merge 11 commits into
mainfrom
test/e2e-windows
Closed

RealKai42 wants to merge 11 commits into
mainfrom
test/e2e-windows

Conversation

@RealKai42

Copy link
Copy Markdown
Collaborator

Requirement or Bug

新 E2E 只在 Linux 上跑,而 CLI 和 Desktop 都发布 Windows 版本,主 CI 的 Windows 测试从 6 月起一直关着。这个 PR 让新 E2E 的四个面都能在 Windows 上跑,并在 e2e.yml 里加上手动触发的 Windows 作业。先只手动触发,等四个面在 Windows 上都稳定通过,再放到 PR 上。

基于 MoonshotAI/kimi-code#5380(这个 PR 的 base 是它的分支)。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

核心思路:用户在 Windows 上怎么用,驱动就怎么用。TUI 和 kimi web 都跑在 ConPTY 的伪终端里,kimi web 在三个平台上都改成在终端里按 Ctrl+C 结束;进程的启动和停止按平台区分;Windows 上暂时做不到的检查在动作表里声明,并写明理由。

面 Windows 上要解决的问题 做法
TUI 没有 /bin/sh 和 stty CLI 直接跑在 ConPTY 里,退出码取自伪终端;读终端模式的 expectTerminalRestored 在 Windows 上不适用(unavailableOn)
TUI ConPTY 不原样转发 CLI 的清屏序列 resize 的证据在 Windows 上改为「改尺寸之后有新的输出,并且输入框按新宽度画好」
Web process.kill(-pid, 'SIGINT') 在 Windows 上等于强杀,验证不了正常退出 kimi web 跑在伪终端里(surfaces/terminal-process.ts),驱动在终端里按 Ctrl+C;三个平台都这样,比原来发信号更像用户
Web ConPTY 用光标定位输出横幅,去掉控制序列后几行粘在一起 把终端输出渲染到 xterm.js 里,从屏幕的行里读地址
ACP 终端命令用进程组起停,Windows 上停不掉 只在非 Windows 上 detached;用 killProcessTree 停(Windows 上是 taskkill /T)
Desktop 按进程组查「自己的进程都退了」,Windows 上恒为真 Windows 上查主进程
Desktop 隔离的用户目录里没有 Downloads,产品创建主窗口时取下载目录就失败 启动前在隔离目录里建好 Downloads(真实用户都有);产品这一侧的问题另行记录
共用 审批里显示 C:/…/workspace/docs/b.txt,测试的工作区是短路径加反斜杠 namesFile 用工作区和它的真实路径、统一成 / 再比较
共用 摘要按 scenarios/ 前缀分类、用例限时 120 秒 先把反斜杠换成 /;限时跟着 testkit 的平台系数

关键决策:

决策 选择 没选 理由
Windows 作业何时上 PR 先只手动触发 直接放到每个 PR 上 产品在 Windows 上的问题可能还会冒出来,PR 上不能长期挂着一个红的作业;也不能用「不适用」把红藏起来
Windows 上读不了终端模式 动作表 unavailableOn + 场景 exceptPlatforms,写明理由 给测试加 .skip 「不适用」和面一样有理由、显示在报告里;只用于驱动还做不到的检查,不能用来绕开产品 bug
kimi web 的结束方式 三个平台都在伪终端里按 Ctrl+C 只在 Windows 上换 一条路径,本机就能验证;用户本来就是在终端里按 Ctrl+C

阅读指南:

  1. tests/e2e/surfaces/terminal-process.ts:在伪终端里跑 kimi web、按 Ctrl+C、从渲染后的屏幕读行。
  2. tests/e2e/surfaces/tui.ts 的 startTui、exitCode、resize:Windows 上不用启动脚本。
  3. tests/e2e/support/verbs.ts 的 unavailableOn、namesFile,support/scenario.ts 的 exceptPlatforms。
  4. .github/workflows/e2e.yml 末尾的 windows 作业。
  5. 其余是按平台的小改动:acp.ts、desktop.ts、run-summary.ts、playwright.config.ts。

Behavior Changes and Affected Users

产品代码没有改动,受影响的是写和跑新 E2E 的人,以及 CI。

Behavior Before After Who relies on the old behavior Escape hatch
新 E2E 在 Windows 上 四个面的驱动都直接报错 能跑;expectTerminalRestored 和用到它的场景在 Windows 上显示为不适用 无 无
kimi web 的启动和结束 普通子进程,结束时给进程组发 SIGINT 跑在伪终端里,结束时在终端里按 Ctrl+C;Linux 上同样依赖 node-pty(见 #5380) 无 无
动作表和场景选项 只有按面的不适用 多了按平台的不适用(unavailableOn、exceptPlatforms) 写场景的人 无
e2e.yml 只有 Linux 作业 多了 4 个 Windows <面> (manual) 作业,只在手动触发时跑 无 无

验证结论:四个面的全套在本机 macOS 上照常通过;Windows 上试跑了三次,ACP、Web 都全过过一次,TUI 从 8 条红修到 1 条再修好,Desktop 在第三次试跑里验证;剩下的 Windows 红是产品问题,见下。

验证细节

本机 macOS arm64,构建产物(TESTKIT_CLI_BUILD=dist):

  • 在这个 PR 和之后两个 PR 叠在一起的头上,Desktop 172 条、Web 178 条全过;TUI、ACP(含之后 PR 的两个跑法)的全套也都过了。
  • 这个 PR 改到的部分单独在它自己的头上跑过:TUI 的改尺寸、审批、权限模式,Web 和 Desktop 的重启、命令、文件读写。

破坏性检查:

改坏 结果
TerminalProcess.interrupt() 不写 Ctrl+C Web 的收尾检查报「按了 Ctrl+C 也没退出」
给一个没用到不可用动作的场景加 exceptPlatforms 收尾检查报这个排除没有依据

Windows(GitHub windows-latest,手动触发):

试跑 结果
1(45552046846) ACP 全过。TUI 156 过、8 红:审批里的路径是 C:/…,测试的工作区是短路径;ConPTY 不转发清屏序列。Web 等不到地址:ConPTY 用光标定位输出横幅。Desktop 主窗口打不开:隔离目录里没有 Downloads
2(45559275088) Web 全过。TUI 163 过、1 红:改尺寸后马上重启时屏幕还没画完。ACP 127 过、9 红:kimi acp 退出时 libuv 断言失败(Assertion failed: !(handle->flags & UV_HANDLE_CLOSING), file src\win\async.c, line 76),是产品问题,第 1 次没出现
3(45564604320) 进行中

还没解决的 Windows 问题(产品一侧,不在这个 PR 里修):

  • kimi acp 退出时偶发崩溃(上面的 libuv 断言);
  • Desktop 创建主窗口时同步调用 app.getPath('downloads')(apps/desktop/src/main/window/main-window.ts:605),取不到就建不出主窗口,错误只记成一条未处理的 rejection。

其他:干净 worktree 里 pnpm lint 以 0 退出;node --test 'scripts/checks/*.test.mjs' 全过;pnpm run check:duplication 没有新增重复;只读 agent 评审过,一条 P1(ACP 对已退出命令的 PID 调 taskkill,PID 可能已被复用)和几条 P2 已改。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

…s default config

The TUI driver made its pseudo-terminal with the system script command,
which Windows lacks and which cannot change the terminal size. Start the
launcher in node-pty instead (already a Desktop dependency); the terminal
is still xterm.js. node-pty is loaded when a TUI case starts, so a missing
native build only fails the TUI.

Add a resize('narrow' | 'normal') user action on the TUI (120x40 and
60x40, delivered as SIGWINCH) and on Web (1440x900 and 390x844). The TUI
evidence is a full redraw after the resize plus the input box or panel
drawn at the new width; the Web evidence is the visible input area laid
out inside the new viewport and stable across two reads. A restart keeps
the size. A new scenario narrows the window while a reply streams.

Run the product with the user's default config: testkit now exports the
switches it turns off only to speed up unit tests (session index read
model, search worker) as UNIT_TEST_SWITCHES, and the E2E drivers unset
them.

Split the Desktop and Web CI jobs into two shards each and run Desktop
with two workers (one when headed); the run summary names the shard.
…d update the import check test

Electron downloads its binary the first time it is started. With two
Desktop workers both cases downloaded and spawned it at once and failed
with spawn ETXTBSY, so the Desktop job now fetches it in a step before
the cases run.

The boundary check's own test still expected the TUI driver to import
node:child_process; it now checks node-pty instead.
…Windows jobs

- TUI: on Windows the CLI runs directly in ConPTY through node-pty and the
  exit code comes from the pseudo-terminal; Linux and macOS keep the /bin/sh
  launcher that prints stty -a after the CLI exits.
- Web: kimi web now runs in a pseudo-terminal on every platform, the way a
  user starts it, and the driver stops it by pressing Ctrl+C there instead
  of sending SIGINT to its process group. The address is read from the
  terminal output with control sequences removed.
- ACP: terminal commands are detached only off Windows and are killed with
  killProcessTree (taskkill /T on Windows).
- Desktop: the own-process check looks at the main process on Windows,
  where process groups do not exist.
- Shared: file paths in approvals also match the platform path join, the
  run summary normalises backslashes, and the case time limit follows the
  testkit platform factor.
- Verbs can be unavailable on a platform (unavailableOn); scenarios that use
  one declare exceptPlatforms. expectTerminalRestored is unavailable on
  Windows for now.
- e2e.yml gains a Windows job per surface that runs on manual dispatch only.
…Windows

The TUI on Windows shows the real path of a file with forward slashes,
while the test workspace path can be a short 8.3 alias with backslashes.
Compare against the workspace and its real path with slashes normalised.

ConPTY repaints the screen itself after a resize and does not pass the
CLI's clear-screen sequence through, so on Windows resize() waits for new
output plus the input box drawn at the new width. Failure diagnostics of
the TUI now include the tail of the raw terminal output.
…e Desktop home a Downloads folder

ConPTY draws the kimi web banner with cursor moves instead of newlines,
so the address line never matched after stripping control sequences.
Render the server's terminal in xterm.js and read its rows, the way a
user reads the screen.

Desktop creates its main window with app.getPath('downloads'), which
fails on Windows when the isolated home has no Downloads folder. Create
it in the test home before launching, as every real profile has one.
- ACP: once a command has exited, kill only its process group on POSIX
  and nothing on Windows, where its process id may already belong to
  another process.
- kimi web in a pseudo-terminal: fail at once when the server exits
  before printing its address, check that the entry exists, clean up a
  process group left behind, and describe the rendered screen.
- exceptPlatforms must be backed by an action that is unavailable on the
  excluded platform; the closing checks report one that is not.
- The guide says what the weaker resize evidence on Windows cannot prove.
On Windows the evidence of a redraw is any new output, so resize() could
return while the CLI was still drawing and a restart right after it saw
a busy screen. Wait until the input box or panel has the new width and
two reads of the screen agree.
@changeset-bot

changeset-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: bb4a40c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T11:45:41.442524Z bb4a40c New commits
🔒 Security Review ✅ Completed 2026-11-25T07:39:38.246616Z ae5cf4c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…pending approval

After the user answers an approval on Desktop or Web, the card stays on
screen with disabled buttons until the product has handled the answer.
The renderer treated it as a pending approval, so waitIdle() right after
rejectWithFeedback() failed on a slow Windows runner. An approval is
pending only while its buttons are visible and enabled.
@pkg-pr-new

pkg-pr-new Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@bb4a40c
npx https://pkg.pr.new/@moonshot-ai/kimi-code@bb4a40c

commit: bb4a40c

…r them

isEnabled() waits for the element, so when the approval card folded away
between isVisible() and isEnabled() the check hung for the full time
limit while stopping a turn that waits for approval. Look up enabled
buttons by role instead; isVisible() does not wait.
@RealKai42
RealKai42 added this pull request to stack #5419 November 25, 2026 11:34
@RealKai42

Copy link
Copy Markdown
Collaborator Author

已并入 #5423:叠着的四个 PR 合成一个,避免 squash 合并后每个都要再解一次冲突。改动不变,请在 #5423 继续评审。

@RealKai42 RealKai42 closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants