Skip to content

feat: add Python patching support with comprehensive tests#28

Merged
Mikola Lysenko (mikolalysenko) merged 5 commits intomainfrom
feature/add-python-patching-tests
Feb 13, 2026
Merged

feat: add Python patching support with comprehensive tests#28
Mikola Lysenko (mikolalysenko) merged 5 commits intomainfrom
feature/add-python-patching-tests

Conversation

@mikolalysenko
Copy link
Copy Markdown
Contributor

Summary

Add Python ecosystem support to socket-patch with comprehensive test coverage:

  • PythonCrawler: Discovers packages in site-packages via dist-info/METADATA files
  • PURL utilities: PyPI package parsing, qualification stripping
  • Apply/rollback: Full support for PyPI packages with qualifier variant fallback
  • Scan integration: Combined npm + python scanning with ecosystem summary
  • Test utilities: createTestPythonPackage helper and pypi support in setupTestEnvironment

Test Coverage (52 new tests across 6 files)

File Tests Coverage
purl-utils.test.ts 10 PURL parsing, stripping, type detection
python-crawler.test.ts 18 Crawl, batch, dedup, findByPurls, PEP 503 normalization
apply-python.test.ts 5 Apply patches to pypi packages, mixed ecosystems, dry-run
apply-qualifier-fallback.test.ts 5 Variant selection, hash matching, rollback mapping
scan-python.test.ts 5 Combined scanning, API integration, ecosystem summary
python-venv.test.ts 5 Real venv tests (skip if python3 unavailable)

All 195 tests pass (52 new + 143 existing, 0 regressions).

🤖 Generated with Claude Code

- Add getBunGlobalPrefix() function to detect bun's global package path
- Update getGlobalNodeModulesPaths() to include pnpm, yarn, and bun paths
- Export getBunGlobalPrefix() for external use

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Export the getBunGlobalPrefix function to allow checking bun's global
package prefix. Also adds test coverage for the export.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add Python ecosystem support to socket-patch including:
- PythonCrawler for discovering packages in site-packages via dist-info/METADATA
- PURL utilities for PyPI package parsing and qualification stripping
- Apply/rollback support for PyPI packages with qualifier variant fallback
- Scan command integration with ecosystem summary (npm + python)

Test coverage (52 new tests across 6 files):
- purl-utils: stripPurlQualifiers, isPyPIPurl, isNpmPurl, parsePyPIPurl
- python-crawler: canonicalizePyPIName, crawlAll, crawlBatches, findByPurls,
  findPythonDirs, findLocalVenvSitePackages, getSitePackagesPaths
- apply-python: patch application to pypi packages, mixed npm+pypi, dry-run
- apply-qualifier-fallback: variant selection, hash matching, dedup
- scan-python: combined scanning, API integration, ecosystem summary
- python-venv: real venv tests (skippable if python3 unavailable)

Also exports canonicalizePyPIName, findPythonDirs, findLocalVenvSitePackages
from crawlers module, and extends test-utils with createTestPythonPackage
and pypi support in setupTestEnvironment.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Ensure finally blocks always restore process.env.VIRTUAL_ENV to its
original state, including deleting it when it was originally undefined.
Prevents env var leaks between tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove the python3 -c fallback from findLocalVenvSitePackages.
In local mode (non-global), only project-local venvs should be scanned
(VIRTUAL_ENV, .venv, venv). System-wide packages are only discovered
when --global is passed, via getGlobalPythonSitePackages.

This fixes e2e test failures where empty projects incorrectly found
system Python packages on CI runners.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mikolalysenko Mikola Lysenko (mikolalysenko) merged commit 7b8f849 into main Feb 13, 2026
4 checks passed
@mikolalysenko Mikola Lysenko (mikolalysenko) deleted the feature/add-python-patching-tests branch February 13, 2026 22:04
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.

1 participant