Skip to content

Fix has_manifest_files failing to match root-level manifest files#168

Merged
lelia merged 5 commits intomainfrom
fix/has-manifest-files-root-path-matching
Mar 6, 2026
Merged

Fix has_manifest_files failing to match root-level manifest files#168
lelia merged 5 commits intomainfrom
fix/has-manifest-files-root-path-matching

Conversation

@dc-larsen
Copy link
Contributor

Summary

has_manifest_files() unconditionally prepends **/ to patterns without /, then matches using PurePath.match(). In Python 3.12+, PurePath("package.json").match("**/package.json") returns False because ** requires at least one directory component. Root-level manifest files (the common case) never match.

This sets has_supported_files=False, forcing every scan into full scan mode instead of diff scan mode. Full scans don't post MR/PR comments.

Fix

Try the direct pattern match first (handles root-level files), then fall back to **/ prefixed pattern for subdirectory matching.

Reproduction

  1. Create a git repo with package.json at the root
  2. Run socketcli --target-path . --enable-debug --enable-diff
  3. Before fix: has_supported_files=False, falls back to full scan
  4. After fix: has_supported_files=True, proceeds with diff scan

Test plan

  • Added unit tests for root-level, subdirectory, wildcard, and edge cases (11 tests)
  • Reproduced locally on Python 3.14, confirmed fix resolves the issue
  • Verify socketdev/cli:latest Docker image Python version

Fixes Zendesk #2447

PurePath.match("**/package.json") returns False for root-level files
in Python 3.12+ because ** requires at least one directory component.
The function was unconditionally prepending **/ to all patterns,
causing root-level manifests like package.json and package-lock.json
to never match. This forced every scan into full scan mode instead of
diff scan mode, which meant MR/PR comments were never posted.

Fix by trying the direct pattern match first, then falling back to
the **/ prefixed pattern for subdirectory matching.

Fixes Zendesk #2447
@dc-larsen dc-larsen requested a review from a team as a code owner March 4, 2026 21:37
@github-actions
Copy link

github-actions bot commented Mar 4, 2026

🚀 Preview package published!

Install with:

pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple socketsecurity==2.2.77.dev3

Docker image: socketdev/cli:pr-168

@dc-larsen dc-larsen requested a review from lelia March 4, 2026 21:38
@lelia
Copy link
Contributor

lelia commented Mar 5, 2026

Version Check Failed

Please increment...

@dc-larsen you can resolve this locally by running python .hooks/version_check.py

Copy link
Contributor

@lelia lelia left a comment

Choose a reason for hiding this comment

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

@dc-larsen I recently added a GH workflow that will automatically runs unit tests for the CLI when PRs are opened, but I realized it won't pick up anything under /tests/core/**/*.py. Could you please make the following updates:

  • Update .github/workflows/python-tests.yml to trigger on tests/core/**/*.py (not just tests/unit/**/*.py)
  • Update the workflow test command (L50) to run both suites (or all tests), e.g. uv run pytest -q tests/unit/ tests/core/ or uv run pytest -q tests/

Thanks!

Copy link
Contributor Author

@dc-larsen dc-larsen left a comment

Choose a reason for hiding this comment

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

Done — added tests/core/**/*.py to the trigger paths and updated the test command to run both suites.

lelia added 2 commits March 5, 2026 19:38
…test construction

Signed-off-by: lelia <lelia@socket.dev>
@lelia
Copy link
Contributor

lelia commented Mar 6, 2026

Done — added tests/core/**/*.py to the trigger paths and updated the test command to run both suites.

Thanks! Looks like that has surfaced some legitimate test failures, but I don't believe they were introduced by your PR.

Rather, there's been some substantial drift between several core unit tests and the SDK model that the CLI relies upon, and because these tests weren't running continuously, it's likely they've been silently failing for a while.

If you're curious, here's the details for the fixes I just pushed up to get tests passing:

  • Updated stale core test fixtures/mocks to match current SDK/core behavior:
    • tests/core/conftest.py
    • tests/data/repos/repo_info_success.json
    • tests/data/repos/repo_info_no_head.json
  • Updated outdated test expectations and object construction in:
    • tests/core/test_sdk_methods.py
    • tests/core/test_package_and_alerts.py
    • tests/core/test_supporting_methods.py
    • tests/core/test_diff_generation.py
    • tests/core/test_has_manifest_files.py
  • Fixed real core compatibility gaps surfaced by enabling tests/core:
    • socketsecurity/core/classes.py
      • Package now supports optional release/diffType in full-scan contexts
      • from_diff_artifact now handles current diff artifact shapes (including enum diffType and flattened/no-ref variants)
    • socketsecurity/core/__init__.py
      • get_sbom_data now consistently returns artifact dicts (matching downstream usage)

Now that we have these tests running regularly, we should be able to prevent a lot more CLI <> SDK drift! 🎉

@lelia lelia merged commit 4903ae3 into main Mar 6, 2026
10 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