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

未关闭 适合新手
#210 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
69/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
devtools, testing

调研方向

首先追踪 Vitest 插件中的 mock.clock(on).set(ms),并将其行为与 issue 中描述的引擎时钟校验进行比较。复现使用 vitest.config.ts,以及一个先将时钟推进到 1000 ms、再将其设为 500 ms 的测试。当这个情况在 Vitest 插件中也抛出引擎的时钟倒退错误时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

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).
主要语言
TypeScript
星标
0
派生
0
平均合并
29 分钟
30 天内合并 PR
138

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

kwitsch/claude-code-plugin-tooling 的其他 Issue

查看 kwitsch/claude-code-plugin-tooling 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。