Skip to content

test: answer Responses requests in testkit, share test env isolation, and freeze fixed waits - #5437

Merged
RealKai42 merged 8 commits into
mainfrom
test/consolidate-test-infra
Nov 25, 2026
Merged

RealKai42 merged 8 commits into
mainfrom
test/consolidate-test-infra

Conversation

@RealKai42

@RealKai42 RealKai42 commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

这是「理清测试基建」的第 2 轮,前一轮是 #5422。这一轮收尾第 1 轮留下的几件事,补上 testkit 一直缺的 OpenAI Responses 协议,把三份测试环境隔离合并成一份,并给测试里的固定等待加上冻结检查。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

这个 PR 有三块,彼此独立,一块一个提交。

块 问题 改法
testkit 的 OpenAI Responses 协议 testkit 只会回答 chat completions、Anthropic 和 Google。用 openai_responses provider 或 Kimi 的 Responses 协议的测试拿不到假模型;#5422 只能让引擎 harness 遇到这种请求时明确报错 新增 Responses 编码器。请求一侧把 instructions 和 input 条目(消息、函数调用、调用结果、reasoning)解析成和其他协议相同的请求视图,所以剧本、通道、消息检查都照常工作。回复一侧按真实 API 的事件顺序输出。harness 去掉了那个报错,Responses 的默认结束原因改成和引擎读到的一致
测试环境隔离 引擎和 kap-server 的 setup 各自只清 KIMI_CODE_*,testkit 的 testEnv() 又有一份更宽的清单。这两个包的测试会读到开发者机器上真实的 provider key 和代理 两个 setup 都改成调用 testkit 的 isolateProcessEnv()
固定等待 AGENTS.md 禁止用 sleep 或超时同步,但测试里已有 600 多处,也没有任何东西拦住新增 新增 scripts/checks/fixed-waits.mjs,按文件冻结三种写法:用 setTimeout/setImmediate resolve 的 Promise、node:timers/promises 的计时器、Playwright 的 waitForTimeout。正常的计时器用法(比如定时中止)不算。初始基线按 main 的现状冻结了 231 个文件里的 637 处,其中包括这个 PR 打开期间 #5292 在 worktreeService.test.ts 里新加的 1 处

关键决策

决策 选择 没选 理由
固定等待数哪些写法 只数「等一段固定时间」的三种写法 像 e2e-boundary 那样数所有 setTimeout( 普通测试里有正当的计时器用法(测超时逻辑、配合假计时器)。全部计数的话,正当用法也要申请调高基线
固定等待这一轮做到哪一步 只冻结,存量不动 同时清理 清理要逐处找替代的信号,是另一件事。先让问题不再扩大
环境隔离以哪份为准 testkit 的 testEnv() 保留各包自己那份 它是三份里最完整的,tests/scenarios 和 tests/e2e 已经在用
Responses 的流事件 照真实 API 发 output_item.added、content_part.added、*.delta、*.done 和最终的 response.completed 只发引擎会读的几种事件 用官方 SDK 的 responses.stream() 验证时,它会按事件顺序拼出完整响应;事件不全的话,SDK 这一侧的对照就证明不了什么
阅读指南
  1. packages/testkit/src/model/protocols/openai-responses.ts:EventWriter 按输出条目的顺序维护「当前打开的文本或 reasoning 条目」和「打开的函数调用」,每个流式单元写出对应的事件,收尾时补上 *.done 和最终状态。
  2. packages/testkit/test/protocols.test.ts 的 openai responses 组:官方 SDK 的流式、responses.stream()、非流式、截断、HTTP 错误和流中错误。
  3. packages/agent-core-v2/test/harness/scripted-generate.test.ts:引擎的 OpenAI 和 Kimi Responses requester 经过 harness 拿到剧本里的文字、工具调用、usage 和结束原因。
  4. scripts/checks/fixed-waits.mjs 和它的自测。

其余的可以略读:两个 setup 文件各一行,加上 package.json、registry.json、AGENTS.md 的接线,以及基线 JSON。

Behavior Changes and Affected Users

产品代码没有改动。下表的变化只影响跑测试和写测试的人。

Behavior Before After Who relies on the old behavior Escape hatch
agent-core-v2、kap-server 测试进程看到的环境变量 只清掉 KIMI_CODE_*,再设一两个开关 按 testkit 的 testEnv():清掉所有 KIMI_*、各家 provider 的 key 和代理变量,关掉遥测、搜索 worker、minidb 读模型和模型目录刷新 本地跑测试时依赖自己 shell 里这些变量的人。测试本来就不该依赖它们,两个包全量跑下来没有用例依赖 单个测试需要某个变量时用 vi.stubEnv
测试里新增固定等待 不拦 pnpm lint 失败,并给出改用信号的写法 写新测试的人 只是把已有的等待在文件间挪动时,用 --update --allow-increase 更新基线,并在 PR 里说明
Responses 请求打到 testkit 假模型 404,或者被引擎 harness 明确拒绝 按剧本回答 无 —

没有 changeset:只改了测试、私有包 testkit、仓库检查脚本和说明文件。

验证

只在 macOS 上验证过,Linux 交给 CI,Windows 没有验证。

  • packages/testkit 178 条加 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

  • 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.

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.
@changeset-bot

changeset-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: cb873be

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 25, 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-25T14:43:16.043779Z cb873be Manual request
🔒 Security Review ✅ Completed 2026-11-25T14:11:13.256881Z cbd8078 PR opened
ℹ️ 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 25, 2026 •

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

commit: cb873be

@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: 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.
@RealKai42

Copy link
Copy Markdown
Collaborator Author

@codex

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: cb873becaf

ℹ️ 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".

@RealKai42
RealKai42 merged commit df97f8e into main Nov 25, 2026
26 checks passed
@RealKai42
RealKai42 deleted the test/consolidate-test-infra branch November 25, 2026 14:52
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 25, 2026
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.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 26, 2026
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.
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