fix: reconcile orphaned files/entries left by ServiceNow record renames#98
Open
AlexAlvarez092 wants to merge 1 commit into
Open
fix: reconcile orphaned files/entries left by ServiceNow record renames#98AlexAlvarez092 wants to merge 1 commit into
AlexAlvarez092 wants to merge 1 commit into
Conversation
When a record's key field (e.g. name) changes remotely, pull commands previously wrote a file under the new local path but never cleaned up the old file or its stale index entry, leaving a duplicate behind. SnSyncIndexService now detects renames (same table/sys_id/fieldName, different localPath) during recordPullFiles, replacePullSnapshot, and replaceTableSnapshot, and reconciles them: - Unmodified old file -> deleted, stale entry dropped, reported via PULL_RENAME_CLEANUP_PREFIX. - Locally modified old file -> left untouched to avoid data loss, reported via PULL_RENAME_CONFLICT_PREFIX. - Missing old file -> stale entry silently dropped. Wired the new reportPullRenameReconciliation helper into pull current, pull by sys_id (via snScopedPullCommandService), pull table, and pull all files, so all four pull commands surface cleanup/conflict results. Fixed an aliasing bug found while testing: recordPullFiles used state.entries directly as the rename lookup map, so bookkeeping deletions during processing incorrectly removed entries from state even when they should have been preserved (conflict case). Now passes a shallow copy. Updated developer-docs/sn-pull-*.md and docs/commands.md to document the new rename-reconciliation behavior. Added unit tests covering clean rename cleanup, conflict preservation, missing-file handling, and delete-failure resilience; coverage remains at 100%. Closes #97 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a bug where pulling a ServiceNow record that was renamed remotely (e.g. a Script Include's
namechanged) created a new local file under the new name but left the old file and its sync index entry orphaned, instead of cleaning them up.Type of change
Related issues
Closes #97
What was changed
SnSyncIndexServicenow detects renames duringrecordPullFiles,replacePullSnapshot, andreplaceTableSnapshot— an incoming pull update matching an existing entry'stable/sys_id/fieldNamebut with a differentlocalPathsignals a remote rename.baseHash) → deleted, stale index entry removed, user informed via a newPULL_RENAME_CLEANUP_PREFIXmessage.PULL_RENAME_CONFLICT_PREFIXmessage so the conflict can be resolved manually.SnSyncIndexReconciliationResultmodel and areportPullRenameReconciliationhelper, wired into all four pull commands (pull current,pull by sys_id,pull table,pull all files) so every pull surfaces cleanup/conflict results.recordPullFilespassedstate.entriesitself as the rename lookup map, so internal bookkeeping deletions incorrectly removed entries from persisted state even in the "keep the old entry" (conflict) case. Now passes a separate shallow copy.developer-docs/sn-pull-*.md(all four pull commands) anddocs/commands.mdto document the new behavior.How to test
sn: pull→ all files to sync a table (e.g. a Script Include).name).sn: pull currenton the (now stale) local file, orsn: pull table/sn: pull by sys_idfor that record.Checklist
npm run coveragelocally.Notes for reviewers
pull table/pull all filesalready have a "clear destination before pull" preference (pull.clearBeforePull); when that preference deletes the destination folder first, this reconciliation naturally has nothing to do (the old file is already gone), so it only matters when the folder isn't cleared before pulling.