ConatusMoon2222 asked whether a routing group can have a note. It couldn't: a group had an id and a name, nothing else of the user's. A group now has an optional one-line note (provider.Group.Note, "note" in providers.json). SaveGroup cleans it: whitespace and newlines run together, cut at 200 characters (in runes), and an empty one is no note. It is the user's own word and is never sent to an agent or a vendor. - Routing page: the note shows under the group's name as one muted, ellipsized line, the whole of it on hover, and only when there is one. The group editor has a Note field under Name (Enter saves, as in Name). Every save of the group sends it: the editor, a manual group's pick and a routing picked from the row, so none of them wipes it. - CLI: `magpie group set <id> note=...` (note= clears it), `magpie group add ... note=...`; `magpie group <id>` and the list print it. - TUI: N in a group's view edits it; the view shows it under the head. - A copy, a shared group, a backup (StoredGroups/RestoreGroups) and sync (Mirror) carry it: they move whole Group structs. TestGroupNote checks each. Two existing GUI tests clicked rows that the extra editor row pushed under the view's foot bar at 420px in WebKit, which doesn't scroll the page's own scroller to a click: group-defaults' reach() now counts in sight as above the foot bar, and group-unlists' openAdvanced wheels the summary into view as its other helpers do. Both passed on origin/main and failed on this change before the fix. Run (on mote, at this head rebased on origin/main): - go test ./internal/provider ./internal/cli ./internal/tui ./internal/gui: ok - gofmt -l: clean; go vet ./... darwin, GOOS=linux -tags nogui, GOOS=windows: ok - GUI, chromium + webkit: group-note (en, zh, zh-TW, ja, de, and 390px), every group-*, routing-group-*, routing-groups-*, settings-groups, routing-manual, routing-save*, routing-tag-whole, fallback-group and i18n-* file: 752 tests, 752 pass Broken by hand, each red: - SaveGroup without CleanNote, and the CLI's note= without it: TestGroupNote and TestGroupNoteCLI fail on the uncleaned note. - the editor's Save body without note: group-note fails (the typed note never posted). - the pick and route-tag bodies without note: group-note fails (the note wiped by a pick). Not tried: the real TUI by hand, the real app in Linux WebKitGTK, and Windows (the change has no OS-specific code; windows vet ran).
113 lines
2.8 KiB
Go
113 lines
2.8 KiB
Go
package provider
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// A routing group keeps a note of the user's (ConatusMoon2222 on X): saved
|
|
// as one line, its spaces run together, cut at NoteLongest characters, and
|
|
// cleared by saving it empty. It goes with the group where the group goes:
|
|
// a copy, a group shared to another magpie, a backup's StoredGroups and
|
|
// sync's Mirror. A save that changes something else keeps it.
|
|
func TestGroupNote(t *testing.T) {
|
|
fastHome(t)
|
|
note := func(id string) string {
|
|
t.Helper()
|
|
g, _, ok := FindGroup(GroupPrefix + id)
|
|
if !ok {
|
|
t.Fatalf("no group %s", id)
|
|
}
|
|
return g.Note
|
|
}
|
|
g := Group{ID: "work", Name: "Work", Note: " for the office key\n\tweekdays only ", Members: []string{"rl/claude-opus-5-5", "an/claude-sonnet-5"}}
|
|
if err := SaveGroup(g); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := note("work"); got != "for the office key weekdays only" {
|
|
t.Fatalf("note %q", got)
|
|
}
|
|
|
|
// another change keeps it
|
|
saved, _, _ := FindGroup(GroupPrefix + "work")
|
|
saved.Routing = Rotate
|
|
if err := SaveGroup(saved); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := note("work"); got != "for the office key weekdays only" {
|
|
t.Fatalf("after a routing change %q", got)
|
|
}
|
|
|
|
// a long one is cut, in characters, not bytes
|
|
saved.Note = strings.Repeat("备", NoteLongest+50)
|
|
if err := SaveGroup(saved); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := note("work"); got != strings.Repeat("备", NoteLongest) {
|
|
t.Fatalf("long note kept %d characters", len([]rune(got)))
|
|
}
|
|
saved.Note = "for the office key"
|
|
if err := SaveGroup(saved); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// a copy has it
|
|
cp, err := CopyGroup("work", "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := note(cp.ID); got != "for the office key" {
|
|
t.Fatalf("copy's note %q", got)
|
|
}
|
|
|
|
// shared to another magpie
|
|
text, err := ShareGroup("work")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(text, `"note":"for the office key"`) {
|
|
t.Fatalf("shared text without the note: %s", text)
|
|
}
|
|
|
|
// a backup and a sync carry it
|
|
stored, err := StoredGroups()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ps, err := Stored()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := Mirror(ps, nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, _, ok := FindGroup(GroupPrefix + "work"); ok {
|
|
t.Fatal("Mirror with no groups kept work")
|
|
}
|
|
if err := Mirror(ps, stored); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := note("work"); got != "for the office key" {
|
|
t.Fatalf("after Mirror %q", got)
|
|
}
|
|
if err := DeleteGroup("work"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := RestoreGroups(stored); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := note("work"); got != "for the office key" {
|
|
t.Fatalf("after RestoreGroups %q", got)
|
|
}
|
|
|
|
// cleared
|
|
saved, _, _ = FindGroup(GroupPrefix + "work")
|
|
saved.Note = " "
|
|
if err := SaveGroup(saved); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := note("work"); got != "" {
|
|
t.Fatalf("cleared note %q", got)
|
|
}
|
|
}
|