#!/usr/bin/env bash # # Gate a fix using pipe itself as the oracle. # # scripts/gate_fixed.sh [key value] # # Exits 0 when the finding is gone: # - with no key/value: the rule reports nothing at all for the repo # - with key/value: no finding for that rule has data[key] == value # # Prefers a built binary (AOT startup is ~30x faster) and falls back to `dart run`. set -euo pipefail if [ "$#" -lt 2 ]; then echo "usage: scripts/gate_fixed.sh [key value]" >&2 exit 2 fi repo="$1" rule="$2" key="${3:-}" value="${4:-}" pipe_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" binary="" for candidate in "$pipe_root"/build/cli/*/bundle/bin/pipe "$pipe_root"/build/pipe; do if [ -x "$candidate" ]; then binary="$candidate" break fi done json="$(mktemp)" trap 'rm -f "$json"' EXIT if [ -n "$binary" ]; then "$binary" check "$repo" -c 8 --rule "$rule" --format json >"$json" else (cd "$pipe_root" && dart run bin/pipe.dart check "$repo" -c 8 --rule "$rule" --format json) >"$json" fi python3 - "$json" "$repo" "$rule" "$key" "$value" <<'PY' import json import sys path, repo, rule, key, value = sys.argv[1:6] with open(path) as handle: report = json.load(handle) findings = [f for f in report.get('findings', []) if f.get('rule') == rule] if key: findings = [f for f in findings if str(f.get('data', {}).get(key)) == value] target = f'{rule}' + (f' {key}={value}' if key else '') if findings: print(f'GATE FAIL: {len(findings)} finding(s) still present for {target}') for finding in findings[:8]: print(f" - {finding.get('file')}:{finding.get('line')} " f"{finding.get('data', {}).get('variant') or finding.get('data', {}).get('event') or ''}") sys.exit(1) print(f'GATE PASS: nothing reported for {target}') PY