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>
100 lines
3.1 KiB
Go
100 lines
3.1 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/Nwflower/reims-go/internal/installer"
|
|
)
|
|
|
|
func newTestTasks(t *testing.T) *[]Task {
|
|
t.Helper()
|
|
sent := &[]Task{}
|
|
old := tasks
|
|
tasks = &taskManager{tasks: map[string]*taskEntry{}, emit: func(x Task) { *sent = append(*sent, x) }}
|
|
t.Cleanup(func() { tasks = old })
|
|
return sent
|
|
}
|
|
|
|
func TestTaskProgressIsThrottledButStepsAndEndsAlwaysGoOut(t *testing.T) {
|
|
sent := newTestTasks(t)
|
|
id := tasks.start("installer-download", "26.7.1", "", func() {})
|
|
tasks.update(id, installer.Update{Kind: installer.KindStep, Message: "downloading", Percent: -1})
|
|
for i := 1; i <= 50; i++ {
|
|
tasks.update(id, installer.Update{Kind: installer.KindProgress, Done: int64(i), Total: 100, Percent: float64(i)})
|
|
}
|
|
tasks.update(id, installer.Update{Kind: installer.KindProgress, Done: 100, Total: 100, Percent: 100})
|
|
tasks.finish(id, "C:/x.img", nil)
|
|
|
|
// start, step, first progress (step unchanged so throttled after), 100%, done.
|
|
if n := len(*sent); n < 4 || n > 6 {
|
|
t.Fatalf("sent %d events: %+v", n, *sent)
|
|
}
|
|
last := (*sent)[len(*sent)-1]
|
|
if last.Status != TaskDone || last.Result != "C:/x.img" || last.Percent != 100 || last.Cancelable {
|
|
t.Fatalf("final = %+v", last)
|
|
}
|
|
if got := tasks.list(); len(got) != 1 || got[0].ID != id {
|
|
t.Fatalf("list = %+v", got)
|
|
}
|
|
tasks.dismiss(id)
|
|
if len(tasks.list()) != 0 {
|
|
t.Fatal("dismissed task still listed")
|
|
}
|
|
}
|
|
|
|
func TestTaskCancelAndFailure(t *testing.T) {
|
|
newTestTasks(t)
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
id := tasks.start("installer-download", "tahoe", "", cancel)
|
|
if err := tasks.cancel(id); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if ctx.Err() == nil {
|
|
t.Fatal("cancel did not reach the context")
|
|
}
|
|
tasks.finish(id, "", fmt.Errorf("reims-util: %w", context.Canceled))
|
|
if got := tasks.list()[0]; got.Status != TaskCanceled {
|
|
t.Fatalf("status = %s", got.Status)
|
|
}
|
|
|
|
id2 := tasks.start("vm-create", "m1", "m1", nil)
|
|
if err := tasks.cancel(id2); err == nil {
|
|
t.Fatal("a create can't be cancelled")
|
|
}
|
|
tasks.finish(id2, "", errors.New("disk full"))
|
|
for _, x := range tasks.list() {
|
|
if x.ID == id2 && (x.Status != TaskFailed || x.Error != "disk full") {
|
|
t.Fatalf("failed task = %+v", x)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCtlTaskWriterRoutesProgressToTheTask(t *testing.T) {
|
|
sent := newTestTasks(t)
|
|
a := &App{} // no Wails context: emitLog is a no-op
|
|
w, finish := a.ctlTaskWriter("vm-create", "macos-tahoe")
|
|
fmt.Fprintln(w, "macos-tahoe: creating the disk")
|
|
for p := 0; p <= 100; p += 5 {
|
|
fmt.Fprintf(w, "macos-tahoe: downloading OpenCore 1.0.8: %d%% of 11 MB\n", p)
|
|
}
|
|
finish(nil)
|
|
|
|
var steps []string
|
|
for _, x := range *sent {
|
|
if len(steps) == 0 || steps[len(steps)-1] != x.Step {
|
|
steps = append(steps, x.Step)
|
|
}
|
|
}
|
|
want := []string{"", "creating the disk", "downloading OpenCore 1.0.8"}
|
|
if fmt.Sprint(steps) != fmt.Sprint(want) {
|
|
t.Fatalf("steps = %q, want %q", steps, want)
|
|
}
|
|
final := (*sent)[len(*sent)-1]
|
|
if final.Status != TaskDone || final.Total != 11_000_000 || final.Percent != 100 || final.Subject != "macos-tahoe" {
|
|
t.Fatalf("final = %+v", final)
|
|
}
|
|
}
|