diff --git a/CLAUDE.md b/CLAUDE.md index 205e358..d7dd450 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -6,7 +6,7 @@ ## 開発進捗 -最新: PLAN_02 のステップ 2-4(`clean --logs`)完了.M2 が終わり(`ls`・`clean` は実サーバでは未確認),次は M3 のステップ 3-1(TongueSegModel の切り替え) +最新: PLAN_02 のステップ 3-2(サーバでの `uv run --no-group`)完了.外すグループがあるときは `--frozen` も付ける形に直した.次は TongueSegModel の側の 3-4・3-5 ※ 本欄は**最新ステップ 1 行のみ上書き更新**.詳細な進捗履歴(動機・設計判断・失敗パターン)は [docs/PROGRESS.md](docs/PROGRESS.md) に追記する.運用ルールは `.claude/rules/progress-log.md` を参照(該当ファイル編集時に自動ロードされる). ## 必須ルール(コード実装時) diff --git "a/docs/03_PLAN/PLAN_02_\351\226\213\347\231\272\343\202\271\343\203\206\343\203\203\343\203\227.md" "b/docs/03_PLAN/PLAN_02_\351\226\213\347\231\272\343\202\271\343\203\206\343\203\203\343\203\227.md" index 096efb8..2113bd9 100644 --- "a/docs/03_PLAN/PLAN_02_\351\226\213\347\231\272\343\202\271\343\203\206\343\203\203\343\203\227.md" +++ "b/docs/03_PLAN/PLAN_02_\351\226\213\347\231\272\343\202\271\343\203\206\343\203\203\343\203\227.md" @@ -90,7 +90,7 @@ | 直すステップ | 内容 | | --- | --- | | 3-1 | TongueSegModel の `pyproject.toml` で,LabRemote を専用の依存グループ(`remote`)に入れ,`labremote.yaml` に `run.exclude_groups: [remote]` を書く | -| 3-2 | サーバに LabRemote のフォルダが無い状態で,`uv run --no-group remote` がロックファイルの確認を通るかは,まだ確かめていない(実サーバとサブモジュールが要る).通らなければ,`--frozen` を足すか,導入に要るものだけを送る形に仕様を直す.今の実装が `uv run` へ渡せるのは `--no-group <名前>` だけである | +| 3-2 | 確かめた(2026-11-30): サーバに LabRemote のフォルダが無い状態で,`uv run --no-group remote` は通らなかった(`--locked` を足しても同じ).`--frozen` を足すと通った.`run.exclude_groups` が 1 つ以上あるときだけ `--frozen` も付けるように,仕様(SPEC_01〜03)と実装を直した | | 1-7c | 依存グループの名前の検証は,`a.`・`a-` のように末尾が記号の名前も通す.依存グループの名前の決まり(末尾は英数字)より緩い.害は無い(uv が拒否する)が,そろえるなら仕様を先に直す | ### 1-6 で分かったこと (Findings from Step 1-6) @@ -212,7 +212,7 @@ | ステップ | 内容 | | --- | --- | | 3-1 | LabRemote をサブモジュール(`external/LabRemote`)として足し,専用の依存グループに入れる.`labremote.yaml` を書く(`predictions.csv`・`split.json` を回収の一覧に足す) | -| 3-2 | **実サーバで確かめる**: パス指定の依存先のフォルダが無いサーバで,`uv run --no-group` が通るか([SPEC_01](../04_SPEC/SPEC_01_アーキテクチャ設計.md) の「※ 未検証」).通らなければ,`--frozen` を足すか,導入に要るものだけを送る形に仕様を直す | +| 3-2 | **実サーバで確かめる**: パス指定の依存先のフォルダが無いサーバで,`uv run --no-group` が通るか.→ 確かめた(2026-11-30): `--no-group` だけ・`--locked` 付きは失敗,`--frozen` 付きは成功.`run.exclude_groups` があるときだけ `--frozen` も付けるように直した([SPEC_01](../04_SPEC/SPEC_01_アーキテクチャ設計.md)「プロジェクトからの使い方」) | | 3-3 | 「この設定で,回収してはならない名前が弾かれる」「送ってはならないフォルダが送られない」テストを,TongueSegModel の側に置く | | 3-4 | `src/tongue_seg_model/remote/`・`cli/remote.py`・そのテスト・`configs/remote.yaml` を消し,文書(SPEC_03・ENV_04 等)の `tsm-remote` を `labremote` に直す | | 3-5 | 合成データで,両サーバの確認をやり直す(接続・送信・起動・回収・削除).使ったサーバ・GPU と,回収・削除した件数を報告する | diff --git "a/docs/04_SPEC/SPEC_01_\343\202\242\343\203\274\343\202\255\343\203\206\343\202\257\343\203\201\343\203\243\350\250\255\350\250\210.md" "b/docs/04_SPEC/SPEC_01_\343\202\242\343\203\274\343\202\255\343\203\206\343\202\257\343\203\201\343\203\243\350\250\255\350\250\210.md" index f5d2f54..5af4220 100644 --- "a/docs/04_SPEC/SPEC_01_\343\202\242\343\203\274\343\202\255\343\203\206\343\202\257\343\203\201\343\203\243\350\250\255\350\250\210.md" +++ "b/docs/04_SPEC/SPEC_01_\343\202\242\343\203\274\343\202\255\343\203\206\343\202\257\343\203\201\343\203\243\350\250\255\350\250\210.md" @@ -32,9 +32,22 @@ LabRemote は手元でだけ動くので,**サーバへは送らず,サーバの環境にも入れない**(2026-11-19 のユーザー判断.送る必要のないものは送らない). - 送信: LabRemote 自身のフォルダ(実行中の `labremote` パッケージが入っているリポジトリ)がプロジェクトのルートの下にある場合,設定に関わらず送らない -- サーバの環境: ジョブを起動するときの `uv run` に,設定で指定した依存グループを外す指定(`--no-group`)を付ける.LabRemote を専用のグループに入れておけば,サーバでは導入されない +- サーバの環境: ジョブを起動するときの `uv run` に,設定で指定した依存グループを外す指定(`--no-group`)と,ロックファイルをそのまま使う指定(`--frozen`)を付ける(` run --frozen --no-group <名前> ... `).LabRemote を専用のグループに入れておけば,サーバでは導入されない.外すグループが無いときは,どちらも付けない(` run `) -※ 未検証: パス指定の依存先のフォルダがサーバに無い状態で,`uv run --no-group` がロックファイルの確認を通るか.通らない場合は,`--frozen` を併せて付けるか,導入に要るもの(`pyproject.toml`・`README.md`・`src/`)だけを送る形に変える.実装の最初に実サーバで確かめる. +パス指定の依存先のフォルダがサーバに無い状態での `uv run` の振る舞いは,2026-11-30 に実サーバで次のとおり確かめた(LabRemote を依存グループ `remote` に入れたプロジェクトで,サーバに `external/LabRemote` が無い状態). + +| サーバで実行したコマンド | 結果 | +| --- | --- | +| `uv run --no-group remote ` | 失敗(終了コード 2.LabRemote のフォルダが見つからず,パッケージの情報を作れない) | +| `uv run --locked --no-group remote ` | 同じエラーで失敗 | +| `uv run --frozen --no-group remote ` | 成功.LabRemote はサーバの環境に入らない | + +`--no-group` だけ(`--locked` を足しても)では,uv がロックファイルと `pyproject.toml` が合っているかを確かめるときに,外したグループの依存先(LabRemote のフォルダ)の情報も読みにいくため,フォルダが無いと止まる(エラーの内容から).`--frozen` は,この確認をせずにロックファイルをそのまま使う指定である.それでよい理由は次のとおり. + +- `uv.lock` は,`push` のたびに手元から送られる.手元では `uv run`(`labremote` の起動を含む)のたびにロックファイルが最新に保たれるので,サーバに届くロックファイルは手元の `pyproject.toml` と合っている +- サーバでロックファイルを作り直させない(サーバで依存先の解決をやり直すと,手元と違う版が入りうる) + +`--frozen` は,外すグループがあるときだけ付ける.外すグループが無ければ,パス指定の依存先がサーバに無いことは起きない(送られている)ので,今までどおり `uv run` にロックファイルの確認をさせる. ## プロジェクトのルートの見つけ方 (Finding the Project Root) diff --git "a/docs/04_SPEC/SPEC_02_\350\250\255\345\256\232\343\203\225\343\202\241\343\202\244\343\203\253\344\273\225\346\247\230.md" "b/docs/04_SPEC/SPEC_02_\350\250\255\345\256\232\343\203\225\343\202\241\343\202\244\343\203\253\344\273\225\346\247\230.md" index 536b029..fca4a6e 100644 --- "a/docs/04_SPEC/SPEC_02_\350\250\255\345\256\232\343\203\225\343\202\241\343\202\244\343\203\253\344\273\225\346\247\230.md" +++ "b/docs/04_SPEC/SPEC_02_\350\250\255\345\256\232\343\203\225\343\202\241\343\202\244\343\203\253\344\273\225\346\247\230.md" @@ -131,17 +131,18 @@ | キー | 既定 | 内容 | | --- | --- | --- | | `env` | `{}` | ジョブに既定で渡す環境変数.`--env` で同じ名前を指定すると,`--env` が優先される | -| `exclude_groups` | `[]` | サーバの `uv run` で外す依存グループの名前.グループごとに `--no-group <名前>` を付ける.名前は英数字で始まり,英数字・`_`・`-`・`.` だけ | +| `exclude_groups` | `[]` | サーバの `uv run` で外す依存グループの名前.グループごとに `--no-group <名前>` を付ける.1 つ以上あるときは `--frozen` も付ける.名前は英数字で始まり,英数字・`_`・`-`・`.` だけ | `exclude_groups` の書き方. - 名前の一覧で書く(`exclude_groups: [remote]`.1 つの文字列 `exclude_groups: remote` はエラーにする) - 名前は文字列で書く.英数字で始まり,英数字・`_`・`-`・`.` だけ(依存グループの名前に使える文字).それ以外(空・空白・`/`・`=`・先頭の `-` 等)はエラーにする - 同じ名前を 2 回書くとエラーにする.比べ方は,Python のパッケージの名前の正規化(PEP 503)と同じにする: 小文字にし,`_`・`-`・`.` が続いた部分を 1 つの `-` にして比べる(`remote` と `Remote`,`a_b` と `a.-b` は同じ名前.`ab` と `a-b` は別の名前).uv がそう扱うためである.サーバへ渡すのは,設定に書いたままの名前である -- サーバのコマンドでは,` run --no-group <名前> ... <コマンド>` の形で,書いた順に,コマンドより前に付ける.値は引用して埋め込む +- サーバのコマンドでは,` run --frozen --no-group <名前> ... <コマンド>` の形で,`--frozen` を 1 つ付けてから,書いた順に,コマンドより前に付ける.値は引用して埋め込む +- `--frozen` は,ロックファイル(`uv.lock`)が `pyproject.toml` と合っているかを確かめずに,そのまま使う指定である.外したグループの依存先(LabRemote のフォルダ)がサーバに無いと,`--no-group` だけでは uv が止まるため付ける([SPEC_01](SPEC_01_アーキテクチャ設計.md)「プロジェクトからの使い方」の実サーバでの確認).`uv.lock` は毎回手元から送られ,手元の `uv run` で最新に保たれるので,サーバでロックファイルを作り直させない - `--cpu` のジョブにも,`--dry-run` の表示にも,同じように付く.ジョブのログの開始行に出るコマンドの表示にも付ける(実際に動くコマンドと,表示を食い違わせない) -- 一覧が空のときは,何も付かない -- `uv run` へ渡せるのは `--no-group <名前>` だけである.任意の引数を渡す設定は設けない +- 一覧が空のときは,何も付かない(`--frozen` も付かない) +- `uv run` へ渡せるのは `--frozen` と `--no-group <名前>` だけで,`--frozen` を付けるかどうかも `exclude_groups` の有無で決まる.任意の引数を渡す設定は設けない - 手元の環境には関わらない(手元で LabRemote を入れるかどうかは,利用する側の `pyproject.toml` で決める) 優先の順は,`run.env` → `servers[].env` → `--env`(後のものが勝つ).予約の環境変数([SPEC_01](SPEC_01_アーキテクチャ設計.md)「環境変数」)は,どこにも書けない. diff --git "a/docs/04_SPEC/SPEC_03_\343\203\252\343\203\242\343\203\274\343\203\210\345\256\237\350\241\214\344\273\225\346\247\230.md" "b/docs/04_SPEC/SPEC_03_\343\203\252\343\203\242\343\203\274\343\203\210\345\256\237\350\241\214\344\273\225\346\247\230.md" index 780762b..44525c5 100644 --- "a/docs/04_SPEC/SPEC_03_\343\203\252\343\203\242\343\203\274\343\203\210\345\256\237\350\241\214\344\273\225\346\247\230.md" +++ "b/docs/04_SPEC/SPEC_03_\343\203\252\343\203\242\343\203\274\343\203\210\345\256\237\350\241\214\344\273\225\346\247\230.md" @@ -126,7 +126,7 @@ - ジョブ名は,英数字で始まり,英数字・`_`・`-` だけ,1〜64 文字 - いずれかのサーバで同じ名前のジョブが実行中ならエラーにする -- tmux のセッション名をジョブ名とし,サーバの `remote_dir` で ` run ` を実行する.設定の `run.exclude_groups` に書いた依存グループは,` run --no-group <名前> ... ` の形で外す(LabRemote をサーバの環境に入れないため.[SPEC_02](SPEC_02_設定ファイル仕様.md)「`run`」).ログの開始行のコマンドの表示にも,同じ形で出す +- tmux のセッション名をジョブ名とし,サーバの `remote_dir` で ` run ` を実行する.設定の `run.exclude_groups` に書いた依存グループは,` run --frozen --no-group <名前> ... ` の形で外す(LabRemote をサーバの環境に入れないため.外すグループがあるときだけ `--frozen` も付ける.[SPEC_02](SPEC_02_設定ファイル仕様.md)「`run`」).ログの開始行のコマンドの表示にも,同じ形で出す - ジョブに渡す環境変数は [SPEC_01](SPEC_01_アーキテクチャ設計.md)「環境変数」のとおり - ログは `/<結果の置き場>/_remote_logs/<ジョブ名>.log` に,開始の行(サーバ名・GPU・日時)と終了コードの行を付けて追記する - `--dry-run` を付けると,GPU の選択までを行い,送信・起動はしない diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md index dbf294b..c5c00e0 100644 --- a/docs/PROGRESS.md +++ b/docs/PROGRESS.md @@ -89,3 +89,6 @@ - 設計判断: 実行中かの確認は,消すのと同じサーバのスクリプトの中で行う.セッションの一覧を取れなかったときは,「tmux が無い」「サーバが動いていない」と確かに分かる場合だけ実行中でないとし,それ以外は消さない - 失敗パターン: ① 一覧で「サーバが動いていない」と分かったら,そこで実行中でないと決める → 一覧と,名前を直接尋ねた答えが食い違う状態で,実行中のジョブのログを消す / ② 一覧の結果に関わらず,名前を直接尋ねる確認を必ず通す形で解決(テストで見つかった) - 後段: 実サーバの tmux が出すメッセージの形しだいで,消せずに止まることがありうる.3-5 で確かめる(PLAN_02) +- [x] **ステップ 3-2(サーバでの `uv run --no-group`.2026-11-30)**: TongueSegModel の切り替えで,サーバに LabRemote のフォルダが無いと `uv run --no-group remote` が止まることが分かった.`run.exclude_groups` が 1 つ以上あるときは `--frozen` も付ける形に直し,Newton・Archimedes の両方で通ることを確かめた(GPU は使わず,CPU のジョブで `tsm-train --help`) + - 判明: `--no-group` で外したグループでも,uv はパス指定の依存先のメタデータを読みにいき,`Distribution not found` で止まる(`--locked` でも同じ).`--frozen` ならロックファイルの中身だけで動き,外したグループは入らない + - 設計判断(ユーザー判断): `--frozen` は外すグループがあるときだけ付ける.いつも付けると,外すグループの無いプロジェクトでもサーバでロックファイルの確認が効かなくなるため.LabRemote の一部を送る案は,自分自身のフォルダを送らない固定の除外を崩すので採らなかった.設定の項目は増やさない diff --git a/src/labremote/cli.py b/src/labremote/cli.py index 0e2bbd6..4034e1f 100644 --- a/src/labremote/cli.py +++ b/src/labremote/cli.py @@ -1635,7 +1635,7 @@ "空き(利用者あり)を priority 順・GPU 番号順に探す)," "そのサーバへコードを送ってから remote_dir で `uv run ` を tmux で起動する" "(設定の run.exclude_groups の各グループは `--no-group <名前>` として" - "uv run の直後に付く)." + "uv run の直後に付き,そのときは `--frozen` も付く)." f"出力は remote_dir//{REMOTE_LOG_DIR_NAME}/.log に追記され" "(results.dir は設定の結果の置き場.既定は runs),接続が切れても継続する." "コマンドは -- の後に書く." @@ -1703,7 +1703,10 @@ "command", nargs=argparse.REMAINDER, metavar="-- COMMAND", - help="サーバで実行するコマンド(uv run と --no-group <名前> の後ろに付く部分).", + help=( + "サーバで実行するコマンド(uv run と,run.exclude_groups があれば" + " --frozen --no-group <名前> の後ろに付く部分)." + ), ) p_logs = sub.add_parser( diff --git a/src/labremote/commands.py b/src/labremote/commands.py index 8909721..ad31092 100644 --- a/src/labremote/commands.py +++ b/src/labremote/commands.py @@ -919,13 +919,17 @@ 開始行(サーバ名・GPU・日時)と終了コード行で挟む.標準入力は /dev/null にする (入力待ちで止まらないように).非対話 ssh では `~/.local/bin` が PATH に無いため, uv のディレクトリと `$HOME/.local/bin` を PATH に足す. - `exclude_groups` の各名前は,` run` の直後(コマンドより前)に `--no-group <名前>` として - 渡した順に付ける(LabRemote を入れた依存グループをサーバの環境に入れないため). + `exclude_groups` が 1 つ以上あれば,` run` の直後(コマンドより前)に `--frozen` を + 1 つ付け,続けて各名前を `--no-group <名前>` として渡した順に付ける(LabRemote を入れた + 依存グループをサーバの環境に入れないため.`--frozen` は,外したグループのパス指定の + 依存先がサーバに無くても,送られてきた `uv.lock` をそのまま使わせるため).空なら + どちらも付けない.ログの開始行の表示にも同じ形で出す. Args: remote_dir: リモートのプロジェクトルート. name: ジョブ名. - command: `uv run`(と `--no-group <名前>`)の後ろに付けて実行するコマンドと引数. + command: `uv run`(と `--frozen --no-group <名前> ...`)の後ろに付けて実行するコマンドと + 引数. uv_path: リモートの uv 実行ファイル. server_name: ログの開始行に書くサーバ名. gpu_index: ログの開始行に書く GPU 番号.None なら GPU を使わないジョブ(`--cpu`)として @@ -936,7 +940,7 @@ results_dir: 検証済みの結果の置き場(設定の `results.dir`). exclude_groups: サーバの `uv run` で外す依存グループの名前(設定の `run.exclude_groups`). 設定で検証済みでも,ここで `validate_dependency_group` を通してから引用して埋め込む. - 空なら何も付けない. + 1 つ以上あれば `--frozen` も付ける.空なら何も付けない. Returns: bash スクリプト(1 行). @@ -957,6 +961,10 @@ uv_options: list[str] = [] for group in exclude_groups: uv_options += ["--no-group", validate_dependency_group(group)] + if uv_options: + # 外したグループのパス指定の依存先がサーバに無いと,ロックファイルの確認で uv が止まる + # ため,送られてきた uv.lock をそのまま使う(SPEC_01「プロジェクトからの使い方」) + uv_options = ["--frozen", *uv_options] uv_quoted = quote_remote_path(uv_path) run_argv = [ diff --git a/src/labremote/config.py b/src/labremote/config.py index 5b81258..a266219 100644 --- a/src/labremote/config.py +++ b/src/labremote/config.py @@ -209,7 +209,7 @@ env: ジョブに既定で渡す環境変数(`servers[].env`・`--env` に同じ名前があれば後者が 勝つ).値はそのまま引用して渡す(`~` は展開しない). exclude_groups: サーバの `uv run` で外す依存グループの名前(書いた順.書いたままの名前で - `--no-group <名前>` として渡す). + `--no-group <名前>` として渡す.1 つ以上あれば `--frozen` も付く). """ env: dict[StrictStr, StrictStr] = Field(default_factory=dict) diff --git a/tests/test_cli.py b/tests/test_cli.py index be28509..f7a1fce 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2353,10 +2353,10 @@ _write_config_data(project, mutate) - def test_dry_run_shows_no_group_options( + def test_dry_run_shows_frozen_and_no_group_options( self, project: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str] ) -> None: - """SPEC_02「`exclude_groups` の書き方」: `--dry-run` の表示にも書いた順に付く.""" + """SPEC_02「`exclude_groups` の書き方」: `--dry-run` の表示も `--frozen` と書いた順.""" self._with_groups(project, ["remote", "dev.tools"]) _free_everywhere(monkeypatch) captured = _spy_job_script(monkeypatch) @@ -2364,6 +2364,7 @@ assert tuple(captured[0]["exclude_groups"]) == ("remote", "dev.tools") remote_command = _remote_command_of_dry_run(capsys.readouterr().out) assert _uv_run_args_of_launch(remote_command) == [ + "--frozen", "--no-group", "remote", "--no-group", @@ -2374,7 +2375,7 @@ def test_dry_run_without_groups_has_no_option( self, project: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str] ) -> None: - """SPEC_02「`exclude_groups` の書き方」: 書いていなければ何も付かない.""" + """SPEC_02「`exclude_groups` の書き方」: 書いていなければ何も付かない(`--frozen` も).""" _free_everywhere(monkeypatch) assert cli.main(_run_dry([])) == 0 remote_command = _remote_command_of_dry_run(capsys.readouterr().out) @@ -2394,14 +2395,27 @@ monkeypatch.setattr(cli, "_run_ssh", fake) assert cli.main(["run", "--name", "s", "--cpu", "--dry-run", "--", "x"]) == 0 remote_command = _remote_command_of_dry_run(capsys.readouterr().out) - assert _uv_run_args_of_launch(remote_command) == ["--no-group", "remote", "x"] + assert _uv_run_args_of_launch(remote_command) == ["--frozen", "--no-group", "remote", "x"] def test_launch_passes_options(self, project: Path, monkeypatch: pytest.MonkeyPatch) -> None: - """SPEC_03「run」: 起動のコマンドでも,`--no-group` がコマンド本体より前に付く.""" + """SPEC_03「run」: 起動のコマンドでも,`--frozen --no-group` がコマンド本体より前に付く.""" self._with_groups(project, ["remote"]) fake = _free_everywhere(monkeypatch) assert cli.main(["run", "--name", "train1", "--no-push", "--", "demo-train"]) == 0 - assert _uv_run_args_of_launch(fake.calls[-1][-1]) == ["--no-group", "remote", "demo-train"] + assert _uv_run_args_of_launch(fake.calls[-1][-1]) == [ + "--frozen", + "--no-group", + "remote", + "demo-train", + ] + + def test_launch_without_groups_has_no_frozen( + self, project: Path, monkeypatch: pytest.MonkeyPatch + ) -> None: + """SPEC_03「run」: 外すグループが無ければ,起動のコマンドは ` run ` のまま.""" + fake = _free_everywhere(monkeypatch) + assert cli.main(["run", "--name", "train1", "--no-push", "--", "demo-train"]) == 0 + assert _uv_run_args_of_launch(fake.calls[-1][-1]) == ["demo-train"] @pytest.mark.parametrize( "groups", [["-x"], ["--frozen"], ["a b"], ["remote", "Remote"], "remote"] diff --git a/tests/test_commands.py b/tests/test_commands.py index bb7cc76..9d62546 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -1126,35 +1126,76 @@ @pytest.mark.parametrize( ("groups", "options"), [ - (["remote"], ["--no-group", "remote"]), - (["remote", "dev.tools"], ["--no-group", "remote", "--no-group", "dev.tools"]), - (["dev.tools", "remote"], ["--no-group", "dev.tools", "--no-group", "remote"]), + (["remote"], ["--frozen", "--no-group", "remote"]), + ( + ["remote", "dev.tools"], + ["--frozen", "--no-group", "remote", "--no-group", "dev.tools"], + ), + ( + ["dev.tools", "remote"], + ["--frozen", "--no-group", "dev.tools", "--no-group", "remote"], + ), ], ) - def test_no_group_options_come_right_after_uv_run_in_order( + def test_frozen_and_no_group_options_come_right_after_uv_run_in_order( self, groups: list[str], options: list[str] ) -> None: - """SPEC_02「`exclude_groups` の書き方」: uv run の直後・コマンドより前に書いた順で付く.""" + """SPEC_02「`exclude_groups` の書き方」. + + ` run --frozen --no-group <名前> ... ` の形で,uv run の直後・コマンドより前に, + `--frozen` を 1 つ付けてから書いた順に `--no-group` が付く. + """ command = ["demo-train", "--config", "c.yaml"] assert _uv_run_args(_script_with_groups(groups, command=command)) == [*options, *command] @pytest.mark.parametrize("groups", [(), []]) def test_empty_list_adds_nothing(self, groups: object) -> None: - """SPEC_02「`exclude_groups` の書き方」: 空なら何も付かない(引数無しと同じ).""" - assert _script_with_groups(groups) == _script(0, ["demo-train", "--config", "c.yaml"]) - assert "--no-group" not in shlex.split(_script_with_groups(groups)) + """SPEC_02「`exclude_groups` の書き方」. + + 空なら何も付かない(` run `.`--frozen` も付かない.引数無しと同じ). + """ + command = ["demo-train", "--config", "c.yaml"] + script = _script_with_groups(groups, command=command) + assert script == _script(0, command) + assert _uv_run_args(script) == command + tokens = shlex.split(script) + assert "--no-group" not in tokens + assert "--frozen" not in tokens + assert "--frozen" not in _log_display_words(script) + + @pytest.mark.parametrize("groups", [["remote"], ["remote", "dev.tools"], ["a", "b", "c", "d"]]) + def test_frozen_appears_exactly_once(self, groups: list[str]) -> None: + """SPEC_02「`exclude_groups` の書き方」: グループがいくつでも `--frozen` は 1 回だけ.""" + script = _script_with_groups(groups) + args = _uv_run_args(script) + assert args.count("--frozen") == 1 + assert args.index("--frozen") == 0 + assert args.count("--no-group") == len(groups) + assert _log_display_words(script).count("--frozen") == 1 def test_no_group_in_user_command_stays_in_command(self) -> None: """SPEC_02「`exclude_groups` の書き方」: コマンド本体の `--no-group` は本体の側に残る.""" command = ["demo-train", "--no-group", "x"] args = _uv_run_args(_script_with_groups(["remote"], command=command)) - assert args == ["--no-group", "remote", *command] + assert args == ["--frozen", "--no-group", "remote", *command] + + @pytest.mark.parametrize("groups", [["remote"], []]) + def test_frozen_in_user_command_stays_in_command(self, groups: list[str]) -> None: + """SPEC_02「`exclude_groups` の書き方」. + + コマンド本体の `--frozen` は本体の側に残る(uv run の側の `--frozen` は, + `exclude_groups` の有無だけで決まる). + """ + command = ["demo-train", "--frozen"] + args = _uv_run_args(_script_with_groups(groups, command=command)) + expected_options = ["--frozen", "--no-group", "remote"] if groups else [] + assert args == [*expected_options, *command] @pytest.mark.parametrize("gpu_index", [0, None]) def test_added_for_gpu_and_cpu_jobs(self, gpu_index: int | None) -> None: """SPEC_02「`exclude_groups` の書き方」: `--cpu` のジョブにも同じように付く.""" args = _uv_run_args(_script_with_groups(["remote"], gpu_index=gpu_index)) - assert args[:2] == ["--no-group", "remote"] + assert args[:3] == ["--frozen", "--no-group", "remote"] @pytest.mark.parametrize("groups", [["remote"], ["remote", "dev.tools"], []]) def test_log_header_display_matches_actual_command(self, groups: list[str]) -> None: