Skip to content

fix: allow creating new files in nested non-existent directories - #1741

Open
Juwan-Hwang wants to merge 1 commit into
anthropics:mainfrom
Juwan-Hwang:fix/validate-nested-new-file-paths
Open

fix: allow creating new files in nested non-existent directories#1741
Juwan-Hwang wants to merge 1 commit into
anthropics:mainfrom
Juwan-Hwang:fix/validate-nested-new-file-paths

Conversation

@Juwan-Hwang

@Juwan-Hwang Juwan-Hwang commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Problem

When validating paths for new files that have not yet been created, validatePathWithinRepo fell back to calling realpath(parentDir) on the immediate parent directory.

If a new file is being created inside nested directories that do not yet exist (for example src/components/button/index.tsx where neither components/ nor button/ has been created yet), realpath(parentDir) threw ENOENT, which was caught and caused the function to incorrectly reject the valid path with Path '...' resolves outside the repository root.

Solution

Update validatePathWithinRepo to walk up the directory tree to find the closest existing ancestor directory:

  • Recursively inspect parent directories until an existing ancestor directory is found.
  • Verify that the resolved ancestor directory resides within resolvedRoot.
  • Return initialPath for the non-existent target path once the ancestor is validated.

Testing

  • Added unit tests for new files in nested non-existent directories under existing directories (src/components/button/index.tsx).
  • Added unit tests for new files in deeply nested non-existent directories from repo root (deeply/nested/non/existent/dir/file.txt).
  • Verified path traversal attacks (../outside/...) and escaping symlinks continue to be correctly rejected for non-existent nested paths.
  • Verified valid internal symlinks to directories continue to accept nested new files.
  • All path validation unit tests pass (27 pass, 0 fail).
  • All format and TypeScript checks pass (bun run format:check, bun run typecheck).

Copilot AI lite review requested due to automatic review settings August 27, 2026 17:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

2 participants