[scanner] fix: add unit tests for pkg/agent utility files#19951
Conversation
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>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
✅ Deploy Preview for kubestellarconsole canceled.
|
|
👋 Hey @clubanderson — thanks for opening this PR!
This is an automated message. |
|
🐝 Hi @clubanderson! I'm Trusted users — org members and contributors with write access — can mention Automation may take a moment to start, and follow-up happens through workflow activity rather than chat replies. |
There was a problem hiding this comment.
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
workersconcurrency fan-out cap andagentshell sentinel error. - Added prompt validation tests for
DefaultSystemPrompt/ChatOnlySystemPrompt. - Added basic tests for
federationtypes/constants andFederationError.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(). |
| 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) | ||
| } |
| 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>
|
Quality review note — Two CI failures on this PR:
Once both issues are resolved, the |
Signed-off-by: sec-check <sec-check@hive.kubestellar.io>
Signed-off-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Quality review update — The
Fix: Rebase onto current main and drop the The |
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>
22d25b4 to
3c72da7
Compare
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>
|
Thank you for your contribution! Your PR has been merged. Check out what's new:
Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey |
|
Post-merge build verification passed ✅ Both Go and frontend builds compiled successfully against merge commit |
✅ Post-Merge Verification: passedCommit: |
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>
…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>
Partially addresses #19907
Adds unit tests for 4 previously-untested utility files in
pkg/agent/:Targets the most testable files with pure functions and simple logic (4 of 12 untested files).