Skip to content

Fix silent failures: dry-run commit, undefined RELEASE_BASE, unchecked download#30

Merged
toshi0806 merged 3 commits into
mainfrom
issue-29-fix-silent-failures
Jun 12, 2026
Merged

Fix silent failures: dry-run commit, undefined RELEASE_BASE, unchecked download#30
toshi0806 merged 3 commits into
mainfrom
issue-29-fix-silent-failures

Conversation

@toshi0806

Copy link
Copy Markdown
Member

resolve #29

修正内容

1. git commit --porcelain の削除(重大バグ)

--porcelaingit commit では dry-run を意味するため、「add LaTeX environment」コミットは実際には一度も作成されていなかった(変更はステージされたまま)。フラグを削除し、コミットが実際に作成されるようにした。

2. 未定義変数 RELEASE_BASE の修正

rm -rf ${RELEASE_BASE} は空文字に展開され、展開済みの latex-environment-release/ ディレクトリが削除されずに残っていた。"${REPOSITORY_NAME}-${BRANCH}" に修正。

3. ダウンロード系のエラーハンドリング追加

curl-f を追加し、curl / unzip / cd の失敗時に stderr へ明確なエラーメッセージを出して exit 1 するようにした。従来はダウンロード失敗後も処理が継続し、分かりにくいエラーになっていた。

テスト結果

  • bash -n: 構文 OK
  • ✅ shellcheck: 修正前に存在した SC2164(cd 失敗未処理)が解消、新規警告なし(残存警告は既存・本 PR 対象外)
  • ✅ 正常系: 一時ディレクトリで実行 → 「add LaTeX environment」コミットが実際に作成されることを確認、残骸ディレクトリ無し、作業ツリークリーン
  • ✅ 異常系: 存在しないブランチ URL で実行 → Error: failed to download LaTeX environment from ... を表示し exit 1

🤖 Generated with Claude Code

- Remove --porcelain from git commit: the flag implies a dry-run,
  so the 'add LaTeX environment' commit was never actually created
- Replace undefined RELEASE_BASE with REPOSITORY_NAME-BRANCH so the
  extracted directory is cleaned up after integration
- Add error handling for curl (-f), unzip, and cd so download or
  extraction failures stop the script with a clear error message
Copilot AI review requested due to automatic review settings June 12, 2026 15:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PRの修正内容は全体的に正確で重要なバグを修正しています。特に --porcelain フラグの削除と未定義変数 RELEASE_BASE の修正は重大なバグ修正です。いくつか追加で検討すべき点を指摘します。

Comment thread aldc Outdated
@@ -117,14 +127,14 @@ for i in $(find . -type f); do
done

cd ..

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 [HIGH] cd .. はエラーハンドリングがなく、shellcheckでもSC2164として警告される可能性があります。cd .. が失敗した場合、続く rm -rf "${REPOSITORY_NAME}-${BRANCH}" が予期しないディレクトリに対して実行されるリスクがあります。

cd .. || { echo "Error: failed to return to parent directory" >&2; exit 1; }

とすることを強く推奨します。

Comment thread aldc Outdated
rm -f "${ZIP_NAME}"
exit 1
fi
rm "${ZIP_NAME}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [MEDIUM] rm -f "${ZIP_NAME}" はunzip失敗時のクリーンアップとして追加されていますが、rm "${ZIP_NAME}" (成功時)はエラーハンドリングがありません。一貫性のため、成功時も rm -f "${ZIP_NAME}" とするか、失敗時に exit 1 する前に rm が失敗した場合の処理を考慮してください。

また、cd .. (119行目付近) の後の rm -rf "${REPOSITORY_NAME}-${BRANCH}" も、cd が失敗した場合に意図しないディレクトリを削除するリスクがあります。cd .. にも || { echo ... >&2; exit 1; } を追加することを推奨します。

- Add error handling to 'cd ..' so rm -rf never runs in an
  unexpected directory if the cd fails (review HIGH)
- Use rm -f for the zip on the success path for consistency with
  the failure-path cleanup (review MEDIUM)

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このPRは3つの重大なバグを修正しており、全体的に正しい方向性です。ただし、いくつか検討すべき点があります。

Comment thread aldc

cd ..
rm -rf ${RELEASE_BASE}
cd .. || {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [MEDIUM] ### cd .. の失敗ハンドリングについて

cd .. が失敗するケースは実質的にほぼ存在しません(親ディレクトリが消えるなど極めて異常な状況)。それよりも問題なのは、cd でサブディレクトリに移動した後にエラーが発生した場合(例:ファイル除外処理中の失敗)、cd .. に到達せずスクリプトが終了し、呼び出し元のカレントディレクトリが変わったまま残る可能性があることです。

より堅牢な設計として、cd でのディレクトリ移動の代わりに絶対パスを使用するか、pushd/popd を使用するか、あるいはサブシェル ( cd "${REPOSITORY_NAME}-${BRANCH}" && ... ) で処理を囲む方法を検討してください。

Comment thread aldc Outdated
if [ "$QUIET" = "false" ]; then
git add .
git commit --quiet --porcelain -m "add LaTeX environment"
git commit --quiet -m "add LaTeX environment"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ [LOW] ### --porcelain フラグ削除(重大バグ修正)

git commit --porcelain はdry-runとして機能するため、コミットが一度も作成されていなかったという重大なバグの修正です。この修正は正しいです。

ただし、git add 後に変更がない場合(例:LaTeX環境のファイルが既に存在する場合)、git commit は非ゼロの終了コードを返します。QUIET=false の場合はスクリプトがそこで止まる可能性があります(set -e が有効な場合)。git diff --cached --quiet || git commit --quiet -m "add LaTeX environment" のように、コミットが必要な場合のみ実行する形も検討してください。

Comment thread aldc
fi
if ! unzip -q "${ZIP_NAME}"; then
echo "Error: failed to extract ${ZIP_NAME}" >&2
rm -f "${ZIP_NAME}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ [LOW] ### unzip 失敗時の rm -f について

unzip 失敗時に rm -f "${ZIP_NAME}" でZIPファイルを削除してから exit 1 しています。これは適切なクリーンアップですが、curl 失敗時(ファイルが存在しない、または不完全な場合)には rm -f が実行されません。curl 失敗時にも念のため rm -f "${ZIP_NAME}" を追加することを検討してください(-f フラグがあっても部分的なファイルが残る場合があります)。

@toshi0806

Copy link
Copy Markdown
Member Author

レビュー指摘 2 件に af6bec7 で対応しました。

対応内容

🚨 HIGH: cd .. のエラーハンドリング欠如

cd .. 失敗時に rm -rf が予期しないディレクトリで実行されるリスクへの指摘。以下のとおりガードを追加:

cd .. || {
    echo "Error: failed to return to parent directory" >&2
    exit 1
}

shellcheck でも SC2164 が出ないことを確認済み。

⚠️ MEDIUM: rm "${ZIP_NAME}" の一貫性

成功パスも失敗パスと同じ rm -f "${ZIP_NAME}" に統一。

再検証

  • bash -n: 構文 OK
  • ✅ shellcheck: SC2164 検出ゼロ
  • ✅ 機能テスト再実行: 「add LaTeX environment」コミット作成・残骸ディレクトリ無しを再確認

- Remove possibly partial zip when curl fails (review LOW)
- Only run git commit when there are staged changes, avoiding a
  confusing 'nothing to commit' failure (review LOW)
Copilot AI review requested due to automatic review settings June 12, 2026 21:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@toshi0806

Copy link
Copy Markdown
Member Author

再レビューの指摘 3 件に対応しました(eabe81e)。

対応した指摘

ℹ️ LOW: curl 失敗時の部分ファイル

curl 失敗時の分岐に rm -f "${ZIP_NAME}" を追加し、部分的にダウンロードされたファイルが残らないようにしました。

ℹ️ LOW: 変更が無い場合の git commit 失敗

git diff --cached --quiet || git commit ... の形に変更し、ステージされた変更がある場合のみコミットするようにしました。

見送った指摘(理由)

⚠️ MEDIUM: cd .. の代わりにサブシェル/絶対パスを使う設計

今回は見送ります。理由:

  1. 本スクリプトは bash -c "$(curl ...)"子プロセスとして実行されるため、スクリプトが途中終了しても呼び出し元シェルのカレントディレクトリには影響しません
  2. サブディレクトリ内に居る区間(除外処理〜統合ループ)には exit する経路が無く、「cd .. に到達せず終了」は発生しません
  3. 統合ループはサブシェル化すると backups 変数が親に伝播せず、バックアップ通知機能が壊れるため、変更コストに見合いません

直前のコミットで cd .. 自体には失敗時ガードを追加済みです。

再検証

  • bash -n 構文 OK
  • ✅ 機能テスト: 初回実行・再実行(.devcontainer 削除後)ともコミット作成と終了コード 0 を確認

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

全体的に重要なバグ修正が適切に行われています。特に --porcelain フラグの削除と RELEASE_BASE の修正は重大な問題の解消です。いくつか気になる点を指摘します。

Comment thread aldc

cd ..
rm -rf ${RELEASE_BASE}
cd .. || {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [MEDIUM] [MEDIUM] cd .. の失敗ハンドリングは実質的に不要

cd .. は通常のファイルシステムでは失敗しません(親ディレクトリは常に存在する)。一方で、もし何らかの理由で失敗した場合、その後の rm -rf "${REPOSITORY_NAME}-${BRANCH}" が誤ったディレクトリで実行される危険性があります。

より安全な実装として、cd に依存せず絶対パスや変数でディレクトリを管理する方法を検討してください。例えば、展開先ディレクトリを変数に保存しておき、処理後に rm -rf "${WORK_DIR}" のように絶対パスで削除する方が堅牢です。

Comment thread aldc
if [ "$QUIET" = "false" ]; then
git add .
git commit --quiet --porcelain -m "add LaTeX environment"
git diff --cached --quiet || git commit --quiet -m "add LaTeX environment"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ [LOW] [LOW] git diff --cached --quiet によるステージング確認の意図が不明確

git diff --cached --quiet でステージされた変更がない場合にコミットをスキップする実装になっています。これは「何も変更がなければコミットしない」という意図だと思われますが、git add . の直後にステージされた変更がない状況(=LaTeX環境のファイルが一切追加・変更されなかった)は、むしろ異常系として扱うべきではないでしょうか。

サイレントにスキップするのではなく、警告メッセージを出力することを検討してください:

if git diff --cached --quiet; then
    echo "Warning: no changes to commit after adding LaTeX environment" >&2
else
    git commit --quiet -m "add LaTeX environment"
fi

@toshi0806

Copy link
Copy Markdown
Member Author

eabe81e に対する再レビュー 2 件は、いずれもコード変更なしで見送りとします。

⚠️ MEDIUM: 「cd .. の失敗ハンドリングは実質的に不要、絶対パス管理へ」

cd .. のガードは初回レビューの 🚨 HIGH 指摘(r3404407740)に従って追加したものです。失敗がほぼ起き得ない点は同意ですが、ガードはコストゼロで「万一失敗した場合に誤ったディレクトリで rm -rf が走る」リスク(初回 HIGH が指摘したリスクそのもの)を塞ぐため、残します。絶対パス/サブシェルへの再設計は、統合ループの backups 変数伝播を壊さずに行うには変更範囲が本 issue のスコープを超えるため、見送ります(必要なら別 issue で)。

ℹ️ LOW: 「変更なし時にサイレントスキップせず警告を」

git diff --cached --quiet || git commit ... は前回レビュー(r3404475560)の提案どおりの実装です。コミット対象が無いケースは「.devcontainer を手動復元した後の再実行」のような良性の再実行シナリオに限られ(通常の再実行は冒頭の .devcontainer 存在チェックで早期終了)、setup.sh 等の自動化からの利用では余計な stderr 出力がノイズになるため、現状の挙動を維持します。


CI は ✅ success。3 コミット(c0c0196 / af6bec7 / eabe81e)で issue #29 の 3 バグ修正と妥当なレビュー指摘への対応が完了しています。人間レビューをお願いします。

@toshi0806
toshi0806 merged commit 248b4b1 into main Jun 12, 2026
1 check passed
@toshi0806
toshi0806 deleted the issue-29-fix-silent-failures branch June 12, 2026 22:04
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.

Fix silent failures: git commit --porcelain is a dry-run, undefined RELEASE_BASE, unchecked curl

2 participants