vitest plugin: shape validator for event inputs and hook results (M5)

未關閉
#33 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
35/100
Issue 類型
功能
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
typescript
領域
devtools, testing

研究方向

Start by reading packages/core/src/hook-placeholders.ts, the existing hook-type generator, and the Vitest plugin entry point where claudeCodeMod and hook calls are handled. Check the current dependencies for TypeScript compiler API or type-to-schema tools, then decide where the pinned type base belongs. Done means generated schemas validate event inputs and hook results, both required regression tests fail as specified, self tests pass, and the README, deviation list, and changeset are updated.

由索引模型根據 Issue 內容生成。

描述

enhancement

Problem

The kit accepts any event input and any hook result. The real engine validates both. A test can therefore fire session.start without cwd, or session.compact with empty messages, and pass under Vitest while claude plugin test and Claude Code reject the call. The kit's own conformance suite cannot catch this, because it only compares outcomes for inputs that are valid in the first place.

Proposal

Validate event inputs and hook returns at run time against the types of a pinned Claude Code version.

claudeCodeMod({
  mod: "./src/hooks/register.ts",
  claudeCodeVersion: "2.1.332", // shapes of this version
  types: "./claude-code.d.ts", // or a file made by /plugin-types
});
Pipeline
Step What
Type base A claude-code.d.ts of the pinned version, produced by Claude Code's /plugin-types; never maintained by hand
Generator A script turns the .d.ts into one schema per event at build time
Validator in the kit Checks the test's input to on(...)/$.<ns>.<event>() and the return value of every hook
Options claudeCodeVersion (version of the bundled base), types (path that overrides the bundled base)
Required regression tests
  • session.start without cwd fails in Vitest.
  • session.compact with empty messages fails in Vitest.

Design points

  • Where the type base lives. Open point: bundled in the package or in @kwitsch/claude-code-plugin-core. The core package already carries the hook-type allow-list (packages/core/src/hook-placeholders.ts) and a hook-type generator, so shared data may belong there; a bundled copy keeps the vitest plugin free of a second consumer. Decide first.
  • Generator input. A .d.ts is TypeScript; reading it needs the TypeScript compiler API or a type-to-schema tool. Check what is already a dependency before adding one.
  • Error wording. The conformance suite compares messages with the real engine. Capture the engine's wording for a rejected input (claude plugin test with a bad input) and match it, or document the difference in the deviation list.
  • Both directions. Input of the test to on(...) and return of the hook. The hook-return check must not break { deny }, { value } or the next chain.
  • Version coupling. The bundled base names the Claude Code version it came from. README and changelog state it; a new base is at least a minor. The compatibility table in the README gains the base version.
  • Drift. Depends on the nightly drift job in #34, which compares against claude@latest and opens an issue with the diff of claude-code.d.ts.

Scope

  • Generator script and a committed, generated type base (with the version it came from).
  • Validator in src/testing/, options in claudeCodeMod, README section, deviation list update.
  • Self tests for the generator and the validator; the two regression tests above.
  • Changeset: minor (0.2.0 together with the sandbox check).
  • Independent of the sandbox check (#32); both can run in parallel.

Acceptance

  • The two regression tests fail in Vitest as described.
  • The generated schemas come from a committed claude-code.d.ts, not from hand-written types.

Relations

  • Originating PR: #31
主要語言
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 摘要。