Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,36 @@ export class SyncDaemon {
}
}

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

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.


if (sameNameScriptNodes.length !== 0) {
// SN meaning same name
const scriptToRename = sameNameScriptNodes.at(-1);
if (scriptToRename) {
const oldFilePaths = scriptToRename.path;
const newFilePath = this.fileWriter.getFilePath(scriptToRename);

if (oldFilePaths.length !== 0) {
// Write new one path
this.fileWatcher.suppressNextChange(newFilePath, scriptToRename.source);
this.fileWriter.writeScript(scriptToRename);

// Upsert the subtree into the sourcemap
this.sourcemapGenerator.upsertSubtree(
scriptToRename,
this.tree.getAllNodes(),
this.fileWriter.getAllMappings(),
config.sourcemapPath,
oldFilePaths,
false,
);
}
}
}
}

this.fileWriter.cleanupEmptyDirectories();
}

Expand Down