Skip to content

fix(tests): terminate find -exec and pass {} — the placeholder step was a no-op - #192

Open
hyperpolymath wants to merge 3 commits into
mainfrom
fix/find-exec-terminator
Open

fix(tests): terminate find -exec and pass {} — the placeholder step was a no-op#192
hyperpolymath wants to merge 3 commits into
mainfrom
fix/find-exec-terminator

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

tests/e2e/template_instantiation_test.sh ran find … -exec bash -c '…' _ "\$file", which has two defects on one line:

  1. No ; or + terminator — the file does not parse (SC2067).
  2. "\$file" where {} belongs\$file is assigned only inside the -exec body, so in the outer scope it is unset. \$1 arrived empty, file="", and every grep/sed operated on an empty path.

The consequence is worse than a lint error. The placeholder-replacement step silently did nothing, then logged "All placeholder tokens replaced". A test whose entire purpose is to prove instantiation worked was passing without replacing a single token — a plausible cause of estate repos shipping with literal {{project}} still in their sources.

Corrected to ' _ {} \; so find passes each matched path.

Found by an estate-wide sweep of 5,111 scripts across 375 repos: this identical stale copy exists in 30 repositories. rsr-template-repo's own copy is already correct and restructured (371 lines vs the 268 here), so these are stale duplicates that never picked up the upstream fix.

…as a no-op

tests/e2e/template_instantiation_test.sh ran:

    find ... -exec bash -c '
        file="$1"
        ... grep/sed over $file ...
    ' _ "$file"

Two defects in that one line:

  1. No ';' or '+' terminator, so the file does not parse (SC2067).
  2. "$file" is passed where {} belongs. $file is assigned ONLY inside the
     -exec body, so in the outer scope it is UNSET — $1 arrived empty, file=""
     and every grep/sed operated on an empty path.

⚠ The consequence is worse than a lint error: the placeholder-replacement step
SILENTLY DID NOTHING, then logged "All placeholder tokens replaced". A test
whose whole purpose is to prove instantiation worked was passing without
replacing a single token. That is a plausible cause of estate repos shipping
with literal {{project}} tokens still in their sources.

Corrected to "' _ {} \;" so find passes each matched path.

Found by an estate-wide shellcheck sweep of 5,111 scripts across 375 repos:
this identical stale copy exists in 30 repositories. rsr-template-repo's own
copy is already correct and restructured (371 lines vs the 268 here), so these
are stale duplicates that never picked up the upstream fix.
@gitar-bot

gitar-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown

Gitar is working

Gitar

@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 17ca9d64-27e0-42b6-beca-cbdebb1b8330

📥 Commits

Reviewing files that changed from the base of the PR and between fb96b3d and 6a5985d.

📒 Files selected for processing (1)
  • affinescript-ecosystem/rattlescript/tests/e2e/template_instantiation_test.sh

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout. (20)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: governance / Security policy checks
  • GitHub Check: governance / Well-Known (RFC 9116 + RSR)
  • GitHub Check: governance / Code quality + docs
  • GitHub Check: governance / Language / package anti-pattern policy
  • GitHub Check: governance / Licence consistency
  • GitHub Check: governance / Guix primary / Nix fallback policy
  • GitHub Check: governance / Check Workflow Staleness
  • GitHub Check: governance / Trusted-base reduction policy
  • GitHub Check: governance / Workflow security linter
  • GitHub Check: hypatia / Hypatia Neurosymbolic Analysis
  • GitHub Check: scan / rust-secrets
  • GitHub Check: scan / gitleaks
  • GitHub Check: scan / shell-secrets
  • GitHub Check: Empty-linter (invisible characters)
  • GitHub Check: Validate A2ML manifests
  • GitHub Check: Validate K9 contracts
  • GitHub Check: Groove manifest check
  • GitHub Check: analyze (javascript-typescript, none)
  • GitHub Check: sync
🔇 Additional comments (1)
affinescript-ecosystem/rattlescript/tests/e2e/template_instantiation_test.sh (1)

115-116: LGTM!


📝 Walkthrough

Summary by CodeRabbit

  • Tests
    • Improved the template instantiation end-to-end test to apply placeholder replacement reliably across all matched files.

Walkthrough

The template instantiation end-to-end test now exports placeholder variables to the replacement subprocess and passes each matched file to the inline shell script as $1.

Changes

Template instantiation testing

Layer / File(s) Summary
Pass matched files to replacement script
affinescript-ecosystem/rattlescript/tests/e2e/template_instantiation_test.sh
The test exports the placeholder variables. The find -exec bash -c command uses the standard ' _ {} \; argument form, so each matched file is available as $1.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: ⚪ Minimal · up to 6a598

This localized change corrects the test script’s file-placeholder handling so instantiation checks operate on the intended files; no actionable merge-blocking risk remains beyond normal checks and review.

Poem

A rabbit checks each file in line
$1 now holds the path just fine
Exported values reach the shell
Placeholders update as well
The test completes its hop in time

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the defects in the find -exec command, the silent test failure, and the corrective change.
Title check ✅ Passed The title clearly identifies the corrected find -exec terminator and {} placeholder. It accurately summarises the main change.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Aug 26, 2026
@codacy-production

Copy link
Copy Markdown
Contributor

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

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

Pull Request Overview

Although this PR correctly fixes the find -exec termination syntax to resolve the immediate shell error, the resulting implementation remains non-functional (a 'no-op') due to how variables are handled in the subshell. Specifically, shell variables $placeholder and $value will not expand inside the single-quoted subshell, and the file path passed via {} is not correctly mapped to the $file variable.

Furthermore, the sed command lacks portability for macOS/BSD environments and does not safely handle special characters like | or &. While Codacy indicates the PR is 'up to standards' based on static analysis, the functional logic errors identified in the review represent a high risk of failure in the test suite. Additionally, the file is noted to be significantly behind its upstream reference, which may lead to further divergence issues.

Test suggestions

  • Verify find -exec correctly iterates over template files and executes the subshell logic.
  • Verify the bash subshell correctly maps the passed {} path to the variable used in sed commands.
Low confidence findings
  • This script is currently a 'stale copy' (268 lines) compared to the upstream reference (371 lines). While this PR fixes a syntax bug, the divergence suggests the file may require a full synchronization to prevent missing other critical logic or modern standards present in the upstream version.

TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback

Comment on lines 137 to +140
sed -i "s|$placeholder|$value|g" "$file"
fi
done
' _ "$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.

🔴 HIGH RISK

The find syntax is now valid, but the subshell logic (lines 137-140) remains broken for several reasons:

  1. Variable Scoping: Because the sh -c command is wrapped in single quotes, $placeholder and $value are not expanded by the parent shell and will be empty in the subshell.
  2. Path Mapping: The path passed via {} becomes $1 in the subshell, but the script attempts to use $file, which is undefined.
  3. Sed Portability & Safety: The sed -i command is not portable to macOS/BSD (which requires sed -i '') and will fail if $value contains delimiters like | or the special character &.

Recommendation: Refactor the command to pass variables as positional arguments:
find ... -exec sh -c 'p="$1"; v="$2"; shift 2; for f in "$@"; do sed -i "s|$p|$v|g" "$f"; done' _ "$placeholder" "$value" {} +

@hyperpolymath
hyperpolymath enabled auto-merge (squash) August 28, 2026 07:47
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