Skip to content

GH#3711: Fix critical quality-debt in codacy-collector-helper.sh#4067

Merged
marcusquinn merged 1 commit intomainfrom
bugfix/codacy-collector-quality-debt
Mar 10, 2026
Merged

GH#3711: Fix critical quality-debt in codacy-collector-helper.sh#4067
marcusquinn merged 1 commit intomainfrom
bugfix/codacy-collector-quality-debt

Conversation

@marcusquinn
Copy link
Copy Markdown
Owner

@marcusquinn marcusquinn commented Mar 10, 2026

Summary

Addresses all 13 findings from PR #1384 review feedback (coderabbit, gemini-code-assist, human reviewers) on .agents/scripts/codacy-collector-helper.sh.

Closes #3711

Changes

CRITICAL

  • SQL injection via --limit: Validate as positive integer (1-10000) before interpolation into SQL
  • CWD-dependent config paths: Anchor AUDIT_CONFIG and AUDIT_CONFIG_TEMPLATE to REPO_ROOT (derived from SCRIPT_DIR) instead of relative paths that break when invoked from non-repo CWD

HIGH

  • Unsafe JSON body construction: Use jq -nc with --arg/--argjson to build cursor pagination request body safely
  • No transaction wrapper: Wrap batch INSERT statements in BEGIN TRANSACTION/COMMIT for atomicity and performance (single fsync)
  • Rate-limit retries consume error budget: 429 responses now use a separate retry counter (max 5) and decrement the attempt counter so they don't consume the 3-attempt error budget

MEDIUM

  • Dead code + system tmpdir: Remove unused tmp_headers allocation and -D curl arg; use ~/.aidevops/.agent-workspace/tmp/ for all temp files
  • ShellCheck SC2155: Separate declare and assign for REPO_ROOT readonly

Already fixed (verified present from b0c77ce)

  • ${MAX_RETRIES:-3} defaults throughout
  • ${ERROR_UNKNOWN_COMMAND:-Unknown command:} default
  • Severity/category input validation with case statements

Verification

  • shellcheck -x passes (only SC1091 info for external source, expected)
  • All 13 findings from the issue addressed

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved API rate-limit error handling with dedicated retry management to prevent request failures
    • Enhanced transaction safety for database operations
  • Improvements

    • Configuration paths now resolve correctly regardless of working directory
    • Refined temporary file management for API interactions
    • Added stricter input validation for query parameters

…3711)

Address all 13 findings from PR #1384 review feedback (coderabbit,
gemini-code-assist, human reviewers):

CRITICAL:
- Anchor AUDIT_CONFIG paths to REPO_ROOT instead of relative CWD paths
- Validate --limit as positive integer (max 10000) to prevent SQL injection

HIGH:
- Use jq to build JSON request body safely (cursor escaping)
- Wrap batch inserts in BEGIN/COMMIT transaction for atomicity + performance
- Rate-limit retries (429) use separate budget, don't consume error retries

MEDIUM:
- Remove dead tmp_headers allocation and -D curl arg
- Use workspace tmp dir (~/.aidevops/.agent-workspace/tmp/) for all temp files
- Fix SC2155: separate declare and assign for REPO_ROOT

Previously fixed in b0c77ce (verified still present):
- ${MAX_RETRIES:-3} defaults throughout
- ${ERROR_UNKNOWN_COMMAND:-Unknown command:} default
- Severity/category input validation with case statements
@github-actions github-actions bot added the bug Auto-created from TODO.md tag label Mar 10, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 10, 2026

Walkthrough

This change refactors .agents/scripts/codacy-collector-helper.sh to address code review findings by anchoring config paths to repository root, improving temporary file handling with dedicated workspace directories, enhancing 429 rate-limit retry logic with separate budgets, replacing string interpolation with jq for JSON construction, wrapping database inserts in transactions, and adding stricter input validation.

Changes

Cohort / File(s) Summary
Config path anchoring & temp file refactoring
.agents/scripts/codacy-collector-helper.sh
Introduced REPO_ROOT variable to anchor AUDIT_CONFIG and AUDIT_CONFIG_TEMPLATE paths for CWD-independent resolution; replaced generic temp file usage with dedicated ~/.aidevops/.agent-workspace/tmp directory and per-run mktemp paths; removed unused tmp_headers file and isolated tmp_response cleanup.
API retry & rate-limit handling
.agents/scripts/codacy-collector-helper.sh
Separated 429 rate-limit handling from general retry logic using rate_limit_retries and max_rate_limit_retries budgets; preserved main retry semantics by decrementing attempts only on non-429 errors; added detailed rate-limit context to log messages.
JSON pagination & SQL transaction improvements
.agents/scripts/codacy-collector-helper.sh
Replaced manual JSON string interpolation with jq for safe cursor escaping in pagination requests; wrapped SQL batch inserts in BEGIN TRANSACTION/COMMIT blocks for improved atomicity and performance; enhanced temp file handling consistency.
Input validation hardening
.agents/scripts/codacy-collector-helper.sh
Added strict --limit validation in cmd_query to enforce positive integer range (1–10000) with explicit error messaging.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • #1384 — Initial codacy-collector-helper.sh implementation that introduced pagination, rate-limit handling, and database insertion logic being refined in this PR.

Poem

🛡️ Shell scripts fortified with safety and grace,
Config paths anchored to their proper place,
Retries and rate-limits now wisely depart,
Transactions guard databases close to the heart,
jq's gentle hand escapes what strings could break—
Zero debt maintained, for quality's sake! ✨

🚥 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 clearly identifies the primary change as fixing critical quality debt in codacy-collector-helper.sh, directly corresponding to the main objective of resolving 13 code-review findings from PR #1384.
Linked Issues check ✅ Passed The changeset comprehensively addresses all 13 findings from issue #3711: SQL injection prevention via --limit validation [#3711], safe JSON construction with jq [#3711], transaction-wrapped INSERTs [#3711], separated 429 retry budgeting [#3711], repo-root anchored config paths [#3711], improved temp-file handling [#3711], and safe defaults for set -u resilience [#3711].
Out of Scope Changes check ✅ Passed All changes are directly scoped to codacy-collector-helper.sh and directly address the objectives outlined in issue #3711; no unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/codacy-collector-quality-debt

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.

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Code Quality Report

�[0;35m[MONITOR]�[0m Code Review Monitoring Report

�[0;34m[INFO]�[0m Latest Quality Status:
SonarCloud: 0 bugs, 0 vulnerabilities, 396 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Tue Mar 10 10:47:37 UTC 2026: Code review monitoring started
Tue Mar 10 10:47:37 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 396

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 396
  • VULNERABILITIES: 0

Generated on: Tue Mar 10 10:47:40 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@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.

🧹 Nitpick comments (2)
.agents/scripts/codacy-collector-helper.sh (2)

41-45: Solid SC2155 fix — consider adding defensive validation for consistency.

The separation of declaration and assignment correctly addresses ShellCheck SC2155. The repo-root anchoring makes config paths CWD-independent as intended.

For consistency with line 26's || exit pattern on SCRIPT_DIR, consider adding a guard to ensure REPO_ROOT resolved successfully:

🛡️ Optional: Add defensive validation
 REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
 readonly REPO_ROOT
+[[ -d "$REPO_ROOT" ]] || { echo "FATAL: Could not determine REPO_ROOT" >&2; exit 1; }
 readonly AUDIT_CONFIG="${REPO_ROOT}/configs/code-audit-config.json"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.agents/scripts/codacy-collector-helper.sh around lines 41 - 45, REPO_ROOT
is derived from SCRIPT_DIR but lacks the defensive validation used earlier;
after computing REPO_ROOT ensure it succeeded (e.g., test that REPO_ROOT is
non-empty and points to an existing directory) and fail fast if not (similar to
the SCRIPT_DIR "|| exit" pattern), then only mark REPO_ROOT readonly and proceed
to set AUDIT_CONFIG and AUDIT_CONFIG_TEMPLATE so the script won't continue with
invalid paths.

530-537: Transaction wrapping is correct — consider total_changes() for accurate counts.

The transaction wrapping provides atomicity and the single-fsync performance benefit as intended. The 5000ms .timeout in db() should handle any concurrent write contention with code-audit-helper.sh.

One minor observation: the count on line 537 comes from wc -l on the SQL file, not actual committed rows. If any inserts fail silently within the transaction, the count could be inaccurate.

♻️ Optional: Use total_changes() for accurate row count
 		{
 			echo "BEGIN TRANSACTION;"
 			cat "$sql_file"
 			echo "COMMIT;"
+			echo "SELECT total_changes();"
 		} |
-			db "$AUDIT_DB" 2>/dev/null || log_warn "Some Codacy inserts may have failed"
-		count=$(wc -l <"$sql_file" | tr -d ' ')
+			db "$AUDIT_DB" 2>/dev/null | tail -1 || log_warn "Some Codacy inserts may have failed"
+		# count is now the actual committed row count from total_changes()
+		count=${count:-0}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.agents/scripts/codacy-collector-helper.sh around lines 530 - 537, Replace
the post-transaction line-count (count=$(wc -l <"$sql_file" | tr -d ' ')) with a
query against the same SQLite handle to get the number of rows actually changed
by the transaction: after the BEGIN...COMMIT pipeline finishes, call db
"$AUDIT_DB" and run "SELECT total_changes();" (or "SELECT changes();" depending
on desired scope) to retrieve the committed insert count and assign that to
count; reference the existing db function, AUDIT_DB variable, and sql_file/BEGIN
TRANSACTION...COMMIT block so the code measures actual committed rows rather
than the number of SQL lines.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.agents/scripts/codacy-collector-helper.sh:
- Around line 41-45: REPO_ROOT is derived from SCRIPT_DIR but lacks the
defensive validation used earlier; after computing REPO_ROOT ensure it succeeded
(e.g., test that REPO_ROOT is non-empty and points to an existing directory) and
fail fast if not (similar to the SCRIPT_DIR "|| exit" pattern), then only mark
REPO_ROOT readonly and proceed to set AUDIT_CONFIG and AUDIT_CONFIG_TEMPLATE so
the script won't continue with invalid paths.
- Around line 530-537: Replace the post-transaction line-count (count=$(wc -l
<"$sql_file" | tr -d ' ')) with a query against the same SQLite handle to get
the number of rows actually changed by the transaction: after the BEGIN...COMMIT
pipeline finishes, call db "$AUDIT_DB" and run "SELECT total_changes();" (or
"SELECT changes();" depending on desired scope) to retrieve the committed insert
count and assign that to count; reference the existing db function, AUDIT_DB
variable, and sql_file/BEGIN TRANSACTION...COMMIT block so the code measures
actual committed rows rather than the number of SQL lines.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bd5644ee-1e67-4b72-817e-05472f117b86

📥 Commits

Reviewing files that changed from the base of the PR and between 18760ea and f10d853.

📒 Files selected for processing (1)
  • .agents/scripts/codacy-collector-helper.sh

@marcusquinn marcusquinn merged commit efb3188 into main Mar 10, 2026
28 checks passed
@marcusquinn marcusquinn deleted the bugfix/codacy-collector-quality-debt branch March 10, 2026 11:10
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the robustness, security, and reliability of the codacy-collector-helper.sh script. It addresses several critical and high-impact findings by implementing stricter input validation, improving API interaction safety, ensuring database transactional integrity, and making configuration paths more resilient to execution context. The changes collectively aim to prevent common vulnerabilities and improve the script's operational stability.

Highlights

  • Security Enhancement: SQL Injection Prevention: Implemented validation for the --limit parameter in cmd_query to ensure it is a positive integer within a safe range (1-10000), preventing potential SQL injection vulnerabilities.
  • Configuration Path Robustness: Anchored AUDIT_CONFIG and AUDIT_CONFIG_TEMPLATE paths to the repository root, making them independent of the current working directory and improving script reliability.
  • Safe JSON Body Construction: Switched to using jq -nc with --arg/--argjson for building cursor pagination request bodies, ensuring safe JSON escaping and preventing injection issues.
  • Database Transactional Integrity: Wrapped batch INSERT statements in BEGIN TRANSACTION and COMMIT to ensure atomicity, improve performance, and guarantee data consistency.
  • Improved Rate-Limit Handling: Introduced a separate retry mechanism for HTTP 429 (Too Many Requests) responses, preventing rate-limit retries from consuming the general error budget and improving resilience to API rate limiting.
  • Temporary File Management Refinement: Centralized temporary file creation to a dedicated directory (~/.aidevops/.agent-workspace/tmp/) and removed unused tmp_headers allocation, streamlining resource management.
  • ShellCheck Compliance: Addressed ShellCheck warning SC2155 by separating the declaration and assignment of the REPO_ROOT variable.
Changelog
  • .agents/scripts/codacy-collector-helper.sh
    • Anchored configuration file paths (AUDIT_CONFIG, AUDIT_CONFIG_TEMPLATE) to the repository root, resolving CWD-dependent issues.
    • Separated the declaration and assignment of REPO_ROOT to comply with ShellCheck SC2155.
    • Removed the tmp_headers variable and the corresponding -D curl argument, as they were unused.
    • Modified temporary file creation (tmp_response, sql_file, jq_filter_file) to use a centralized directory (~/.aidevops/.agent-workspace/tmp/).
    • Implemented a dedicated retry counter for HTTP 429 (rate-limit) responses, ensuring they do not deplete the general error retry budget.
    • Updated JSON request body construction for cursor pagination to use jq -nc --argjson for secure and robust JSON escaping.
    • Wrapped batch SQL INSERT statements within BEGIN TRANSACTION and COMMIT for atomicity and improved performance.
    • Added input validation for the --limit parameter in cmd_query, restricting it to positive integers between 1 and 10000 to prevent SQL injection.
Activity
  • The pull request addresses 13 findings from previous review feedback (coderabbit, gemini-code-assist, human reviewers) on .agents/scripts/codacy-collector-helper.sh.
  • An auto-generated release notes summary was provided by CodeRabbit, highlighting bug fixes for API rate-limit error handling and transaction safety, and improvements for configuration paths, temporary file management, and input validation.
  • Verification steps included passing shellcheck -x (with expected SC1091 info) and confirming all 13 identified issues were addressed.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@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 significantly improves the codacy-collector-helper.sh script by addressing several critical, high, and medium severity issues. Key enhancements include anchoring configuration paths to the repository root for better portability, implementing a more robust rate-limiting retry mechanism, utilizing jq for safe JSON request body construction to prevent injection, wrapping SQL INSERT statements in transactions for atomicity and performance, and adding strict input validation for the --limit parameter to mitigate SQL injection vulnerabilities. These changes collectively enhance the script's security, reliability, and maintainability.

Comment on lines +44 to +45
readonly AUDIT_CONFIG="${REPO_ROOT}/configs/code-audit-config.json"
readonly AUDIT_CONFIG_TEMPLATE="${REPO_ROOT}/configs/code-audit-config.json.txt"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

Anchoring AUDIT_CONFIG and AUDIT_CONFIG_TEMPLATE to REPO_ROOT correctly resolves the critical issue of CWD-dependent config paths. This ensures that the script can be invoked from any directory within the repository and still locate its configuration files, significantly improving its reliability and preventing unexpected failures.

Comment on lines +621 to +625
if [[ "$2" =~ ^[0-9]+$ ]] && [[ "$2" -gt 0 && "$2" -le 10000 ]]; then
limit="$2"
else
log_error "Invalid limit value: $2 (must be a positive integer, max 10000)"
return 1
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

The added input validation for the --limit parameter is a critical security fix. By ensuring that the limit is a positive integer within a defined range (1-10000), the script effectively prevents SQL injection attacks that could exploit malformed or malicious input. This is a strong defense-in-depth measure for handling user-provided input.

References
  1. Employ a defense-in-depth strategy for handling user-provided input. Sanitize input at the entry point using a strict allowlist, and also apply context-specific escaping or safe handling mechanisms (e.g., parameterized queries for SQL, --arg for jq) at each point of use.
  2. To prevent SQL injection in shell scripts, sanitize input using a strict allowlist and also perform context-specific escaping (e.g., doubling single quotes for SQL strings) before interpolating the value into a query.
  3. When parsing delimited data from an untrusted source in a shell script, validate numeric fields before using them in calculations. This provides defense-in-depth against injection attacks that could result from delimiter shifting caused by malicious data.

Comment on lines +279 to +283
rate_limit_retries=$((rate_limit_retries + 1))
if [[ $rate_limit_retries -ge $max_rate_limit_retries ]]; then
log_error "Rate limited ${rate_limit_retries} times — giving up: ${endpoint}"
return 1
fi
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

The new logic to check rate_limit_retries against max_rate_limit_retries before giving up on 429 responses is a robust improvement. It ensures that the script attempts to recover from rate limits a predefined number of times, preventing premature failure and improving overall success rates for API calls.

Comment on lines +531 to +535
{
echo "BEGIN TRANSACTION;"
cat "$sql_file"
echo "COMMIT;"
} |
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

Wrapping the batch INSERT statements in BEGIN TRANSACTION; and COMMIT; is a significant improvement for both atomicity and performance. This ensures that either all inserts succeed or none do, maintaining data integrity. Furthermore, it can drastically improve performance by reducing the number of fsync operations, as noted in the PR description.

Comment on lines +405 to 409
request_body=$(jq -nc --argjson limit "$CODACY_PAGE_SIZE" --arg cursor "$cursor" \
'{limit: $limit, cursor: $cursor}')
else
request_body="{\"limit\": ${CODACY_PAGE_SIZE}}"
request_body=$(jq -nc --argjson limit "$CODACY_PAGE_SIZE" '{limit: $limit}')
fi
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

Using jq -nc --argjson and --arg for constructing the JSON request body is a critical security improvement. This method safely escapes shell variables into JSON, preventing potential injection vulnerabilities that could arise from directly interpolating values into a JSON string. This aligns with best practices for handling user-provided input and constructing data payloads securely.

References
  1. In shell scripts, use jq --arg for strings and --argjson for other JSON types (like numbers) to safely pass variables into a jq filter. This avoids syntax errors if the variables contain special characters.
  2. In shell scripts, use jq --argjson to safely pass JSON content from variables when merging JSON arrays, instead of direct string interpolation, to prevent parsing errors.
  3. Employ a defense-in-depth strategy for handling user-provided input. Sanitize input at the entry point using a strict allowlist, and also apply context-specific escaping or safe handling mechanisms (e.g., parameterized queries for SQL, --arg for jq) at each point of use.

@@ -243,7 +249,6 @@ codacy_api_request() {
-s
-w "%{http_code}"
-o "$tmp_response"
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

The removal of -D "$tmp_headers" from the curl command is appropriate, as the tmp_headers variable and its associated functionality have been removed. This keeps the curl command clean and focused on its primary task.

_save_cleanup_scope
trap '_run_cleanups' RETURN
push_cleanup "rm -f '${tmp_response}' '${tmp_headers}'"
push_cleanup "rm -f '${tmp_response}'"
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

The cleanup for tmp_headers is correctly removed, aligning with the variable's removal. This ensures that no non-existent files are attempted to be removed, preventing potential errors.

Comment on lines +479 to +482
local tmp_dir="${HOME}/.aidevops/.agent-workspace/tmp"
mkdir -p "$tmp_dir" 2>/dev/null || true
sql_file=$(mktemp "${tmp_dir}/codacy-sql.XXXXXX")
jq_filter_file=$(mktemp "${tmp_dir}/codacy-jq.XXXXXX")
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

Similar to codacy_api_request, using a dedicated temporary directory ~/.aidevops/.agent-workspace/tmp for sql_file and jq_filter_file is a good practice. It centralizes temporary files and improves management. The mkdir -p with 2>/dev/null || true ensures graceful handling of directory creation.

References
  1. In status display functions, it is acceptable to suppress stderr (2>/dev/null) for commands that might fail transiently (e.g., parsing a file being written). This prioritizes clean, formatted output and graceful degradation over showing noisy, transient errors, especially when common failure cases are handled separately.
  2. Suppress stderr (2>/dev/null) for find commands when it is expected that the target directory may not exist. This prevents noisy, unactionable errors in status display scripts where a fallback value (e.g., || echo "0") is used.

Comment on lines +42 to +43
REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
readonly REPO_ROOT
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

The REPO_ROOT variable is correctly declared and then made readonly in separate steps. This adheres to the ShellCheck SC2155 recommendation, which suggests separating declaration and assignment for readonly variables to avoid potential issues in some shell environments. This is a good practice for maintainability and robustness.

References
  1. When declaring and assigning local variables in shell scripts, separate the local declaration from the assignment if command substitution is involved, to ensure exit code safety. For consistency, this pattern should be maintained even for simple assignments.


tmp_response=$(mktemp)
tmp_headers=$(mktemp)
local tmp_response
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

The removal of tmp_headers addresses the identified dead code, simplifying the script and removing unnecessary resource allocation. This is a good cleanup for maintainability.

alex-solovyev added a commit that referenced this pull request Mar 10, 2026
…review

- Add defensive REPO_ROOT validation to fail fast if path resolution fails,
  matching the SCRIPT_DIR || exit pattern (CodeRabbit nitpick)
- Replace wc -l line count with SQLite total_changes() for accurate
  committed row count after transaction (CodeRabbit nitpick)

Closes #4075
alex-solovyev added a commit that referenced this pull request Mar 11, 2026
…review (#4100)

- Add defensive REPO_ROOT validation to fail fast if path resolution fails,
  matching the SCRIPT_DIR || exit pattern (CodeRabbit nitpick)
- Replace wc -l line count with SQLite total_changes() for accurate
  committed row count after transaction (CodeRabbit nitpick)

Closes #4075
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Auto-created from TODO.md tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

quality-debt: .agents/scripts/codacy-collector-helper.sh — PR #1384 review feedback (critical)

1 participant