Skip to content

Commit 61ab160

Browse files
runningcodeclaude
andcommitted
ci(lint): Add decision-model-linter with SDK review rules
Adds rules that a small model answers from the changed lines of one file: exception handling, PII, tests, public API annotations, Kotlin interop, Android, instrumentation, resources and time, and Gradle build logic. Rules that a parser can decide stay with detekt, Error Prone and Spotless, and rules that need reading across files stay with Warden. Every rule starts at warn, so findings are reported but never fail the check. A file the model could not check fails the check, so a green run means every changed file was reviewed. Fork PRs get no secrets and skip the lint. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 413c889 commit 61ab160

15 files changed

Lines changed: 493 additions & 0 deletions
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Decision model lint
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize, labeled, unlabeled]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.event.number }}
9+
cancel-in-progress: true
10+
11+
permissions: {}
12+
13+
jobs:
14+
lint:
15+
name: Decision model lint
16+
# Never pull_request_target, which would give a pull request's code the key. Forks get no
17+
# secrets, so skip them. Every label change re-runs the lint, because a skipped run would
18+
# replace the last result.
19+
if: github.event.pull_request.head.repo.full_name == github.repository
20+
runs-on: ubuntu-latest
21+
timeout-minutes: 15
22+
permissions:
23+
contents: read
24+
pull-requests: write # to keep one comment with the findings
25+
steps:
26+
# The pull request's merge commit and its first parent: HEAD^1..HEAD is what it changes.
27+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
28+
with:
29+
fetch-depth: 2
30+
persist-credentials: false
31+
32+
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
33+
with:
34+
node-version: '24'
35+
36+
- run: npm ci --prefix lint --ignore-scripts
37+
38+
- name: Lint
39+
env:
40+
OPENROUTER_API_KEY: ${{ secrets.WARDEN_OPENROUTER_API_KEY }}
41+
GH_TOKEN: ${{ github.token }}
42+
PR: ${{ github.event.number }}
43+
LABEL: Override decision model lint
44+
OVERRIDDEN: "${{ contains(github.event.pull_request.labels.*.name, 'Override decision model lint') }}"
45+
run: |
46+
report="$RUNNER_TEMP/decision-model-lint.md"
47+
status=0
48+
lint/node_modules/.bin/decision-model-linter --config lint/decision-model-linter.config.ts \
49+
--base HEAD^1 --format markdown > "$report" || status=$?
50+
51+
# Only 1 means findings; any other failure means the linter did not finish.
52+
if [ "$status" -eq 1 ] && [ "$OVERRIDDEN" = true ]; then
53+
printf '\nThe `%s` label keeps these errors from failing the check.\n' "$LABEL" >> "$report"
54+
elif [ "$status" -eq 1 ]; then
55+
printf '\nThese errors fail the check; fix the code to resolve them. If you and a reviewer are confident an error is wrong, a person can add the `%s` label to pass the check while the findings stay reported. Agents should never add this label.\n' "$LABEL" >> "$report"
56+
elif [ "$status" -gt 1 ] && [ "$OVERRIDDEN" = true ]; then
57+
printf 'The linter did not finish (exit %s), and the `%s` label passes the check anyway; see the job log.\n' "$status" "$LABEL" >> "$report"
58+
fi
59+
60+
marker='<!-- decision-model-linter -->'
61+
comment=$(gh api "repos/$GITHUB_REPOSITORY/issues/$PR/comments" --paginate \
62+
--jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | contains(\"$marker\"))) | .id" | head -n 1)
63+
body=
64+
if [ -s "$report" ] && { [ "$status" -le 1 ] || [ "$OVERRIDDEN" = true ]; }; then
65+
body=$(printf '%s\n%s' "$marker" "$(cat "$report")")
66+
elif [ "$status" -eq 0 ] && [ -n "$comment" ]; then
67+
body=$(printf '%s\nNo findings on the latest commit.' "$marker")
68+
fi
69+
if [ -n "$body" ] && [ -n "$comment" ]; then
70+
gh api -X PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$comment" -f body="$body" > /dev/null
71+
elif [ -n "$body" ]; then
72+
gh api "repos/$GITHUB_REPOSITORY/issues/$PR/comments" -f body="$body" > /dev/null
73+
fi
74+
cat "$report" >> "$GITHUB_STEP_SUMMARY"
75+
76+
if [ "$status" -ne 0 ] && [ "$OVERRIDDEN" = true ]; then exit 0; fi
77+
exit "$status"

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ agents.lock
3737

3838
# Warden local run logs
3939
.warden/logs/
40+
41+
# decision-model-linter dependencies
42+
lint/node_modules/
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Questions a decision model answers about each changed file on a pull request. Rules here need only
2+
// the changed lines of one file, and need judgment: anything a parser can decide (banned calls or
3+
// imports, formatting, unused code) belongs in Spotless, detekt, Error Prone, or Android Lint. Rules
4+
// that need reading across files belong in the Warden `java-sdk-review` skill.
5+
import type { Config, Model } from "@sentry/decision-model-linter";
6+
7+
import android from "./suites/android.ts";
8+
import gradle from "./suites/gradle.ts";
9+
import instrumentation from "./suites/instrumentation.ts";
10+
import kotlinInterop from "./suites/kotlin-interop.ts";
11+
import publicApi from "./suites/public-api.ts";
12+
import resources from "./suites/resources.ts";
13+
import safety from "./suites/safety.ts";
14+
import tests from "./suites/tests.ts";
15+
16+
const jev = {
17+
provider: "openrouter",
18+
name: "typesafe/jev-1.13",
19+
apiKey: process.env.OPENROUTER_API_KEY,
20+
maxInputTokens: 32_768,
21+
} satisfies Model;
22+
23+
export default {
24+
model: jev,
25+
threshold: 0.7,
26+
// A file the model could not check must never look like a clean pass.
27+
unchecked: "error",
28+
ignores: [
29+
"**/build/**",
30+
"**/generated/**",
31+
// Samples and test helpers ship no SDK code.
32+
"sentry-samples/**",
33+
"sentry-android-integration-tests/**",
34+
"sentry-test-support/**",
35+
"sentry-system-test-support/**",
36+
// Build logic is not SDK code; only the gradle suite lints it again.
37+
"build-logic/**",
38+
"buildSrc/**",
39+
],
40+
suites: { safety, tests, publicApi, kotlinInterop, android, instrumentation, resources, gradle },
41+
} satisfies Config;

‎lint/files.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// The linter's globs have no brace expansion, so each extension is its own glob.
2+
export const MAIN_JAVA = ["**/src/main/**/*.java"];
3+
export const MAIN_KOTLIN = ["**/src/main/**/*.kt"];
4+
export const MAIN_SOURCES = [...MAIN_JAVA, ...MAIN_KOTLIN];
5+
export const TEST_SOURCES = [
6+
"**/src/test/**/*.java",
7+
"**/src/test/**/*.kt",
8+
"**/src/androidTest/**/*.java",
9+
"**/src/androidTest/**/*.kt",
10+
];

‎lint/package-lock.json‎

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lint/package.json‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"private": true,
3+
"type": "module",
4+
"devDependencies": {
5+
"@sentry/decision-model-linter": "0.3.0"
6+
}
7+
}

‎lint/suites/android.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { Suite } from "@sentry/decision-model-linter";
2+
3+
import { yesNo } from "../yes-no.ts";
4+
5+
export default {
6+
files: ["sentry-android*/**/src/main/**/*.java", "sentry-android*/**/src/main/**/*.kt"],
7+
context: { minSdk: "The SDK's minSdk is 21." },
8+
rules: {
9+
missingRequiresApi: yesNo(
10+
"Do the new lines add a class or method that calls Android APIs newer than `minSdk` and only runs " +
11+
"on those API levels, without `@RequiresApi`?",
12+
"Code that only runs above minSdk is missing `@RequiresApi`.",
13+
"The new lines call no API newer than minSdk, or are annotated `@RequiresApi`.",
14+
"Annotate it with `@RequiresApi(...)` so Lint catches callers that don't check the SDK version.",
15+
),
16+
redundantNewApiSuppression: yesNo(
17+
"Do the new lines add `@SuppressLint(\"NewApi\")` or `@SuppressWarnings(\"NewApi\")` to code where an " +
18+
"SDK version check already guards the call?",
19+
"A NewApi suppression is added where a version check already guards the call.",
20+
"The new lines add no NewApi suppression, or the suppression is needed.",
21+
"Remove the suppression. The version check already satisfies Lint, and the suppression would hide " +
22+
"future unguarded calls.",
23+
),
24+
},
25+
} satisfies Suite;

‎lint/suites/gradle.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Banned calls such as `afterEvaluate`, `tasks.create`, or string dependency coordinates belong in
2+
// detekt, not here: a parser decides them without a model.
3+
import type { Suite } from "@sentry/decision-model-linter";
4+
5+
import { yesNo } from "../yes-no.ts";
6+
7+
export default {
8+
files: ["**/*.gradle.kts", "build-logic/**/*.kt", "buildSrc/**/*.kt"],
9+
// The config ignores build logic for the SDK suites; lint it again here.
10+
ignores: ["!build-logic/**", "!buildSrc/**"],
11+
rules: {
12+
configurationCacheHazard: yesNo(
13+
"Do the new lines read a hard-coded local path (such as `~/.m2` or a user directory), or read " +
14+
"`project`, system properties, or environment variables at execution time in a way that breaks " +
15+
"the configuration cache?",
16+
"Build logic reads local paths or breaks the configuration cache.",
17+
"The new lines read no local paths and stay configuration-cache compatible.",
18+
"Use providers (`providers.environmentVariable`, `layout`) and avoid machine-specific paths.",
19+
),
20+
raisedSupportFloor: yesNo(
21+
"Do the new lines raise `minSdk`, the Java or JVM target level, or the lowest supported version of " +
22+
"a framework the SDK integrates with?",
23+
"A support floor is raised.",
24+
"No support floor is raised.",
25+
"Raising a support floor drops customers. Make sure the PR calls it out and `CHANGELOG.md` (and " +
26+
"`MIGRATION.md` if needed) says so.",
27+
),
28+
},
29+
} satisfies Suite;

‎lint/suites/instrumentation.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import type { Suite } from "@sentry/decision-model-linter";
2+
3+
import { MAIN_KOTLIN, MAIN_SOURCES } from "../files.ts";
4+
import { yesNo } from "../yes-no.ts";
5+
6+
export default {
7+
files: MAIN_SOURCES,
8+
rules: {
9+
firstHeaderValueOnly: yesNo(
10+
"Do the new lines read an HTTP header that may appear more than once (such as `Cookie`, " +
11+
"`Set-Cookie`, or `baggage`) and use only its first value?",
12+
"Only the first value of a header that can repeat is processed.",
13+
"The new lines read no repeatable header, or process every value.",
14+
"Process every value of this header; it can appear more than once.",
15+
),
16+
replacesThirdPartyBaggage: yesNo(
17+
"Do the new lines remove or overwrite the whole `baggage` header when adding Sentry's entries, " +
18+
"instead of merging with existing third-party entries?",
19+
"Third-party baggage entries are dropped when Sentry's are added.",
20+
"The new lines don't touch baggage, or merge with existing entries.",
21+
"Merge Sentry's entries into the existing `baggage` header instead of replacing it.",
22+
),
23+
coroutineCancellationAsError: yesNo(
24+
"Do the new lines, in coroutine instrumentation, treat `CancellationException` as an error (mark the " +
25+
"span as errored or capture it) instead of setting `SpanStatus.CANCELLED` and rethrowing?",
26+
"Coroutine cancellation is treated as an error.",
27+
"The new lines don't handle coroutine cancellation, or handle it as cancellation.",
28+
"Handle `CancellationException` separately: set `SpanStatus.CANCELLED` and rethrow it.",
29+
{ files: MAIN_KOTLIN },
30+
),
31+
wastedWork: yesNo(
32+
"Do the new lines do measurement, allocation, or other expensive work on a hot path (per span, per " +
33+
"event, per frame, per request) before checking whether the result is needed, for example when " +
34+
"there is no active span or the feature's option is disabled?",
35+
"Work is done on a hot path even when its result is thrown away.",
36+
"The new lines check whether the work is needed first, or are not on a hot path.",
37+
"Check first, and skip the work when its result would be discarded.",
38+
),
39+
},
40+
} satisfies Suite;

‎lint/suites/kotlin-interop.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { Suite } from "@sentry/decision-model-linter";
2+
3+
import { MAIN_JAVA } from "../files.ts";
4+
import { yesNo } from "../yes-no.ts";
5+
6+
export default {
7+
files: MAIN_JAVA,
8+
rules: {
9+
mismatchedAccessors: yesNo(
10+
"Do the new lines add or change a Java getter or setter whose pair uses a different type (boxed " +
11+
"versus primitive, such as `Boolean` and `boolean`) or a name that doesn't match (`isX` with " +
12+
"`setY`, `getX` with `setX` taking another type)?",
13+
"A getter and setter pair don't match, so Kotlin can't combine them into one property.",
14+
"Every new getter and setter shown matches its pair, or there are none.",
15+
"Use the same type and matching names for the getter and setter, so Kotlin callers get a single " +
16+
"property instead of a getter and a separate `setX(...)` call.",
17+
),
18+
},
19+
} satisfies Suite;

0 commit comments

Comments
 (0)