Skip to content

fix(web): set correct intermediate directory paths in buildFileTree - #1708

Open
riteshvish02 wants to merge 1 commit into
sourcebot-dev:mainfrom
riteshvish02:fix/filetree-dir-path-corruption
Open

riteshvish02 wants to merge 1 commit into
sourcebot-dev:mainfrom
riteshvish02:fix/filetree-dir-path-corruption

Conversation

@riteshvish02

@riteshvish02 riteshvish02 commented Oct 3, 2026 •

Copy link
Copy Markdown

Fixes #1707

Summary

Fixes an issue where buildFileTree assigned leaf item paths to newly created intermediate directory nodes instead of their actual reconstructed directory path.

Root Cause

In packages/web/src/features/git/utils.ts, lines 68-74:

if (!next) {
    next = {
        name: part,
        path: item.path, // <--- Assigns leaf file path to directory
        type: nodeType,
        children: [],
    };
    current.children.push(next);
}

When processing a flat list containing nested paths like src/components/buttons/PrimaryButton.tsx, intermediate directory nodes src and components had path: "src/components/buttons/PrimaryButton.tsx" instead of "src" and "src/components".

Impact

  • In fileTreePanel.tsx, folder expand/collapse state tracking openPaths.has(node.path) and route sync failed for intermediate directories.
  • In the public git tree API (getTree), consumers received corrupted FileTreeNode paths for directory nodes.

Changes

  • Updated path in buildFileTree to parts.slice(0, i + 1).join('/').
  • Added unit test in packages/web/src/features/git/utils.test.ts verifying that intermediate directory nodes retain their correct parent paths.

Note

Low Risk
Small path-construction bugfix in git file-tree utilities with added regression test; no auth or data-handling changes.

Overview
Fixes buildFileTree so newly created intermediate directory nodes get path values built from the path segments walked so far (parts.slice(0, i + 1).join('/')), instead of inheriting the leaf file’s full path.

That restores correct folder keys for browse UI expand/collapse (openPaths.has(node.path)) and for getTree consumers that rely on directory FileTreeNode.path. A focused unit test covers nested paths like src/components/buttons/….

Reviewed by Cursor Bugbot for commit 2cdd153. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected paths for nested directories and files in the file tree, so each entry reflects its own location.

When constructing the file tree from a flat list in buildFileTree, new intermediate directory nodes were assigned item.path (the path of the leaf item being processed) instead of their actual directory path.

This caused intermediate directory nodes to have full file paths instead of their directory path (e.g. directory 'src' receiving path 'src/components/Button.tsx'), breaking folder expansion state tracking (openPaths.has(node.path)) and corrupting directory paths returned by getTree.

Reconstruct the node path using parts.slice(0, i + 1).join('/') so both directories and leaves have the correct path.
@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e6a110f0-7efb-4e49-8ec6-4e3af4ce2661
📥 Commits

Reviewing files that changed from the base of the PR and between b4d1a02 and 2cdd153.

📒 Files selected for processing (2)
  • packages/web/src/features/git/utils.test.ts
  • packages/web/src/features/git/utils.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.


Walkthrough

buildFileTree now assigns each node the path prefix through its current segment. A new test checks the paths and types of nested directory nodes and a leaf file.

Changes

File tree path correction

Layer / File(s) Summary
Build and verify node paths
packages/web/src/features/git/utils.ts, packages/web/src/features/git/utils.test.ts
buildFileTree assigns each node its accumulated path prefix. The test checks intermediate directory paths and types, and the leaf file path and type.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 2cdd1

This change corrects directory paths in file trees and adds focused nested-path coverage. No remaining merge-blocking risk is evident.

Security Architecture Review

Security architecture risk: ⚪ Minimal · up to 2cdd1

The corrected directory paths preserve the existing repository-access boundary. No material security risk was identified in the reviewed change.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed values affect logical locations within the selected repository's tree, including browse links and expansion queries. They do not introduce a new tenant selector, filesystem root, or privileged operation.

Trust Boundaries and Controls

  • observed — The public tree route validates the request schema. getTree runs inside the existing optional-authentication wrapper, looks up the repository using the current organization ID, checks revision and requested paths, and supplies normalized paths after git's argument separator. The path-prefix correction occurs downstream of these controls.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the fix: correcting intermediate directory paths in buildFileTree.
Linked Issues check ✅ Passed Issue #1707 requires intermediate directory nodes to use their reconstructed directory paths. buildFileTree now uses parts.slice(0, i + 1).join('/') when creating each node. The added test checks …
Out of Scope Changes check ✅ Passed The diff changes only buildFileTree path construction and adds a regression test for issue #1707. Both changes directly support the issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

This branch has not been deployed

No deployments
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.

bug(web): Intermediate directory nodes in buildFileTree receive child leaf paths instead of directory paths

1 participant