settings: the routing groups' defaults are kept through a Settings save and known to be saved by the Routing page's own route
6b7ee4a98added groupSink, groupFirstToken and groupPatience to settings and to settingsapi.Keys. Two guards went red on main (#5644): - TestSettingsSaveKeepsWhatItDoesNotSend wants every setting the Settings page doesn't send set in the test and kept by POST /api/settings. Merge already keeps the three (6b7ee4a98added that); the test never set them, so it couldn't check it. It sets them now (true, 30, 120), as it does BusyLoad. - TestSettingsCLISetsWhatTheWindowSaves wants every key `magpie settings` sets to be one a page sends POST /api/settings. The Routing groups page saves these three through POST /api/groups/defaults (settings.SetGroupDefaults), and the page itself names `magpie settings set` as the other way to set them. The CLI path is real, so the keys stay in settingsapi.Keys. The test now has ownRoute: a key a page saves through a route of its own, with the call and the body key it sends it as, and it fails when no page's call sends that key any more, or when ownRoute names a key the CLI can't set. Siblings:6b7ee4a98added no other settings key. provider.Group's new NoSink and FirstTokenWait have no CLI side to miss: `magpie group set` has no sink, first-token or patience option before or after it. Run on mote at origin/mainf8525323d: - Before the change, the two tests: red with the 3+3 lines of #5644. After: ok. - Broken by hand: Merge not keeping groupPatience made TestSettingsSaveKeepsWhatItDoesNotSend red ("GroupPatience: 0 ... was 120"); client.js's groups/defaults call without patience made TestSettingsCLISetsWhatTheWindowSaves red. Restored. - Real CLI, a built magpie in a sandbox HOME: `settings set` groupPatience 120, groupSink true, groupFirstToken 45 were saved to settings.json and listed; groupPatience 999 was refused with nothing changed. - go test -tags nogui ./internal/cli ./internal/gui: ok. - gofmt -l: clean. GOOS=linux go vet -tags nogui ./... and GOOS=windows go vet ./...: clean. Not run: the full suite and the GUI (Playwright) suite; no page script changed. Fixes #5644
This commit is contained in:
@@ -93,13 +93,69 @@ func TestSettingsCLISetsWhatTheWindowSaves(t *testing.T) {
|
||||
t.Errorf("the window saves %q, which `magpie settings` can't set: add it to settingsapi.Keys", k)
|
||||
}
|
||||
}
|
||||
pages := pagesSource(t)
|
||||
for k, own := range ownRoute {
|
||||
if !settingsapi.Known(k) {
|
||||
t.Errorf("ownRoute names %q, which `magpie settings` can't set: take it out", k)
|
||||
}
|
||||
saved := false
|
||||
for rest := pages; ; {
|
||||
i := strings.Index(rest, own.call)
|
||||
if i < 0 {
|
||||
break
|
||||
}
|
||||
rest = rest[i+len(own.call):]
|
||||
j := strings.Index(rest, "{")
|
||||
if j < 0 {
|
||||
break
|
||||
}
|
||||
body := rest[j:]
|
||||
if regexp.MustCompile(`[{,]\s*` + own.field + `\s*:`).MatchString(body[:balanced(body)]) {
|
||||
saved = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !saved {
|
||||
t.Errorf("no page sends %q as %s to %s any more: send it in a save of POST /api/settings, or name the call that saves it", k, own.field, own.call)
|
||||
}
|
||||
}
|
||||
for _, k := range settingsapi.Keys {
|
||||
if !slices.Contains(gui, k) {
|
||||
if _, own := ownRoute[k]; !own && !slices.Contains(gui, k) {
|
||||
t.Errorf("`magpie settings` sets %q, which no page sends", k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ownRoute are the settings `magpie settings` sets that a page saves
|
||||
// through a route of its own instead of POST /api/settings, with the call
|
||||
// that does it: the Routing groups page's defaults for every group
|
||||
// (settings.SetGroupDefaults), which `magpie settings set` sets too. field
|
||||
// is the key the call's body sends it as.
|
||||
var ownRoute = map[string]struct{ call, field string }{
|
||||
"groupSink": {`api("groups/defaults"`, "sink"},
|
||||
"groupFirstToken": {`api("groups/defaults"`, "firstToken"},
|
||||
"groupPatience": {`api("groups/defaults"`, "patience"},
|
||||
}
|
||||
|
||||
// pagesSource is every page script the window serves, the built-in
|
||||
// plugins' among them, as one text.
|
||||
func pagesSource(t *testing.T) string {
|
||||
t.Helper()
|
||||
var all strings.Builder
|
||||
err := filepath.WalkDir(filepath.Join("..", "gui", "assets"), func(p string, d os.DirEntry, err error) error {
|
||||
if err != nil || d.IsDir() || !strings.HasSuffix(p, ".js") || strings.Contains(p, "vendor") {
|
||||
return err
|
||||
}
|
||||
b, err := os.ReadFile(p)
|
||||
all.Write(b)
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return all.String()
|
||||
}
|
||||
|
||||
// What a route without a command is waiting for. Later stages of #4745
|
||||
// take routes out of notYet into cliForRoute.
|
||||
const (
|
||||
|
||||
@@ -209,6 +209,8 @@ func TestSettingsSaveKeepsWhatItDoesNotSend(t *testing.T) {
|
||||
was.RouterNote = "Los Angeles" // the Library's servers/hub-note
|
||||
was.RouterAllTools = true // the Library's servers/hub-tools
|
||||
was.BusyLoad = 150 // the Routing page's busy-load
|
||||
// the Routing groups page's defaults for every group (groups/defaults)
|
||||
was.GroupSink, was.GroupFirstToken, was.GroupPatience = true, 30, 120
|
||||
if err := settings.Save(was); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user