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 摘要。