From 89cc717bee1132d9956ed3ef200147660add2132 Mon Sep 17 00:00:00 2001 From: Verve Agent <> Date: Sun, 15 Mar 2026 04:20:32 +0000 Subject: [PATCH] fix: prevent internal server error when saving expectations on ready repo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When editing repo expectations from the settings dialog (repo already in "ready" status), clicking "Save & Complete" attempted a ready→ready status transition which was not in the valid transitions map, causing an untagged error that mapped to 500. Now UpdateRepoSetupStatus treats same-status transitions as a no-op. Co-Authored-By: Claude Opus 4.6 --- internal/repo/store.go | 3 +++ internal/repoapi/http_handler_test.go | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/internal/repo/store.go b/internal/repo/store.go index 3b8a263..d24d910 100644 --- a/internal/repo/store.go +++ b/internal/repo/store.go @@ -78,6 +78,9 @@ func (s *Store) UpdateRepoSetupStatus(ctx context.Context, id RepoID, status str if err != nil { return err } + if current.SetupStatus == status { + return nil + } if !isValidTransition(current.SetupStatus, status) { return fmt.Errorf("invalid setup status transition from %q to %q", current.SetupStatus, status) } diff --git a/internal/repoapi/http_handler_test.go b/internal/repoapi/http_handler_test.go index 69672a5..7bfda71 100644 --- a/internal/repoapi/http_handler_test.go +++ b/internal/repoapi/http_handler_test.go @@ -146,6 +146,28 @@ func TestUpdateSetup_MarkReady(t *testing.T) { assert.NotNil(t, res.Data.SetupCompletedAt, "setup_completed_at should be set") } +func TestUpdateSetup_MarkReadyWhenAlreadyReady(t *testing.T) { + f := newFixture(t) + r := f.addRepo("owner/test-repo") + + // Move repo to ready (pending → scanning → ready) + ctx := context.Background() + require.NoError(t, f.RepoStore.UpdateRepoSetupStatus(ctx, r.ID, repo.SetupStatusScanning)) + require.NoError(t, f.RepoStore.UpdateRepoSetupStatus(ctx, r.ID, repo.SetupStatusReady)) + + // Editing expectations from settings dialog when repo is already ready + // should not fail with internal server error. + expectations := "## Updated expectations" + req := repoapi.UpdateSetupRequest{ + Expectations: &expectations, + MarkReady: true, + } + res := doPatch[server.Response[repo.Repo]](t, f.repoSetupURL(r.ID), req) + assert.Equal(t, "## Updated expectations", res.Data.Expectations) + assert.Equal(t, repo.SetupStatusReady, res.Data.SetupStatus, "should remain ready") + assert.NotNil(t, res.Data.SetupCompletedAt, "setup_completed_at should be set") +} + func TestUpdateSetup_Combined(t *testing.T) { f := newFixture(t) r := f.addRepo("owner/test-repo")