Repository navigation
test: answer Responses requests in testkit, share test env isolation, and freeze fixed waits - #5437
Conversation
The testkit fake model now has an OpenAI Responses codec for `…/responses`. It reads `instructions` and the `input` items (messages, function calls, function call outputs, reasoning) into the shared request view, and answers with the event sequence the API sends: output items for reasoning, text and function calls, argument deltas, and a terminal `response.completed` or `response.incomplete` with usage. Non-streaming replies, HTTP errors and mid-stream error events use the API's shapes too. `fakeModelConfig` accepts the `openai_responses` provider type. The engine harness no longer rejects Responses requests; its default raw finish reasons for that protocol now match what the engine reads. The official SDK checks cover streaming, `responses.stream()`, non-streaming, truncation and errors, and a harness test drives the engine's OpenAI and Kimi Responses requesters through it.
AGENTS.md rules out sleep- and timeout-based synchronization, but tests already hold hundreds of fixed waits and nothing stopped new ones. The new fixed-waits check counts three spellings per test file: a promise resolved by setTimeout or setImmediate, a timer imported from node:timers/promises, and Playwright's waitForTimeout. Ordinary timer use, such as scheduling an abort, does not count. The baseline freezes the 636 existing waits in 230 files; a new one fails `pnpm lint` with the signal-based alternatives, and a removed one lowers the baseline. The check runs in `pnpm lint` and is listed in the guard registry, and AGENTS.md names it next to the rule.
The engine and kap-server test setups each removed only KIMI_CODE_* variables and set their own switches, while the testkit's testEnv() held a third, wider list. Both setups now call isolateProcessEnv() from the testkit, so all three share one definition. Tests in these two packages no longer see the developer's KIMI_* variables, provider API keys or proxy settings, and run with telemetry, the search worker, the minidb read model and model-catalog refresh turned off, as the testkit already did for other suites.
The Responses codec repeated the chat codec's loop that turns string or array content into view parts. Both now call contentPartsOf() and keep only their own part-type mapping. The harness's Responses finish-reason mapping lists every finish reason instead of relying on a default.
|
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: cbd8078521
ℹ️ 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 Responses codec started a new assistant message when assistant text followed a function call, so a reply such as a tool call followed by text, replayed into the next request with its function_call_output, was read as two assistant turns and the message check reported the text as arriving before the tool result. Assistant message, function call and reasoning items now merge into the current assistant turn until a user message or tool output starts a new one. A regression test replays the codec's own output through the official SDK.
The worktree service test that landed on main while this branch was open holds one promise resolved by setTimeout. The fixed-waits baseline was written before that file existed, so it now counts that wait as the file's starting point like every other existing one.
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Port the testkit half of upstream df97f8e: the Responses protocol joins the scripted model, the registry and provider config know the protocol, and the protocol suite reads created/incomplete/error events the way the SDK does. protocols 27 pass / 1 skip, typecheck clean. The agent-core-v2/kap-server setup isolation and the fixed-waits gate are recorded as remaining; that gate does not exist in this fork.
The testkit Responses half is in; the consumer setup isolation cannot import testkit fixtures without the cross-package #/ tsc collision, and the fixed-waits gate does not exist in this fork.
Requirement or Bug
这是「理清测试基建」的第 2 轮,前一轮是 #5422。这一轮收尾第 1 轮留下的几件事,补上 testkit 一直缺的 OpenAI Responses 协议,把三份测试环境隔离合并成一份,并给测试里的固定等待加上冻结检查。
Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
这个 PR 有三块,彼此独立,一块一个提交。
openai_responsesprovider 或 Kimi 的 Responses 协议的测试拿不到假模型;#5422 只能让引擎 harness 遇到这种请求时明确报错instructions和input条目(消息、函数调用、调用结果、reasoning)解析成和其他协议相同的请求视图,所以剧本、通道、消息检查都照常工作。回复一侧按真实 API 的事件顺序输出。harness 去掉了那个报错,Responses 的默认结束原因改成和引擎读到的一致KIMI_CODE_*,testkit 的testEnv()又有一份更宽的清单。这两个包的测试会读到开发者机器上真实的 provider key 和代理isolateProcessEnv()scripts/checks/fixed-waits.mjs,按文件冻结三种写法:用setTimeout/setImmediateresolve 的 Promise、node:timers/promises的计时器、Playwright 的waitForTimeout。正常的计时器用法(比如定时中止)不算。初始基线按 main 的现状冻结了 231 个文件里的 637 处,其中包括这个 PR 打开期间 #5292 在worktreeService.test.ts里新加的 1 处关键决策
e2e-boundary那样数所有setTimeout(testEnv()output_item.added、content_part.added、*.delta、*.done和最终的response.completedresponses.stream()验证时,它会按事件顺序拼出完整响应;事件不全的话,SDK 这一侧的对照就证明不了什么阅读指南
packages/testkit/src/model/protocols/openai-responses.ts:EventWriter按输出条目的顺序维护「当前打开的文本或 reasoning 条目」和「打开的函数调用」,每个流式单元写出对应的事件,收尾时补上*.done和最终状态。packages/testkit/test/protocols.test.ts的openai responses组:官方 SDK 的流式、responses.stream()、非流式、截断、HTTP 错误和流中错误。packages/agent-core-v2/test/harness/scripted-generate.test.ts:引擎的 OpenAI 和 Kimi Responses requester 经过 harness 拿到剧本里的文字、工具调用、usage 和结束原因。scripts/checks/fixed-waits.mjs和它的自测。其余的可以略读:两个 setup 文件各一行,加上
package.json、registry.json、AGENTS.md的接线,以及基线 JSON。Behavior Changes and Affected Users
产品代码没有改动。下表的变化只影响跑测试和写测试的人。
KIMI_CODE_*,再设一两个开关testEnv():清掉所有KIMI_*、各家 provider 的 key 和代理变量,关掉遥测、搜索 worker、minidb 读模型和模型目录刷新vi.stubEnvpnpm lint失败,并给出改用信号的写法--update --allow-increase更新基线,并在 PR 里说明没有 changeset:只改了测试、私有包 testkit、仓库检查脚本和说明文件。
验证
只在 macOS 上验证过,Linux 交给 CI,Windows 没有验证。
packages/testkit178 条加tests/scenarios,共 228 条,全部通过。其中 Responses 编码器有 3 条 SDK 对照和 2 条引擎对照。packages/kap-server全量 1,571 条,全部通过。packages/agent-core-v2全量 8,245 条,失败 10 条(main 上 11 条),新增 2 条:MCP stdio 子进程退出、skill 目录的文件监听。这两个文件单独各跑 3 次都通过,属于全量负载下的偶发失败,和隔离改动无关。node --test 'scripts/checks/*.test.mjs':105 条通过,其中 6 条是固定等待检查的自测。pnpm lint:通过。pnpm run check:duplication <main>:没有新增重复。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.