feat(scan): leave test data (fixtures, testdata) out of the whole scan #820

Merged
sharang merged 2 commits from feat/test-data-scan-exclude into main 2026-11-04 08:28:52 +00:00
Owner

Why

Dogfooding on prod (our own repos, bp-smoketest workspace): the pruefwerk repo got 211 [CVE] issues and 20 high code issues in one scan, almost all from our own test fixtures (fixtures/nightly/eco/*, fixtures/dotnet, demo targets). Customers with fixtures will see the same. There was no way to leave them out: only a few hard-coded skip lists in single stages.

What

  • New pipeline::test_data: test_data_dirs(root) finds directories named fixtures, __fixtures__, testdata, test_data, test-data, test-fixtures, test_fixtures (case-insensitive, any depth, top-most only, never the tree root, never through a symlink). tests/, spec/, examples/, demo/ are not matched: they hold real code and can leak real secrets.

  • scan_tree removes them from the working copy before the first stage, so every stage (semgrep, cppcheck, mobsfscan, DevSkim, patterns, secrets, syft and the own SBOM collectors, PLC/CODESYS, CVE) sees the tree without them. Threading an exclude list through each walker was the alternative; there are too many independent walkers for that to stay correct.

  • Guards on the deletion:

    • prune refuses any tree not under GIT_CLONE_BASE_PATH or ARTIFACT_STORE_BASE_PATH (and the base itself);
    • it never follows .., absolute paths or symlinks.
  • Restoring:

    • the git fetch now checks out with recreate_missing(true), so a checkout is whole again before every scan;
    • an upload is unpacked again on every scan.

    So what is left out always follows the current rules.

  • Shared checkout: PR review and the code graph read the same clone and will not see the fixtures either after a scan. That is intended.

  • The run gets a note: stage test_data, SkipCode::TestData, informational. There are DE/EN texts and a docs row in guide/scanning.md.

  • Findings an earlier scan stored in test data close as ScanChangeKind::NowTestData, with their own issue comment (DE/EN), not as "fixed".

  • CVE issues of the removed components close through the existing path: a complete scan no longer finds the CVE. This is independent of ISSUE_AUTOCLOSE, which only governs VEX-settled CVEs.

Tests

  • Unit (test_data.rs):
    • detection by name, nested dirs reported once, the root is never matched, .git is skipped;
    • prune removes only the test data;
    • refusal outside the owned bases;
    • no .. or absolute paths;
    • a symlink named testdata is left alone.
  • Integration (tests/resolve_findings.rs, Mongo in CI): a stale finding under fixtures/ closes as NowTestData.
  • Built and tested by CI only; nothing was built locally.

Expected effect on prod (after promotion)

The prod build-id rescan (#465) of the pruefwerk repo drops the fixture components from the SBOM. Its CVE stage on 03.11. ran complete (no CVE-stage warnings in that scan's trace), so the CVE issues should close on that scan. The 20 code issues close via issue sync. I can verify this on stage only; prod needs a promotion.

🤖 Generated with Claude Code

## Why Dogfooding on prod (our own repos, bp-smoketest workspace): the pruefwerk repo got 211 `[CVE]` issues and 20 high code issues in one scan, almost all from our own test fixtures (`fixtures/nightly/eco/*`, `fixtures/dotnet`, demo targets). Customers with fixtures will see the same. There was no way to leave them out: only a few hard-coded skip lists in single stages. ## What - New `pipeline::test_data`: `test_data_dirs(root)` finds directories named `fixtures`, `__fixtures__`, `testdata`, `test_data`, `test-data`, `test-fixtures`, `test_fixtures` (case-insensitive, any depth, top-most only, never the tree root, never through a symlink). `tests/`, `spec/`, `examples/`, `demo/` are **not** matched: they hold real code and can leak real secrets. - `scan_tree` removes them from the working copy **before the first stage**, so every stage (semgrep, cppcheck, mobsfscan, DevSkim, patterns, secrets, syft and the own SBOM collectors, PLC/CODESYS, CVE) sees the tree without them. Threading an exclude list through each walker was the alternative; there are too many independent walkers for that to stay correct. - Guards on the deletion: - `prune` refuses any tree not under `GIT_CLONE_BASE_PATH` or `ARTIFACT_STORE_BASE_PATH` (and the base itself); - it never follows `..`, absolute paths or symlinks. - Restoring: - the git fetch now checks out with `recreate_missing(true)`, so a checkout is whole again before every scan; - an upload is unpacked again on every scan. So what is left out always follows the current rules. - Shared checkout: PR review and the code graph read the same clone and will not see the fixtures either after a scan. That is intended. - The run gets a note: stage `test_data`, `SkipCode::TestData`, informational. There are DE/EN texts and a docs row in `guide/scanning.md`. - Findings an earlier scan stored in test data close as `ScanChangeKind::NowTestData`, with their own issue comment (DE/EN), not as "fixed". - CVE issues of the removed components close through the existing path: a complete scan no longer finds the CVE. This is independent of `ISSUE_AUTOCLOSE`, which only governs VEX-settled CVEs. ## Tests - Unit (`test_data.rs`): - detection by name, nested dirs reported once, the root is never matched, `.git` is skipped; - prune removes only the test data; - refusal outside the owned bases; - no `..` or absolute paths; - a symlink named `testdata` is left alone. - Integration (`tests/resolve_findings.rs`, Mongo in CI): a stale finding under `fixtures/` closes as `NowTestData`. - Built and tested by CI only; nothing was built locally. ## Expected effect on prod (after promotion) The prod build-id rescan (#465) of the pruefwerk repo drops the fixture components from the SBOM. Its CVE stage on 03.11. ran complete (no CVE-stage warnings in that scan's trace), so the CVE issues should close on that scan. The 20 code issues close via issue sync. I can verify this on stage only; prod needs a promotion. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
sharang added 1 commit 2026-11-04 07:53:26 +00:00
feat(scan): leave test data (fixtures, testdata) out of the whole scan
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 3m51s
CI / Check (pull_request) Failing after 4m14s
5d6737ecd8
A repository's fixtures are not what it ships, but every stage scanned
them as product code: our own repo got 211 CVE issues from sample
lockfiles (struts2 2.3.30, spring 5.0.0, urllib3 1.24.1) and 20 high
code issues from sample code under fixtures/.

Directories named fixtures, __fixtures__, testdata, test_data, test-data,
test-fixtures or test_fixtures (at any depth, top-most only, never the
tree itself, never through a link) now leave the scan's working copy
before the first stage, so no stage reports them: no code findings, no
SBOM components, no CVEs. tests/, spec/ and examples/ are scanned as
before.

- Only a working copy under the clone or artifact directories is pruned;
  anything else is refused. The git fetch now checks out with
  recreate_missing, and an upload is unpacked again every scan, so the
  directories come back before the next scan applies the current rules.
- The run notes what was left out (SkipCode::TestData, stage test_data).
- Findings an earlier scan stored there close as NowTestData, with their
  own issue comment, not as fixed.
- CVE issues of the removed components close on the next complete scan,
  as for a removed dependency.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sharang added 1 commit 2026-11-04 08:01:09 +00:00
style: module order
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 3m58s
CI / Check (pull_request) Successful in 17m10s
49a710ccaa
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sharang merged commit ac95126af2 into main 2026-11-04 08:28:52 +00:00
Sign in to join this conversation.