Skip to content

Commit 9a9c91e

Browse files
committed
Address review: clean up new-findings temp file, test group ordering
- Remove the new-findings temp file via an EXIT trap (path baked into the trap so it survives the local going out of scope under set -u). - Add a regression test asserting same-(rule,file) findings interleaved with another key still group correctly (jq group_by sorts internally, so it is order-independent; this guards that guarantee).
1 parent 0611665 commit 9a9c91e

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

sast/opengrep/scripts/opengrep-report.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,10 @@ main() {
553553
# New findings = head full scan minus baseline full scan, by stable identity.
554554
local new_json
555555
new_json=$(mktemp)
556+
# Bake the path into the trap now (double quotes): the EXIT trap fires in the
557+
# global scope where this local would be unbound under `set -u`.
558+
# shellcheck disable=SC2064 # intentional: expand $new_json at definition time
559+
trap "rm -f '$new_json'" EXIT
556560
compute_new_findings "$baseline_json" "$head_json" "$new_json"
557561

558562
local new_count all_count scanned_count

sast/opengrep/tests/report-diff-test.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ expect "second finding same rule+file -> 1 new" 1 1 \
8080
"$(results_doc "$(finding run.yml 5 'echo a')")" \
8181
"$(results_doc "$(finding run.yml 5 'echo a')" "$(finding run.yml 50 'echo NEW')")"
8282

83+
# Same-key findings interleaved with another key in the results array must
84+
# still group correctly (jq's group_by sorts internally; scan output order is
85+
# not guaranteed). run.yml gains one finding; other.yml is unchanged.
86+
expect "interleaved same-key findings -> 1 new" 1 1 \
87+
"$(results_doc "$(finding run.yml 5 'echo a')" "$(finding other.yml 1 'echo z')")" \
88+
"$(results_doc "$(finding run.yml 5 'echo a')" "$(finding other.yml 1 'echo z')" "$(finding run.yml 50 'echo NEW')")"
89+
8390
# Empty baseline (unavailable) -> every head finding is new (conservative).
8491
expect "empty baseline -> all new" 2 1 \
8592
'{"results":[],"errors":[],"paths":{}}' \

0 commit comments

Comments
 (0)