π OpenHands: AI-Driven Development
fix(llm-profiles): keep the auto-filled profile name following the model (#18017)
Engel Nyst387403344585
diff --git a/__tests__/components/settings/llm-profiles/llm-settings-local-view.test.tsx b/__tests__/components/settings/llm-profiles/llm-settings-local-view.test.tsxindex 580107d6be..929ac1e672 100644--- a/__tests__/components/settings/llm-profiles/llm-settings-local-view.test.tsx+++ b/__tests__/components/settings/llm-profiles/llm-settings-local-view.test.tsx@@ -465,6 +465,55 @@ describe("LlmSettingsLocalView", () => {});});+ describe("create mode profile name auto-fill", () => {+ const changeModel = (model: string) =>+ fireEvent.change(screen.getByTestId("mock-basic-model-input"), {+ target: { value: model },+ });++ it("keeps the untouched name following the selected model", async () => {+ const user = userEvent.setup();+ renderWithProviders(<LlmSettingsLocalView />);+ await user.click(screen.getByTestId("add-llm-profile"));+ const nameInput = screen.getByTestId("profile-name-input");+ expect(nameInput).toHaveValue("gpt-5.6-sol");++ changeModel("deepseek/deepseek-chat");+ expect(nameInput).toHaveValue("deepseek-chat");++ changeModel("anthropic/claude-sonnet-5");+ expect(nameInput).toHaveValue("claude-sonnet-5");+ });++ it("stops following the model once the user types a name, and resumes after the name is cleared", async () => {+ const user = userEvent.setup();+ renderWithProviders(<LlmSettingsLocalView />);+ await user.click(screen.getByTestId("add-llm-profile"));+ const nameInput = screen.getByTestId("profile-name-input");++ fireEvent.change(nameInput, { target: { value: "my-profile" } });+ changeModel("deepseek/deepseek-chat");+ expect(nameInput).toHaveValue("my-profile");++ fireEvent.change(nameInput, { target: { value: "" } });+ changeModel("anthropic/claude-sonnet-5");+ expect(nameInput).toHaveValue("claude-sonnet-5");+ });++ it("clears the auto-filled name instead of using an existing profile's name", async () => {+ const user = userEvent.setup();+ renderWithProviders(<LlmSettingsLocalView />);+ await user.click(screen.getByTestId("add-llm-profile"));+ const nameInput = screen.getByTestId("profile-name-input");+ expect(nameInput).toHaveValue("gpt-5.6-sol");++ // "gpt-4-profile" is an existing profile's name.+ changeModel("openai/gpt-4-profile");+ expect(nameInput).toHaveValue("");+ expect(screen.getByTestId("save-profile-btn")).toBeDisabled();+ });+ });+describe("edit mode form initialization", () => {it("populates profile name when editing an existing profile", async () => {const user = userEvent.setup();@@ -587,6 +636,10 @@ describe("LlmSettingsLocalView", () => {await waitFor(() => {expect(screen.getByTestId("save-profile-btn")).not.toBeDisabled();});+ // Changing the model never renames an existing profile.+ expect(screen.getByTestId("profile-name-input")).toHaveValue(+ "gpt-4-profile",+ );});});diff --git a/src/components/features/settings/llm-profiles/llm-settings-local-view.tsx b/src/components/features/settings/llm-profiles/llm-settings-local-view.tsxindex 06520f9840..b5453bd513 100644--- a/src/components/features/settings/llm-profiles/llm-settings-local-view.tsx+++ b/src/components/features/settings/llm-profiles/llm-settings-local-view.tsx@@ -132,6 +132,9 @@ export function LlmSettingsLocalView() {const [viewMode, setViewMode] = useState<ViewMode>("list");const [profileName, setProfileName] = useState("");+ // Whether the user typed the current create-mode name. Until they do (or+ // after they clear it), the name is auto-derived from the selected model.+ const [isProfileNameUserEdited, setIsProfileNameUserEdited] = useState(false);const [editingProfile, setEditingProfile] = useState<EditingProfile | null>(null,);@@ -169,8 +172,14 @@ export function LlmSettingsLocalView() {return true;}, [profileName, viewMode, existingNames, editingProfile?.profile.name]);+ const handleProfileNameChange = useCallback((value: string) => {+ setProfileName(value);+ setIsProfileNameUserEdited(value !== "");+ }, []);+const handleAddProfile = useCallback(() => {setProfileName("");+ setIsProfileNameUserEdited(false);setEditingProfile(null);setViewMode("create");}, []);@@ -252,24 +261,25 @@ export function LlmSettingsLocalView() {(control: SdkSectionSaveControl) => {setSaveControl(control);- // Auto-derive profile name from model in create mode.+ // Auto-derive profile name from model in create mode, and keep it+ // following later model changes until the user types their own name.// Note: The uniqueness check uses existingNames from state, which is derived// from profilesData at component render time. If another client creates a// profile with the same derived name while this form is open, the client-side// check would pass but the server save would fail with a conflict error.// This is acceptable for the current use case; the server error is handled// gracefully in handleSave.- if (viewMode === "create" && !profileName) {+ if (viewMode === "create" && !isProfileNameUserEdited) {const modelValue = control.values["llm.model"];if (typeof modelValue === "string" && modelValue) {const derived = deriveProfileNameFromModel(modelValue);- if (!existingNames.has(derived)) {- setProfileName(derived);- }+ // Never auto-fill an existing profile's name; clear the previous+ // model's name instead so it cannot be saved under the new model.+ setProfileName(existingNames.has(derived) ? "" : derived);}}},- [viewMode, profileName, existingNames],+ [viewMode, isProfileNameUserEdited, existingNames],);const handleSave = useCallback(async () => {@@ -497,7 +507,7 @@ export function LlmSettingsLocalView() {<ProfileNameInputtestId="profile-name-input"value={profileName}- onChange={setProfileName}+ onChange={handleProfileNameChange}isRequired/>