Skip to content

Conversation

@aaronliu0130
Copy link
Member

@aaronliu0130 aaronliu0130 commented Apr 24, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved signal handling so temporary output files are reliably cleaned up if the script is interrupted.
  • Refactor

    • Centralized temporary-file cleanup into a single routine and updated how the linting command is invoked to integrate with that cleanup flow.

✏️ Tip: You can customize this high-level summary in your review settings.

@aaronliu0130 aaronliu0130 requested a review from cclauss April 24, 2025 00:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds signal handling to the regen-defs.zsh script to clean up temporary files when interrupted, and uses eval to fix glob expansion in cpplint commands. The script processes .def test fixture files that contain cpplint commands with glob patterns (like src/*) and their expected outputs.

  • Added trap handler for INT and TERM signals to clean up temporary files on interruption
  • Changed command execution to use eval to properly expand glob patterns in the commands
  • Refactored cleanup logic into a dedicated function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


# Clean up temporary files
rm "$stdout_file" "$stderr_file"
cleanup
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

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

The cleanup function is only called on successful completion of a loop iteration (line 51), but not when errors occur earlier. If uv run fails or if any operation between lines 23-48 causes the script to exit, the temporary files will not be cleaned up.

Additionally, the trap handler won't catch normal exit conditions (like the exit calls on lines 6 and 11). Consider:

  1. Adding EXIT to the trap signals: trap cleanup INT TERM EXIT
  2. Moving the trap setup earlier in the script to catch early exits

Note: If you add EXIT to the trap, you may need to prevent double-cleanup on line 51.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think a command in between can cause termination of the entire script, and as mentioned trapping EXIT can get a bit messy.

Copy link

Copilot AI commented Nov 28, 2025

@aaronliu0130 I've opened a new pull request, #415, to work on those changes. Once the pull request is ready, I'll request review from you.

I do not think "attackers controlling .def content" is a plausible scenario, but this does seem to be the better tool for the job.
@coderabbitai
Copy link

coderabbitai bot commented Nov 28, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds a cleanup function and installs an INT/TERM trap to remove temporary stdout/stderr files; switches cpplint invocation to use an evaluated/executed command line; replaces direct rm calls with the new cleanup function across the script.

Changes

Cohort / File(s) Change Summary
Signal handling, cleanup, and cpplint invocation
regen-defs.zsh
Adds a cleanup function to remove temp stdout/stderr files and installs a trap for INT and TERM; replaces direct rm calls with cleanup invocations; runs cpplint via eval (or equivalent) to incorporate the extracted command line/arguments.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10–15 minutes

  • Verify the evaluated cpplint command preserves quoting/argument separation and does not introduce shell injection risks.
  • Confirm the trap fires and cleanup runs on SIGINT/SIGTERM and that all temp files are removed for all exit paths.
  • Check there are no remaining code paths that call rm directly on the same temp files.

Poem

🐰 I hopped in the shell with a tidy design,
I trap every signal and clear every line.
Temp files are gone with a small, graceful sweep,
cpplint runs tidy — the codebase can sleep. ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: fixing globs and adding proper cleanup of temporary files on INT/TERM signals.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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 tempreglob

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b32e1f3 and 7abe1d2.

📒 Files selected for processing (1)
  • regen-defs.zsh (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build-test (3.x, windows-latest)
  • GitHub Check: build-test (3.10, windows-latest)
🔇 Additional comments (2)
regen-defs.zsh (2)

51-51: Cleanup function call is well-placed.

Calling cleanup after successful iteration completion ensures temp files are removed on the normal (non-signal) path. Combined with the trap handler, this provides cleanup in both success and interruption scenarios.


33-33: Zsh syntax ${(~)cmd} is correct for enabling glob and tilde expansion.

The syntax ${(~)cmd} is indeed the correct zsh parameter expansion flag for enabling GLOB_SUBST. This causes the expanded variable value to undergo glob pattern matching and tilde expansion—wildcards and ~ characters in the .def file's first line will be expanded as patterns before being passed to uv run "$cpplint".

This aligns with the PR objective to fix globbing. However, the security concern you raised is legitimate: since .def file content is read directly without validation (line 20) and then expanded with glob patterns enabled (line 33), any glob patterns in .def files will be evaluated by the shell. This is safe only if .def files are from trusted sources. If .def files can be supplied by untrusted users, consider adding validation or escaping mechanisms to prevent unintended pattern expansion.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
regen-defs.zsh (2)

26-30: Add -f flag to rm for idempotent cleanup.

The cleanup function should use rm -f instead of plain rm to prevent errors if the temporary files don't exist and to make cleanup idempotent. This is especially important for signal handlers, which may be invoked at unexpected times.

Apply this diff:

-    cleanup() {
-      rm "$stdout_file" "$stderr_file"
-    }
+    cleanup() {
+      rm -f "$stdout_file" "$stderr_file"
+    }

This aligns with the best practice discussed in prior review feedback for robust cleanup handlers.


33-33: Add a security note documenting that .def files must be trusted.

Using eval to execute the command line extracted from .def files requires that those files remain under your control. If a .def file is compromised or maliciously modified, arbitrary code could execute. While this is a developer-internal tool and .def files are repo-controlled, it's good practice to document this assumption.

Apply this diff to add a clarifying comment:

+    # Note: eval is used to enable glob expansion. .def files must be trusted;
+    # do not run this script on untrusted .def file input.
     eval uv run "$cpplint" $cmd > "$stdout_file" 2> "$stderr_file"
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7abe1d2 and e12e484.

📒 Files selected for processing (1)
  • regen-defs.zsh (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build-test (3.10, windows-latest)
  • GitHub Check: build-test (3.x, windows-latest)

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.

3 participants