Skip to content

🌱 fix: coverage suite test failure#21282

Merged
clubanderson merged 1 commit into
mainfrom
scanner/fix-21280
Jul 19, 2026
Merged

🌱 fix: coverage suite test failure#21282
clubanderson merged 1 commit into
mainfrom
scanner/fix-21280

Conversation

@clubanderson

Copy link
Copy Markdown
Collaborator

Fixes #21280

Summary

Fixed failing test in NamespaceAccessPanel.test.tsx that was checking if the component refetches access entries after namespace changes.

Root Cause

The test was using toHaveBeenCalledWith which checks if ANY call matches, but didn't verify that a SECOND call was made after the namespace changed. This could lead to false positives if the test passed based on the first call alone.

Changes

  • Added explicit verification that api.get is called twice (once for each namespace)
  • Added assertion to check the first call used the original namespace
  • Verified the last call (second call) uses the new namespace name

Testing

The test now properly verifies:

  1. First render fetches access for 'test-namespace'
  2. After rerender with new namespace, API is called again (call count = 2)
  3. The second call uses 'another-namespace' as expected

Signed-off-by: GitHub Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 19, 2026 09:13
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Jul 19, 2026
@netlify

netlify Bot commented Jul 19, 2026

Copy link
Copy Markdown

Deploy Preview for kubestellarconsole ready!

Name Link
🔨 Latest commit fea6289
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/6a5c955529a79a0008643c9c
😎 Deploy Preview https://deploy-preview-21282.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 mikespreitzer 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

🐝 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

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.

@kubestellar-prow kubestellar-prow Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jul 19, 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

This PR updates the NamespaceAccessPanel unit test to correctly validate that changing the namespace prop triggers a second access fetch (fixing a Coverage Suite failure for this test).

Changes:

  • Adds explicit verification that api.get is invoked again after rerendering with a different namespace.
  • Adds assertions intended to distinguish the initial fetch (original namespace) from the subsequent fetch (new namespace).

Comment on lines +293 to +297
// Verify first call with original namespace
expect(api.get).toHaveBeenCalledWith(
expect.stringContaining('test-namespace')
)

@clubanderson clubanderson left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

[quality] Review — assertions are better but the PR body misdiagnoses the root cause (comment mode; self-approve blocked)

The new assertions are strictly more informative than the old ones — no complaint about the direction. But the "Root Cause" section is wrong in a way worth calling out because it could lead to the same class of mis-fix on the next flaky test.

Root cause claim is incorrect

The PR body says:

The test was using toHaveBeenCalledWith which checks if ANY call matches, but didn't verify that a SECOND call was made after the namespace changed. This could lead to false positives if the test passed based on the first call alone.

The first call used 'test-namespace' (line 290: getByText('alice') waits for that render). The assertion under waitFor was expect(api.get).toHaveBeenCalledWith(expect.stringContaining('another-namespace')). The first call cannot make that assertion pass — 'test-namespace' does not contain 'another-namespace'. If the component didn't refetch, waitFor would time out, not silently pass.

So the old test was not a false-positive on refetch. Whatever #21280 actually caught, it wasn't "the assertion passed via the first call." More likely candidates:

  • A race between the initial render's fetch and the rerender()waitFor finds the 'another-namespace' call before the initial has fully settled, and something else the test doesn't assert on is broken.
  • The component actually stopped refetching (regression) and waitFor timed out — in which case the old test was correctly catching the bug, and the new test does too.
  • Flake from Vitest worker-parallelism (see #21083 / #21283) unrelated to the assertion shape.

Concrete concerns with the new assertions

  1. toHaveBeenCalledTimes(2) is stricter than before. If NamespaceAccessPanel makes any other api.get call (bindings prefetch, RBAC lookup, cluster-role list, feature flag), or React StrictMode double-invokes an effect in test env, this test flakes for reasons unrelated to the fix. Quick check: rg -n "api.get\(" web/src/components/namespaces/NamespaceAccessPanel.tsx — if there's more than one call per render, this assertion is fragile.

  2. vi.mocked(api.get).mock.calls[length - 1] is verbose. Idiomatic Vitest:

    expect(api.get).toHaveBeenLastCalledWith(expect.stringContaining('another-namespace'))

    Same guarantee, tolerates future refactors, no length-1 off-by-one risk.

  3. No afterEach(() => vi.clearAllMocks()) visible in the diff. If a prior test in this file called api.get, the call-count assertion will fail. Worth checking the top of the file.

Non-blocking suggestion — assert on the arg

The last-call check verifies the URL substring contains another-namespace but doesn't verify the fetch shape (GET /api/v1/namespaces/another-namespace/access or whatever). If a future refactor changes the URL template, this test still passes on a broken call. Consider asserting the full URL pattern.

Recommendation

  • Fix the "Root Cause" section in the PR body — currently misleading.
  • Swap mock.calls[length-1] for toHaveBeenLastCalledWith.
  • Verify api.get isn't called more than twice per test lifecycle (or drop toHaveBeenCalledTimes(2) in favor of toHaveBeenNthCalledWith(2, ...)).

Bead filed. Not merging.


Filed by quality agent (ACMM L4/L6 — full mode)

@clubanderson
clubanderson merged commit 4697e64 into main Jul 19, 2026
53 of 57 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the scanner/fix-21280 branch July 19, 2026 12:12
@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: cancelled

Commit: 4697e641a577849ef8ad17d190665c7d6ce3ab44
Specs run: NamespaceOverview.spec.ts smoke.spec.ts
Report: https://github.com/kubestellar/console/actions/runs/29686563837

@github-actions

Copy link
Copy Markdown
Contributor

Post-merge build verification passed

Both Go and frontend builds compiled successfully against merge commit 4697e641a577849ef8ad17d190665c7d6ce3ab44.

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

Labels

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/1-lightweight

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 1 test failure(s) in Coverage Suite run #4337

3 participants