Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
28 changes: 25 additions & 3 deletions .github/workflows/ci-simple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ jobs:

test:
runs-on: ubuntu-latest
env:
DISPLAY: ":99"
DBUS_SESSION_BUS_ADDRESS: "unix:path=/tmp/dbus-test-session"

steps:
- uses: actions/checkout@v3
Expand All @@ -69,7 +72,19 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install ibus libgirepository1.0-dev libmarisa-dev clang libibus-1.0-dev unzip libgtk-4-dev zstd
sudo apt-get install -y \
xvfb xdotool dbus-x11 at-spi2-core \
ibus libibus-1.0-dev libgtk-4-dev \
libgirepository1.0-dev libmarisa-dev clang unzip zstd
- name: Start Xvfb
run: |
Xvfb :99 -screen 0 1024x768x24 &
sleep 2
- name: Start D-Bus session
run: |
dbus-daemon --session --fork \
--address="unix:path=/tmp/dbus-test-session"
sleep 1
- name: make test data
run: |
cd akaza-data/ && make test-data
Expand All @@ -79,5 +94,12 @@ jobs:
- uses: dtolnay/rust-toolchain@master
with:
toolchain: "1.92.0"
- name: Run tests
run: cargo test
- name: Run unit tests
run: cargo test --lib
timeout-minutes: 2
- name: Run integration tests
run: cargo test --test integration
timeout-minutes: 5
- name: Run all other tests
run: cargo test --bins --tests
timeout-minutes: 10
72 changes: 70 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,46 @@ cargo fmt

変更後にテストを実行して、既存機能が壊れていないことを確認してください。

#### Docker環境でのテスト(推奨)

ibus-akazaのテストはX11とIBusが必要なため、Docker環境での実行を推奨します:

```bash
# Dockerイメージのビルド(初回のみ)
make docker-test-build

# すべてのテストを実行
make docker-test

# Unit testsのみ
make docker-test-unit

# Integration testsのみ
make docker-test-integration

# E2E testsのみ(将来拡張予定)
make docker-test-e2e

# デバッグ用シェル
make docker-test-shell
```

Docker環境はGitHub Actions CIと同じ構成を使用しているため、ローカルでの動作がCIでも同じように動作します。

詳細は `ibus-akaza/DOCKER_TESTING.md` を参照してください。

#### 直接実行(libakaza等、X11不要なパッケージ)

```bash
# 全体のテスト
cargo test

# 特定のパッケージのみ
cargo test --package libakaza
cargo test --package akaza-data

# ibus-akazaのunit testsのみ(X11不要)
cargo test --lib --package ibus-akaza
```

### 推奨: Clippy チェック
Expand All @@ -50,12 +83,14 @@ cargo clippy --all-targets --all-features

## PR 作成時

- **タイトルと本文は日本語で記述する**
- タイトルは変更内容を明確に
- 本文には以下を含める:
- Summary: 変更の概要
- 変更内容の詳細
- テスト結果
- 関連する Issue があれば記載
- テスト結果(Docker環境での実行結果を含む)
- 関連する Issue があれば記載(例: `Related: #354`)
- コメントも日本語で記述する

## 開発フロー

Expand All @@ -76,6 +111,39 @@ cargo clippy --all-targets --all-features
- 新機能には対応するテストを追加
- エッジケースのテストも考慮

#### テストのレイヤー

1. **Unit Tests**: 個別の関数やモジュールのテスト
- FFIをモック化
- 高速(<1秒)
- `cargo test --lib` で実行

2. **Integration Tests**: モジュール間の連携テスト
- IBusなしで状態遷移を検証
- 中速(~10秒)
- `cargo test --test integration` で実行

3. **E2E Tests**: 実際のIBusを使用したテスト
- 実際のXvfb + IBusが必要
- 低速(~60秒)
- `cargo test --test e2e -- --ignored --test-threads=1` で実行
- Docker環境推奨: `make docker-test-e2e`

#### テストが書きにくいコードについて

テストが書きにくいコードを発見した場合:

1. Issue を作成して記録
2. 以下の情報を含める:
- なぜテストが書きにくいか
- どのような依存関係があるか
- リファクタリングの提案(あれば)
3. ラベル `testability` を付ける

これにより、将来的なリファクタリングの参考になります。

例: Issue #353 - CurrentState のテスト容易性改善

### 依存関係の更新

- renovate が自動的に依存関係を更新
Expand Down
89 changes: 89 additions & 0 deletions Cargo.lock

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

22 changes: 21 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,25 @@ clean:
cargo clean
$(MAKE) -C ibus-akaza clean

.PHONY: all install install-resources clean
# Docker test targets
docker-test-build:
docker compose -f docker-compose.test.yml build

docker-test:
docker compose -f docker-compose.test.yml run --rm test test

docker-test-unit:
docker compose -f docker-compose.test.yml run --rm test test-unit

docker-test-integration:
docker compose -f docker-compose.test.yml run --rm test test-integration

docker-test-e2e:
docker compose -f docker-compose.test.yml run --rm test test-e2e

docker-test-shell:
docker compose -f docker-compose.test.yml run --rm test bash

.PHONY: all install install-resources clean \
docker-test-build docker-test docker-test-unit docker-test-integration docker-test-e2e docker-test-shell

21 changes: 21 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: '3.8'

services:
test:
build:
context: .
dockerfile: ibus-akaza/Dockerfile.test
volumes:
- .:/akaza
- cargo-cache:/root/.cargo/registry
- target-cache:/akaza/target
environment:
- DISPLAY=:99
- DBUS_SESSION_BUS_ADDRESS=unix:path=/tmp/dbus-test-session
# デバッグ用にコンテナを残す
stdin_open: true
tty: true

volumes:
cargo-cache:
target-cache:
11 changes: 11 additions & 0 deletions ibus-akaza/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
name = "ibus_akaza_lib"
path = "src/lib.rs"

[[bin]]
name = "ibus-akaza"
path = "src/main.rs"

[dependencies]
tempfile = "3"
anyhow = "1.0"
Expand All @@ -25,3 +33,6 @@ xdg = "2.5"

[build-dependencies]
cc = "1.0"

[dev-dependencies]
serial_test = "3.0"
Loading