Skip to content

Enhance SRI script robustness and refine Restaurant docs#265

Merged
myoshi2891 merged 1 commit into
mainfrom
dev-from-macmini
Feb 11, 2026
Merged

Enhance SRI script robustness and refine Restaurant docs#265
myoshi2891 merged 1 commit into
mainfrom
dev-from-macmini

Conversation

@myoshi2891

Copy link
Copy Markdown
Owner

No description provided.

@coderabbitai

coderabbitai Bot commented Feb 11, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Summary by CodeRabbit

リリースノート

  • ドキュメント

    • コード例をより読みやすく、簡潔なスタイルに更新しました。
  • 改善

    • スクリプトの堅牢性を向上させました。ダウンロード失敗の適切なハンドリング、レスポンス検証、リソースのクリーンアップ機能を強化しました。

Walkthrough

このプルリクエストは、Markdownドキュメントの説明文を簡潔に更新し、シェルスクリプトの信頼性を強化しています。calc_sri_fix.shに厳密なシェルオプションとエラーハンドリングを追加し、HTTPダウンロードの失敗に対する耐性を向上させました。

Changes

Cohort / File(s) Summary
Documentation Updates
Mathematics/Fundamentals/HackerRank/Claude/Easy/Restaurant/Restaurant.md
TYPE_CHECKING インポートを削除し、可読性と簡潔性に関する説明コメントを更新。アルゴリズムの動作に変更はなし。
Shell Script Hardening
calc_sri_fix.sh
strict オプション (set -euo pipefail) を追加、一時ファイルへのダウンロード機構を実装、ダウンロード失敗とレスポンス検証エラーハンドリングを強化、確実なクリーンアップフローを追加。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 ダウンロード失敗に備えて、
一時ファイルで受け止める知恵よ。
エラーハンドリング、しっかり記述、
スクリプトの信頼、ぐんと向上!
小さな改善、大きな安定。 ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive プルリクエストの説明が提供されていないため、変更内容との関連性を評価できません。 変更内容を説明するプルリクエスト説明を追加してください。最低限、SRIスクリプトの改善点とRestaurantドキュメントの変更理由を記載することをお勧めします。
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed プルリクエストのタイトルは、変更セットの主な内容(SRIスクリプトの堅牢性向上とRestaurantドキュメントの改善)を適切に反映しています。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev-from-macmini

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@calc_sri_fix.sh`:
- Around line 7-25: The temporary file created in this function (temp_file via
mktemp) can leak if a command like the openssl pipeline fails under set -e; add
a trap at the start of the function to ensure rm -f "$temp_file" runs on
function exit (use trap 'rm -f "$temp_file"' RETURN for Bash 4+ or trap 'rm -f
"$temp_file"' EXIT at script top-level for wider compatibility), then remove the
final explicit rm -f "$temp_file" or keep it as a no-op; apply the change around
the block that downloads with curl and computes the hash (the temp_file variable
and the openssl dgst ... | openssl base64 -A pipeline).
- Line 3: The strict shell mode (set -euo pipefail) can leave the temp file
behind if openssl in the pipeline fails; inside the calculate_sri function, add
a cleanup trap so the temp file is always removed on function exit (e.g., trap
"rm -f \"$temp_file\"" RETURN placed at the top of calculate_sri), ensure
temp_file is defined before the trap is set, and keep the existing rm -f
"$temp_file" at the end for normal-path cleanup.

Comment thread calc_sri_fix.sh
@@ -1,9 +1,28 @@
#!/bin/bash

set -euo pipefail

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cat calc_sri_fix.sh

Repository: myoshi2891/Algorithm-DataStructures-Math-SQL

Length of output: 948


set -euo pipefail の追加により、厳格なシェルモードが有効になりました。

-e オプションによるエラー発生時の即座の終了は、スクリプトの堅牢性を向上させます。Line 28 の calculate_sri が失敗した場合、スクリプト全体が終了し Line 29 の呼び出しが実行されないのは、エラー時の適切なフェイルファーストの動作です。

ただし、重要な問題として、Line 23 のパイプライン内で openssl コマンドが失敗した場合、set -e により即座にスクリプトが終了するため、Line 25 の rm -f "$temp_file" が実行されず、一時ファイルがクリーンアップされないままになります。 この問題を解決するには、関数内で以下のようなトラップを設定してください:

trap "rm -f \"$temp_file\"" RETURN

このトラップを関数の先頭に追加することで、予期しない終了時にも一時ファイルが確実にクリーンアップされます。

🤖 Prompt for AI Agents
In `@calc_sri_fix.sh` at line 3, The strict shell mode (set -euo pipefail) can
leave the temp file behind if openssl in the pipeline fails; inside the
calculate_sri function, add a cleanup trap so the temp file is always removed on
function exit (e.g., trap "rm -f \"$temp_file\"" RETURN placed at the top of
calculate_sri), ensure temp_file is defined before the trap is set, and keep the
existing rm -f "$temp_file" at the end for normal-path cleanup.

Comment thread calc_sri_fix.sh
Comment on lines +7 to +25
temp_file=$(mktemp)

# curl options: -f (fail on HTTP error), -S (show error), -s (silent equivalent), -L (follow redirects)
if ! curl -fS -sL "$url" -o "$temp_file"; then
echo "Error downloading $url" >&2
rm -f "$temp_file"
return 1
fi

# Check for empty response
if [ ! -s "$temp_file" ]; then
echo "Error: Empty response from $url" >&2
rm -f "$temp_file"
return 1
fi

hash=$(openssl dgst -sha384 -binary < "$temp_file" | openssl base64 -A)
echo "$url sha384-$hash"
rm -f "$temp_file"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

一時ファイルのクリーンアップに trap の使用を推奨します。

Line 23 の openssl コマンドが失敗した場合、set -e によりスクリプトが即座に終了し、Line 25 の rm -f "$temp_file" が実行されずに一時ファイルがリークします。関数冒頭で trap を設定することで、異常終了時も確実にクリーンアップできます。

🛡️ trap を使った修正案
 calculate_sri() {
     url="$1"
     temp_file=$(mktemp)
+    trap 'rm -f "$temp_file"' RETURN
 
     # curl options: -f (fail on HTTP error), -S (show error), -s (silent equivalent), -L (follow redirects)
     if ! curl -fS -sL "$url" -o "$temp_file"; then
         echo "Error downloading $url" >&2
-        rm -f "$temp_file"
         return 1
     fi
 
     # Check for empty response
     if [ ! -s "$temp_file" ]; then
         echo "Error: Empty response from $url" >&2
-        rm -f "$temp_file"
         return 1
     fi
 
     hash=$(openssl dgst -sha384 -binary < "$temp_file" | openssl base64 -A)
     echo "$url sha384-$hash"
-    rm -f "$temp_file"
 }

注意: trap ... RETURN は Bash 4.0+ で利用可能です。もし互換性が必要な場合は、trap ... EXIT をスクリプトのトップレベルで設定するか、各パスでの手動 rm を維持しつつ openssl 行を if で囲む方法も有効です。

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
temp_file=$(mktemp)
# curl options: -f (fail on HTTP error), -S (show error), -s (silent equivalent), -L (follow redirects)
if ! curl -fS -sL "$url" -o "$temp_file"; then
echo "Error downloading $url" >&2
rm -f "$temp_file"
return 1
fi
# Check for empty response
if [ ! -s "$temp_file" ]; then
echo "Error: Empty response from $url" >&2
rm -f "$temp_file"
return 1
fi
hash=$(openssl dgst -sha384 -binary < "$temp_file" | openssl base64 -A)
echo "$url sha384-$hash"
rm -f "$temp_file"
temp_file=$(mktemp)
trap 'rm -f "$temp_file"' RETURN
# curl options: -f (fail on HTTP error), -S (show error), -s (silent equivalent), -L (follow redirects)
if ! curl -fS -sL "$url" -o "$temp_file"; then
echo "Error downloading $url" >&2
return 1
fi
# Check for empty response
if [ ! -s "$temp_file" ]; then
echo "Error: Empty response from $url" >&2
return 1
fi
hash=$(openssl dgst -sha384 -binary < "$temp_file" | openssl base64 -A)
echo "$url sha384-$hash"
🤖 Prompt for AI Agents
In `@calc_sri_fix.sh` around lines 7 - 25, The temporary file created in this
function (temp_file via mktemp) can leak if a command like the openssl pipeline
fails under set -e; add a trap at the start of the function to ensure rm -f
"$temp_file" runs on function exit (use trap 'rm -f "$temp_file"' RETURN for
Bash 4+ or trap 'rm -f "$temp_file"' EXIT at script top-level for wider
compatibility), then remove the final explicit rm -f "$temp_file" or keep it as
a no-op; apply the change around the block that downloads with curl and computes
the hash (the temp_file variable and the openssl dgst ... | openssl base64 -A
pipeline).

@myoshi2891 myoshi2891 merged commit 2c2282e into main Feb 11, 2026
1 check 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