Files
openchamber-android-native/third_party/mygo/internal/e2e/left_behind_test.go
T
OpenChamber 6c0ee61750 feat: port the client to MyGo native UI (0.3.0)
Switch from Asuka to MyGo, keeping the API client and the feature set:

- servers: saved servers, passwordless and password login, proxy,
  self-signed certificates, per-server device tokens (Keystore), connect
  form, instance list sheet with switch/disconnect
- sessions: virtualized list, search, new session, rename/archive/delete,
  running indicator, event stream keeps it live
- chat: pushed window with system back bar, streaming Markdown via
  ui/markdown, reasoning and tool rows with image previews, footer menu
  (read aloud via a Kotlin TTS plugin, copy, fork), user message menu
  (copy, revert, fork), context usage ring and detail sheet, attachments
  (photos/files via the document picker), permissions
- release builds allow plain http:// LAN servers (Go's net/http dials
  directly, no cleartext manifest needed)
- a local fork of MyGo (third_party/mygo) lowers the Android host's
  minSdk to 24 (Android 7.0); Go 1.27.4 via mise

Version 0.3.0.
2026-11-18 13:22:59 +08:00

49 lines
1.6 KiB
Go

//go:build !js
package e2e
import (
"slices"
"strings"
"testing"
"github.com/egoist/mygo"
)
// watchLeftBehind notes what a package's tests share and one can change for
// those after it: the keyboard, whose lock keys outlive a window and even
// the process on an X server, and the windows open. The function it returns
// reports what changed since and puts it back, so that the test at fault
// fails, by name, rather than one that runs much later and did nothing wrong.
func watchLeftBehind() (check func(report func(format string, args ...any))) {
keyboard, restore := keyboardState()
windows := mygo.Windows()
return func(report func(format string, args ...any)) {
if now, _ := keyboardState(); now != keyboard {
report("the test left the keyboard with %s, and found it with %s: tests after it would get other keys; a test that presses a lock key or holds one lets it go in a cleanup", now, keyboard)
restore()
}
for _, w := range mygo.Windows() {
if !slices.Contains(windows, w) {
report("the test left a window open, titled %q: it can take the keyboard from the tests after it", w.Title())
w.Destroy()
}
}
}
}
// TestLeftBehindWindow leaves a window open: the check says so and closes it.
func TestLeftBehindWindow(t *testing.T) {
check := watchLeftBehind()
w := mygo.NewWindow(mygo.WindowOptions{Title: "Left open", Hidden: true})
var got []string
check(func(format string, args ...any) { got = append(got, format) })
if len(got) != 1 || !strings.Contains(got[0], "window") {
t.Errorf("reported %q, want the window", got)
}
if !w.IsDestroyed() {
t.Error("the window is still open")
w.Destroy()
}
}