vitest plugin: clock.set(ms) goes backwards, the engine's clock does not

Aperta Adatta ai principianti
#210 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

Inizia tracciando mock.clock(on).set(ms) nel plugin Vitest e confronta il suo comportamento con la convalida dell’orologio del motore descritta nell’issue. La riproduzione usa vitest.config.ts e un test che fa avanzare l’orologio fino a 1000 ms, poi lo imposta a 500 ms. Il lavoro è completato quando anche nel plugin Vitest questo caso genera l’errore del motore per l’orologio che torna indietro.

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

Descrizione

bug

Problem

mock.clock(on).set(ms) moves the kit's clock backwards under the vitest plugin. Under claude plugin test it throws, because the engine's clock does not run backwards. A test that sets the clock to an earlier time (to check a mod that must survive a wall clock stepping back) passes under vitest and fails under the engine.

Versions

  • @kwitsch/vitest-plugin-claude-code-mod 0.18.0
  • claude --version: 2.1.336 (Claude Code)
  • vitest 5.1.2
  • node v26.14.0

Minimal reproduction

Any plugin (the test uses no mod hook): package.json {"name":"scratch","version":"0.0.1","type":"module"}, plugin/.claude-plugin/plugin.json with the same name, plugin/hooks/hooks.json {"modules":["./register.js"]}, plugin/hooks/register.js export const register = (on) => { on("session.start", async ($, e, next) => next(e)); }; (also as src/register.js), vitest.config.ts with claudeCodeMod({ mod: "./src/register.js", portable: "error" }).

import { expect, mock, test } from "claude-code/testing";

test("T4 the clock can be set back", async ($, on) => {
  const clock = mock.clock(on);
  await clock.advance(1000);
  await clock.set(500);
  expect(clock.now()).toBe(500);
});

vitest: passes. claude plugin test:

(fail) T4 the clock can be set back [0.62ms]
  TypeError: set(ms): a time in milliseconds at or past now (1000); the clock does not run backwards

Expected

clock.set(ms) with ms before the clock's now throws the engine's error (set(ms): a time in milliseconds at or past now (<now>); the clock does not run backwards) under the vitest plugin too.

Relations

  • Part of #41, found while migrating jevfort (kwitsch/claude-plugins-development#196): its test "A clock that reads earlier than the last timeout ends the pause (a new session)" needs a clock reading earlier, which neither runner offers through set.
  • Same family as #205, #206, #207 and #33 (the kit accepts what the engine rejects). jevfort also hit the other three: a second stub for one event (on("session.start") registered twice, #205), an option of the wrong type (#206) and mock.env read live (#207).
Lingua principale
TypeScript
Stelle
0
Fork
0
Merge medio
29m
PR unite (30g)
138

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 kwitsch/claude-code-plugin-tooling

Tutte le issue di kwitsch/claude-code-plugin-tooling

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.