Skip to content

Allow renaming a resource to a different case of its own name (#328) - #350

Merged
Timmoth merged 1 commit into
Timmoth:stagingfrom
VirSanctus:bug/328-case-d
Sep 29, 2026
Merged

Timmoth merged 1 commit into
Timmoth:stagingfrom
VirSanctus:bug/328-case-d

Conversation

@VirSanctus

Copy link
Copy Markdown
Contributor

Part of #328 (case D)

Problem

A rename that only changes case fails:

$ rpk servers rename Srv01 srv01
Conflict: Server resource 'srv01' already exists.

RenameResourceUseCase refuses the rename if GetByNameAsync(newName) finds anything, and since names compare case-insensitively that lookup finds the resource being renamed. The Web UI rename dialog and the MCP rename_resource tool go through the same use case, so they fail the same way.

Fix

Only a different resource with the new name is a conflict now. The check looks through GetAllOfTypeAsync<Resource>() for a match that is not the resource being renamed (compared by reference, since both lookups return the same instances). As you suggested, renaming onto another resource's case variant is still refused, whatever its kind.

I compared by reference rather than skipping the conflict when GetByNameAsync(newName) returns the resource itself, because in a config that already holds Dup61 and dup61 that lookup returns the first one. rename Dup61 DUP61 would then succeed as a rename onto dup61's case variant.

The runsOn and connection rewrites already compare case-insensitively (#329), so they follow the new casing without changes.

Renaming a resource to exactly its current name used to fail with "already exists"; it now returns early and succeeds without writing anything. In the Web UI that means pressing Save in the rename dialog without editing the name no longer shows an error.

Tests

Five CLI tests in Tests/EndToEnd/ConnectionTests/RenameResourceTests.cs:

Test Checks
rename_that_only_changes_case_updates_the_name a case-only rename succeeds and re-cases the name
rename_that_only_changes_case_updates_runs_on_and_connections dependants' runsOn and connection endpoints get the new casing
rename_onto_another_resources_case_variant_is_still_refused same kind and different kind
rename_to_the_identical_name_leaves_the_file_unchanged succeeds and leaves the file text unchanged
rename_is_refused_when_the_config_already_holds_a_case_variant the Dup61 / dup61 config

The first, second and fourth fail on staging and pass with the fix. The third and fifth pass on both; they guard what must not change, and the fifth fails if the check is written as "skip the conflict when the match is the resource itself".

I also checked the Web UI by hand in the Docker image built from this branch: renaming Srv01 to srv01 in the dialog goes to the page for srv01, saving the dialog again without editing the name shows no error, and renaming it to OTHER01 while Other01 exists shows the conflict in the dialog.

Not included

Interaction with #348

This merges cleanly with #348, and the CLI tests pass on the merge (383/383).

Local results

  • CLI tests: 381/381
  • MCP tests: 70/70
  • Discovery tests: 260/260
  • E2E tests: 106/106
  • dotnet format --verify-no-changes: clean
  • Build: 0 warnings, 0 errors

Checklist

…h#328)

The conflict check matched the resource being renamed, so a case-only
rename such as Srv01 -> srv01 failed with "already exists". Only a
different resource with the new name is now a conflict, so renaming onto
another resource's case variant is still refused, including in a config
that already holds both variants.

Renaming a resource to exactly its current name now succeeds without
writing anything, instead of failing with "already exists".
@VirSanctus
VirSanctus marked this pull request as ready for review September 29, 2026 08:29
@Timmoth

Timmoth commented Sep 29, 2026

Copy link
Copy Markdown
Owner

Amazing - thanks @VirSanctus !

@Timmoth
Timmoth merged commit 1f4c9fa into Timmoth:staging Sep 29, 2026
6 checks passed
@VirSanctus
VirSanctus deleted the bug/328-case-d branch September 29, 2026 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants