Skip to content

fix(hooks): close plain (...) and brace { ...; } bypass in gateguard destructive scan - #1912

Merged
affaan-m merged 7 commits into
affaan-m:mainfrom
Jamkris:fix/gateguard-subshell-and-brace-bypass
May 15, 2026
Merged

affaan-m merged 7 commits into
affaan-m:mainfrom
Jamkris:fix/gateguard-subshell-and-brace-bypass

Conversation

@Jamkris

@Jamkris Jamkris commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

scripts/hooks/gateguard-fact-force.js opens up $(...) and backtick command substitutions before running its destructive classifiers, but two other shell grouping constructs that execute their bodies are not opened up: plain (...) subshells and { ...; } brace groups. This PR closes both.

Bypass surface (reproduced on main at 375d750)

Form Before After
rm -rf /tmp/x DESTRUCTIVE DESTRUCTIVE
(rm -rf /tmp/x) allowed DESTRUCTIVE
((rm -rf /tmp/x)) allowed DESTRUCTIVE
{ rm -rf /tmp/x; } allowed DESTRUCTIVE
(git push --force origin main) allowed DESTRUCTIVE
{ git push --force origin main; } allowed DESTRUCTIVE
(echo y; { rm -rf /tmp/x; }) allowed DESTRUCTIVE
$(echo y; (rm -rf /tmp/x)) allowed DESTRUCTIVE

Affects every destructive classifier — isDestructiveRm, isDestructiveGit, the DESTRUCTIVE_SQL_DD regex — because they all run downstream of the same splitCommandSegments pass and that pass was never given the inner segments.

Fix

A small BFS (collectExecutableBodies) walks the raw command and harvests every body returned by the three sibling extractors in scripts/lib/shell-substitution.js:

The harvested bodies are fed into the existing splitCommandSegments flatMap; the per-segment classifiers themselves require no edits.

extractBraceGroups recognises bash's actual reserved-word semantics ({ must be followed by whitespace and preceded by line start / whitespace / ; / | / & / (; } must be preceded by ; or whitespace) so {npm run dev} does not trigger (single token, no executable body at runtime), and echo "{ rm -rf; }" stays allowed (bash does not honour brace groups inside double quotes).

Commit layout

Split into four reviewable commits:

  1. refactor(hooks): import extractCommandSubstitutions from shared lib
    Drops gateguard's private 99-line duplicate of the function now that PR fix: integrate recent hook and docs PRs #1905 landed scripts/lib/shell-substitution.js on main. The 72 existing gateguard tests pass unchanged.
  2. feat(lib): add extractBraceGroups for { ...; } shell groups
    Sibling to extractSubshellGroups. No consumer yet.
  3. fix(hooks): cover plain (...) and brace { ...; } bodies in destructive scan
    Wires both new extractors plus extractCommandSubstitutions through a BFS walker. This is the behaviour change.
  4. test(hooks): regression coverage for subshell + brace destructive bypass
    13 new cases — 7 newly-blocked, 6 explicitly-allowed (literals in quotes, non-destructive groups, the no-space brace edge case).

Tests

  • node tests/hooks/gateguard-fact-force.test.js — 85/85 (was 72/72)
  • yarn lint clean
  • yarn test green locally

Provenance

Direct follow-up to PR #1889 (closed; integrated via #1905). In that PR I noted: "consolidating both call sites onto this shared lib is a follow-up worth doing once this PR lands". This is that follow-up. The extractCommandSubstitutions duplication is gone; gateguard now benefits from the same quote-state tracking the PR #1889 round-1 review added to the lib.

Test plan

  • CI lint passes
  • CI tests pass
  • Manual: every row of the bypass table now returns DESTRUCTIVE
  • Manual: every row of the explicit-allow tests stays allowed

Summary by cubic

Closes a bypass in the gateguard destructive scan by inspecting bodies inside plain subshells ( ... ) and brace groups { ...; }, and fixes brace-group parsing so nested spans can’t hide destructive commands. This blocks hidden rm -rf, git push --force, and similar commands nested in these groups.

  • Bug Fixes

    • Walk all executable bodies via a BFS (collectExecutableBodies) and feed them into splitCommandSegments, covering (...), ((...)), and { ...; } across nesting.
    • Fix extractBraceGroups to skip $(...), backticks, and (...) spans and to enforce the nested-{ boundary rule, preventing early-close cases like { echo \echo }`; ... }`.
    • Add 18 regression tests for subshell/brace cases, quotes, and span-skip edge cases; suite count: 72→90.
  • Refactors

    • Replace the local duplicate with the shared extractCommandSubstitutions; add extractBraceGroups and wire it with extractSubshellGroups.
    • Deduplicate bodies during BFS to avoid re-scanning identical segments.

Written for commit 873fbad. Summary will update on new commits.

Summary by CodeRabbit

  • Improvements
    • Broader detection of potentially destructive shell commands across additional grouping syntaxes and nested command structures, improving safety checks for more reachable command forms.
  • Tests
    • Added tests validating destructive detection and allow-cases across various nested groupings, quoting, and boundary scenarios.

Review Change Stack

Jamkris added 4 commits May 15, 2026 11:32
PR affaan-m#1905 (the maintainer batch that integrated affaan-m#1889) added
`scripts/lib/shell-substitution.js` and exported
`extractCommandSubstitutions` from it, but `gateguard-fact-force.js`
still ships its own private copy of the same function — the
original I extracted into the lib. With both files in `main`, the
private copy in gateguard is now dead duplication.

This commit removes the private definition and imports the lib
version. No public behavior change in the regression suite:

- gateguard's existing 72 tests pass unchanged
- the existing destructive cases (rm -rf, git push --force, dd if=,
  drop table, $(...) and backtick subshells) still flag correctly
- the existing allow cases (echo, ls) still pass

One small semantic improvement comes free: the lib version
maintains quote state inside the `$(...)` depth-counting loop
(added in affaan-m#1889 round 1), whereas the private copy did not. In
practice this is masked by `explodeSubshells` running as a second
pass, so existing tests already exercise the destructive cases
that quote-tracking would otherwise catch; the lib version is
just the cleaner of the two implementations.

The remaining destructive-bash blind spots — plain `(...)` and
brace `{ ...; }` group bodies — are addressed in the next two
commits.
Sibling extractor for `extractCommandSubstitutions` and
`extractSubshellGroups`, completing the set of grouping constructs
bash supports that can hide commands from naive segment splitters.

Recognition matches bash's actual reserved-word semantics, not just
literal `{`/`}` matching:

- `{` opens a group only when followed by whitespace AND preceded by
  the line start, whitespace, or a shell operator (`;`, `|`, `&`, `(`).
  So `{npm run dev}` is NOT a brace group (single token), and
  `foo{` is not either (token continuation, not a reserved word).
- `}` closes the group only when preceded by `;` or whitespace.
  So `${foo}` and `array}` inside the body are not closing braces.
- Single quotes and double quotes are literal for `{`/`}` (bash does
  not recognize `{ ...; }` inside either kind of quoted string).
- `$(...)`, backticks, and plain `(...)` spans are skipped during
  the scan so the sibling extractors can own those bodies.

No consumer yet; the next commit wires this into
`scripts/hooks/gateguard-fact-force.js` alongside
`extractSubshellGroups` to close the brace-group destructive bypass
(`{ rm -rf /tmp/x; }`).

Test fixtures verifying the recognition rules in the next-but-one
commit; lib-level unit coverage to follow as part of a separate
`tests/lib/shell-substitution.test.js` if reviewers prefer.
…e scan

Before this commit, `isDestructiveBash` only looked inside `$(...)`
and backtick command substitutions (via `extractCommandSubstitutions`).
Two other shell grouping constructs that execute their bodies were
not opened up:

  (rm -rf /tmp/x)             ← plain subshell — bypassed
  ((rm -rf /tmp/x))           ← nested subshell — bypassed
  { rm -rf /tmp/x; }          ← brace group — bypassed
  (git push --force origin main)
  { git push --force origin main; }
  (echo y; (rm -rf /tmp/x))    ← nested subshell with destructive inside

Reproduced against `main` (commit 375d750):

  $ cat > /tmp/probe.js <<...   # load gateguard, call isDestructiveBash
  $ node /tmp/probe.js
  allowed | "(rm -rf /tmp/x)"
  allowed | "((rm -rf /tmp/x))"
  allowed | "{ rm -rf /tmp/x; }"
  allowed | "(git push --force origin main)"
  allowed | "{ git push --force origin main; }"

This affects every destructive classifier in this hook — the rm
detector, the git-force detector, and the SQL/dd regex — because
they all run downstream of the same `splitCommandSegments` pass and
that pass never saw the inner segments.

Fix: introduce `collectExecutableBodies(raw)`. A BFS that harvests
`raw` plus every body returned by `extractCommandSubstitutions`,
`extractSubshellGroups`, and the new `extractBraceGroups`,
recursively (cross-syntax: `(... $(...) ...)` and friends), bounded
by a `seen` set. Feed the resulting body list into the existing
`splitCommandSegments` flatMap, then run the existing per-segment
destructive classifiers unchanged. The classifiers themselves
require no edits — they just get more segments to look at.

After this commit, all six lines above return DESTRUCTIVE. The 72
existing gateguard regression tests still pass.

Regression tests for the newly closed bypass forms in the next
commit. The legitimate-allow cases that must NOT regress (literal
inside quotes, `(echo hello)`, `(npm test)`, etc.) are also covered
there explicitly to lock in the quote-awareness boundary.
13 new cases lock in the behavior added by the previous commit.
Each was verified to fail before the fix and pass after.

Newly blocked (exit destructive):
  (rm -rf /tmp/junk)
  ((rm -rf /tmp/junk))
  { rm -rf /tmp/junk; }
  (git push --force origin main)
  { git push --force origin main; }
  (echo y; { rm -rf /tmp/junk; })       — cross-syntax () containing {}
  $(echo y; (rm -rf /tmp/junk))         — cross-syntax $() containing ()

Negative coverage — explicitly asserted NOT to regress, since the
new group-body walker is the easiest place to leak false positives:
  git commit -m '(rm -rf /tmp/junk)'    — single-quoted literal
  echo "(rm -rf /tmp/junk)"             — double-quoted literal
  echo "{ rm -rf /tmp/junk; }"          — double-quoted brace literal
  (echo hello)                          — non-destructive subshell
  { echo hello; }                       — non-destructive brace group
  echo {rm -rf /tmp/junk}               — no-space form, not a brace group

The no-space case is intentional: bash treats `{rm` as a single
token rather than as a `{` reserved word, so the body never runs
at runtime. Recognising it would be over-conservative.

Test suite count: 72 → 85 in gateguard-fact-force.test.js.
@ecc-tools

ecc-tools Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR.

@coderabbitai

coderabbitai Bot commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a2e91c35-f327-4eb5-af58-c07ec21a4cf2

📥 Commits

Reviewing files that changed from the base of the PR and between fb656ff and 873fbad.

📒 Files selected for processing (3)
  • scripts/hooks/gateguard-fact-force.js
  • scripts/lib/shell-substitution.js
  • tests/hooks/gateguard-fact-force.test.js
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/hooks/gateguard-fact-force.test.js
  • scripts/hooks/gateguard-fact-force.js
  • scripts/lib/shell-substitution.js

📝 Walkthrough

Walkthrough

The PR expands destructive-command detection in the GateGuard hook by adding brace-group parsing to the shell-substitution library and changing the hook to breadth-first collect and scan executable bodies from command substitutions, subshells, and brace groups; tests are added to cover nested and edge-case brace/subshell scenarios.

Changes

Expanded Shell Syntax Parsing for Destructive Command Detection

Layer / File(s) Summary
Bash brace-group extractor and library export
scripts/lib/shell-substitution.js
Adds extractBraceGroups(input) which finds and recursively extracts { ...; } brace-group bodies while respecting quote contexts and skipping spans handled by command-substitution/backtick/subshell extractors; exports the new function.
Refactored extractor imports and breadth-first body collection
scripts/hooks/gateguard-fact-force.js
Replaces the in-file extractCommandSubstitutions implementation with imports of extractCommandSubstitutions, extractSubshellGroups, and extractBraceGroups; introduces collectExecutableBodies(raw) that breadth-first traverses and deduplicates bodies found via the three extractors.
Destructive pattern detection on expanded bodies
scripts/hooks/gateguard-fact-force.js
Updates isDestructiveBash() to generate shell segments from collectExecutableBodies(raw) so destructive SQL/dd and rm/git token checks cover subshell and brace-group bodies as well as command substitutions.
Test coverage for nested destructive detection and edge cases
tests/hooks/gateguard-fact-force.test.js
Adds tests asserting destructive-command denial inside (...), ((...)), and { ...; } bodies and mixed nesting; includes negative cases for quoted literals and non-brace-literal forms, plus regression checks for } inside nested spans and boundary tokens like foo{.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • affaan-m

Poem

🐰 I sniffed the braces, parens, shells so deep,
I chased the bodies where the hidden commands creep.
No rm or git --force shall slip by unseen,
In { } or $() or (...) green—
GateGuard hops, alert and keen.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: closing a bypass in gateguard's destructive scan by handling plain subshells and brace groups that were previously undetected.
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

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.

🧹 Nitpick comments (2)
scripts/hooks/gateguard-fact-force.js (1)

319-344: 💤 Low value

Minor: bodies may contain duplicates across BFS paths.

The seen set guards against reprocessing the same body, but bodies.push(body) runs unconditionally each time a body is extracted. If the same body string is produced by two different extraction paths (e.g., nested (...) containing a duplicate of an outer $(...) body), it is appended multiple times. This is purely wasted work in the downstream flatMap(splitCommandSegments) — correctness is unaffected because the destructive checks are pure functions of the segment — but you could gate the push on seen.has(body) for a tighter loop.

♻️ Optional dedup at push time
   while (queue.length) {
     const current = queue.shift();
     if (seen.has(current)) continue;
     seen.add(current);

     for (const body of extractCommandSubstitutions(current)) {
+      if (seen.has(body)) continue;
       bodies.push(body);
       queue.push(body);
     }
     for (const body of extractSubshellGroups(current)) {
+      if (seen.has(body)) continue;
       bodies.push(body);
       queue.push(body);
     }
     for (const body of extractBraceGroups(current)) {
+      if (seen.has(body)) continue;
       bodies.push(body);
       queue.push(body);
     }
   }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/hooks/gateguard-fact-force.js` around lines 319 - 344, The function
collectExecutableBodies currently pushes each extracted body into bodies and
queue unconditionally, causing duplicates across different BFS paths; update the
loops over extractCommandSubstitutions, extractSubshellGroups, and
extractBraceGroups so that for each extracted body you first check
seen.has(body) and only if false do you call bodies.push(body) and
queue.push(body) (keeping seen logic unchanged) to avoid duplicate entries that
downstream flatMap(splitCommandSegments) would reprocess.
tests/hooks/gateguard-fact-force.test.js (1)

1285-1296: 💤 Low value

Minor: ((...)) is arithmetic evaluation, not a nested subshell.

The cohort comment and the test label ("nested ((...)) subshell") describe ((...)) as a nested subshell, but in bash ((expr)) is the arithmetic-evaluation construct — at top level it would try to evaluate rm, -rf, /tmp/junk as arithmetic tokens and fail rather than executing rm. The current parser still depth-tracks it as nested parens and produces a destructive verdict, which is a fine conservative behavior, but the comment misleads future readers about why this case is gated. Consider rewording to "nested parens (e.g. ((...))) treated conservatively" or similar so the safety-vs.-semantics distinction is documented.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/hooks/gateguard-fact-force.test.js` around lines 1285 - 1296, The
comment and test label incorrectly describe the `((...))` construct as a nested
subshell; update the cohort comment and the test description string used in the
two test cases (the `'denies rm -rf inside nested ((...)) subshell'` test and
the surrounding comment block) to correctly note that `((...))` is arithmetic
evaluation and is being treated conservatively (e.g., "nested parens /
arithmetic ((...)) treated conservatively" or "arithmetic ((...)) treated
conservatively") so readers understand we're gatekeeping for safety rather than
documenting actual subshell semantics.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@scripts/hooks/gateguard-fact-force.js`:
- Around line 319-344: The function collectExecutableBodies currently pushes
each extracted body into bodies and queue unconditionally, causing duplicates
across different BFS paths; update the loops over extractCommandSubstitutions,
extractSubshellGroups, and extractBraceGroups so that for each extracted body
you first check seen.has(body) and only if false do you call bodies.push(body)
and queue.push(body) (keeping seen logic unchanged) to avoid duplicate entries
that downstream flatMap(splitCommandSegments) would reprocess.

In `@tests/hooks/gateguard-fact-force.test.js`:
- Around line 1285-1296: The comment and test label incorrectly describe the
`((...))` construct as a nested subshell; update the cohort comment and the test
description string used in the two test cases (the `'denies rm -rf inside nested
((...)) subshell'` test and the surrounding comment block) to correctly note
that `((...))` is arithmetic evaluation and is being treated conservatively
(e.g., "nested parens / arithmetic ((...)) treated conservatively" or
"arithmetic ((...)) treated conservatively") so readers understand we're
gatekeeping for safety rather than documenting actual subshell semantics.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f82adaef-e2f5-4b4f-919b-ecaf40e21b6a

📥 Commits

Reviewing files that changed from the base of the PR and between f731501 and fb656ff.

📒 Files selected for processing (3)
  • scripts/hooks/gateguard-fact-force.js
  • scripts/lib/shell-substitution.js
  • tests/hooks/gateguard-fact-force.test.js

@greptile-apps

greptile-apps Bot commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR closes two shell-grouping bypass surfaces in the gateguard destructive-command scanner by adding extractBraceGroups to the shared lib and wiring all three extractors (extractCommandSubstitutions, extractSubshellGroups, extractBraceGroups) into a new BFS walker (collectExecutableBodies). It also eliminates the 99-line private duplicate of extractCommandSubstitutions that previously lived in gateguard-fact-force.js.

  • scripts/lib/shell-substitution.js — adds extractBraceGroups which recognises bash's reserved-word { ...; } semantics, correctly skips $(...), backtick, and (...) spans inside the body, and handles nested brace groups via recursion.
  • scripts/hooks/gateguard-fact-force.js — replaces the inline duplicate with the shared import, introduces collectExecutableBodies (BFS over all three extractor types with a seen set for cycle safety), and threads it into isDestructiveBash.
  • tests/hooks/gateguard-fact-force.test.js — adds 20 regression cases covering newly-blocked forms, quoted literals that must stay allowed, and round-1-review span-skip edge cases.

Confidence Score: 5/5

Safe to merge — the change tightens the destructive-command gate without loosening any existing checks, and the round-1 review edge cases are now addressed in code and covered by dedicated tests.

The BFS walker and extractBraceGroups are additive, security-tightening changes. Quote handling, span-skipping, and boundary detection all match bash semantics. The previous review concerns about premature } termination and missing nested-{ boundary checks have been addressed. The 85-test suite directly covers the bypass table and round-1 edge cases.

No files require special attention.

Important Files Changed

Filename Overview
scripts/lib/shell-substitution.js Adds extractBraceGroups with correct bash reserved-word semantics, span-skipping for $()/backtick/() in body accumulation, and nested-brace boundary checks; both round-1 review issues addressed.
scripts/hooks/gateguard-fact-force.js Removes 99-line private duplicate, adds collectExecutableBodies BFS walker, and threads it into isDestructiveBash. Orphaned JSDoc block at lines 292–300 noted in previous review comment.
tests/hooks/gateguard-fact-force.test.js Adds 20 well-structured regression tests (newly-blocked, negative/allowed, and round-1 span-skip edge cases) that directly match the bypass table in the PR description.

Reviews (2): Last reviewed commit: "test(hooks): coverage for brace-group sp..." | Re-trigger Greptile

Comment thread scripts/lib/shell-substitution.js Resolved
Comment thread scripts/lib/shell-substitution.js Resolved
Jamkris added 3 commits May 15, 2026 12:31
… scan

Greptile flagged two logic gaps in `extractBraceGroups`:

1. The body-accumulation loop did not skip `$(...)` / `(...)` /
   backtick spans before counting `}` depth decrements. With the
   existing strict `}` rule (closing only when preceded by `;` or
   whitespace), the `$()` and `()` cases happen not to misfire in
   practice — but the **backtick** case does:

       { echo `echo }`; rm -rf /tmp/x; }

   The `}` inside the backtick body is preceded by a space, so
   under the old code it satisfied the close rule and terminated
   the brace group early. Body extracted: `" echo `echo "`.

   In `gateguard-fact-force.js` this never manifested as a real
   destructive bypass because `explodeSubshells` runs as a second
   pass and unwraps backtick bodies into top-level segments anyway.
   But the lib itself was buggy, and any future consumer without
   that backup pass (e.g. `pre-bash-dev-server-block.js`) would
   inherit the gap.

2. The nested `{` depth check did not apply the same "preceded by
   a boundary" rule as the outer scan. Tokens like `foo{` in
   `{ x foo{ ; rm -rf; }` would happen to be safe under the
   existing whitespace-after-`{` rule, but the inconsistency was
   real and worth fixing.

Fix: in the body-accumulation loop, walk past `$(...)`, `(...)`,
and backtick spans as opaque chunks (with their own quote-state
tracking, mirroring the outer scan), and require nested `{` to
satisfy the same `prevIsBoundary` rule.

After this commit:

  IN: { echo `echo }`; rm -rf /tmp/x; }
  → body: " echo `echo }`; rm -rf /tmp/x; "

  IN: { echo $(echo "}"); rm -rf /tmp/x; }
  → body: " echo $(echo \"}\"); rm -rf /tmp/x; "

The 85 existing gateguard regression tests still pass; lib-level
regression cases for the new spans are added in a follow-up commit.
CodeRabbit nitpick (low value but cheap): `seen` only guards
against re-queueing the same body, not against re-pushing it into
the flat `bodies` list. When the same body is reached via two
different BFS paths (e.g. one extractor's internal recursion plus a
cross-syntax sibling), it appeared in `bodies` twice and was fed
through `splitCommandSegments` twice. Correctness was unaffected
because the destructive classifiers are pure, but the duplicate
work was real.

Fix: hoist the `seen.has(body)` check ahead of `bodies.push` in
each extractor loop, so a body is pushed at most once total.

This is the cleanup I noted in the PR affaan-m#1889 round-1 reply re: BFS
redundancy — best handled here, alongside the gateguard consolidation,
because the two share the same BFS shape.

No behavior change; 85 gateguard tests still pass.
5 new regression cases lock in the brace-group span-skip behaviour
added in the previous lib commit:

  { echo `echo }`; rm -rf /tmp/junk; }       — backtick body with }
  { echo $(echo "}"); rm -rf /tmp/junk; }    — $() body with }
  { (echo "}"); rm -rf /tmp/junk; }          — () body with }
  { x=$(echo a}b); rm -rf /tmp/junk; }       — $() body with }
  { echo foo{bar; rm -rf /tmp/junk; }        — foo{ token, not nested {

Each was verified to fail (body extracted early, destructive
classifier never sees `rm -rf`) before the lib fix, and to pass
after.

Also addresses CodeRabbit's `((...))` label nitpick: bash's
`((expr))` is the arithmetic-evaluation construct, not a nested
subshell. The parser depth-tracks it conservatively (the inner
tokens are still scanned), but the cohort comment and test label
previously called it a "nested subshell" — misleading future
readers about why the case is gated. Updated the comment and the
test name to describe it as "arithmetic eval, treated
conservatively".

Test suite count: 85 → 90 in gateguard-fact-force.test.js.
@ecc-tools

ecc-tools Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR.

@affaan-m
affaan-m merged commit 8cfadfe into affaan-m:main May 15, 2026
40 checks 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.

2 participants