Skip to content

#444 を実装する(スプリント m10b) - #448

Merged
takemi-ohama merged 10 commits into
sprint/m10bfrom
feat/issue-444-m10b
Oct 8, 2026
Merged

takemi-ohama merged 10 commits into
sprint/m10bfrom
feat/issue-444-m10b

Conversation

@takemi-ohama

@takemi-ohama takemi-ohama commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

#444 のリファクタリング 13 件(R1〜R13)をスプリント m10b のブランチへ集めます。長い関数から段を抜き出し、引数をまとめ、形ごとの処理を対応表へ分けました。あわせてテストの補助を 1 か所に寄せています。

利用者向けの変化

  • 無し

移行の手順

  • 無し

変更の要点

  • volume/compose.py
    • _aws_sync_plan は _SyncContext を受け取って振り分けるだけにしました(R1)。
    • environment の形ごとの伏せ方を、対応表 _ENV_MASKERS へ分けました(R3・R4)。
  • commands/container.py
    • 起動の後の処理で各段に渡す引数を _ComposeDeployment にまとめました(R5)。
    • docs/specifications/post-start.md もこれに合わせて直しました。
  • commands/env.py
    • --group の名前の検証を check_group_option にまとめました(R2)。
    • env.yml の値の集め方から、自動生成の段と入力の段を抜き出しました(R6)。
    • env keygen から次の 3 つを抜き出しました(R7)。tui/actions_env_keys.py もこれに合わせています。
      • 既存の鍵の表示
      • 読めない鍵があるときの中止
      • 作り直しの同意
    • env list の節の出し方を 1 つの関数にまとめました(R8・R9)。
  • snapshot/manager.py
    • 復元の処理から、前の検査と差分の展開を抜き出しました(R10)。
  • テスト
    • compose のテストの補助を tests/volume/conftest.py の 1 か所にまとめました(R11・R12)。
    • 偽の OpenBao の do_POST を経路ごとの関数に分けました(R13)。
    • tests/cli/tui/test_actions_env_keys.py・tests/commands/test_env_sync_group.py・tests/commands/test_env_user_axis.py にテストを足しました。
  • 変更は 13 ファイル、+530 / −325 行です。

テスト

ステップ exit 結果
test-limited 0 範囲テスト 1 本が ok(133.9 秒、戦略 local-full)

モード: standard / 通した工程: 実装 → 完了判定 → Pull Request

🤖 Generated with Claude Code

測定(変更の前後)

コマンド: uvx ruff check --select C901 --config 'lint.mccabe.max-complexity=0' <ファイル>(C901)・uvx complexipy <ファイル> --output-format json(認知的複雑度)・ast の lineno/end_lineno と引数の数(self を除く)。スクリプトは measure.py

件 関数 変更の前 変更の後
R1 lib/devbase/commands/env.py#_aws_sync_plan 69 行・引数 3・認知 21・C901 15 18 行・引数 1・認知 4・C901 3
R1 lib/devbase/commands/env.py#_aws_plan_for_selection — 20 行・引数 2・認知 4・C901 4
R1 lib/devbase/commands/env.py#_aws_plan_for_unregistered — 32 行・引数 1・認知 6・C901 6
R1 lib/devbase/commands/env.py#_report_unknown_profiles — 4 行・引数 1・認知 1・C901 2
R1 lib/devbase/commands/env.py#_report_profile_conflicts — 6 行・引数 1・認知 1・C901 2
R2 lib/devbase/commands/env.py#check_group_option — 18 行・引数 3・認知 2・C901 3
R2 lib/devbase/commands/env.py#_target_group 40 行・引数 3・認知 10・C901 8 34 行・引数 3・認知 9・C901 7
R2 lib/devbase/tui/actions_env_keys.py#group_attrs 28 行・引数 1・認知 6・C901 5 26 行・引数 1・認知 6・C901 5
R3・R4 lib/devbase/volume/compose.py#_mask_secret_environment 58 行・引数 2・認知 23・C901 8 21 行・引数 2・認知 1・C901 2
R3・R4 lib/devbase/volume/compose.py#_mask_env_none — 3 行・引数 3・認知 1・C901 1
R3・R4 lib/devbase/volume/compose.py#_mask_env_dict — 9 行・引数 3・認知 4・C901 2
R3・R4 lib/devbase/volume/compose.py#_mask_env_list — 14 行・引数 3・認知 7・C901 3
R3・R4 lib/devbase/volume/compose.py#_mask_env_other — 9 行・引数 3・認知 0・C901 1
R5 lib/devbase/commands/container.py#_run_post_start 32 行・引数 7・認知 3・C901 3 36 行・引数 4・認知 3・C901 3
R6 lib/devbase/commands/env.py#_collect_from_env_yml 33 行・引数 2・認知 19・C901 7 17 行・引数 2・認知 6・C901 5
R6 lib/devbase/commands/env.py#_generated_secret — 8 行・引数 1・認知 1・C901 2
R6 lib/devbase/commands/env.py#_prompt_env_var — 15 行・引数 2・認知 4・C901 3
R7 lib/devbase/commands/env.py#cmd_env_keygen 93 行・引数 3・認知 13・C901 8 47 行・引数 3・認知 6・C901 5
R7 lib/devbase/commands/env.py#_show_existing_key — 13 行・引数 1・認知 1・C901 2
R7 lib/devbase/commands/env.py#_refuse_unreadable_key — 22 行・引数 1・認知 2・C901 2
R7 lib/devbase/commands/env.py#_confirm_key_regeneration — 23 行・引数 2・認知 2・C901 3
R8・R9 lib/devbase/commands/env.py#cmd_env_list 49 行・引数 7・認知 21・C901 8 28 行・引数 7・認知 5・C901 4
R8・R9 lib/devbase/commands/env.py#_print_env_section — 5 行・引数 5・認知 0・C901 1
R8・R9 lib/devbase/commands/env.py#_list_global_sections — 10 行・引数 6・認知 4・C901 3
R8・R9 lib/devbase/commands/env.py#_list_project_sections — 12 行・引数 6・認知 6・C901 3
R10 lib/devbase/snapshot/manager.py#SnapshotManager.restore 60 行・引数 2・認知 15・C901 9 38 行・引数 2・認知 2・C901 2
R10 lib/devbase/snapshot/manager.py#SnapshotManager._restore_source — 12 行・引数 2・認知 4・C901 4
R10 lib/devbase/snapshot/manager.py#SnapshotManager._apply_incrementals — 16 行・引数 5・認知 9・C901 5
R11・R12 tests/volume/conftest.py#write_compose — 7 行・引数 3・認知 1・C901 2
R11・R12 tests/volume/conftest.py#load_scaled — 3 行・引数 1・認知 0・C901 1
R11・R12 tests/volume/conftest.py#mount_source — 10 行・引数 2・認知 9・C901 5
R13 tests/conftest.py#_Handler.do_POST 46 行・引数 0・認知 20・C901 13 5 行・引数 0・認知 1・C901 2
R13 tests/conftest.py#_Handler._login — 13 行・引数 1・認知 3・C901 3
R13 tests/conftest.py#_Handler._write_secret — 18 行・引数 1・認知 5・C901 6
R13 tests/conftest.py#_Handler._refuse_write — 20 行・引数 2・認知 8・C901 6
R13 tests/conftest.py#_Handler._apply_cas — 15 行・引数 3・認知 3・C901 2

対象の 6 ファイル(と tests/volume の 2 つのテスト)の既存の関数で、C901・認知的複雑度が上がったものは 0 件。
R11・R12: tests/volume/test_compose_vscode.py・test_compose_group.py に _write_compose・_load_scaled・_mount_source の定義は無い(grep で 0 件)。

R8・R9 の cmd_env_list の引数 7 個は CLI の引数をそのまま受ける形で、表の兆候(duplication・long_method)には含まれない。

現状固定のテストを先に足した経路(設計の決定 11): CLI の --group global・--group 1234 の誤りの文、TUI で 1234・projects を入れたときの誤りの行、env list の節の出力(変数の無い節と --keys-only を含む)。変更の前のコードで通ることを確かめた。

固有の語の検査は手元では語の一覧が無く飛ばされた(検査していない)。CI の Proper term check の結果で確かめる。

takemi-ohama and others added 10 commits October 8, 2026 17:09
控えの項目の 3 つの経路のうち、aws_profiles の分岐と控えの無い分岐を
_aws_plan_for_selection・_aws_plan_for_unregistered へ抜き出し、入れ子の
report の関数をモジュールの関数へ出した。振る舞いは変えない。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_target_group と TUI の group_attrs に重なっていた storage_group の検査と
誤りの文の組み立てを 1 つの関数にした。TUI の前段(validate_account_group)は
account_rule で選ぶ。先に CLI と TUI の誤りの文を丸ごと固定するテストを足した。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_mask_secret_environment は形を求めて対応表の関数を呼び、返った値を置くだけにした。
形ごとの式と警告の文は変えない。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
project_name・scale・dev_service_name・compose_file を凍結した dataclass に
まとめ、_run_post_start の引数を 4 個にした。個々の処理への引数と順は変えない。
確定仕様の関数の形も合わせた。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
理由の注記は、それが説明するコードと一緒に抜き出した関数へ移した。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
見出し・変数・件数の行を _print_env_section で出し、共通とプロジェクトの
節の選び方を別の関数へ抜き出した。先に節の出力を丸ごと固定するテストを足した。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…R12)

test_compose_vscode.py と test_compose_group.py に重なっていた write_compose・
load_scaled・mount_source を conftest.py へ移し、両方から取り込む。期待値は変えない。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ログインを _login、KV の書き込みを _write_secret へ振り分け、書き込みの前の
拒否と CAS の更新を更に抜き出した。応答と順は変えない。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@takemi-ohama
takemi-ohama marked this pull request as ready for review October 8, 2026 08:30
@takemi-ohama
takemi-ohama merged commit 6645b21 into sprint/m10b Oct 8, 2026
10 checks passed
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.

1 participant