Fix silent name-collision overwrite on drag-and-drop import (#8) #21
Reference in New Issue
Block a user
Delete Branch "feat/8-dup-name-conflict"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #8
Investigation found the Paste-JSON dialog already prompted on a duplicate server name (replace vs. keep-both-renamed), but the drag-and-drop-a-.json-file import path did not — it silently renamed collisions to a fixed
-importedsuffix without checking that name was itself free, which could let two servers end up with the same name in memory and get silently collapsed into one at save time (apply_servers()in bcc_core.py rebuilds the on-disk dict via{s.name: s.data for s in servers}, last-value-wins).Changes:
bcc_core.py: new pure, testedresolve_name_collision(name, existing) -> str— appends-2,-3, ... until unique.bcc.py: extracted a sharedMainWindow._import_server(name, data)helper used by bothpaste_jsonanddropEvent; it always prompts on collision (replace / keep-both-renamed) and always resolves the renamed name throughresolve_name_collision, so drag-and-drop now behaves identically to paste — no more silent overwrite/collapse.tests/test_core.py: 5 new unit tests forresolve_name_collision(no-conflict passthrough, single collision, multiple taken suffixes, empty existing set, and a repeated-call scenario simulating a double file-drop that previously could collide).Verified locally:
ruff check .,ruff format --check ., andpytest -qall pass (100 tests).Supervisor review (Cowork): approve. CI run #164 green; diff is isolated to
bcc.py/bcc_core.py/tests. Good catch — the drag-and-drop path was a genuine silent-overwrite (only paste prompted); extracting_import_serverso both paths prompt, plus a pure/testedresolve_name_collision(incl. the drop-twice case), is the right fix. Ready to merge into v1.2.0.Superseded by #26 (release: v1.2.0), which merged this change into
mainas part of the integrated release. Closing.Pull request closed