Skip to content

test: let testkit scripts set the reply's response id - #5392

Merged
RealKai42 merged 1 commit into
mainfrom
test/testkit-response-id
Nov 25, 2026
Merged

RealKai42 merged 1 commit into
mainfrom
test/testkit-response-id

Conversation

@RealKai42

Copy link
Copy Markdown
Collaborator

Requirement or Bug

testkit 的假模型给每个回复编的 ID 固定是 testkit-<请求序号>,剧本没法指定。引擎里还有一批测试在用 harness 自带的旧假模型(mockNextResponse),其中有的断言写死了回复 ID(mock-1、response-1 这类)。下一步要把这些测试的底层换成 testkit,实测换完后有 9 条用例只差在这个 ID 上。这个 PR 让剧本可以指定回复 ID,后面换底座时这些测试就不用改。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

新增剧本步骤 withResponseId(id, step),写法和 withUsage、finishWith 一样,包在一个回复步骤外面。

文件 改了什么
packages/testkit/src/model/types.ts ReplyStep 加可选的 responseId
packages/testkit/src/model/steps.ts、index.ts 新增并导出 withResponseId
packages/testkit/src/model/fake-model.ts 编码回复时,步骤带了 responseId 就用它,否则照旧用 testkit-<请求序号>
packages/testkit/README.md 步骤表加一行

三家协议的编码器本来就从同一个地方取这个 ID:OpenAI 写进 id,Anthropic 写进 message 的 id,Google 写进 responseId。所以编码器本身没有改动。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
没用 withResponseId 的回复 ID testkit-<请求序号> 不变 所有用 testkit 假模型的测试 —
用了 withResponseId 的回复 ID 不支持 用指定的值 无 —

测试覆盖:packages/testkit/test/protocols.test.ts 新增一条,用 OpenAI、Anthropic、Google 三家官方 SDK,流式和非流式各请求一次,检查拿到的 ID 是剧本指定的值,没指定的回复仍是 testkit-<请求序号>。这条在改动前的代码上会失败。

验证
  • pnpm lint:通过。
  • pnpm exec tsc -p packages/testkit/tsconfig.json --noEmit:通过。
  • pnpm exec vitest run packages/testkit tests/scenarios:208 条通过,3 条失败,都和这次改动无关:
    • tests/scenarios/cold-recovery.test.ts、concurrent-file-writes.test.ts:KAP 子进程 30 秒内没起来。在没改动的 main 上同样失败,是本机环境问题。
    • packages/testkit/test/fixtures.test.ts 的网络守卫一条:只在全量并行时失败过一次,单独连跑 3 次都通过。
  • 没有 changeset:testkit 是私有包,以往改它的源码都没写过。

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 fake model always reported testkit-<requestIndex> as the reply ID,
so a test could not pin the ID a provider returns. Engine tests that
move from the harness model to the testkit assert those IDs.

- Add withResponseId(id, step), wrapping a reply step like withUsage.
- Use the scripted ID when encoding the reply; unscripted replies keep
  testkit-<requestIndex>.
- Check the ID through the official OpenAI, Anthropic and Google SDKs,
  streamed and not.
@changeset-bot

changeset-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 200a4d0

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-25T07:13:34.525682Z 200a4d0 PR opened
🔒 Security Review ✅ Completed 2026-11-25T07:03:55.232243Z 200a4d0 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@200a4d0
npx https://pkg.pr.new/@moonshot-ai/kimi-code@200a4d0

commit: 200a4d0

@RealKai42
RealKai42 merged commit 7238d6d into main Nov 25, 2026
23 of 24 checks passed
@RealKai42
RealKai42 deleted the test/testkit-response-id branch November 25, 2026 07:45
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 25, 2026
Port upstream 7238d6d. withResponseId sets the response id a scripted
reply carries, and unscripted replies are numbered by request; the protocol
suite checks the id through the official OpenAI, Anthropic and Google SDKs.

Verified: scripted response ids 1 pass, testkit typecheck clean.
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