Skip to content

🐛 Fix 3 test failures from React 18 setState batch timing#14009

Merged
kubestellar-hive[bot] merged 1 commit into
mainfrom
fix/14002-test-failures
May 16, 2026
Merged

🐛 Fix 3 test failures from React 18 setState batch timing#14009
kubestellar-hive[bot] merged 1 commit into
mainfrom
fix/14002-test-failures

Conversation

@kubestellar-hive
Copy link
Copy Markdown
Contributor

Fixes #14002

Problem

3 tests failed after PR #14000 (commit 3fab259):

  1. useDrillDownWebSocket closes all trackedopenTrackedWs() monkey-patches ws.close with a wrapper function, replacing the vi.fn() spy. The test then asserts .toHaveBeenCalled() on the non-spy wrapper, which always fails.

  2. useStellar acknowledgeNotification restores — The removed variable was set as a side effect inside a setNotifications updater callback. React 18's automatic batching may defer updater execution past the await boundary, leaving removed as null in the catch block.

  3. useStellar dismissAllNotifications clears all — Same issue: snapshot was captured inside a setState updater and read immediately after. With batching, it remains [], causing early return.

Fix

  • WS test: Store the original close spy on a _closeSpy field in the mock, assert on that persistent reference.
  • useStellar hook: Introduce notificationsRef kept in sync via a setNotifications wrapper. Both acknowledgeNotification and dismissAllNotifications now read from the ref (which reflects the last React-flushed value) instead of relying on updater side effects.

Risk

Low — the hook behavior is identical; only the mechanism for reading current state in async callbacks changes from "side effect in updater" to "ref read". All other tests should continue to pass.

- useDrillDownWebSocket: openTrackedWs monkey-patches ws.close with a
  wrapper, making the original spy inaccessible. Store the spy on
  _closeSpy field and assert on that in the unmount test.

- useStellar acknowledgeNotification/dismissAllNotifications: These
  functions relied on side effects inside setState updaters to capture
  snapshots (removed/snapshot variables). React 18's automatic batching
  may defer updater execution past the await boundary, leaving the
  variables at their initial values. Fix: introduce notificationsRef
  kept in sync via a setNotifications wrapper, and read directly from
  the ref before issuing state updates.

Fixes #14002

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: kubestellar-bot <kubestellar-bot@kubestellar.io>
Copilot AI review requested due to automatic review settings May 16, 2026 02:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label May 16, 2026
@kubestellar-prow
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign eeshaansa for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@netlify
Copy link
Copy Markdown

netlify Bot commented May 16, 2026

Deploy Preview for kubestellarconsole ready!

Name Link
🔨 Latest commit 206c33a
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/6a07d0d551ef100008e92e41
😎 Deploy Preview https://deploy-preview-14009.console-deploy-preview.kubestellar.io
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions Bot added the ai-generated Pull request generated by AI label May 16, 2026
@github-actions
Copy link
Copy Markdown
Contributor

👋 Hey @kubestellar-hive[bot] — thanks for opening this PR!

🤖 This project is developed exclusively using AI coding assistants.

Please do not attempt to code anything for this project manually.
All contributions should be authored using an AI coding tool such as:

This ensures consistency in code style, architecture patterns, test coverage,
and commit quality across the entire codebase.


This is an automated message.

@kubestellar-prow kubestellar-prow Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 16, 2026
@github-actions
Copy link
Copy Markdown
Contributor

✅ Test Coverage Check

All new source files in this PR have corresponding test files.

Checked web/src/hooks/ and web/src/components/ against origin/main.

@kubestellar-hive kubestellar-hive Bot merged commit b1f4407 into main May 16, 2026
36 of 37 checks passed
@kubestellar-prow kubestellar-prow Bot deleted the fix/14002-test-failures branch May 16, 2026 02:22
@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

Check out what's new:

Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey

@github-actions
Copy link
Copy Markdown
Contributor

Post-merge build verification passed

Both Go and frontend builds compiled successfully against merge commit b1f44074a12b987d48a0fc80fc86a26e7e737cb8.

@github-actions
Copy link
Copy Markdown
Contributor

✅ Post-Merge Verification: passed

Commit: b1f44074a12b987d48a0fc80fc86a26e7e737cb8
Specs run: smoke.spec.ts
Report: https://github.com/kubestellar/console/actions/runs/25950337700

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated Pull request generated by AI copilot dco-signoff: yes Indicates the PR's author has signed the DCO. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tier/2-standard

1 participant