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

feat: use urllib@4.5.0 #5371

Merged
merged 2 commits into from
Nov 30, 2024
Merged

feat: use urllib@4.5.0 #5371

merged 2 commits into from
Nov 30, 2024

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Nov 30, 2024

auto fallback to urllib@3 when require urllib4 error

Summary by CodeRabbit

  • New Features

    • Expanded CI workflow to include Node.js version 23 for testing.
    • Enhanced HttpClientNext class with improved error handling and configuration management.
    • Added support for HTTP/2 functionality in the test suite, including self-signed certificate handling.
  • Bug Fixes

    • Improved error handling for library imports based on Node.js versions.
  • Chores

    • Updated dependency versions in package.json.
    • Modified HTTP client configuration to include a new connect property.

Copy link

coderabbitai bot commented Nov 30, 2024

Walkthrough

The pull request introduces several updates across multiple files. The CI workflow configuration is modified to include Node.js version 23. The HttpClientNext class in lib/core/httpclient_next.js is enhanced with improved error handling for dynamic imports and a new connect property. The package.json file updates the urllib4 dependency version and adds a new dependency, https-pem. Additionally, the httpclient configuration file is updated to include a connect property with SSL settings, and the test suite for the HTTP client is enhanced to support HTTP/2 functionality.

Changes

File Change Summary
.github/workflows/nodejs-3.x.yml Updated Node.js version parameter to include 23 in CI workflow.
lib/core/httpclient_next.js Enhanced error handling for dynamic imports, added connect property in constructor, updated safeCurl method.
package.json Updated urllib4 version from ^4.3.0 to ^4.5.0, added new dependency https-pem with version ^3.0.0.
test/fixtures/apps/httpclient-allowH2/config/config.default.js Added connect property with rejectUnauthorized: false to httpclient configuration.
test/lib/core/httpclient.test.js Enhanced test suite with support for HTTP/2, added new test case for HTTP/2 server interaction.

Possibly related PRs

  • feat: allow to httpClient use HTTP2 first #5332: The changes in the HttpClientNext class in lib/core/httpclient_next.js related to adding the allowH2 property are directly connected to the main PR's updates in the same file, indicating a focus on HTTP/2 functionality.

Suggested labels

core: httpclient

Poem

In the fields where rabbits play,
New changes hop in bright array.
With Node.js versions now in line,
Our HTTP clients will surely shine!
Error handling, tests galore,
Let’s celebrate and hop some more! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Nov 30, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 99.69%. Comparing base (4d401d5) to head (fdcb529).
Report is 1 commits behind head on 3.x.

Files with missing lines Patch % Lines
lib/core/httpclient_next.js 83.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              3.x    #5371      +/-   ##
==========================================
- Coverage   99.74%   99.69%   -0.06%     
==========================================
  Files          35       35              
  Lines        3573     3583      +10     
  Branches      527      528       +1     
==========================================
+ Hits         3564     3572       +8     
- Misses          9       11       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fengmk2 fengmk2 changed the title test: run test on Node.js 23 feat: use urllib@4.5.0 Nov 30, 2024
@fengmk2
Copy link
Member Author

fengmk2 commented Nov 30, 2024

@coderabbitai review

Copy link

coderabbitai bot commented Nov 30, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
test/lib/core/httpclient.test.js (1)

331-361: Enhance test reliability and resource management in HTTP/2 test

The new test case for HTTP/2 with a self-signed certificate is valuable. Consider the following improvements:

  • Use a try...finally block to ensure the server is closed even if the test fails, preventing resource leaks.
  • Update the test description for clarity.

Apply this diff to improve the test:

 it('should work on http2.server with self-signed certificate', async () => {
   const server = createSecureServer(pem);
   server.on('stream', (stream, headers) => {
     // ...
   });
   server.listen(0);
   await once(server, 'listening');
+  try {
     const response = await app.httpclient.request(`https://localhost:${server.address().port}`, {
       dataType: 'text',
       headers: {
         'x-my-header': 'foo',
       },
     });
     assert.equal(response.status, 200);
     assert.equal(response.headers['x-custom-h2'], 'hello');
     assert.equal(response.data, 'hello h2!');
+  } finally {
+    server.close();
+  }
 });

This ensures that the server is properly closed after the test, even if an error occurs.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4d401d5 and fdcb529.

📒 Files selected for processing (5)
  • .github/workflows/nodejs-3.x.yml (1 hunks)
  • lib/core/httpclient_next.js (3 hunks)
  • package.json (2 hunks)
  • test/fixtures/apps/httpclient-allowH2/config/config.default.js (1 hunks)
  • test/lib/core/httpclient.test.js (2 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
lib/core/httpclient_next.js

[warning] 14-15: lib/core/httpclient_next.js#L14-L15
Added lines #L14 - L15 were not covered by tests

🔇 Additional comments (7)
.github/workflows/nodejs-3.x.yml (1)

15-15: Update CI Workflow to Include Node.js v23

Adding Node.js version 23 to the CI workflow is a proactive step to ensure compatibility with the latest Node.js release. This helps in identifying potential issues early and keeps the project up-to-date.

lib/core/httpclient_next.js (1)

10-15: 🛠️ Refactor suggestion

Enhance Error Logging for 'urllib4' Import Failure

When attempting to import urllib4, the error is currently logged using debug, which may not be sufficient to alert developers to critical issues.

  • Use a Higher Severity Logging Method: Replace debug with this.app.logger.error to ensure that import failures are prominently logged and monitored.
  • Improve Error Message Clarity: Provide a clear and descriptive error message to facilitate easier debugging.

Static analysis indicates that lines 14-15 are not covered by tests. To confirm and address this:

Consider adding test cases to cover this scenario to improve test coverage.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 14-15: lib/core/httpclient_next.js#L14-L15
Added lines #L14 - L15 were not covered by tests

package.json (2)

59-59: Verify compatibility and potential breaking changes for urllib4 update

The urllib4 dependency has been updated to version ^4.5.0. Please ensure that this version is compatible with the existing codebase and that it does not introduce any breaking changes.

Review the changelog to check for breaking changes:

✅ Verification successful

Based on the changelog, I can generate the final response since I have enough information to verify the compatibility and potential breaking changes for the urllib4 update from version 4.3.0 to 4.5.0.

No breaking changes found in urllib4 update to ^4.5.0

The changes between 4.3.0 and 4.5.0 include:

  • Upgrade to undici v7 (4.5.0)
  • Added fetch implementation (4.4.0)
  • Fixed type exports (4.3.1)

All changes are backwards compatible feature additions and bug fixes. The major version (4.x.x) remains unchanged, indicating no breaking changes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for breaking changes between urllib versions 4.3.0 and 4.5.0.

# Fetch the changelog from GitHub
curl -s https://raw.githubusercontent.com/node-modules/urllib/master/CHANGELOG.md | less

Length of output: 49723


82-82: Verify the necessity and security of adding https-pem dependency

The new dependency https-pem has been added. Ensure that this addition is necessary and does not introduce security vulnerabilities.

Run the following script to check for known security advisories related to https-pem:

✅ Verification successful

Let me gather more information about how this dependency is being used in the codebase.


Let me check the test file to understand how https-pem is being used.


Based on the analysis of the test file and codebase, I can now provide a final response:

The https-pem dependency is safely used for testing HTTP/2 servers with self-signed certificates

The package is only used in test files for creating secure HTTP/2 servers with self-signed certificates during testing. It's not used in production code or for handling sensitive data. The package has no known security vulnerabilities according to GitHub's Security Advisory Database.

  • Used in test/lib/core/httpclient.test.js specifically for testing HTTP/2 functionality
  • Only imported and used within test environment
  • No production code dependencies on this package
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for security advisories for the 'https-pem' package.

# Query GitHub Security Advisory Database
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: NPM, package: "https-pem") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
      firstPatchedVersion {
        identifier
      }
    }
  }
}'

Length of output: 342


Script:

#!/bin/bash
# Search for usage of https-pem in the codebase
rg -l "https-pem" --type js --type ts

# Search for any configuration files or certificates
fd -e pem
fd -e key
fd -e crt

# Look for imports or requires of https-pem
ast-grep --pattern 'require("https-pem")' 
ast-grep --pattern 'from "https-pem"'

Length of output: 190


Script:

#!/bin/bash
# Check the content of the test file to understand the usage
cat test/lib/core/httpclient.test.js

# Also check if there's a corresponding implementation file
rg -l "httpclient" --type js --type ts

Length of output: 23938

test/lib/core/httpclient.test.js (3)

2-2: Ensure compatibility with Node.js versions for 'node:events' import

The import statement for once uses the 'node:events' prefix:

const { once } = require('node:events');

Verify that this syntax is compatible with the minimum Node.js version specified in package.json (>= 14.20.0), as the 'node:' protocol was introduced in Node.js 12.12.0.


3-3: Confirm Node.js version supports the 'http2' module

The http2 module is imported:

const { createSecureServer } = require('node:http2');

Ensure that the Node.js version used in the project supports the http2 module, which became stable in Node.js 10.10.0.


6-6: Confirm that 'https-pem' is included in dependencies

The https-pem module is required:

const pem = require('https-pem');

Ensure that https-pem is listed in the project's dependencies in package.json to prevent runtime errors.

@fengmk2 fengmk2 merged commit e4f7069 into 3.x Nov 30, 2024
24 of 26 checks passed
@fengmk2 fengmk2 deleted the node-23-test branch November 30, 2024 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant