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.
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package background
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/egoist/mygo/internal/wait"
|
|
)
|
|
|
|
type result struct {
|
|
run int64
|
|
ok bool
|
|
}
|
|
|
|
func handlers(t *testing.T, m map[string]func(context.Context) error) {
|
|
t.Helper()
|
|
tasks.Lock()
|
|
defer tasks.Unlock()
|
|
tasks.handlers, tasks.running = m, map[int64]context.CancelFunc{}
|
|
}
|
|
|
|
// A task runs its handler and says what came of it; one the app no longer has
|
|
// finishes, so that the system stops asking; a panic stays in its task.
|
|
func TestRun(t *testing.T) {
|
|
handlers(t, map[string]func(context.Context) error{
|
|
"fine": func(context.Context) error { return nil },
|
|
"fails": func(context.Context) error { return errors.New("no network") },
|
|
"panics": func(context.Context) error { panic("oh") },
|
|
})
|
|
done := make(chan result, 1)
|
|
report := func(run int64, ok bool) { done <- result{run, ok} }
|
|
for i, c := range []struct {
|
|
name string
|
|
ok bool
|
|
}{{"fine", true}, {"fails", false}, {"panics", false}, {"gone", true}} {
|
|
run(runEvent{Run: int64(i), Name: c.name}, report)
|
|
if got := wait.For(t, c.name, done); got != (result{int64(i), c.ok}) {
|
|
t.Errorf("%s: %+v", c.name, got)
|
|
}
|
|
}
|
|
}
|
|
|
|
// The system's time running out ends the handler's context.
|
|
func TestStop(t *testing.T) {
|
|
started := make(chan struct{})
|
|
handlers(t, map[string]func(context.Context) error{
|
|
"long": func(ctx context.Context) error {
|
|
close(started)
|
|
<-ctx.Done()
|
|
return ctx.Err()
|
|
},
|
|
})
|
|
done := make(chan result, 1)
|
|
run(runEvent{Run: 7, Name: "long"}, func(run int64, ok bool) { done <- result{run, ok} })
|
|
wait.For(t, "it to start", started)
|
|
stop(7)
|
|
if got := wait.For(t, "it to end", done); got != (result{7, false}) {
|
|
t.Errorf("stopped: %+v", got)
|
|
}
|
|
}
|