Skip to content

Reject renaming a file over a directory - #23

Merged
Project516 merged 1 commit into
masterfrom
p516/memory-rename
Nov 3, 2026
Merged

Project516 merged 1 commit into
masterfrom
p516/memory-rename

Conversation

@Project516

Copy link
Copy Markdown
Owner

Renaming a file over a directory in the memory filesystem succeeds and leaves the same path in both the file and directory maps. Reject that rename before changing either entry.

A regression test checks that the file and directory stay intact and that replacing another file still works.

Test: node --test test/fs.test.ts.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • File renames now fail when the destination is an existing directory, preserving the file and directory contents. Renaming onto another file continues to work.

MemoryBackend.rename now returns false when a file is renamed onto an existing directory. A test verifies that this operation preserves the file and directory, and that renaming onto another file succeeds with the source contents at the destination.

Changes: Rename behavior

Layer / File(s) Summary
Destination validation and test
src/fs.ts, test/fs.test.ts
MemoryBackend.rename rejects a destination that is an existing directory. The test checks that the failed rename preserves the file, directory, and directory child. It also checks that renaming onto another file succeeds and preserves the source contents at the destination.

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

Change: Bug fix

Suggested reviewers: project516-review-bot

Merge Risk: Minimal · up to ab747

The change is ready to merge subject to normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title "Reject renaming a file over a directory" matches the main change in src/fs.ts. MemoryBackend.rename now rejects a rename when the destination is an existing directory. The test/fs.test.ts c…
Description check Passed The description states the bug, which is that renaming a file over a directory succeeds and leaves the same path in both maps. It says the fix rejects that rename before either entry changes. It also …
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Reject renaming a file over a directory" matches the main change in src/fs.ts. MemoryBackend.rename now rejects a rename when the destination is an existing directory. The test/fs.test.ts change covers this case.

Full details: Description check

Explanation

The description states the bug, which is that renaming a file over a directory succeeds and leaves the same path in both maps. It says the fix rejects that rename before either entry changes. It also describes the regression test and the test command. This matches the src/fs.ts and test/fs.test.ts changes.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Simplify code
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ast-grep (0.51.1)

ast-grep could not parse rule config: /ast-grep-rules/ast-grep-essentials/rules/c/security/sizeof-this-c.yml

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

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

A rabbit checks the path ahead,
A directory blocks the way.
The file stays safe, its name unchanged,
Another file can take its place.
The rabbit hops through tested paths.

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 14f0dd30-1ef0-4dc6-8042-bfdb99853bad
Commits

Reviewing files that changed from the base of the PR and between cf6854f and ab747db.

Files selected for processing: 2
  • src/fs.ts
  • test/fs.test.ts

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

Recent review details
Context from checks skipped due to timeout: 8
  • GitHub Check: jtreg / run (3)
  • GitHub Check: jtreg / run (1)
  • GitHub Check: jtreg / run (4)
  • GitHub Check: jtreg / run (2)
  • GitHub Check: CodeRabbit
  • GitHub Check: test
  • GitHub Check: Analyze (java-kotlin)
  • GitHub Check: Analyze (javascript-typescript)
Additional comments: 2
src/fs.ts: 1

259-259: LGTM!

test/fs.test.ts: 1

1-19: LGTM!

@project516-review-bot project516-review-bot Bot 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.

The PR fixes a bug in MemoryBackend.rename where renaming a file onto an existing directory would succeed and corrupt the filesystem state by leaving the same path in both the file and directory maps. The fix adds a check to reject the rename when the target path is already a directory. A regression test verifies the file and directory remain intact after a failed rename, and that renaming a file over another file still works.


review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict approve

@Project516
Project516 merged commit 865a77f into master Nov 3, 2026
12 checks passed
@Project516
Project516 deleted the p516/memory-rename branch November 3, 2026 01:21
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.

1 participant

⌂ Proxy