Files
magpie/internal/appdir/minimax_test.go
T
yetone e7fe52fdc3 minimax: follow the data folder MiniMax Code Desktop moved, not ~/.minimax (YujunT46308 on X)
YujunT46308 on X (magpie 0.1.3519, MiniMax Code 3.1.13 CN): with the
app's data folder moved to another parent (localRuntimeDataParentDir),
magpie went on writing ~/.minimax/config.yaml, which the app no longer
reads.

How MiniMax Code 3.1.13 finds it, read from its own app.asar
(dist/main/modules/local-runtime/data-dir.js,
resolveLocalRuntimeDataDirSelection; @mavis/config's config.js for the
runtime): MINIMAX_DATA_DIR, then MAVIS_DATA_DIR, then the desktop
setting, then ~/.minimax. Settings' data-folder move keeps the parent as
config.localRuntimeDataParentDir in its electron-store file
(storage.ipc.js: minimax-agent-cn-config.json for the China build,
minimax-agent-config.json for the global one) in Electron userData,
named by app-identity.js: "MiniMax" (CN) / "MiniMax Agent". The data
folder is <parent>/.minimax.

What changed:
- appdir.MiniMaxDirIn resolves the folder in that order, reading the
  store under ~/Library/Application Support on a Mac and %APPDATA% on
  Windows. A missing, unreadable or unparseable store, or a parent that
  isn't an absolute string, is ~/.minimax, as electron-store itself
  reads a file it can't parse as its defaults.
- internal/agent's MiniMaxDir (detection, connect, restore, Sync, Check)
  and internal/sessions' MiniMaxDir (Usage's calls) both use it; the
  Library's skills follow a.Dir. WSL's mcode still uses the distro's
  ~/.minimax (no desktop app there).
- MAVIS_DATA_DIR joins agentenv's variables, so tests sandbox it.
- agent-wiring.md and reference.md say where the folder comes from.

Run:
- On mote, the real MiniMax Code 3.1.13 CN arm64 dmg: launched with no
  setting, userData was ~/Library/Application Support/MiniMax holding
  minimax-agent-cn-config.json; with config.localRuntimeDataParentDir
  set to a folder, the next launch created <parent>/.minimax/config.yaml.
  appdir.MiniMaxDir() against that real store printed <parent>/.minimax.
  (The test data I made on mote was removed after.)
- mote-run go test -count=1 ./internal/appdir ./internal/agentenv
  ./internal/sessions ./internal/library: ok. ./internal/agent -run
  'MiniMax|Minimax|WSL|Env|Spelled|Handwired': ok.
- win-run go test -run MiniMax ./internal/appdir ./internal/agent
  ./internal/sessions: ok, TestMiniMaxDirIn and
  TestMiniMaxCodeMovedByDesktop ran (not skipped) with %APPDATA% paths.
- gofmt -l clean; go vet of the touched packages for darwin, windows
  and linux (nogui, CGO off) ok.

Broken by hand: with the desktop store read turned off,
TestMiniMaxDirIn and TestMiniMaxCodeMovedByDesktop go red (the folder
reads as ~/.minimax).

Not tried: the Windows desktop app itself (userData %APPDATA%\MiniMax
is Electron's appData plus the app name, the same rule seen on the
Mac); the global build's store with a real install; a store mid-rollback
(the app's guard writes the restored parent back to the same key on its
next launch). A user who also runs the mcode CLI without
MINIMAX_DATA_DIR has it on ~/.minimax, which magpie now leaves alone
while the desktop folder is moved.
2026-11-10 14:43:44 +08:00

112 lines
4.1 KiB
Go

package appdir
import (
"encoding/json"
"os"
"path/filepath"
"runtime"
"testing"
)
// writeMiniMaxStore writes MiniMax Code Desktop's electron-store file as
// 3.1.13 does, its config holding body.
func writeMiniMaxStore(t *testing.T, userData, file, body string) {
t.Helper()
if err := os.MkdirAll(userData, 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(userData, file), []byte(body), 0o644); err != nil {
t.Fatal(err)
}
}
// The desktop app's Settings moves the data folder to <parent>/.minimax
// and keeps the parent in its store, in Electron's userData: Application
// Support/MiniMax on a Mac, %APPDATA%\MiniMax on Windows (YujunT46308 on
// X). The global build's store is read too; a store that sets none, isn't
// JSON, or holds no usable path leaves ~/.minimax.
func TestMiniMaxDesktopParent(t *testing.T) {
parent := filepath.Join(t.TempDir(), "D", "data")
store := `{"user":{},"config":{"language":"zh","localRuntimeDataParentDir":` + quote(parent) + `,"localRuntimePreviousDataParentDirs":[]}}`
for _, goos := range []string{"darwin", "windows"} {
for _, s := range miniMaxDesktopStores {
t.Run(goos+"/"+s[0], func(t *testing.T) {
home := t.TempDir()
base := filepath.Join(home, "Library", "Application Support")
if goos == "windows" {
base = filepath.Join(t.TempDir(), "Roaming")
t.Setenv("APPDATA", base)
}
if got := miniMaxDesktopParent(home, goos); got != "" {
t.Fatalf("no store: %q", got)
}
writeMiniMaxStore(t, filepath.Join(base, s[0]), s[1], store)
if got := miniMaxDesktopParent(home, goos); got != parent {
t.Fatalf("got %q, want %q", got, parent)
}
})
}
}
t.Run("linux", func(t *testing.T) {
home := t.TempDir()
writeMiniMaxStore(t, filepath.Join(home, ".config", "MiniMax"), "minimax-agent-cn-config.json", store)
if got := miniMaxDesktopParent(home, "linux"); got != "" {
t.Fatalf("linux has no desktop app: %q", got)
}
})
for name, body := range map[string]string{
"unset": `{"config":{"language":"zh"}}`,
"empty": `{"config":{"localRuntimeDataParentDir":" "}}`,
"number": `{"config":{"localRuntimeDataParentDir":3}}`,
"relative": `{"config":{"localRuntimeDataParentDir":"data"}}`,
"broken": `{"config":{"localRuntimeDataParentDir":` + quote(parent),
} {
t.Run(name, func(t *testing.T) {
home := t.TempDir()
writeMiniMaxStore(t, filepath.Join(home, "Library", "Application Support", "MiniMax"), "minimax-agent-cn-config.json", body)
if got := miniMaxDesktopParent(home, "darwin"); got != "" {
t.Fatalf("got %q", got)
}
})
}
}
// MINIMAX_DATA_DIR, then MAVIS_DATA_DIR, win over the desktop app's
// setting, as in the app; without either the moved folder is the one.
func TestMiniMaxDirIn(t *testing.T) {
home := t.TempDir()
t.Setenv("APPDATA", filepath.Join(home, "AppData", "Roaming"))
t.Setenv("MINIMAX_DATA_DIR", "")
t.Setenv("MAVIS_DATA_DIR", "")
if got, want := MiniMaxDirIn(home), filepath.Join(home, ".minimax"); got != want {
t.Fatalf("default: %q", got)
}
parent := filepath.Join(t.TempDir(), "moved")
userData := filepath.Join(home, "Library", "Application Support", "MiniMax")
if goos := runtime.GOOS; goos == "windows" {
userData = filepath.Join(home, "AppData", "Roaming", "MiniMax")
} else if goos != "darwin" {
t.Skip("MiniMax Code Desktop ships for macOS and Windows only")
}
writeMiniMaxStore(t, userData, "minimax-agent-cn-config.json", `{"config":{"localRuntimeDataParentDir":`+quote(parent)+`}}`)
if got, want := MiniMaxDirIn(home), filepath.Join(parent, ".minimax"); got != want {
t.Fatalf("moved: %q, want %q", got, want)
}
mavis := filepath.Join(t.TempDir(), "mavis")
t.Setenv("MAVIS_DATA_DIR", mavis)
if got := MiniMaxDirIn(home); got != mavis {
t.Fatalf("MAVIS_DATA_DIR: %q", got)
}
env := filepath.Join(t.TempDir(), "env")
t.Setenv("MINIMAX_DATA_DIR", env)
if got := MiniMaxDirIn(home); got != env {
t.Fatalf("MINIMAX_DATA_DIR: %q", got)
}
}
// quote is s as a JSON string, a Windows path's backslashes escaped.
func quote(s string) string {
b, _ := json.Marshal(s)
return string(b)
}