fix(analyze): tolerate log noise before the SARIF JSON - #35
Merged
Merged
Conversation
The live preview cluster's E2E surfaced a real defect: when the gate blocks,
the PR comment said "0 findings / no parseable report" instead of listing
the findings. Root cause: ephpm analyze --format sarif writes its tracing
lines (ANSI-coloured INFO ...) to stdout, prepended to the SARIF JSON, so the
captured stdout is log noise followed by the document. serde_json fails on the
leading bytes -> 0 findings -> the fallback comment. The block itself is
correct (it comes from the exit code); only the finding detail was lost.
Fix (defensive; we do not trust the producer's stdout hygiene): in
parse_sarif_findings, skip to the first '{' and parse from there. No '{' at
all keeps today's graceful empty result. Exit-code->verdict mapping and block
behavior unchanged.
Tests: leading_log_noise_before_the_json_is_tolerated (ANSI-prefixed valid
SARIF -> findings extracted with expected rule_id/file/line) and
log_noise_with_no_json_object_is_the_graceful_empty_path (no '{' -> empty, no
panic). ESC bytes assembled at runtime.
|
ePHPm Preview — removed Preview deployment has been torn down. |
This branch was previously deployed
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.
What
Fixes a defect the live preview cluster's E2E surfaced: when the analyze gate blocks, the PR comment said "0 findings / no parseable report" instead of listing the findings.
Root cause
ephpm analyze --format sarifwrites its tracing lines (ANSI-colouredINFO …) to stdout, prepended to the SARIF JSON, so the captured stdout is:switchboard
serde_json-parses that verbatim → fails on the leading log bytes → 0 findings → the "no parseable report" fallback comment. The block itself is correct (the deny comes from the exit code); only the finding detail was lost.An ePHPm-side fix to route those logs to stderr is in flight, but switchboard must be robust to junk before the JSON regardless — we don't trust the producer's stdout hygiene for our own comment integrity.
Fix (defensive, no redesign)
In
parse_sarif_findings(src/analyze.rs): before deserializing, skip to the first{and parse from there. If there is no{at all, keep today's graceful empty result. The exit-code→verdict mapping and block behavior are unchanged — this is finding-detail extraction only.Tests
leading_log_noise_before_the_json_is_tolerated— a valid SARIF document prefixed with ANSI-colouredtracinglog lines (ESC bytes assembled at runtime) yields the finding with the expectedrule_id/file/line.log_noise_with_no_json_object_is_the_graceful_empty_path— junk with no{yields the empty result, no panic.unparseable_or_empty_sarif_yields_no_findingsstill passes ("",not json,{}).cargo fmt --check,cargo clippy --all-targets -- -D warnings, andcargo test(309 pass) all green.Do not merge / do not deploy — over to the coordinator to merge, rebuild, and redeploy the nodes.