Repository navigation
test: move seven KAP conversation contract cases onto testkit scenarios - #5200
Conversation
Move S1 to S6 and the steered-turn undo case from packages/kap-server/test/conversationContract.e2e.test.ts into tests/scenarios/conversation.test.ts. The scenarios hold the fake model at named points instead of delaying replies by 1.5 to 4 seconds, wait on KAP frames and the session wait endpoint instead of polling, and observe the server only through KAP. S2 and S3 fold into the existing queue and approval scenarios as extra assertions.
|
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: |
Requirement or Bug
packages/kap-server/test/conversationContract.e2e.test.ts守着 KAP 的对话契约:回合和条目在 WS 帧上的实时变化要和 REST 分页一致,中途插话、审批、后台任务、取消、继续、撤销的协议行为要对。它用一个手写的 OpenAI 流假模型,靠固定延迟(1.5 到 4 秒)让回合停在「进行中」,再每 150 毫秒轮询一次结果。中途操作能不能落在回合进行中,取决于延迟够不够长。最近三周这个文件在 8 个分支上失败了 40 次,其中 2 次同一提交重跑后通过。这个 PR 是把脆弱用例迁到 testkit 的第一批试点:把其中最依赖时序的 7 条搬到 testkit 场景上,断言逐条保留。
Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
核心思路:用 testkit 的挂起点
held()把假模型停在确定的位置,等hold.reached()后再做中途操作,做完再release(),不再依赖延迟的长短。等待改为kap.waitIdle(服务端长轮询)和socket.waitFor(等具体的帧),不再每 150 毫秒轮询。每条用例有自己的服务端和 home,收尾时自动核对编排的回复是否用完、挂起点是否都已放行。tests/scenarios/conversation.test.ts)item.started再放行prompt_ids和结束状态:wait等待审批三处有意的差异,其余断言原样保留,逐条对应见下方折叠块:
closeSessionById关会话再读回。KAP 没有关闭会话的接口,所以改为重启服务端后读回。验证的仍然是「落盘的回合和内存里的一致」。:wait接口取。tests/scenarios只允许通过 KAP 和 testkit 观察,boundaries.test.ts会检查这一点。model.callId(0, 0)和原场景里的命令,断言的含义不变。旧文件还剩 S7、S9、S10、S11、S12、S13 六条,留给后面两批;只被已迁用例用到的导入和辅助成员一并删掉。手写的 SSE 辅助函数仍被剩下的用例使用,所以这个文件的旧替身基线(
inline-openai-stream6 处)这次不变,最后一批删掉旧文件时归零。每条旧断言在新场景里的位置
新场景都在
tests/scenarios/conversation.test.ts。S1 → 「keeps streamed item ids in the persisted turn and reports the agent idle only after the turn ends」
turns帧,has_more为 false:原样保留。ordinal、turn_number、kind、status、outcome的值,turn_id的格式,没有end_reason,ended_at是字符串:原样保留。output为 4,回合用量等于 step 用量:原样保留。用量改由withUsage({ input: 10, output: 4 })给出,数值和旧的假模型相同。prompt_ids、来源、文本、附件、技能都对得上:原样保留。hello world:原样保留。item.started和text字段的item.delta帧,turn.updated只带 step 1:原样保留。回复在第一个分片后挂起,收到item.started后才放行,所以一定会有单独的item.delta。compacting: false,都不带turn_number、prompt_id、retry;running 之后的 idle 帧排在turn.ended之后:原样保留。S2 → 并入「queues a prompt sent while the model is still replying and runs it as its own turn」
prompt_ids依次是两次提交的 id:新增断言。撤销插话后的回合 → 「undoes a steered turn on REST and WebSocket and gives the resent prompt the same ordinal」
prompts:steer加prompt_ids:接口不变。prompt_id;WS 等于 REST:原样保留。turns.removed帧带两轮 id,不会补发新的turns快照,WS 为空,重新订阅的快照为空:原样保留。closeSessionById关会话再读回;KAP 没有关闭会话的接口,改为重启服务端后读回。S3 → 并入「waits for approval in manual mode, shows it on the tool item and runs the tool once approved」
:wait(kap.waitForInteraction),并沿用原场景对交互字段的断言。item.started帧。interaction_id都对得上,没有stage,输出包含命令结果:原样保留。item.started,之后有 stage 为 awaiting_approval、带interaction_id的item.updated,item.ended只有一次;WS 等于 REST:原样保留。model.callId(0, 0),命令沿用原场景的echo approved-run。S4 → 「reports a background subagent as a task and starts a notification turn when it completes」
child_agent_id是字符串:原样保留。<notification:原样保留。原来的写法是判断标题长度大于 0。agent_refs指向子 agent;WS 等于 REST:原样保留。S5 → 「shows a client that subscribes mid-turn the running turn and a running agent」
turn.ended,WS 等于 REST:原样保留。S6 → 「gives a client that subscribes after a turn the same turns page as REST」
has_more与 REST 默认分页一致;只有一个已结束的 Bash 工具条目,id 对得上:原样保留。调用 id 改用model.callId(0, 0)。Behavior Changes and Affected Users
None。只改了测试:没有改产品代码、KAP 契约文件(
packages/kap-server/schema/)、能力清单、CI 工作流或棘轮基线。这 7 个行为原来在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 3f514458d:没有新增重复。满负载对比:用 10 个空转进程占满本机 10 个核,新旧 7 条各跑 50 遍。
旧用例在本机加负载后也没有失败,CI 上偶发的那几次没能在本机复现。所以这一批能确定的收益是:
迁移前后在 CI 上稳定性的差异,要靠合入后的 CI 记录确认。
Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.