fix(web): preserve aw_url when a settings POST omits it
A UI save was silently blanking the configured AW URL because handlePostSettings bound the whole Settings from the request and saved it as-is. Now reads s.settings.AWURL under the existing settingsMu lock and carries it forward when req.AWURL is empty, so fields not exposed in the form are never erased.
This commit is contained in:
@@ -45,6 +45,11 @@ func (s *Server) handlePostSettings(c *gin.Context) {
|
||||
s.settingsMu.Lock()
|
||||
apply := s.applyFn
|
||||
path := s.settingsPath
|
||||
// aw_url is not exposed in the settings form; preserve the persisted value
|
||||
// so a UI save never blanks a configured AW URL.
|
||||
if req.AWURL == "" {
|
||||
req.AWURL = s.settings.AWURL
|
||||
}
|
||||
s.settingsMu.Unlock()
|
||||
if apply == nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "settings not wired"})
|
||||
|
||||
@@ -111,6 +111,37 @@ func TestPostSettingsInvalidJSONIs400(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostSettingsPreservesAWURL(t *testing.T) {
|
||||
s, _ := newTestServer(t)
|
||||
path := filepath.Join(t.TempDir(), "settings.json")
|
||||
fa := &fakeApplier{}
|
||||
cur := settings.Settings{AIBackend: "claude", AWURL: "http://aw.remote:9999"}
|
||||
s.SetSettings(path, cur, fa.apply)
|
||||
r := s.Router()
|
||||
|
||||
// POST a body that omits aw_url (mirrors what the real UI form sends).
|
||||
body := `{"ai_backend":"claude","marvin_cmd":"","knowledge_path":""}`
|
||||
w := post(t, r, "/settings", body)
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("status = %d, want 200 (body %s)", w.Code, w.Body.String())
|
||||
}
|
||||
if fa.called != 1 {
|
||||
t.Fatalf("applier called %d times, want 1", fa.called)
|
||||
}
|
||||
// (a) applyFn must have received the preserved AWURL.
|
||||
if fa.last.AWURL != "http://aw.remote:9999" {
|
||||
t.Errorf("applied AWURL = %q, want http://aw.remote:9999", fa.last.AWURL)
|
||||
}
|
||||
// (b) persisted file must also preserve the AWURL.
|
||||
saved, err := settings.Load(path)
|
||||
if err != nil {
|
||||
t.Fatalf("settings file not loadable: %v", err)
|
||||
}
|
||||
if saved.AWURL != "http://aw.remote:9999" {
|
||||
t.Errorf("saved AWURL = %q, want http://aw.remote:9999", saved.AWURL)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBrowseListsDirsAndMarkdown(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
if err := os.Mkdir(filepath.Join(dir, "sub"), 0o755); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user