Skip to content

fix: make pre-commit hooks portable on Windows - #6881

Open
Vaishnavi220506 wants to merge 9 commits into
crewAIInc:mainfrom
Vaishnavi220506:codex/fix-windows-precommit
Open

fix: make pre-commit hooks portable on Windows#6881
Vaishnavi220506 wants to merge 9 commits into
crewAIInc:mainfrom
Vaishnavi220506:codex/fix-windows-precommit

Conversation

@Vaishnavi220506

Copy link
Copy Markdown

Summary

Fixes #6863.

The local pre-commit hooks sourced .venv/bin/activate through Bash, which fails on Windows before Ruff, Ruff Format, mypy, or pip-audit can run. The hooks now invoke uv run directly, allowing uv to select the project environment on every supported platform.

A regression test verifies that every local hook uses uv run and does not depend on the Unix-only activation path.

Validation

  • pytest lib/crewai/tests/test_pre_commit_config.py -q -n 0 — passed
  • pre-commit run --files lib/crewai/tests/test_pre_commit_config.py — Ruff and Ruff Format passed
  • pre-commit validate-config — passed

The repository-wide all-files run still reports unrelated existing Ruff/mypy issues outside this change.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 57b56aaa-ae0e-4dd7-b44f-34feb7defd70

📥 Commits

Reviewing files that changed from the base of the PR and between 34199c2 and 3faaf8f.

📒 Files selected for processing (2)
  • .pre-commit-config.yaml
  • lib/crewai/tests/test_pre_commit_config.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • lib/crewai/tests/test_pre_commit_config.py
  • .pre-commit-config.yaml

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Local pre-commit hooks now call Ruff, Ruff Format, Mypy, and pip-audit through direct uv run commands. A pytest verifies the command format and the removal of .venv/bin/activate.

Changes

Pre-commit hook execution

Layer / File(s) Summary
Direct uv run hook commands
.pre-commit-config.yaml
Ruff, Ruff Format, Mypy, and pip-audit no longer use shell-based virtual-environment activation or argument forwarding.
Hook command validation
lib/crewai/tests/test_pre_commit_config.py
The test verifies that local hook entries use the expected uv run prefixes and do not reference .venv/bin/activate.

Suggested reviewers: vidit-ostwal

Priority: ➖ Normal — Impact reflects medium issue severity.

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 3faaf

Local hooks now use platform-independent uv commands, with configuration coverage for the removed Unix activation path. No current merge-blocking risk is identified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: making pre-commit hooks portable on Windows.
Description check ✅ Passed The description explains the Windows issue, the uv run solution, the regression test, and validation results. It uses equivalent headings instead of the template headings and does not include a separa…
Linked Issues check ✅ Passed The changes directly address issue #6863 by removing Unix-only virtual environment activation and invoking Ruff, Ruff Format, mypy, and pip-audit through uv run. The regression test verifies the requi…
Out of Scope Changes check ✅ Passed The changes are limited to the pre-commit configuration and a regression test for the Windows portability issue. No unrelated code changes are present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 …
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Vaishnavi220506
Vaishnavi220506 marked this pull request as ready for review August 9, 2026 07:45

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
lib/crewai/tests/test_pre_commit_config.py (1)

23-25: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert the intended tool for each hook.

The current assertions only check the uv run prefix. An entry could invoke the wrong tool for its hook ID and still pass. Assert command prefixes for ruff, ruff-format, mypy, and pip-audit by hook ID.

Proposed test strengthening
     assert local_hooks
     assert all(hook["entry"].startswith("uv run ") for hook in local_hooks)
     assert all(".venv/bin/activate" not in hook["entry"] for hook in local_hooks)
+    expected_prefixes = {
+        "ruff": "uv run ruff check --config pyproject.toml",
+        "ruff-format": "uv run ruff format --config pyproject.toml",
+        "mypy": "uv run mypy --config-file pyproject.toml",
+        "pip-audit": "uv run pip-audit --skip-editable",
+    }
+    hooks_by_id = {hook["id"]: hook for hook in local_hooks}
+    assert set(expected_prefixes) <= set(hooks_by_id)
+    for hook_id, prefix in expected_prefixes.items():
+        assert hooks_by_id[hook_id]["entry"].startswith(prefix)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/crewai/tests/test_pre_commit_config.py` around lines 23 - 25, Strengthen
the assertions in the pre-commit hook test by mapping each hook ID to its
expected command prefix and validating the corresponding hook["entry"] for ruff,
ruff-format, mypy, and pip-audit. Retain the existing checks for local hooks,
the uv run prefix, and absence of .venv/bin/activate.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@lib/crewai/tests/test_pre_commit_config.py`:
- Around line 23-25: Strengthen the assertions in the pre-commit hook test by
mapping each hook ID to its expected command prefix and validating the
corresponding hook["entry"] for ruff, ruff-format, mypy, and pip-audit. Retain
the existing checks for local hooks, the uv run prefix, and absence of
.venv/bin/activate.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2cfc5518-d11e-48cc-bd79-f4186b07be67

📥 Commits

Reviewing files that changed from the base of the PR and between f7ba8e3 and 78c8fff.

📒 Files selected for processing (2)
  • .pre-commit-config.yaml
  • lib/crewai/tests/test_pre_commit_config.py

@Vaishnavi220506

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Already reviewed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Vidit-Ostwal Vidit-Ostwal self-assigned this Aug 26, 2026

@Vidit-Ostwal Vidit-Ostwal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks — this is the right fix. Dropping source .venv/bin/activate and the bash -c wrapper is the portable version (Git Bash is no longer required). pass_filenames: true still appends paths onto uv run ruff/mypy ..., so that behavior is preserved.

Please rebase onto main before we can merge (mergeStateStatus is CONFLICTING). The pip-audit ignore list on main has grown (e.g. PYSEC-2026-139, GHSA-2wm9-hf6c-p5cr, GHSA-36p7-vc44-83pf, GHSA-xph7-9rjv-w5fr). Keep those entries; only change the entry wrapper from bash -c 'source .venv/bin/activate && uv run ...' to uv run ....

CodeRabbit's nit on the regression test is optional: asserting each hook id maps to the matching tool (ruff, ruff format, mypy, pip-audit) would make the test fail if an entry were copy-pasted onto the wrong hook. Not a merge blocker.

The parents[3] walk from lib/crewai/tests/ to the repo root is a bit brittle if this file ever moves, but it's fine for this check.

@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@Vaishnavi220506
Vaishnavi220506 force-pushed the codex/fix-windows-precommit branch from 70c6021 to c1051ad Compare September 4, 2026 07:48
@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@Vaishnavi220506

Copy link
Copy Markdown
Author

Hi, just checking in on PR #6881. I rebased it onto the latest main and addressed the test suggestion. All checks are passing. Please let me know if anything else is needed. Thanks!

@Vaishnavi220506

Copy link
Copy Markdown
Author

Hi @Vidit-Ostwal, the required GitHub Actions runs for this fork PR are expiring while waiting for maintainer approval. CodeRabbit has passed and there are no new code comments; the branch is already rebased onto the latest main. Could you please approve the workflow runs and review the PR when convenient? No further code changes are needed from my side. Thanks!

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@Vaishnavi220506

Copy link
Copy Markdown
Author

Hi @Vidit-Ostwal, I pushed commit a604363 with a small test-isolation fix. The failed test matrix was caused by test_bedrock_completion_module_is_imported removing the Bedrock completion module from sys.modules without restoring it; it now uses pytest's monkeypatch cleanup. The original Windows pre-commit changes are unchanged. Could you please approve the new fork workflow runs so CI can execute? Thanks!

@Vidit-Ostwal Vidit-Ostwal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Keep Unix source .venv/bin/activate and add a Windows $OSTYPE branch instead of dropping activation.

Comment thread .pre-commit-config.yaml Outdated
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.

[BUG] pre-commit hooks fail on Windows due to hardcoded Unix virtual environment path

2 participants