Skip to content

🐛 Fix remaining Vitest failures from Coverage Suite run #1873#11184

Merged
clubanderson merged 1 commit intomainfrom
fix/11182
May 1, 2026
Merged

🐛 Fix remaining Vitest failures from Coverage Suite run #1873#11184
clubanderson merged 1 commit intomainfrom
fix/11182

Conversation

@clubanderson
Copy link
Copy Markdown
Collaborator

Fixes #11182

Fix 28 remaining test failures (out of 44 total) not addressed by #11183.

Root Cause

  • workloads tests (26 failures): Tests mocked api.get via mockApiGet, but hooks call agentFetch() for the REST API fallback path. The agentFetch mock returned an empty Response, so test data never reached the hooks.
  • dedup test (1 failure): shareMetricsBetweenSameServerClusters guarded the first pass with (clusters || []) but not the second pass, crashing on null input.
  • useDataCompliance test (1 failure): Test expected isLoading=true with corrupt cache, but with empty clusters the hook completes immediately setting isLoading=false.

Changes

  • workloads.core.test.ts / workloads-coverage.test.ts: Wire agentFetch mock to delegate to mockApiGet (adapting response shape) so existing test assertions work
  • dedup.ts: Add null guard to second pass of shareMetricsBetweenSameServerClusters
  • useDataCompliance-coverage.test.ts: Fix assertion to match actual hook behavior

Verification

All 299 previously-failing tests now pass across all 7 test files.

- Fix agentFetch mock in workloads.core and workloads-coverage tests to
  delegate to mockApiGet so test assertions match actual hook fetch path
- Add null guard to shareMetricsBetweenSameServerClusters second pass
  (first pass already guarded, second pass crashed on null input)
- Fix useDataCompliance corrupt cache test: with empty clusters the hook
  completes immediately so isLoading is false, not true

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings May 1, 2026 00:39
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label May 1, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented May 1, 2026

Deploy Preview for kubestellarconsole ready!

Name Link
🔨 Latest commit d4585ca
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/69f3f64f11b9d10008e91656
😎 Deploy Preview https://deploy-preview-11184.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

github-actions Bot commented May 1, 2026

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

Pull request overview

Fixes remaining Vitest failures from the coverage suite by aligning test mocks with the current REST fallback implementation (agentFetch), hardening a dedup pure function against nullish inputs, and updating an assertion to match the hook’s real loading behavior.

Changes:

  • Updated workloads tests to route agentFetch mock calls through existing mockApiGet so REST fallback paths receive expected data.
  • Added a null/undefined guard in the second pass of shareMetricsBetweenSameServerClusters.
  • Adjusted useDataCompliance corrupt-cache test expectation for isLoading.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
web/src/hooks/mcp/dedup.ts Adds null guard for metrics-sharing second pass to prevent crashes on nullish input.
web/src/hooks/mcp/__tests__/workloads.core.test.ts Rewires agentFetch mock to delegate to mockApiGet for REST fallback coverage.
web/src/hooks/mcp/__tests__/workloads-coverage.test.ts Same as above for extended/branch coverage cases.
web/src/hooks/__tests__/useDataCompliance-coverage.test.ts Updates loading expectation when clusters are empty and cache is corrupt.

agentFetch: vi.fn().mockImplementation(() => Promise.resolve(new Response(JSON.stringify({}), { status: 200 }))),
agentFetch: vi.fn().mockImplementation(async (...args: unknown[]) => {
const result = await mockApiGet(...args)
return { ok: true, status: 200, json: async () => result?.data ?? result }
Comment on lines +45 to 46
return (clusters || []).map(cluster => {
if (!cluster.server) return cluster
agentFetch: vi.fn().mockImplementation(() => Promise.resolve(new Response(JSON.stringify({}), { status: 200 }))),
agentFetch: vi.fn().mockImplementation(async (...args: unknown[]) => {
const result = await mockApiGet(...args)
return { ok: true, status: 200, json: async () => result?.data ?? result }
@clubanderson clubanderson merged commit 8eb067f into main May 1, 2026
35 of 38 checks passed
@kubestellar-prow kubestellar-prow Bot deleted the fix/11182 branch May 1, 2026 00:53
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

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

github-actions Bot commented May 1, 2026

✅ Post-Merge Verification: passed

Commit: 8eb067f3fd3114ee589f54d6b4195dcc70d3bbcf
Specs run: smoke.spec.ts
Report: https://github.com/kubestellar/console/actions/runs/25196924721

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

Post-merge build verification passed

Both Go and frontend builds compiled successfully against merge commit 8eb067f3fd3114ee589f54d6b4195dcc70d3bbcf.

clubanderson pushed a commit that referenced this pull request May 1, 2026
…n, type signatures

- feedback_config.go: add resolveGitHubUIBase() for GHE-aware web link construction
- feedback_github.go: use resolveGitHubUIBase() for SHA commit link (#11177 follow-up)
- ComplianceReports.tsx: clear selectedCluster when it's filtered out by reachability
  (was only auto-set when empty, leaving stale selection pointing to hidden cluster)
- ComplianceReports.tsx + ControlPlaneHealth.tsx: fix misleading 'only reachable'
  comments — predicate c.reachable !== false also includes undefined (not-yet-checked)
- dedup.ts: widen shareMetricsBetweenSameServerClusters signature to ClusterInfo[] |
  null | undefined to match the runtime guard already in the body (#11184 medium)
- shared.ts: fix dedup priority comment — reachability is criterion #1, not #2

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Copilot <[email protected]>
clubanderson added a commit that referenced this pull request May 1, 2026
* 🐛 Fix incorrect assertion in agentFetch 401 retry test

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Copilot <[email protected]>

* test: batch 16 coverage — preflightCheck, useClusterContext, sampleData (#11192)

* test: add batch 16 coverage tests for preflightCheck, useClusterContext, sampleData

Add 116 tests across 3 files to push line coverage past 90.50%:
- preflightCheck-coverage (67 tests): classifyKubectlError, resolveRequiredTools, runToolPreflightCheck
- useClusterContext-coverage (17 tests): operator name stripping, helm chart parsing, pod issues
- sampleData-coverage (32 tests): field heuristics, detectFieldFormat edge cases

Signed-off-by: Andrew Anderson <[email protected]>

* fix: change savedCards/sharedDashboards to let for reassignment in resetShareRegistries

Signed-off-by: Andrew Anderson <[email protected]>

---------

Signed-off-by: Andrew Anderson <[email protected]>

* 🐛 Fix medium Copilot comments: GHE commit URL, stale cluster selection, type signatures

- feedback_config.go: add resolveGitHubUIBase() for GHE-aware web link construction
- feedback_github.go: use resolveGitHubUIBase() for SHA commit link (#11177 follow-up)
- ComplianceReports.tsx: clear selectedCluster when it's filtered out by reachability
  (was only auto-set when empty, leaving stale selection pointing to hidden cluster)
- ComplianceReports.tsx + ControlPlaneHealth.tsx: fix misleading 'only reachable'
  comments — predicate c.reachable !== false also includes undefined (not-yet-checked)
- dedup.ts: widen shareMetricsBetweenSameServerClusters signature to ClusterInfo[] |
  null | undefined to match the runtime guard already in the body (#11184 medium)
- shared.ts: fix dedup priority comment — reachability is criterion #1, not #2

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Copilot <[email protected]>

---------

Signed-off-by: Copilot <[email protected]>
Signed-off-by: Andrew Anderson <[email protected]>
Co-authored-by: Copilot <[email protected]>
lightyagami2109 pushed a commit to lightyagami2109/kubestellar_console_OJT that referenced this pull request May 3, 2026
…r#1873 (kubestellar#11184)

- Fix agentFetch mock in workloads.core and workloads-coverage tests to
  delegate to mockApiGet so test assertions match actual hook fetch path
- Add null guard to shareMetricsBetweenSameServerClusters second pass
  (first pass already guarded, second pass crashed on null input)
- Fix useDataCompliance corrupt cache test: with empty clusters the hook
  completes immediately so isLoading is false, not true

Signed-off-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Signed-off-by: lightyagami2109 <[email protected]>
lightyagami2109 pushed a commit to lightyagami2109/kubestellar_console_OJT that referenced this pull request May 3, 2026
…1202)

* 🐛 Fix incorrect assertion in agentFetch 401 retry test

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Copilot <[email protected]>

* test: batch 16 coverage — preflightCheck, useClusterContext, sampleData (kubestellar#11192)

* test: add batch 16 coverage tests for preflightCheck, useClusterContext, sampleData

Add 116 tests across 3 files to push line coverage past 90.50%:
- preflightCheck-coverage (67 tests): classifyKubectlError, resolveRequiredTools, runToolPreflightCheck
- useClusterContext-coverage (17 tests): operator name stripping, helm chart parsing, pod issues
- sampleData-coverage (32 tests): field heuristics, detectFieldFormat edge cases

Signed-off-by: Andrew Anderson <[email protected]>

* fix: change savedCards/sharedDashboards to let for reassignment in resetShareRegistries

Signed-off-by: Andrew Anderson <[email protected]>

---------

Signed-off-by: Andrew Anderson <[email protected]>

* 🐛 Fix medium Copilot comments: GHE commit URL, stale cluster selection, type signatures

- feedback_config.go: add resolveGitHubUIBase() for GHE-aware web link construction
- feedback_github.go: use resolveGitHubUIBase() for SHA commit link (kubestellar#11177 follow-up)
- ComplianceReports.tsx: clear selectedCluster when it's filtered out by reachability
  (was only auto-set when empty, leaving stale selection pointing to hidden cluster)
- ComplianceReports.tsx + ControlPlaneHealth.tsx: fix misleading 'only reachable'
  comments — predicate c.reachable !== false also includes undefined (not-yet-checked)
- dedup.ts: widen shareMetricsBetweenSameServerClusters signature to ClusterInfo[] |
  null | undefined to match the runtime guard already in the body (kubestellar#11184 medium)
- shared.ts: fix dedup priority comment — reachability is criterion kubestellar#1, not kubestellar#2

Co-authored-by: Copilot <[email protected]>
Signed-off-by: Copilot <[email protected]>

---------

Signed-off-by: Copilot <[email protected]>
Signed-off-by: Andrew Anderson <[email protected]>
Co-authored-by: Copilot <[email protected]>
Signed-off-by: lightyagami2109 <[email protected]>
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.

🐛 44 test failure(s) in Coverage Suite run #1873

3 participants