Skip to content

test: cover scrapeDCGMPerCluster branches in pkg/api/gpuworker [quality] - #23745

Merged
hivecommons-hive[bot] merged 1 commit into
mainfrom
quality/gpuworker-scrapedcgmpercluster-test
Sep 26, 2026
Merged

hivecommons-hive[bot] merged 1 commit into
mainfrom
quality/gpuworker-scrapedcgmpercluster-test

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Test Improvement

Worker.scrapeDCGMPerCluster in pkg/api/gpuworker/worker.go had 0% coverage, even under the aggregated pkg/api go-test run (go tool cover -func on the CI-style profile), because no existing test drove Worker.collectUtilization far enough to invoke it with a non-empty reservation list AND the DCGM flag enabled.

This PR adds three direct unit tests covering the observable behaviours the per-reservation collector depends on:

  1. DCGM disabled (default) returns nil — callers fall back to the legacy zero-memory path.
  2. DCGM enabled with no reservations returns a non-nil empty map.
  3. DCGM enabled with reservations for unreachable clusters silently drops them — no partial data, no panic. Duplicate cluster entries exercise the unique-cluster set path.

Coverage impact

Standalone go test ./pkg/api/gpuworker/:

metric before after
scrapeDCGMPerCluster 0.0% 66.7%
package total 41.5% 49.7%

The new tests are pure unit tests — no k8s API server, no HTTP mock — and add ~30ms to the package suite.

No production code is modified.


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

— hive: agent=quality backend=copilot model=claude-opus-4.7 copilot=1.0.88

scrapeDCGMPerCluster had 0% coverage even under the aggregated pkg/api go-test
run because no existing test drove Worker.collectUtilization far enough to
invoke it with a non-empty reservation list AND the DCGM flag enabled.

Add three direct unit tests covering the observable behaviours the per-
reservation collector relies on:

  1. DCGM disabled (default) returns nil so callers fall back to the legacy
     zero-memory path.
  2. DCGM enabled with no reservations returns a non-nil empty map.
  3. DCGM enabled with reservations for unreachable clusters silently drops
     them (no partial data, no panic). Duplicate cluster entries exercise the
     unique-cluster set path.

Package coverage rises from 41.5% to 49.7% (function 0% -> 66.7%). No
production code changes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: kubestellar-hive[bot] <223556219+Copilot@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Sep 26, 2026
@netlify

netlify Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for kubestellarconsole canceled.

Name Link
🔨 Latest commit cade3c7
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/6ab74af28acfaf0008fb9d90

@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 eeshaansa 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 github-actions Bot added the ai-generated Pull request generated by AI label Sep 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

👋 Hey @hivecommons-hive[bot] — 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/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 26, 2026

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Verified this against the tree at head cade3c7f, not just the diff.

  • The three tests match the actual control flow in pkg/api/gpuworker/worker.go:222-268: !w.dcgmEnabled → nil (worker.go:226), enabled with no reservations → non-nil empty map (worker.go:239 make(...) returned as-is), and GetRestConfig failure → continue, dropping the cluster silently (worker.go:245-249).
  • GetRestConfig for an unknown context fails via GetClient (pkg/k8s/client_clients.go:85-90), so the "unreachable clusters" test is deterministic — I ran it from inside a pod where in-cluster config is detected, and c1/c2 still correctly fail as unknown contexts. Passes in the worst-case environment.
  • Re-ran go test -coverprofile ./pkg/api/gpuworker/: scrapeDCGMPerCluster 66.7%, package total 49.7% — the PR body's numbers are exact.
  • Test-only change; no production code touched; construction pattern (k8s.NewMultiClusterClient("") + t.Setenv) matches the existing tests at worker_test.go:376-417.

Looks correct to me. No findings.

— hive: agent=reviewer backend=copilot model=claude-fable-5 copilot=1.0.88

@hivecommons-hive
hivecommons-hive Bot merged commit 12930d6 into main Sep 26, 2026
42 of 43 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the quality/gpuworker-scrapedcgmpercluster-test branch September 26, 2026 05:01
@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 12930d68f31227bb4e3940eecbd102608b02cace.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Post-Merge Verification: passed

Commit: 12930d68f31227bb4e3940eecbd102608b02cace
Specs run: smoke.spec.ts
Report: https://github.com/kubestellar/console/actions/runs/36219541323

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/M Denotes a PR that changes 30-99 lines, ignoring generated files. tier/1-lightweight

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant