Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .claude/skills/deep-code-review/scripts/review_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,14 @@ for t in data:
k = key(t) or fkey(t)
if not k or len(groups[k]) <= 3: out.append(row(t))
elif k not in done: done.add(k); out.append(summ(k, groups[k]) if key(t) else fsumm(k, groups[k]))
# Corroboration: when different tools flag the same normalized file:line, every such row gets a "tools" list and a " [corroborated by: ...]" suffix. No row is dropped or merged. not-checked, summary, line<=0 and per-file-summary rows are skipped.
cg = {}
for r in out:
if r["rule"] != "not-checked" and not r["rule"].endswith("-summary") and r["line"] > 0 and r["file"] not in ("", "-") and "_lines" not in r: cg.setdefault((os.path.normpath(r["file"]), r["line"]), []).append(r)
for g in cg.values():
ts = sorted({r["tool"].removesuffix("-history") for r in g}) # gitleaks and gitleaks-history are one scanner
if len(ts) > 1:
for r in g: r["tools"] = ts; sfx = f" [corroborated by: {', '.join(ts)}]"; r["message"] += sfx; r["text"] += sfx
ML = [r.pop("_lines", None) for r in out] # per-file summary rows: every member line; popped here in every mode so the key never prints
ud = sys.argv[11] # `git diff -U0` of BASE...HEAD; "" under --full/--history or when a git read above failed (no "new" key)
if ud:
Expand Down
2 changes: 2 additions & 0 deletions changelog.d/hub-corroboration-dedup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Changed
- review_checks.sh marks findings that several tools report on the same file and line: every such row gets a `tools` list and a "[corroborated by: ...]" message suffix. No row is dropped or merged, so per-tool row consumers are unaffected. scripts/test-review-checks-hub-dedup.sh covers it.
2 changes: 2 additions & 0 deletions scripts/ci-tests.d/review-checks-hub-dedup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Registers the review_checks.sh hub corroboration test (same file:line from several tools is marked, no row dropped).
bash scripts/test-review-checks-hub-dedup.sh
61 changes: 61 additions & 0 deletions scripts/test-review-checks-hub-dedup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash
# review_checks.sh hub corroboration: semgrep, zizmor and actionlint rows on the same file:line keep one row each, all marked with the three tools
# and a corroborated-by suffix; no row is dropped; a different line is unmarked, and one tool on two lines is not corroboration. Stub tools on a
# hermetic PATH, fictional workflow content only.
set -euo pipefail
ROOT=$(cd "$(dirname "$0")/.." && pwd)
RC=${REVIEW_CHECKS:-$ROOT/.claude/skills/deep-code-review/scripts/review_checks.sh}
T=$(mktemp -d "${TMPDIR:-/tmp}/hubdedup.XXXXXX") && [ -n "$T" ] && [ -d "$T" ] || { echo "no temp dir" >&2; exit 1; }
trap 'cd /; rm -r -- "$T"' EXIT
fail=0
export DCR_CACHE_ROOT="$T/nocache" DCR_USER_BIN= PERUN_HEAVY_DIR="$T/heavy" REVIEW_LEASE_WAIT=0 REVIEW_SEMGREP_REGISTRY=0
unset REVIEW_OSV REVIEW_OSV_DB_DIR OSV_SCANNER_LOCAL_DB_CACHE_DIRECTORY REVIEW_SEMGREP_CONFIG REVIEW_FIXTURE_ROWS REVIEW_TEST_CMD
G() { git -c user.email=t@example.com -c user.name=t "$@"; }
mkdir -p "$T/bin" "$T/zbin" "$T/sys"
for b in bash env git grep sed head tail cat rm mkdir mktemp dirname basename python3 perl timeout gtimeout jq true sort uniq paste tr cut wc awk date cp mv ls find touch tee readlink sleep cmp nice uname; do
p=$(type -P "$b") || continue; ln -s "$p" "$T/sys/$b" # only the system binaries review_checks.sh needs, never the host PATH
done
cat >"$T/bin/semgrep" <<'S'
#!/usr/bin/env bash
cat "$SG_JSON"
S
cat >"$T/bin/zizmor" <<'S'
#!/usr/bin/env bash
cat "$ZZ_JSON"; exit 13
S
cat >"$T/bin/actionlint" <<'S'
#!/usr/bin/env bash
cat "$AL_JSON"; exit 1
S
cat >"$T/bin/gitleaks" <<'S'
#!/usr/bin/env bash
rep=; a=("$@"); for i in "${!a[@]}"; do [ "${a[$i]}" = -r ] && rep=${a[$((i + 1))]}; done
cat "${GL_JSON:-/dev/null}" >"$rep"
S
chmod +x "$T/bin/"*
WF=.github/workflows/ci.yml
mkdir -p "$T/repo" && cd "$T/repo" && git init -q . && G commit -q --allow-empty -m base && git branch base
mkdir -p .github/workflows && printf 'name: acme-ci\non: push\njobs:\n build:\n runs-on: ubuntu-latest\n steps:\n - uses: actions/checkout@v4\n - run: make test\n - run: make lint\n - run: make pack\n' >"$WF"
G add -A && G commit -q -m change
# sg LINE...: one semgrep row per line, message "low: ..."; zz ROW0...: zizmor rows (0-based); al LINE...: actionlint rows, message "error: ..."
sg() { local r= l; for l in "$@"; do r+="${r:+,}{\"check_id\":\"acme-rule\",\"path\":\"$WF\",\"start\":{\"line\":$l},\"extra\":{\"message\":\"low: mutable tag\"}}"; done; printf '{"results":[%s],"errors":[],"paths":{"scanned":["%s"]}}\n' "$r" "$WF"; }
zz() { local r= l; for l in "$@"; do r+="${r:+,}{\"ident\":\"unpinned-uses\",\"desc\":\"d\",\"locations\":[{\"symbolic\":{\"kind\":\"Primary\",\"key\":{\"Local\":{\"verbatim_path\":\"$WF\"}}},\"concrete\":{\"location\":{\"start_point\":{\"row\":$l}}}}]}"; done; printf '[%s]\n' "$r"; }
al() { local r= l; for l in "$@"; do r+="${r:+,}{\"message\":\"error: bad step\",\"filepath\":\"$WF\",\"line\":$l,\"kind\":\"expression\"}"; done; printf '[%s]\n' "$r"; }
go() { PATH="$T/bin:$T/sys" GL_JSON="${GL_JSON:-}" SG_JSON="$T/sg.json" ZZ_JSON="$T/zz.json" AL_JSON="$T/al.json" bash "$RC" --base base ${GO_ARGS:-} >"$T/out" 2>"$T/err" || true; }
at() { jq -c --argjson l "$1" '[.[] | select(.line==$l and .rule!="not-checked")]' "$T/out"; }
eq() { if [ "$1" = "$2" ]; then echo "ok - $3"; else echo "FAIL - $3 (got $1, want $2)"; fail=1; fi; }

sg 5 >"$T/sg.json"; zz 4 >"$T/zz.json"; al 5 >"$T/al.json"; go # all three on line 5
eq "$(at 5 | jq length)" 3 "3 tools, same line: all 3 rows kept"
eq "$(at 5 | jq -r '[.[].tools | sort | join(",")] | unique | join(";")')" "actionlint,semgrep,zizmor" "every row names all 3 tools"
eq "$(at 5 | jq -r 'all(.[]; .message | test("\\[corroborated by: actionlint, semgrep, zizmor\\]$"))')" true "every message carries the suffix"

sg 5 9 >"$T/sg.json"; zz 99 >"$T/zz.json"; al 99 >"$T/al.json"; go # only semgrep has rows on 5 and 9
eq "$(at 5 | jq length)$(at 9 | jq length)" 11 "one tool, 2 lines: 2 rows"
eq "$(jq '[.[] | select(.tools)] | length' "$T/out")" 0 "one tool alone is not corroborated"
eq "$(jq '[.[] | select(.tool=="semgrep")] | length' "$T/out")" 2 "no merge across lines"
printf '[{"RuleID":"acme-key","Description":"d","File":"%s","StartLine":5,"Fingerprint":"fp1"}]\n' "$WF" >"$T/gl.json"
sg 90 >"$T/sg.json"; zz 80 >"$T/zz.json"; al 70 >"$T/al.json"; GL_JSON="$T/gl.json" GO_ARGS=--history go # gitleaks (tree) + gitleaks-history on line 5
eq "$(jq '[.[] | select(.tool|test("^gitleaks"))] | length' "$T/out")" 2 "gitleaks and gitleaks-history rows both present"
eq "$(jq '[.[] | select(.tools)] | length' "$T/out")" 0 "gitleaks + gitleaks-history alone is not corroboration"
exit $fail
2 changes: 1 addition & 1 deletion scripts/test_route_auth_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -2180,7 +2180,7 @@ def repo(name, files):
r = subprocess.run(["bash", str(RC), "--full", "--repo", str(repo("g", FX))], capture_output=True, text=True, env=env)
rows = [x for x in json.loads(r.stdout) if x["tool"] == "route-auth"]
want = {g.split(": HIGH: ")[0] + "|" + g.split(": HIGH: ")[1] for g in self.gold if ": HIGH: " in g}
got = {"%s:%d|%s" % (x["file"], x["line"], x["message"]) for x in rows}
got = {"%s:%d|%s" % (x["file"], x["line"], re.sub(r" \[corroborated by: [^\]]*\]$", "", x["message"])) for x in rows}
self.assertEqual(got, want)
self.assertEqual({x["rule"] for x in rows}, {"missing-auth"})
self.assertIn("route-auth: heuristic; scanned %d handlers; silence is not proof of authentication" % len(self.gold), r.stderr)
Expand Down
Loading