Files
openchamber-android-native/third_party/mygo/internal/uivet/analyze_test.go
T
OpenChamber 6c0ee61750 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.
2026-11-18 13:22:59 +08:00

56 lines
1.9 KiB
Go

package uivet
import (
"go/ast"
"go/parser"
"go/token"
"go/types"
"strings"
"testing"
)
type testImporter struct{ ui *types.Package }
func (i testImporter) Import(path string) (*types.Package, error) { return i.ui, nil }
func TestStoredValuesAndGoroutineCaptures(t *testing.T) {
ui := types.NewPackage(uiPath, "ui")
for _, name := range []string{"Element", "Context", "Handle", "Services"} {
obj := types.NewTypeName(token.NoPos, ui, name, nil)
types.NewNamed(obj, types.NewStruct(nil, nil), nil)
ui.Scope().Insert(obj)
}
ui.Scope().Insert(types.NewFunc(token.NoPos, ui, "Box", types.NewSignatureType(nil, nil, nil, types.NewTuple(types.NewVar(token.NoPos, ui, "c", types.NewPointer(ui.Scope().Lookup("Context").Type()))), types.NewTuple(types.NewVar(token.NoPos, ui, "", ui.Scope().Lookup("Element").Type())), false)))
ui.MarkComplete()
fs := token.NewFileSet()
f, err := parser.ParseFile(fs, "app.go", `package app
import native "github.com/egoist/mygo/ui"
type E = native.Element
type app struct { bad E; context *native.Context; safe native.Handle; services native.Services; view func(*native.Context) }
var saved native.Element
func view(c *native.Context){
e:=native.Box(c)
go func(){ _=e; _=c }()
go func(e native.Element){}(e)
var h native.Handle
go func(){_=h}()
}
`, 0)
if err != nil {
t.Fatal(err)
}
info := &types.Info{Defs: map[*ast.Ident]types.Object{}, Uses: map[*ast.Ident]types.Object{}, Types: map[ast.Expr]types.TypeAndValue{}}
pkg, err := (&types.Config{Importer: testImporter{ui}}).Check("example/app", fs, []*ast.File{f}, info)
if err != nil {
t.Fatal(err)
}
diagnostics := Analyze(fs, []*ast.File{f}, pkg, info)
if len(diagnostics) != 6 {
t.Fatalf("got %d: %#v", len(diagnostics), diagnostics)
}
for _, d := range diagnostics {
if strings.Contains(d.Message, "safe") || strings.Contains(d.Message, "services") {
t.Fatal(d)
}
}
}