[codex] app初期化責務の分割(factory/bootstrap/version/platform)#43
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景とユーザー影響
今回の変更前は、CLI起動の中心である
app.pyに OS 判定、--version処理、設定ロードとエラーハンドリング、logging 初期化、runtime 注入、サブコマンド登録が集中していました。機能追加時に単一ファイルへ責務が雪だるま式に増えるため、変更の影響範囲が読みにくくなり、レビュー時に副作用を追跡しづらい状態でした。結果として、新規機能や不具合修正の開発速度と安全性の両方に悪影響が出るリスクがありました。根本原因
CLI のエントリポイントと初期化処理の境界が曖昧で、アプリ構築・ブートストラップ・プラットフォーム判定・バージョン表示が
app.pyに同居していたことが根本原因です。責務分離が不足していたため、関心事ごとのテスト設計もしづらく、拡張時に結合度が高まる構造になっていました。対応内容
app.pyの責務を分割し、機能ごとのモジュールへ移しました。src/ableton_cli/app_factory.pycreate_app()とregister_commands(app)を配置build_runtime_context(...)を呼び出す構成へ整理src/ableton_cli/bootstrap.pyRuntimeContext構築を集約src/ableton_cli/platform_detection.pyPlatformPaths構築処理を移動src/ableton_cli/version.pysrc/ableton_cli/app.pycreate_appの再エクスポート)に縮小src/ableton_cli/cli.pyapp_factoryに更新テストと検証
分割に合わせてテストを追加・更新し、振る舞い維持を確認しました。
tests/test_bootstrap.pytests/test_platform_detection.pytests/test_version.pytests/test_app_factory.pytests/test_cli_json_output.py実行したチェック:
uv run python -m ableton_cli.dev_checksruff check,ruff format --check,pytestを実行uv run pytestを再実行上記はすべて成功しています(全 361 テスト通過)。
補足
挙動のフォールバック経路や後方互換用の分岐は追加していません。責務分離のみを目的に、既存の CLI 仕様は維持したまま内部構造を整理しています。