Files
NwflowerandClaude Opus 5.5 565577589a refactor: give each VM action one window binding
Every VM action had two bindings: one by name and one by driver and name.
The window used only the second, so the first is gone and the WithDriver
suffix with it. Unused bindings and frontend exports are removed too.

Tests now reject bindings the window never calls, stale generated
bindings and unused frontend exports. TypeScript rejects unused locals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 21:16:28 -07:00

71 lines
2.0 KiB
Go

package app
import (
"context"
"encoding/binary"
"os"
"path/filepath"
"testing"
"time"
"github.com/Nwflower/reims-go/internal/config"
"github.com/Nwflower/reims-go/internal/driver"
vmlifecycle "github.com/Nwflower/reims-go/internal/lifecycle"
"github.com/Nwflower/reims-go/internal/plugin"
)
func TestGetDefenderExclusionCommand(t *testing.T) {
a := &App{cfg: &config.Config{DataRoot: `D:\Rei's VMs`}}
const want = `Add-MpPreference -ExclusionPath 'D:\Rei''s VMs' -ExclusionProcess 'qemu-system-x86_64.exe'`
if got := a.GetDefenderExclusionCommand(); got != want {
t.Fatalf("GetDefenderExclusionCommand = %q, want %q", got, want)
}
}
func TestVMStatsDiskHeaderMeta(t *testing.T) {
cfg := &config.Config{DataRoot: t.TempDir()}
disk := filepath.Join(cfg.DataRoot, "disk.qcow2")
hdr := make([]byte, 104)
copy(hdr, "QFI\xfb")
binary.BigEndian.PutUint32(hdr[4:8], 3)
binary.BigEndian.PutUint32(hdr[60:64], 2)
binary.BigEndian.PutUint64(hdr[72:80], 0x10)
if err := os.WriteFile(disk, hdr, 0o644); err != nil {
t.Fatal(err)
}
drv := &appSecondDriver{
id: driver.BuiltinReimsMacOSDriverID,
vms: []driver.VMInfo{{
Name: "test",
DriverID: driver.BuiltinReimsMacOSDriverID,
Directory: cfg.DataRoot,
State: "stopped",
DiskPath: disk,
}},
}
reg := plugin.NewRegistry(nil)
if err := reg.Register(plugin.PluginDef{
Manifest: plugin.Manifest{ID: "test.macos", Version: "1.0.0"},
Source: plugin.SourceBuiltin,
Desired: true,
Activate: func(_ context.Context, sc *plugin.Scope) error {
reg.RegisterGuestDriver(sc, drv.id, drv)
return nil
},
}); err != nil {
t.Fatal(err)
}
reg.Reconcile(context.Background())
router := driver.NewRouter(reg, nil)
a := &App{
cfg: cfg,
lastVMsAt: time.Now(),
lifecycleSvc: vmlifecycle.New(reg, router, nil),
}
stats, err := a.GetVMStats("", "test")
if err != nil || !stats.DiskExtendedL2 || stats.DiskSnapshotCount != 2 {
t.Fatalf("GetVMStats = %+v, %v", stats, err)
}
}