chore(axios,appex-qa): remove axios from shared test infrastructure#268531
Draft
azasypkin wants to merge 3 commits intoelastic:mainfrom
Draft
chore(axios,appex-qa): remove axios from shared test infrastructure#268531azasypkin wants to merge 3 commits intoelastic:mainfrom
azasypkin wants to merge 3 commits intoelastic:mainfrom
Conversation
|
🤖 Jobs for this PR can be triggered through checkboxes. 🚧
ℹ️ To trigger the CI, please tick the checkbox below 👇
|
Contributor
💔 Build Failed
Failed CI Steps
Test Failures
Metrics [docs]Public APIs missing comments
Public APIs missing exports
Unknown metric groupsAPI count
History
|
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
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.
Summary
Important
NOTE TO CODE OWNERS: I'm modifying code I don't own day to day. Please verify the changes still work as expected. For these migrations a quick run of the affected scripts/tests is worth more than a code-only review.
This PR removes the
axiosdependency for files owned by@elastic/kibana-operationsand@elastic/appex-qa(jointly). Phase 5 of the axios migration tracked under #266556.Why
Node.js 22 ships a native
fetchAPI built on undici, and every browser Kibana targets supportsfetchnatively. Removing axios cuts one runtime dependency and continues the per-team rollout that mirrors the earlier node-fetch migration (#250719 and siblings).This phase covers the shared test infrastructure cluster (
kbn-test-saml-auth,kbn-kbn-client,kbn-journeys,kbn-failed-test-reporter-cli) plus a couple of leaf scripts. These utilities are consumed by tests across the codebase, so getting them off axios early simplifies later phases that touch test code.Changes
13 files migrated, grouped by area:
kbn-failed-test-reporter-cli(CI failure reporter):existing_failed_test_issues.tsandgithub_api.ts. The Github API helper had its ownaxios.createinstance with retry logic andisAxiosResponseError/isAxiosRequestErrorerror guards from@kbn/dev-utils; replaced with inlinefetchplus explicit non-2xx vs network-error branches. Updated the corresponding test fromjest.mock('axios')tojest.spyOn(global, 'fetch').kbn-test-saml-auth(SAML auth flows for FTR/Scout):saml_auth.ts(5 axios call sites: cloud login, SAML request, SAML response, SAML callback, security profile) andfetch_kibana_version.ts. SAML'smaxRedirects: 0flag becameredirect: 'manual'since the flow has to inspect the 302 itself, not follow it.validateStatus: () => trueis now implicit (fetch never auto-throws). HTTPS agent (https.Agentfor self-signed certs) becameundici.Agentvia thedispatcheroption. Tests switched tojest.spyOn(global, 'fetch')withResponse-based mocks;mockResolvedValuewas changed tomockImplementationfor the retry tests sinceResponsebody streams can only be consumed once.kbn-journeys(FTR test harness):services/auth.ts(Kibana login) andjourney/journey_ftr_harness.ts. The harness's catch handler that detected 404 via(error as AxiosError).response?.statusnow reads(error as { status?: number }).statusagainst the newKbnClientRequesterErrorshape (see next bullet).kbn-kbn-client(the shared HTTP client used by FTR/Scout test runners):kbn_client_requester.ts,kbn_client_requester_error.ts, and the requester-error test. The internalaxios.requestcall becamefetchwith a manual{ data, status, statusText, headers }envelope that preserves the public API for the ~10 sibling consumer files (kbn_client_saved_objects.ts,kbn_client_ui_settings.ts,kbn_client_import_export.ts, etc.) that only destructure.data. TheKbnClientRequesterErrorclass lost its.axiosErrorfield and now exposes.status?: numberdirectly, with the underlying error attached viaError.cause.kbn-ftr-common-functional-services/services/security/role.ts(transitive consumer): updated the catch handler that reade.axiosError.responseto usee.statusande.messagefrom the newKbnClientRequesterErrorshape. Same owners (ops + appex-qa) as the requester change.x-pack/platform/test/api_integration/services/spaces.ts(FTR Spaces service): had its ownAxios.createinstance with custom HTTPS agent andvalidateStatus: () => true. Replaced with a small inlinerequest()helper over fetch that returns the same{ data, status, statusText }envelope used by all 5 call sites (post/put/delete/get/get).Removed the corresponding entries from
AXIOS_LEGACY_CONSUMERSin.eslintrc.js(5 globs total). New axios usage in any of these directories is now blocked by the existing global ban.Behavior parity
res.ok/res.statusexplicitly. axios threw automatically.body: JSON.stringify(payload)and explicitContent-Type: application/json(axios set the header implicitly when given an object body).await res.json()/.text()instead ofres.data. Thekbn-kbn-clientrequester centralizes this in areadBody<T>helper that respects theresponseType: 'text' | 'json' | 'stream' | ...flag the public API exposed.https.Agent({ rejectUnauthorized })→undici.Agent({ connect: { rejectUnauthorized } })via thedispatcheroption (Node fetch uses undici under the hood).Headers.getSetCookie()(Node 22 / undici) with a fallback toHeaders.get('set-cookie')for jsdom test environments that don't yet havegetSetCookie.AbortSignal.timeout(ms)where the runtime supports it; one helper falls back toAbortController + setTimeoutbecause jsdom 20 (the default jest test env) doesn't haveAbortSignal.timeout.maxRedirects: 0→redirect: 'manual'. Critical for the SAML flow which has to inspect the 302 itself rather than follow it.maxContentLength/maxBodyLength): no fetch equivalent, dropped. Kibana endpoints have their own limits.jest.mock('axios')/jest.spyOn(axios, 'request')→jest.spyOn(global, 'fetch')withResponse-based mocks. Argument-shape assertions adapted (axios's third arg is the config object; fetch passes everything in the second arg'sinit).Contract changes worth a closer look
KbnClientRequesterError.axiosErrorremoved, replaced with.status?: numberand standardError.cause. One external consumer (kbn-ftr-common-functional-services/services/security/role.ts) updated in this PR.kbn-evals/src/utils/http_handler_from_kbn_client.tsreads.axiosErrortoo but uses?? errand a guardedif, so it gracefully handles the now-undefined field with no behavior change. That file will be cleaned up later in its owners' phase.KbnClientRequester.request<T>()return type renamed fromAxiosResponse<T>toKbnClientResponse<T>({ data, status, statusText, headers }). All sibling consumers inkbn-kbn-client/and external consumers inkbn-evals,agent_builder, and security tests only destructure.dataso they keep working unchanged. The headers field type changed from axios's record-shape to fetch'sHeadersclass; grepped the codebase forheaders[...]bracket access onKbnClientRequesterresults and found none.Backport audit
Per the per-phase audit, most files are byte-identical with
mainon the four backport branches; cherry-picks should apply cleanly. Notable drift to expect manual fixups for:journey_ftr_harness.tsdiffers ~219 lines on8.19(pre-existing drift, unrelated to axios)saml_auth.tsdiffers ~13 lines on8.19, ~3 lines on9.2kbn_client_requester.ts,auth.ts,github_api.ts,spaces.ts: small drifts (3-12 lines) on at least one older branchkbn_client_requester_error.test.tsis missing on 9.2 and 9.3 (test was added later); the backport there will skip that file