Skip to content

fix: rename GUID-suffixed scripts when name conflicts are resolved#52

Open
Biraru wants to merge 1 commit into
Ransomwave:devfrom
Biraru:dev
Open

fix: rename GUID-suffixed scripts when name conflicts are resolved#52
Biraru wants to merge 1 commit into
Ransomwave:devfrom
Biraru:dev

Conversation

@Biraru

@Biraru Biraru commented Jul 2, 2026

Copy link
Copy Markdown

Fixes #51

@Ransomwave

Ransomwave commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Have you tested if this causes any weird regressions regarding #14?

@Biraru

Biraru commented Jul 3, 2026

Copy link
Copy Markdown
Author

Yes, i just did and i found out that deleting a same name parent causes the children to be orphaned. (aka just sit there without any reference in the sourcemap)
Never mind, this is undefined behaviour. Will keep testing though

@Biraru

Biraru commented Jul 3, 2026

Copy link
Copy Markdown
Author

Pretty sure #14 would need to be resolved first to make sure this doesn't cause any bugs.

@Ransomwave

Copy link
Copy Markdown
Owner

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of deleted items so matching sibling scripts are kept in sync when one node is removed.
    • After a deletion, the app now preserves and updates the last remaining sibling with the same name, helping keep script mappings and file updates consistent.

Walkthrough

SyncDaemon.handleDeleted in src/index.ts now performs an additional step after pruning: when the deleted node had a parentGuid, it searches the parent's descendant scripts for same-named sibling nodes, rewrites the last matching sibling's script file (suppressing the watcher), and upserts that sibling into the sourcemap using its previous path.

Changes

Sibling Rename on Deletion

Layer / File(s) Summary
Post-prune sibling rename handling
src/index.ts
After pruning a deleted node's sourcemap subtree, checks parent's descendant scripts for same-named siblings, rewrites the last matching sibling's file with watcher suppression, and upserts its subtree into the sourcemap using the sibling's prior path.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Watcher
  participant SyncDaemon
  participant FileSystem
  participant SourceMap

  Watcher->>SyncDaemon: handleDeleted(node)
  SyncDaemon->>SourceMap: prune subtree
  SyncDaemon->>SourceMap: find same-name sibling under parentGuid
  alt sibling found
    SyncDaemon->>Watcher: suppress next change event
    SyncDaemon->>FileSystem: rewrite sibling script file
    SyncDaemon->>SourceMap: upsert sibling subtree with prevPath
  end
Loading

Related issues: #51 – Same named GUID-suffixed object isn't renamed after the original object is removed.

Suggested labels: bug, enhancement

Suggested reviewers: none identified

🐰 A script named twice, one gone, one stayed,
No longer must it wear the GUID's shade,
Quietly renamed, its old self restored,
The sourcemap updated, the watcher ignored.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the rename-back behavior for GUID-suffixed scripts when a name conflict is removed.
Description check ✅ Passed The description directly references the linked issue and matches the change in the patch.
Linked Issues check ✅ Passed The code restores a remaining same-named sibling to its original name after the conflicting object is deleted, matching #51.
Out of Scope Changes check ✅ Passed No unrelated or extra changes are evident beyond the rename-after-delete fix required by the issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/index.ts`:
- Around line 312-314: The restore logic in the node handling path is matching
too broadly because getDescendantScripts(node.parentGuid) returns the full
subtree, not just direct siblings. In the block that builds sameNameScriptNodes,
update the filtering around node.parentGuid so only scripts with
sibling.parentGuid === node.parentGuid and the same name are considered, using
the existing tree lookup in this section to keep the restore restricted to true
siblings.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 33fe7b42-0c4d-42f3-8e0d-d6ab9e9ead74

📥 Commits

Reviewing files that changed from the base of the PR and between 144a61c and 9f16a9f.

📒 Files selected for processing (1)
  • src/index.ts

Comment thread src/index.ts
Comment on lines +312 to +314
if (node.parentGuid) {
const siblingScriptNodes = this.tree.getDescendantScripts(node.parentGuid);
const sameNameScriptNodes = siblingScriptNodes.filter(sibling => sibling.name === node.name);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Confirm getDescendantScripts recurses into grandchildren (not just direct children)
# and check TreeNode's parentGuid/name fields.
fd -e ts . src | xargs rg -n -A15 'getDescendantScripts' --type=ts
rg -n -B2 -A10 'interface TreeNode' --type=ts

Repository: Ransomwave/azul

Length of output: 3539


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the relevant implementations and types with line numbers.
sed -n '240,290p' src/fs/treeManager.ts
printf '\n----\n'
sed -n '300,345p' src/index.ts
printf '\n----\n'
rg -n -A20 -B5 'class FileWriter|getFilePath\\(|writeScript\\(|deleteScript\\(' src -t ts
printf '\n----\n'
rg -n -A12 -B4 'interface TreeNode|type TreeNode|class TreeNode' src -t ts

Repository: Ransomwave/azul

Length of output: 3149


Restrict this restore to direct siblings. getDescendantScripts(node.parentGuid) walks the full subtree, so sameNameScriptNodes can match a nested descendant under a child folder instead of a true sibling. Add a sibling.parentGuid === node.parentGuid check here.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/index.ts` around lines 312 - 314, The restore logic in the node handling
path is matching too broadly because getDescendantScripts(node.parentGuid)
returns the full subtree, not just direct siblings. In the block that builds
sameNameScriptNodes, update the filtering around node.parentGuid so only scripts
with sibling.parentGuid === node.parentGuid and the same name are considered,
using the existing tree lookup in this section to keep the restore restricted to
true siblings.

Repository owner deleted a comment from coderabbitai Bot Jul 3, 2026
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.

Same named GUID suffixed object isn't renamed after the original object is removed

2 participants