Skip to content

fix: improve Windows shell quoting and test environment portability (…#89

Merged
DataDave-Dev merged 1 commit into
DataDave-Dev:mainfrom
YasserYG8:fix/issue-31-windows-compact
Jul 6, 2026
Merged

fix: improve Windows shell quoting and test environment portability (…#89
DataDave-Dev merged 1 commit into
DataDave-Dev:mainfrom
YasserYG8:fix/issue-31-windows-compact

Conversation

@YasserYG8

@YasserYG8 YasserYG8 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Description

Key Changes

1. Windows Command Line Quoting Fixes

  • src/becwright/cli.py: Swapped single quotes (') with double quotes (") around --pattern regex values inside the starter rules generated by init. Windows cmd.exe does not strip single quotes from commands, which was causing checks to silently pass (as quotes were compiled as literal characters of the regex pattern).
  • tests/test_init.py: Updated starter rules test assertions to reflect double-quoted patterns.

2. POSIX Inline Environment Portability in Tests

  • tests/test_engine_integration.py, tests/test_cli_and_git.py, tests/test_staged_content.py, tests/test_mcp.py, tests/test_report_and_json.py:
    • Replaced Unix-style inline environment variable commands (e.g., PYTHONPATH="..." python -m ...) with cross-platform Python execution syntax: python -c "import sys; sys.path.insert(0, ...)".
    • Swapped test commands in helper functions to use YAML's block scalar syntax (check: |-) to prevent path formatting conflicts (like Windows colons C:/... and quotes) from breaking the generated YAML syntax.

3. Portable Timeouts

  • tests/test_engine_integration.py: Swapped Unix sleep 5 command used for timeout testing with a portable python-based sleep: python -c "import time; time.sleep(5)".

4. Unix Command Fallbacks in Tests

  • tests/test_cli_and_git.py: Updated test rules using Unix-specific true and false commands to run portable python exits instead (python -c "import sys; sys.exit(0/1)").

Verification Results

Verified locally on a Windows platform. Running the test suite yields 100% green tests:

collected 293 items
======================= 293 passed in 111.09s (0:01:51) =======================

Summary by CodeRabbit

  • Bug Fixes
    • Improved how pattern-based checks are written and evaluated, making rule behavior more consistent across JavaScript, Go, Rust, and commit-message checks.
    • Updated command execution handling so checks run more reliably in different environments, including preview and staged-content flows.
    • Adjusted test coverage to reflect the updated command and pattern formatting.

@YasserYG8 YasserYG8 requested a review from DataDave-Dev as a code owner July 6, 2026 16:05
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Regex patterns embedded in generated check commands for forbid/require rules in cli.py were changed from single-quoted/raw-string form to double-quoted with escaped backslashes. Test helpers and scenarios across multiple test files were updated to invoke checks via sys.executable -c with explicit sys.path injection instead of PYTHONPATH-based python -m invocation.

Changes

Regex Quoting and Check Invocation Updates

Layer / File(s) Summary
Starter rule and signal mapping regex quoting
src/becwright/cli.py
JS/TS/Go/Rust starter rule check strings and CLAUDE/commit-message signal mappings switch from single-quoted/raw regex literals to double-quoted strings with escaped backslashes.
Starter rule test expectations
tests/test_init.py
Assertions updated to expect double-quoted --pattern regex literals for Go, Rust, and JS debugger checks.
Test check-command helper rewrite
tests/test_cli_and_git.py, tests/test_engine_integration.py, tests/test_mcp.py, tests/test_report_and_json.py, tests/test_staged_content.py
Helper functions generating rule check commands switch from PYTHONPATH=... python -m becwright.checks.<module> to sys.executable -c snippets that inject the repo src path into sys.path and call the check module's main().
Test scenario check values updated
tests/test_cli_and_git.py, tests/test_engine_integration.py, tests/test_mcp.py
Inline rule check values and preview_rule check arguments change from true/false/sleep 5 shell strings to sys.executable -c commands with explicit sys.exit(...) codes or time.sleep.

Estimated code review effort: 2 (Simple) | ~12 minutes

Possibly related PRs

  • DataDave-Dev/becwright#6: Updates to cli.py starter-rule forbid --pattern regex quoting and corresponding test_init.py expectations align with starter-rule generation behavior.
  • DataDave-Dev/becwright#16: Both PRs modify generated starter check strings in cli.py and adjust forbid --pattern command encoding.
  • DataDave-Dev/becwright#45: Both PRs modify cli.py's CLAUDE.md-to-generated-rule mapping logic affecting generated check strings.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR does not add the requested community-health files; it only changes CLI quoting and tests, so it misses issue #39's requirements. Add SECURITY.md, CODE_OF_CONDUCT.md, CHANGELOG.md, CITATION.cff, .github/FUNDING.yml, .github/CODEOWNERS, and .github/ISSUE_TEMPLATE/config.yml instead.
Out of Scope Changes check ⚠️ Warning The changes are entirely unrelated to the linked docs-only scope and introduce portability/test updates instead. Remove the CLI and test portability changes, or split them into a separate PR if they are intentionally out of scope.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the main change: Windows shell quoting and test-portability fixes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/becwright/cli.py (1)

628-645: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Inconsistent quoting idiom between rule groups.

These commit-message signal check strings use raw string literals (r'...') with a literal embedded ", whereas the JS/Go/Rust starter rules above (Lines 509-528) use regular strings with escaped \"/\\. Both produce correct output, but mixing styles in the same file for the same kind of value is slightly harder to scan/verify at a glance.

🤖 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 `@src/becwright/cli.py` around lines 628 - 645, The commit-message signal
definitions in _COMMIT_MSG_SIGNALS use a different quoting style than the
adjacent rule groups, making the check values harder to scan consistently.
Update the check strings in the conventional-commits and no-ai-attribution
entries to match the existing idiom used in the other starter rules, and keep
the symbol names _COMMIT_MSG_SIGNALS and the dict entries for those rules as the
place to make the change.
tests/test_cli_and_git.py (1)

25-28: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract duplicated check-command builder to a shared test helper.

The sys.executable -c "..." command-construction snippet (path injection + import + sys.exit(main())) is copy-pasted nearly verbatim in test_cli_and_git.py, test_engine_integration.py, test_mcp.py, test_report_and_json.py, and test_staged_content.py. Any future portability tweak (e.g., another Windows quoting fix) will need to be replicated in all five places.

Consider moving this into a shared conftest.py fixture/helper (e.g., _check_cmd(module)) that all test files import/use.

🤖 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 `@tests/test_cli_and_git.py` around lines 25 - 28, The check-command
construction is duplicated across multiple test files, so any quoting or
portability change must be updated in several places. Extract the shared
sys.executable -c command builder into a common test helper in conftest.py (for
example, a helper used by _rules_yaml), and update the affected tests to call
that shared helper instead of rebuilding the
import/path-injection/sys.exit(main()) string inline.
🤖 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.

Inline comments:
In `@tests/test_cli_and_git.py`:
- Around line 173-176: The inline comment near the advisory rule setup is stale
and refers to the old false command even though the check now runs
sys.executable with a Python exit(1) snippet. Update or remove the comment in
the test setup around the rules.yaml write in the relevant test so it accurately
describes the current advisory check mechanism and does not restate outdated
behavior.

---

Nitpick comments:
In `@src/becwright/cli.py`:
- Around line 628-645: The commit-message signal definitions in
_COMMIT_MSG_SIGNALS use a different quoting style than the adjacent rule groups,
making the check values harder to scan consistently. Update the check strings in
the conventional-commits and no-ai-attribution entries to match the existing
idiom used in the other starter rules, and keep the symbol names
_COMMIT_MSG_SIGNALS and the dict entries for those rules as the place to make
the change.

In `@tests/test_cli_and_git.py`:
- Around line 25-28: The check-command construction is duplicated across
multiple test files, so any quoting or portability change must be updated in
several places. Extract the shared sys.executable -c command builder into a
common test helper in conftest.py (for example, a helper used by _rules_yaml),
and update the affected tests to call that shared helper instead of rebuilding
the import/path-injection/sys.exit(main()) string inline.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 205d77c2-96c7-44e7-b102-8273c0a997e9

📥 Commits

Reviewing files that changed from the base of the PR and between 7228099 and fa6fddd.

📒 Files selected for processing (7)
  • src/becwright/cli.py
  • tests/test_cli_and_git.py
  • tests/test_engine_integration.py
  • tests/test_init.py
  • tests/test_mcp.py
  • tests/test_report_and_json.py
  • tests/test_staged_content.py

Comment thread tests/test_cli_and_git.py
Comment on lines 173 to 176
# `false` always "fails"; an advisory rule must report but not block the commit.
(tmp_path / ".bec" / "rules.yaml").write_text(
"rules:\n - id: adv\n paths: ['**/*.py']\n check: 'false'\n severity: advisory\n",
f"rules:\n - id: adv\n paths: ['**/*.py']\n check: '\"{sys.executable}\" -c \"import sys; sys.exit(1)\"'\n severity: advisory\n",
encoding="utf-8")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Stale comment no longer matches the code.

The comment # \false` always "fails"...still refers to the old shellfalsecommand, but the check value was rewritten tosys.executable -c "import sys; sys.exit(1)"`. Update the comment to reflect the actual mechanism.

As per coding guidelines, "Use comments only for complex code; if the code is self-explanatory, do not comment it, and do not add comments that merely restate the obvious" — a comment must at least remain accurate.

📝 Proposed fix
-    # `false` always "fails"; an advisory rule must report but not block the commit.
+    # The check exits 1 (always "fails"); an advisory rule must report but not block the commit.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# `false` always "fails"; an advisory rule must report but not block the commit.
(tmp_path / ".bec" / "rules.yaml").write_text(
"rules:\n - id: adv\n paths: ['**/*.py']\n check: 'false'\n severity: advisory\n",
f"rules:\n - id: adv\n paths: ['**/*.py']\n check: '\"{sys.executable}\" -c \"import sys; sys.exit(1)\"'\n severity: advisory\n",
encoding="utf-8")
# The check exits 1 (always "fails"); an advisory rule must report but not block the commit.
(tmp_path / ".bec" / "rules.yaml").write_text(
f"rules:\n - id: adv\n paths: ['**/*.py']\n check: '\"{sys.executable}\" -c \"import sys; sys.exit(1)\"'\n severity: advisory\n",
encoding="utf-8")
🤖 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 `@tests/test_cli_and_git.py` around lines 173 - 176, The inline comment near
the advisory rule setup is stale and refers to the old false command even though
the check now runs sys.executable with a Python exit(1) snippet. Update or
remove the comment in the test setup around the rules.yaml write in the relevant
test so it accurately describes the current advisory check mechanism and does
not restate outdated behavior.

Source: Coding guidelines

@DataDave-Dev DataDave-Dev merged commit 9cf13ca into DataDave-Dev:main Jul 6, 2026
7 checks passed
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