Skip to content

fix(file): accept absolute paths and show the server's reason for missing source - #69

Merged
alerizzo merged 1 commit into
mainfrom
fix/file-path-and-source-reason
Nov 11, 2026
Merged

alerizzo merged 1 commit into
mainfrom
fix/file-path-and-source-reason

Conversation

@alerizzo

Copy link
Copy Markdown
Collaborator

Follow-up to #68: these review fixes were finished locally but not pushed before #68 merged.

Changes

  • Absolute paths: with an auto-detected repository, codacy file /abs/path/to/repo/src/a.ts is resolved against the git root (shell completion and editors pass absolute paths). A local path that ends up outside the repository (../../x.ts, /etc/passwd) is refused before any request.
  • Source-unavailable reason: Source not available (…) now shows the server's message via errorReason(err), not the generated client's static status name (e.g. Payload Too Large).
  • Docs: SPECS/commands/file.md, src/commands/AGENTS.md, SPECS/README.md changelog.
  • Changeset: the file command is unreleased, so the existing file-command.md changeset is extended rather than adding a separate patch.

Tests

+2 tests in file.test.ts (absolute path, outside-repo refusal) and the source-error test updated to the server's reason. tsc --noEmit clean, 854/854 passing.

🤖 Generated with Claude Code

…sing source

- Resolve an absolute path against the git root when the repository is
  auto-detected; refuse a path outside the repository before any request.
- "Source not available (...)" now shows the server's message via
  errorReason() instead of the client's static status name.
- These were review-round-2 fixes left uncommitted when #68 merged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 6 complexity · 0 duplication

Metric Results
Complexity 6
Duplication 0

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@codacy-production codacy-production 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.

Pull Request Overview

👀 Worth a closer look

Two medium-severity portability issues remain in path validation: cross-drive paths may bypass the outside-repository check on Windows, and symlinked paths inside the repository may be rejected. These do not indicate a general acceptance-criteria gap, but they warrant review for cross-platform correctness.

Test suggestions

  • Resolve an absolute path inside the Git repository to a repository-relative path.
  • Reject relative and absolute paths outside the detected repository.
  • Keep explicit-repository paths repository-relative.
  • Display the server's message when source retrieval fails.
  • Continue rendering issues when source retrieval fails.

TIP How was this review? Give us feedback

Comment thread src/commands/file.ts
let joined: string;
if (path.isAbsolute(trimmed)) {
const root = getGitRepoRoot();
joined = root ? path.relative(root, trimmed).split(path.sep).join("/") : "..";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 MEDIUM RISK

An absolute path through a symlink to the repository is rejected even when it names a file inside the repository. Consider resolving symlink aliases before comparing the path with the git root.

TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.

Comment thread src/commands/file.ts
} else {
joined = path.posix.join(getCwdRepoRelativePath(), trimmed);
}
if (joined === ".." || joined.startsWith("../")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 MEDIUM RISK

On Windows, an absolute path on another drive is not rejected as outside the repository because path.relative returns an absolute path rather than ../.... Consider rejecting an absolute joined result as well.

TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.

@alerizzo
alerizzo merged commit 684c852 into main Nov 11, 2026
4 checks passed
@alerizzo
alerizzo deleted the fix/file-path-and-source-reason branch November 11, 2026 15:03
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