Skip to content

fix: resolve Memory Summary showing no data in Hardware Information (…#821

Open
amarnath-ac wants to merge 2 commits intomainfrom
mem_summary_no_data
Open

fix: resolve Memory Summary showing no data in Hardware Information (…#821
amarnath-ac wants to merge 2 commits intomainfrom
mem_summary_no_data

Conversation

@amarnath-ac
Copy link
Contributor

#816)

Enhanced parseCIMResponse to handle typed slices using reflection.
Added test for parseCIMResponse function achieving 100% coverage.

…816)

Enhanced parseCIMResponse to handle typed slices using reflection.
Added test for parseCIMResponse function achieving 100% coverage.

Signed-off-by: C, Amarnath <amarnath.c@intel.com>
Signed-off-by: S, Devipriya <devipriya.s@intel.com>
@codecov
Copy link

codecov bot commented Mar 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 39.76%. Comparing base (ceaa99c) to head (3c0a659).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #821   +/-   ##
=======================================
  Coverage   39.76%   39.76%           
=======================================
  Files         114      114           
  Lines       10768    10768           
=======================================
  Hits         4282     4282           
  Misses       6087     6087           
  Partials      399      399           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@amarnath-ac amarnath-ac requested a review from DevipriyaS17 March 4, 2026 06:24
@amarnath-ac amarnath-ac marked this pull request as ready for review March 4, 2026 08:35
@madhavilosetty-intel
Copy link
Contributor

@amarnath-ac Since we know the type of data which is []physical.PhysicalMemory, it's not necessary to use reflect. Reflect is generally used when the type is truly unknown at compile time. Instead, convert the typed slice to []interface{} at the source (in createMapInterfaceForHWInfo), which is consistent with how the other CIM types are handled. This way parseCIMResponse doesn't need to change at all.

internal\usecase\devices\wsman\message.go: line number 534

"responses": interfaceSlice(hwResults.PhysicalMemoryResult.Body.PullResponse.MemoryItems),

Add the following function to the same file

func interfaceSlice(items []physical.PhysicalMemory) []interface{} {
    result := make([]interface{}, len(items))
    for i, item := range items {
      result[i] = item
    }

	return result
}

I have tested this fix on AMT 19 and Memory Summary loads correctly. Please verify on your end as well.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes the Hardware Information “Memory Summary shows no data” regression by making parseCIMResponse correctly handle responses values that come back as typed slices (e.g., []physical.PhysicalMemory) rather than only []interface{}.

Changes:

  • Update parseCIMResponse to convert typed slices in info["responses"] into []interface{} via reflection.
  • Add a focused private-unit test suite for parseCIMResponse, covering nil/invalid inputs and multiple responses/status shapes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/usecase/devices/info.go Converts typed-slice responses values to []interface{} so memory items populate correctly.
internal/usecase/devices/info_private_test.go Adds comprehensive unit tests for parseCIMResponse covering typed slice handling and edge cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@amarnath-ac
Copy link
Contributor Author

@amarnath-ac Since we know the type of data which is []physical.PhysicalMemory, it's not necessary to use reflect. Reflect is generally used when the type is truly unknown at compile time. Instead, convert the typed slice to []interface{} at the source (in createMapInterfaceForHWInfo), which is consistent with how the other CIM types are handled. This way parseCIMResponse doesn't need to change at all.

internal\usecase\devices\wsman\message.go: line number 534

"responses": interfaceSlice(hwResults.PhysicalMemoryResult.Body.PullResponse.MemoryItems),

Add the following function to the same file

func interfaceSlice(items []physical.PhysicalMemory) []interface{} {
    result := make([]interface{}, len(items))
    for i, item := range items {
      result[i] = item
    }

	return result
}

I have tested this fix on AMT 19 and Memory Summary loads correctly. Please verify on your end as well.

Thanks for feedback, will update as suggested.

Convert PhysicalMemory slice to interface slice at source.
@amarnath-ac
Copy link
Contributor Author

@amarnath-ac Since we know the type of data which is []physical.PhysicalMemory, it's not necessary to use reflect. Reflect is generally used when the type is truly unknown at compile time. Instead, convert the typed slice to []interface{} at the source (in createMapInterfaceForHWInfo), which is consistent with how the other CIM types are handled. This way parseCIMResponse doesn't need to change at all.
internal\usecase\devices\wsman\message.go: line number 534
"responses": interfaceSlice(hwResults.PhysicalMemoryResult.Body.PullResponse.MemoryItems),
Add the following function to the same file

func interfaceSlice(items []physical.PhysicalMemory) []interface{} {
    result := make([]interface{}, len(items))
    for i, item := range items {
      result[i] = item
    }

	return result
}

I have tested this fix on AMT 19 and Memory Summary loads correctly. Please verify on your end as well.

Thanks for feedback, will update as suggested.

@madhavilosetty-intel , Updated code

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +539 to +551
// interfaceSlice converts []physical.PhysicalMemory to []interface{} for consistent handling.
func interfaceSlice(items []physical.PhysicalMemory) []interface{} {
if items == nil {
return []interface{}{}
}

result := make([]interface{}, len(items))

for i := range items {
result[i] = items[i]
}

return result
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

interfaceSlice is named as if it were a generic helper, but it only accepts []physical.PhysicalMemory. Consider renaming it to reflect the specific type/purpose (or making it generic if that’s the intent) to avoid confusion for future callers.

Copilot uses AI. Check for mistakes.
Comment on lines +11 to +81
func TestInterfaceSlice(t *testing.T) {
t.Parallel()

tests := []struct {
name string
input []physical.PhysicalMemory
expected []interface{}
}{
{
name: "empty slice",
input: []physical.PhysicalMemory{},
expected: []interface{}{},
},
{
name: "single item",
input: []physical.PhysicalMemory{
{
Capacity: 17179869184, // 16 GB
Manufacturer: "Kingston",
PartNumber: "9905700-101.A00G",
},
},
expected: []interface{}{
physical.PhysicalMemory{
Capacity: 17179869184,
Manufacturer: "Kingston",
PartNumber: "9905700-101.A00G",
},
},
},
{
name: "multiple items",
input: []physical.PhysicalMemory{
{
Capacity: 8589934592, // 8 GB
Manufacturer: "Samsung",
PartNumber: "M471A1K43CB1-CRC",
},
{
Capacity: 8589934592, // 8 GB
Manufacturer: "Samsung",
PartNumber: "M471A1K43CB1-CRC",
},
},
expected: []interface{}{
physical.PhysicalMemory{
Capacity: 8589934592,
Manufacturer: "Samsung",
PartNumber: "M471A1K43CB1-CRC",
},
physical.PhysicalMemory{
Capacity: 8589934592,
Manufacturer: "Samsung",
PartNumber: "M471A1K43CB1-CRC",
},
},
},
{
name: "nil slice",
input: nil,
expected: []interface{}{},
},
}

for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

result := interfaceSlice(tc.input)
require.Equal(t, tc.expected, result)
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

PR description mentions updating/testing parseCIMResponse (and using reflection for typed slices), but this change instead introduces interfaceSlice in wsman/message.go and tests that helper. Please update the PR description (or include the missing parseCIMResponse changes/tests) so the intent and scope match what’s actually being merged.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants