Skip to content

test(device-plugin): Improve test coverage for device-plugin/nvidiadevice/nvinternal/cdi - #2351

Merged
hami-robot[bot] merged 2 commits into
Project-HAMi:masterfrom
shinigami-777:test/improve-coverage
Aug 6, 2026
Merged

test(device-plugin): Improve test coverage for device-plugin/nvidiadevice/nvinternal/cdi#2351
hami-robot[bot] merged 2 commits into
Project-HAMi:masterfrom
shinigami-777:test/improve-coverage

Conversation

@shinigami-777

@shinigami-777 shinigami-777 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?
/kind feature

What this PR does / why we need it:
This PR introduces unit tests for the pkg/device-plugin/nvidiadevice/nvinternal/cdi package. Previously, the cdi package lacked unit tests (0% coverage). With these additions, statement coverage has been improved to 25.8%.

The following tests have been added :

  1. null_test.go: Validates the behavior of the null CDI fallback handler ensuring safe defaults.
  2. options_test.go: Verifies configuration options correctly populate the cdiHandler.
  3. imex_test.go: Confirms the IMEX CDI spec generation effectively creates standard device node edits.
  4. cdi_test.go: Checks CDI additional device discovery (AdditionalDevices) and naming conventions (QualifiedName).

All the newly created files include the required Apache 2.0 open-source license headers to ensure compliance with the checks.

New test coverage:

ok      github.com/Project-HAMi/HAMi/pkg/device-plugin/nvidiadevice/nvinternal/cdi      1.041s  coverage: 25.8% of statements

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:
No, it only improves the test coverage.

AI assistance disclosure:
I used assistance from Gemini 3.1 Pro for writing the tests.

Summary by CodeRabbit

  • Tests
    • Added coverage for CDI qualified-name generation and additional-device enumeration.
    • Added validation for IMEX channel specification and container device-node paths.
    • Added tests for null-handler behavior and CDI specification file creation.
    • Added coverage for configuration options, including device strategies, paths, identifiers, feature flags, and IMEX channels.
    • These checks help ensure reliable device configuration and resource exposure across supported GPU features.

…rnal/cdi

Signed-off-by: shinigami-777 <chattopadhyaytamaghna@gmail.com>
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e3f2f62b-6b7c-411f-bbe8-f16c97e57b89

📥 Commits

Reviewing files that changed from the base of the PR and between db7f1d9 and 12b5ca5.

📒 Files selected for processing (3)
  • pkg/device-plugin/nvidiadevice/nvinternal/cdi/cdi_test.go
  • pkg/device-plugin/nvidiadevice/nvinternal/cdi/imex_test.go
  • pkg/device-plugin/nvidiadevice/nvinternal/cdi/options_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • pkg/device-plugin/nvidiadevice/nvinternal/cdi/imex_test.go
  • pkg/device-plugin/nvidiadevice/nvinternal/cdi/cdi_test.go
  • pkg/device-plugin/nvidiadevice/nvinternal/cdi/options_test.go

📝 Walkthrough

Walkthrough

Added unit tests for CDI naming, additional-device enumeration, IMEX channel spec generation, null-handler behavior, and CDI handler option configuration.

Changes

CDI handler test coverage

Layer / File(s) Summary
Handler behavior tests
pkg/device-plugin/nvidiadevice/nvinternal/cdi/cdi_test.go, pkg/device-plugin/nvidiadevice/nvinternal/cdi/null_test.go
Tests qualified-name generation, auxiliary device enumeration, null-handler construction, spec-file creation, and empty qualified names.
IMEX specification generation
pkg/device-plugin/nvidiadevice/nvinternal/cdi/imex_test.go
Tests CDI spec generation for two IMEX channels and their expected device-node paths.
Handler option configuration
pkg/device-plugin/nvidiadevice/nvinternal/cdi/options_test.go
Uses table-driven cases to validate CDI handler option state, including device-list strategy, paths, device ID strategy, vendor, feature flags, and IMEX channels.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • Project-HAMi/HAMi#2087: Adds CDI module tests for handler functionality, qualified names, and option configuration.

Suggested reviewers: archlitchi

Poem

A rabbit checks each CDI trail,
Names and channels without fail.
Options line up, devices appear,
Null paths stay quiet and clear.
Tests now hop through every detail.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: adding unit tests to improve coverage for the device-plugin/nvidiadevice/nvinternal/cdi package.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
pkg/device-plugin/nvidiadevice/nvinternal/cdi/imex_test.go (1)

35-40: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Group the external and project-local imports separately.

The import block puts github.com/stretchr/testify/require (external) and github.com/Project-HAMi/HAMi/pkg/device-plugin/nvidiadevice/nvinternal/imex (project-local) in the same group. The coding guidelines require three separate groups: standard library, then external imports, then github.com/Project-HAMi/HAMi/... imports.

🔧 Proposed fix
 import (
 	"testing"

 	"github.com/stretchr/testify/require"
+
 	"github.com/Project-HAMi/HAMi/pkg/device-plugin/nvidiadevice/nvinternal/imex"
 )

As per coding guidelines, "Go import blocks must be grouped as standard library imports first, then external imports, then github.com/Project-HAMi/HAMi/... imports."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/device-plugin/nvidiadevice/nvinternal/cdi/imex_test.go` around lines 35 -
40, Reorganize the import block in the test file to follow the three-group
import structure. The imports currently mix external imports
(github.com/stretchr/testify/require) with project-local imports
(github.com/Project-HAMi/HAMi/...) in the same group. Separate these two groups
by adding a blank line between the external imports and the project-local
imports, maintaining the standard library imports (testing) at the top as the
first group.

Source: Coding guidelines

pkg/device-plugin/nvidiadevice/nvinternal/cdi/options_test.go (1)

132-135: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the configured IMEX channel path.

Line 133 checks the channel count. Line 134 checks only Channel.ID. If WithImexChannels drops or changes Channel.Path, this test still passes. Assert c.imexChannels[0].Path equals "/path1".

Proposed test update
 			validate: func(t *testing.T, c *cdiHandler) {
 				require.Len(t, c.imexChannels, 1)
 				require.Equal(t, "channel1", c.imexChannels[0].ID)
+				require.Equal(t, "/path1", c.imexChannels[0].Path)
 			},
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/device-plugin/nvidiadevice/nvinternal/cdi/options_test.go` around lines
132 - 135, Update the validate callback in the WithImexChannels test to also
assert that c.imexChannels[0].Path equals "/path1", while preserving the
existing length and ID assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/device-plugin/nvidiadevice/nvinternal/cdi/cdi_test.go`:
- Around line 35-40: Organize imports in
pkg/device-plugin/nvidiadevice/nvinternal/cdi/cdi_test.go lines 35-40 with
goimports, sorting NVIDIA and Testify imports in the external group. In
pkg/device-plugin/nvidiadevice/nvinternal/cdi/options_test.go lines 35-42, keep
NVIDIA and Testify imports external and place the
github.com/Project-HAMi/HAMi/... import in a separate local group; run goimports
-local github.com/Project-HAMi/HAMi on both files.

---

Nitpick comments:
In `@pkg/device-plugin/nvidiadevice/nvinternal/cdi/imex_test.go`:
- Around line 35-40: Reorganize the import block in the test file to follow the
three-group import structure. The imports currently mix external imports
(github.com/stretchr/testify/require) with project-local imports
(github.com/Project-HAMi/HAMi/...) in the same group. Separate these two groups
by adding a blank line between the external imports and the project-local
imports, maintaining the standard library imports (testing) at the top as the
first group.

In `@pkg/device-plugin/nvidiadevice/nvinternal/cdi/options_test.go`:
- Around line 132-135: Update the validate callback in the WithImexChannels test
to also assert that c.imexChannels[0].Path equals "/path1", while preserving the
existing length and ID assertions.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bbeb0132-fd53-4561-8395-b040c45bb209

📥 Commits

Reviewing files that changed from the base of the PR and between 4f8a82f and db7f1d9.

📒 Files selected for processing (4)
  • pkg/device-plugin/nvidiadevice/nvinternal/cdi/cdi_test.go
  • pkg/device-plugin/nvidiadevice/nvinternal/cdi/imex_test.go
  • pkg/device-plugin/nvidiadevice/nvinternal/cdi/null_test.go
  • pkg/device-plugin/nvidiadevice/nvinternal/cdi/options_test.go

Comment thread pkg/device-plugin/nvidiadevice/nvinternal/cdi/cdi_test.go
@github-actions github-actions Bot removed the kind/feature new function label Aug 4, 2026
…test files

Signed-off-by: shinigami-777 <chattopadhyaytamaghna@gmail.com>
@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unittests 61.61% <ø> (+0.62%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@archlitchi archlitchi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@hami-robot

hami-robot Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: archlitchi, shinigami-777

The full list of commands accepted by this bot can be found here.

The pull request process is described 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

@hami-robot hami-robot Bot added the approved label Aug 6, 2026
@hami-robot
hami-robot Bot merged commit 0019e69 into Project-HAMi:master Aug 6, 2026
17 checks passed
@shinigami-777
shinigami-777 deleted the test/improve-coverage branch August 9, 2026 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants