package main import ( "strings" "testing" "time" "github.com/Nwflower/reims-go/internal/driver/reims" "github.com/Nwflower/reims-go/internal/i18n" ) func TestParseSerialAndQemuMilestones(t *testing.T) { k, msg := parseSerialMilestone(i18n.ZhCN, `BdsDxe: starting Boot0002 "UEFI QEMU HARDDISK"`) if k != "serial:boot" || !strings.Contains(msg, "OpenCore") { t.Fatalf("serial boot = %q, %q", k, msg) } k, msg = parseSerialMilestone(i18n.EnUS, `#[EB|LOG:HANDOFF TO XNU] _`) if k != "serial:xnu" || !strings.Contains(msg, "XNU") { t.Fatalf("serial xnu = %q, %q", k, msg) } k, msg = parseQemuMilestone(i18n.ZhCN, `reims-vgpu INFO reims_vgpu_vulkan::rt_platform: the rt platform's device: NVIDIA GeForce RTX 4070 Ti (10de:2782), driver NVIDIA 610.88; instance extensions`) if k != "qemu:gpu" || !strings.Contains(msg, "RTX 4070 Ti") { t.Fatalf("qemu gpu = %q, %q", k, msg) } k, msg = parseQemuMilestone(i18n.ZhCN, `reims-vgpu: rt-diag allocation sites, rt-presents 71011`) if msg != "" { t.Fatalf("expected rt-diag dump to be ignored, got %q", msg) } k, msg = parseQemuMilestone(i18n.ZhCN, `qemu: WHPX: Unexpected VP exit code 4`) if k != "" || !strings.Contains(msg, "WHPX: Unexpected VP exit code 4") { t.Fatalf("expected WHPX error to pass through, got k=%q msg=%q", k, msg) } } func TestFormatBootHeartbeatAndRedactLogLine(t *testing.T) { hb := formatBootHeartbeat(i18n.ZhCN, 4*time.Minute+30*time.Second, 15*1024*1024*1024, 256*1024*1024, 142.4) if !strings.Contains(hb, "4m30s") || !strings.Contains(hb, "15.00 GB") || !strings.Contains(hb, "+256.0 MB") || !strings.Contains(hb, "142%") { t.Fatalf("unexpected heartbeat: %q", hb) } redacted := reims.RedactLogLine("network user, mac 52:54:00:bc:bc:0d, ssh on 127.0.0.1:2222") if strings.Contains(redacted, "bc:bc:0d") || !strings.Contains(redacted, "mac [redacted]") { t.Fatalf("MAC not redacted: %q", redacted) } redactedSerial := reims.RedactLogLine("OpenCore presents the VM as an iMac20,1, serial C02FDGY9PN5T") if strings.Contains(redactedSerial, "C02FDGY9PN5T") || !strings.Contains(redactedSerial, "serial [redacted]") { t.Fatalf("serial not redacted: %q", redactedSerial) } }