Files
Vetting/agent/probes/inventory_test.go
T
josh 8acef92a60
CI / Lint + build + test (push) Successful in 1m35s
Release / release (push) Successful in 9m34s
feat(inventory): deep hardware capture + per-probe substeps + verbose logs
Extend Inventory stage from a one-liner summary to a per-probe substep
emitter with ~20-30 narrative log lines per run.

- spec: per-DIMM memory (slot/size/speed/manufacturer/part_number),
  richer CPU (vendor/stepping/physical_cores/flags), disk
  model/transport/rotational, NIC driver/pci_addr, GPU vram/pci/driver,
  new System/Baseboard/PSU/OS top-level sections. All fields omitempty
  so existing expected-spec YAML and artifacts stay compatible.
- spec.Diff: new diffDIMMs/diffSystem/diffBaseboard/diffPSU/diffOS
  helpers; extended diffDisks/diffNICs/diffGPUs for new fields. GPU
  diff gains PCIAddr-pinned matching alongside count-by-model.
- agent/probes/inventory: CPU (/proc/cpuinfo extended), Memory
  (dmidecode -t 17 multi-block), Disks (+model/transport/rotational),
  NICs (+driver/pci from sysfs), GPUs (VRAM from lspci -vv),
  new System/Baseboard (dmidecode -t system/baseboard), PSU
  (dmidecode -t 39), OS (/proc/sys/kernel/osrelease + /etc/os-release).
  All probes accept a Logger and emit per-finding info/warn lines.
- agent/probes/firmware: parseDmidecodeAllSections for multi-block
  fixtures (memory / PSU).
- agent/runner: Inventory case becomes 9 substep rows (CPU / Memory /
  Disks / NICs / GPUs / System / Baseboard / PSU / OS) with per-probe
  start/complete timestamps.
- report: new Inventory HTML section between Stages and Firmware;
  resolveReporting loads the inventory.json artifact.
- agent/tests/fakes/dmidecode: dispatches on -t flag to serve bios /
  memory / system / baseboard / 39 fixtures for unit tests.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-19 22:21:17 -04:00

172 lines
4.1 KiB
Go

package probes
import (
"strings"
"testing"
"vetting/internal/spec"
)
func TestParseCPUInfoInto(t *testing.T) {
sample := `processor : 0
vendor_id : GenuineIntel
model name : Intel(R) N95
stepping : 3
cpu cores : 4
flags : fpu vme de pse tsc msr aes sse4_2 vmx
processor : 1
vendor_id : GenuineIntel
model name : Intel(R) N95
`
var c spec.CPUSpec
parseCPUInfoInto(strings.NewReader(sample), &c)
if c.Model != "Intel(R) N95" {
t.Fatalf("model: got %q", c.Model)
}
if c.Vendor != "GenuineIntel" {
t.Fatalf("vendor: got %q", c.Vendor)
}
if c.Stepping != "3" {
t.Fatalf("stepping: got %q", c.Stepping)
}
if c.PhysicalCores != 4 {
t.Fatalf("physical cores: got %d", c.PhysicalCores)
}
// Only vmx, aes, sse4_2 should survive the allow-list filter.
if len(c.Flags) != 3 {
t.Fatalf("flags count: got %v", c.Flags)
}
}
func TestParseOSRelease(t *testing.T) {
in := `PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
VERSION_ID="12"
NAME=Debian
`
dist, ver := parseOSRelease(in)
if dist != "Debian GNU/Linux 12 (bookworm)" {
t.Fatalf("distribution: got %q", dist)
}
if ver != "12" {
t.Fatalf("version: got %q", ver)
}
}
func TestParseDmidecodeSize(t *testing.T) {
cases := []struct {
in string
want int
}{
{"16 GB", 16},
{"32 GiB", 32},
{"8192 MB", 8},
{"No Module Installed", 0},
{"garbage", 0},
}
for _, c := range cases {
if got := parseDmidecodeSize(c.in); got != c.want {
t.Errorf("parseDmidecodeSize(%q) = %d, want %d", c.in, got, c.want)
}
}
}
func TestParseMTS(t *testing.T) {
if n := parseMTS("3200 MT/s"); n != 3200 {
t.Errorf("parseMTS MT/s: got %d", n)
}
if n := parseMTS("2400 MHz"); n != 2400 {
t.Errorf("parseMTS MHz: got %d", n)
}
if n := parseMTS("Unknown"); n != 0 {
t.Errorf("parseMTS unknown: got %d", n)
}
}
func TestCleanDmidecodeValue(t *testing.T) {
cases := map[string]string{
"Micron": "Micron",
"Not Specified": "",
" Unknown ": "",
"To Be Filled By O.E.M.": "",
"": "",
}
for in, want := range cases {
if got := cleanDmidecodeValue(in); got != want {
t.Errorf("cleanDmidecodeValue(%q) = %q, want %q", in, got, want)
}
}
}
func TestParseDIMMs(t *testing.T) {
// Two populated + two empty slots. Verifies the multi-section parser
// produces the expected count and the empty-slot detection fires on
// "No Module Installed".
sample := `Handle 0x0032, DMI type 17, 84 bytes
Memory Device
Size: 16 GB
Locator: DIMM_A1
Manufacturer: Micron
Part Number: 8ATF2G64AZ-3G2E1
Configured Memory Speed: 3200 MT/s
Handle 0x0033, DMI type 17, 84 bytes
Memory Device
Size: No Module Installed
Locator: DIMM_A2
Manufacturer: Not Specified
Handle 0x0034, DMI type 17, 84 bytes
Memory Device
Size: 16 GB
Locator: DIMM_B1
Manufacturer: Micron
Part Number: 8ATF2G64AZ-3G2E1
Speed: 3200 MT/s
Handle 0x0035, DMI type 17, 84 bytes
Memory Device
Size: No Module Installed
Locator: DIMM_B2
`
dimms := parseDIMMs(strings.NewReader(sample), Logger{})
if len(dimms) != 4 {
t.Fatalf("expected 4 DIMM entries, got %d: %+v", len(dimms), dimms)
}
populated := 0
for _, d := range dimms {
if d.Populated {
populated++
}
}
if populated != 2 {
t.Fatalf("expected 2 populated, got %d", populated)
}
if dimms[0].Slot != "DIMM_A1" || dimms[0].SizeGB != 16 || dimms[0].SpeedMTS != 3200 {
t.Fatalf("DIMM_A1 mismatch: %+v", dimms[0])
}
if dimms[0].PartNumber != "8ATF2G64AZ-3G2E1" {
t.Fatalf("DIMM_A1 part number mismatch: %q", dimms[0].PartNumber)
}
if dimms[1].Populated || dimms[1].Slot != "DIMM_A2" {
t.Fatalf("DIMM_A2 should be empty: %+v", dimms[1])
}
}
func TestParseLspciVerbose(t *testing.T) {
sample := `01:00.0 VGA compatible controller: NVIDIA Corporation
Subsystem: ASUSTeK
Kernel driver in use: nvidia
Memory at f6000000 (32-bit, non-prefetchable) [size=16M]
Memory at c0000000 (64-bit, prefetchable) [size=8G]
Memory at d0000000 (64-bit, prefetchable) [size=32M]
`
vram, driver := parseLspciVerbose(sample)
if vram != 8 {
t.Errorf("VRAM: got %d, want 8", vram)
}
if driver != "nvidia" {
t.Errorf("driver: got %q", driver)
}
}