vitest plugin: mock.env reads its variables object live, the engine keeps a copy
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 52/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- node.js, typescript
Rechercherichtung
Start by locating the vitest plugin’s implementation of mock.env and compare how it supplies variables to $.env.get with the engine’s snapshot behavior described here. The issue provides no implementation file or test path, so trace those entry points from the plugin source and its tests. Done when both runners return the same values after the variables object is changed between calls, with a test covering the behavior.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Problem
mock.env(on, variables) answers $.env.get from the object it was given. Under the vitest plugin the object is read at call time, so a test that changes it between two calls sees the new value. Under claude plugin test the object is copied when mock.env is called and later changes are not seen. A test that switches a variable between calls passes under vitest and fails under the engine.
Versions
@kwitsch/vitest-plugin-claude-code-mod0.18.0- Claude Code 2.1.336 (
claude plugin test) - vitest 5.1.2, Node 26.14.0, Linux (WSL2)
Minimal reproduction
Plugin repro-len (package.json: { "name": "repro-len", "version": "0.0.1", "type": "module" }; plugin/hooks/hooks.json: { "modules": ["./register.js"] }; plugin/.claude-plugin/plugin.json: { "name": "repro-len", "version": "0.0.1", "description": "repro", "userConfig": { "limit": { "type": "number", "title": "Limit", "description": "A limit", "default": 5 } } }). src/register.js is copied to plugin/hooks/register.js:
export const register = (on, options) => {
on("session.start", async ($, e, next) => {
const v = await $.env.get("REPRO_VAR");
await $.ui.toast(`${v} ${typeof options?.limit}`);
return next(e);
});
};
vitest.config.ts: plugins: [claudeCodeMod({ mod: "./src/register.js", portable: "error" })]. The test file is claude-tests/len.test.ts; vitest runs it with vitest run, the engine with claude plugin test <copy of plugin/ with the test in test/>.
import { expect, mock, test } from "claude-code/testing";
const START = { source: "startup", cwd: "/proj", surface: "terminal", isInteractive: true };
test("3: mock.env variables object changed after the call to mock.env", async ($, on) => {
const vars: Record<string, string> = { REPRO_VAR: "first" };
const toasts: string[] = [];
mock.env(on, vars);
on("ui.toast", (_$, e) => (toasts.push(String(e.text)), { value: undefined }));
on("session.start", () => ({ cwd: "/proj" }));
await $.session.start(START);
vars.REPRO_VAR = "second";
await $.session.start(START);
expect(toasts.map((t) => t.split(" ")[0])).toEqual(["first", "second"]);
});
vitest: passes.
claude plugin test:
(fail) 3: mock.env variables object changed after the call to mock.env [35.16ms]
AssertionError: expect(received).toEqual()
Expected: ["first", "second"]
Received: ["first", "first"]
Expected
Both runners treat mock.env's variables the same way. The engine's copy semantics is the reference (the kit is documented as a snapshot answerer: "answers $.env.get from a set of variables"); the vitest plugin should copy the object when mock.env is called, or the README should name live reading and the engine side be aligned if the copy is the bug. Until then a test that needs a changing variable answers env.get itself from its own object.
Relations
- Part of #41 (migration of kwitsch/claude-plugins-development), same family as #33 (the kit accepts what the engine rejects). Found by the jev-api migration, kwitsch/claude-plugins-development#195: its tests had to be rewritten to the engine-valid form, which then passes under both runners.
- 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 48/100
kwitsch/claude-code-plugin-tooling#209 ·
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
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