Skip to content

fix(rules): case arms inside $(...), escaped operators before & - #1143

Merged
hyperpolymath merged 7 commits into
mainfrom
claude/shell-mask-case-escape
Nov 14, 2026
Merged

hyperpolymath merged 7 commits into
mainfrom
claude/shell-mask-case-escape

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

What

This PR fixes the two Codex edge cases that #1129 left as stated limits (threads 4575524786 and 4575524789).

  • Hypatia.Workflow.shell_mask/2: the word case at the start of a command pushes :case, and esac pops it. While :case is on top, a ) ends a pattern, not the enclosing $(…).
    • v=$(case yes in yes)# … is now a comment.
    • $(case y in y) echo;; esac)#x still closes the substitution, so #x is part of the word.
  • WF033 later_command?/1: backslash-escaped bytes are literals. In echo \>& echo done, the & is a separator, not part of a >& redirection.

Why

The owner asked for both to be fixed rather than left as limits.

Evidence

  • Three new tests fail on main (219 tests, 3 failures) and pass with this change:
    • "a case arm inside $(...) ends the word, so its # is a comment"
    • "the substitution still closes after esac"
    • "an escaped > before a background & does not make a redirection"
  • A guard test, "the word case as an argument does not open a case", passes before and after.
  • mix test test/rules test/soundness_test.exs: 984 tests, 0 failures.
  • mix format --check-formatted passes on the changed files, as do gen-rules-praxis.sh --check, check-readme-claims.sh and rules-praxis-test.sh.

Not done

  • $((…)) arithmetic and ( inside double quotes are still not tracked.
  • The full suite ran in CI only, because my local copy of the repo is partial.

Generated by Claude Code

The two Codex edge cases #1129 left as stated limits:
- shell_mask: the word `case` at a command start pushes :case and `esac`
  pops it. While :case is on top, a `)` ends a pattern, not the
  enclosing `$(...)`, so `v=$(case yes in yes)# ...` is a comment and
  `$(case y in y) echo;; esac)#x` still closes the substitution.
- WF033 later_command?/1: backslash-escaped bytes are literals, so in
  `echo \>& echo done` the `&` is a separator, not part of `>&`.

Tests for both fail without the change. A guard test checks that
`case` as an argument opens nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0136P7ZkGCWGEyedTtdEHAPT
@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 10 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: a9d27fb0-ace0-4cda-8a2b-79efc8238be0
Commits

Reviewing files that changed from the base of the PR and between c3e0f28 and 3f7e944.

Files selected for processing: 4

  • lib/hypatia/workflow.ex
  • lib/rules/workflow_audit.ex
  • test/rules/always_reads_cancelled_needs_test.exs
  • test/rules/ci_failure_triage_test.exs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T23:35:03.196505Z 3f7e944 New commits
🔒 Security Review ✅ Completed 2026-11-14T23:30:22.551709Z 3f7e944 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 42e6416a35

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/hypatia/workflow.ex Resolved
Comment thread lib/hypatia/workflow.ex Resolved
Codex on #1143: in `v=$(if true; then case yes in yes)# ...` the byte
before `case` belongs to `then`, so command_start?/1 refused it, the
pattern's `)` closed the substitution and the comment stayed visible.

A reserved word that a command follows (then, do, else, elif, if,
while, until, !, {) now counts as a command start, provided it starts a
command itself; `echo then case` still opens nothing.

Test "a case after then or do opens a case too" fails without this
change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0136P7ZkGCWGEyedTtdEHAPT
Codex on #1143: in `$(case esac in yes)# ...` the subject `esac` popped
:case, so the pattern's `)` closed the substitution and the comment
stayed visible.

`case` now pushes :case_head; the word `in` turns it into :case, and
only then does `esac` close it. A `)` under either state ends a pattern
and pops nothing.

Test "esac as the case subject does not close the case" fails without
this change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0136P7ZkGCWGEyedTtdEHAPT

Copy link
Copy Markdown
Owner Author

The red Integration Status on 42e6416 is on a superseded head. Its jobs were cancelled when ec9d330 and then 94c7968 were pushed, and the status job reports those cancellations as a failure. Only CI on the current head, 94c7968, counts.


Generated by Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 94c79682ec

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/hypatia/workflow.ex Resolved
Codex on #1143: `esac>/dev/null)` was not recognised as `esac`, so the
substitution's `)` was taken as another pattern end and the live
`#suffix --hypatia-ref` was masked. `<` and `>` now end the words
`case`, `in` and `esac`.

Test "esac with a redirection attached still closes the case" fails
without this change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0136P7ZkGCWGEyedTtdEHAPT

Copy link
Copy Markdown
Owner Author

Container Security (Trivy) (deploy/Containerfile) failed on 68c010d before any scan ran. The image build could not fetch its base image: Head "https://cgr.dev/v2/chainguard/wolfi-base/manifests/latest": … connection reset by peer. That is a registry or network failure, and this PR does not touch deploy/Containerfile. I will re-run that job once, after its workflow run finishes.


Generated by Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 68c010dd5f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/hypatia/workflow.ex Resolved
Comment thread lib/hypatia/workflow.ex Resolved
Comment thread lib/hypatia/workflow.ex Resolved
Comment thread lib/hypatia/workflow.ex Resolved
Codex on #1143:
- `time` and `coproc` join the reserved words a command follows.
- `(` ends the words `case`, `in` and `esac`, so `in(x)` enters the body.
- A separator escaped with a backslash (`\;`, `\` newline) is not a
  command start, so `echo \; case ...` opens nothing.

Each has a test that fails without the change. Not done: `case` as a
literal pattern alternative (`x|case)`) still opens a nested case;
telling a pattern position from a command position needs a real parser.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0136P7ZkGCWGEyedTtdEHAPT

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f010a27080

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/hypatia/workflow.ex Resolved
@hyperpolymath
hyperpolymath enabled auto-merge (squash) November 14, 2026 23:26
@sonarqubecloud

Copy link
Copy Markdown

@hyperpolymath
hyperpolymath merged commit 9af7f88 into main Nov 14, 2026
88 checks passed
@hyperpolymath
hyperpolymath deleted the claude/shell-mask-case-escape branch November 14, 2026 23:34

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3f7e944dea

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/hypatia/workflow.ex

defp mask(<<?), r::binary>>, nil, _, _, qs?, ps, acc) do
case ps do
[top | _] when top in [:case, :case_head] -> mask(r, nil, true, false, qs?, ps, [?) | acc])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recognize a nested case at the start of a case arm

When an outer arm starts a nested case on the same line, as in case a in a) case b in ..., this pattern-closing ) sets whitespace state but leaves no indication that the next token is at a command start, so command_start?/1 rejects the nested case. Its esac then pops the outer case state, and a later outer pattern ) can incorrectly close the surrounding $(...), leaving a following commented pin visible to check_hypatia_pin_drift; preserve the case-arm command-start context after this delimiter.

Useful? React with 👍 / 👎.

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