-
Notifications
You must be signed in to change notification settings - Fork 81
fix: auto-install extension filtering logic and add comprehensive tests #6434
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
Merged
Conversation
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
Previously, extensions were being auto-installed on all sites with the feature flag enabled, regardless of whether the required packages were present in package.json. This caused mass installations of extensions like Neon on accounts that didn't need them. Now properly filters extensions to only install when: 1. Extension is not already installed, AND 2. At least one required package exists in project dependencies Fixes the logic in handleAutoInstallExtensions to check package.json dependencies before attempting installation.
Previously, auto-install extensions used `cwd` to look for package.json, but this isn't always the correct location. The config system calculates `buildDir` which represents the proper base directory where package.json should be found (either `build.base` or `repositoryRoot`). Changes: - Pass `buildDir` instead of `cwd` to handleAutoInstallExtensions - Update parameter and error logging to use buildDir - Gracefully fail if no package.json found in buildDir - Maintain existing package detection logic without new dependencies
- Use buildDir instead of cwd when reading package.json in auto-install extensions - Add extensionApiBaseUrl parameter to fetchAutoInstallableExtensionsMeta for test mocking - Update main config to use testOpts.host for extension API calls in test environment - Add comprehensive test suite covering: - Feature flag disabled/enabled scenarios - Missing package.json graceful handling - Package detection logic (with/without required packages) - buildDir resolution with and without netlify.toml - Mock auto-installable extensions API for deterministic testing Fixes mass installation bug where extensions were installed on all sites regardless of whether required packages were present in dependencies.
…ints - Add global fetch mock to intercept external extension installation requests - Mock installation endpoint responses without modifying implementation code - Track installation requests for comprehensive test assertions - Verify correct HTTP method, URL, headers, and request body - Add unique mock response identifiers for verification - Maintain clean separation between test and production code This approach properly mocks external HTTP requests using test-only code, ensuring no real network calls are made during testing while preserving the original implementation behavior.
Contributor
|
This pull request adds or modifies JavaScript ( |
- Revert implementation changes to fetchAutoInstallableExtensionsMeta and main.ts - Extend global fetch mock to handle both installation and extension API endpoints - Remove server-side mocks in favor of pure fetch interception - Maintain clean separation between test and production code This approach provides complete HTTP mocking without polluting the implementation with test-specific logic, following proper testing best practices.
Contributor
|
This pull request adds or modifies JavaScript ( |
khendrikse
approved these changes
Jun 5, 2025
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.
Problem
Previously, extensions were being auto-installed on all accounts with the feature flag enabled, regardless of whether the required packages were present in package.json. This caused mass installations of extensions like Neon on accounts that didn't need them.
The core issues were:
cwdinstead ofbuildDirfor reading package.jsonSolution
🔧 Core Bug Fixes
buildDirinstead ofcwdfor package.json detection to respect Netlify's build configuration🧪 Comprehensive Test Suite
🎯 Proper Extension Filtering
Now properly filters extensions to only install when:
Technical Details
Files Changed:
src/utils/extensions/auto-install-extensions.ts- Fixed filtering logic and updated to use buildDirtests/extensions/- Complete test suite with fixtures and HTTP mockingTest Coverage:
HTTP Mocking Strategy:
Impact
This fix prevents the mass installation bug that was causing extensions to be installed on accounts regardless of whether they had the required packages. The comprehensive test suite ensures this regression won't happen again and provides confidence in the auto-install logic across different project configurations.
Testing
npm test -- tests/extensions/tests.jsAll tests pass and verify:
For us to review and ship your PR efficiently, please perform the following steps:
we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or
something that`s on fire 🔥 (e.g. incident related), you can skip this step.
your code follows our style guide and passes our tests.
A picture of a cute animal (not mandatory, but encouraged)