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

Aperta Adatta ai principianti
#2,515 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
77/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
testing

Direzione di ricerca

Inizia da src/api/providers/__tests__/kimi-code.spec.ts, concentrandoti sui test di retry 401 intorno alle righe 181 e 204 e sul test «does not force-refresh on non-401 OAuth failures». Leggi src/test-utils/reset.ts per vedere cosa reimposta clearAllMocks(), quindi esegui il comando Vitest per mescolare l’ordine indicato nell’issue con seed 100. Il lavoro è completato quando la spec passa in ordine casuale e il test non-401 non può consumare una risposta accodata da un test precedente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
2k
Fork
301
Merge medio
3g 14h
PR unite (30g)
103

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Zoo-Code-Org/Zoo-Code

Tutte le issue di Zoo-Code-Org/Zoo-Code

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.