ci: fix failing pre-commit status checks on main#16
Conversation
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR fixes failing pre-commit status checks on main by correcting the bandit hook configuration, tightening JSON checks, and making minor lint/format-only changes in tests and documentation files so that CI pre-commit hooks pass consistently under Python 3.12. Sequence diagram for updated bandit pre-commit hook behaviorsequenceDiagram
actor Developer
participant pre_commit
participant bandit
alt Before_fix
Developer->>pre_commit: pre-commit run --all-files
pre_commit->>bandit: bandit -c .trunk/configs/bandit.yaml -r .
bandit->>bandit: [recursively scan entire tree]
bandit-->>pre_commit: B105 failure on tests/unit/clients/*
else After_fix
Developer->>pre_commit: pre-commit run --all-files
pre_commit->>bandit: bandit -c .trunk/configs/bandit.yaml
bandit->>bandit: [scan files from pre-commit honoring exclude ^tests/]
bandit-->>pre_commit: all checks pass
end
Flow diagram for updated check-json hook file exclusionflowchart LR
A[check-json hook] --> B{path matches ^\.vscode/.*\.json$}
B -- Yes --> C[skip strict JSON parsing]
B -- No --> D[run strict JSON validation]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Pull request overview
This PR addresses failing pre-commit status checks on main by adjusting the Bandit hook to avoid recursively scanning the entire repository, and by applying formatting/lint fixes that were failing other hooks (ruff/ruff-format/prettier/check-json).
Changes:
- Update the Bandit pre-commit hook to scan only files passed by pre-commit (removing the recursive
-r .walk that caused unintended scanning and failures). - Fix ruff failures and apply ruff-format formatting updates in test helpers and test data structures.
- Normalize Markdown/YAML formatting and exclude VS Code JSONC config files from strict
check-json.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
tests/unit/models/test_response.py |
Removes an unused import and applies ruff-format to a helper signature and a dict literal. |
tests/unit/clients/test_session.py |
Applies ruff-format to a helper function signature. |
tests/functional/clients/test_enhance_client.py |
Removes extra blank lines to satisfy formatting hooks. |
CONTRIBUTING.md |
Applies Prettier Markdown normalization (blank line insertion). |
.pre-commit-config.yaml |
Fixes pre-commit hook configuration: Bandit args adjusted; check-json excludes .vscode/*.json; minor formatting normalization. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Fixes the two failing status checks on
main(Pre-commit / pre-commitandpre-commit.ci). The pre-commit run had several failing hooks; the primary breakage was bandit.Root cause: bandit scanned the whole tree
The bandit hook was configured with
args: [-c, .trunk/configs/bandit.yaml, -r, .]andexclude: ^tests/. The-r .makes bandit recursively walk the entire working tree, which defeats theexcludefilter (and also scans.venv, etc.). In CI — where bandit runs under Python 3.12 perdefault_language_version— B105 (hardcoded password) fired on the*_tokenfixtures intests/unit/clients/*, failing the check. (B105 doesn't fire under newer Python, which is why this passed in some local setups.)Fix: drop
-r .so bandit only scans the files pre-commit passes, which honorexclude: ^tests/. Source undersrc/is still fully scanned; tests are excluded as intended.Other hook failures fixed
PropertyMockimport intests/unit/models/test_response.py.CONTRIBUTING.mdand.pre-commit-config.yaml..vscode/*.json(JSONC —//comments are valid for VS Code but not strict JSON).Verification
pre-commit run --all-filesin a fresh Python 3.12 environment (matching CI) — all hooks pass.-r .and no longer fires after the fix;src/scanned clean.pytest tests/unit— 61 passed.Summary by Sourcery
Resolve failing pre-commit status checks by tightening bandit configuration and excluding non-strict JSON files from JSON validation.
Enhancements:
Tests: