Repository navigation
test: move four more KAP conversation contract cases onto testkit scenarios - #5202
Conversation
|
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: |
Keep both testkit model imports in conversation.test.ts: call from the invalid tool argument retry scenario on main and todoList from this branch.
Requirement or Bug
这是把
packages/kap-server/test/conversationContract.e2e.test.ts迁到 testkit 场景的第二批,第一批是 #5200。这一批搬的是会话控制相关的 4 条:取消(S11)、继续(S13)、新会话的 agent 帧和 todo 帧(S10),以及关闭旁聊 agent(S12)。这几条原来的写法有三个问题:
Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
核心思路和第一批相同:用
held()把假模型停在确定的位置,用 KAP 帧和:wait接口等待,只通过 KAP 观察,每条用例有自己的服务端和 home。tests/scenarios/conversation.test.ts)end_reason、二次取消和会话状态的断言:continuecompaction通道三处有意的差异,其余断言原样保留,逐条对应见下方折叠块:
activity为 background。cwd:旧用例用/tmp建会话,testkit 用自己隔离的工作区,断言改为和它比较。旧文件只剩 S7、S9 两条,留给第三批。下面这些只被已迁用例用到,一并删掉了:
sseTextChunks、帧还原、WS 订阅封装、超时诊断;这个文件的旧替身基线(
inline-openai-stream)按test-doubles检查的要求从 6 降到 4。关闭旁聊 agent 的场景单条约 3.2 秒,时间全花在关闭接口本身:引擎移除 agent 时最多等它静止 3 秒,空闲的旁聊 agent 每次都等满。旧用例同样如此(约 3.4 秒)。这是产品问题,另行处理,这个 PR 不改。
每条旧断言在新场景里的位置
新场景都在
tests/scenarios/conversation.test.ts。S11 前半 → 并入「cancels a turn while the model request is in flight and has nothing to cancel once idle」
cwd等于请求里的cwd,activity为 idle:保留。旧用例请求的是/tmp,testkit 传的是自己隔离的工作区,断言改为和它比较。turn.started帧。{ cancelled: true }:原场景已有。end_reason: user_cancelled结束:保留。{ cancelled: false };会话activity为 idle,last_turn_outcome为 interrupted:保留。S11 后半 → 「keeps a background command running on cancel until the client also asks to stop background work」
sleep 10:保留。旧用例绕过模型直接调用引擎执行 Bash;现在由假模型在一轮里发起bash({ ..., run_in_background: true }),等这一轮结束后再取消。include_background取消返回{ cancelled: false },任务最后一帧仍是 running:保留。新增一条:会话activity为 background。include_background取消返回{ cancelled: true },任务以 killed 结束:保留。S13 → 「continues an interrupted or failed turn and refuses when nothing is left to continue or a turn is running」
:continue报 40940;回合进行中报 40901:保留。回合在第一个分片后挂起,旧用例是暂停 5 秒。{ continued: true },续上的一轮已完成、没有用户消息、回答为resumed reply,回合数至少为 2:保留。已完成时再继续报 40940:保留。httpError(400)。Summarize the conversation和Continue the interrupted work from where it stopped识别压缩请求和继续请求。现在压缩请求按请求元数据进 testkit 的compaction通道,继续请求按顺序由主通道回答。turn.ended,再检查最后一轮。S10 → 「sends a new subscriber the idle main agent and its empty todo list, then pushes TodoList writes」
todoList(...)生成。S12 → 「closes a side agent with an ended agent frame and refuses to close the main agent」
{ closed: true },它的最后一条 agent 帧是 ended、compacting: false:保留。KapEnvelopeError.code读取。Behavior Changes and Affected Users
None。只改了测试和
scripts/checks/baselines/test-doubles.json里这个文件的计数(只降不升)。没有改产品代码、KAP 契约文件、能力清单或 CI 工作流。旧文件里这 4 条用例覆盖的行为原来在kap-server项目里跑,现在在scenarios项目里跑,两者都属于根目录pnpm test的 Linux 分片。本机验证(macOS):
pnpm exec vitest run tests/scenarios/conversation.test.ts packages/kap-server/test/conversationContract.e2e.test.ts tests/scenarios/boundaries.test.ts:24 条全部通过。pnpm exec tsc -p tests/scenarios/tsconfig.json --noEmit和pnpm exec tsc -p packages/kap-server/tsconfig.json --noEmit:通过。pnpm lint:通过。pnpm run check:duplication 2e37a3208:没有新增重复。满负载对比:用 10 个空转进程占满本机 10 个核,新旧各跑 50 遍。
两边的耗时里都有关闭旁聊 agent 时那 3 秒左右的等待。和第一批一样,旧用例在本机加负载后也没有失败。所以这一批能确定的收益是:
:continue(应报 40901)都发生在挂起点上,不再取决于 5 秒的暂停够不够长;Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.