vitest plugin: the sandbox check refuses a mod source file above 65536 code units, although the built bundle (comments stripped) is far below
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- typescript
調査の方向性
Start by reading the README’s “Sandbox check” section and trace how claudeCodeMod({ mod }) passes module source to checkMod; the issue does not name implementation or test files. Compare that behavior with what claude plugin test loads from plugin/hooks/*.js. Done means the reproduced oversized source passes under Vitest with sandbox rules still enabled, while the existing source fallback remains available when no build output exists.
索引モデルが issue の本文から書いたものです。
説明
Problem
claudeCodeMod({ mod }) runs checkMod on the unbundled source of every module of the mod (README, "Sandbox check"). checkMod refuses a source longer than 65536 UTF-16 code units before it parses it (source is longer than 65536 UTF-16 code units and is not parsed; split the mod into modules, see #83, #197). claude plugin test never sees that source: it loads the built plugin/hooks/register.js, which the tsdown preset bundles and minifies (TSDoc and comments removed) and which passes the build-time check.
A mod with long doc comments therefore builds, loads and passes every test under claude plugin test, and cannot run a single test under vitest: every test that loads the mod fails with the error above. strictSandbox: false would make it a warning, but that switches the whole sandbox check off for the module (the README: no rule-less switch exists), so it is no answer for a plugin that wants portable: "error" and the sandbox rules.
Real case: jevfort/src/hooks/register.ts is 73874 characters (all hooks and every $ use must live in this one file by an engine rule), its built plugin/hooks/register.js is 42477 bytes. Migrating jevfort's 361 mod tests to the plugin (#41) is blocked: all 361 fail under vitest, all 361 pass under claude plugin test.
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 s2/ (the node_modules/@kwitsch/vitest-plugin-claude-code-mod and node_modules/vitest entries are symlinks to the installed packages):
package.json
{"name":"scratch","version":"0.0.1","type":"module"}
plugin/.claude-plugin/plugin.json
{"name":"scratch","version":"0.0.1","description":"scratch"}
plugin/hooks/hooks.json
{"modules":["./register.js"]}
plugin/hooks/register.js (91 bytes, what the build emits)
export const register = (on) => {
on("session.start", async ($, e, next) => next(e));
};
src/register.js: the same module preceded by a doc comment of 81398 characters (1100 lines of * Line <i> of a long doc comment that the build removes from the bundle. inside /** ... */), 81489 characters in all.
vitest.config.ts
import claudeCodeMod from "@kwitsch/vitest-plugin-claude-code-mod";
import { defineConfig } from "vitest/config";
export default defineConfig({
plugins: [claudeCodeMod({ mod: "./src/register.js", portable: "error" })],
});
claude-tests/x.test.ts
import { expect, test } from "claude-code/testing";
test("the mod answers session.start", async ($, on) => {
on("session.start", async () => ({ cwd: "/p" }));
const r = (await $.session.start({ source: "startup", cwd: "/p", surface: "terminal", isInteractive: true })) as { cwd: string };
expect(r.cwd).toBe("/p");
});
Vitest run (node <vitest>/vitest.mjs run), verbatim:
RUN v5.1.2 /tmp/claude-1000/s/803043992785/scratchpad/s2
❯ claude-tests/x.test.ts (1 test | 1 failed) 17ms
× the mod answers session.start 16ms
FAIL claude-tests/x.test.ts > the mod answers session.start
Error: claudeCodeMod: the mod breaks the Claude Code sandbox:
/tmp/claude-1000/s/803043992785/scratchpad/s2/src/register.js: source is longer than 65536 UTF-16 code units and is not parsed; split the mod into modules
Plugin: claude-code-mod
File: /tmp/claude-1000/s/803043992785/scratchpad/s2/src/register.js?claude-code-mod=0
Test Files 1 failed (1)
Tests 1 failed (1)
Engine run (copy plugin/ to a temp dir, the test to <tmp>/test/, claude plugin test <tmp>), verbatim:
test/x.test.ts:
(pass) the mod answers session.start [27.87ms]
1 pass
0 fail
Ran 1 test across 1 file. [0.23s]
Expected
The same test gives the same result under both runners. Options, in the order of preference:
- The plugin checks what the engine loads: when the build output of the mod exists (
plugin/hooks/*.js), check that; otherwise check the source per module as now. - The size limit is its own rule, switchable like
imports/timers(strictSandbox: { size: false }), so one oversized-but-built source does not switch the other rules off. - The README states that the size rule applies to source, with the above switch.
Relations
- Part of #41 (migration of the legacy kit tests); blocks the jevfort migration, PR kwitsch/claude-plugins-development (branch
feat/jevfort-vitest-plugin, kwitsch/claude-plugins-development#196). - Related to #197 (mod split into chunks below the limit), #83 and #137 (why the limit exists).
- 主要言語
- TypeScript
- スター
- 0
- フォーク
- 0
- 平均マージ
- 29分
- マージ済み PR(30日)
- 138
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
kwitsch/claude-code-plugin-tooling のほかの issue
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
kwitsch/claude-code-plugin-tooling#219 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 69/100
kwitsch/claude-code-plugin-tooling#210 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 4/5 3〜5日 初心者へのやさしさ 54/100
kwitsch/claude-code-plugin-tooling#212 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
kwitsch/claude-code-plugin-tooling#209 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 52/100
kwitsch/claude-code-plugin-tooling#207 ·
メンテナーはふだん 1 日以内に返信
kwitsch/claude-code-plugin-tooling の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
makecindy/cindy#15342 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
no-repo-link tool-submission
難易度 1/5 1時間未満 初心者へのやさしさ 74/100
BraveOPotato/NoSignups#2618 ·
-
enhancement good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
-
bug needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Priyanshu-byte-coder/devtrack#4067 ·
メンテナーはふだん 1 日以内に返信