Skip to content

ci: fix failing pre-commit status checks on main#16

Merged
brendancsmith merged 3 commits into
mainfrom
ci/fix-precommit-checks
Jul 5, 2026
Merged

ci: fix failing pre-commit status checks on main#16
brendancsmith merged 3 commits into
mainfrom
ci/fix-precommit-checks

Conversation

@brendancsmith

@brendancsmith brendancsmith commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes the two failing status checks on main (Pre-commit / pre-commit and pre-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, .] and exclude: ^tests/. The -r . makes bandit recursively walk the entire working tree, which defeats the exclude filter (and also scans .venv, etc.). In CI — where bandit runs under Python 3.12 per default_language_version — B105 (hardcoded password) fired on the *_token fixtures in tests/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 honor exclude: ^tests/. Source under src/ is still fully scanned; tests are excluded as intended.

Other hook failures fixed

  • ruff – removed an unused PropertyMock import in tests/unit/models/test_response.py.
  • ruff-format – reformatted long signatures / a dict literal in 3 test files.
  • prettier – normalized CONTRIBUTING.md and .pre-commit-config.yaml.
  • check-json – excluded .vscode/*.json (JSONC — // comments are valid for VS Code but not strict JSON).

Verification

  • pre-commit run --all-files in a fresh Python 3.12 environment (matching CI) — all hooks pass.
  • Confirmed B105 fires under Python 3.12 with -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:

  • Adjust bandit pre-commit hook configuration to only scan files passed by pre-commit rather than the entire tree.
  • Exclude VS Code JSONC configuration files from strict JSON checking in pre-commit.
  • Clean up minor formatting and whitespace issues in tests and CONTRIBUTING.md to satisfy linting and formatting hooks.

Tests:

  • Remove an unused mock import and reformat test helpers and data structures to comply with linting and formatting rules.

@trunk-io

trunk-io Bot commented Jul 5, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

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

@sourcery-ai

sourcery-ai Bot commented Jul 5, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This 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 behavior

sequenceDiagram
  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
Loading

Flow diagram for updated check-json hook file exclusion

flowchart LR
  A[check-json hook] --> B{path matches ^\.vscode/.*\.json$}
  B -- Yes --> C[skip strict JSON parsing]
  B -- No --> D[run strict JSON validation]
Loading

File-Level Changes

Change Details Files
Adjust bandit pre-commit hook so it scans only files passed by pre-commit instead of recursively walking the entire tree.
  • Removed the -r . argument from the bandit hook configuration while keeping the custom config path.
  • Added an explanatory comment documenting why -r . was removed and that exclude is now honored as intended.
.pre-commit-config.yaml
Prevent strict JSON validation from failing on VS Code JSONC configuration files.
  • Added an exclude pattern to the check-json hook to skip .vscode/*.json files.
  • Documented that VS Code config files use JSONC with comments, which is incompatible with strict JSON parsing.
.pre-commit-config.yaml
Resolve ruff and ruff-format issues in test files so pre-commit passes.
  • Removed an unused PropertyMock import from a unit test.
  • Reformatted long function signatures for mock response helpers to match ruff-format expectations.
  • Reformatted a dict literal in a test to meet ruff-format line-wrapping rules.
  • Removed stray blank lines in an async functional test to satisfy formatting hooks.
tests/unit/models/test_response.py
tests/unit/clients/test_session.py
tests/functional/clients/test_enhance_client.py
Normalize Markdown formatting to satisfy prettier.
  • Added a blank line before a list in CONTRIBUTING.md to conform to prettier’s Markdown style.
CONTRIBUTING.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

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.

@brendancsmith
brendancsmith marked this pull request as ready for review July 5, 2026 21:09
Copilot AI review requested due to automatic review settings July 5, 2026 21:09

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@brendancsmith
brendancsmith merged commit 9baa0d3 into main Jul 5, 2026
12 checks passed
@brendancsmith
brendancsmith deleted the ci/fix-precommit-checks branch July 5, 2026 21:12
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.

2 participants