Files
Reims-Go/internal/app/guesttools_toggle_test.go
T
Nwflower 181c616909 feat(plugin,ui): consolidate builtin.core, enforce Guest Tools toggle, and add QQ group entry
- Merge essential builtins (driver, default theme, start prep, host workarounds) into always-on system plugin builtin.core, with state.json and arg-ledger migration plus app-scoped workaround settings honored by both GUI and CLI.
- Ensure disabling builtin.bridge.guest-tools stops the localhost bridge without being restarted by feature callers, fix guesttools.Server Start/Close race, and reflect the disabled state in VMPage and SettingsModal.
- Add QQ community group entry in About settings with Windows tencent:// protocol detection, cached invite redirect resolution, and copy-ID fallback.
- Update docs/plugin-architecture.md, Wails bindings, and i18n strings.
2026-11-29 09:54:51 -07:00

76 lines
2.3 KiB
Go

package app
import (
"context"
"strings"
"testing"
"time"
"github.com/Nwflower/reims-go/internal/config"
"github.com/Nwflower/reims-go/internal/guesttools"
"github.com/Nwflower/reims-go/internal/i18n"
"github.com/Nwflower/reims-go/internal/plugin"
"github.com/Nwflower/reims-go/internal/plugin/builtin"
)
// Switching the Guest Tools plugin off must stop the bridge for real: feature
// calls get an error instead of quietly starting a new server.
func TestGuestToolsBridgeFollowsPluginSwitch(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.EnUS
a := &App{cfg: cfg, pluginMgr: mgr}
err = mgr.Registry().Register(plugin.PluginDef{
Manifest: plugin.Manifest{Schema: 1, ID: builtin.IDGuestTools, Version: "0.0.0"},
Source: plugin.SourceBuiltin,
Trust: plugin.TrustOfficial,
Desired: false,
Activate: func(_ context.Context, sc *plugin.Scope) error {
srv := guesttools.NewTransportServer(nil)
if _, err := srv.Start(-1); err != nil {
return err
}
sc.Provide(builtin.ServiceGuestToolsTransport, "1.0.0", srv)
sc.OnDispose(func() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
_ = srv.Close(ctx)
})
return nil
},
})
if err != nil {
t.Fatal(err)
}
mgr.Registry().Reconcile(context.Background())
if _, _, err := a.ensureGuestToolsBridge(); err == nil || !strings.Contains(err.Error(), "turned off") {
t.Fatalf("plugin off: want a turned-off error, got %v", err)
}
if a.guestTools != nil {
t.Fatal("plugin off: a feature call started the Guest Tools server")
}
if err := mgr.Registry().SetDesired(context.Background(), builtin.IDGuestTools, true); err != nil {
t.Fatal(err)
}
srv, port, err := a.ensureGuestToolsBridge()
if err != nil || srv == nil || port <= 0 {
t.Fatalf("plugin on: want the plugin's server, got srv=%v port=%d err=%v", srv, port, err)
}
if err := mgr.Registry().SetDesired(context.Background(), builtin.IDGuestTools, false); err != nil {
t.Fatal(err)
}
if a.guestToolsEnabled() {
t.Fatal("plugin switched back off: Guest Tools still reported as available")
}
}