Library -> Memory reviewed one memory at a time: To review held
candidates that had to be opened and kept or deleted one by one.
- Select (beside the filters, shown when two or more are listed) puts a
box on each memory. A click picks one, Shift-click the range from the
last one clicked, up/down move between the boxes (Shift picks as it
goes), Cmd/Ctrl+A picks all shown, Escape ends it. A search or filter
unpicks what it hides.
- The bar under the list (the library's lib-pickbar, as Skills' Select)
keeps (To review), archives (In use) or restores (Archived) the picked
ones, and deletes them on a second click.
- POST /api/memory/status {ids, status}: memory.SetStatus changes them in
one write, each as Edit by the user (an archived inferred memory is
dismissed, so it isn't proposed again). Unknown ids are skipped; none
found, or a bad status, is a 400 and changes nothing.
Delete reuses POST /api/memory/remove {ids}.
Run (mote, at this head):
- go test ./internal/memory ./internal/memdistill ./internal/library: ok
- go test -run 'Memory|Distill|Dream' ./internal/gui: ok
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
./..., and the three builds: ok. gofmt -l: clean.
- library-memory-select.test.cjs (new): 22/22, chromium and webkit,
en/zh/zh-TW/ja/de at 980 and 420 wide (no native select, no sideways
overflow).
- Every library-*, i18n-* and gui-* GUI file (67), both engines: 1309 of 1309 pass.
- Rebased on 2219fdd49: i18n-keys, library-memory, library-memory-select
and library-bili 132/132; go test ./internal/memory and -run Memory
./internal/gui ok (at d374168d0; only a
client_icons test changed in those packages since).
Broken by hand:
- SetStatus without editIn: TestSetStatusOfSome red ("after keeping two:
candidate candidate candidate candidate"), and
TestMemoryStatusRouteActsOnSome red.
- memPick with no Shift range: the GUI test red (got [c1, c4], wanted
c1..c4).
Not tried: the real app with a real memory.json, the WebKitGTK Linux app,
Windows' WebView2.
77 lines
2.4 KiB
Go
77 lines
2.4 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/memory"
|
|
)
|
|
|
|
// The Memory tab's Select acts on the memories picked at once
|
|
// (RealZeroP27 on X): /api/memory/status keeps the ones to review and
|
|
// answers with the tab as it is now; deleting several goes through
|
|
// /api/memory/remove. A request naming none, or a status that isn't
|
|
// one, is refused and changes nothing.
|
|
func TestMemoryStatusRouteActsOnSome(t *testing.T) {
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
|
mux := http.NewServeMux()
|
|
memoryRoutes(mux)
|
|
post := func(path, body string) (int, memoryView) {
|
|
t.Helper()
|
|
rec := httptest.NewRecorder()
|
|
mux.ServeHTTP(rec, httptest.NewRequest("POST", path, strings.NewReader(body)))
|
|
var v memoryView
|
|
if rec.Code == 200 {
|
|
if err := json.Unmarshal(rec.Body.Bytes(), &v); err != nil {
|
|
t.Fatalf("%s: %s", path, rec.Body)
|
|
}
|
|
}
|
|
return rec.Code, v
|
|
}
|
|
var ids []string
|
|
for _, text := range []string{"Prefers pnpm.", "Ships on Fridays.", "Answers in Chinese."} {
|
|
kind, scope, st := memory.Preference, memory.Global, memory.Candidate
|
|
m, _, err := memory.Save(memory.Input{Text: &text, Kind: &kind, Scope: &scope, Status: &st}, memory.FromInferred, nil, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ids = append(ids, m.ID)
|
|
}
|
|
statuses := func(v memoryView) map[string]string {
|
|
out := map[string]string{}
|
|
for _, m := range v.Memories {
|
|
out[m.ID] = m.Status
|
|
}
|
|
return out
|
|
}
|
|
|
|
code, v := post("/api/memory/status", `{"ids":["`+ids[0]+`","`+ids[1]+`"],"status":"active"}`)
|
|
if code != 200 {
|
|
t.Fatalf("keep: %d", code)
|
|
}
|
|
if s := statuses(v); s[ids[0]] != "active" || s[ids[1]] != "active" || s[ids[2]] != "candidate" {
|
|
t.Fatalf("after keeping two: %v", s)
|
|
}
|
|
if code, _ := post("/api/memory/status", `{"ids":[],"status":"active"}`); code != 400 {
|
|
t.Fatalf("none named: %d", code)
|
|
}
|
|
if code, _ := post("/api/memory/status", `{"ids":["`+ids[2]+`"],"status":"gone"}`); code != 400 {
|
|
t.Fatalf("a bad status: %d", code)
|
|
}
|
|
if m, _ := memory.Get(ids[2]); m.Status != memory.Candidate {
|
|
t.Fatalf("a refused request changed it: %s", m.Status)
|
|
}
|
|
|
|
code, v = post("/api/memory/remove", `{"ids":["`+ids[0]+`","`+ids[2]+`"]}`)
|
|
if code != 200 {
|
|
t.Fatalf("remove: %d", code)
|
|
}
|
|
if s := statuses(v); len(s) != 1 || s[ids[1]] != "active" {
|
|
t.Fatalf("after removing two: %v", s)
|
|
}
|
|
}
|