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

Đang mở Phù hợp với người mới
#210 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
69/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
node.js, typescript
Lĩnh vực
devtools, testing

Hướng nghiên cứu

Bắt đầu bằng cách lần theo mock.clock(on).set(ms) trong plugin Vitest và so sánh hành vi của nó với phần kiểm tra đồng hồ của engine được mô tả trong issue. Trường hợp tái hiện sử dụng vitest.config.ts và một bài kiểm thử đưa đồng hồ tiến đến 1000 ms, rồi đặt đồng hồ về 500 ms. Công việc hoàn tất khi trường hợp đó cũng gây ra lỗi đồng hồ chạy ngược của engine trong plugin Vitest.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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).
Ngôn ngữ chính
TypeScript
Star
0
Fork
0
Merge trung bình
29 phút
Pull request đã merge (30 ngày)
138

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của kwitsch/claude-code-plugin-tooling

Tất cả issue của kwitsch/claude-code-plugin-tooling

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.