Skip to content

fix(critcheck): treat BSD grep regex errors as malformed checks - #198

Open
pcbeingused333 wants to merge 1 commit into
Agent-Field:mainfrom
pcbeingused333:fix/bsd-grep-regex-errors
Open

pcbeingused333 wants to merge 1 commit into
Agent-Field:mainfrom
pcbeingused333:fix/bsd-grep-regex-errors

Conversation

@pcbeingused333

Copy link
Copy Markdown

Fixes #192

Summary

  • Malformed recognized GNU grep and ripgrep regex failures (Unmatched, Invalid regular expression, Trailing backslash, regex parse error) and option errors. It did not recognize BSD grep.
  • macOS ships BSD grep. The same refusal comes from regerror(3) in lowercase: parentheses not balanced, brackets ([ ]) not balanced, trailing backslash (\), and the other pattern-compile errors (braces not balanced, invalid regular expression, invalid character class, invalid character range, invalid backreference number, invalid repetition count(s), invalid collating element, repetition-operator operand invalid, empty (sub)expression).
  • A criterion such as grep -E 'Checksum(' file therefore stayed a real failure on macOS, and TestAMalformedCheckWithNoRepairIsNotCounted failed there because it re-runs grep. Those lines are now usage errors, same as the GNU wording. A missing file (No such file or directory) and out of memory stay real failures. Exit status 2 alone is not enough: grep uses it for both.

Testing and validation

  • TestMalformedTellsUsageFromAssertion covers each BSD regerror line above, plus egrep:, and keeps a missing file and out of memory as assertions.
  • TestABSDGrepRegexErrorIsNotCounted re-runs `grep -E 'Checksum(' ledger.go` with tool output grep: parentheses not balanced and expects the criterion not counted.
  • TestAMissingGrepTargetStaysARealFailure keeps grep: ledger.go: No such file or directory as a failure.
  • Before the signature change, TestABSDGrepRegexErrorIsNotCounted and TestMalformedTellsUsageFromAssertion failed. After it, go test -race -count=1 ./internal/critcheck passed (23 tests). The existing GNU case still passes on a host whose grep prints Unmatched (.

Behavior Impact

  • Backward compatible behavior change

A malformed grep or egrep pattern is not counted on macOS as well as on Linux. A check that runs and fails, including a missing path, is unchanged.

AI assistance was used to prepare this change and its tests.

macOS grep reports "parentheses not balanced" and a lowercase
"trailing backslash" when it refuses a pattern. Those lines were
not usage errors, so a malformed grep criterion counted as a
real failure.

Fixes Agent-Field#192
Fixes Agent-Field#190
@AbirAbbas

Copy link
Copy Markdown
Collaborator

Thanks! Before we can review this, please sign the SWE-AF CLA: https://cla-assistant.io/Agent-Field/SWE-AF?pullRequest=198 (it's separate from the agentfield one).

@pcbeingused333

Copy link
Copy Markdown
Author

@AbirAbbas the CLA is signed and the check is green now.

This branch has not been deployed

No deployments
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.

critcheck does not recognise BSD grep's regex errors, so malformed checks count as failures on macOS

2 participants