test: handle CRLF in stale identity guard - #2741
Open
abhinavkr26104 wants to merge 2 commits into
Open
Conversation
|
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 1 file
Architecture diagram
sequenceDiagram
participant Test as Test Suite
participant Guard as Stale Identity Guard
participant Parser as Match Parser
participant Grep as Git Grep
participant Allowlist as Legacy Allowlist
Note over Test,Allowlist: CRLF/LF Line Ending Handling in Stale Identity Check
Test->>Guard: Run "does not reintroduce" test
Guard->>Grep: Execute git grep pattern
alt Grep exits with code 1 (matches found)
Grep-->>Guard: stdout with results
Guard->>Parser: findUnexpectedMatches(stdout)
Parser->>Parser: Trim output and split on /\r?\n/u
Parser->>Parser: Filter empty lines
loop Each match line
Parser->>Parser: Parse file, line number, contents
alt Parsed successfully
Parser->>Parser: Build identity string
Parser->>Allowlist: Check if identity is allowed
alt Identity in allowlist
Allowlist-->>Parser: Allowed
Parser->>Parser: Filter out match
else Identity not in allowlist
Allowlist-->>Parser: Not allowed
Parser->>Parser: Keep match
end
else Parse failed
Parser->>Parser: Keep original match
end
end
Parser-->>Guard: Unexpected matches list
Guard-->>Test: Assert no unexpected matches
else Grep exits with code 0 (no matches)
Grep-->>Guard: Empty stdout
Guard-->>Test: Empty unexpected list
end
Note over Test,Allowlist: Regression Test with CRLF Line Endings
Test->>Parser: findUnexpectedMatches with CRLF joined output
Parser->>Parser: Split on CRLF correctly
Parser->>Allowlist: Verify exact legacy cleanup matches
Allowlist-->>Parser: All identities allowed
Parser-->>Test: Empty unexpected list
Test->>Test: Assert no unexpected matches
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
why
The stale-identity guard split
git grepoutput only on\n. Windows CRLF output therefore left a trailing\ron every line except the last, causing explicitly allowed legacy cleanup strings to be reported as forbidden identities.Fixes #2735
what changed
test plan
vitest run rules/ast-grep/stale-identity.test.ts --reporter=verbose(2 passed on Windows)rules/ast-grepsuite (7 files passed, 35 tests passed)git diff --checkSummary by cubic
Parses CRLF line endings in the stale identity guard test to avoid Windows-only false positives. Previously we split
git grepoutput on LF only; now we split on LF or CRLF via a shared parser.findUnexpectedMatchesto parse matches consistently.Written for commit 36a4c3f. Summary will update on new commits.