package app import ( "context" "testing" "github.com/Nwflower/reims-go/internal/config" "github.com/Nwflower/reims-go/internal/i18n" "github.com/Nwflower/reims-go/internal/macos/guest" "github.com/Nwflower/reims-go/internal/macos/installguide" "github.com/Nwflower/reims-go/internal/macos/reims" "github.com/Nwflower/reims-go/internal/macos/startprep" "github.com/Nwflower/reims-go/internal/plugin" "github.com/Nwflower/reims-go/internal/plugin/builtin" ) 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}, } { startprep.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: "dark", 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, nil); err != nil { t.Fatal(err) } if err := guest.Register(mgr.Registry(), cb, mgr.DesiredFor); 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(), guest.ID, 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(), guest.ID, 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") } }