-
Notifications
You must be signed in to change notification settings - Fork 5
feat: treat namespaces as a special case when checking for typos #378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
/lgtm review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🦉 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
scastlara
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
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