Skip to content

fix(compliance-audit): replace echo|grep -q pipes with here-strings in detect_ecosystems#249

Merged
don-petry merged 2 commits into
mainfrom
fix/broken-pipe-detect-ecosystems
May 12, 2026
Merged

fix(compliance-audit): replace echo|grep -q pipes with here-strings in detect_ecosystems#249
don-petry merged 2 commits into
mainfrom
fix/broken-pipe-detect-ecosystems

Conversation

@don-petry
Copy link
Copy Markdown
Contributor

@don-petry don-petry commented May 12, 2026

Problem

detect_ecosystems() in scripts/compliance-audit.sh uses the pattern:

echo "$tree" | grep -qE '...'

When $tree is large (repos with many files), grep -q exits immediately after the first match, closing the read end of the pipe. The echo subprocess is still writing and receives SIGPIPE, producing:

scripts/compliance-audit.sh: line 153: echo: write error: Broken pipe
scripts/compliance-audit.sh: line 159: echo: write error: Broken pipe

Fix

Replace all 8 echo "$tree" | grep -qE calls with bash here-strings:

grep -qE '...' <<< "$tree"

A here-string feeds the variable directly to grep's stdin with no subprocess pipe — no SIGPIPE is possible regardless of the size of $tree.

Affected lines

Line Pattern
130 package.json (npm)
133 pnpm-lock.yaml (pnpm)
141 go.mod (go)
144 Cargo.toml (rust)
147 pyproject.toml / requirements.txt (python)
150 *.tf (terraform)
153 .github/workflows/*.yml (github-actions) ← reported error
159 _bmad(-output)?/ (bmad-method) ← reported error

Summary by CodeRabbit

  • Refactor
    • Optimized internal compliance audit script with streamlined ecosystem detection logic for improved performance.

Review Change Stack

echo "$tree" | grep -q exits early on first match (grep -q),
closing the read end of the pipe before echo finishes writing when
$tree is large. This causes SIGPIPE / "write error: Broken pipe".

Replace all 8 occurrences with grep -qE ... <<< "$tree" which feeds
the string directly to grep's stdin without a subprocess pipe.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@don-petry don-petry requested a review from a team as a code owner May 12, 2026 02:50
Copilot AI review requested due to automatic review settings May 12, 2026 02:50
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

Warning

Rate limit exceeded

@don-petry has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 48 minutes and 58 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: c8957bf4-07a5-475d-acd8-0ba1cfd0711d

📥 Commits

Reviewing files that changed from the base of the PR and between 3403601 and 200aedd.

📒 Files selected for processing (1)
  • scripts/compliance-audit.sh
📝 Walkthrough

Walkthrough

The detect_ecosystems() function in the compliance-audit script is refactored to use POSIX here-string syntax with grep instead of piping echo output. Detection patterns for seven ecosystems (npm, go, rust, python, terraform, github-actions, BMAD) remain functionally identical.

Changes

Ecosystem Detection Refactoring

Layer / File(s) Summary
Ecosystem-marker detection refactoring
scripts/compliance-audit.sh
Ecosystem checks for npm/pnpm, go, rust, python, terraform, github-actions, and BMAD directories refactored from echo "$tree" | grep -qE ... to grep -qE ... <<< "$tree" syntax. Detection logic and patterns are unchanged.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: replacing echo|grep pipes with here-strings in the detect_ecosystems function.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/broken-pipe-detect-ecosystems

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[bot]
coderabbitai Bot previously approved these changes May 12, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the detect_ecosystems function in scripts/compliance-audit.sh to use Bash here-strings instead of piping echo to grep, which is a more efficient way to process the file tree variable. The review feedback suggests improving the robustness of the GitHub Actions detection by updating the regular expression to support both .yml and .yaml file extensions.

Comment thread scripts/compliance-audit.sh Outdated
Copy link
Copy Markdown
Contributor

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 updates detect_ecosystems() in scripts/compliance-audit.sh to avoid SIGPIPE/“Broken pipe” noise caused by echo "$tree" | grep -qE ... when scanning very large repository trees, by switching those checks to grep ... <<< "$tree".

Changes:

  • Replaced 8 instances of echo "$tree" | grep -qE ... with grep -qE ... <<< "$tree" inside detect_ecosystems().
  • Preserved existing ecosystem-detection regexes and behavior while eliminating the pipe that can trigger echo write errors.

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

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@don-petry don-petry merged commit fea867c into main May 12, 2026
12 checks passed
@don-petry don-petry deleted the fix/broken-pipe-detect-ecosystems branch May 12, 2026 03:02
@sonarqubecloud
Copy link
Copy Markdown

don-petry added a commit that referenced this pull request May 13, 2026
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
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.

2 participants