Skip to content

fix(python): select venv python.exe on Windows for python3 sources - #692

Merged
a-oren merged 5 commits into
guacsec:mainfrom
a-oren:TC-7486
Nov 12, 2026
Merged

a-oren merged 5 commits into
guacsec:mainfrom
a-oren:TC-7486

Conversation

@a-oren

@a-oren a-oren commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes Python virtual-environment analysis on Windows (blocked TC-7485). With TRUSTIFY_DA_PYTHON_VIRTUAL_ENV=true and a source interpreter named python3, venv creation succeeded but the pip upgrade targeted the nonexistent Scripts\python3.exe, so analysis failed with an unrecognized-command error and no report was produced.

  • src/providers/python_controller.js — prepareEnvironment() now selects the venv executables by platform instead of deriving them from the source interpreter name: Windows always uses Scripts\python.exe / Scripts\pip.exe, and POSIX uses bin/python / bin/pip; both are independent of how the source interpreter is named. The two duplicated branches (each with its own drive-letter handling) collapse into one path that still reuses #decideIfWindowsOrLinuxPath.
  • test/providers/python_controller.test.js — new esmock-based suite that stubs os.platform() and invokeCommand to capture venv creation and pip-upgrade invocations: Windows with a python3 source (the reproducer), Windows with a python source, and POSIX python3 and python regression cases asserting bin/python/bin/pip.
  • test/providers/python_controller.test.js — tightened the Windows cases to require the exact venv-anchored Scripts\python.exe and Scripts\pip.exe paths; the exact-path equality already rejects a same-basename executable from a different venv. The POSIX cases now pin bin/python/bin/pip too (TC-7502).

Root cause

venv installs python.exe/pip.exe on Windows no matter how the source interpreter is named. Before this change, prepareEnvironment() keyed the executable names off pathToPythonBin.includes("python3"), and #decideIfWindowsOrLinuxPath() only appended .exe, never normalizing python3 to python. The source-name heuristic is now removed: standard python/pip names are used inside the venv on both platforms.

Testing

  • Reproducer verified failing-first: on the unfixed source it observes Scripts\python3.exe (expected 'python3.exe' to equal 'python.exe'); after the fix it observes Scripts\python.exe and Scripts\pip.exe, with no invocation targeting python3.exe/pip3.exe.
  • npm run tests -- --grep "Python_controller" — 7 passing.
  • npm run lint — 0 errors (16 pre-existing warnings in untouched files).
  • npm test — 1037 passing / 15 failing. The 15 failures are the known environment-dependent baseline and all reproduce on pristine main in this environment: 2 python-pip cases broken by a stale local ~/.local/bin/pipdeptree (ModuleNotFoundError: No module named 'pipdeptree._runner', reproducible outside the repo), 10 python-pyproject/poetry cases, and 3 OCI registry lookups.

Notes

  • Scope is limited to the interpreter-selection defect. The separate hard-coded temp-directory concern from the bug is intentionally not addressed here.

Implements TC-7486

Summary by Sourcery

Fix virtual-environment analysis by selecting executable names from the platform-specific venv layout instead of the source interpreter name.

Bug Fixes:

  • Use the standard python and pip executables inside virtual environments regardless of the source interpreter name, fixing Windows analysis for python3 sources.

Enhancements:

  • Simplify virtual-environment executable path selection with platform-specific layouts and preserve Windows drive-letter handling.

Tests:

  • Add platform-mocked coverage for Windows and POSIX virtual-environment executable paths with both python and python3 source interpreters.

On Windows the venv created from a `python3` source interpreter still
installs Scripts\python.exe and Scripts\pip.exe, but prepareEnvironment()
derived the venv executable names from the source interpreter name and
selected the nonexistent Scripts\python3.exe. The pip upgrade then failed
with an unrecognized-command error and Python analysis produced no report.

Select the venv executable names by platform instead: Windows always uses
python.exe/pip.exe, while POSIX keeps python3/pip3 for a python3 source and
python/pip otherwise. The duplicated per-branch drive-letter handling is
folded into a single path that still reuses #decideIfWindowsOrLinuxPath.

Adds a failing-first esmock reproducer covering Windows with python3 and
python sources plus a POSIX python3/pip3 regression case.

Implements TC-7486

Signed-off-by: Adva Oren <aoren@redhat.com>
Assisted-by: Claude Code
@sourcery-ai

sourcery-ai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Select the venv’s standard Python and pip executable names by platform, independent of the source interpreter name, while retaining Windows drive-letter path handling.

  • src/providers/python_controller.js L110-121

Tests

Add mocked coverage for Windows and POSIX venv executable selection across python and python3 sources, including exact paths anchored to the created venv.

  • test/providers/python_controller.test.js L6, L15-49, L120-186

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

@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 found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="test/providers/python_controller.test.js" line_range="142-143" />
<code_context>
+			// Then the pip upgrade runs through the venv Scripts/python.exe
+			expect(pipUpgradeInvocation.args).to.deep.equal(['-m', 'pip', 'install', '--upgrade', 'pip'])
+			expect(pipUpgradeInvocation.bin).to.equal(controller.pathToPythonBin)
+			expect(pathComponents(pipUpgradeInvocation.bin)).to.include('Scripts')
+			expect(path.basename(pipUpgradeInvocation.bin)).to.equal('python.exe')
+
+			// Then the venv pip path ends in Scripts/pip.exe
</code_context>
<issue_to_address>
**Wrong venv directory goes unnoticed**

When the executable paths point to a different directory that still contains `Scripts`, the Windows test accepts any path containing a `Scripts` component and the expected basename, so a path such as `/tmp/wrong/Scripts/python.exe` (and likewise for pip) passes without pointing into the venv it created.

Assert each executable path equals the expected path built from `controller.pythonEnvDir`, the platform-specific venv subdirectory, and the executable name.

Also at `test/providers/python_controller.test.js:146-147`.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: test/providers/python_controller.test.js:143


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@codecov-commenter

codecov-commenter commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.60%. Comparing base (ea9033d) to head (5836d6b).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #692      +/-   ##
==========================================
+ Coverage   91.49%   91.60%   +0.10%     
==========================================
  Files          44       44              
  Lines       11642    11638       -4     
  Branches     2347     2346       -1     
==========================================
+ Hits        10652    10661       +9     
+ Misses        990      977      -13     
Flag Coverage Δ
unit-tests 91.60% <100.00%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/providers/python_controller.js 89.61% <100.00%> (+2.70%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@a-oren
a-oren requested review from Strum355 and ruromero November 10, 2026 12:17
@a-oren

a-oren commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

[sdlc-workflow/verify-pr] Re: @sourcery-ai[bot] review — Classified as code change request — exact expected interpreter and pip paths should be anchored to the created venv directory, not only a Scripts component and executable basename. Sub-task TC-7502 created for this finding and duplicate inline comment 4524563687; no duplicate task created. Review item: review-body-5841416362.

@a-oren

a-oren commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Verification Report for TC-7486 (commit eb7eb92)

PR: #692
Verified HEAD: eb7eb920615a723ce6219c3e30d479bca4f3d3cf
Base: b0da026363c02cab2e195ff1e1bba80eb03370fc

Check Result Details
Review Feedback WARN Enumerated 1 inline thread and 1 substantive review body; both request the same exact-path assertions. Created one deduplicated blocking sub-task TC-7502 and replied to both items.
Root-Cause Investigation DONE Created TC-7504 for a language-agnostic test-oracle check in bug-fix task planning. Historical authoring-skill attribution remains unproven.
Scope Containment PASS Both changed files match the task; no extra or missing files. Temp-placement work in TC-7494 remains out of scope.
Diff Size PASS 2 expected files; +116/-16, 132 lines changed.
Commit Traceability PASS Sole commit references Implements TC-7486.
Sensitive Patterns PASS No sensitive patterns in 116 added lines across 2 files.
CI Status PASS All 6 checks pass; Ubuntu Node 22/24 jobs each report 1,051 passing.
Acceptance Criteria WARN 4/4 supported; native Windows report generation remains indirectly verified, not executed.
Test Quality PASS No repetitive-test or documentation issues. Eval Quality: N/A (no qualifying eval-result reviews).
Test Change Classification ADDITIVE Independent isolated classifier: +3 runtime cases, +19 assertion sites; no removed/weakened coverage.
Verification Commands FAIL Focused tests and lint pass; local full suite has 15 failures, all also reproduced on pristine base.

Overall: FAIL

The failure is the required local npm test command, not a demonstrated PR regression. All 15 HEAD failures also reproduce on pristine base; no HEAD-only failing test was found. Review-fix sub-task TC-7502 remains open. Acceptance verification is limited to mocked Windows behavior and source inspection; native Windows SBOM/report generation was not tested.

Review feedback

test/providers/python_controller.test.js:142-147: component/basename checks can accept an executable under the wrong venv directory. Assert independent exact interpreter and pip paths anchored to the created venv. Inline comment 4524563687 and review body 5841416362 are duplicates, both tracked by TC-7502. Source inspection found correct use of this.pythonEnvDir; this finding concerns regression-test strength, not an observed production wrong-directory defect.

Verification evidence

Command/check Result
npm run tests -- --grep "Python_controller" PASS — exit 0; 6 passing.
Failing-first replay: immutable base controller plus HEAD regression tests Expected failure — exit 1; 2 passing, 1 failing: expected 'python3.exe' to equal 'python.exe'. The corresponding HEAD case passes.
npm run lint PASS — exit 0; 0 errors, 16 warnings, identical to pristine base.
npm test at HEAD FAIL — exit 15; 1,036 passing, 15 failing. Both existing virtual-env golden-SBOM cases pass.
npm test at pristine base FAIL — exit 16; 1,032 passing, 16 failing. Same 15 failures plus one existing 2-second timeout.

Local failures: 10 missing-Poetry cases (spawnSync poetry ENOENT), 2 broken local pipdeptree launcher cases (No module named 'pipdeptree._runner'), and 3 OCI golden-SBOM mismatches also present on base. These are outside this task's executable-selection scope; CI has no failed checks requiring fix sub-tasks.

CI test run 42811649429 matches the verified HEAD and passes both Node jobs. Its runner is Ubuntu, not Windows.

Preventive follow-up

TC-7504 adds a test-oracle sufficiency method and eval coverage to bug-fix task generation. The original task explicitly prescribed basename/component checks, and the implementation followed that guidance. The earliest observable limitation is therefore test specification, not proven implementation noncompliance. There is no Feature/incorporates lineage, and available artifacts do not establish which skill or person authored the guidance. triage-bug is the proposed preventive location, not a proven historical invocation. The improvement preserves partial assertions when they adequately test the contract rather than requiring exact equality everywhere.

Root-cause and test-quality/classification rows are informational and excluded from the Overall verdict. The overall FAIL comes from Verification Commands; Review Feedback and indirect Windows acceptance verification are WARN.

No code was modified, no PR was merged, and no Jira status was transitioned.


This comment was AI-generated by sdlc-workflow/verify-pr v0.13.10.

Anchor the Windows pip-upgrade interpreter, pathToPythonBin, and
pathToPipBin expectations to the venv directory recorded on the -m venv
invocation instead of accepting any Scripts component with the expected
basename. Add a negative case proving a same-basename executable from a
different venv is rejected, and tighten POSIX expectations the same way.

Implements TC-7502

Signed-off-by: Adva Oren <aoren@redhat.com>
Assisted-by: Claude Code

@Strum355 Strum355 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some changes to make, as always, double check my logic on your end before making changes 😄

Comment thread src/providers/python_controller.js Resolved
Comment thread src/providers/python_controller.js Resolved
venv always installs the unversioned python and pip names, so the
includes("python3") heuristic only added a branch without changing
behavior. Use python/pip on both platforms and keep only the platform
directory and .exe handling. Update the POSIX regression cases to cover
both python3 and python sources.

Implements TC-7486

Signed-off-by: Adva Oren <aoren@redhat.com>
Assisted-by: Claude Code
sourcery-ai[bot]
sourcery-ai Bot previously approved these changes Nov 12, 2026

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

Sourcery assessment

Approved.

The removed test asserted inequality against a directory production can
never produce, so it could not fail for any plausible regression. The
exact-path equality assertions in the Windows cases already reject a
same-basename executable from another venv. Drop the test and its
now-unused pathComponents helper.

Implements TC-7502

Signed-off-by: Adva Oren <aoren@redhat.com>
Assisted-by: Claude Code
Strum355
Strum355 previously approved these changes Nov 12, 2026
Signed-off-by: Adva Oren <aoren@redhat.com>
@a-oren
a-oren merged commit ce9658d into guacsec:main Nov 12, 2026
9 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.

3 participants