Files
Reims-Go/internal/qmp/watcher_test.go
T
NwflowerandClaude Opus 5.5 2f43182f0c feat: offline installer downloads, task progress events, Win10 cold reboot
Offline installers (roadmap M1.3):
- internal/installer drives `reims-util --json offline-installer` and parses
  its JSON event stream (upstream reims-vgpu 3731afd, reims_util.rs:423-509)
- downloads hold installers/.lock like reims-ctl, so the two never write the
  same file; checked against the real reims-ctl (TestLockExcludesReimsCtl)
- pause = stop the process, rerun resumes; deletes go through
  `reims-ctl downloads delete`, which refuses files in use or downloading
- CLI: reims-go installer list | download | cached | delete
- Wails bindings: ListOfflineReleases, DownloadInstaller, ListInstallers,
  DeleteInstaller

Task events (ui-redesign B1):
- tasks.go tracks long-running work and emits "reims:task" (throttled to
  200 ms per task); VM creation turns reims-ctl's progress lines into task
  progress and logs each step once
- the status bar shows the current task with a progress bar, details in a
  tooltip and a pause button; the frontend regex merging is removed

Win10 cold reboot workaround:
- host probes whether WinHvPlatform.dll lacks WHvResetPartition (Win10 19045)
- internal/qmp watches a dedicated QMP channel for guest resets; with
  -no-reboot the app restarts the VM in a fresh partition
- architecture.md documents download routing and the workaround

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 03:35:03 -07:00

75 lines
2.1 KiB
Go

package qmp
import (
"bufio"
"context"
"net"
"testing"
"time"
)
func TestMergeWin10RebootArgs(t *testing.T) {
got := MergeWin10RebootArgs("", 44551)
want := "-no-reboot -qmp tcp:127.0.0.1:44551,server=on,wait=off"
if got != want {
t.Fatalf("empty merge: got %q, want %q", got, want)
}
got = MergeWin10RebootArgs("-boot menu=on "+got+" -d guest_errors", 44552)
want = "-boot menu=on -d guest_errors -no-reboot -qmp tcp:127.0.0.1:44552,server=on,wait=off"
if got != want {
t.Fatalf("idempotent merge: got %q, want %q", got, want)
}
// reims-ctl show wraps extra-args values containing colons/commas in single quotes.
got = MergeWin10RebootArgs("-qmp 'tcp:127.0.0.1:58557,server=on,wait=off' -no-reboot", 44553)
want = "-no-reboot -qmp tcp:127.0.0.1:44553,server=on,wait=off"
if got != want {
t.Fatalf("quoted show merge: got %q, want %q", got, want)
}
}
func runMockQMP(t *testing.T, eventJSON string) (bool, error) {
t.Helper()
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
defer ln.Close()
go func() {
conn, err := ln.Accept()
if err != nil {
return
}
defer conn.Close()
_, _ = conn.Write([]byte("{\"QMP\":{\"version\":{\"qemu\":{\"major\":11}}}}\r\n"))
sc := bufio.NewScanner(conn)
if sc.Scan() {
_, _ = conn.Write([]byte("{\"return\":{}}\r\n"))
}
_, _ = conn.Write([]byte(eventJSON + "\r\n"))
}()
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
return WatchForGuestReset(ctx, ln.Addr().String())
}
func TestWatchForGuestReset(t *testing.T) {
reset, err := runMockQMP(t, `{"event":"SHUTDOWN","data":{"guest":true,"reason":"guest-reset"}}`)
if err != nil || !reset {
t.Fatalf("guest-reset: got reset=%v err=%v, want true nil", reset, err)
}
reset, err = runMockQMP(t, `{"event":"SHUTDOWN","data":{"guest":true,"reason":"guest-shutdown"}}`)
if err != nil || reset {
t.Fatalf("guest-shutdown: got reset=%v err=%v, want false nil", reset, err)
}
reset, err = runMockQMP(t, `{"event":"SHUTDOWN","data":{"guest":false,"reason":"host-ui"}}`)
if err != nil || reset {
t.Fatalf("host-ui: got reset=%v err=%v, want false nil", reset, err)
}
}