[9.3] chore(axios,security-engineering-productivity): remove axios from run_cypress scripts (#267684)#267733
Merged
kibanamachine merged 1 commit intoelastic:9.3from May 5, 2026
Conversation
…_cypress scripts (elastic#267684) ## Summary **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 `axios` dependency for files owned by `@elastic/security-engineering-productivity`. Phase 3 of the axios migration tracked under elastic#266556. ### Why Node.js 22 ships a native `fetch` API built on undici, and every browser Kibana targets supports `fetch` natively. Removing axios cuts one runtime dependency and continues the per-team rollout that mirrors the earlier node-fetch migration ([elastic#250719](elastic#250719) and siblings). ### Changes Three files under `x-pack/solutions/security/plugins/security_solution/scripts/run_cypress/`, all developer/CI scripts that spin up serverless test projects and poll their readiness: - `parallel_serverless.ts` - 5 axios calls (proxy healthcheck, ES `_cluster/health`, Kibana `/api/status`, ES root, Kibana login). Replaced with `fetch` + explicit `res.ok` check + typed `await res.json()`. Dropped the `.catch(catchAxiosErrorFormatAndThrow)` wrappers that wrapped AxiosError into FormattedAxiosError; replaced with inline `throw new Error('${response.status}:${await response.text()}')` that preserves status+body in the error message. Folded `'Content-Type': 'application/json'` into the module-private `API_HEADERS` constant and unwrapped `[ELASTIC_HTTP_VERSION_HEADER]: [INITIAL_REST_VERSION]` to a bare string - axios was setting Content-Type implicitly for object bodies and silently joining the single-element array, neither of which fetch does. - `cloud_project_handler.ts` - 4 axios calls (create project, delete project, reset credentials, status poll). - `proxy_project_handler.ts` - same shape as `cloud_project_handler.ts` with proxy-specific URLs. Both project_handler files: catch blocks previously had an `if (error instanceof AxiosError) { log status:data } else { log message }` branch; with fetch the AxiosError branch is now dead, so they collapse to a single `this.log.error(${error.message})`. The thrown error's message contains `${status}:${responseBody}` to preserve the same diagnostic content. The retry callbacks' `error instanceof AxiosError && error.code === 'ENOTFOUND'` checks (used to log a friendlier "URL not yet reachable" message during DNS failures) were replaced with `(error as { cause?: { code?: string } }).cause?.code === 'ENOTFOUND'` — Node fetch wraps the underlying network error on `error.cause`, so DNS failures still surface with `cause.code === 'ENOTFOUND'`. The one retry callback in `proxyHealthcheck` previously guarded its log behind `if (error instanceof AxiosError)`; with fetch every error reaching that callback is HTTP/network-related, so the guard is dropped and the parameter omitted. Removed the corresponding `run_cypress/` entries from `AXIOS_LEGACY_CONSUMERS` in `.eslintrc.js`. New axios usage anywhere in this directory is now blocked by the existing global ban. ### Behavior parity - Status-based retry decisions unchanged: `res.ok` is true exactly for 2xx, matching axios's auto-throw on non-2xx + `error.response.status === 200` checks. - ENOTFOUND detection unchanged: fetch's wrapped `cause.code` matches axios's `code` for DNS failures. - Error log content preserved: messages still include status code and response body where the original did. - The `catchAxiosErrorFormatAndThrow` import (which would have required migrating the `format_axios_error.ts` utility owned by `@elastic/security-defend-workflows`) is no longer needed; that utility stays as-is for its other consumers and will be migrated in a later phase. (cherry picked from commit cbbfb6d)
Contributor
Author
💚 Build Succeeded
Metrics [docs]
cc @azasypkin |
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.
Backport
This will backport the following commits from
mainto9.3:Questions ?
Please refer to the Backport tool documentation