Skip to content
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

fix: functions with name matching config prop cause crash #4748

Merged
merged 20 commits into from
Jul 11, 2022
Merged

Conversation

JWhist
Copy link
Contributor

@JWhist JWhist commented Jun 28, 2022

🎉 Thanks for submitting a pull request! 🎉

Summary

Fixes #4679

Fixes bug by sending appropriate functions config data to zisi for bundling.


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures 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.
  • Read the contribution guidelines 📖. This ensures your code follows our style guide and
    passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)

@github-actions github-actions bot added the type: bug code to address defects in shipped code label Jun 28, 2022
@github-actions
Copy link

github-actions bot commented Jun 28, 2022

📊 Benchmark results

Comparing with 74527f4

Package size: 227 MB

(no change)

^                                                                                                  227 MB 
│  221 MB  221 MB  221 MB  221 MB  221 MB  221 MB  221 MB  221 MB  221 MB  221 MB  221 MB  221 MB   ┌──┐  
│   ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    ┌──┐    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-12    T-11    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend

@JWhist JWhist marked this pull request as ready for review June 28, 2022 19:15
@@ -840,4 +840,25 @@ test('should handle content-types with charset', async (t) => {
})
})

test('should execute function when name clashes with config key names', async (t) => {
Copy link
Member

Choose a reason for hiding this comment

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

The fix itself looks good to me, but I'm not sure this is the right test to add. The fact that a function name was clashing with a config property was not the underlying problem, it was one of the side effects. The underlying problem was that CLI was sending the wrong configuration object to zip-it-and-ship-it, and I think that's what we should assert in the test.

I think the best way to do that would be to stub the call to zip-it-and-ship-it, which isn't very straightforward in this type of integration test (i.e. using withDevServer and testing the end-to-end flow).

Instead, you could write a unit test for the functions registry, asserting that it receives the entire configuration in its constructor but then passes just the functions block to zip-it-and-ship-it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I disagree slightly here. Having a unit test is the way to go, but I would keep the integration test. Even though it might not have been the root cause, it is a really good test to have.
If we ever have the same wrong behavior again due to refactors or other changes, but because of a different root cause we would catch it here.

@JWhist JWhist requested a review from a team July 1, 2022 12:59
eduardoboucas
eduardoboucas previously approved these changes Jul 1, 2022
Copy link
Member

@eduardoboucas eduardoboucas left a comment

Choose a reason for hiding this comment

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

Nice! I left a couple of non-blocking comments.

tests/unit/lib/functions/registry.test.js Outdated Show resolved Hide resolved
tests/unit/lib/functions/registry.test.js Outdated Show resolved Hide resolved
tests/unit/lib/functions/registry.test.js Outdated Show resolved Hide resolved
tests/unit/lib/functions/registry.test.js Outdated Show resolved Hide resolved
tests/unit/lib/functions/registry.test.js Outdated Show resolved Hide resolved
@@ -840,4 +840,25 @@ test('should handle content-types with charset', async (t) => {
})
})

test('should execute function when name clashes with config key names', async (t) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I disagree slightly here. Having a unit test is the way to go, but I would keep the integration test. Even though it might not have been the root cause, it is a really good test to have.
If we ever have the same wrong behavior again due to refactors or other changes, but because of a different root cause we would catch it here.

@JWhist JWhist requested a review from danez July 7, 2022 16:08
danez
danez previously approved these changes Jul 7, 2022
@JWhist JWhist removed the request for review from karagulamos July 8, 2022 13:35
@github-actions
Copy link

github-actions bot commented Jul 8, 2022

📊 Benchmark results

Comparing with 13dd3a3

Package size: 227 MB

(no change)

^  227 MB  227 MB  227 MB  227 MB 
│   ┌──┐    ┌──┐    ┌──┐    ┌──┐  
│   |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴──>
    T-3     T-2     T-1      T    
Legend

@JWhist JWhist dismissed eduardoboucas’s stale review July 8, 2022 13:36

Eduardo is OOO, and review is stale

@JWhist
Copy link
Contributor Author

JWhist commented Jul 8, 2022

Unable to merge this due to problems with the CI failing (integration test 130 in particular, and other eleventy tests unrelated to this change, they were fine yesterday - I've retried numerous times)

@JWhist JWhist merged commit 19aee7c into main Jul 11, 2022
@JWhist JWhist deleted the functionError branch July 11, 2022 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: `` is not an Option Object when using plugins.js as a function name
3 participants