Repository navigation
test: add a cross-surface end-to-end suite and run its first scenario on the TUI - #5304
Conversation
… 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
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
There was a problem hiding this comment.
💡 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".
…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.
There was a problem hiding this comment.
💡 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".
…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.
There was a problem hiding this comment.
💡 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".
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.
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
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.tsKIMI_*名字scripts/checks/e2e-boundary.mjsmodel.verify()、工作区里没有未声明的改动support/scenario.ts的收尾检查self-test/概念
scenarios/files/read-and-edit.spec.ts:读一个文件,批准后改另一个文件VERBS:send、approve、reject、stop、waitIdle、expectTool、expectReply;Product接口由它推导surfaces/tui.tsselfTest('动作', { 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测试只从三个地方接触产品:终端的输入输出、假模型收到的请求、工作区的磁盘。产品是独立的子进程,测试没有别的入口。
关键决策
scenario(),本体只收三个参数testtest的话,场景能拿到page、test.info(),也能用test.skip,「场景看不到面」就只能靠 lint 守script命令包一层,CLI 看到的是真终端send怎么输入approve、reject以什么为证据Approved: …或Rejected: …expect*等到什么时候Worked for、新增的Interrupted by user,或新增的Error: [Error: …这样的文字;等待模型和执行工具时产品只显示月相图标,没有文字标签❯、●、✗;工具卡片要符合整张卡的格式❯ …或● Used Read (…)是缩进的续行,不是条目;以Used开头的普通回复也不是工具卡片expect*看哪些内容Read N files卡片。expectTool按ctrl+o展开、逐个核对文件和状态,再按一次收起KIMI_*名字能用docs/en/configuration/env-vars.md里的except或onlyOn加理由,报告里显示为跳过并带着理由support/scenario.ts生效selfTest()登记时检查每个面都有正例和反例;self-test/coverage.spec.ts检查每个动作都有自测文件prefix: true,把 CDN 上fd/和rg/的下载按前缀回 404阅读指南
tests/e2e/AGENTS.md:规矩和每条规矩由什么守。tests/e2e/scenarios/files/read-and-edit.spec.ts:一个场景长什么样。tests/e2e/support/verbs.ts,再看support/scenario.ts:场景 API、夹具的生命周期和收尾检查。tests/e2e/surfaces/tui.ts:每个动作在 TUI 上怎么做、以屏幕上的什么为证据。tests/e2e/self-test/*.spec.ts:动作的含义由这些用例固定。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 linte2e-boundary,只检查tests/e2e下的 JS/TS 文件scripts/checks/e2e-boundary.json,要写理由FetchStuburl必须和请求地址完全相同prefix;不写时仍然是完全相同才匹配E2E工作流Build (optional)和TUI (optional)两个作业tests/e2e/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 个完整性检查。验证
TESTKIT_CLI_BUILD=dist)下各跑过,36 个用例全过。最新提交上做过加压:6 个占满 CPU 的进程加 10 个 worker,全套 3 轮共 108 次全过;上一个提交上同样的负载下stop的正例 40 次全过。没有残留进程,通过的用例不留临时目录。把fd和rg从PATH里拿掉来模拟 CI:全过;去掉前缀桩后网络守卫记下对 CDN 的连接,用例变红。TUI (optional)作业验证。TUI 驱动用的script写法和已有的真 PTY 冒烟相同。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 replyexpectReply、expectTool会匹配上一回合的内容expectReply negative: does not take a reply from an earlier turn;expectTool negative: does not take a tool from an earlier turnsend negative里新增一条断言directoryChanges把名字像constructor的新增文件报成「内容变化」packages/testkit/test/fixtures.test.ts新增一例process.(句号结尾的英文)和标题里的retries当成违规;fetch (、x.sleep(这类写法漏过scripts/checks/e2e-boundary.test.mjs新增和扩充的用例expectReply找不到第二段里的文字expectReply positive: finds text in a later paragraph of the replyE2E_CLI_EXIT=0时,等待直接报「CLI 已退出」waitIdle positive: keeps following a conversation that mentions a process exit status。标记现在带每次启动随机生成的后缀expectTool找不到单个文件expectTool({ name: 'Read', target: 'a.txt', … })失败expectTool新增三例:逐个文件能找到、不在其中的文件报错、组内读取失败的文件状态是failedwaitIdle等到超时waitIdle positive: returns after a reply whose line starts with a moon emojiexpectReply找不到分隔线之后的文字expectReply positive: finds text after a horizontal rule in the reply❯ …被当成新的用户消息;引用的● Used Read (…)能让expectTool通过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 markerUsed或Read 2 files开头的普通回复被当成工具卡片expectReply找不到这条回复expectReply positive: finds a reply whose first words read like the start of a tool card上表每个
tests/e2e的回归用例都先在修复前跑过,确认是红的。已知的限制
tests/e2e/AGENTS.md里写了:剧本里的思考文本不要包含要断言的回复文字。support/scenario.ts,不是场景文件,因为test()是在scenario()里调用的。标题唯一,按文件过滤也照常可用。留给维护者决定
tests/e2e是纯测试。如果希望给 testkit 记一条,请在评审里说明。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.