import { describe, it, expect } from "vitest"; import { parseProbe, proposeCorrections, buildRecommendations } from "./machineProbe.js"; const PROXMOX = [ "===SU:PROBE_OS===", 'PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"', "ID=debian", 'VERSION_ID="12"', "VERSION_CODENAME=bookworm", "===SU:PROBE_ARCH===", "x86_64", "amd64", "===SU:PROBE_VIRT===", "none", "===SU:PROBE_PROXMOX===", "PROXMOX=1", "===SU:PROBE_RPI===", "RPI=0", "===SU:PROBE_GPU===", "01:00.0 VGA compatible controller: Matrox MGA G200eW", "===SU:PROBE_NET===", "vmbr0 10.0.3.202/24", "===SU:EXIT=0===", ].join("\n"); const RPI = [ "===SU:PROBE_OS===", "ID=debian", "VERSION_CODENAME=bookworm", "===SU:PROBE_ARCH===", "aarch64", "arm64", "===SU:PROBE_VIRT===", "none", "===SU:PROBE_PROXMOX===", "PROXMOX=0", "===SU:PROBE_RPI===", "RPI=1", "===SU:PROBE_GPU===", "no-lspci", "===SU:PROBE_NET===", "eth0 192.168.1.50/24", "===SU:EXIT=0===", ].join("\n"); const KVM_VM = [ "===SU:PROBE_OS===", "ID=ubuntu", 'VERSION_ID="24.04"', "VERSION_CODENAME=noble", "===SU:PROBE_ARCH===", "x86_64", "amd64", "===SU:PROBE_VIRT===", "kvm", "===SU:PROBE_PROXMOX===", "PROXMOX=0", "===SU:PROBE_RPI===", "RPI=0", "===SU:PROBE_GPU===", "no-lspci", "===SU:PROBE_NET===", "ens18 10.0.3.5/24", "===SU:EXIT=0===", ].join("\n"); describe("parseProbe", () => { it("extrait os-release, arch, virt et drapeaux", () => { const p = parseProbe(PROXMOX); expect(p.osId).toBe("debian"); expect(p.osVersion).toBe("12"); expect(p.osCodename).toBe("bookworm"); expect(p.arch).toBe("x86_64"); expect(p.dpkgArch).toBe("amd64"); expect(p.virt).toBe("none"); expect(p.isProxmox).toBe(true); expect(p.isRpi).toBe(false); expect(p.gpus).toHaveLength(1); expect(p.net).toEqual([{ iface: "vmbr0", addr: "10.0.3.202/24" }]); }); }); describe("proposeCorrections", () => { it("Proxmox → os_family proxmox + machine_kind proxmox_host", () => { const c = proposeCorrections(parseProbe(PROXMOX)); expect(c.osFamily).toBe("proxmox"); expect(c.machineKind).toBe("proxmox_host"); expect(c.virtualization).toBe("none"); }); it("Raspberry Pi → raspbian + raspberry_pi", () => { const c = proposeCorrections(parseProbe(RPI)); expect(c.osFamily).toBe("raspbian"); expect(c.machineKind).toBe("raspberry_pi"); }); it("VM KVM Ubuntu → ubuntu + vm + virtualization kvm", () => { const c = proposeCorrections(parseProbe(KVM_VM)); expect(c.osFamily).toBe("ubuntu"); expect(c.machineKind).toBe("vm"); expect(c.virtualization).toBe("kvm"); }); }); describe("sonde enrichie (cpu/mem/disk + recommandations)", () => { const ENRICHED = [ "===SU:PROBE_OS===", "ID=debian", "===SU:PROBE_ARCH===", "x86_64", "amd64", "===SU:PROBE_VIRT===", "kvm", "===SU:PROBE_PROXMOX===", "PROXMOX=0", "===SU:PROBE_RPI===", "RPI=0", "===SU:PROBE_GPU===", "no-lspci", "===SU:PROBE_NET===", "ens18 10.0.0.8/22", "===SU:PROBE_CPU===", "MODEL=Intel(R) Xeon(R) CPU E5-2670", "4", "===SU:PROBE_MEM===", "MemTotal: 4194304 kB", "===SU:PROBE_DISK===", "DISK\tsda\t34359738368", "DISK\tsdb\t1073741824000", "===SU:EXIT=0===", ].join("\n"); it("extrait cpuModel/cores, mémoire et disques", () => { const p = parseProbe(ENRICHED); expect(p.cpuModel).toBe("Intel(R) Xeon(R) CPU E5-2670"); expect(p.cpuCores).toBe(4); expect(p.memoryBytes).toBe(4194304 * 1024); expect(p.disks).toHaveLength(2); expect(p.disks[0]).toEqual({ name: "sda", sizeBytes: 34359738368 }); }); it("recommande vm_guest_tools sur KVM", () => { const recs = buildRecommendations(parseProbe(ENRICHED)); expect(recs.some((r) => r.profileId === "vm_guest_tools")).toBe(true); }); });