Skip to content
cccskills
FreePublished on GitHub

Vitest Mock Isolation Review

Detects Vitest test-isolation hazards: unrestored vi.spyOn/vi.mock without afterEach cleanup or restoreMocks config, un-awaited resolves/rejects assertions, and shared mutable module state across tests.

The English summary is being prepared. Showing the original description.

Run score Not tested

See how to install

Files included (4)

  • SKILL.md4.0 KB
  • fixtures/01-unrestored-spy-happy.md1.3 KB
  • fixtures/02-config-restoremocks-guard.md1.3 KB
  • golden/01-unrestored-spy-happy.md1.0 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Pattern declaration

Primary pattern: Reviewer Secondary patterns: Inversion Why: Vitest 固有の mock lifecycle と async expect 契約をチェックリスト型で検査し、設定不明時はゲートで止める。

Goal / 目的

  • vi.spyOn / vi.mock の未復元によりテスト間でモック状態が漏れ、実行順序依存の flaky を生むのを防ぐ。
  • expect(...).resolves / .rejects の await/return 漏れによる「常に pass する空 assertion」を検出する。
  • モジュールスコープの可変状態がテスト間でリークするのを検出する。

Non-goals / 扱わないこと

  • テストの存在有無・カバレッジ・命名は downstream test スキルの領域であり、本スキルでは扱わない。
  • どのアサーションライブラリを使うべきかの選定。
  • テスト対象の実装ロジックの正しさ(本スキルは mock lifecycle と async expect 契約に限定)。

Pre-execution Gate / 実行前ゲート

このスキルは以下の条件がすべて満たされない限りNO_REVIEWを返す。

  • 差分に vi.mock / vi.spyOn / expect(...) の追加・変更が含まれている
  • diff コンテキストが利用可能である

ゲート不成立時の出力: NO_REVIEW: vitest-mock-isolation — mock / spy / expect の変更なし

False-positive guards / 抑制条件

  • vitest config(vitest.config.ts / vite.config.ts)で test.restoreMocks: true / clearMocks: true / mockReset: true が設定されている場合、afterEach の明示呼び出しが無くても指摘しない。diff だけで設定が見えない場合は断定せず質問に留める。
  • vi.fn() をローカル変数で都度生成し再利用していないケースはリーク源でないため指摘しない。
  • setupFiles で指定された setup ファイルが意図的にグローバルモックを共有する場合は、別スコープとして扱い指摘しない。

抑制時の出力: 該当する指摘を出力しない(黙る)。

Rule / ルール

  • vi.spyOn / vi.mock を使う場合、afterEach(() => vi.restoreAllMocks())(spy 復元)または vi.clearAllMocks() の呼び出し、もしくは config の restoreMocks: true 等のいずれかを満たすことを確認する。いずれも無ければモック状態がテスト間で漏れる。
  • expect(promise).resolves / .rejects は await または return する。async テスト内で await されない expect は検出する。
  • モジュールスコープの可変変数を複数テストが書き換える場合、beforeEach 等でのリセットを確認する。

Evidence / 根拠の取り方

  • 指摘は <file>:<line> で差分に紐づけ、Vitest 公式の該当規約(mock restore / async assertion)を 1 行で添える。
  • config が diff 外にあり確認できない場合は断定せず「可能性」として質問に留める。

Output / 出力(短文版の推奨)

コメントは日本語で返す。

  • Finding: どの分離契約に反しているか(1文)
  • Impact: テスト間状態リーク / 実行順序依存 flaky / 常に pass する空 assertion 等
  • Fix: afterEach(vi.restoreAllMocks) / restoreMocks: true / await expect(...).rejects の最小修正案

Sources / 出典

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

<What this skill does>

The English summary is being prepared. Showing the original description.

s977043/river-review7Updated Oct 24, 2026

画像・ボタン・フォーム要素に適切なアクセシブルネームがあるか確認する。

The English summary is being prepared. Showing the original description.

s977043/river-review7Updated Oct 24, 2026

Ensure ADRs capture context, decision, alternatives, tradeoffs, and follow-ups in a way that prevents future drift.

The English summary is being prepared. Showing the original description.

s977043/river-review7Updated Oct 24, 2026

敵対的分析手法を統合したレビューの entry skill。認知バイアス対策の3手法 (Pre-mortem / War Game / Logic Torturing)と、宣言・主張と実態の乖離を突く claim-vs-actual 検出3パターン(Self-Contradiction / Refactor-Claim Audit / Cross-File Leakage)へルーティングし、通常のレビューでは見えない設計の盲点・ 防御の穴・論理の弱点・宣言と実装のズレを可視化する。

The English summary is being prepared. Showing the original description.

s977043/river-review7Updated Oct 24, 2026

Review changes to the Agent Skills import/export bridge for path safety, round-trip fidelity, and validation correctness.

The English summary is being prepared. Showing the original description.

s977043/river-review7Updated Oct 24, 2026

Checks whether AI-assisted work defines review criteria, accessible context, explicit review loop, human judgment boundary, and feedback capture before delegating to an agent.

The English summary is being prepared. Showing the original description.

s977043/river-review7Updated Oct 24, 2026

See all skills by s977043

Report a problem with this skill