Skip to content

test: cover the remaining user operations in the e2e cache topic - #5578

Merged
RealKai42 merged 14 commits into
mainfrom
test/e2e-cache-batch-3
Nov 27, 2026
Merged

RealKai42 merged 14 commits into
mainfrom
test/e2e-cache-batch-3

Conversation

@RealKai42

@RealKai42 RealKai42 commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

这是 tests/e2e/scenarios/cache 专题(#5526)的第 3 批,也是最后一批。清单 catalog.yaml 列出会改变产品发给模型服务的请求的用户操作,开这个 PR 之前还有 16 项写着缺口,多数是因为驱动还没有对应的用户动作:换模型、思考强度、计划模式、/btw、回到旧会话、/reload、技能、/init 等。这个 PR 把有价值的都补上:先加用户动作和驱动自测,再写缓存场景。做完之后清单 40 项,只剩 2 项缺口。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

核心思路:每一项都是同一个套路。先用真实的用户操作做这件事,证明它生效了(界面上看得见的效果,或者模型收到的内容),再断言账本里前后主请求的延续关系:承诺「保持」的,一路以上一次主请求为基线、没有断点,system 和工具不变;承诺「有意断开」的,用清单里的原因声明断点,并断言断点只落在该落的那一段。

新增的用户动作(都登记在 support/verbs.ts 的 VERBS,每个面都有正例和反例自测,tests/e2e/AGENTS.md「写驱动」表里各有一行写明各面怎么做、证据是什么):

动作 面 用户怎么做
openSession(标题) 四个面 TUI /sessions 面板;Desktop/Web 点侧栏会话行;ACP session/list 加 session/load
switchModel(名字)、setThinkingEffort(强度) 四个面 TUI /model、/effort 选择器;Desktop/Web 模型菜单;ACP session/set_config_option
setPlanMode('on' | 'off') 四个面 TUI /plan on/off;Desktop/Web Add 菜单里的 Plan 和 Exit mode;ACP session/set_mode plan
btw(问题, 回答) TUI、Desktop、Web /btw,看到旁路回答后关掉旁路回到主对话。ACP 没有旁路问题
reload() TUI、Desktop、Web /reload。ACP 没有重新加载会话的请求
useSkill(名字) 四个面 /skill:<名字>
init() TUI /init。别的面没有这个入口
addDir(路径) TUI /add-dir
setBrowserControl('on' | 'off') Desktop 设置里的「让 agent 控制内置浏览器」开关

缓存场景(scenarios/cache/):

清单项 场景 承诺
A2 going-back-to-an-earlier-session-keeps-its-prefix 回到旧会话后,以旧会话最后一次请求为基线,同一个缓存键
A3 manual-compaction-keeps-the-prefix-across-a-restart 压缩、压缩后一回合、重启、再一回合,重启后以压缩后的请求为基线
A5 undo-breaks-only-the-history 有意断开历史:断点只在历史上,撤销后的请求仍复用撤销点之前的前缀
B2 plan-mode-keeps-the-prefix 计划模式开和关只加提醒
B3 switching-to-another-model-and-back-keeps-the-prefix 换回第一个模型后接着它自己的前缀
B4 thinking-effort-change-breaks-only-the-model-settings 有意断开模型参数:断点只在 params,历史不变
B7 adding-a-workspace-directory-keeps-the-prefix /add-dir 只加提醒,system 不重渲染
B8 reload-keeps-the-prefix /reload 不改前缀
C4 skill-keeps-the-prefix 技能正文作为消息送达,前缀不变
C5 turning-the-browser-control-off-and-on-keeps-the-prefix 开关只加提醒,工具清单不变(只在 Desktop)
D9 side-question-keeps-the-prefix 旁路请求复用主对话前缀(reusedTokens 覆盖上一次主请求),主对话之后照常延续
E3 git-branch-switch-keeps-the-prefix 在终端切 git 分支,前缀不变
E6 init-keeps-the-prefix /init 写出 AGENTS.md 后 system 不变(只在 TUI)

KAP 场景(tests/scenarios/prompt-cache.test.ts):B6 goal 模式、B9 关掉实验特性后重新加载、C7 启用插件、F1 第二个客户端中途订阅并发出下一回合。这几项要么协议层更便宜,要么 E2E 没有办法准备(例如在测试 home 里安装插件)。

清单的其他改动:A7 新增一项,压缩请求被服务端拒为太长后去掉最早的消息重试,有意断开历史,覆盖指向 #5538 的两条引擎用例;B6、B7、B9、C5、C7 原来承诺未定,读代码并实测后都定为「保持」,依据写在各自的说明里。

测试基建:

  • 场景选项 git 和 workspace.git(参数):把工作区做成 git 仓库,像用户在自己的终端里那样跑 git。testkit 的 createGitRepository 支持分支,新增 runGit;测试仓库设了 core.autocrlf=false,检出的文件和提交时一字不差,不随机器的 git 配置变(Windows 的 CI 机器默认会把换行换成 CRLF)。工作区快照不计 .git/。
  • support/scenario.ts 改成按会话记录「标题和上一条提示词」,openSession() 之后 restart() 等的是当前会话的上一条提示词。收尾检查「主请求的缓存键个数 ≤ 1 + newSession() 次数」不变:回到旧会话不算新会话。
  • ACP 驱动的 setPermissionMode 和 setPlanMode 共用同一个切模式的实现,setPermissionMode 的行为不变。

阅读顺序:

  1. tests/e2e/scenarios/cache/catalog.yaml:每项的承诺、覆盖和依据;
  2. tests/e2e/AGENTS.md「写驱动」表里新增的几行;
  3. 挑一个场景看套路,例如 switching-to-another-model-and-back-keeps-the-prefix 和 thinking-effort-change-breaks-only-the-model-settings;
  4. 各面驱动里对应的方法(surfaces/tui.ts、surfaces/acp.ts、surfaces/renderer.ts)和 self-test/ 下的新自测。

可以略读:STEP_TITLES 的中文步骤标题、page-driver.ts 的转发。

Behavior Changes and Affected Users

没有改产品代码,产品行为不变。测试一侧:

行为 之前 之后 谁依赖旧行为 退路
testkit createGitRepository 建的仓库 换行转换跟着机器的 git 配置 仓库自己设 core.autocrlf=false,文件原样检出 用它的测试(createGitWorktree 等),Windows 上原来可能拿到 CRLF 不需要:只会更确定
E2E 场景会话的「上一条提示词」 整个场景一份 按会话各记一份 用 newSession() 再 restart() 的场景 不需要:没有 openSession() 时和原来一样
ACP 驱动的 setPermissionMode 自己发 session/set_mode 和 setPlanMode 共用一个实现 setPermissionMode 的自测和场景 不需要:请求和证据都没变

顺带发现的产品问题(都和缓存无关,没在这个 PR 里改):

  • Windows 上经 SDK 建的会话(TUI、print 模式、SDK)收不到日期提醒:E5 场景在 Windows tui 上发现,已由 fix(agent-core-v2): compare working directories as paths before sending the date reminder #5576 修复。
  • 启用插件后,产品对用户和模型都说「运行 /reload 或 /new 生效」,但 /reload 恢复的是存下来的 system,插件的 prompt 进不来,只有新会话才有。建议改文案,不要让 /reload 重渲染 system,那会破坏缓存。

验证:见折叠块。

运行的命令和结果

本地在 macOS 上跑,E2E 全部交给本 PR 的 CI(Linux 和 Windows)。

  • pnpm lint:通过,e2e-cache-catalog 报 40 项、24 个缓存场景都已登记、2 项写明了缺口(C7 的 E2E、E1)。
  • node --test 'scripts/checks/*.test.mjs':124 条通过。
  • pnpm run check:duplication 488dbc119:没有新增重复。
  • pnpm exec tsc -p tests/e2e/tsconfig.json --noEmit、pnpm exec tsc -p tests/scenarios/tsconfig.json --noEmit、pnpm exec tsc -p packages/testkit/tsconfig.json --noEmit:通过。
  • pnpm exec vitest run packages/testkit/test/fixtures.test.ts -t createGit:2 条通过,其中 1 条是新加的分支和 runGit。
  • tests/scenarios/prompt-cache.test.ts 里新增的 KAP 用例在本地跑过,通过。
  • 新加的动作、自测和 E2E 场景没有在本地跑 Playwright,以 CI 结果为准。各动作在写之前都读过产品源码核对了界面文字和可访问名字,几项承诺也先用临时 KAP 用例实测过(已删除)。

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.

@changeset-bot

changeset-bot Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: c6213cc

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 26, 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-27T05:50:56.876571Z c6213cc New commits
ℹ️ 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 26, 2026 •

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

commit: c6213cc

@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: 0de999293f

ℹ️ 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 packages/testkit/src/fixtures/git.ts Resolved
Add an openSession action that returns to an earlier session the way a
user does on each surface: the /sessions picker in the terminal UI, the
sidebar in Desktop and Web, and session/list plus session/load from an
ACP editor. Sessions are found by their title, which is the first prompt
of the session when the product cannot generate titles.

The new cache scenario starts a second session, goes back to the first
one and checks that the next request extends the first session's last
request under the same prompt cache key, while the second session uses
a key of its own. Catalog entry A2 now lists it as explicit coverage.
Add the reload, init and useSkill actions to the E2E drivers, with a
self-test for each, and cover catalog entries B8, E6 and C4 with cache
scenarios that check the main requests continue one another while the
system prompt and the tool list stay the same.
…ache scenarios

Add switchModel and setThinkingEffort to every e2e surface with self-tests,
cover B3 (switching to another model and back keeps the first model's prefix)
and B4 (changing the thinking effort breaks only the model settings) in the
prompt cache catalog.

@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: b66c741122

ℹ️ 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/acp.ts Resolved
…ments, browser control and plugins

Goal mode, /add-dir, /experiments, turning the Desktop browser control off
and enabling a plugin all keep the request prefix: the system prompt and the
tool list stay as the session started, and the change reaches the model in
reminders. Record the promises as keeps and say what each entry still needs.
…ode, experiments and plugins

Add two E2E actions with self-tests: addDir on the TUI, which adds a
workspace directory for this session with /add-dir, and setBrowserControl
on Desktop, which switches agent control of the built-in browser in the
Browser settings. Two cache scenarios use them to show that the system
prompt, the tool list and the prompt cache prefix stay the same while the
change reaches the model in a reminder.

The KAP prompt cache scenarios now also start a goal between two turns,
turn an experimental feature off and reload the session, and enable a
plugin, and the catalog lists all five entries as covered.
Add a setPlanMode action on every surface and a btw action on the
terminal UI, Desktop and Web, each with positive and negative
self-tests. ACP has no side question: the agent answers /btw with
"Unknown ACP command".

Two cache scenarios use them. Turning plan mode on and off between
turns reaches the model as reminders while system and tools stay the
same, and the main requests continue one prefix. A /btw side question
leaves the main history alone, and its request reuses the whole
prefix of the last main request before it.

Catalog entries B2 and D9 now list these scenarios instead of a gap.

@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: b8a32a7251

ℹ️ 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
…eep workspace snapshots out of .git

- TUI: after /sessions the CLI stops drawing the activity area, so the
  replayed last entry and the resume notice sit right on top of the
  input box. The driver now counts that block as transcript instead of
  status, so expectReply and expectTranscript see the resumed turn.
- Desktop and Web: the side chat does not split its conversation into
  list rows. btw() now finds the question as exact text in the Side Chat
  tab and the reply as a visible Markdown block outside its input.
- snapshotDirectory takes a list of top-level directories to skip, and
  git workspaces skip .git, so a lock file that git removes mid-snapshot
  no longer fails the step on Windows.
…ig options on reopening a session

- TUI btw(): the side panel has no sign that the side turn finished, so
  two identical reads were taken as the end. Between two streamed parts
  the panel holds still, and the driver pressed Esc and cancelled the
  rest of the answer. It now waits for the requested reply or a failure
  line, and closes the panel before it throws on a timeout. A new
  self-test streams the side answer in two parts.
- ACP openSession(): keep the configuration options that session/load
  returns, as the restart path already does. Before, switchModel() in a
  reopened session read the options of the session it had just left. A
  new self-test switches back to the first model in an earlier session
  left on the second one.

@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: c6213cc263

ℹ️ 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/acp.ts
Comment on lines +496 to +497
await this.switchMode('setPlanMode()', state === 'on' ? PLAN_MODE : (this.modeBeforePlan ?? SESSION_MODES.manual));
this.modeBeforePlan = state === 'on' ? current : undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep the pre-plan permission mode scoped to its session

When two sessions enter plan mode from different permission modes, modeBeforePlan can belong to the session just left rather than the one currently open. For example, enter plan mode in session A from manual, create session B, switch B to yolo and enter plan mode, then reopen A and turn plan mode off. Because openSession() never restores or clears modeBeforePlan, this call switches A to yolo instead of its original manual, silently changing approval behavior in subsequent scenario steps. Store the pre-plan mode per session and restore it when reopening that session, using the documented default only when its previous mode is unknown.

AGENTS.md reference: tests/e2e/AGENTS.md:L113-L113

Useful? React with 👍 / 👎.

@RealKai42
RealKai42 merged commit 8d9c3f8 into main Nov 27, 2026
19 of 27 checks passed
@RealKai42
RealKai42 deleted the test/e2e-cache-batch-3 branch November 27, 2026 06:03
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