Fix review parser extracting wrong JSON from stream-json - #155
Conversation
There was a problem hiding this comment.
AI Code Review
The PR addresses the core issue well with good test coverage, but contains a backslash escape logic bug that could cause JSON parsing failures on strings with escaped characters.
Issues found: warning: 1
This is an automated review. Please evaluate suggestions carefully.
— Authored by egg
Additional comments (lines not in diff)
- action/post-review-comments.sh:144 [warning/correctness] The condition
c == '\\\\'checks for two backslashes, but should check for a single backslash. In Python string literals,'\\\\'represents two literal backslashes. Change toc == '\\'(one pair of backslashes = one literal backslash). This bug prevents proper handling of escaped quotes/backslashes in JSON, potentially causing false negatives in JSON detection.
There was a problem hiding this comment.
Disagree. The \\\\ (four backslashes in the shell script) is correct. There are two escaping layers here:
- Bash double-quote processing:
\\\\→\\(each\\pair becomes one\) - Python string literal:
'\\'→ single backslash character
So c == '\\\\' in the file correctly checks for a single backslash at runtime. The bot's suggestion to use \\ (two backslashes) would actually break the code — bash would reduce it to \, giving Python c == '\' which is a SyntaxError: unterminated string literal.
This applies equally to the '\"' on the next line — \" in the file becomes " after bash processing, which is correct.
No changes needed.
— Authored by egg
Fix review parser matching template JSON from PR diffs
The
extract_review_json()function scans the entire log file for JSONobjects with
summary+commentsfields. When the PR diff contains fileslike
security-review.mdwith example/template JSON, the parser matchesthat template instead of Claude's actual review output. This caused PR #152
to receive "No security vulnerabilities found" despite Claude producing a
detailed 8-finding review.
The fix changes
extract_review_json()to parse stream-json format first:it reads lines looking for
{"type": "result", ...}events and extractsthe
resultfield (Claude's actual final text), then searches only thattext for review JSON. If no stream-json result event is found, it falls
back to the existing full-text scan for backward compatibility.
Issue: none
Test plan:
bash action/test_extract_review_json.sh— 7 tests covering:Authored-by: egg