Skip to content

fix: preserve symlink target when source is parent#46

Merged
fbosch merged 1 commit intomasterfrom
fix/symlink-target-empty
Apr 20, 2026
Merged

fix: preserve symlink target when source is parent#46
fbosch merged 1 commit intomasterfrom
fix/symlink-target-empty

Conversation

@fbosch
Copy link
Copy Markdown
Owner

@fbosch fbosch commented Apr 20, 2026

Summary

  • Fix applyTargetDir symlink mode to normalize empty relative targets ("") to ".".
  • Add regression coverage for sourceDir === dirname(targetDir) to assert symlink usability and link target.
  • This prevents broken symlinks introduced by relative-link generation when parent and source are the same directory.

Testing

  • pnpm build && pnpm test

Summary by CodeRabbit

  • Bug Fixes

    • Fixed symlink target path computation on non-Windows platforms to ensure proper resolution in edge cases.
  • Tests

    • Added test coverage for symlink handling on non-Windows systems.

Copilot AI review requested due to automatic review settings April 20, 2026 09:31
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ef3e73b5-5d07-47d0-93d1-2418c8eba8a4

📥 Commits

Reviewing files that changed from the base of the PR and between 533db8e and f9bc445.

📒 Files selected for processing (2)
  • src/cache/targets.ts
  • tests/targets.test.js

📝 Walkthrough

Walkthrough

A one-line fix normalizes empty relative paths to "." in symlink target computation for non-Windows platforms within applyTargetDir. A corresponding test case validates this behavior when a target directory's parent equals the source directory.

Changes

Cohort / File(s) Summary
Symlink Target Normalization
src/cache/targets.ts
Fixed symlink target path computation by normalizing empty relative paths to "." when sourceDir resolves to parentDir, ensuring non-empty link targets.
Test Coverage
tests/targets.test.js
Added test case verifying applyTargetDir behavior in symlink mode when target directory is a direct subdirectory of source, confirming readlink returns "." and file access works correctly.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 A dot in the path, so clever and slight,
When directories dance and align just right,
The symlink now whispers, "I am self-aware,"
No empty strings floating through the cool air! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing symlink target preservation when the source directory is the parent of the target directory.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/symlink-target-empty

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 and usage tips.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 20, 2026

Open in StackBlitz

npx https://pkg.pr.new/docs-cache@46

commit: f9bc445

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes symlink target generation in applyTargetDir so that when the computed relative target is an empty string (i.e., sourceDir === dirname(targetDir)), it normalizes to "." to avoid creating unusable symlinks. Adds a regression test to ensure the symlink both works (can read a file through it) and preserves the expected link target.

Changes:

  • Normalize non-Windows symlink targets from path.relative(...) to path.relative(...) || "." to handle the empty-string case.
  • Add a regression test covering sourceDir === dirname(targetDir) and asserting both symlink usability and readlink() target value.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tests/targets.test.js Adds regression coverage for the “source is target parent” symlink case.
src/cache/targets.ts Normalizes empty relative symlink targets to "." on non-Windows platforms.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fbosch fbosch merged commit bff9b5c into master Apr 20, 2026
20 checks passed
@fbosch fbosch deleted the fix/symlink-target-empty branch April 20, 2026 09:38
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