codeant-ai-for-open-source[bot] commented on code in PR #39957:
URL: https://github.com/apache/superset/pull/39957#discussion_r3211383526


##########
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterBar.test.tsx:
##########
@@ -39,7 +39,7 @@ import FilterBar from '.';
 import { FILTERS_CONFIG_MODAL_TEST_ID } from 
'../FiltersConfigModal/FiltersConfigModal';
 import * as dataMaskActions from 'src/dataMask/actions';
 
-jest.useFakeTimers();
+jest.useFakeTimers({ advanceTimers: true });

Review Comment:
   **Suggestion:** Enabling fake timers at module scope without per-test 
teardown makes timer state shared across all tests in this file. Pending 
timeouts/intervals from one test can bleed into the next test and cause flaky 
assertions or hangs, especially with React/AntD deferred work. Scope fake 
timers per test lifecycle (`beforeEach` + `afterEach`) and clear/restore timers 
after each test. [logic error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ⚠️ Native filter bar tests can become flaky across runs.
   - ⚠️ Cross-test timer bleed complicates debugging timer-related regressions.
   - ⚠️ Jest suite may intermittently hang due to uncleared timers.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Run the dashboard filter bar tests, for example with `jest
   
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterBar.test.tsx`,
   which uses the custom JSDOM environment configured in
   `superset-frontend/jest.config.js:38-39` pointing to
   `spec/helpers/jsDomWithFetchAPI.ts:20-42` (this environment disables 
`MessageChannel` so
   React falls back to `setTimeout`-based scheduling).
   
   2. When Jest loads `FilterBar.test.tsx`, the module-level call 
`jest.useFakeTimers({
   advanceTimers: true });` at
   
`superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterBar.test.tsx:42`
   enables fake timers for the entire file; only `jest.clearAllMocks()` is run 
in
   `beforeEach` at lines 80-83, and there is no corresponding `afterEach` that 
calls
   `jest.clearAllTimers()` or `jest.useRealTimers()`, so timer state persists 
across tests.
   
   3. Several tests mount `<FilterBar />` via `renderFilterBar` (e.g., 
`test('FilterBar
   renders dividers with title and description', ...)` at lines 351-381 and 
`test('FilterBar
   does not crash when filter has value but empty extraFormData', ...)` around 
lines 30-61 in
   the tail of the file), which exercise the component logic in
   `src/dashboard/components/nativeFilters/FilterBar/index.tsx:97-158` where
   `publishDataMask` is defined using `lodash.debounce(...)` and invoked from a 
`useEffect`
   at lines 134-140, scheduling debounced work on the fake timer queue without 
explicitly
   flushing or cancelling it in the tests.
   
   4. Later tests in the same file use `jest.advanceTimersByTime(...)` inside 
`act`, for
   example at `FilterBar.test.tsx:370-371`, 51-52, 84-85, 127-128, 185-186, and 
249-250,
   which will advance all pending fake timers in the shared queue, including 
any debounced
   `publishDataMask` callbacks left over from previous tests; because fake 
timers were
   enabled once at module scope and never restored, these cross-test timer side 
effects can
   cause flaky assertions (unexpected URL/history updates) or hangs when 
leftover timers keep
   scheduling work that no test explicitly drains, and this behavior can be 
reproduced by
   repeatedly running the suite and observing nondeterministic failures.
   ```
   </details>
   
   [Fix in 
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset-frontend%2Fsrc%2Fdashboard%2Fcomponents%2FnativeFilters%2FFilterBar%2FFilterBar.test.tsx%0A%2A%2ALine%3A%2A%2A%2042%3A42%0A%2A%2AComment%3A%2A%2A%0A%09%2ALogic%20Error%3A%20Enabling%20fake%20timers%20at%20module%20scope%20without%20per-test%20teardown%20makes%20timer%20state%20shared%20across%20all%20tests%20in%20this%20file.%20Pending%20timeouts%2Fintervals%20from%20one%20test%20can%20bleed%20into%20the%20next%20test%20and%20cause%20flaky%20assertions%20or%20hangs%2C%20especially%20with%20React%2FAntD%20deferred%20work.%20Scope%20fake%20timers%20per%20test%20lifecycle%20%28%60beforeEach%60%20%2B%20%60afterEach%60%29%20and%20clear%2Frestore%20timers%20after%20each%20test.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix
 
%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
 | [Fix in VSCode 
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset-frontend%2Fsrc%2Fdashboard%2Fcomponents%2FnativeFilters%2FFilterBar%2FFilterBar.test.tsx%0A%2A%2ALine%3A%2A%2A%2042%3A42%0A%2A%2AComment%3A%2A%2A%0A%09%2ALogic%20Error%3A%20Enabling%20fake%20timers%20at%20module%20scope%20without%20per-test%20teardown%20makes%20timer%20state%20shared%20across%20all%20tests%20in%20this%20file.%20Pending%20timeouts%2Fintervals%20from%20one%20test%20can%20bleed%20into%20the%20next%20test%20a
 
nd%20cause%20flaky%20assertions%20or%20hangs%2C%20especially%20with%20React%2FAntD%20deferred%20work.%20Scope%20fake%20timers%20per%20test%20lifecycle%20%28%60beforeEach%60%20%2B%20%60afterEach%60%29%20and%20clear%2Frestore%20timers%20after%20each%20test.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterBar.test.tsx
   **Line:** 42:42
   **Comment:**
        *Logic Error: Enabling fake timers at module scope without per-test 
teardown makes timer state shared across all tests in this file. Pending 
timeouts/intervals from one test can bleed into the next test and cause flaky 
assertions or hangs, especially with React/AntD deferred work. Scope fake 
timers per test lifecycle (`beforeEach` + `afterEach`) and clear/restore timers 
after each test.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39957&comment_hash=536ca7b21ed5ae0f6b8ba2dfa1a79c777ba10bba6c190104845a502b7657d24e&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39957&comment_hash=536ca7b21ed5ae0f6b8ba2dfa1a79c777ba10bba6c190104845a502b7657d24e&reaction=dislike'>👎</a>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to