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.
This commit is contained in:
1 parent
2fb4a8ea79
commit
6c0ee61750
2538 files changed
+675779
-4792
No files matched your search
@@ -0,0 +1,112 @@
|
||||
// App runs the round trip's checks where go test does not reach, and the
|
||||
// SQLite plugin's: in an app on a phone, whose modules are their Swift on
|
||||
// iOS and their Kotlin on Android. It logs each check, then "roundtrip: PASS" or "roundtrip:
|
||||
// FAIL", which CI waits for in the system's log:
|
||||
//
|
||||
// go run ./cmd/mygo build -platform android/arm64 native/internal/roundtrip/app
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"runtime"
|
||||
|
||||
"github.com/egoist/mygo"
|
||||
"github.com/egoist/mygo/native/internal/roundtrip/check"
|
||||
"github.com/egoist/mygo/ui"
|
||||
)
|
||||
|
||||
func main() {
|
||||
result := "running"
|
||||
mygo.App.WhenReady(func() {
|
||||
var w *mygo.Window
|
||||
w = mygo.NewWindow(mygo.WindowOptions{Title: "Round trip", Content: ui.View(func(c *ui.Context) {
|
||||
ui.Column(c).Fill().Padding(24).Children(func() {
|
||||
ui.Text(c, "roundtrip: "+result).FontSize(20)
|
||||
})
|
||||
})})
|
||||
go func() {
|
||||
failed := run()
|
||||
mygo.RunOnMain(func() {
|
||||
result = map[bool]string{true: "FAIL", false: "PASS"}[failed]
|
||||
w.Invalidate()
|
||||
})
|
||||
log.Printf("roundtrip: %s", map[bool]string{true: "FAIL", false: "PASS"}[failed])
|
||||
}()
|
||||
})
|
||||
if err := mygo.App.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// run runs the checks, each on a goroutine of its own, as a test is, and
|
||||
// reports whether one failed.
|
||||
func run() bool {
|
||||
failed := false
|
||||
checks := append(check.All, struct {
|
||||
Name string
|
||||
Run func(check.T)
|
||||
}{"SQLite", checkSQLite})
|
||||
for _, c := range checks {
|
||||
t := &tester{name: c.Name}
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer close(done)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
t.failed = true
|
||||
t.log(fmt.Sprint("panic: ", r))
|
||||
}
|
||||
}()
|
||||
c.Run(t)
|
||||
}()
|
||||
<-done
|
||||
for i := len(t.cleanups) - 1; i >= 0; i-- {
|
||||
t.cleanups[i]()
|
||||
}
|
||||
switch {
|
||||
case t.failed:
|
||||
failed = true
|
||||
log.Printf("roundtrip: --- FAIL: %s", c.Name)
|
||||
case t.skipped:
|
||||
// A check that skips here fails: the app is for where the module
|
||||
// runs.
|
||||
failed = true
|
||||
log.Printf("roundtrip: --- SKIP: %s", c.Name)
|
||||
default:
|
||||
log.Printf("roundtrip: --- ok: %s", c.Name)
|
||||
}
|
||||
}
|
||||
return failed
|
||||
}
|
||||
|
||||
// tester is a check's T: Fatal and Skip end its goroutine, as testing.T's
|
||||
// do.
|
||||
type tester struct {
|
||||
name string
|
||||
failed, skipped bool
|
||||
cleanups []func()
|
||||
}
|
||||
|
||||
func (t *tester) Helper() {}
|
||||
|
||||
func (t *tester) log(msg string) { log.Printf("roundtrip: %s: %s", t.name, msg) }
|
||||
|
||||
func (t *tester) Fatal(args ...any) {
|
||||
t.failed = true
|
||||
t.log(fmt.Sprint(args...))
|
||||
runtime.Goexit()
|
||||
}
|
||||
|
||||
func (t *tester) Fatalf(format string, args ...any) { t.Fatal(fmt.Sprintf(format, args...)) }
|
||||
|
||||
func (t *tester) Skip(args ...any) {
|
||||
t.skipped = true
|
||||
t.log(fmt.Sprint(args...))
|
||||
runtime.Goexit()
|
||||
}
|
||||
|
||||
func (t *tester) Context() context.Context { return context.Background() }
|
||||
|
||||
func (t *tester) Cleanup(f func()) { t.cleanups = append(t.cleanups, f) }
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "Roundtrip",
|
||||
"identifier": "dev.mygo.roundtrip"
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"reflect"
|
||||
|
||||
"github.com/egoist/mygo/native/internal/roundtrip/check"
|
||||
"github.com/egoist/mygo/plugins/sqlite"
|
||||
)
|
||||
|
||||
// checkSQLite checks the SQLite plugin's native module, which phones build
|
||||
// from its Swift and its Kotlin as they do the round trip's.
|
||||
func checkSQLite(t check.T) {
|
||||
ctx := context.Background()
|
||||
db, err := sqlite.Open(ctx, ":memory:", sqlite.OpenOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
if _, err := db.Execute(ctx, "CREATE TABLE t (id INTEGER PRIMARY KEY, name TEXT NOT NULL, score REAL, data BLOB)"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r, err := db.Execute(ctx, "INSERT INTO t (name, score, data) VALUES (?, ?, ?)", "héllo 🌍", 0.5, []byte{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if r.Changes != 1 || r.LastInsertID != 1 {
|
||||
t.Fatalf("insert: %+v", r)
|
||||
}
|
||||
rows, err := db.Query(ctx, "SELECT id, name, score, data, NULL AS none, sqlite_version() FROM t")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := sqlite.Rows{Columns: []string{"id", "name", "score", "data", "none", "sqlite_version()"}, Values: [][]any{{int64(1), "héllo 🌍", 0.5, []byte{}, nil, "3.53.4"}}}
|
||||
if !reflect.DeepEqual(rows, want) {
|
||||
t.Fatalf("query: %#v, want %#v", rows, want)
|
||||
}
|
||||
var e *sqlite.Error
|
||||
if _, err := db.Execute(ctx, "INSERT INTO t (name) VALUES (NULL)"); !errors.As(err, &e) || e.ExtendedCode != 1299 {
|
||||
t.Fatalf("NOT NULL: %v, want SQLITE_CONSTRAINT_NOTNULL", err)
|
||||
}
|
||||
if _, err := db.Execute(ctx, "SELEC 1"); !errors.As(err, &e) || e.Code != 1 {
|
||||
t.Fatalf("syntax: %v, want SQLITE_ERROR", err)
|
||||
}
|
||||
if _, err := db.Execute(ctx, "SELECT 1; SELECT 2"); err == nil {
|
||||
t.Fatal("two statements ran")
|
||||
}
|
||||
if _, err := db.Execute(ctx, "ATTACH ':memory:' AS other"); err == nil {
|
||||
t.Fatal("ATTACH ran")
|
||||
}
|
||||
results, err := db.Transaction(ctx, []sqlite.Statement{
|
||||
{SQL: "INSERT INTO t (name) VALUES (?)", Args: []any{"a"}},
|
||||
{SQL: "UPDATE t SET score = score + 1 WHERE score IS NOT NULL"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(results) != 2 || results[0].LastInsertID != 2 || results[1].Changes != 1 {
|
||||
t.Fatalf("transaction: %+v", results)
|
||||
}
|
||||
if _, err := db.Transaction(ctx, []sqlite.Statement{{SQL: "INSERT INTO t (name) VALUES ('b')"}, {SQL: "INSERT INTO t (name) VALUES (NULL)"}}); err == nil {
|
||||
t.Fatal("a failing transaction committed")
|
||||
}
|
||||
if rows, err := db.Query(ctx, "SELECT count(*) FROM t"); err != nil || rows.Values[0][0] != int64(2) {
|
||||
t.Fatalf("after rollback: %v %v", rows, err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user