Skip to content

feat(ci): add diff-aware PR scans (--changed-since/--changed-files) and findings baseline (--baseline) - #211

Merged
vsn411 merged 4 commits into
secfoo-com:mainfrom
SriRamkunamsetty:feat/diff-baseline-ci-109
Nov 29, 2026
Merged

vsn411 merged 4 commits into
secfoo-com:mainfrom
SriRamkunamsetty:feat/diff-baseline-ci-109

Conversation

@SriRamkunamsetty

Copy link
Copy Markdown
Contributor

Fixes #109

Summary

  • Diff-aware PR scans (--changed-since, --changed-files, --fail-scope):
    • Added src/secfoo/targets/diff.py computing changed paths via git diff --name-only --no-renames --merge-base (with merge-base fallback and untracked handling) and reading newline-separated path lists, validating git repos and refs before any skill executes.
    • Updated render_prompt() in src/secfoo/skills/renderer.py to include the changed-files brief and instructions to tag unchanged-file findings with scope: context.
    • Updated src/secfoo/runner.py to pass effective_scan_scope into complete_run and update_structured_findings so out-of-scope findings remain open, and extract per-finding scope (changed vs context) and fingerprints on RunOutcome for --fail-scope changed.
  • Findings baseline (--baseline, secfoo findings baseline write|check):
    • Added src/secfoo/report/baseline.py supporting JSON baselines with fingerprint, skill, severity, title, optional reason, and expires (YYYY-MM-DD) handling.
    • Added secfoo findings baseline write and secfoo findings baseline check in src/secfoo/cli.py.
    • Wired --baseline into secfoo run (excluding active entries from --fail-on, reporting and re-counting expired entries, persisting active acknowledgments in finding_baselines) and secfoo findings export (SARIF baselineState: "unchanged" | "new" via src/secfoo/report/sarif.py, JSONL baseline: {reason, expires}).
    • Surfaced Accepted in baseline badges and rationale/expiry in the SAST dashboard (sast_findings_list.html, sast_finding_detail.html).
  • Action & documentation:
    • Added changed-only and baseline inputs to action.yml and updated examples/ci/github-actions-manual.yml, examples/ci/gitlab-ci.yml, docs/CI.md (including "Adopting secfoo in an existing repo"), and docs/REFERENCE.md.
  • Tests:
    • Added comprehensive tests in tests/test_diff_and_baseline.py.

Verification

  • ruff check . — 0 errors
  • bandit -c .bandit -ll -r src/secfoo — 0 medium/high issues
  • pytest tests/test_diff_and_baseline.py tests/test_cli.py tests/test_runner.py tests/test_docs_consistency.py tests/test_report/test_sarif.py tests/test_storage/test_structured_findings_storage.py tests/test_web/test_sast_finding_route.py tests/test_web/test_no_inline_scripts.py -q — 180 passed

classify_finding_scope let the report's Scope: tag override the
finding's location. The tag is model output, so text in a scanned PR
could get a finding in a changed file tagged context and past
--fail-scope changed. Use the tag only for findings without a location.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vsn411

vsn411 commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

Thanks, and welcome! This is a solid take on #109. The git handling validates the ref (--verify --end-of-options, no leading -) before any agent starts. Out-of-scope findings stay open, and baselined findings are annotated in SARIF/JSONL rather than dropped. You also claimed the issue first, so this is the implementation we'll take forward.

I pushed one fix (5e596c4), with a test. classify_finding_scope let the report's Scope: tag override the finding's file path. The tag is model output, so text inside a scanned PR could talk the model into tagging a finding in a changed file as context, and that would take it out of --fail-scope changed. The path now decides whenever a finding has one. The tag is only used for findings without a location.

Once a maintainer approves the workflow run and CI is green, this is ready to merge.

# Conflicts:
#	src/secfoo/runner.py
#	src/secfoo/skills/renderer.py
# Conflicts:
#	src/secfoo/cli.py
@vsn411
vsn411 merged commit 64ff2da into secfoo-com:main Nov 29, 2026
16 checks passed
@vsn411

vsn411 commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

Merged, thank you! 🎉 Diff-scoped PR scans, --fail-scope changed and the findings baseline are in, which closes #109. That's three merged PRs from you today: #209, #211 and #213.

Before merging, I pushed the scope fix described above (the finding's path decides, not the model's tag) with a test. I also merged current main, resolving the conflicts with #208 (Responsible AI persistence in runner.py and the AI-BOM context in renderer.py) and #209 (per-skill models in cli.py). CI and CodeQL were green.

#212 and #210 are still open with review notes. Happy to help with the rebases when you get to them.

@github-actions

Copy link
Copy Markdown

Leaderboard update

SriRamkunamsetty now has 26 points (rank #3, Bronze). 24 more to reach Silver.

Full leaderboard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI that stays green: diff-aware PR scans (--changed-since) and a findings baseline (--baseline)

2 participants