Repository navigation
test: add the e2e prompt cache topic - #5526
Conversation
Add tests/e2e/scenarios/cache with a catalog of the user operations that may change the prompt prefix the product sends to the model service, a lint check that keeps the catalog and the cache scenarios in step, and the first cache scenarios: automatic compaction, an MCP server adding a tool with and without on-demand tool loading, a retry after a finished turn, files changed outside the product, and trusting a new folder. The existing restart cache scenario moves into the same directory. Scenarios can now set the fake provider, merge config.toml and declare MCP servers whose tools change in the middle of a session. Every scenario fails when the main requests of a session use more than one prompt cache key, and failed scenarios attach the prompt cache ledger.
|
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: ab100c5666
ℹ️ 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".
The MCP server handle in the e2e scenarios returned once the product had asked for the tool list again, before the fake server had answered, so the next prompt could reach the product before it applied the change. Record answered requests on the fake HTTP MCP server and wait for the answer to the next tools/list instead. The product applies a refreshed tool list asynchronously and does not promise that the very next request reflects it, so the two MCP cache scenarios now require the new tool to be announced exactly once after the change rather than in the next request.
…-cache-topic # Conflicts: # package.json
Requirement or Bug
Prompt 缓存命中直接决定每一轮对话的成本和延迟,用户在会话里做的很多事(重启、重试、改文件、MCP 服务变工具、压缩……)都可能让产品改写请求前缀。E2E 的假模型默认已经开着缓存账本,但只有一个场景专门针对缓存。把现有 36 个场景在 6 个 project 上的账本导出来看,有 10 个场景只有一个被接受的主请求,在缓存上什么都没验证;产品如果在会话中途换了缓存键,账本也不会报错;场景还没法模拟用户配置 MCP 服务、改 provider 配置这些情况。
这个 PR 在
tests/e2e下建立 cache 专题:一份清单列出会改变请求前缀的用户操作和每项的承诺,lint 保证清单和场景对得上;补上让场景能模拟这些情况的基建;先写第一批 6 个场景,并把现有的重启缓存场景搬进来。Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
核心思路:判定只看产品发给模型服务的请求,场景只用用户能做的操作驱动产品。
tests/e2e/scenarios/cache/catalog.yaml是这个专题的总账:每一项写明用户操作、承诺(保持前缀、有意断开,或者还没查清)和哪些测试覆盖它,没覆盖的写明缺什么。新的 lint 检查保证账和场景一致。场景框架多了三个选项(provider、config、mcp)和一个对所有场景都生效的收尾检查:同一个会话的主请求只能用一个缓存键。catalog.yaml,39 项,其中 20 项写明了缺口explicit(scenarios/cache/下的场景)、implicit(别的 E2E 场景会走到,由默认的账本检查覆盖)、kap(tests/scenarios)、engine(包内测试)newSession()的次数」就失败清单和检查只管「账对不对」,缓存本身的判定仍然由 testkit 的账本做:场景把用户操作做完,账本按服务端的规则比较前后两次请求,场景再显式断言延续关系。
tests/quarantine.yaml一个做法。场景只能 importsupport/scenario.ts和 testkit 的剧本,TS 常量要改边界规则addTool一类的方法等假服务收到产品新的tools/list才返回阅读指南:
tests/e2e/scenarios/cache/catalog.yaml:专题覆盖什么、缺什么;scripts/checks/e2e-cache-catalog.mjs和它的测试:清单要守的规则;tests/e2e/support/scenario.ts:provider、config、mcp怎么变成测试 home 里的config.toml和mcp.json,mcp()句柄怎么等产品重新读取工具清单,收尾检查和失败附件;tests/e2e/scenarios/cache/下的场景。可以略读:
packages/testkit里writeMcpConfig多接受 HTTP 和 SSE 条目、步骤标题、CODEOWNERS、lint 接线和tests/e2e/AGENTS.md的说明。第一批场景:
restart-keeps-the-prefix(从conversation/搬来,内容不变)automatic-compaction-keeps-the-prefixmcp-tool-change-keeps-the-tool-listmcp-tool-change-with-on-demand-loading-keeps-the-prefixdeferred时,新工具从对话里公告,前缀不变retry-after-a-finished-turn-keeps-the-prefixfiles-changed-outside-the-product-keep-the-prefixtrusting-a-new-folder-keeps-the-prefixBehavior Changes and Affected Users
没有改产品代码,产品行为不变。测试一侧的变化:
newSession()的次数」就失败model-requestsprompt-cache:每个请求的通道、缓存键、基线、断点和复用量,以及账本报出的问题scenarios/conversation/keeps-one-prompt-cache-prefix-across-a-restart.spec.tsscenarios/cache/restart-keeps-the-prefix.spec.ts,内容不变pnpm lintscripts/checks/e2e-cache-catalog.mjswriteMcpConfig{ transport: 'http' | 'sse', url, deferred? }验证:整套 E2E(场景加驱动自测)在 macOS 上 6 个 project 都跑过;同步到最新的 main 之后,又重跑了受影响的部分。结果见下面的折叠块。新的收尾检查做过破坏性验证:临时让场景会话不统计
newSession(),approval/new-session-asks-again在收尾时报出两个缓存键,失败报告里带上了prompt-cache附件。只在 macOS 上跑过;Linux 和 Windows 交给这个 PR 的 E2E 作业。运行的命令和结果
pnpm lint:通过,包括新的e2e-cache-catalog(39 项,7 个 cache 场景都已登记,20 项写明了缺口)。pnpm exec tsc -p tests/e2e/tsconfig.json --noEmit、pnpm exec tsc -p packages/testkit/tsconfig.json --noEmit:通过。node --test 'scripts/checks/*.test.mjs':115 条通过,其中 8 条是新检查的。pnpm exec vitest run packages/testkit/test/fixtures.test.ts:60 条通过。32b0ddcab,跑构建产物(TESTKIT_CLI_BUILD=dist):--project=tui --project=tui-kitty --project=acp --project=acp-bare:707 条通过、113 条不适用,用时 6.0 分钟;--project=web --project=desktop:374 条通过、36 条不适用,用时 24.6 分钟。5a6d97c1d之后,在 6 个 project 上重跑scenarios/cache/、conversation/quit-during-turn-keeps-the-prompt、files/file-tool-cards-survive-restart,以及restart、restartDuringTurn、newSession的自测:newSession(),approval/new-session-asks-again在 TUI 上收尾失败,报出两个缓存键;json reporter 里能看到prompt-cache附件。改动已还原。写场景时查清的两件事
toolSelectService.ts的state.initial)。新增的工具只在提醒里出现,提醒原文是The current model cannot load runtime tool additions。这对缓存是好的,清单里 C1 的承诺按实测写成「保持」。tool_call。ACP 驱动的expectTool要求读取发生在工具运行期间,所以 E2 场景只对第一次读取查工具卡,第二次读取用回复和模型收到的内容来验证。这和缓存无关,单独记录,没有在这个 PR 里处理。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.