Aside keeps one folder per account (~/.aside/u/<id>, each with its own settings.json, models.json, credentials.json and state.db), and which one is in use is currentAccountId in ~/.aside/accounts.json, which the app and `aside account use <id>` both set. magpie only ever wrote u/0 and asked the runtime about --account u0, so with u1 active Connect changed an account the reporter wasn't using. - magpie now follows currentAccountId. An accounts.json that is missing, doesn't parse, names no active account, or names one with no folder is "unknown" and keeps u0, as before; it is never written. - The Aside row gets an account field (under Details, shown only with more than one account) listing each account with its e-mail or "Local Account" and which one is active in Aside; `magpie aside account u1` does the same from the CLI. The pick is kept in magpie's own aside-account.json; Default removes it and follows Aside again. A pick whose folder is gone is passed over. - What magpie remembers to put back on Disconnect is per account (aside-state.json for u0, as before, aside-state-uN.json for others), so switching accounts never restores one account's model into another. The legacy stash still migrates into u0's only. - All runtime reads and writes go to `aside repl --account uN` for the account in use. - GUI strings in en, zh, zh-TW, ja, de. Run: go test -tags nogui ./... in a sandbox HOME; new aside_account_test.go uses the reporter's accounts.json bytes (TestAsideFollowsTheActiveAccount, TestAsideUnreadableAccountsKeepU0, TestAsidePickedAccountOverridesActive, TestAsideRestorePointsArePerAccount, TestAsideKeepsModelsPermissions); with asideChoice forced to 0 the follow, pick and restore tests fail, and with one shared record the restore test fails. GUI: aside-account.test.cjs (chromium and webkit, 980 and 360px, en/zh/zh-TW/ja/de) plus aside-native, i18n-keys, agent-field-names, agent-layout and agent-models-picker, 45 passing. gofmt -l; GOOS=linux and GOOS=windows go vet -tags nogui ./internal/agent ./internal/gui.
74 lines
2.2 KiB
Go
74 lines
2.2 KiB
Go
package agent
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/edit"
|
|
)
|
|
|
|
func TestAsideLegacyRestorePointIsReadWithoutMigrationWrites(t *testing.T) {
|
|
settings, models := asideHome(t)
|
|
if err := edit.SetJSON(settings, edit.KV{Path: "defaultModel.provider", Value: "magpie"}, edit.KV{Path: "defaultModel.modelId", Value: "relay/glm-4.6"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
stash(map[string]string{"aside.was": "native/native-model"})
|
|
a := mustFindAside(t)
|
|
if err := a.Connect(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
before := readFile(settings) + readFile(models) + readFile(stashPath())
|
|
if _, err := DisconnectPreview(a, "no executable needed"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if readFile(settings)+readFile(models)+readFile(stashPath()) != before {
|
|
t.Fatal("migration preview wrote config")
|
|
}
|
|
if err := a.Disconnect(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if a.Field("model").Get() != "native/native-model" {
|
|
t.Fatal("trusted legacy restore point not used")
|
|
}
|
|
}
|
|
|
|
func TestAsideRuntimeWinsOverSavedModelAndPlanRefusesMismatch(t *testing.T) {
|
|
settings, _ := asideHome(t)
|
|
a := mustFindAside(t)
|
|
if err := a.Apply("model", "magpie/relay/glm-4.6"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
plan, err := a.Native.Disconnect()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
asideRead = func(string) (map[string]json.RawMessage, error) {
|
|
var s map[string]json.RawMessage
|
|
_ = json.Unmarshal([]byte(readFile(settings)), &s)
|
|
s["defaultModel"] = json.RawMessage(`{"provider":"native","modelId":"new-choice","thinkingLevel":"high","fastMode":true}`)
|
|
return s, nil
|
|
}
|
|
if err := a.Native.Execute(plan); err == nil || !strings.Contains(err.Error(), "changed") {
|
|
t.Fatal("disconnect ignored runtime mismatch")
|
|
}
|
|
}
|
|
|
|
func TestAsideReadbackConfirmsRestoreSettings(t *testing.T) {
|
|
settings, _ := asideHome(t)
|
|
a := mustFindAside(t)
|
|
if err := a.Apply("model", "magpie/relay/glm-4.6"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
inner := asideSet
|
|
asideSet = func(account, expr string) error {
|
|
if err := inner(account, expr); err != nil {
|
|
return err
|
|
}
|
|
return edit.SetJSON(settings, edit.KV{Path: "defaultModel.thinkingLevel", Value: "low"})
|
|
}
|
|
if err := a.Disconnect(); err == nil {
|
|
t.Fatal("incorrect restore settings accepted")
|
|
}
|
|
}
|