Files
Reims-Go/internal/app/install_guide_test.go
T
Nwflower 8969c53644 Merge pull request #3 from yxc0915/feat/vm-window-install-guide
Integrate the VM-window macOS installation and recovery guide from #3
as an optional built-in plugin (builtin.install-guide):
- Register builtin.install-guide providing ui.install-guide with
  zero-residue lifecycle disposal and live toggle support
- Keep VMPage's in-page recovery guide as automatic fallback when
  the plugin is disabled
- Preserve VM-window guide UX, DPI layout, and restart resume from #3
2026-11-29 10:39:02 -07:00

100 lines
3.0 KiB
Go

package app
import (
"context"
"testing"
"github.com/Nwflower/reims-go/internal/config"
"github.com/Nwflower/reims-go/internal/driver/reims"
"github.com/Nwflower/reims-go/internal/i18n"
"github.com/Nwflower/reims-go/internal/installguide"
"github.com/Nwflower/reims-go/internal/plugin"
"github.com/Nwflower/reims-go/internal/plugin/builtin"
"github.com/Nwflower/reims-go/internal/vmstart"
)
func TestInstallGuideFollowsBootMedia(t *testing.T) {
d := reims.VMDetail{Directory: t.TempDir()}
for _, test := range []struct {
marker, path string
want installguide.Kind
show bool
}{
{"", "", installguide.BuiltIn, false}, {"want", "", installguide.BuiltIn, false},
{"on", "", installguide.BuiltIn, true}, {"restore", "", installguide.BuiltIn, false},
{"", "BaseSystem.img", installguide.Online, true}, {"", "offline-installer-tahoe.img", installguide.Offline, true},
} {
vmstart.WriteRecoveryMarker(d.Directory, test.marker)
d.HasInstaller, d.InstallerPath = test.path != "", test.path
if kind, show := installGuideKind(d); kind != test.want || show != test.show {
t.Errorf("%+v: got (%d,%t)", test, kind, show)
}
}
}
func TestInstallGuideFollowsPluginSwitch(t *testing.T) {
dataRoot := t.TempDir()
mgr, err := plugin.NewManager(plugin.ManagerOptions{DataRoot: dataRoot, HostVersion: "0.0.0"})
if err != nil {
t.Fatal(err)
}
defer mgr.Close()
cfg := config.Default()
cfg.DataRoot = dataRoot
cfg.Locale = i18n.ZhCN
a := &App{
cfg: cfg,
pluginMgr: mgr,
themeMode: installguide.ThemeDark,
pollWake: make(chan struct{}, 1),
}
if loc, th := a.guidePreferences(); loc != i18n.ZhCN || th != installguide.ThemeDark {
t.Fatalf("guidePreferences = (%q, %q)", loc, th)
}
cb := builtin.HostCallbacks{
GetConfig: func() config.Config { return *cfg },
SyncInstallGuides: a.wakePoll,
}
if err := builtin.RegisterAll(mgr.Registry(), cb, func(id string, def bool) bool {
return id == builtin.IDInstallGuide && def
}); err != nil {
t.Fatal(err)
}
mgr.Registry().Reconcile(context.Background())
if !a.installGuideEnabled() {
t.Fatal("expected install guide enabled when plugin is active")
}
// Drain initial SyncInstallGuides wakeup.
select {
case <-a.pollWake:
default:
t.Fatal("expected initial SyncInstallGuides to wake poll")
}
// Disabling the plugin removes the service and closes the guide manager.
if err := mgr.Registry().SetDesired(context.Background(), builtin.IDInstallGuide, false); err != nil {
t.Fatal(err)
}
if a.installGuideEnabled() || a.getInstallGuideManager() != nil {
t.Fatal("expected install guide disabled after plugin toggle off")
}
// Re-enabling restores the service and wakes pollVMs to attach running VMs.
if err := mgr.Registry().SetDesired(context.Background(), builtin.IDInstallGuide, true); err != nil {
t.Fatal(err)
}
if !a.installGuideEnabled() {
t.Fatal("expected install guide enabled after plugin toggle on")
}
select {
case <-a.pollWake:
default:
t.Fatal("expected re-enabling builtin.install-guide to wake poll")
}
}