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.
129 lines
3.8 KiB
Go
129 lines
3.8 KiB
Go
//go:build !js
|
|
|
|
package mygo
|
|
|
|
import (
|
|
"bytes"
|
|
"image/png"
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/egoist/mygo/internal/fake"
|
|
"github.com/egoist/mygo/internal/platform"
|
|
)
|
|
|
|
func TestFileIcon(t *testing.T) {
|
|
dir := t.TempDir()
|
|
data, err := Shell.FileIcon(dir, 24)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if img, err := png.Decode(bytes.NewReader(data)); err != nil || img.Bounds().Dx() != 24 {
|
|
t.Errorf("FileIcon: %v, %v", img, err)
|
|
}
|
|
if _, err := Shell.FileIcon(dir, 0); err == nil {
|
|
t.Error("FileIcon of size 0 did not fail")
|
|
}
|
|
if _, err := Shell.FileIcon(filepath.Join(dir, "missing"), 16); err == nil {
|
|
t.Error("FileIcon of a missing file did not fail")
|
|
}
|
|
}
|
|
|
|
func TestTypeIcon(t *testing.T) {
|
|
data, err := Shell.TypeIcon(".pdf", 24)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if img, err := png.Decode(bytes.NewReader(data)); err != nil || img.Bounds().Dx() != 24 {
|
|
t.Errorf("TypeIcon: %v, %v", img, err)
|
|
}
|
|
if _, err := Shell.TypeIcon("pdf", 0); err == nil {
|
|
t.Error("TypeIcon of size 0 did not fail")
|
|
}
|
|
}
|
|
|
|
func TestTrashItemRelativePath(t *testing.T) {
|
|
t.Chdir(t.TempDir())
|
|
defer func() { fake.Trashed = nil }()
|
|
if err := Shell.TrashItem(filepath.Join("notes", "old.txt")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
wd, _ := os.Getwd()
|
|
if want := []string{filepath.Join(wd, "notes", "old.txt")}; !slices.Equal(fake.Trashed, want) {
|
|
t.Errorf("TrashItem passed %q, want %q", fake.Trashed, want)
|
|
}
|
|
}
|
|
|
|
func TestTrashItemResultRelativePath(t *testing.T) {
|
|
t.Chdir(t.TempDir())
|
|
defer func() { fake.Trashed = nil }()
|
|
trashPath, err := Shell.TrashItemResult(filepath.Join("docs", "report.pdf"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
wd, _ := os.Getwd()
|
|
wantSrc := filepath.Join(wd, "docs", "report.pdf")
|
|
if !slices.Equal(fake.Trashed, []string{wantSrc}) {
|
|
t.Errorf("TrashItemResult recorded %q, want %q", fake.Trashed, wantSrc)
|
|
}
|
|
if trashPath == "" {
|
|
t.Error("TrashItemResult returned an empty trash path")
|
|
}
|
|
}
|
|
|
|
// TestPreviewItemRelativePath checks that a relative path reaches the
|
|
// backend absolute, as the preview needs a file URL.
|
|
func TestPreviewItemRelativePath(t *testing.T) {
|
|
t.Chdir(t.TempDir())
|
|
defer func() { fake.Previewed = nil }()
|
|
if err := Shell.PreviewItem(filepath.Join("notes", "old.txt")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
wd, _ := os.Getwd()
|
|
if want := []string{filepath.Join(wd, "notes", "old.txt")}; !slices.Equal(fake.Previewed, want) {
|
|
t.Errorf("PreviewItem passed %q, want %q", fake.Previewed, want)
|
|
}
|
|
}
|
|
|
|
func TestInstalledApps(t *testing.T) {
|
|
fake.Apps = []platform.Application{
|
|
{Name: "zed", ID: "dev.zed.Zed", Path: "/Applications/Zed.app"},
|
|
{Name: "Calculator", ID: "com.apple.calculator", Path: "/System/Applications/Calculator.app"},
|
|
{Name: "Arc", ID: "company.thebrowser.Browser", Path: "/Applications/Arc.app"},
|
|
}
|
|
defer func() { fake.Apps, fake.Opened = nil, nil }()
|
|
apps, err := Shell.InstalledApps()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var names []string
|
|
for _, a := range apps {
|
|
names = append(names, a.Name)
|
|
}
|
|
if want := []string{"Arc", "Calculator", "zed"}; !slices.Equal(names, want) {
|
|
t.Errorf("InstalledApps: %v, want %v", names, want)
|
|
}
|
|
if err := Shell.LaunchApp(apps[1]); err != nil || !slices.Equal(fake.Opened, []string{"/System/Applications/Calculator.app"}) {
|
|
t.Errorf("LaunchApp: %v, opened %v", err, fake.Opened)
|
|
}
|
|
if err := Shell.LaunchApp(InstalledApp{Name: "nothing"}); err == nil {
|
|
t.Error("LaunchApp of an app without a path did not fail")
|
|
}
|
|
}
|
|
|
|
func TestDefaultApp(t *testing.T) {
|
|
defer func() { fake.DefaultAppURLs = nil }()
|
|
app, err := Shell.DefaultApp("https://example.com")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if app.Path == "" {
|
|
t.Error("DefaultApp returned an app without a path")
|
|
}
|
|
if want := []string{"https://example.com"}; !slices.Equal(fake.DefaultAppURLs, want) {
|
|
t.Errorf("DefaultApp passed %q, want %q", fake.DefaultAppURLs, want)
|
|
}
|
|
}
|