Skip to content

chore(test): カバレッジ計測の母数を整備する (#1038)#1047

Merged
otomatty merged 3 commits into
developfrom
cursor/coverage-denominator-setup-573f
Jun 11, 2026
Merged

chore(test): カバレッジ計測の母数を整備する (#1038)#1047
otomatty merged 3 commits into
developfrom
cursor/coverage-denominator-setup-573f

Conversation

@otomatty

@otomatty otomatty commented Jun 11, 2026

Copy link
Copy Markdown
Owner

概要

カバレッジ数値の母数から、実行不能・テスト対象外のファイルを除外し、全ワークスペースで --coverage が動作するよう整備しました。テストコードの追加はありません(設定のみの変更)。

Closes #1038

変更点

フロントエンド (vite.config.ts)

  • src/types/ の型のみファイル 9 件を exclude(ai.tsstorage.ts は関数・型ガードを含むため残す)
  • エントリポイント src/App.tsx を exclude

admin (admin/vitest.config.ts)

  • coverage 設定を追加
  • src/i18n/locales/**(i18n JSON)と main.tsx / App.tsx を exclude

ワークスペース coverage 設定の統一

  • vitest.coverage.shared.ts で provider / reporter / 共通 exclude を共通化
  • vitest.config.ts に coverage 設定を追加
  • server/mcpserver/hocuspocus@vitest/coverage-v8 を追加
  • scripts/run-workspace-coverage.mjs + bun run test:coverage でローカル一括計測

CI

  • test job: ルート配下ワークスペースの coverage を計測(重複回避のため server/* は各専用 job)
  • api-test / mcp-test / hocuspocus-test: --coverage 実行 + レポート artifact アップロード

packages/ui

  • shadcn vendored の components/*.tsx を母数から除外(自前実装の hooks / lib / sidebar / resizable のみ計測)

整備後の基準値(2026-06-11)

ワークスペース Lines Branch 80%
src/(フロント) 53.7% 45.8%
server/api 78.4% 69.2%
server/hocuspocus 95.9% 87.8%
server/mcp 52.4% 56.6%
admin 43.3% 36.3%
packages/shared 100% 100%
packages/ui 54.7% 44.1%
packages/claude-sidecar 94.4% 87.0%

※ 型定義・JSON・エントリポイント除外により、以前より正確な母数になっています。admin / packages/ui は明示的 include により未テストの自前コードも母数に含まれるため、旧基準値より低く見える場合があります。

テスト

  • bun run test:coverage(全ワークスペース、--with-servers 付き)がエラーなく完了
  • 既存テストの挙動に変更なし(設定のみ)

関連

Open in Web Open in Cursor 

Summary by CodeRabbit

  • New Features
    • CI now generates and publishes per-component code coverage reports (frontend and servers) for easier quality tracking.
    • Coverage collection expanded to additional packages and server components for more complete metrics.
  • Chores
    • Standardized coverage configuration across workspaces and added a workspace-level runner to aggregate and upload reports.

- 共通 coverage 設定モジュール (vitest.coverage.shared.ts) を追加
- フロント: src/types/ の型のみファイルと App.tsx を exclude
- admin: i18n JSON とエントリポイントを exclude
- 全ワークスペースの vitest.config に coverage 設定を追加
- server/mcp・server/hocuspocus に @vitest/coverage-v8 を追加
- bun run test:coverage で全ワークスペースの計測を実行可能に
- CI: 各 job で coverage を計測・アップロード
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a2b5031c-52c0-43cf-8cfe-edc190e53df3

📥 Commits

Reviewing files that changed from the base of the PR and between ab77357 and adc3798.

⛔ Files ignored due to path filters (1)
  • server/mcp/bun.lock is excluded by !**/*.lock
📒 Files selected for processing (1)
  • server/mcp/package.json

📝 Walkthrough

Walkthrough

Adds shared Vitest V8 coverage helpers, applies them to frontend/packages/servers, introduces a workspace coverage runner script, updates root test:coverage, and modifies CI to run coverage per workspace and upload per-workspace coverage artifacts.

Changes

Monorepo-Wide Coverage Configuration Consolidation

Layer / File(s) Summary
Shared Coverage Configuration Foundation
vitest.coverage.shared.ts
Defines shared Vitest V8 coverage constants (coverageReporters, coverageTestExcludes, frontendTypeOnlyExcludes) and exports createCoverageConfig used by workspace configs.
Cross-Workspace Coverage Orchestration
scripts/run-workspace-coverage.mjs, package.json
New orchestrator script runs Vitest coverage across default front-end workspaces and optionally servers; root test:coverage updated to invoke it.
Frontend Coverage Configuration
admin/vitest.config.ts, vite.config.ts
Admin and root Vite configs import createCoverageConfig and set coverage includes/excludes to focus on source files while excluding entrypoints, i18n JSON, and type-only files.
Package Coverage Configuration
packages/shared/vitest.config.ts, packages/ui/vitest.config.ts, packages/claude-sidecar/vitest.config.ts
Packages import createCoverageConfig and add coverage settings with workspace-specific include/exclude globs.
Server Workspace Coverage Setup
server/api/vitest.config.ts, server/api/package.json, server/mcp/vitest.config.ts, server/mcp/package.json, server/hocuspocus/vitest.config.ts, server/hocuspocus/package.json
Server workspaces gain test:coverage scripts, @vitest/coverage-v8 where added, and per-workspace test.coverage config so --coverage runs succeed.
CI Workflow Coverage Execution and Artifacts
.github/workflows/ci.yml
CI root unit job now invokes the orchestrator; api/mcp/hocuspocus CI jobs run coverage and upload each workspace's coverage directory as separate artifacts.

Sequence Diagram(s)

sequenceDiagram
    participant CI as CI Workflow
    participant RootScript as run-workspace-coverage.mjs
    participant Workspace as Workspace<br/>(admin/shared/ui/claude)
    participant ServerWS as Server Workspace<br/>(api/mcp/hocuspocus)
    
    CI->>RootScript: npm run test:coverage
    RootScript->>RootScript: parse --with-servers flag
    RootScript->>Workspace: for each frontend workspace
    Workspace->>Workspace: bunx vitest run --coverage
    Workspace->>Workspace: load vitest.config + createCoverageConfig
    Workspace->>Workspace: generate coverage report
    alt with --with-servers
        RootScript->>ServerWS: for each server workspace
        ServerWS->>ServerWS: bunx vitest run --coverage
        ServerWS->>ServerWS: load vitest.config + createCoverageConfig
        ServerWS->>ServerWS: generate coverage report
    end
    RootScript-->>CI: exit 0 if all pass
    CI->>CI: upload coverage artifacts
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

  • otomatty/zedi#1046: Related refactor of monorepo coverage runner and shared coverage config.
  • otomatty/zedi#760: Overlaps Vitest and CI wiring points and may contain related changes.

Suggested labels

enhancement

Poem

🐰 I hopped through workspaces, tail afloat,
Collected coverage like a little note.
Helpers shared, scripts in stride,
Artifacts saved, reports aligned.
The rabbit cheers — metrics tidy, all in one tote.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly references the main objective: organizing coverage measurement base units, which matches the core purpose of standardizing coverage configuration across workspaces.
Linked Issues check ✅ Passed All linked issue requirements are met: type-only files excluded from frontend, admin i18n JSON excluded, coverage settings added to all vitest configs, server coverage dependencies added, CI workflow updated, and bun run test:coverage is implemented.
Out of Scope Changes check ✅ Passed All changes directly support coverage configuration objectives; no unrelated modifications detected in the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/coverage-denominator-setup-573f

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request standardizes Vitest coverage configurations across the monorepo workspaces by introducing a shared helper createCoverageConfig in vitest.coverage.shared.ts and updating workspace-specific configurations. It also adds a workspace coverage runner script (scripts/run-workspace-coverage.mjs) and updates package scripts and lockfiles accordingly. Feedback on the changes highlights potential execution failures on Windows when using spawnSync directly with bun or bunx without a shell, recommending the use of shell: true on Windows and adding proper error handling for spawn failures.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +65 to +75
function run(label, command, cwd) {
console.log(`\n=== Coverage: ${label} ===\n`);
const result = spawnSync("bunx", command, {
cwd,
stdio: "inherit",
env: process.env,
});
if (result.status !== 0) {
process.exit(result.status ?? 1);
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Windows環境において、bunbunx などのコマンドを spawnSync で直接実行すると、シェル経由でないために ENOENT エラーが発生して実行に失敗することがあります。また、コマンドの起動自体に失敗した場合(result.error が存在する場合)、エラー内容がコンソールに出力されず、終了コード 1 でサイレントに終了してしまいます。\n\nこれを防ぐために、Windows環境では shell: true を有効にし、result.error が存在する場合はエラー内容を出力するように改善することを推奨します。

function run(label, command, cwd) {
  console.log("\\n=== Coverage: \${label} ===\\n");
  const result = spawnSync("bunx", command, {
    cwd,
    stdio: "inherit",
    env: process.env,
    shell: process.platform === "win32",
  });
  if (result.error) {
    console.error(result.error);
    process.exit(1);
  }
  if (result.status !== 0) {
    process.exit(result.status ?? 1);
  }
}

Comment on lines +79 to +89
if (workspace.preInstall) {
console.log(`\n--- Installing dependencies for ${workspace.name} ---\n`);
const install = spawnSync("bun", ["install", "--frozen-lockfile"], {
cwd,
stdio: "inherit",
env: process.env,
});
if (install.status !== 0) {
process.exit(install.status ?? 1);
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

依存関係のインストール処理(bun install)においても、Windows環境での実行失敗を防ぐために shell: true を有効にし、起動失敗時のエラーハンドリング(install.error の出力)を追加することを推奨します。

  if (workspace.preInstall) {
    console.log("\\n--- Installing dependencies for \${workspace.name} ---\\n");
    const install = spawnSync("bun", ["install", "--frozen-lockfile"], {
      cwd,
      stdio: "inherit",
      env: process.env,
      shell: process.platform === "win32",
    });
    if (install.error) {
      console.error(install.error);
      process.exit(1);
    }
    if (install.status !== 0) {
      process.exit(install.status ?? 1);
    }
  }

@otomatty otomatty marked this pull request as ready for review June 11, 2026 10:00
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d40d41ada8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread server/mcp/package.json Outdated
},
"devDependencies": {
"@types/node": "^25.3.3",
"@vitest/coverage-v8": "4.0.18",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Align coverage-v8 with Vitest in MCP tests

In the fresh server/mcp install used by the changed mcp-test workflow, the lockfile resolves vitest to 4.1.4 while this new provider is pinned to 4.0.18; @vitest/coverage-v8@4.0.18 declares an exact peer on vitest@4.0.18, so bun run test:coverage is now exercising a mismatched Vitest/provider pair. Pin both packages to the same patch (or update the lockfile so they resolve together) before enabling coverage in CI.

Useful? React with 👍 / 👎.

"devDependencies": {
"@types/node": "^25.3.2",
"@types/pg": "^8.16.0",
"@vitest/coverage-v8": "4.0.18",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Align coverage-v8 with Vitest in Hocuspocus tests

The changed Hocuspocus CI path now runs bun run test:coverage, but this newly added provider is pinned to 4.0.18 while server/hocuspocus/bun.lock resolves vitest to 4.1.2. Because the coverage provider has an exact Vitest peer for its own patch version, fresh installs will run coverage with an unsupported provider/runtime combination; keep the two Vitest packages on the same version before making coverage mandatory.

Useful? React with 👍 / 👎.

- server/mcp・server/hocuspocus の vitest を 4.0.18 に固定(coverage-v8 と一致)
- run-workspace-coverage.mjs: Windows 向け shell 有効化と spawn 失敗時のエラー出力
Align server/mcp vitest and @vitest/coverage-v8 to 4.1.4 after develop bump.
@otomatty otomatty merged commit 12658dc into develop Jun 11, 2026
21 checks passed
@otomatty otomatty deleted the cursor/coverage-denominator-setup-573f branch June 11, 2026 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore(test): カバレッジ計測の母数を整備する(型定義の exclude・全ワークスペースの coverage 設定)

2 participants