Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

fix(ci): parse clang-tidy analyzer warning suffix

Your GitHub Username7aeacae908e1
diff --git a/scripts/lint-mem-gate.py b/scripts/lint-mem-gate.py
index 140062f37..d5ccd76d2 100755
--- a/scripts/lint-mem-gate.py
+++ b/scripts/lint-mem-gate.py
@@ -47,7 +47,15 @@ WHITELIST = Path(os.environ.get(
MIN_WHY = 120
MIN_TRIED = 40
-FINDING_RE = re.compile(r"^(?P<file>[^:]+):(?P<line>\d+):\d+:\s+(?:error|warning):\s+(?P<msg>.*?)\s*\[(?P<check>[\w.-]+)\]\s*$")
+# With WarningsAsErrors enabled, clang-tidy appends the escalation reason to
+# analyzer checks, for example:
+# [clang-analyzer-core.NullDereference,-warnings-as-errors]
+# Keep the check name separate from that suffix so the gate still matches the
+# same whitelist key instead of silently dropping the finding.
+FINDING_RE = re.compile(
+ r"^(?P<file>[^:]+):(?P<line>\d+):\d+:\s+(?:error|warning):\s+"
+ r"(?P<msg>.*?)\s*\[(?P<check>[\w.-]+)(?:,-warnings-as-errors)?\]\s*$"
+)
def strip_noise(text):
diff --git a/tests/test_lint_mem_gate.sh b/tests/test_lint_mem_gate.sh
new file mode 100755
index 000000000..05c2bd4a3
--- /dev/null
+++ b/tests/test_lint_mem_gate.sh
@@ -0,0 +1,39 @@
+#!/usr/bin/env bash
+# Regression contract for clang-tidy's `,-warnings-as-errors` diagnostic suffix.
+set -euo pipefail
+
+ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
+FIX="$(mktemp -d "${TMPDIR:-/tmp}/lint-mem-gate.XXXXXX")"
+trap 'rm -rf "$FIX"' EXIT
+
+cat > "$FIX/sample.c" <<'EOF'
+int sample(int *value) {
+ return *value;
+}
+EOF
+
+cat > "$FIX/whitelist.txt" <<EOF
+## $FIX/sample.c :: sample :: clang-analyzer-core.NullDereference
+segment-sha256: PLACEHOLDER
+why: |
+ The test deliberately models a diagnostic that is suppressed by the fixture whitelist.
+ This text is long enough to exercise the gate's normal argument validation path.
+tried: |
+ The fixture is intentionally minimal and only verifies diagnostic parsing.
+EOF
+
+HASH="$(LINT_MEM_WHITELIST="$FIX/whitelist.txt" python3 "$ROOT/scripts/lint-mem-gate.py" --hash "$FIX/sample.c" sample | awk '/^segment-sha256:/ {print $2}')"
+python3 - "$FIX/whitelist.txt" "$HASH" <<'PY'
+from pathlib import Path
+import sys
+
+path = Path(sys.argv[1])
+text = path.read_text(encoding="utf-8").replace("PLACEHOLDER", sys.argv[2])
+path.write_text(text, encoding="utf-8")
+PY
+
+printf '%s\n' "$FIX/sample.c:2:12: warning: possible null dereference [clang-analyzer-core.NullDereference,-warnings-as-errors]" \
+ | LINT_MEM_WHITELIST="$FIX/whitelist.txt" python3 "$ROOT/scripts/lint-mem-gate.py" 2> "$FIX/stderr"
+
+grep -q 'memory gate clean (1 argued false positive' "$FIX/stderr"
+echo 'lint-mem-gate warning suffix contract passed'