import { describe, it, expect } from "vitest"; import { parseProbe, proposeCorrections } 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"); }); });