Files
magpie/internal/edit/del_test.go
T
yetone df27f0882a agent: the 接入 switch and a model picked in the row, both (owner: 对于那种想在 magpie 中一键设置 Agent 模型的用户能否也兼容一下,鱼和熊掌都要兼得); a row opens in place and slides as on iOS (owner: 展开的时候,上/下 padding 变了,导致抖动;展开和折叠都没有 iOS 那种丝滑优雅精致的动画)
Every agent row keeps its 接入 switch and now has its model picker beside it. Picking a magpie model on an agent that isn't connected connects it first (agent.Pick, used by /api/set), so one pick sets the agent up; disconnecting still puts back what the agent had. The intro line says both ways.

An opened row shook: the connected row centred its lines in its 56px min-height, and the 3px row-gap couldn't be folded away, so opening moved the name and the switch and changed the space under them. The first line now has its own height and isn't centred, the row-gap is 0 with the spacing in margins, and the opened part starts where the shut row ended (56/56 at 980px, 90/90 at 560px; the name at 8px and the switch at 19px open and shut). Opening and closing animate the part's height, padding, margin and border on iOS's sheet curve cubic-bezier(.32,.72,0,1), 460 ms open and 340 ms shut, and what's in it fades in from 6px above; a row already open slides shut before another opens. With reduced motion it opens at once.

Gemini CLI's .env made by magpie for its key was left holding a newline after a disconnect (main too): DelEnvFile now removes a dotenv file once the deleted keys were all it held.

TestPickConnectsFirst, the only.env case in TestEnvFile, agent-start-pick and agent-expand-steady (name and switch unmoved, the opened part's top at the shut row's end, at least 3 heights between on the way open and shut, growing/shrinking only, chromium and webkit at 980 and 560px) fail on the old code and pass. Tests that open rows wait for the slide. In a sandbox HOME with real accounts: Claude Code and Gemini CLI picked while not connected answer PONG and disconnect back to what they had; Goose's pick → disconnect round trip is byte-identical (goose itself stops at a Linear MCP OAuth, so no request). go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui for edit, agent and gui under a temp HOME pass; GUI tests that fail here fail the same on 82340f41 (account-arrange, cli-update, mobile-web, provider-levels-scroll, provider-proxy, redact-rule-row, routing-compact, provider-detect-models, plugin-move).
2026-10-04 02:05:10 +08:00

94 lines
2.8 KiB
Go

package edit
import (
"os"
"testing"
)
func TestDelJSONMiddleKeepsLayout(t *testing.T) {
in := "{\n \"env\": {\n \"A\": \"1\",\n \"B\": \"2\",\n \"C\": \"3\"\n },\n \"model\": \"m\"\n}\n"
p := tmpFile(t, "s.json", in)
if err := DelJSON(p, "env.B"); err != nil {
t.Fatal(err)
}
want := "{\n \"env\": {\n \"A\": \"1\",\n \"C\": \"3\"\n },\n \"model\": \"m\"\n}\n"
if got := read(t, p); got != want {
t.Fatalf("got\n%s\nwant\n%s", got, want)
}
// last member: preceding comma goes
if err := DelJSON(p, "env.C", "nope.x"); err != nil {
t.Fatal(err)
}
want = "{\n \"env\": {\n \"A\": \"1\"\n },\n \"model\": \"m\"\n}\n"
if got := read(t, p); got != want {
t.Fatalf("got\n%s\nwant\n%s", got, want)
}
// only member: parent collapses to {}
if err := DelJSON(p, "env.A"); err != nil {
t.Fatal(err)
}
want = "{\n \"env\": {},\n \"model\": \"m\"\n}\n"
if got := read(t, p); got != want {
t.Fatalf("got\n%s\nwant\n%s", got, want)
}
// top-level last member
if err := DelJSON(p, "model"); err != nil {
t.Fatal(err)
}
want = "{\n \"env\": {}\n}\n"
if got := read(t, p); got != want {
t.Fatalf("got\n%s\nwant\n%s", got, want)
}
}
func TestDelJSONCompactAndComments(t *testing.T) {
p := tmpFile(t, "c.jsonc", "{\"a\":1,\"b\":{\"x\":true},\"c\":3}")
if err := DelJSON(p, "a", "b.x"); err != nil {
t.Fatal(err)
}
if got := read(t, p); got != "{\"b\":{},\"c\":3}" {
t.Fatalf("got %q", got)
}
p = tmpFile(t, "d.jsonc", "{\n // keep me\n \"a\": 1, // trailing\n \"b\": 2\n}\n")
if err := DelJSON(p, "b"); err != nil {
t.Fatal(err)
}
if got := read(t, p); got != "{\n // keep me\n \"a\": 1 // trailing\n}\n" {
t.Fatalf("got %q", got)
}
}
func TestEnvFile(t *testing.T) {
p := tmpFile(t, ".env", "# comment\nFOO=bar\nexport BAZ=\"q x\"\n")
if v, ok := GetEnvFile(p, "BAZ"); !ok || v != "q x" {
t.Fatalf("got %q %v", v, ok)
}
if err := SetEnvFile(p, KV{"FOO", "new"}, KV{"KEY", "sk-1"}); err != nil {
t.Fatal(err)
}
if got := read(t, p); got != "# comment\nFOO=new\nexport BAZ=\"q x\"\nKEY=sk-1\n" {
t.Fatalf("got %q", got)
}
if err := DelEnvFile(p, "FOO", "KEY"); err != nil {
t.Fatal(err)
}
if got := read(t, p); got != "# comment\nexport BAZ=\"q x\"\n" {
t.Fatalf("got %q", got)
}
// the keys all it held: the file goes, not a blank line left
only := tmpFile(t, "only.env", "GEMINI_API_KEY=magpie\nGOOGLE_GEMINI_BASE_URL=http://127.0.0.1:3425\n")
if err := DelEnvFile(only, "GEMINI_API_KEY", "GOOGLE_GEMINI_BASE_URL"); err != nil {
t.Fatal(err)
}
if _, err := os.Stat(only); !os.IsNotExist(err) {
t.Fatalf("left %q", read(t, only))
}
np := tmpFile(t, "new.env", "")
if err := SetEnvFile(np, KV{"A", "1"}); err != nil {
t.Fatal(err)
}
if got := read(t, np); got != "A=1\n" {
t.Fatalf("got %q", got)
}
}