Skip to content

🐛 [scanner] fix: auto-select first cluster in CreateNamespaceModal and CanIChecker#21363

Merged
clubanderson merged 2 commits into
mainfrom
scanner/fix-21083
Jul 21, 2026
Merged

🐛 [scanner] fix: auto-select first cluster in CreateNamespaceModal and CanIChecker#21363
clubanderson merged 2 commits into
mainfrom
scanner/fix-21083

Conversation

@clubanderson

Copy link
Copy Markdown
Collaborator

Fixes #21083

Root cause

Issue #21083 tracks the nightly unit-test suite regression. The original 3-file failures (helm-core, helm-branches, useStackDiscovery) were fixed in prior PRs. However the nightly kept failing because the component–test mismatch introduced by the revert in PR #21323 was never resolved.

What happened:

  1. PR [scanner] fix: nightly unit-test regression #21318 added auto-select of the first cluster in both CreateNamespaceModal and CanIChecker
  2. PR 🐛 fix: stabilize flaky Coverage Suite tests #21323 reverted that auto-select behavior (back to '' initial state)
  3. PRs 🌱 fix: update CanIChecker tests for auto-select cluster behavior #21344 and [scanner] 🐛 fix: update CreateNamespaceModal test for auto-select cluster #21354 later updated the tests to expect auto-select ('cluster-a' / 'cluster-1'), not knowing the component was already reverted
  4. Result: tests assert auto-select behavior; components don't auto-select → nightly fails every run

Fix

CreateNamespaceModal.tsx: change useState('')useState(clusters[0] ?? '') so the first cluster prop is pre-selected on mount, matching the test assertion in auto-selects first cluster on initialization.

CanIChecker.tsx: memoize the derived clusters array (prevents spurious effect re-runs), then add a useEffect that dispatches SET_FIELD for 'cluster' when clusters are available and none is selected yet, matching the auto-selects the first cluster assertion. Pattern mirrors the approach from PR #21318.

Test impact

  • CreateNamespaceModal.test.tsx > auto-selects first cluster on initialization — now passes
  • CanIChecker.test.tsx > auto-selects the first cluster — now passes
  • All other CanIChecker and CreateNamespaceModal tests should continue to pass since they either use selectCluster() explicitly or don't depend on initial cluster value

Signed-off-by: clubanderson 407614+clubanderson@users.noreply.github.com

…d CanIChecker

Both components initialised their cluster state to '' while their tests
(updated by PRs #21344 and #21354) assert auto-selection of the first
available cluster. This mismatch caused the nightly unit-test suite to
fail on every run since the revert in PR #21323.

CreateNamespaceModal: change useState('') → useState(clusters[0] ?? '')
so the first cluster prop is selected on mount, matching the assertion
in 'auto-selects first cluster on initialization'.

CanIChecker: memoize the clusters array with useMemo to stabilise the
dependency reference, then add a useEffect that dispatches SET_FIELD
for 'cluster' when clusters become available and no cluster is selected
yet, matching 'auto-selects the first cluster'.

Fixes #21083

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Scanner Agent <scanner@agents.github.com>
Copilot AI review requested due to automatic review settings July 21, 2026 10:57
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Jul 21, 2026
@netlify

netlify Bot commented Jul 21, 2026

Copy link
Copy Markdown

Deploy Preview for kubestellarconsole ready!

Name Link
🔨 Latest commit 0bd73e0
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/6a5f587dd316730008979f5f
😎 Deploy Preview https://deploy-preview-21363.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.

@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 clubanderson 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

@github-actions

Copy link
Copy Markdown
Contributor

👋 Hey @clubanderson — 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.

@github-actions

Copy link
Copy Markdown
Contributor

🐝 Hi @clubanderson! I'm kubestellar-hive[bot], an automation bot for this repo.

Trusted users — org members and contributors with write access — can mention @kubestellar-hive in a comment to trigger repo automation.
On issues, that mention queues an automated fix attempt. On pull requests, it records extra context for existing automation.
This is not an interactive Q&A bot, so mentions should be treated as requests for automation rather than a conversation.

Automation may take a moment to start, and follow-up happens through workflow activity rather than chat replies.

@github-actions github-actions Bot added the ai-generated Pull request generated by AI label Jul 21, 2026
@kubestellar-prow kubestellar-prow Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jul 21, 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.

@github-actions

Copy link
Copy Markdown
Contributor

♿ Accessibility Audit (WCAG 2.1 AA)

✅ No WCAG 2.1 AA violations detected in audited routes.


Powered by axe-core. Target: WCAG 2.1 AA compliance.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Restores “auto-select first cluster” behavior in two RBAC/namespace UI components to match the unit test expectations (fixing the nightly unit-test regression tracked in #21083).

Changes:

  • CreateNamespaceModal: initialize the cluster state to clusters[0] ?? '' so the first cluster is preselected on mount.
  • CanIChecker: memoize the derived cluster-name array and auto-select the first cluster via an effect when clusters become available.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
web/src/components/rbac/CanIChecker.tsx Memoizes cluster-name list and reintroduces first-cluster auto-select to match tests.
web/src/components/namespaces/CreateNamespaceModal.tsx Initializes modal cluster selection to the first provided cluster.
Comments suppressed due to low confidence (1)

web/src/components/namespaces/CreateNamespaceModal.tsx:22

  • useState(clusters[0] ?? '') only runs on the initial mount. If the modal is opened before clusters have loaded (prop is [] initially) and then the clusters prop updates, cluster will stay '' and the first cluster won’t actually auto-select (and Create remains disabled until the user manually selects). Consider syncing cluster when clusters changes and no cluster is selected yet (and optionally when the selected cluster disappears).
export function CreateNamespaceModal({ clusters, onClose, onCreated }: CreateNamespaceModalProps) {
  const { t } = useTranslation()
  const [name, setName] = useState('')
  const [cluster, setCluster] = useState(clusters[0] ?? '')
  const [teamLabel, setTeamLabel] = useState('')
  const [creating, setCreating] = useState(false)
  const [error, setError] = useState<string | null>(null)
  const [showDiscardConfirm, setShowDiscardConfirm] = useState(false)

Comment on lines +181 to +185
useEffect(() => {
if (!cluster && clusters.length > 0) {
dispatch({ type: 'SET_FIELD', field: 'cluster', value: clusters[0] })
}
}, [cluster, clusters])
@clubanderson
clubanderson merged commit c681eac into main Jul 21, 2026
29 of 32 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the scanner/fix-21083 branch July 21, 2026 11:31
@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 Verification: passed

Commit: c681eacfb0161f06668ff601b721aa282b9721c2
Specs run: NamespaceOverview.spec.ts smoke.spec.ts
Report: https://github.com/kubestellar/console/actions/runs/29826451286

@github-actions

Copy link
Copy Markdown
Contributor

Post-merge build verification passed

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

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 dco-signoff: yes Indicates the PR's author has signed the DCO. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. tier/2-standard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nightly regression: unit-test

2 participants