Events to the frontend go through App.emit, and a test keeps their names in step with wails.ts. QEMU argument splitting, hidden console processes, the macOS release record, the running check and a few smaller helpers now exist once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
117 lines
4.6 KiB
Go
117 lines
4.6 KiB
Go
package app
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/Nwflower/reims-go/internal/macos/guest"
|
|
"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/qmp"
|
|
)
|
|
|
|
func TestLegacyExtraArgsAdoptedWithoutDuplication(t *testing.T) {
|
|
// Simulate an existing pre-plugin VM whose vm.toml already contains:
|
|
// user arg + REIMSTOOLS + REIMSHELP + Win10 managed QMP args, with NO ledger file yet.
|
|
legacy := "-cpu host"
|
|
legacy = reims.MergeGuestToolsArgs(legacy, `D:\Data\cache\tools.img`)
|
|
legacy = reims.MergeOfflineHelperArgs(legacy, `D:\Data\cache\reimshelp.img`)
|
|
legacy = qmp.MergeWin10RebootUnixArgs(legacy, `D:\Data\vms\mac\reims-go-reboot.sock`)
|
|
|
|
ledger := &plugin.ArgLedger{Version: 1, Owners: map[string][]plugin.ArgFragment{}}
|
|
active := map[string]bool{
|
|
builtin.IDGuestTools: true,
|
|
guest.ID: true,
|
|
}
|
|
intents := []plugin.StartIntent{
|
|
{
|
|
PluginID: builtin.IDGuestTools,
|
|
Args: []plugin.ArgFragment{{
|
|
PluginID: builtin.IDGuestTools, Key: "reimstools", Builtin: true, Priority: 80,
|
|
Tokens: qmp.SplitArgs(reims.MergeGuestToolsArgs("", `D:\Data\cache\tools.img`)),
|
|
}},
|
|
},
|
|
{
|
|
PluginID: guest.ID,
|
|
Args: []plugin.ArgFragment{{
|
|
PluginID: guest.ID, Key: "reimshelp", Builtin: true, Priority: 85,
|
|
Tokens: qmp.SplitArgs(reims.MergeOfflineHelperArgs("", `D:\Data\cache\reimshelp.img`)),
|
|
}, {
|
|
PluginID: guest.ID, Key: "win10-cold-reboot", Builtin: true, Priority: 95,
|
|
Tokens: qmp.SplitArgs(qmp.MergeWin10RebootUnixArgs("", `D:\Data\vms\mac\reims-go-reboot.sock`)),
|
|
}},
|
|
},
|
|
}
|
|
|
|
base := stripLegacyManagedExtraArgs(legacy)
|
|
res := plugin.ReconcileStartIntents(base, ledger, active, intents)
|
|
|
|
if !strings.Contains(res.ExtraArgs, "-cpu host") {
|
|
t.Fatalf("user arg lost: %s", res.ExtraArgs)
|
|
}
|
|
for _, needle := range []string{"id=reimstools,", "id=reimstools-dev,", "id=reimshelp,", "id=reimshelp-dev,", "-no-reboot", "-qmp"} {
|
|
if got := strings.Count(res.ExtraArgs, needle); got != 1 {
|
|
t.Errorf("expected exactly 1 occurrence of %q, got %d in: %s", needle, got, res.ExtraArgs)
|
|
}
|
|
}
|
|
|
|
// Simulate detaching Guest Tools & ejecting offline installer on next start.
|
|
nextIntents := []plugin.StartIntent{
|
|
{PluginID: builtin.IDGuestTools, ClearKeys: []string{"reimstools"}},
|
|
{PluginID: guest.ID, ClearKeys: []string{"reimshelp", "win10-cold-reboot"}},
|
|
}
|
|
base2 := stripLegacyManagedExtraArgs(res.ExtraArgs)
|
|
res2 := plugin.ReconcileStartIntents(base2, ledger, active, nextIntents)
|
|
if res2.ExtraArgs != "-cpu host" {
|
|
t.Fatalf("expected only user arg after clearing managed keys, got: %q", res2.ExtraArgs)
|
|
}
|
|
}
|
|
|
|
func TestStripLegacyPreservesUserNoReboot(t *testing.T) {
|
|
// A user hand-wrote `-no-reboot` without any reims-go managed QMP target.
|
|
got := stripLegacyManagedExtraArgs("-cpu host -no-reboot")
|
|
if got != "-cpu host -no-reboot" {
|
|
t.Fatalf("user -no-reboot was stripped unexpectedly: %q", got)
|
|
}
|
|
}
|
|
|
|
// A VM started before the builtins were merged has kernel-irqchip=off owned
|
|
// by the retired whpx-fallback plugin. The core's WHPX step leaves an arg that
|
|
// is already there alone, so without handing the fragment over it would be
|
|
// stripped as belonging to a gone plugin and the next start could crash.
|
|
func TestPreMergeLedgerFragmentsCarriedIntoCore(t *testing.T) {
|
|
irq := plugin.ArgFragment{
|
|
PluginID: builtin.IDCore, Key: "kernel-irqchip", Builtin: true, Priority: 90,
|
|
Tokens: []string{"-machine", "kernel-irqchip=off"},
|
|
}
|
|
extra := "-cpu host -machine kernel-irqchip=off"
|
|
active := map[string]bool{guest.ID: true}
|
|
intents := []plugin.StartIntent{{PluginID: guest.ID}}
|
|
newLedger := func() *plugin.ArgLedger {
|
|
return &plugin.ArgLedger{Version: 1, Owners: map[string][]plugin.ArgFragment{
|
|
builtin.IDCore: {irq},
|
|
}}
|
|
}
|
|
|
|
unmigrated := plugin.ReconcileStartIntents(extra, newLedger(), active, intents)
|
|
if strings.Contains(unmigrated.ExtraArgs, "kernel-irqchip") {
|
|
t.Fatalf("test premise: an unmigrated ledger should drop the fragment, got %q", unmigrated.ExtraArgs)
|
|
}
|
|
|
|
ledger := newLedger()
|
|
if !guest.MigrateLedger(ledger) {
|
|
t.Fatal("MigrateLedger reported no change for a retired owner")
|
|
}
|
|
res := plugin.ReconcileStartIntents(extra, ledger, active, intents)
|
|
if got := strings.Count(res.ExtraArgs, "kernel-irqchip=off"); got != 1 {
|
|
t.Fatalf("want kernel-irqchip=off carried exactly once, got %d in %q", got, res.ExtraArgs)
|
|
}
|
|
if !strings.Contains(res.ExtraArgs, "-cpu host") {
|
|
t.Fatalf("user arg lost: %q", res.ExtraArgs)
|
|
}
|
|
if guest.MigrateLedger(ledger) {
|
|
t.Fatal("MigrateLedger should be a no-op once migrated")
|
|
}
|
|
}
|