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.
88 lines
3.0 KiB
Go
88 lines
3.0 KiB
Go
package nativelib
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestParse(t *testing.T) {
|
|
sum := strings.Repeat("ab", 32)
|
|
ok := `{"libraries": [{"name": "adder", "build": {"cargo": "./rust/adder", "args": ["--features", "x"]}, "release": "https://example.com/r",
|
|
"files": {"linux-amd64": {"name": "libadder.so", "url": "https://example.com/r/adder-linux-amd64.so", "sha256": "` + sum + `"}}}]}`
|
|
m, err := Parse([]byte(ok))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
l, found := m.Lookup("adder")
|
|
if tool, dir := l.Build.Tool(); !found || tool != "cargo" || dir != "./rust/adder" {
|
|
t.Fatalf("Lookup = %+v, %v", l, found)
|
|
}
|
|
if l.FileName("linux", "amd64") != "libadder.so" || l.FileName("windows", "arm64") != "adder.dll" {
|
|
t.Error("FileName")
|
|
}
|
|
for _, bad := range []string{
|
|
`{"libraries": [{"name": ""}]}`,
|
|
`{"libraries": [{"name": "../x"}]}`,
|
|
`{"libraries": [{"name": "my lib"}]}`,
|
|
`{"libraries": [{"name": ".hidden"}]}`,
|
|
`{"libraries": [{"name": "x"}, {"name": "x"}]}`,
|
|
`{"libraries": [{"name": "x", "build": {}}]}`,
|
|
`{"libraries": [{"name": "x", "build": {"cargo": "a", "zig": "b"}}]}`,
|
|
`{"libraries": [{"name": "x", "build": {"zig": "../elsewhere"}}]}`,
|
|
`{"libraries": [{"name": "x", "build": {"zig": "/abs"}}]}`,
|
|
`{"libraries": [{"name": "x", "files": {"linux-amd64": {"name": "..", "sha256": "` + sum + `"}}}]}`,
|
|
`{"libraries": [{"name": "x", "files": {"linux-amd64": {"name": "x.so", "sha256": "` + strings.ToUpper(sum) + `"}}}]}`,
|
|
`{"libraries": [{"name": "x", "files": {"linux-amd64": {"name": "x.so", "sha256": "../../etc"}}}]}`,
|
|
} {
|
|
if _, err := Parse([]byte(bad)); err == nil {
|
|
t.Errorf("Parse(%s) accepted it", bad)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestFileName(t *testing.T) {
|
|
for _, c := range []struct{ name, goos, want string }{
|
|
{"adder", "darwin", "libadder.dylib"},
|
|
{"adder", "linux", "libadder.so"},
|
|
{"adder", "windows", "adder.dll"},
|
|
{"libghostty-vt", "darwin", "libghostty-vt.dylib"},
|
|
{"libghostty-vt", "windows", "ghostty-vt.dll"},
|
|
{"mygo-sqlite3", "linux", "libmygo-sqlite3.so"},
|
|
} {
|
|
if got := FileName(c.name, c.goos); got != c.want {
|
|
t.Errorf("FileName(%q, %q) = %q, want %q", c.name, c.goos, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestMinMacOS(t *testing.T) {
|
|
for _, c := range []struct{ app, lib, want string }{
|
|
{"", "", "12.0"},
|
|
{"", "13.0", "13.0"},
|
|
{"14.0", "13.0", "14.0"},
|
|
{"13.2", "13.10", "13.10"},
|
|
{"15", "", "15"},
|
|
} {
|
|
if got := (&Build{MacOS: c.lib}).MinMacOS(c.app); got != c.want {
|
|
t.Errorf("MinMacOS(%q) with %q = %q, want %q", c.app, c.lib, got, c.want)
|
|
}
|
|
}
|
|
if _, err := Parse([]byte(`{"libraries": [{"name": "x", "build": {"zig": ".", "macOS": "13; rm"}}]}`)); err == nil {
|
|
t.Error("accepted an invalid macOS version")
|
|
}
|
|
}
|
|
|
|
func TestModuleRootRelative(t *testing.T) {
|
|
// The package's directory, below the module's root, as a relative
|
|
// path whose walk up passes the working directory.
|
|
root, err := ModuleRoot(".")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := os.Stat(filepath.Join(root, "go.mod")); err != nil {
|
|
t.Fatalf("ModuleRoot(\".\") = %s, which has no go.mod", root)
|
|
}
|
|
}
|