Loosen apiClient ESLint rule on Security#252212
Conversation
| { | ||
| // Security Solution | ||
| files: [ | ||
| 'x-pack/solutions/security/**/plugins/**/test/{scout,scout_*}/**/*.ts', | ||
| 'x-pack/platform/**/plugins/**/security/**/test/{scout,scout_*}/**/*.ts', | ||
| ], | ||
| rules: { | ||
| '@kbn/eslint/scout_require_api_client_in_api_test': [ | ||
| 'error', | ||
| { alternativeFixtures: ['esClient'] }, | ||
| ], | ||
| }, | ||
| }, |
There was a problem hiding this comment.
I say "Security Solution" but x-pack/platform/**/plugins/**/security/**/test/{scout,scout_*}/**/*.ts is not security solution - it's just a platform plugin, correct?
If yes, do you have any better name suggestions for this section?
cc @dmlemeshko
There was a problem hiding this comment.
let's allow it globally, it will be annoying to update .eslintrc.js every time a new team decided to use only esClient for api tests.
As Sophie pointed out, it is totally fine to use apiClient or esClient for API tests when Teams think this what they want to do.
| const ALT_ERROR_MSG = | ||
| 'One of `apiClient` or `esArchiver` fixtures should be used in `apiTest` to interact with an endpoint and later verify the response.'; |
There was a problem hiding this comment.
apiClient or esClient.
esArchiver should be actually disallowed to be used in test block
| }); | ||
|
|
||
| // --- Tests with alternativeFixtures option --- | ||
| const altOptions = [{ alternativeFixtures: ['esArchiver'] }]; |
There was a problem hiding this comment.
apiClient has to be set here
| code: dedent` | ||
| apiTest('uses esArchiver', async ({ esArchiver }) => { | ||
| await esArchiver.load('path/to/archive'); | ||
| }); |
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Unknown metric groupsESLint disabled in files
Total ESLint disabled count
History
|
|
Starting backport for target branches: 8.19, 9.2, 9.3 https://github.com/elastic/kibana/actions/runs/21894140720 |
💔 All backports failed
Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
Fix jest failure on main caused by the now-unnecessary disable comment after the ESLint rule was loosened in 24d327b (elastic#252212).
## Summary The Security Solution team has test cases that intentionally use `esClient` directly without `apiClient`, so enforcing the `scout_require_api_client_in_api_test` rule on their scout tests produces false positives. Instead of excluding Security Solution from the rule entirely, this PR enhances the rule with a configurable `alternativeFixtures` schema option so it can accept additional fixtures per directory. ## Changes - Added `alternativeFixtures` schema option to `scout_require_api_client_in_api_test`, allowing directories to configure additional accepted fixtures via `.eslintrc.js` - Generalized `functionUsesApiClient` to `functionUsesFixture`, parameterizing the fixture name so the same detection logic works for any fixture - Error messages are dynamic and list only the accepted fixtures for the given configuration - Added a Security Solution override in `.eslintrc.js` with `alternativeFixtures: ['esClient']` so their tests accept either `apiClient` or `esClient` - Added unit tests for the new `alternativeFixtures` option --------- Co-authored-by: Dzmitry Lemechko <dzmitry.lemechko@elastic.co> (cherry picked from commit 24d327b) # Conflicts: # x-pack/solutions/security/plugins/entity_store/test/scout/api/tests/dsl_translation.spec.ts # x-pack/solutions/security/plugins/entity_store/test/scout/api/tests/esql_translation.spec.ts # x-pack/solutions/security/plugins/entity_store/test/scout/api/tests/painless_translation.spec.ts
## Summary The Security Solution team has test cases that intentionally use `esClient` directly without `apiClient`, so enforcing the `scout_require_api_client_in_api_test` rule on their scout tests produces false positives. Instead of excluding Security Solution from the rule entirely, this PR enhances the rule with a configurable `alternativeFixtures` schema option so it can accept additional fixtures per directory. ## Changes - Added `alternativeFixtures` schema option to `scout_require_api_client_in_api_test`, allowing directories to configure additional accepted fixtures via `.eslintrc.js` - Generalized `functionUsesApiClient` to `functionUsesFixture`, parameterizing the fixture name so the same detection logic works for any fixture - Error messages are dynamic and list only the accepted fixtures for the given configuration - Added a Security Solution override in `.eslintrc.js` with `alternativeFixtures: ['esClient']` so their tests accept either `apiClient` or `esClient` - Added unit tests for the new `alternativeFixtures` option --------- Co-authored-by: Dzmitry Lemechko <dzmitry.lemechko@elastic.co> (cherry picked from commit 24d327b) # Conflicts: # .eslintrc.js # x-pack/solutions/security/plugins/entity_store/test/scout/api/tests/dsl_translation.spec.ts # x-pack/solutions/security/plugins/entity_store/test/scout/api/tests/esql_translation.spec.ts # x-pack/solutions/security/plugins/entity_store/test/scout/api/tests/painless_translation.spec.ts
## Summary The Security Solution team has test cases that intentionally use `esClient` directly without `apiClient`, so enforcing the `scout_require_api_client_in_api_test` rule on their scout tests produces false positives. Instead of excluding Security Solution from the rule entirely, this PR enhances the rule with a configurable `alternativeFixtures` schema option so it can accept additional fixtures per directory. ## Changes - Added `alternativeFixtures` schema option to `scout_require_api_client_in_api_test`, allowing directories to configure additional accepted fixtures via `.eslintrc.js` - Generalized `functionUsesApiClient` to `functionUsesFixture`, parameterizing the fixture name so the same detection logic works for any fixture - Error messages are dynamic and list only the accepted fixtures for the given configuration - Added a Security Solution override in `.eslintrc.js` with `alternativeFixtures: ['esClient']` so their tests accept either `apiClient` or `esClient` - Added unit tests for the new `alternativeFixtures` option --------- Co-authored-by: Dzmitry Lemechko <dzmitry.lemechko@elastic.co> (cherry picked from commit 24d327b) # Conflicts: # .eslintrc.js # x-pack/solutions/security/plugins/entity_store/test/scout/api/tests/dsl_translation.spec.ts # x-pack/solutions/security/plugins/entity_store/test/scout/api/tests/esql_translation.spec.ts # x-pack/solutions/security/plugins/entity_store/test/scout/api/tests/painless_translation.spec.ts
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
# Backport This will backport the following commits from `main` to `9.3`: - [Loosen `apiClient` ESLint rule on Security (#252212)](#252212) <!--- Backport version: 10.2.0 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Stelios Mavro","email":"81311181+steliosmavro@users.noreply.github.com"},"sourceCommit":{"committedDate":"2026-02-11T05:42:20Z","message":"Loosen `apiClient` ESLint rule on Security (#252212)\n\n## Summary\n\nThe Security Solution team has test cases that intentionally use\n`esClient` directly without `apiClient`, so enforcing the\n`scout_require_api_client_in_api_test` rule on their scout tests\nproduces false positives. Instead of excluding Security Solution from\nthe rule entirely, this PR enhances the rule with a configurable\n`alternativeFixtures` schema option so it can accept additional fixtures\nper directory.\n\n## Changes\n\n- Added `alternativeFixtures` schema option to\n`scout_require_api_client_in_api_test`, allowing directories to\nconfigure additional accepted fixtures via `.eslintrc.js`\n- Generalized `functionUsesApiClient` to `functionUsesFixture`,\nparameterizing the fixture name so the same detection logic works for\nany fixture\n- Error messages are dynamic and list only the accepted fixtures for the\ngiven configuration\n- Added a Security Solution override in `.eslintrc.js` with\n`alternativeFixtures: ['esClient']` so their tests accept either\n`apiClient` or `esClient`\n- Added unit tests for the new `alternativeFixtures` option\n\n---------\n\nCo-authored-by: Dzmitry Lemechko <dzmitry.lemechko@elastic.co>","sha":"24d327be1100929b7c10c39a0a6cb1217355f09a","branchLabelMapping":{"^v9.4.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:all-open","v9.4.0"],"title":"Loosen `apiClient` ESLint rule on Security","number":252212,"url":"https://github.com/elastic/kibana/pull/252212","mergeCommit":{"message":"Loosen `apiClient` ESLint rule on Security (#252212)\n\n## Summary\n\nThe Security Solution team has test cases that intentionally use\n`esClient` directly without `apiClient`, so enforcing the\n`scout_require_api_client_in_api_test` rule on their scout tests\nproduces false positives. Instead of excluding Security Solution from\nthe rule entirely, this PR enhances the rule with a configurable\n`alternativeFixtures` schema option so it can accept additional fixtures\nper directory.\n\n## Changes\n\n- Added `alternativeFixtures` schema option to\n`scout_require_api_client_in_api_test`, allowing directories to\nconfigure additional accepted fixtures via `.eslintrc.js`\n- Generalized `functionUsesApiClient` to `functionUsesFixture`,\nparameterizing the fixture name so the same detection logic works for\nany fixture\n- Error messages are dynamic and list only the accepted fixtures for the\ngiven configuration\n- Added a Security Solution override in `.eslintrc.js` with\n`alternativeFixtures: ['esClient']` so their tests accept either\n`apiClient` or `esClient`\n- Added unit tests for the new `alternativeFixtures` option\n\n---------\n\nCo-authored-by: Dzmitry Lemechko <dzmitry.lemechko@elastic.co>","sha":"24d327be1100929b7c10c39a0a6cb1217355f09a"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.4.0","branchLabelMappingKey":"^v9.4.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/252212","number":252212,"mergeCommit":{"message":"Loosen `apiClient` ESLint rule on Security (#252212)\n\n## Summary\n\nThe Security Solution team has test cases that intentionally use\n`esClient` directly without `apiClient`, so enforcing the\n`scout_require_api_client_in_api_test` rule on their scout tests\nproduces false positives. Instead of excluding Security Solution from\nthe rule entirely, this PR enhances the rule with a configurable\n`alternativeFixtures` schema option so it can accept additional fixtures\nper directory.\n\n## Changes\n\n- Added `alternativeFixtures` schema option to\n`scout_require_api_client_in_api_test`, allowing directories to\nconfigure additional accepted fixtures via `.eslintrc.js`\n- Generalized `functionUsesApiClient` to `functionUsesFixture`,\nparameterizing the fixture name so the same detection logic works for\nany fixture\n- Error messages are dynamic and list only the accepted fixtures for the\ngiven configuration\n- Added a Security Solution override in `.eslintrc.js` with\n`alternativeFixtures: ['esClient']` so their tests accept either\n`apiClient` or `esClient`\n- Added unit tests for the new `alternativeFixtures` option\n\n---------\n\nCo-authored-by: Dzmitry Lemechko <dzmitry.lemechko@elastic.co>","sha":"24d327be1100929b7c10c39a0a6cb1217355f09a"}}]}] BACKPORT-->
# Backport This will backport the following commits from `main` to `9.2`: - [Loosen `apiClient` ESLint rule on Security (#252212)](#252212) <!--- Backport version: 10.2.0 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Stelios Mavro","email":"81311181+steliosmavro@users.noreply.github.com"},"sourceCommit":{"committedDate":"2026-02-11T05:42:20Z","message":"Loosen `apiClient` ESLint rule on Security (#252212)\n\n## Summary\n\nThe Security Solution team has test cases that intentionally use\n`esClient` directly without `apiClient`, so enforcing the\n`scout_require_api_client_in_api_test` rule on their scout tests\nproduces false positives. Instead of excluding Security Solution from\nthe rule entirely, this PR enhances the rule with a configurable\n`alternativeFixtures` schema option so it can accept additional fixtures\nper directory.\n\n## Changes\n\n- Added `alternativeFixtures` schema option to\n`scout_require_api_client_in_api_test`, allowing directories to\nconfigure additional accepted fixtures via `.eslintrc.js`\n- Generalized `functionUsesApiClient` to `functionUsesFixture`,\nparameterizing the fixture name so the same detection logic works for\nany fixture\n- Error messages are dynamic and list only the accepted fixtures for the\ngiven configuration\n- Added a Security Solution override in `.eslintrc.js` with\n`alternativeFixtures: ['esClient']` so their tests accept either\n`apiClient` or `esClient`\n- Added unit tests for the new `alternativeFixtures` option\n\n---------\n\nCo-authored-by: Dzmitry Lemechko <dzmitry.lemechko@elastic.co>","sha":"24d327be1100929b7c10c39a0a6cb1217355f09a","branchLabelMapping":{"^v9.4.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:all-open","v9.4.0"],"title":"Loosen `apiClient` ESLint rule on Security","number":252212,"url":"https://github.com/elastic/kibana/pull/252212","mergeCommit":{"message":"Loosen `apiClient` ESLint rule on Security (#252212)\n\n## Summary\n\nThe Security Solution team has test cases that intentionally use\n`esClient` directly without `apiClient`, so enforcing the\n`scout_require_api_client_in_api_test` rule on their scout tests\nproduces false positives. Instead of excluding Security Solution from\nthe rule entirely, this PR enhances the rule with a configurable\n`alternativeFixtures` schema option so it can accept additional fixtures\nper directory.\n\n## Changes\n\n- Added `alternativeFixtures` schema option to\n`scout_require_api_client_in_api_test`, allowing directories to\nconfigure additional accepted fixtures via `.eslintrc.js`\n- Generalized `functionUsesApiClient` to `functionUsesFixture`,\nparameterizing the fixture name so the same detection logic works for\nany fixture\n- Error messages are dynamic and list only the accepted fixtures for the\ngiven configuration\n- Added a Security Solution override in `.eslintrc.js` with\n`alternativeFixtures: ['esClient']` so their tests accept either\n`apiClient` or `esClient`\n- Added unit tests for the new `alternativeFixtures` option\n\n---------\n\nCo-authored-by: Dzmitry Lemechko <dzmitry.lemechko@elastic.co>","sha":"24d327be1100929b7c10c39a0a6cb1217355f09a"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.4.0","branchLabelMappingKey":"^v9.4.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/252212","number":252212,"mergeCommit":{"message":"Loosen `apiClient` ESLint rule on Security (#252212)\n\n## Summary\n\nThe Security Solution team has test cases that intentionally use\n`esClient` directly without `apiClient`, so enforcing the\n`scout_require_api_client_in_api_test` rule on their scout tests\nproduces false positives. Instead of excluding Security Solution from\nthe rule entirely, this PR enhances the rule with a configurable\n`alternativeFixtures` schema option so it can accept additional fixtures\nper directory.\n\n## Changes\n\n- Added `alternativeFixtures` schema option to\n`scout_require_api_client_in_api_test`, allowing directories to\nconfigure additional accepted fixtures via `.eslintrc.js`\n- Generalized `functionUsesApiClient` to `functionUsesFixture`,\nparameterizing the fixture name so the same detection logic works for\nany fixture\n- Error messages are dynamic and list only the accepted fixtures for the\ngiven configuration\n- Added a Security Solution override in `.eslintrc.js` with\n`alternativeFixtures: ['esClient']` so their tests accept either\n`apiClient` or `esClient`\n- Added unit tests for the new `alternativeFixtures` option\n\n---------\n\nCo-authored-by: Dzmitry Lemechko <dzmitry.lemechko@elastic.co>","sha":"24d327be1100929b7c10c39a0a6cb1217355f09a"}}]}] BACKPORT-->
# Backport This will backport the following commits from `main` to `8.19`: - [Loosen `apiClient` ESLint rule on Security (#252212)](#252212) <!--- Backport version: 10.2.0 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Stelios Mavro","email":"81311181+steliosmavro@users.noreply.github.com"},"sourceCommit":{"committedDate":"2026-02-11T05:42:20Z","message":"Loosen `apiClient` ESLint rule on Security (#252212)\n\n## Summary\n\nThe Security Solution team has test cases that intentionally use\n`esClient` directly without `apiClient`, so enforcing the\n`scout_require_api_client_in_api_test` rule on their scout tests\nproduces false positives. Instead of excluding Security Solution from\nthe rule entirely, this PR enhances the rule with a configurable\n`alternativeFixtures` schema option so it can accept additional fixtures\nper directory.\n\n## Changes\n\n- Added `alternativeFixtures` schema option to\n`scout_require_api_client_in_api_test`, allowing directories to\nconfigure additional accepted fixtures via `.eslintrc.js`\n- Generalized `functionUsesApiClient` to `functionUsesFixture`,\nparameterizing the fixture name so the same detection logic works for\nany fixture\n- Error messages are dynamic and list only the accepted fixtures for the\ngiven configuration\n- Added a Security Solution override in `.eslintrc.js` with\n`alternativeFixtures: ['esClient']` so their tests accept either\n`apiClient` or `esClient`\n- Added unit tests for the new `alternativeFixtures` option\n\n---------\n\nCo-authored-by: Dzmitry Lemechko <dzmitry.lemechko@elastic.co>","sha":"24d327be1100929b7c10c39a0a6cb1217355f09a","branchLabelMapping":{"^v9.4.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:all-open","v9.4.0"],"title":"Loosen `apiClient` ESLint rule on Security","number":252212,"url":"https://github.com/elastic/kibana/pull/252212","mergeCommit":{"message":"Loosen `apiClient` ESLint rule on Security (#252212)\n\n## Summary\n\nThe Security Solution team has test cases that intentionally use\n`esClient` directly without `apiClient`, so enforcing the\n`scout_require_api_client_in_api_test` rule on their scout tests\nproduces false positives. Instead of excluding Security Solution from\nthe rule entirely, this PR enhances the rule with a configurable\n`alternativeFixtures` schema option so it can accept additional fixtures\nper directory.\n\n## Changes\n\n- Added `alternativeFixtures` schema option to\n`scout_require_api_client_in_api_test`, allowing directories to\nconfigure additional accepted fixtures via `.eslintrc.js`\n- Generalized `functionUsesApiClient` to `functionUsesFixture`,\nparameterizing the fixture name so the same detection logic works for\nany fixture\n- Error messages are dynamic and list only the accepted fixtures for the\ngiven configuration\n- Added a Security Solution override in `.eslintrc.js` with\n`alternativeFixtures: ['esClient']` so their tests accept either\n`apiClient` or `esClient`\n- Added unit tests for the new `alternativeFixtures` option\n\n---------\n\nCo-authored-by: Dzmitry Lemechko <dzmitry.lemechko@elastic.co>","sha":"24d327be1100929b7c10c39a0a6cb1217355f09a"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.4.0","branchLabelMappingKey":"^v9.4.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/252212","number":252212,"mergeCommit":{"message":"Loosen `apiClient` ESLint rule on Security (#252212)\n\n## Summary\n\nThe Security Solution team has test cases that intentionally use\n`esClient` directly without `apiClient`, so enforcing the\n`scout_require_api_client_in_api_test` rule on their scout tests\nproduces false positives. Instead of excluding Security Solution from\nthe rule entirely, this PR enhances the rule with a configurable\n`alternativeFixtures` schema option so it can accept additional fixtures\nper directory.\n\n## Changes\n\n- Added `alternativeFixtures` schema option to\n`scout_require_api_client_in_api_test`, allowing directories to\nconfigure additional accepted fixtures via `.eslintrc.js`\n- Generalized `functionUsesApiClient` to `functionUsesFixture`,\nparameterizing the fixture name so the same detection logic works for\nany fixture\n- Error messages are dynamic and list only the accepted fixtures for the\ngiven configuration\n- Added a Security Solution override in `.eslintrc.js` with\n`alternativeFixtures: ['esClient']` so their tests accept either\n`apiClient` or `esClient`\n- Added unit tests for the new `alternativeFixtures` option\n\n---------\n\nCo-authored-by: Dzmitry Lemechko <dzmitry.lemechko@elastic.co>","sha":"24d327be1100929b7c10c39a0a6cb1217355f09a"}}]}] BACKPORT-->
Summary
The Security Solution team has test cases that intentionally use
esClientdirectly withoutapiClient, so enforcing thescout_require_api_client_in_api_testrule on their scout tests produces false positives. Instead of excluding Security Solution from the rule entirely, this PR enhances the rule with a configurablealternativeFixturesschema option so it can accept additional fixtures per directory.Changes
alternativeFixturesschema option toscout_require_api_client_in_api_test, allowing directories to configure additional accepted fixtures via.eslintrc.jsfunctionUsesApiClienttofunctionUsesFixture, parameterizing the fixture name so the same detection logic works for any fixture.eslintrc.jswithalternativeFixtures: ['esClient']so their tests accept eitherapiClientoresClientalternativeFixturesoption