π OpenHands: AI-Driven Development
fix: preserve backend kind in edit mode (#1263)
Rajiv Shah83d65c1f06b2
diff --git a/__tests__/components/backends/manage-backends-modal.test.tsx b/__tests__/components/backends/manage-backends-modal.test.tsxindex d3ea7ab66e..48cfd783f5 100644--- a/__tests__/components/backends/manage-backends-modal.test.tsx+++ b/__tests__/components/backends/manage-backends-modal.test.tsx@@ -207,6 +207,57 @@ describe("ManageBackendsModal", () => {expect(backendId).not.toBe("");});+ it("preserves kind:cloud when renaming a cloud backend on a custom domain", async () => {+ const user = userEvent.setup();++ let backendId = "";+ renderWithProviders(+ <TestSeed+ onMount={(ctx) => {+ backendId = ctx.addBackend({+ name: "OHE Prod",+ host: "https://app.company.com",+ apiKey: "sk-oh-test",+ kind: "cloud",+ }).id;+ }}+ >+ <ManageBackendsModal onClose={vi.fn()} />+ </TestSeed>,+ );++ await user.click(+ await screen.findByTestId("manage-backends-edit-OHE Prod"),+ );+ await screen.findByTestId("edit-backend-modal");++ // Rename only -- host and kind are untouched+ const nameInput = screen.getByTestId(+ "edit-backend-name",+ ) as HTMLInputElement;+ await user.clear(nameInput);+ await user.type(nameInput, "OHE Prod Renamed");++ await user.click(screen.getByTestId("edit-backend-submit"));++ await waitFor(() => {+ expect(+ screen.queryByTestId("edit-backend-modal"),+ ).not.toBeInTheDocument();+ });++ const stored = JSON.parse(+ window.localStorage.getItem("openhands-backends") ?? "[]",+ );+ const updated = stored.find(+ (b: { id: string }) => b.id === backendId,+ );+ expect(updated).toMatchObject({+ name: "OHE Prod Renamed",+ kind: "cloud",+ });+ });+it("closes the edit form when the header close button is clicked", async () => {const user = userEvent.setup();diff --git a/src/components/features/backends/backend-form-modal.tsx b/src/components/features/backends/backend-form-modal.tsxindex 1dc25c09ee..35b1be14bb 100644--- a/src/components/features/backends/backend-form-modal.tsx+++ b/src/components/features/backends/backend-form-modal.tsx@@ -345,8 +345,13 @@ export function BackendForm({const [nameTouched, setNameTouched] = React.useState(false);const [hostTouched, setHostTouched] = React.useState(false);- // Kind is inferred from the host on every change.- const kind: BackendKind = inferKindFromHost(host);+ // In edit mode preserve the existing backend's kind so that renaming or+ // rotating the API key on a cloud backend (e.g. an OHE/enterprise instance+ // on a custom domain) does not silently downgrade it to "local" and switch+ // the auth header from `Authorization: Bearer` to `X-Session-API-Key`.+ // Only infer from the host when adding a new backend.+ const kind: BackendKind =+ mode === "edit" && backend ? backend.kind : inferKindFromHost(host);const testIdRoot =explicitTestIdRoot ?? (mode === "edit" ? "edit-backend" : "add-backend");