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

Abierto Apto para principiantes
#2,515 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
77/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
typescript
Área
testing

Línea de trabajo

Empieza con src/api/providers/__tests__/kimi-code.spec.ts, centrándote en las pruebas de reintento 401 alrededor de las líneas 181 y 204 y en la prueba «does not force-refresh on non-401 OAuth failures». Lee src/test-utils/reset.ts para ver qué restablece clearAllMocks() y luego ejecuta el comando de Vitest para mezclar el orden indicado en el issue con la semilla 100. El trabajo está terminado cuando la spec pasa en orden aleatorio y la prueba que no es 401 no puede consumir una respuesta encolada por una prueba anterior.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
TypeScript
Estrellas
2k
Forks
301
Merge medio
3 d 14 h
PR fusionados (30 d)
103

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Zoo-Code-Org/Zoo-Code

Todos los issues de Zoo-Code-Org/Zoo-Code

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.