Skip to content

test: add a cross-surface end-to-end suite and run its first scenario on the TUI - #5304

Merged
RealKai42 merged 4 commits into
mainfrom
test/new-e2e-tui
Nov 23, 2026
Merged

RealKai42 merged 4 commits into
mainfrom
test/new-e2e-tui

Conversation

@RealKai42

@RealKai42 RealKai42 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

现在每个产品面的端到端测试各有一套假模型和夹具:Desktop 的旅程基本都跑在它自己的桩模型上,ACP 的测试都在测试进程内部跑,Web 没有端到端测试,TUI 只有「首问」一个对话用例。同一个用户行为在不同的面上没法用同一条测试来验收,一个面红了也没法和另一个面对照。

这个 PR 新建 tests/e2e:一端是模拟的用户输入,另一端是真实的产品进程,中间只有 testkit 的假模型是假的。场景写一次,之后在 TUI、ACP、Desktop、Web 四个面上各跑一遍,每次查三样:模型收到了什么、界面显示了什么、磁盘变成了什么样。这个 PR 先接通 TUI;ACP、Desktop、Web 的驱动在后续 PR 里接入。旧的端到端测试原地不动。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

核心思路

场景只描述用户行为,不知道自己跑在哪个面上。它拿到的只有三样东西:product(七个用户动作)、model(testkit 假模型)、workspace(工作区)。面和面之间的差异全部放进驱动,驱动只能做用户能做的操作:TUI 驱动只往真终端里写按键、读屏幕。

共用场景有一个风险:驱动替产品圆场,场景照样通过,用户走的那条路却是坏的。所以这个 PR 同时带了四道保障,让「这个测试真的会红」可以被检查:

保障 守什么 在哪
结构 场景拿不到面名、终端、process.env、test.info(),写不出「如果是某个面就……」 support/scenario.ts
lint import 白名单、后门写法、跳过和重试和固定等待、没有写进用户文档的 KIMI_* 名字 scripts/checks/e2e-boundary.mjs
每次运行自动查 产品正常退出、没有对外连接、至少查过一次界面、model.verify()、工作区里没有未声明的改动 support/scenario.ts 的收尾检查
驱动自测 每个动作都有正例和反例,反例断言「这个动作必须报错」 self-test/

概念

概念 回答什么问题 这个 PR 之后
场景 用户做了什么,产品应该怎样 scenarios/files/read-and-edit.spec.ts:读一个文件,批准后改另一个文件
动作 用户能做哪些操作、能看到什么 VERBS:send、approve、reject、stop、waitIdle、expectTool、expectReply;Product 接口由它推导
驱动 一个动作在某个面上具体怎么做、以什么为证据 surfaces/tui.ts
收尾检查 场景本体通过之后,还有什么必须成立 见上表第三行
自测 动作在该报错的时候会不会报错 selfTest('动作', { positive, negative }),一个动作一个文件

结构

flowchart LR
  subgraph e2e["tests/e2e"]
    S["场景和自测<br/>只拿到 product、model、workspace"]
    P["support<br/>scenario() 和收尾检查"]
    D["TUI 驱动<br/>写按键、读屏幕"]
  end
  M["testkit 假模型"]
  C["真实的 CLI 进程<br/>跑在真终端里"]
  W[("工作区")]
  S --> P --> D
  D -- 按键 --> C
  C -- 屏幕 --> D
  C <-- 模型请求 --> M
  C -- 读写文件 --> W
  S -- 写剧本、查请求 --> M
  P -- 收尾时对比快照 --> W
Loading

测试只从三个地方接触产品:终端的输入输出、假模型收到的请求、工作区的磁盘。产品是独立的子进程,测试没有别的入口。

关键决策

决策 选择 没选 理由
场景怎么拿夹具 自己的 scenario(),本体只收三个参数 直接导出 Playwright 的 test 导出 test 的话,场景能拿到 page、test.info(),也能用 test.skip,「场景看不到面」就只能靠 lint 守
TUI 怎么启动 用系统的 script 命令包一层,CLI 看到的是真终端 管道加虚拟终端 真终端才是用户实际的运行方式;做法照已有的真 PTY 冒烟
send 怎么输入 括号粘贴后按 Enter 逐字输入 逐字输入要在字符之间加固定间隔,否则会被识别成粘贴;新目录不许用固定等待
approve、reject 以什么为证据 转录里多出一行 Approved: … 或 Rejected: … 审批面板消失 能区分批准和拒绝;连续两个审批时面板不会消失
expect* 等到什么时候 等到期望成立,或者回合结束;回合结束时还不成立就报错 等到超时 反例能很快报错,不靠「等到超时还没出现」下结论。「回合结束」要连续两次读到相同的屏幕才算,防止读到画了一半的帧
怎么判断回合结束 输入框回来了,输入框正上方没有产品的活动指示(月相或点阵图标),并且出现了结束的证据:Worked for、新增的 Interrupted by user,或新增的 Error: [ 只凭转录里出现的文字 回复和工具输出里也可能出现 Error: … 这样的文字;等待模型和执行工具时产品只显示月相图标,没有文字标签
怎么分清转录和界面外框 按位置:先在屏幕底部找到输入框或审批面板,它上面紧挨着的几行是活动行,再往上才是转录 逐行匹配图标和制表符 回复里也可能有以月相表情开头的行,或者 Markdown 分隔线渲染出来的横线
怎么认转录里的条目 只认画在条目那一列上的 ❯、●、✗;工具卡片要符合整张卡的格式 去掉缩进后再匹配 回复正文里引用的 ❯ … 或 ● Used Read (…) 是缩进的续行,不是条目;以 Used 开头的普通回复也不是工具卡片
expect* 看哪些内容 只看最近一条用户消息之后的内容;工具卡片不算回复;一条回复一直算到下一个带标记的条目为止 扫整个转录;只看回复的第一段 否则上一回合的回复或工具、工具卡片上的文字都会被当成这一回合的回复;多段回复的后几段也要能断言
同一步里的多个 Read TUI 会把它们合并成一张 Read N files 卡片。expectTool 按 ctrl+o 展开、逐个核对文件和状态,再按一次收起 只认单独的卡片 展开是用户会做的操作;核对完收起,保留默认的界面状态
哪些 KIMI_* 名字能用 出现在 docs/en/configuration/env-vars.md 里的 手工维护一份名单 前置准备只能用用户自己也能用的方式,而「是不是公开」本来就由用户文档决定
某个面不适用怎么表示 except 或 onlyOn 加理由,报告里显示为跳过并带着理由 悄悄不跑 不适用必须看得见。这需要 Playwright 的 skip,所以例外表里登记了一条,只对 support/scenario.ts 生效
自测是否齐全怎么查 selfTest() 登记时检查每个面都有正例和反例;self-test/coverage.spec.ts 检查每个动作都有自测文件 在一个用例里加载所有自测文件 Playwright 不允许一个测试文件加载另一个测试文件
第三方下载怎么处理 testkit 的服务桩加 prefix: true,把 CDN 上 fd/ 和 rg/ 的下载按前缀回 404 在测试里算出完整的下载地址 算地址要 import 产品内部模块,新目录不允许。产品如果换了域名,网络守卫会记下违例,测试变红

阅读指南

  1. tests/e2e/AGENTS.md:规矩和每条规矩由什么守。
  2. tests/e2e/scenarios/files/read-and-edit.spec.ts:一个场景长什么样。
  3. tests/e2e/support/verbs.ts,再看 support/scenario.ts:场景 API、夹具的生命周期和收尾检查。
  4. tests/e2e/surfaces/tui.ts:每个动作在 TUI 上怎么做、以屏幕上的什么为证据。
  5. tests/e2e/self-test/*.spec.ts:动作的含义由这些用例固定。
  6. scripts/checks/e2e-boundary.mjs:规则表在文件开头。

可以略读:scripts/checks/e2e-boundary.test.mjs(每条规则的正例和反例)、testkit 的两个小功能和它们的测试、工作区登记(pnpm-workspace.yaml、flake.nix、typecheck 列表、CODEOWNERS)。

关于改动量

这个 PR 约 2,700 行(不算 lockfile),超过了 2,000 行的拆分线。没有拆的原因:其中约 950 行是 lint 检查和它自己的测试,它检查的对象就是这个 PR 新建的目录,规则和被它约束的代码放在一起才好评审;TUI 套件在 Linux 上的首次验证也依赖这个 PR 里的 CI 作业。

Behavior Changes and Affected Users

产品行为:None。这个 PR 没有改 apps/*/src,packages/ 下只改了私有的测试包 testkit;契约文件都没有动。

对仓库贡献者和 CI 有下面这些变化:

行为 改动前 改动后 谁依赖旧行为 退路
pnpm lint 9 项检查 多一项 e2e-boundary,只检查 tests/e2e 下的 JS/TS 文件 没有:这个目录是新建的 例外登记在 scripts/checks/e2e-boundary.json,要写理由
testkit 的 FetchStub url 必须和请求地址完全相同 多一个可选的 prefix;不写时仍然是完全相同才匹配 现有的调用方:TUI 夹具、Desktop 夹具、KAP 子进程 不需要:默认行为没变
PR 上的 CI 没有 E2E 工作流 每个 PR 多跑 Build (optional) 和 TUI (optional) 两个作业 所有开 PR 的人:多用一次构建的 CI 时间 不是必过检查,红了不挡合并
CI 的类型检查 不含 tests/e2e 包含 没有 —
CODEOWNERS — /tests/e2e/ 和 /scripts/checks/e2e-boundary.* 会自动请三位负责人评审 没有 规则集没有开「必须由代码负责人批准」

受影响的模块和对应的测试:

  • e2e-boundary 检查:scripts/checks/e2e-boundary.test.mjs,每条规则都有通过和不通过的例子,例外表的校验也在里面。
  • FetchStub 的 prefix:packages/testkit/test/fixtures.test.ts 里新增一例,同时钉住「不写 prefix 时带查询串的地址不匹配」。这个用例不带 tsx 启动子进程,所以也验证了 preload 导入链仍然只用可擦除语法。
  • 工作区快照:同一个文件里新增三例,覆盖新增、删除、内容变化、内容相同的重写和符号链接。
  • tests/e2e 自身:1 个场景,七个动作共 34 个正反例,1 个完整性检查。

验证

  • macOS(arm64):TUI 套件在源码模式和构建产物模式(TESTKIT_CLI_BUILD=dist)下各跑过,36 个用例全过。最新提交上做过加压:6 个占满 CPU 的进程加 10 个 worker,全套 3 轮共 108 次全过;上一个提交上同样的负载下 stop 的正例 40 次全过。没有残留进程,通过的用例不留临时目录。把 fd 和 rg 从 PATH 里拿掉来模拟 CI:全过;去掉前缀桩后网络守卫记下对 CDN 的连接,用例变红。
  • Linux:没有在本地验证,由这个 PR 的 TUI (optional) 作业验证。TUI 驱动用的 script 写法和已有的真 PTY 冒烟相同。
  • Windows:不支持,驱动在 Windows 上直接报错。
  • pnpm lint、node --test 'scripts/checks/*.test.mjs'、testkit 的测试、tests/e2e 和 testkit 的类型检查、sherif、新增重复代码检查:都通过。
破坏性检查:临时改坏,确认会红
改坏什么 结果
expectReply 永远通过 expect-reply 的 2 个反例变红
approve 什么都不做 approve 的正例和反例都变红
waitIdle 立刻返回 wait-idle 的 3 个用例变红
expectTool 不看状态 expect-tool 的 2 个反例变红
场景不声明磁盘改动 收尾检查报 changed b.txt
场景一次界面都不查 收尾检查报「没有检查界面」
剧本多写一步 收尾检查报假模型有没用完的步骤
场景结束时审批还挂着 收尾检查报「回合还在进行」
驱动上报一条对外连接 收尾检查报网络违例
不适用的理由写成空白 列用例那一步就失败

改坏的地方都已改回,提交里没有这些改动。

评审发现的问题和对应的回归用例
问题 修复前 回归用例
等待模型和执行工具时产品只显示月相图标,驱动没认出来,把还在跑的回合当成空闲 回复里有一行 Error: [example] … 时,回合进行中的 send() 被放行;stop 的正例在高负载下约八分之一失败 waitIdle negative: does not take reply text that looks like a failed turn for the end of the turn;stop 的正例加压重复 40 次
expectReply 会匹配工具卡片上的文字 expectReply('Used Read (a.txt)') 通过 expectReply negative: does not take a tool card for a reply
expectReply、expectTool 会匹配上一回合的内容 第二回合里断言第一回合的回复和工具都通过 expectReply negative: does not take a reply from an earlier turn;expectTool negative: does not take a tool from an earlier turn
提示词以反斜杠结尾时永远提交不了 等 30 秒后超时 send negative 里新增一条断言
directoryChanges 把名字像 constructor 的新增文件报成「内容变化」 — packages/testkit/test/fixtures.test.ts 新增一例
lint 把场景里的 process.(句号结尾的英文)和标题里的 retries 当成违规;fetch (、x.sleep( 这类写法漏过 — scripts/checks/e2e-boundary.test.mjs 新增和扩充的用例
多段回复只认第一段 expectReply 找不到第二段里的文字 expectReply positive: finds text in a later paragraph of the reply
对话里出现退出标记的文字时,驱动以为 CLI 已经退出 回复里有 E2E_CLI_EXIT=0 时,等待直接报「CLI 已退出」 waitIdle positive: keeps following a conversation that mentions a process exit status。标记现在带每次启动随机生成的后缀
同一步里的多个 Read 被合并成一张卡,expectTool 找不到单个文件 expectTool({ name: 'Read', target: 'a.txt', … }) 失败 expectTool 新增三例:逐个文件能找到、不在其中的文件报错、组内读取失败的文件状态是 failed
回复里以月相表情开头的行被当成活动指示 回合已完成,waitIdle 等到超时 waitIdle positive: returns after a reply whose line starts with a moon emoji
回复里的 Markdown 分隔线被当成界面外框 expectReply 找不到分隔线之后的文字 expectReply positive: finds text after a horizontal rule in the reply
回复正文里引用的 ❯ … 被当成新的用户消息;引用的 ● Used Read (…) 能让 expectTool 通过 没有执行过 Read,expectTool 也通过 expectTool negative: does not take reply text that looks like a tool card for a tool;expectReply positive: finds text after a line of the reply that quotes a prompt marker
以 Used 或 Read 2 files 开头的普通回复被当成工具卡片 expectReply 找不到这条回复 expectReply positive: finds a reply whose first words read like the start of a tool card

上表每个 tests/e2e 的回归用例都先在修复前跑过,确认是红的。

已知的限制

  • TUI 上分不开思考文本和回复:两者在屏幕上只有颜色不同,读屏拿不到颜色。tests/e2e/AGENTS.md 里写了:剧本里的思考文本不要包含要断言的回复文字。
  • 强杀时可能留下 Bash 工具的子进程:用例失败或超时、驱动强杀 CLI 时,如果正有一条 Bash 命令在跑,这条命令的进程会留下。这个 PR 里没有跑命令的场景,留到带命令场景的 PR 处理。
  • 报告里用例的位置显示为 support/scenario.ts,不是场景文件,因为 test() 是在 scenario() 里调用的。标题唯一,按文件过滤也照常可用。

留给维护者决定

  • changeset:没有写。testkit 是私有的测试包,没有 CHANGELOG,之前改它的源码也没有写过;tests/e2e 是纯测试。如果希望给 testkit 记一条,请在评审里说明。

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.

… on the TUI

tests/e2e drives the real product process with simulated user input; the
testkit fake model is the only fake. A scenario is written once against
seven user verbs and checks three things: what the model received, what
the interface showed, and what the disk looks like. This change wires the
TUI surface, the first scenario, and positive and negative self-tests for
every verb. The ACP, Desktop and Web drivers follow separately.

- testkit: directory snapshots and prefix-matched fetch stubs
- scripts/checks/e2e-boundary: keeps tests/e2e to allowlisted imports and
  user operations, wired into pnpm lint
- .github/workflows/e2e.yml: optional build and TUI jobs on every PR
@changeset-bot

changeset-bot Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 9496685

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 23, 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-23T16:27:46.403203Z 9496685 Manual request
🔒 Security Review ✅ Completed 2026-11-23T15:39:53.571707Z 7477dcf 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.

@pkg-pr-new

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

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

commit: 9496685

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7477dcf679

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/e2e/surfaces/tui.ts Resolved
Comment thread tests/e2e/surfaces/tui.ts Resolved
Comment thread tests/e2e/surfaces/tui.ts Resolved
…he exit marker private

- expectReply now reads an assistant message up to the next transcript
  entry, so text in a later paragraph of the reply is found.
- expectTool expands a "Read N files" card with ctrl+o to check each file
  of several reads made in one step, then folds it again.
- The launcher's exit marker carries a random suffix, so conversation text
  can no longer be mistaken for the CLI exiting.

Each change comes with driver self-tests that failed before it.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ff7fd2807e

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/e2e/surfaces/tui.ts Resolved
Comment thread tests/e2e/surfaces/tui.ts Resolved
…n structure on the TUI

The driver matched any screen line against the spinner glyphs and the box
drawing characters, so reply text could be taken for product chrome: a
reply line starting with a moon emoji kept waitIdle waiting, and a Markdown
horizontal rule cut the rest of the reply off.

The screen is now split by position: the editor box (or the approval panel)
is located at the bottom, the lines right above the editor are the activity
line, and everything above that is the transcript. A turn is over only
when the editor is back.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e521b58265

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/e2e/surfaces/tui.ts Resolved
Rows were trimmed before the entry markers were matched, so a line of reply
text that quoted a marker became a transcript entry: a quoted prompt line
started a new user message, and an indented "Used Read (a.txt)" line in a
reply satisfied expectTool without any Read having run.

Markers now count only at the column where the product draws entries. The
tool card pattern also requires the whole card shape, so a reply that
merely begins with "Used" or "Read 2 files" is still a reply.
@RealKai42

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 9496685d48

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@RealKai42
RealKai42 merged commit 8d22a9b into main Nov 23, 2026
31 checks passed
@RealKai42
RealKai42 deleted the test/new-e2e-tui branch November 23, 2026 16:29
@RealKai42 RealKai42 mentioned this pull request Nov 23, 2026
4 of 6 tasks
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.

1 participant