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.
78 lines
2.0 KiB
Go
78 lines
2.0 KiB
Go
//go:build windows
|
|
|
|
package mygo
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// TestOpenSharedLetsAppsSave replaces and deletes a document's file
|
|
// while the app reads it. A file opened with os.Open refuses both ("Access
|
|
// is denied"); one openShared opened lets another app replace it with a
|
|
// POSIX-semantics rename (as os.Root.Rename and current save code do) or
|
|
// delete it, and the app goes on reading what it opened. A rename by
|
|
// MoveFileEx, as os.Rename does, is refused while any handle to the file
|
|
// is open, whatever it shares: an app saving so tries again once the app
|
|
// has read the file (TestDocumentOtherApps).
|
|
func TestOpenSharedLetsAppsSave(t *testing.T) {
|
|
dir := t.TempDir()
|
|
root, err := os.OpenRoot(dir)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer root.Close()
|
|
path := filepath.Join(dir, "doc.txt")
|
|
reset := func() {
|
|
t.Helper()
|
|
if err := os.WriteFile(path, []byte("one"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
save := func() error {
|
|
if err := os.WriteFile(path+".tmp", []byte("two"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return root.Rename("doc.txt.tmp", "doc.txt")
|
|
}
|
|
|
|
// What os.Open refuses, here.
|
|
reset()
|
|
plain, err := os.Open(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Logf("with os.Open: save %v, delete %v", save(), os.Remove(path))
|
|
plain.Close()
|
|
|
|
reset()
|
|
f, err := openShared(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := save(); err != nil {
|
|
t.Fatalf("saving over a file the app reads: %v", err)
|
|
}
|
|
if b, err := io.ReadAll(f); err != nil || string(b) != "one" {
|
|
t.Errorf("read %q, %v from the file opened before the save", b, err)
|
|
}
|
|
f.Close()
|
|
if b, _ := os.ReadFile(path); string(b) != "two" {
|
|
t.Errorf("the file has %q after the save", b)
|
|
}
|
|
|
|
reset()
|
|
if f, err = openShared(path); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer f.Close()
|
|
if err := os.Remove(path); err != nil {
|
|
t.Fatalf("deleting a file the app reads: %v", err)
|
|
}
|
|
if b, err := io.ReadAll(f); err != nil || string(b) != "one" {
|
|
t.Errorf("read %q, %v from the file opened before it was deleted", b, err)
|
|
}
|
|
}
|