perf(scan): scan once and write both artifacts - #50
Open
joeymussalli wants to merge 1 commit into
Open
Conversation
The script ran two full scans of the target: one redirected to trustabl.sarif, one to trustabl.json. That is not needed. trustabl has --json-out and --sarif-out, which write their documents independently of --format, so a single run produces both. Cost aside, the two-scan arrangement had a correctness edge. Rules are fetched at scan time, so the two runs could resolve different rulesets -- the SARIF that gets uploaded and shown in the CodeCatalyst Reports tab and the JSON that decides the gate were describing two separate scans, with nothing checking that they agreed. On a large repository it also simply doubled the wall-clock and the compute bill of every build. There is a side benefit. Both runs previously redirected stdout to a file, so trustabl's own output never reached the build log at all -- everything a user saw came from this script's report box. With the machine documents going to --json-out/--sarif-out, --format human puts the scanner's own summary in the log where it belongs. - One invocation: --format human --json-out "$JSON_FILE" --sarif-out "$SARIF_FILE". - NATIVE_CODE still comes from that single run, so the gate is unaffected. Verified with a stub scanner that records its invocations: two full scans before (`--format sarif`, then `--format json`), one after, with both output files written and valid. Exit codes 0, 1 and 2 propagate to NATIVE_CODE exactly as before. bash -n passes. KNOWN CONFLICT. This touches the two scan invocations, and chore/remove-dead-code deletes the SCAN_END line immediately after them, so those two branches collide on one line. It is the only collision in the series and the resolution is to take both changes: no second scan, no SCAN_END. I tried stacking this on that branch instead, which removes the collision here but creates two larger ones against the gate and severity branches -- strictly worse, so this is left standalone. One compatibility note for reviewers: this requires a trustabl release that has --json-out/--sarif-out. VERSION defaults to "latest" so most users are covered, but anyone pinning an older tag would have the scan fail on the unknown flag. That fails closed -- a non-zero exit the gate reports -- rather than silently mis-reporting, which is the right direction, but it is a real consideration if you support older pinned versions and may warrant a documented minimum.
joeymussalli
force-pushed
the
perf/single-scan-both-outputs
branch
2 times, most recently
from
August 24, 2026 20:05
9705439 to
6865e94
Compare
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.
The script ran two full scans of the target: one redirected to trustabl.sarif, one to trustabl.json. That is not needed. trustabl has --json-out and --sarif-out, which write their documents independently of --format, so a single run produces both.
Cost aside, the two-scan arrangement had a correctness edge. Rules are fetched at scan time, so the two runs could resolve different rulesets -- the SARIF that gets uploaded and shown in the CodeCatalyst Reports tab and the JSON that decides the gate were describing two separate scans, with nothing checking that they agreed. On a large repository it also simply doubled the wall-clock and the compute bill of every build.
There is a side benefit. Both runs previously redirected stdout to a file, so trustabl's own output never reached the build log at all -- everything a user saw came from this script's report box. With the machine documents going to --json-out/--sarif-out, --format human puts the scanner's own summary in the log where it belongs.
Verified with a stub scanner that records its invocations: two full scans before (
--format sarif, then--format json), one after, with both output files written and valid. Exit codes 0, 1 and 2 propagate to NATIVE_CODE exactly as before. bash -n passes.One compatibility note for reviewers: this requires a trustabl release that has --json-out/--sarif-out. VERSION defaults to "latest" so most users are covered, but anyone pinning an older tag would have the scan fail on the unknown flag. That fails closed -- a non-zero exit the gate reports -- rather than silently mis-reporting, which is the right direction, but it is a real consideration if you support older pinned versions and may warrant a documented minimum.