Files
magpie/internal/cli/profile_rename_cli_test.go
T
yetoneanderlinerd 1cb4d43013 profiles: a saved profile renames, in its details, the TUI and magpie rename (#2721, erlinerd)
erlinerd's patch on #2721 (profile.Rename, /api/state profile/rename,
a Rename button in the details), reviewed against main and adapted:

- profile.Rename trims both names, refuses an empty, taken or missing
  name and leaves profiles.json as it was, renames by case only
  (home -> Home), and keeps what the profile holds.
- GUI: Rename turns the details' name into a field. Enter renames
  through profileAction, so the chip is renamed at once, pending, and
  rolled back with the error if magpie refuses; the details stay open
  under the new name, with In use kept. Escape or a click away puts
  the name back. The field lives in profilerename.js, imported on
  press, so the core script stays under its budget (no raise; 50 bytes
  under after comments in app.js were cut). While the field is open
  In use, Apply and Rename hide so a 360px panel's field has room.
- TUI: ctrl+e on a profile renames it on the name line.
- CLI: `magpie rename <old> <new>`; a flag is never taken for a name.
- WebDAV: a rename syncs as the old name gone and the new one in
  (davsync test).

Run on mote at 47672f11c (on 70b96126e), and again after rebasing on
52195b6b0 (backup), as 3b279fdee:
- go test ./internal/profile ./internal/cli ./internal/gui ./internal/tui
  ./internal/davsync: ok except TestEveryRouteHasACommandOrIsNamed
  (#4826) and TestMainWindowCorners (#3949), both red on origin/main
  07f4d46c5 too. gofmt clean; GOOS=linux (-tags nogui) and
  GOOS=windows go vet ok.
- GUI, chromium and webkit: profile-rename (en, zh, zh-TW, ja, de;
  900x560 window and 360x420 panel), panel-profiles, profile-confirm,
  profile-in-use, profile-details, hermes-profiles,
  view-wheel-after-click, i18n-keys, gui-de, gui-ja, gui-zh-tw,
  editor-roomy: 219 pass, 0 fail. After the rebase: profile, cli,
  gui, tui and vet again (same two reds only, core budget ok), and the
  GUI files above with auto-backup in place of editor-roomy: 161 pass.
  Then rebased over ea51526b6 (gateway, plugin, provider only; no
  file of this change, no GUI asset) without another run.

Broken by hand, each red, then restored:
- Rename comparing names with EqualFold: TestRename red (case-only).
- Dropping the CLI's "-" check: TestRenameCommand red.
- Dropping `profileOpen = to`: profile-rename 22 of 22 red, both engines.

Not tried: the real app on Linux (WebKitGTK) or Windows; a rename
synced over a real WebDAV server.

Co-authored-by: erlinerd <erlinerd@outlook.com>
2026-11-02 18:37:25 +08:00

39 lines
1.0 KiB
Go

package cli
import (
"slices"
"testing"
"github.com/yetone/magpie/internal/profile"
)
// magpie rename moves a profile's name; a flag or a missing or extra word
// is no name to write, and leaves the profiles as they were (#2721).
func TestRenameCommand(t *testing.T) {
helpHome(t)
if err := profile.Save("work", profile.Profile{Fields: map[string]string{"codex.model": "m"}}); err != nil {
t.Fatal(err)
}
names := func() []string {
ps, err := profile.Load()
if err != nil {
t.Fatal(err)
}
return profile.Names(ps)
}
for _, args := range [][]string{{"rename"}, {"rename", "work"}, {"rename", "work", "-x"}, {"rename", "work", "a", "b"}} {
if _, err := runOut(t, args...); err == nil {
t.Errorf("magpie %v went through", args)
}
if got := names(); !slices.Equal(got, []string{"work"}) {
t.Fatalf("magpie %v: %v", args, got)
}
}
if _, err := runOut(t, "rename", "work", "desk"); err != nil {
t.Fatal(err)
}
if got := names(); !slices.Equal(got, []string{"desk"}) {
t.Fatalf("after magpie rename work desk: %v", got)
}
}