Our own repository ships Semgrep rules in compliance-agent/rules:
Rule samples: next to each rule X.yaml sits the sample X.py / X.cs / X.m / X.js it is tested on, written to hold the flaws the rule must find.
Vendored packs: packs under vendor/ bring their own manifests, such as a pom.xml naming old Struts and Spring versions.
Scanned as product code, the samples become code findings, and the vendored manifests become SBOM components with CVEs. Vendor code is left out of code findings but still goes into the SBOM. Every repository that keeps Semgrep rules with tests has the same problem, so this is a general rule, not a path special-case.
Change
Detection:test_data::test_data_dirs also lists a directory that holds a Semgrep rule file next to a sample of the same name, the convention semgrep --test uses, with everything below it. It never lists the tree itself.
What counts as a rule file: YAML of at most 1 MiB with a rules list naming id, languages and message, which Semgrep requires of every rule. A configuration file next to the code it configures (settings.yaml + settings.py) is not one.
Cost: each directory with a candidate YAML is read once, and a YAML file is parsed only when a same-named sample exists.
What follows from test data: the pack is pruned from the working copy before any stage runs, so it yields no code findings, no SBOM components and no CVEs. Findings an earlier scan stored there close as test data (#904), and their issues follow.
Docs:docs/guide/scanning.md names the rule.
In this repository the rule matches only compliance-agent/rules, checked by simulating it over the tree.
Tests
Unit tests in test_data.rs:
Listed: a pack with samples and a nested vendored pack yields only the pack's directory.
Not listed: a config next to code, a rule without a sample, and a pack at the tree's root.
Rule-file check: large and broken YAML is refused.
## Problem
Our own repository ships Semgrep rules in `compliance-agent/rules`:
- **Rule samples:** next to each rule `X.yaml` sits the sample `X.py` / `X.cs` / `X.m` / `X.js` it is tested on, written to hold the flaws the rule must find.
- **Vendored packs:** packs under `vendor/` bring their own manifests, such as a `pom.xml` naming old Struts and Spring versions.
Scanned as product code, the samples become code findings, and the vendored manifests become SBOM components with CVEs. Vendor code is left out of code findings but still goes into the SBOM. Every repository that keeps Semgrep rules with tests has the same problem, so this is a general rule, not a path special-case.
## Change
- **Detection:** `test_data::test_data_dirs` also lists a directory that holds a Semgrep rule file next to a sample of the same name, the convention `semgrep --test` uses, with everything below it. It never lists the tree itself.
- **What counts as a rule file:** YAML of at most 1 MiB with a `rules` list naming `id`, `languages` and `message`, which Semgrep requires of every rule. A configuration file next to the code it configures (`settings.yaml` + `settings.py`) is not one.
- **Cost:** each directory with a candidate YAML is read once, and a YAML file is parsed only when a same-named sample exists.
- **What follows from test data:** the pack is pruned from the working copy before any stage runs, so it yields no code findings, no SBOM components and no CVEs. Findings an earlier scan stored there close as *test data* (#904), and their issues follow.
- **Docs:** `docs/guide/scanning.md` names the rule.
In this repository the rule matches only `compliance-agent/rules`, checked by simulating it over the tree.
## Tests
Unit tests in `test_data.rs`:
- **Listed:** a pack with samples and a nested vendored pack yields only the pack's directory.
- **Not listed:** a config next to code, a rule without a sample, and a pack at the tree's root.
- **Rule-file check:** large and broken YAML is refused.
- **Nesting:** only the top-most directories are kept.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
A repository that ships Semgrep rules keeps, next to each rule X.yaml, the
sample X.py or X.cs it is tested on, written to hold the flaws the rule
must find. Vendored packs bring their own manifests (a pom.xml naming old
Struts and Spring versions). Scanned as product code, the samples become
code findings and the manifests SBOM components with CVEs.
test_data_dirs now also lists a directory with a Semgrep rule file and a
sample of the same name (Semgrep's test convention), with everything below
it, never the tree itself. A YAML file counts as a rule file when it has a
rules list naming id, languages and message, and is at most 1 MiB. As test
data, the pack leaves the working copy before any stage, and findings an
earlier scan stored there close as test data (#904).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sharang
merged commit b2b9fd2a02 into main2026-11-05 19:11:58 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Problem
Our own repository ships Semgrep rules in
compliance-agent/rules:X.yamlsits the sampleX.py/X.cs/X.m/X.jsit is tested on, written to hold the flaws the rule must find.vendor/bring their own manifests, such as apom.xmlnaming old Struts and Spring versions.Scanned as product code, the samples become code findings, and the vendored manifests become SBOM components with CVEs. Vendor code is left out of code findings but still goes into the SBOM. Every repository that keeps Semgrep rules with tests has the same problem, so this is a general rule, not a path special-case.
Change
test_data::test_data_dirsalso lists a directory that holds a Semgrep rule file next to a sample of the same name, the conventionsemgrep --testuses, with everything below it. It never lists the tree itself.ruleslist namingid,languagesandmessage, which Semgrep requires of every rule. A configuration file next to the code it configures (settings.yaml+settings.py) is not one.docs/guide/scanning.mdnames the rule.In this repository the rule matches only
compliance-agent/rules, checked by simulating it over the tree.Tests
Unit tests in
test_data.rs:🤖 Generated with Claude Code