Skip to content

fix(analyze): tolerate log noise before the SARIF JSON - #35

Merged
luthermonson merged 1 commit into
mainfrom
fix/sarif-lenient-parse
Sep 14, 2026
Merged

luthermonson merged 1 commit into
mainfrom
fix/sarif-lenient-parse

Conversation

@luthermonson

Copy link
Copy Markdown
Contributor

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 sarif writes its tracing lines (ANSI-coloured INFO …) to stdout, prepended to the SARIF JSON, so the captured stdout is:

<ESC>[2m2026-…Z<ESC>[0m  INFO analyzer skipped analyzer=wp-vuln reason=…
{
  "$schema": "https://json.schemastore.org/sarif-2.1.0.json",
  ...

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-coloured tracing log lines (ESC bytes assembled at runtime) yields the finding with the expected rule_id/file/line.
  • log_noise_with_no_json_object_is_the_graceful_empty_path — junk with no { yields the empty result, no panic.
  • Existing unparseable_or_empty_sarif_yields_no_findings still passes ("", not json, {}).

cargo fmt --check, cargo clippy --all-targets -- -D warnings, and cargo test (309 pass) all green.

Do not merge / do not deploy — over to the coordinator to merge, rebuild, and redeploy the nodes.

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

ephpm Bot commented Sep 14, 2026

Copy link
Copy Markdown

ePHPm Preview — removed

Preview deployment has been torn down.

@ephpm
ephpm Bot temporarily deployed to preview-pr-35 September 14, 2026 00:21 Inactive
@ephpm
ephpm Bot temporarily deployed to preview-pr-35 September 14, 2026 00:21 Inactive
@luthermonson
luthermonson merged commit 0d37621 into main Sep 14, 2026
4 checks passed
@luthermonson
luthermonson deleted the fix/sarif-lenient-parse branch September 14, 2026 00:25

This branch was previously deployed

1 inactive deployment
preview-pr-35 9ee983a6 Deployed Sep 14, 2026 by ephpm[bot]
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.

1 participant