vitest plugin: `mock.clock(on)` and the other mocks throw `mock: pass the test's own on` for a wrapper around `on`, `claude plugin test` accepts it
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 48/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- node.js, typescript
Rechercherichtung
Start with the vitest plugin’s engine lookup in dist/testing.mjs, especially engineOf and the implementations of mock.clock, mock.store and mock.env; compare how claude plugin test associates mocks with a test. Reproduce the failure with the provided wrapper example and inspect the related test setup. Done means both runners behave consistently for wrapped on handlers, with tests covering the chosen behavior.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Problem
A test file that builds its fake environment in a helper often wraps the test's on (to let a single test put its own hook ahead of a stub of the helper, because the engine takes one stub per event: on("clock.now") registered twice). Under claude plugin test the mocks (mock.clock, mock.store, mock.env) accept such a wrapper function; under the vitest plugin they throw mock: pass the test's own on because the mocks look the test up by the identity of on.
The same test file therefore passes under one runner and fails under the other. The only way to hook ahead of a mock's stub in a way both runners accept is an inline plugin with a register that holds all its state (no closure over the test), which cannot count calls or run a turn from the test (jevfort: 6 tests).
Versions
@kwitsch/vitest-plugin-claude-code-mod0.18.0claude --version: 2.1.336 (Claude Code)- vitest 5.1.2
- node v26.14.0
Minimal reproduction
Scratch plugin directory s1/ (symlinked node_modules as in the other reproductions): package.json {"name":"scratch","version":"0.0.1","type":"module","userConfig":{"flag":{"type":"boolean","title":"Flag","description":"A boolean option","default":true}}}, plugin/.claude-plugin/plugin.json with the same name, version, description and userConfig, plugin/hooks/hooks.json {"modules":["./register.js"]}, plugin/hooks/register.js and src/register.js (same content):
export const register = (on) => {
on("session.start", async ($, e, next) => {
const value = await $.env.get("A");
const r = await next(e);
return { ...r, cwd: String(value) };
});
};
vitest.config.ts: claudeCodeMod({ mod: "./src/register.js", portable: "error" }) as in the other reproductions. claude-tests/x.test.ts:
import { expect, mock, test } from "claude-code/testing";
const START = { source: "startup", cwd: "/p", surface: "terminal", isInteractive: true };
test("T1 mock.clock takes a wrapper around the test's on", async ($, on) => {
const wrapped = ((event: string, ...rest: unknown[]) => (on as (...a: unknown[]) => unknown)(event, ...rest)) as typeof on;
const clock = mock.clock(wrapped);
on("session.start", async () => ({ cwd: "/p" }));
await $.session.start(START);
await clock.advance(1);
expect(typeof clock.now()).toBe("number");
});
Vitest, verbatim:
❯ claude-tests/x.test.ts (5 tests | 2 failed) 20ms
× T1 mock.clock takes a wrapper around the test's on 2ms
FAIL claude-tests/x.test.ts > T1 mock.clock takes a wrapper around the test's on
Error: mock: pass the test's own on
❯ engineOf .../@kwitsch/vitest-plugin-claude-code-mod/dist/testing.mjs:898:16
❯ Object.clock .../testing.mjs:904:18
❯ claude-tests/x.test.ts:7:22
(the file holds four more tests, see the issue on the other runner differences; only T1 matters here.) Engine, verbatim:
test/x.test.ts:
(pass) T1 mock.clock takes a wrapper around the test's on [29.04ms]
Expected
Both runners agree. Either the vitest mocks accept any on (register through it, keep the engine state per test, not per function identity), or the engine rejects a wrapper too and the README says to hand the mocks the test's own on. In the second case the kit should give a way to hook ahead of a mock's stub with closures (for example mock.clock(on, { wrap })), because an inline plugin cannot share state with the test.
Relations
- Part of #41; one of the reasons the jevfort PR (branch
feat/jevfort-vitest-plugin, kwitsch/claude-plugins-development#196) stays a draft: 6 tests (An answered Jev call leaves no budget timer pending,A clock that reads earlier than the last timeout ends the pause (a new session),A turn reads the project, env and lists once, the cwd once at step 0 and the transcript once per hook, and three tick tests incache.test.ts) pass underclaude plugin testand fail under vitest with this error. - Related to #33 (the kit is laxer than the engine; this case is the other way round).
- Vorherrschende Sprache
- TypeScript
- Sterne
- 0
- Forks
- 0
- Ø Merge
- 29 Min.
- Gemergte PRs (30 T.)
- 138
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus kwitsch/claude-code-plugin-tooling
-
enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
kwitsch/claude-code-plugin-tooling#219 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 69/100
kwitsch/claude-code-plugin-tooling#210 ·
Maintainer antworten meist innerhalb von 1 Tag
-
enhancement
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 54/100
kwitsch/claude-code-plugin-tooling#212 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 45/100
kwitsch/claude-code-plugin-tooling#208 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 52/100
kwitsch/claude-code-plugin-tooling#207 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in kwitsch/claude-code-plugin-tooling
Ähnliche Issues
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100
makecindy/cindy#15342 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
Maintainer antworten meist innerhalb von 1 Tag
-
no-repo-link tool-submission
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 74/100
BraveOPotato/NoSignups#2618 ·
-
enhancement good first issue
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
-
bug needs-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Priyanshu-byte-coder/devtrack#4067 ·
Maintainer antworten meist innerhalb von 1 Tag