Repository navigation
test(e2e): check what a running or stopped command printed - #5365
Conversation
…is sent Session update frames are queued and sent after several async reads, while interaction frames are sent the moment an approval or a question appears. A queued frame could therefore report pending_interaction "none" after the client had already received the pending interaction. The desktop and web clients then dropped the approval prompt and the session kept waiting. Read pending_interaction at the moment the frame is sent. The rest of a frame pushed for an activity change still describes that change, and a frame is sent as built when the current state of its session can no longer be read.
…val-dropped-by-stale-session-frame
expectTool() gains the status "running" and, for Bash, an "output" line. A running command can only be expected together with a line it has printed: until a command prints, the surfaces do not agree on whether it is running or still waiting for approval. The output is matched as a whole line of what the command printed, on the same card as the status. The new scenario stops a command that has already printed a line and checks that the line is still shown and that the model receives it with the next message. The TUI driver now takes a turn for stopped only when the stop notice is the last entry of the transcript, because a stopped command carries the same sentence in its own card.
…stopped-command-output
|
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: |
…tens The ACP driver attached its exit listener to a terminal command only after it had closed the command's log file. A command that ends almost at once, such as `echo two >> b.txt` or `exit 3`, could exit while that close was pending, so its exit event fired with no listener. The driver then never reported an exit status in terminal/output, never answered terminal/wait_for_exit, and the turn timed out. Listen for exit right after spawn, before any await, keep the status in the terminal's exit promise, and copy it onto the terminal record once the record exists.
Requirement or Bug
「用户停止一条正在运行的命令之后,它已经打印出来的内容不能丢:界面上还看得到,模型下一轮也拿得到。」这条行为在引擎(#4854)、服务端(#4772)和客户端各坏过一次,三次修复的测试都在各自模块内部,没有一条从用户入口验证整条链路。
新 E2E 现有的动作写不出这个场景,缺两样:
expectTool只查工具名、目标和状态。这个 PR 给
expectTool补上这两样,并加一个四个面共用的场景。只改测试,不改产品。Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
核心思路
expectTool多了一个状态running和一个只有 Bash 能带的条件output。动作还是七个,没有加新的。状态和输出必须在同一张卡片上同时成立。
output写的是命令打印出来的完整一行。等待规则和原来一样:等到期望成立或回合结束,回合结束了还不成立就报错。它们在四个面上各指什么:
runningoutputRunning a command · $ <命令>Approved:之类)之前的那些行里,有完全相同的一行role="status"、aria-label="running"Output的面板的正文里,有完全相同的一行。驱动先点开卡片,读完再收回去completed或failed回合已经结束时,没有命令算运行中。
关键决策
running能不能单独用output,用类型限制住running单独也能查running和output都只对 Bash;被拒绝的命令不能带outputWaiting for output…,TUI 的提示Press Ctrl+B to run in background,产品追加在结果末尾的行。按「包含」比,output: 'output'这种写法在命令还没打印、甚至审批还挂着的时候就会成立printf 'rea%s\n' dy,打印出来的ready不在命令里Output找到面板,取它的正文role和名字approve()stop()的证据Interrupted by userInterrupted by user就算stop()也会通过新场景
scenarios/turn/stop-running-command.spec.ts,标题keeps what a stopped command printed:ready再等 30 秒的命令,批准;看到ready之后按停止;再问「它打印了什么」readyready。停止后:同一条命令是 failed,ready还在。追问的回复出现新增的自测
每条都在四个面上各跑一遍。
output再查同一条命令也查得到stop)running不带output;给文件类工具带running或output;给被拒绝的命令带outputACP 驱动的一处修复
这个 PR 第一次在 Linux 上跑时,
ACP (optional)红了一条新自测:批准之后回合一直不结束。原因是 ACP 驱动里早就有的一个竞态,不是这次加的代码引入的。printf 'rea%s\n' dy早就跑完了,驱动回给 agent 的terminal/output里却一直没有退出状态,terminal/wait_for_exit也一直不答复。spawn之后立刻挂退出监听,中间不隔任何等待(第二个提交)。阅读指南
tests/e2e/support/verbs.ts:ToolExpectation的四种形状。tests/e2e/support/scenario.ts:assertToolExpectation()。surfaces/tui.ts的printedLines()和endsWithStopNotice(),surfaces/renderer.ts的showsOutput(),surfaces/acp.ts的embedsOutput()。tests/e2e/self-test/expect-tool.spec.ts新增的用例,和新场景文件。tests/e2e/AGENTS.md新增的七行。Behavior Changes and Affected Users
产品行为:None。这个 PR 没有改任何产品源码,也没有动契约文件。
对仓库贡献者和 CI 有下面这些变化:
expectTool的状态done、failed、rejectedrunning,只有 Bash 能用,必须带outputexpectTool的条件outputstop()Interrupted by user、活动指示消失,就算停住了Interrupted by usertests/e2e的场景E2E工作流不是必过检查tests/e2e的自测tests/e2e里写驱动的人not finishedrunningspawn之后立刻监听,不会错过对应的测试:6 个场景加上七个动作的自测,每个面 65 个用例,四个面共 260 个。
验证
E2E工作流验证。第一次运行TUI、Desktop、Web通过,ACP红了一条,原因和修法见上面「ACP 驱动的一处修复」。pnpm lint、node --test 'scripts/checks/*.test.mjs'、sherif、nix 工作区检查、tests/e2e的类型检查、新增重复代码检查,都通过。破坏性检查:临时改坏,确认会红
改坏驱动(每一项只跑受影响的面;
renderer.ts是 Desktop 和 Web 共用的,在 Web 上跑):Output面板output的 10 条全红running状态expectTool的运行时检查改坏产品(确认场景守得住它要守的行为):
Desktop 没有单独为这几项重新构建;它和 Web 用同一份渲染端代码和同一个驱动文件。
已知的限制
running只对 Bash、而且必须带output,理由见「关键决策」。文件类工具的「等审批」留给以后查审批内容的动作。Command executed successfully.、Interrupted by user这一类;TUI、Desktop、Web 上有,ACP 的终端里没有)和界面自己的占位、提示。驱动不区分它们,靠「整行相等」和评审避免拿它们当output。failed,所以「被打断的工具被标成出错」这种问题查不出来。output证明不了输出被显示出来了:在 ACP 里那是编辑器的事,而这里的编辑器就是驱动自己。stop()查不出来。需要审批的命令(中间隔着审批记录)查得出来。stop()要求转录的最后一条是停止提示。停止的那一刻如果正好有后台任务结束,它的记录会排在停止提示后面,stop()会报「没有被打断」。现在没有场景用后台任务。Approved:、Rejected:、Interrupted by user、Error: [开头的行时,这一行和它之后的内容不算输出。@moonshot-ai/e2e是 private 包。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.