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: -accel whpx: warning: WHPX: Hyper-V refuses the TSC deadline timer's register, hr=c0350005: the guest is offered no TSC deadline timer`) if msg != "" { t.Fatalf("expected benign TSC deadline warning to be ignored, got %q", msg) } k, msg = parseQemuMilestone(i18n.ZhCN, `reims-vgpu WARN reims_vgpu_graphics: the control completion ring is full: a message of type 0x103 found no room, and ring 0's answers and events wait for the guest to take more`) if k != "qemu:ring-full" || !strings.Contains(msg, "自动恢复") { t.Fatalf("expected friendly ring-full hint (zh-CN), got k=%q msg=%q", k, msg) } k, msg = parseQemuMilestone(i18n.EnUS, `reims-vgpu WARN reims_vgpu_graphics: the control completion ring is full: a message of type 0x103 found no room, and ring 0's answers and events wait for the guest to take more`) if k != "qemu:ring-full" || !strings.Contains(msg, "recover automatically") { t.Fatalf("expected friendly ring-full hint (en-US), got k=%q msg=%q", k, msg) } k, msg = parseQemuMilestone(i18n.ZhCN, `reims-vgpu WARN reims_vgpu_graphics: the VBLANK of refresh 1496 found the control completion ring full and was dropped: the next carries the count`) if msg != "" { t.Fatalf("expected follow-up VBLANK drop line 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) } }