Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ __pycache__/
*.pyc

# Rust build artifacts
# Workspace shared target (ADR-026 で Cargo workspace 化)
/target/
# 旧レイアウト互換: 各 package ディレクトリ配下の target (残っていれば無視)
src/*/target/
# workspace 化後は root Cargo.lock のみが有効; 誤って再生成されても追跡しない
src/*/Cargo.lock

# Runtime generated files
.claude/.session-id
Expand Down
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- [ADR-023: CodeRabbit false positive 対応スキル](docs/adr/adr-023-coderabbit-reject-thread-skill.md) *(試験運用)*
- [ADR-024: 共通 jj ヘルパーライブラリ](docs/adr/adr-024-shared-jj-helpers-library.md) *(試験運用)*
- [ADR-025: CwdRestore Drop guard パターン](docs/adr/adr-025-cwd-restore-drop-guard.md) *(試験運用)*
- [ADR-026: Cargo workspace による Rust パッケージ統合](docs/adr/adr-026-cargo-workspace.md)

## Automated actor boundary (ADR-022)

Expand Down
112 changes: 97 additions & 15 deletions src/hooks-post-tool-linter/Cargo.lock → Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Workspace root for all Rust packages (ADR-026)
#
# 目的:
# 1. `cargo test` / `cargo build` を workspace 全体で一括実行可能にする
# (各 package で `--manifest-path` 指定が不要)
# 2. shared `target/` で compile cache を共有し、ビルド時間を短縮
# 3. push pipeline (push-runner-config.toml の rust-test group) で
# unit tests と ignored tests を 2 コマンドで網羅できる:
# cargo test
# cargo test -- --ignored --test-threads=1
# (ignored tests は cwd 依存のため直列実行が必須)
#
# 方針:
# - 各 member の Cargo.toml の edition / version はそのまま保持
# - [profile.release] は Cargo がメンバーレベルの設定を無視するため root に集約必須
# (YAGNI ではなく Cargo の仕様要件、ADR-026 §設計原則 2 参照)
# - 依存の重複解消 (`[workspace.dependencies]`) は実利が見えてから別 PR で対応

[workspace]
resolver = "2"
members = [
"src/check-ci-coderabbit",
"src/cli-merge-pipeline",
"src/cli-pr-monitor",
"src/cli-push-pipeline",
"src/cli-push-runner",
"src/hooks-post-tool-linter",
"src/hooks-pre-tool-validate",
"src/hooks-session-start",
"src/hooks-stop-quality",
"src/lib-report-formatter",
]

# workspace 化に伴い [profile.*] は必ず root で定義する必要がある
# (member の profile 設定は Cargo により ignore される)。
# 各 member が持っていた同等設定を root に集約。
[profile.release]
opt-level = 3
lto = true
strip = true
107 changes: 107 additions & 0 deletions docs/adr/adr-026-cargo-workspace.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# ADR-026: Cargo workspace による Rust パッケージ統合

## ステータス

承認済み (2026-04-17)

## コンテキスト

### 問題

本プロジェクトには 10 の Rust パッケージ (`src/check-ci-coderabbit/`, `src/cli-*/`, `src/hooks-*/`, `src/lib-report-formatter/`) が存在するが、各パッケージが独立した `Cargo.toml` を持ち、workspace 化されていなかった。この構成では以下の不便が発生していた:

1. **`cargo test` が repo ルートで動かない**: 各パッケージで `cargo test --manifest-path src/<package>/Cargo.toml` のように個別指定が必要。PR #44 で push pipeline に rust-test group を追加したとき、この個別指定が必要になった
2. **target/ ディレクトリが package ごとに分散**: 10 個の `src/<pkg>/target/` が独立して生成され、compile cache が共有されない。依存する lib-report-formatter のコンパイル結果も再利用されない
3. **profile.release が各パッケージで重複定義**: 9 個のパッケージに同じ `[profile.release]` ブロック (opt-level=3, lto=true, strip=true) が書かれていた

### Rust workspace 化の効果

Cargo workspace を導入すると:

- `cargo test` を repo ルート 1 行で全パッケージ実行
- `cargo test -- --ignored --test-threads=1` で統合テストも同様に 1 行
- `target/` が workspace 共通化され、compile cache 再利用でビルド時間短縮 (特に lib-report-formatter に依存する複数パッケージ)
- `[profile.release]` を workspace root に集約でき、重複排除
- 将来の `[workspace.dependencies]` (共通依存バージョン管理) への拡張余地

## 決定

### workspace 構成 (最小構成)

`Cargo.toml` (repo ルート、新規) に以下を定義:

```toml
[workspace]
resolver = "2"
members = [
"src/check-ci-coderabbit",
"src/cli-merge-pipeline",
"src/cli-pr-monitor",
"src/cli-push-pipeline",
"src/cli-push-runner",
"src/hooks-post-tool-linter",
"src/hooks-pre-tool-validate",
"src/hooks-session-start",
"src/hooks-stop-quality",
"src/lib-report-formatter",
]

[profile.release]
opt-level = 3
lto = true
strip = true
```

### 設計原則

1. **minimal workspace を先に**: `[workspace.dependencies]` (共通依存バージョン管理) や `[workspace.package]` (共通 metadata) の導入は**本 ADR のスコープ外**。実利が見えてから別 PR で対応 (YAGNI)
2. **`[profile.release]` は root に集約**: workspace では member の profile 設定が ignore されるため、root で一元管理する必要がある (Cargo の仕様)
3. **target/ は workspace 共通化**: `.gitignore` で `/target/` (root) と `src/*/target/` (legacy 互換) の両方を ignore
4. **package.json の build スクリプト変更**: `cargo build --release -p <name>` に統一。target path は `target/release/<name>.exe` (workspace 直下)
5. **push pipeline の rust-test group を workspace ベースに**: `cargo test --manifest-path ...` の個別指定を廃止し、`cargo test` 1 行に

### 依存の変更

既存 package 間の依存 (例: cli-pr-monitor → lib-report-formatter) は引き続き `path = "../lib-report-formatter"` で記述する。workspace 化により path dependency が暗黙的に解決されるため、実質的な変更はない。

## 影響

### 採用される構成要素

- `Cargo.toml` (repo ルート): `[workspace]` + members + `[profile.release]`
- `.gitignore`: `/target/` を追加
- `package.json`: 8 個の `build:<name>` スクリプトを `cargo build --release -p <name>` 形式に統一
- `push-runner-config.toml`: rust-test group の command を `cargo test` / `cargo test -- --ignored --test-threads=1` に簡素化
- `templates/push-runner-config.toml`: rust-test group のコメントアウト済みテンプレートを追加 (Rust を使う派生プロジェクトで有効化可能に)

### 避けるべきアンチパターン

- **Member の `[profile.release]` 併存**: workspace では ignore されるため、警告の原因になる。root に集約する
- **各 package で個別 `--manifest-path` 指定**: workspace 化後は不要。誤って個別指定すると target/ の共有が無効化される可能性
- **`cargo build --release` を member dir で実行する旧スタイル**: target path が `src/<pkg>/target/` ではなく `target/` (workspace root) に変わっているため、build 後の `cp` でパスを更新する必要がある

### 削除された構成要素

- 各 member Cargo.toml の `[profile.release]` ブロック (9 箇所): コメントで「workspace root に集約」と記録

### package.json の変更例

Before:
```json
"build:hooks-pre-tool-validate": "cd src/hooks-pre-tool-validate && cargo build --release && cp target/release/hooks-pre-tool-validate.exe ../../.claude/hooks-pre-tool-validate.exe"
```

After:
```json
"build:hooks-pre-tool-validate": "cargo build --release -p hooks-pre-tool-validate && cp target/release/hooks-pre-tool-validate.exe .claude/hooks-pre-tool-validate.exe"
```

`cd` が不要になり、target path が workspace root 基準に統一される。

## 次ステップ (スコープ外)

- **`[workspace.dependencies]` への集約**: serde / toml / regex などの重複依存を集約できる。実利が見えたら別 PR で実施
- **`[workspace.package]` への version / edition 集約**: 現状すべて `version = "0.1.0"` / `edition = "2021"` で統一されているので、集約しても見た目のみの変化。YAGNI で保留
- **cli-push-pipeline の deprecation**: ADR-015 で cli-push-runner (takt ベース) に移行済み。cli-push-pipeline は dead code だが本 ADR の scope 外。削除は別 PR
- **ADR-024 (仮) の正式採用**: 2 つ目の jj ヘルパー使用例が出たら `src/lib-jj-helpers/` を workspace member として新設 (workspace 化により追加が容易に)
- **ADR-025 (仮) の正式採用**: 2 つ目の cwd 依存テストが出たら `src/lib-test-helpers/` を workspace member として新設 (同上)
32 changes: 16 additions & 16 deletions docs/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,26 +136,26 @@
- 上記 #1 の `feat/session-start-hook` の活用方針が決まらないとセッション引継ぎ設計ができない
- takt-test-vc での試験運用を先に行い、本プロジェクトに反映

### 4. Cargo workspace 化 + rust-test template 反映 (ADR-022 導入に伴う infra 整備)
### 4. Cargo workspace 化 + rust-test template 反映 (PR-β、実装済み)

- **やろうとしたこと**: PR #44 のセッション知見を元に:
1. Rust test を push pipeline で一発実行できるよう Cargo workspace 化 (現状は各 package 独立で `--manifest-path` 指定が必要)
2. `templates/push-runner-config.toml` に `rust-test` group を反映し、派生プロジェクトへ `pnpm deploy:hooks` で配布できるようにする
- **現在地**: PR-α (ADR-021~025) マージ後に着手予定
- [ ] 全 Rust package (9 個) の `Cargo.toml` 整合性調査 (edition / resolver / profile.release)
- [ ] ルート `Cargo.toml` 作成 (`[workspace]` + `members = [...]`)
- [ ] `push-runner-config.toml` の rust-test command を `cargo test` (workspace) に戻す
- [ ] `templates/push-runner-config.toml` に rust-test group + コメント追加
- [ ] 回帰テスト: `cargo test` (workspace 全体) + `pnpm build:all`
- [ ] ADR-026 執筆 (Cargo workspace 化の判断記録)
1. Rust test を push pipeline で一発実行できるよう Cargo workspace 化
2. `templates/push-runner-config.toml` に `rust-test` group テンプレートを反映
- **現在地**: 実装完了、PR-β として push 予定
- [x] 全 Rust package (10 個) の `Cargo.toml` 整合性調査 (edition=2021 / profile.release 統一確認)
- [x] ルート `Cargo.toml` 作成 (`[workspace]` + `members` + `[profile.release]` 集約)
- [x] 各 member Cargo.toml から `[profile.release]` を削除 (workspace で ignore される警告解消)
- [x] `.gitignore` に `/target/` 追加 (workspace 共有 target の無視)
- [x] `package.json` の build スクリプトを `cargo build --release -p <name>` 形式に統一
- [x] `push-runner-config.toml` の rust-test command を `cargo test` (workspace) に簡素化
- [x] `templates/push-runner-config.toml` に rust-test group (コメントアウト済み) を追加
- [x] ADR-026 執筆 (Cargo workspace 化の判断記録)
- [x] 回帰テスト: `cargo test` (318 passed + 1 integration) / `pnpm build:all` (警告なしで成功)
- [ ] PR-β 作成 → レビュー → マージ
- **詰まっている箇所**: なし (方針確定済み)
- **依存関係**:
- PR-α (ADR-021~025) が先行マージされていること (ADR-022 の責務分離原則を参照するため)
- **詰まっている箇所**: なし
- **参照 ADR**:
- ADR-021: jj 変更検出ロジック (本実装で確立、ライブラリ化は ADR-024 (仮) で様子見)
- ADR-022: 自動化コンポーネントの責務分離 (本 PR で実装完了)
- ADR-026 (予定): Cargo workspace 化の判断記録
- ADR-021 / ADR-022 (前 PR で確立): 本 infra 整備の背景
- ADR-026: Cargo workspace 化の判断記録 (本 PR で執筆)

---

Expand Down
Loading