Files
Reims-Go/internal/app/install_guide_test.go
T
Nwflower 5cbd7bceac feat(plugins): move macOS support into builtin.guest.macos
Declare the reims guest driver statically, merge the install guide into the optional macOS plugin, and keep compatibility settings under the new owner.

Add data layout v2 with atomic state migration, ledger backups, targeted argument ownership moves, and idempotent v1 upgrade coverage. Reduce builtin.core to the default theme.

Add a reverse import ratchet for internal/macos and document the transition. The macOS plugin remains enabled by default during migration; that default and the future privilege/trust rules remain subject to review.
2026-11-30 07:20:15 -07:00

102 lines
3.1 KiB
Go

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/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, 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")
}
}