- 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.
87 lines
2.8 KiB
Go
87 lines
2.8 KiB
Go
package builtin
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/Nwflower/reims-go/internal/config"
|
|
"github.com/Nwflower/reims-go/internal/guesttools"
|
|
"github.com/Nwflower/reims-go/internal/host"
|
|
"github.com/Nwflower/reims-go/internal/plugin"
|
|
)
|
|
|
|
func TestBuiltinClipboardAndInputLifecycleZeroResidue(t *testing.T) {
|
|
reg := plugin.NewRegistry(nil)
|
|
gtSrv := guesttools.NewTransportServer(nil)
|
|
if _, err := gtSrv.Start(-1); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer func() { _ = gtSrv.Close(context.Background()) }()
|
|
|
|
cb := HostCallbacks{
|
|
GetConfig: func() config.Config { return config.Config{DataRoot: t.TempDir()} },
|
|
EnsureGuestTools: func() (*guesttools.Server, int, error) {
|
|
return gtSrv, gtSrv.Port(), nil
|
|
},
|
|
}
|
|
if err := RegisterAll(reg, cb, nil); err != nil {
|
|
t.Fatalf("RegisterAll: %v", err)
|
|
}
|
|
reg.Reconcile(context.Background())
|
|
|
|
// Clipboard extension should be active and have mounted /v1/clipboard + watcher.
|
|
if !reg.IsActive(IDGuestTools) || !reg.IsActive(IDClipboard) {
|
|
t.Fatalf("expected guest-tools and clipboard active")
|
|
}
|
|
if !gtSrv.HasRoute("/v1/clipboard") || !gtSrv.IsClipboardActive() {
|
|
t.Fatal("expected clipboard route mounted while builtin.bridge.clipboard is active")
|
|
}
|
|
|
|
// Disable clipboard live -> route removed, watcher stopped, zero residue!
|
|
if err := reg.SetDesired(context.Background(), IDClipboard, false); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if gtSrv.HasRoute("/v1/clipboard") || gtSrv.IsClipboardActive() {
|
|
t.Fatal("expected zero clipboard route residue after disabling builtin.bridge.clipboard")
|
|
}
|
|
deadline := time.Now().Add(2 * time.Second)
|
|
for gtSrv.IsClipboardWatcherRunning() && time.Now().Before(deadline) {
|
|
time.Sleep(20 * time.Millisecond)
|
|
}
|
|
if gtSrv.IsClipboardWatcherRunning() {
|
|
t.Fatal("expected clipboard watcher stopped after disable")
|
|
}
|
|
|
|
// Re-enable clipboard -> active again.
|
|
if err := reg.SetDesired(context.Background(), IDClipboard, true); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !gtSrv.HasRoute("/v1/clipboard") {
|
|
t.Fatal("expected clipboard route restored on re-enable")
|
|
}
|
|
|
|
// Disabling transport service cascades and disables clipboard cleanly.
|
|
if err := reg.SetDesired(context.Background(), IDGuestTools, false); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if reg.IsActive(IDClipboard) || gtSrv.HasRoute("/v1/clipboard") {
|
|
t.Fatal("disabling guest-tools transport must cascade-unload clipboard")
|
|
}
|
|
|
|
// Input service disables cleanly with zero hook residue.
|
|
if raw, ok := reg.LookupService(ServiceHostInput); !ok || raw == nil {
|
|
t.Fatal("expected host.input service provided")
|
|
}
|
|
if err := reg.SetDesired(context.Background(), IDInput, false); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, ok := reg.LookupService(ServiceHostInput); ok {
|
|
t.Fatal("expected host.input service removed after disable")
|
|
}
|
|
}
|
|
|
|
func TestInputServiceTypeCheck(t *testing.T) {
|
|
_ = host.NewInputService(nil)
|
|
}
|