test(api): kimi-code spec inherits queued one-shot fetch responses, so shuffled order changes results

未关闭 适合新手
#2,515 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
77/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript
领域
testing

调研方向

从 src/api/providers/__tests__/kimi-code.spec.ts 开始,重点关注第 181 和 204 行附近的 401 重试测试,以及测试“does not force-refresh on non-401 OAuth failures”。阅读 src/test-utils/reset.ts,了解 clearAllMocks() 会重置什么,然后使用 seed 100 运行 issue 中的 Vitest 随机排序命令。完成标准是:spec 在随机排序下通过,并且非 401 测试无法消耗由较早测试排入队列的响应。

由索引模型根据 Issue 内容生成。

描述

Symptom

src/api/providers/__tests__/kimi-code.spec.ts is order dependent. Under --sequence.shuffle at seed 100 the test "does not force-refresh on non-401 OAuth failures" resolves instead of rejecting. It passes in declaration order, which is what CI runs.

Measured

  • Fails at abort-signal head 2f0d1d878518 and also at the previous head 780688ab2f67 with this round's edits reverted, and it fails when that spec is run alone under the same seed.
  • Passes in declaration order at both heads.
  • Repro: cd src && npx vitest run api/providers/__tests__/kimi-code.spec.ts --sequence.shuffle --seed 100

Cause

The suite's beforeEach calls clearAllMocks() from src/test-utils/reset.ts, which is vi.clearAllMocks(). That clears mock.calls, instances and results but keeps implementations, so a response queued with mockResolvedValueOnce by an earlier test - here the 401-retry tests around lines 181 and 204, which queue globalThis.fetch responses - is still in the queue when the next test starts. Under shuffle the 500-path test can therefore consume a queued 401-body response from the previous test and take the refresh branch it is supposed to prove does not happen.

export function clearAllMocks(): void {
	vi.clearAllMocks()
}

Expected

The suite must not depend on execution order. Either reset the once-queues between tests - mockReset() on the mocks that receive queued-once responses, or a helper in test-utils/reset.ts that also drops queued implementations - or give each test its own fetch stub in the test body instead of inheriting a queue. A test that asserts a refresh did not happen should not be able to inherit the response a previous test queued.

Why it matters

The abort-signal series adds tests that queue one-shot fetch responses around OAuth refresh. Every added test increases the chance that a shuffle exposes this, and CI moving to randomised order would turn it into a permanent flake.

主要语言
TypeScript
星标
2k
派生
301
平均合并
3 天 14 小时
30 天内合并 PR
103

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Zoo-Code-Org/Zoo-Code 的其他 Issue

查看 Zoo-Code-Org/Zoo-Code 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。