Repository navigation
test: let testkit scripts set the reply's response id - #5392
Conversation
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.
|
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: |
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.
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.tsReplyStep加可选的responseIdpackages/testkit/src/model/steps.ts、index.tswithResponseIdpackages/testkit/src/model/fake-model.tsresponseId就用它,否则照旧用testkit-<请求序号>packages/testkit/README.md三家协议的编码器本来就从同一个地方取这个 ID:OpenAI 写进
id,Anthropic 写进 message 的id,Google 写进responseId。所以编码器本身没有改动。Behavior Changes and Affected Users
withResponseId的回复 IDtestkit-<请求序号>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 次都通过。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.