Skip to content

feat(findings): show the context of test code on every finding - #251

Merged
SizzleUnrlsd merged 2 commits into
mainfrom
feat/test-context
Oct 14, 2026
Merged

SizzleUnrlsd merged 2 commits into
mainfrom
feat/test-context

Conversation

@SizzleUnrlsd

Copy link
Copy Markdown
Contributor

Stacked on the dynamic-import PR, which only shares an adjacent line of docs/usage.md. Merge after it.

Summary

  • One classification of test code in findings/context.py:
    • is_test_code: whether a path is test code;
    • code_context: the context a finding carries.
  • hardcoded-credential uses is_test_code, so its behaviour is unchanged.
  • The engine adds context: test to every finding in test code, judged on its path relative to the project root, before refiner plugins run, so that they can read it. A context a rule gives (example) stays.
  • The context changes no verdict. It is exported in the JSON report and as a SARIF result property, next to injection.

Verification

  • tests/test_code_context.py, new: 16 tests, covering:

    • the classification;
    • the context on every finding, with unchanged verdicts compared with the same code outside the tests;
    • a project located under a directory named tests;
    • SARIF;
    • a refiner that reads the context.

    No existing test changed.

  • Full suite green, apart from the local test_packaging metadata issue. ruff check and mypy clean. Regression snapshots unchanged.

Known, not changed here: hardcoded-credential classifies the absolute path, so a project located under a directory named tests gets all its credentials at low confidence. Fixing that needs the project root in the plugin API and changes verdicts; it belongs to its own issue.

Closes #244

The context is judged on the path from the root of the report: for a file checked alone, its own directory, as the command line reports it. analyze_file takes that root explicitly.
@SizzleUnrlsd
SizzleUnrlsd deleted the branch feat/dynamic-import-sinks October 13, 2026 22:00
@SizzleUnrlsd SizzleUnrlsd reopened this Oct 14, 2026
@SizzleUnrlsd
SizzleUnrlsd changed the base branch from feat/dynamic-import-sinks to main October 14, 2026 00:04
@SizzleUnrlsd
SizzleUnrlsd merged commit 2777854 into main Oct 14, 2026
15 checks passed
@SizzleUnrlsd
SizzleUnrlsd deleted the feat/test-context branch October 14, 2026 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

findings: test code is recognised only by hardcoded-credential

1 participant