fix: migrate API client HTTP transport from node-fetch to undici#2794
fix: migrate API client HTTP transport from node-fetch to undici#2794brendandburns merged 4 commits intomax-regen-genfrom
Conversation
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Copilot The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot I think that many of your unit test changes delete verifications that were present in the original tests. Can you make sure that as you update tests you are retaining all relevant checks and that the tests remain unchanged other than API changes related to the undici library. |
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
…gent Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
Fixed in commit 2e86fcf. Here's what was restored/fixed: Proxy tests (config_test.ts): Re-added CA and proxy URI verification using undici's internal symbols (
Body verification (object_test.ts metrics.ts and metrics_test.ts: Migrated top_test.ts: Converted from nock to undici All 343 tests pass with lint and formatter clean. |
The regenerated OpenAPI client switched from
node-fetchtoundici, but the codebase was never updated to match, causing build failures and broken authentication.Changes
undicidependencyundicitopackage.json— it was imported in generated files but never listed as a dependency.src/config.ts— dispatcher migrationcontext.setAgent()(removed in new generatedRequestContext) withcontext.setDispatcher().createDispatcher()alongside the existingcreateAgent(): produces an undiciAgent(with TLSconnectoptions) orProxyAgent(HTTP/HTTPS proxies) usingrequestTlsso TLS options are properly threaded through proxy connections.undefinedwhen no TLS options are present, allowing undici to fall through to the global dispatcher (preservesMockAgentbehavior in tests).src/metrics.ts— fetch migrationnode-fetchto undicifetchby usingapplySecurityAuthenticationon aRequestContextto obtain auth headers and dispatcher.ECONNREFUSEDsurface throughfetch failed).src/util.tsnormalizeResponseHeadersto accept any response with aheaders.entries()method, removing the hard dependency on thenode-fetchResponsetype.Test updates
config_test.ts,azure_auth_test.ts,gcp_auth_test.ts: switched assertions fromgetAgent()togetDispatcher(), checking forUndiciAgent/UndiciProxyAgentinstances. Restored proxy CA verification viaSymbol(request tls settings)and proxy URI verification viaSymbol(proxy agent options).clusterG/contextG/userGtotestdata/kubeconfig-proxy-url.yamlfor the "https server, no proxy" test case.integration_test.ts,object_test.ts,metrics_test.ts,top_test.ts: replacednockwith undiciMockAgent— nock patcheshttp.ClientRequestwhich undici bypasses entirely.mockAgent.assertNoPendingInterceptors()as the equivalent of nock'sscope.done()to verify expected HTTP requests were actually made.object_test.ts(_fromTypeScript field →fromJSON key) restored using undici's regex body matching.✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.