Review of Leon Zhao's Lody import (the two commits before this):
- Detection: a bare ~/.lody or ~/.lody-oss another tool made counted as
Lody. Now the home folder counts only with an entry Lody makes there
(workspace-catalog.json, loro-repo, agent-binaries, code-collab-v2, all
in the owner's real ~/.lody). A Lody.app counts only with an ai.lody.
bundle id (the real /Applications/Lody.app is ai.lody.desktop, and
registers the lody scheme) or a plist that isn't XML. Electron's data
folder under os.UserConfigDir (Application Support / %APPDATA% /
~/.config, "Lody", "Lody OSS", "Lody Nightly") still counts as before.
A never-opened install on Windows or Linux has no folder and isn't
shown; said in agent-wiring.md.
- Security: TestLodyLinkCarriesNoSecret turns LAN sharing on and checks
the link holds magpie-lody and never the LAN key, every endpoint is
loopback http, and MAGPIE_ADDR pinned beyond loopback gives no link at
all (0.0.0.0, 127.0.0.1 and [::1] still give one).
- `magpie lody add` with no link (a LAN-pinned gateway) said it opened
Lody and opened ""; it now says why and opens nothing.
- Added *bool: every consumer re-read. The CLI and TUI use agent.Agent's
func (nil-safe), the GUI reads a.added == null, and Cindy's false is now
sent as "added":false. TestLodyImportHandoff also checks Cindy's row
says false and Lody's leaves added out; the handoff test's ~/.lody
holds a catalog file now and checks it is left byte for byte.
- The hint "Opens {name} to add magpie as a provider — confirm it there"
was already translated in zh, zh-TW, ja and de (the import button's
tooltip). import-row now runs in all five languages, asserts Lody's
exact translated line and that no added/not-added wording shows, and
checks both import rows fit a 420px window with no sideways scroll
(waiting for the header's segments to settle after the resize, which
overflow for ~300ms in WebKit en on main too).
Run (on origin/main 4a6bf80f4 + Leon's two; after rebasing onto
dcf292cc8, a routing-only CSS change, import-row, agent-layout,
group-editor-align and i18n-keys were run again in both engines, 47/47,
with the Lody/Cindy/Import Go tests in agent and gui, ok):
- go test -tags nogui -count=1 -timeout 45m ./... under a sandbox HOME
(scratchpad dir, XDG_* there too, Go caches pinned): 64 packages ok,
exit 0 (agent 607s, gateway 674s, gui 130s, provider 219s).
- gofmt -l .: clean. go vet: darwin ./..., GOOS=linux -tags nogui ./...,
GOOS=windows ./...: clean.
- GUI, playwright 1.62.0, Chromium and WebKit: import-row 20/20 (5
languages x added/not x 2 engines, 960/700/420px); i18n-keys, gui-de,
gui-ja, gui-zh-tw, agent-layout, agent-connect, plugin-agent,
agent-cli-missing, agent-connected-unfolded, agent-bulk-visibility,
agents-hidden-last: 116/116.
Broken by hand, each went red, then restored:
- a bare ~/.lody counting again: TestLodyDetectionAndRegistration;
- any Lody.app counting: TestLodyBundle (com.example.lody, ai.lodyx.);
- the loopback switch removed: TestLodyLinkCarriesNoSecret (LAN-pinned
addresses got a link);
- the key taken from agentKeyAt at a LAN address: the LAN key showed in
the link, red;
- Cindy's false left out of state(): TestLodyImportHandoff;
- app.js's unknown-status branch taken out: import-row red in every
language; the de translation removed: import-row de red.
Not tried: Lody opening the link for real (Leon ran Lody's parser), and
Windows or Linux Lody installs.
89 lines
2.5 KiB
Go
89 lines
2.5 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/agent"
|
|
)
|
|
|
|
type importWindows struct {
|
|
Windows
|
|
opened string
|
|
}
|
|
|
|
func (w *importWindows) OpenURL(u string) error { w.opened = u; return nil }
|
|
|
|
func TestLodyImportHandoff(t *testing.T) {
|
|
home := sandboxHome(t)
|
|
if err := os.MkdirAll(filepath.Join(home, ".lody"), 0700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
catalog := filepath.Join(home, ".lody", "workspace-catalog.json")
|
|
if err := os.WriteFile(catalog, []byte(`{"workspaces":[]}`), 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// Cindy, beside it, still says whether it has magpie: false is said,
|
|
// not left out as unknown
|
|
cfg, err := os.UserConfigDir()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.MkdirAll(filepath.Join(cfg, "Cindy"), 0700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var row, cindy *agentJSON
|
|
s := state()
|
|
for i := range s.Agents {
|
|
switch s.Agents[i].ID {
|
|
case "lody":
|
|
row = &s.Agents[i]
|
|
case "cindy":
|
|
cindy = &s.Agents[i]
|
|
}
|
|
}
|
|
if row == nil || !strings.HasPrefix(row.Import, agent.LodyScheme) {
|
|
t.Fatalf("missing Lody import row: %+v", row)
|
|
}
|
|
if row.Added != nil {
|
|
t.Fatal("unknown import status must not be reported as not added")
|
|
}
|
|
if b, _ := json.Marshal(row); strings.Contains(string(b), `"added"`) {
|
|
t.Fatalf("Lody's row says added: %s", b)
|
|
}
|
|
if cindy == nil || cindy.Added == nil || *cindy.Added {
|
|
t.Fatalf("Cindy without magpie: %+v, want added false", cindy)
|
|
}
|
|
if b, _ := json.Marshal(cindy); !strings.Contains(string(b), `"added":false`) {
|
|
t.Fatalf("Cindy's row leaves added out: %s", b)
|
|
}
|
|
w := &importWindows{}
|
|
mux := http.NewServeMux()
|
|
providerRoutes(mux, w)
|
|
for _, link := range []string{row.Import, "lody://session/example", "lody://provider/delete?all=1", "file:///tmp/example"} {
|
|
w.opened = ""
|
|
body, _ := json.Marshal(map[string]string{"url": link})
|
|
rec := httptest.NewRecorder()
|
|
mux.ServeHTTP(rec, httptest.NewRequest("POST", "/api/open", strings.NewReader(string(body))))
|
|
if link == row.Import {
|
|
if w.opened != link {
|
|
t.Fatal("Lody import was not handed to the desktop")
|
|
}
|
|
} else if w.opened != "" {
|
|
t.Fatalf("opened unrelated URL %s", w.opened)
|
|
}
|
|
}
|
|
entries, err := os.ReadDir(filepath.Join(home, ".lody"))
|
|
if err != nil || len(entries) != 1 {
|
|
t.Fatalf("handoff modified Lody data: %v %v", entries, err)
|
|
}
|
|
if b, err := os.ReadFile(catalog); err != nil || string(b) != `{"workspaces":[]}` {
|
|
t.Fatalf("handoff modified Lody's catalog: %q %v", b, err)
|
|
}
|
|
}
|