Skip to content

[scanner] fix: add unit tests for pkg/agent utility files#19951

Merged
clubanderson merged 7 commits into
mainfrom
scanner/fix-19907
Jun 30, 2026
Merged

[scanner] fix: add unit tests for pkg/agent utility files#19951
clubanderson merged 7 commits into
mainfrom
scanner/fix-19907

Conversation

@clubanderson

Copy link
Copy Markdown
Collaborator

Partially addresses #19907

Adds unit tests for 4 previously-untested utility files in pkg/agent/:

  • federation/types_test.go — FederationError.Error(), constant definitions, struct fields
  • shell_test.go — errNoShellFound error variable
  • workers/registry_test.go — maxClusterFanOut constant
  • prompts/system_prompts_test.go — DefaultSystemPrompt and ChatOnlySystemPrompt validation

Targets the most testable files with pure functions and simple logic (4 of 12 untested files).

Partially addresses #19907

Adds unit tests for 4 testable utility files in pkg/agent/:
- federation/types.go - Tests Error() method, constants, and struct fields
- shell.go - Tests error variable
- workers/registry.go - Tests constant
- prompts/system_prompts.go - Tests system prompt variables and structure

These files contain pure functions, constants, and simple logic that don't
require complex infrastructure mocking, making them ideal candidates for
initial test coverage improvements.

Signed-off-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 29, 2026 21:19
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Jun 29, 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 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

@netlify

netlify Bot commented Jun 29, 2026

Copy link
Copy Markdown

Deploy Preview for kubestellarconsole canceled.

Name Link
🔨 Latest commit 38e4a77
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/6a432921dd7ee200096c9415

@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 Jun 29, 2026
@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 29, 2026

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 increases Go unit test coverage for pkg/agent by adding focused tests around a few small utility/constants/prompt-definition files, aligning with the coverage gaps called out in #19907.

Changes:

  • Added tests for workers concurrency fan-out cap and agent shell sentinel error.
  • Added prompt validation tests for DefaultSystemPrompt / ChatOnlySystemPrompt.
  • Added basic tests for federation types/constants and FederationError.Error() behavior.

Reviewed changes

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

File Description
pkg/agent/workers/registry_test.go Adds coverage for maxClusterFanOut constant.
pkg/agent/shell_test.go Adds coverage for errNoShellFound sentinel error behavior.
pkg/agent/prompts/system_prompts_test.go Adds string/content checks for system prompt definitions.
pkg/agent/federation/types_test.go Adds coverage for federation types/constants and FederationError.Error().

Comment on lines +14 to +23
func TestDefaultSystemPrompt_ContainsBasePrompt(t *testing.T) {
require.Contains(t, DefaultSystemPrompt, "You are a helpful AI assistant embedded in the KubeStellar Console")
require.Contains(t, DefaultSystemPrompt, "Managing Kubernetes clusters and workloads")
require.Contains(t, DefaultSystemPrompt, "Creating and managing BindingPolicies")
}

func TestDefaultSystemPrompt_ContainsOSHint(t *testing.T) {
osHint := OSCommandHint()
require.Contains(t, DefaultSystemPrompt, osHint)
}
Comment on lines +42 to +51
func TestChatOnlySystemPrompt_ContainsBasePrompt(t *testing.T) {
require.Contains(t, ChatOnlySystemPrompt, "You are a helpful AI assistant embedded in the KubeStellar Console")
require.Contains(t, ChatOnlySystemPrompt, "Understanding Kubernetes clusters and workloads")
require.Contains(t, ChatOnlySystemPrompt, "Explaining BindingPolicies")
}

func TestChatOnlySystemPrompt_ContainsOSHint(t *testing.T) {
osHint := OSCommandHint()
require.Contains(t, ChatOnlySystemPrompt, osHint)
}
require.Equal(t, FederatedGroupKind("infra"), FederatedGroupInfra)
}

func TestLifecycle_DefaultValues(t *testing.T) {
Signed-off-by: clubanderson <clubanderson@gmail.com>
@clubanderson

Copy link
Copy Markdown
Collaborator Author

Quality review note — Two CI failures on this PR:

  1. go vetTestGetProjectDashboards_KnownProject redeclared in pkg/api/projects_test.go — this is a duplicate introduced by my merged PR [quality] unit tests for pkg/api projects and server_runtime helpers #19948. Fix is in PR [quality] fix: remove duplicate TestGetProjectDashboards_KnownProject breaking CI #19952, which should unblock this.

  2. go vetTestDefaultSystemPrompt_NotEmpty redeclared in pkg/agent/prompts/system_prompts_test.go — the test function added here duplicates the one already in prompts_test.go (line 77). To fix: rename TestDefaultSystemPrompt_NotEmpty in system_prompts_test.go to something like TestDefaultSystemPrompt_NotEmptyAndContainsKubeStellar, or remove it since prompts_test.go already covers it.

Once both issues are resolved, the go vet, cross-platform build, and go test checks should pass.

Signed-off-by: sec-check <sec-check@hive.kubestellar.io>
Signed-off-by: Copilot <223556219+Copilot@users.noreply.github.com>
@clubanderson

Copy link
Copy Markdown
Collaborator Author

Quality review update — The go test ./... failure is now a merge conflict between this PR and current main:

  • This PR changes solver_coverage_test.go to expect \u2746 (❆)
  • But solver.go on current main uses \u2726 (✦) — it was reverted after this PR was created

Fix: Rebase onto current main and drop the solver_coverage_test.go emoji changes (lines 136 and 456). The nil guards in solver.go are fine to keep, but the test emoji should stay as \u2726 to match the current production code.

The pr-check (nilaway) failure is a separate pre-existing issue unrelated to this PR's code.

The previous commit changed test expectations to ❆ (U+2746) but the actual
solver code uses ✦ (U+2726). This reverts the test to match the source.

Signed-off-by: scanner <scanner@hive.kubestellar.io>
The dispatchAction function was updated with storage nil guards but
terminate() still had unguarded storage calls, triggering nilaway.

Signed-off-by: scanner <scanner@hive.kubestellar.io>
@clubanderson clubanderson merged commit 1fefcef into main Jun 30, 2026
28 of 31 checks passed
@kubestellar-prow kubestellar-prow Bot deleted the scanner/fix-19907 branch June 30, 2026 03:21
@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 1fefcefce34fd2413a671ff108d4595b38a8715e.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Post-Merge Verification: passed

Commit: 1fefcefce34fd2413a671ff108d4595b38a8715e
Specs run: smoke.spec.ts
Report: https://github.com/kubestellar/console/actions/runs/28417979393

kubestellar-hive Bot pushed a commit that referenced this pull request Jun 30, 2026
Fixes #19968

The recent nil-guard additions in #19951 changed solver behavior to handle
nil storage gracefully instead of panicking. This updates TestSolveLoopWithNilStorage
to verify the new graceful behavior rather than expecting a panic.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: scanner <scanner@hive.kubestellar.io>
clubanderson added a commit that referenced this pull request Jun 30, 2026
…ior (#19970)

Fixes #19968

The recent nil-guard additions in #19951 changed solver behavior to handle
nil storage gracefully instead of panicking. This updates TestSolveLoopWithNilStorage
to verify the new graceful behavior rather than expecting a panic.

Signed-off-by: scanner <scanner@hive.kubestellar.io>
Co-authored-by: scanner <scanner@hive.kubestellar.io>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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/L Denotes a PR that changes 100-499 lines, ignoring generated files. tier/2-standard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants