Skip to content

[scanner] fix: add hook tests for web/src/hooks/mcp#19656

Merged
clubanderson merged 2 commits into
mainfrom
scanner/fix-19648
Jun 25, 2026
Merged

[scanner] fix: add hook tests for web/src/hooks/mcp#19656
clubanderson merged 2 commits into
mainfrom
scanner/fix-19648

Conversation

@clubanderson

Copy link
Copy Markdown
Collaborator

Fixes #19648

Adds comprehensive test coverage for three previously untested hook files in web/src/hooks/mcp:

Test Files Added

1. sharedImpl.types.test.ts

Tests for type definitions and utility functions:

  • DATA_FIELDS and UI_FIELDS constants
  • updatesTouchData() function
  • updatesTouchUI() function
  • Validates field partitioning and array safety

2. kagent_crds.test.ts

Tests for Kagent CRD hooks:

  • useKagentCRDAgents() - fetches agent resources
  • useKagentCRDTools() - fetches tool server resources
  • useKagentCRDModels() - fetches model config resources
  • useKagentCRDMemories() - fetches memory resources

3. kagenti.test.ts

Tests for Kagenti hooks:

  • useKagentiAgents() - fetches Kagenti agent instances
  • useKagentiBuilds() - fetches build resources
  • useKagentiCards() - fetches agent cards
  • useKagentiTools() - fetches tool bindings
  • useKagentiSummary() - aggregates summary data from all sub-hooks

Test Coverage

All tests follow established patterns from existing test files:

  • Uses vitest test framework
  • Uses @testing-library/react for hook testing
  • Includes hoisted mocks for dependencies
  • Covers key functionality: cache keys, demo data, enabled state, return values
  • Tests edge cases and error conditions

CI Validation

Build and lint validation will be handled by CI on this PR.

Adds comprehensive test coverage for three previously untested hook files:

- sharedImpl.types.test.ts: Tests for DATA_FIELDS, UI_FIELDS, and utility
  functions updatesTouchData() and updatesTouchUI()

- kagent_crds.test.ts: Tests for useKagentCRDAgents, useKagentCRDTools,
  useKagentCRDModels, and useKagentCRDMemories hooks

- kagenti.test.ts: Tests for useKagentiAgents, useKagentiBuilds,
  useKagentiCards, useKagentiTools, and useKagentiSummary hooks

All tests follow established patterns from existing test files, using vitest
and @testing-library/react-hooks for React hook testing.

Fixes #19648

Signed-off-by: Copilot <copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 25, 2026 22:34
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Jun 25, 2026
@netlify

netlify Bot commented Jun 25, 2026

Copy link
Copy Markdown

Deploy Preview for kubestellarconsole ready!

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

@kubestellar-prow kubestellar-prow Bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jun 25, 2026
@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

✅ 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.

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

Adds unit test coverage for MCP-related hooks under web/src/hooks/mcp/, targeting previously untested modules and validating key behaviors (constants/utility helpers and useCache hook configuration) using Vitest and @testing-library/react.

Changes:

  • Added tests for sharedImpl.types.ts constants and slice-detection helpers (updatesTouchData, updatesTouchUI).
  • Added tests for Kagenti hooks (useKagenti*) including summary aggregation behavior.
  • Added tests for Kagent CRD hooks (useKagentCRD*) validating cache keys, demo data wiring, enabled state, and return values.

Reviewed changes

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

File Description
web/src/hooks/mcp/tests/sharedImpl.types.test.ts Adds coverage for sharedImpl.types.ts field partitions and update-touch helpers.
web/src/hooks/mcp/tests/kagenti.test.ts Adds coverage for Kagenti resource hooks and useKagentiSummary aggregation/refetch behavior.
web/src/hooks/mcp/tests/kagent_crds.test.ts Adds coverage for Kagent CRD hooks and their useCache configuration.

* Covers the hooks for fetching Kagenti resources (agents, builds, cards, tools, summary).
*/
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { renderHook, waitFor } from '@testing-library/react'
* Covers the hooks for fetching Kagent CRD resources (agents, tools, models, memories).
*/
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { renderHook, waitFor } from '@testing-library/react'
Comment on lines +52 to +63
import {
useKagentiAgents,
useKagentiBuilds,
useKagentiCards,
useKagentiTools,
useKagentiSummary,
type KagentiAgent,
type KagentiBuild,
type KagentiCard,
type KagentiTool,
type KagentiSummary,
} from '../kagenti'
Comment on lines +187 to +201
// ---------------------------------------------------------------------------
// Guard against undefined arrays (issue #15569)
// ---------------------------------------------------------------------------

describe('Array safety (issue #15569)', () => {
it('updatesTouchData guards against undefined DATA_FIELDS', () => {
// Even if DATA_FIELDS is somehow undefined, function should not crash
expect(() => updatesTouchData({ clusters: [] })).not.toThrow()
})

it('updatesTouchUI guards against undefined UI_FIELDS', () => {
// Even if UI_FIELDS is somehow undefined, function should not crash
expect(() => updatesTouchUI({ isLoading: true })).not.toThrow()
})
})
* Covers the hooks for fetching Kagent CRD resources (agents, tools, models, memories).
*/
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { renderHook, waitFor } from '@testing-library/react'
* Covers the hooks for fetching Kagenti resources (agents, builds, cards, tools, summary).
*/
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { renderHook, waitFor } from '@testing-library/react'
@clubanderson clubanderson merged commit 58d7d51 into main Jun 25, 2026
26 of 29 checks passed
@kubestellar-prow kubestellar-prow Bot deleted the scanner/fix-19648 branch June 25, 2026 23:27
@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 58d7d518725346da0a9357f00fde75f88cc53a69.

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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. tier/1-lightweight

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[quality] Add hook tests for web/src/hooks/mcp (39 files)

2 participants