feat: treat namespaces as a special case when checking for typos#378
Merged
sdn4z merged 1 commit intoelementsinteractive:mainfrom Nov 3, 2025
Merged
feat: treat namespaces as a special case when checking for typos#378sdn4z merged 1 commit intoelementsinteractive:mainfrom
sdn4z merged 1 commit intoelementsinteractive:mainfrom
Conversation
Collaborator
Author
|
/lgtm review |
Contributor
There was a problem hiding this comment.
🦉 lgtm Review
Score: Needs a Lot of Work 🚨
🔍 Summary
This PR introduces a solid architectural refactoring, using a TrustedPackagesProtocol to support different package ecosystems like PyPI and npm. This makes the system more extensible.
However, there are three critical correctness bugs that must be fixed before merging:
- The
TrustedNpmPackageManager.__contains__method is implemented incorrectly and will fail for namespaced packages. - The
top_npm_reference.pyfile is missing animport re, which will cause a runtimeNameError. - Invalid npm package names are silently ignored, which is inconsistent with the PyPI implementation and could hide issues in the trusted source data.
I've also included suggestions to improve performance in NormalizedPackages and to add unit tests for the new npm-specific logic. Given the critical issues, the PR needs significant work.
More information
- Id:
e2d96ad3e5a840a7b8f7c79a0755a0e6 - Model:
gemini-2.5-pro - Created at:
2025-10-30T11:16:19.720185+00:00
Usage summary
- Request count:
2 - Request tokens:
83,337 - Response tokens:
19,093 - Total tokens:
102,430
See the 📚 lgtm-ai repository for more information about lgtm.
src/twyn/trusted_packages/managers/trusted_npm_packages_manager.py
Outdated
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR makes a difference between normal packages and packages with a namespace. For the latter, the behaviour has been extended so that we check only in the namespace for a typo, and if there's a possible one, we require the package to be identical to the legit one.
For example:
@aws/sdk@awz/zdk(namespace could be a typo, but package name does not match trusted one)@awz/sdk(namespace could be a typo, package name matches trusted one)This will help reduce the number of false positives and assumes that if someone is impersonating a package, they'll mimic the namespace but keep the package identical.
refs #97