Skip to content

Commit 829c5fb

Browse files
kibanamachineclaudeszwarckonradgergoabraham
authored
[9.4] [Trusted Apps] Fix flaky invalid-hash form test by removing async input (#290719) (#291084)
# Backport This will backport the following commits from `main` to `9.4`: - [[Trusted Apps] Fix flaky invalid-hash form test by removing async input (#290719)](#290719) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Kibana Machine","email":"42973632+kibanamachine@users.noreply.github.com"},"sourceCommit":{"committedDate":"2026-09-15T10:36:47Z","message":"[Trusted Apps] Fix flaky invalid-hash form test by removing async input (#290719)\n\nFixes #286496\n\n### Summary\n\n- `should validate invalid Hash value` timed out at 5000 ms (and later\nfailed to find `[1] Invalid hash value`) because it drove the value\nthrough slow char-by-char `userEvent.type` inside an async `act`, unlike\nits sibling tests which set values synchronously.\n- Replaces the async input with a synchronous `setTextFieldValue` edit\n(which marks the field visited via blur) plus an explicit\ncontrolled-`item` update, then asserts — so there is no async step to\nexceed the budget.\n\n| Runtime vs. 5s budget | Passed | Avg | Max |\n| --- | --- | --- | --- |\n| Before fix | 25/25 | 0.6s | 0.7s |\n| After fix | 25/25 | 0.4s | 0.5s |\n\n### Context\n\n- The [investigator's\nanalysis](https://github.com/elastic/kibana/issues/286496#issuecomment-5648020729)\ncorrectly identified the async `userEvent.type` as the cost, but its\nproposed drop-in replacement (`setTextFieldValue(...);\nrerenderWithLatestProps();`) fails **0/25** locally.\n`rerenderWithLatestProps()` reads `latestUpdatedItem`, and the form's\n`useEffect(() => processChanged(), [processChanged])` re-fires the\nmoment `hasFormChanged` flips `false`→`true` on the first edit — calling\nthe test's `onChange` with the still-empty `item` prop and clobbering\n`latestUpdatedItem` back to empty. `userEvent.type` masked this only\nbecause its 2nd–8th keystrokes fire *after* `hasFormChanged` is already\n`true`; the sibling `should validate multiple errors in form` avoids it\nbecause its AND-click primes `hasFormChanged` first. This fix therefore\ndeparts from the proposed patch: it supplies the controlled `item`\nexplicitly (as a real parent would) instead of relying on the clobbered\nround-trip value.\n- Product validation isn't broken: `validateValues` still runs on the\ninvalid-hash item via that same `useEffect` and produces the error; the\nidentical assertion runs synchronously and reliably in the sibling at\nthe bottom of the same `describe`.\n- Failures were on `kibana-on-merge - main` (first failure build 107204;\nreopened on build 109576) — a Jest timeout under CI parallel load.\n\n<details>\n<summary>Verification</summary>\n\n#### Verified locally\n\n- ✅ Passed: `node scripts/eslint <file>`\n- ✅ Passed: `node scripts/jest <file> -t \"should validate invalid Hash\nvalue\"`: 25/25 passed before the fix (avg 631ms, max 690ms) and 25/25\nafter (avg 438ms, max 480ms); the ~30% lower average confirms the\nchar-by-char typing cost was removed rather than the wait merely\nre-tuned.\n\n#### Not verified locally\n\n- The reported flake is a timeout under CI parallel load, which does not\nreproduce on this runner (the unpatched test passed 25/25 locally), so\nthe loops measure the runtime reduction rather than reproducing the\nfailure.\n\n</details>\n\n> [!NOTE]\n> Share feedback in #kibana-qa. Mention `@copilot` to make quick\nchanges.\n\n> Generated by [Flaky Test\nFixer](https://github.com/elastic/kibana/actions/runs/34712900863) for\n#286496 · claude · opus · 801.7 AIC · ⌖ 60.4 AIC · ⊞ 14.5K ·\n[◷](https://github.com/search?q=repo%3Aelastic%2Fkibana+%22gh-aw-workflow-id%3A+flaky-test-fixer%22&type=pullrequests)\n\n\n\n\n\n\n---------\n\nCo-authored-by: Claude Opus 4 (1M context) <noreply@anthropic.com>\nCo-authored-by: konrad.szwarc <konrad.szwarc@elastic.co>\nCo-authored-by: Gergő Ábrahám <gergo.abraham@elastic.co>","sha":"c11efe3da7161011d8020631a396e2408a4b2ed9","branchLabelMapping":{"^v9.6.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:version","flaky-test-fixer","flaky-fix-check:skipped","v9.6.0","v9.4.7","v9.5.4"],"title":"[Trusted Apps] Fix flaky invalid-hash form test by removing async input","number":290719,"url":"https://github.com/elastic/kibana/pull/290719","mergeCommit":{"message":"[Trusted Apps] Fix flaky invalid-hash form test by removing async input (#290719)\n\nFixes #286496\n\n### Summary\n\n- `should validate invalid Hash value` timed out at 5000 ms (and later\nfailed to find `[1] Invalid hash value`) because it drove the value\nthrough slow char-by-char `userEvent.type` inside an async `act`, unlike\nits sibling tests which set values synchronously.\n- Replaces the async input with a synchronous `setTextFieldValue` edit\n(which marks the field visited via blur) plus an explicit\ncontrolled-`item` update, then asserts — so there is no async step to\nexceed the budget.\n\n| Runtime vs. 5s budget | Passed | Avg | Max |\n| --- | --- | --- | --- |\n| Before fix | 25/25 | 0.6s | 0.7s |\n| After fix | 25/25 | 0.4s | 0.5s |\n\n### Context\n\n- The [investigator's\nanalysis](https://github.com/elastic/kibana/issues/286496#issuecomment-5648020729)\ncorrectly identified the async `userEvent.type` as the cost, but its\nproposed drop-in replacement (`setTextFieldValue(...);\nrerenderWithLatestProps();`) fails **0/25** locally.\n`rerenderWithLatestProps()` reads `latestUpdatedItem`, and the form's\n`useEffect(() => processChanged(), [processChanged])` re-fires the\nmoment `hasFormChanged` flips `false`→`true` on the first edit — calling\nthe test's `onChange` with the still-empty `item` prop and clobbering\n`latestUpdatedItem` back to empty. `userEvent.type` masked this only\nbecause its 2nd–8th keystrokes fire *after* `hasFormChanged` is already\n`true`; the sibling `should validate multiple errors in form` avoids it\nbecause its AND-click primes `hasFormChanged` first. This fix therefore\ndeparts from the proposed patch: it supplies the controlled `item`\nexplicitly (as a real parent would) instead of relying on the clobbered\nround-trip value.\n- Product validation isn't broken: `validateValues` still runs on the\ninvalid-hash item via that same `useEffect` and produces the error; the\nidentical assertion runs synchronously and reliably in the sibling at\nthe bottom of the same `describe`.\n- Failures were on `kibana-on-merge - main` (first failure build 107204;\nreopened on build 109576) — a Jest timeout under CI parallel load.\n\n<details>\n<summary>Verification</summary>\n\n#### Verified locally\n\n- ✅ Passed: `node scripts/eslint <file>`\n- ✅ Passed: `node scripts/jest <file> -t \"should validate invalid Hash\nvalue\"`: 25/25 passed before the fix (avg 631ms, max 690ms) and 25/25\nafter (avg 438ms, max 480ms); the ~30% lower average confirms the\nchar-by-char typing cost was removed rather than the wait merely\nre-tuned.\n\n#### Not verified locally\n\n- The reported flake is a timeout under CI parallel load, which does not\nreproduce on this runner (the unpatched test passed 25/25 locally), so\nthe loops measure the runtime reduction rather than reproducing the\nfailure.\n\n</details>\n\n> [!NOTE]\n> Share feedback in #kibana-qa. Mention `@copilot` to make quick\nchanges.\n\n> Generated by [Flaky Test\nFixer](https://github.com/elastic/kibana/actions/runs/34712900863) for\n#286496 · claude · opus · 801.7 AIC · ⌖ 60.4 AIC · ⊞ 14.5K ·\n[◷](https://github.com/search?q=repo%3Aelastic%2Fkibana+%22gh-aw-workflow-id%3A+flaky-test-fixer%22&type=pullrequests)\n\n\n\n\n\n\n---------\n\nCo-authored-by: Claude Opus 4 (1M context) <noreply@anthropic.com>\nCo-authored-by: konrad.szwarc <konrad.szwarc@elastic.co>\nCo-authored-by: Gergő Ábrahám <gergo.abraham@elastic.co>","sha":"c11efe3da7161011d8020631a396e2408a4b2ed9"}},"sourceBranch":"main","suggestedTargetBranches":["9.4","9.5"],"targetPullRequestStates":[{"branch":"main","label":"v9.6.0","branchLabelMappingKey":"^v9.6.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/290719","number":290719,"mergeCommit":{"message":"[Trusted Apps] Fix flaky invalid-hash form test by removing async input (#290719)\n\nFixes #286496\n\n### Summary\n\n- `should validate invalid Hash value` timed out at 5000 ms (and later\nfailed to find `[1] Invalid hash value`) because it drove the value\nthrough slow char-by-char `userEvent.type` inside an async `act`, unlike\nits sibling tests which set values synchronously.\n- Replaces the async input with a synchronous `setTextFieldValue` edit\n(which marks the field visited via blur) plus an explicit\ncontrolled-`item` update, then asserts — so there is no async step to\nexceed the budget.\n\n| Runtime vs. 5s budget | Passed | Avg | Max |\n| --- | --- | --- | --- |\n| Before fix | 25/25 | 0.6s | 0.7s |\n| After fix | 25/25 | 0.4s | 0.5s |\n\n### Context\n\n- The [investigator's\nanalysis](https://github.com/elastic/kibana/issues/286496#issuecomment-5648020729)\ncorrectly identified the async `userEvent.type` as the cost, but its\nproposed drop-in replacement (`setTextFieldValue(...);\nrerenderWithLatestProps();`) fails **0/25** locally.\n`rerenderWithLatestProps()` reads `latestUpdatedItem`, and the form's\n`useEffect(() => processChanged(), [processChanged])` re-fires the\nmoment `hasFormChanged` flips `false`→`true` on the first edit — calling\nthe test's `onChange` with the still-empty `item` prop and clobbering\n`latestUpdatedItem` back to empty. `userEvent.type` masked this only\nbecause its 2nd–8th keystrokes fire *after* `hasFormChanged` is already\n`true`; the sibling `should validate multiple errors in form` avoids it\nbecause its AND-click primes `hasFormChanged` first. This fix therefore\ndeparts from the proposed patch: it supplies the controlled `item`\nexplicitly (as a real parent would) instead of relying on the clobbered\nround-trip value.\n- Product validation isn't broken: `validateValues` still runs on the\ninvalid-hash item via that same `useEffect` and produces the error; the\nidentical assertion runs synchronously and reliably in the sibling at\nthe bottom of the same `describe`.\n- Failures were on `kibana-on-merge - main` (first failure build 107204;\nreopened on build 109576) — a Jest timeout under CI parallel load.\n\n<details>\n<summary>Verification</summary>\n\n#### Verified locally\n\n- ✅ Passed: `node scripts/eslint <file>`\n- ✅ Passed: `node scripts/jest <file> -t \"should validate invalid Hash\nvalue\"`: 25/25 passed before the fix (avg 631ms, max 690ms) and 25/25\nafter (avg 438ms, max 480ms); the ~30% lower average confirms the\nchar-by-char typing cost was removed rather than the wait merely\nre-tuned.\n\n#### Not verified locally\n\n- The reported flake is a timeout under CI parallel load, which does not\nreproduce on this runner (the unpatched test passed 25/25 locally), so\nthe loops measure the runtime reduction rather than reproducing the\nfailure.\n\n</details>\n\n> [!NOTE]\n> Share feedback in #kibana-qa. Mention `@copilot` to make quick\nchanges.\n\n> Generated by [Flaky Test\nFixer](https://github.com/elastic/kibana/actions/runs/34712900863) for\n#286496 · claude · opus · 801.7 AIC · ⌖ 60.4 AIC · ⊞ 14.5K ·\n[◷](https://github.com/search?q=repo%3Aelastic%2Fkibana+%22gh-aw-workflow-id%3A+flaky-test-fixer%22&type=pullrequests)\n\n\n\n\n\n\n---------\n\nCo-authored-by: Claude Opus 4 (1M context) <noreply@anthropic.com>\nCo-authored-by: konrad.szwarc <konrad.szwarc@elastic.co>\nCo-authored-by: Gergő Ábrahám <gergo.abraham@elastic.co>","sha":"c11efe3da7161011d8020631a396e2408a4b2ed9"}},{"branch":"9.4","label":"v9.4.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.5","label":"v9.5.4","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Claude Opus 4 (1M context) <noreply@anthropic.com> Co-authored-by: konrad.szwarc <konrad.szwarc@elastic.co> Co-authored-by: Gergő Ábrahám <gergo.abraham@elastic.co>
1 parent bfc4162 commit 829c5fb

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

  • x-pack/solutions/security/plugins/security_solution/public/management/pages/trusted_apps/view/components

x-pack/solutions/security/plugins/security_solution/public/management/pages/trusted_apps/view/components/form.test.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -718,14 +718,10 @@ describe('Trusted apps form', () => {
718718
expect(renderResult.getByText(INPUT_ERRORS.name));
719719
});
720720

721-
it('should validate invalid Hash value', async () => {
722-
const valueField = getConditionValue(getCondition());
723-
await act(async () => {
724-
await userEvent.clear(valueField);
725-
await userEvent.type(valueField, 'someHASH');
726-
fireEvent.blur(valueField);
727-
});
728-
rerenderWithLatestProps();
721+
it('should validate invalid Hash value', () => {
722+
setTextFieldValue(getConditionValue(getCondition()), 'someHASH');
723+
formProps.item = (formProps.onChange as jest.Mock).mock.calls.at(-2)[0].item;
724+
rerender();
729725
expect(renderResult.getByText(INPUT_ERRORS.invalidHash(0)));
730726
});
731727

0 commit comments

Comments
 (0)