Skip to content

fix(tool): resolve file_read paths against git top-level in monorepos#2

Open
chethanuk wants to merge 2 commits into
mainfrom
fix/issue-287-file-read-monorepo
Open

fix(tool): resolve file_read paths against git top-level in monorepos#2
chethanuk wants to merge 2 commits into
mainfrom
fix/issue-287-file-read-monorepo

Conversation

@chethanuk

@chethanuk chethanuk commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Description

Running ocr review from a subdirectory of a monorepo failed with file not found (alibaba#287). Git reports diff paths and git show HEAD:<path> paths relative to the repository root, but RepoDir was scoped to the invocation subdirectory. Joining a root-relative path onto a subdirectory RepoDir produced a double prefix (e.g. repo/subproject1/subproject1/src/...), so both disk reads and git-show reads missed the file.

Fix: resolveWorkingDir now anchors RepoDir at the git top-level via git rev-parse --show-toplevel on the review path (requireGit=true). ocr scan (requireGit=false) deliberately keeps the CWD so its git ls-files walk stays scoped to the subdirectory.

Two robustness details:

  • The top-level lookup goes through a stdout-only git helper (runGitCmdStdout, using cmd.Output()) so git's stderr notices (permissions, deprecations, config warnings) can't pollute the resolved path.
  • If --show-toplevel errors or returns nothing — e.g. a bare repo, where --git-dir succeeds but there is no work tree — resolution now fails loudly instead of silently reusing the subdirectory and reproducing the original bug.
flowchart TD
    A[resolveWorkingDir input, requireGit] --> B[filepath.Abs + os.Stat]
    B --> C[git rev-parse --git-dir]
    C --> D{is git repo?}
    D -- no, requireGit=true --> E[error: not a git repository]
    D -- no, requireGit=false --> F[return subdir, isGit=false]
    D -- yes, requireGit=false scan --> G[return subdir, isGit=true<br/>git ls-files stays scoped]
    D -- yes, requireGit=true review --> H[git rev-parse --show-toplevel<br/>stdout only]
    H --> I{ok and non-empty?}
    I -- yes --> J[RepoDir = git top-level<br/>fix for #287]
    I -- no --> K[return error<br/>fail loudly, no silent fallback]
    J --> L[return repo root, isGit=true]
Loading

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

How Has This Been Tested?

go test ./cmd/opencodereview/ ./internal/tool/ — 592 tests pass; gofmt -l clean; go vet clean.

New regression tests:

  • TestResolveWorkingDir_MonorepoSubdir — review path hoists to the git top-level; scan path keeps the subdirectory.

  • TestResolveWorkingDir_BareRepoFailsLoudly — bare repo (--git-dir ok, --show-toplevel fails) returns an error rather than silently falling back.

  • TestFileReader_Read_CommitMode_MonorepoSubdirPathgit show HEAD:<root-relative-path> and workspace disk reads both resolve, the exact command from the issue.

  • make test passes locally

  • Manual testing (described above)

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (if applicable)
  • I have signed the CLA

Related Issues

closes alibaba#287

Summary by CodeRabbit

  • Bug Fixes
    • Improved path handling in review mode for monorepos so repositories opened from subdirectories correctly resolve to the git top-level.
    • Cleaned up git command output handling to prevent unrelated git messages from interfering with results.
    • More reliably errors when the target repository has no usable working tree (e.g., bare repos), instead of silently continuing.
  • Tests
    • Added coverage for monorepo subdirectory resolution and commit/workspace file reading behavior.
    • Added coverage ensuring bare repository cases fail as expected.
  • Documentation
    • Clarified monorepo rule loading behavior in review mode.

@codeant-ai

codeant-ai Bot commented Jul 6, 2026

Copy link
Copy Markdown

CodeAnt AI is reviewing your PR.

@codeant-ai

codeant-ai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1e761351-32a7-4678-a70f-7ca9edcdcbd9

📥 Commits

Reviewing files that changed from the base of the PR and between 1462a5e and 1c92e47.

📒 Files selected for processing (1)
  • internal/config/rules/system_rules.go
✅ Files skipped from review due to trivial changes (1)
  • internal/config/rules/system_rules.go

📝 Walkthrough

Walkthrough

Adds a stdout-only git helper, anchors review-mode working-directory resolution to the git repository top-level, reuses that resolution in resolveRepoDir, and adds tests plus a rule-loading comment for monorepo subdirectory behavior.

Changes

Monorepo Subdirectory Path Resolution

Layer / File(s) Summary
Stdout-only git helper
cmd/opencodereview/git.go
Adds runGitCmdStdout, mirroring runGitCmd's git -C argument construction but returning only stdout via cmd.Output().
Anchor review paths at the git top-level
cmd/opencodereview/shared.go
Adds strings trimming and updates resolveWorkingDir to run git rev-parse --show-toplevel when requireGit is true, assign the trimmed repository root to absPath, and error when that lookup fails or is empty.
Reuse shared resolution in repo lookup
cmd/opencodereview/review_cmd.go
Replaces resolveRepoDir's direct git-dir validation with a call to resolveWorkingDir(input, true) and returns the resolved repository-top-level path.
Monorepo path tests
cmd/opencodereview/shared_test.go, internal/tool/filereader_read_test.go
Adds tests for anchored repo resolution, bare-repo failure, and FileReader.Read with repo-root-relative paths in commit and workspace modes.
Monorepo rule-loading note
internal/config/rules/system_rules.go
Updates the loadProjectRule comment to describe monorepo execution from a subdirectory and the use of the git top-level rule.json.

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

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main monorepo path-resolution fix.
Description check ✅ Passed The description matches the template and covers the change, testing, checklist, and related issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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/issue-287-file-read-monorepo

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.

@codeant-ai codeant-ai Bot added the size:L This PR changes 100-499 lines, ignoring generated files label Jul 6, 2026

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request addresses issue alibaba#287 by anchoring the repository directory at the git top-level when running ocr review from a subdirectory of a monorepo, ensuring root-relative paths resolve correctly. It also adds comprehensive tests to verify this behavior. The reviewer pointed out a potential issue where using runGitCmd to retrieve the top-level path could pollute the path string with stderr warnings or errors. They suggested executing the command directly with exec.Command and capturing only stdout, which is a safer and more robust approach.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread cmd/opencodereview/shared.go
Comment thread cmd/opencodereview/shared.go
@codeant-ai

codeant-ai Bot commented Jul 6, 2026

Copy link
Copy Markdown

CodeAnt AI finished reviewing your PR.

@greptile-apps

greptile-apps Bot commented Jul 6, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes a double-prefix path bug (alibaba#287) that caused ocr review to fail with "file not found" when run from a monorepo subdirectory. The fix anchors RepoDir at the git top-level (via git rev-parse --show-toplevel) for review runs, while scan runs deliberately keep the CWD to preserve their scoped git ls-files walk.

  • cmd/opencodereview/git.go: Adds runGitCmdStdout — a stdout-only variant of runGitCmd so git stderr warnings cannot corrupt path-resolution output.
  • cmd/opencodereview/shared.go: resolveWorkingDir now calls --show-toplevel (stdout-only) when requireGit=true and overrides absPath with the canonical repo root on success; failures fall back silently to the caller-provided directory.
  • Tests: Two regression tests added — TestResolveWorkingDir_MonorepoSubdir (hoisting behavior for review vs. scan) and TestFileReader_Read_CommitMode_MonorepoSubdirPath (git-show resolution of root-relative paths) — with proper EvalSymlinks error handling for macOS symlink normalization.

Confidence Score: 4/5

Safe to merge for the core monorepo path-fix; a known silent-fallback edge case and a rule.json lookup behavior change in subdirectory-based workflows should be reviewed before landing.

The path-resolution fix is correct and well-tested. Two open concerns carry real user-facing impact: (1) if rev-parse --show-toplevel fails after --git-dir succeeds, the function returns the subdirectory with no signal to the caller, silently reproducing the original bug for bare-repo or certain worktree setups; (2) rules.NewResolver now receives the git root instead of the subdirectory, so per-project rule.json files placed in monorepo subdirectories are silently ignored on review runs — a behavior change for existing users. Both were flagged in previous review rounds and remain unaddressed.

cmd/opencodereview/shared.go — the rev-parse --show-toplevel silent-fallback path and the downstream rules.NewResolver call that now receives the git root.

Important Files Changed

Filename Overview
cmd/opencodereview/git.go Adds runGitCmdStdout that uses cmd.Output() to capture stdout only, preventing git stderr warnings from polluting path-resolution results.
cmd/opencodereview/shared.go Core fix: when requireGit=true, resolveWorkingDir now anchors RepoDir at the git top-level via rev-parse --show-toplevel; failure silently falls back to the CWD (already flagged) and the rules.NewResolver path shift is a noted concern.
cmd/opencodereview/shared_test.go Regression test for monorepo subdirectory hoist (review path) vs. CWD retention (scan path); EvalSymlinks errors are now properly fataled.
internal/tool/filereader_read_test.go Regression test for git-show layer: verifies that a root-relative monorepo path resolves correctly in both commit mode and workspace mode when RepoDir is set to the git top-level.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["resolveWorkingDir(input, requireGit)"] --> B["filepath.Abs(input)"]
    B --> C["os.Stat(absPath)"]
    C --> D["git rev-parse --git-dir\n(CombinedOutput)"]
    D --> E{isGit?}
    E -- "No + requireGit=true" --> F["Error: not a git repo"]
    E -- "No + requireGit=false" --> G["return absPath, false"]
    E -- "Yes" --> H{requireGit?}
    H -- "false (scan path)" --> I["return absPath (subdirectory)\nisGit=true\ngit ls-files stays scoped"]
    H -- "true (review path)" --> J["git rev-parse --show-toplevel\n(stdout-only via runGitCmdStdout)"]
    J --> K{topErr == nil\n&& t != empty?}
    K -- "Yes" --> L["absPath = git top-level\n(fix for #287)"]
    K -- "No (bare repo,\nworktree edge case)" --> M["absPath unchanged\n(silent fallback)"]
    L --> N["return absPath (git root), true"]
    M --> N
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A["resolveWorkingDir(input, requireGit)"] --> B["filepath.Abs(input)"]
    B --> C["os.Stat(absPath)"]
    C --> D["git rev-parse --git-dir\n(CombinedOutput)"]
    D --> E{isGit?}
    E -- "No + requireGit=true" --> F["Error: not a git repo"]
    E -- "No + requireGit=false" --> G["return absPath, false"]
    E -- "Yes" --> H{requireGit?}
    H -- "false (scan path)" --> I["return absPath (subdirectory)\nisGit=true\ngit ls-files stays scoped"]
    H -- "true (review path)" --> J["git rev-parse --show-toplevel\n(stdout-only via runGitCmdStdout)"]
    J --> K{topErr == nil\n&& t != empty?}
    K -- "Yes" --> L["absPath = git top-level\n(fix for #287)"]
    K -- "No (bare repo,\nworktree edge case)" --> M["absPath unchanged\n(silent fallback)"]
    L --> N["return absPath (git root), true"]
    M --> N
Loading

Reviews (3): Last reviewed commit: "test: fail loudly if EvalSymlinks errors..." | Re-trigger Greptile

Comment thread cmd/opencodereview/shared.go
Comment thread cmd/opencodereview/shared_test.go Outdated

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
cmd/opencodereview/git.go (1)

15-23: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Add a timeout via exec.CommandContext (noctx).

Static analysis flags exec.Command on line 20; os/exec.Command should be replaced with os/exec.CommandContext to allow cancellation/timeout. Without it, this call can block indefinitely (e.g. hung git process, credential prompt) on the review request path.

🔧 Proposed fix (bounded timeout, no signature change)
+import (
+	"context"
+	"os/exec"
+	"time"
+)
+
 // runGitCmdStdout is like runGitCmd but returns stdout only. Use it when the
 // output is consumed as data (e.g. a resolved path) so git's stderr warnings
 // (permissions, deprecations, config notices) can't pollute the result.
 func runGitCmdStdout(repoDir string, args ...string) ([]byte, error) {
 	fullArgs := append([]string{"-C", repoDir}, args...)
-	cmd := exec.Command("git", fullArgs...)
+	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+	defer cancel()
+	cmd := exec.CommandContext(ctx, "git", fullArgs...)
 	return cmd.Output()
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/opencodereview/git.go` around lines 15 - 23, The runGitCmdStdout helper
currently uses exec.Command directly, so the git process cannot be cancelled and
may hang the review path. Update runGitCmdStdout in git.go to create the command
with exec.CommandContext using a bounded context timeout, while keeping the same
function signature and preserving the current stdout-only behavior. Make sure
the context is created locally inside runGitCmdStdout and applied to the
existing git invocation built from repoDir and args.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cmd/opencodereview/git.go`:
- Around line 15-23: The runGitCmdStdout helper currently uses exec.Command
directly, so the git process cannot be cancelled and may hang the review path.
Update runGitCmdStdout in git.go to create the command with exec.CommandContext
using a bounded context timeout, while keeping the same function signature and
preserving the current stdout-only behavior. Make sure the context is created
locally inside runGitCmdStdout and applied to the existing git invocation built
from repoDir and args.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 04a29c23-2d2d-406b-a519-d623173d12b6

📥 Commits

Reviewing files that changed from the base of the PR and between 10f5875 and 1e050f0.

📒 Files selected for processing (4)
  • cmd/opencodereview/git.go
  • cmd/opencodereview/shared.go
  • cmd/opencodereview/shared_test.go
  • internal/tool/filereader_read_test.go

@chethanuk
chethanuk force-pushed the fix/issue-287-file-read-monorepo branch 2 times, most recently from a27296e to 4cc0b24 Compare July 6, 2026 11:04

@greptile-apps greptile-apps 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.

chethanuk has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@lizhengfeng101

Copy link
Copy Markdown

Hi @chethanuk 👋

We noticed you're also fixing alibaba#287 — and it turns out we landed on the exact same approach independently: anchoring RepoDir at the git top-level via git rev-parse --show-toplevel on the review path, while keeping the CWD scope for ocr scan (requireGit=false). We opened alibaba#308 for the same issue.

Your version also handles a detail ours doesn't — reading the top-level through a stdout-only git helper so stderr notices can't pollute the resolved path. Nice touch.

Since your fix is effectively a superset, we'd be happy to close ours in favor of yours. Could you open your PR against alibaba/open-code-review when you get a chance? Once it's up (or merged), we'll close alibaba#308. Thanks for the work here! 🙏

ocr review from a monorepo subdirectory failed with "file not found" (alibaba#287):
git reports diff and `git show HEAD:<path>` paths relative to the repo root,
but RepoDir was scoped to the invocation subdirectory, producing a double
prefix. resolveWorkingDir now anchors RepoDir at `git rev-parse
--show-toplevel` on the review path (requireGit=true); scan keeps the CWD so
its `git ls-files` walk stays scoped.

The top-level lookup uses a stdout-only git helper so stderr notices can't
pollute the path, and fails loudly if --show-toplevel errors or is empty
(e.g. a bare repo) instead of silently reusing the subdirectory. Adds
regression tests for the subdir hoist, the scan-path scoping, git-show
resolution of root-relative paths, and the bare-repo failure.
@chethanuk
chethanuk force-pushed the fix/issue-287-file-read-monorepo branch from 4cc0b24 to 1462a5e Compare July 6, 2026 13:05

@greptile-apps greptile-apps 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.

chethanuk has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (2)
cmd/opencodereview/git.go (1)

15-22: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Use exec.CommandContext with a timeout for the git subprocess.

Static analysis flags Line 20 for using exec.Command instead of exec.CommandContext. Since this call has no timeout, a hung/slow git process (e.g. due to FS issues) blocks callers indefinitely. This mirrors the existing pattern in runGitCmd (Lines 9-13), so consider addressing both together.

♻️ Proposed fix
-func runGitCmdStdout(repoDir string, args ...string) ([]byte, error) {
-	fullArgs := append([]string{"-C", repoDir}, args...)
-	cmd := exec.Command("git", fullArgs...)
-	return cmd.Output()
-}
+func runGitCmdStdout(repoDir string, args ...string) ([]byte, error) {
+	ctx, cancel := context.WithTimeout(context.Background(), gitCmdTimeout)
+	defer cancel()
+	fullArgs := append([]string{"-C", repoDir}, args...)
+	cmd := exec.CommandContext(ctx, "git", fullArgs...)
+	return cmd.Output()
+}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/opencodereview/git.go` around lines 15 - 22, runGitCmdStdout currently
uses exec.Command without any cancellation, so a stuck git process can hang
callers indefinitely. Update runGitCmdStdout to take a context and use
exec.CommandContext, matching the timeout/cancellation pattern already used by
runGitCmd, and then adjust any call sites as needed so both helpers share the
same subprocess lifecycle behavior.

Source: Linters/SAST tools

internal/tool/filereader_read_test.go (1)

220-273: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Test doesn't actually exercise the #287 anchoring bug it claims to reproduce.

The docstring says this "reproduces #287 at the git-show layer," but the setup never simulates the buggy scenario: git is inited directly in dir, and FileReader{RepoDir: dir, ...} uses dir as-is — already the correct top-level. The original bug required RepoDir to be mis-anchored to a subdirectory (causing double-prefixed paths like subproject1/subproject1/...); this test would pass identically even without this PR's fix, as long as RepoDir happened to equal the repo root. It does add useful new coverage for multi-segment root-relative paths in commit mode, but it doesn't guard the actual anchoring regression — that's only covered by TestResolveWorkingDir_MonorepoSubdir in shared_test.go. Since internal/tool can't import the unexported resolveWorkingDir from cmd/opencodereview (package main) to derive a realistically mis/correctly-anchored RepoDir, true end-to-end coverage isn't feasible here — consider softening the docstring to avoid overstating what's being protected.

✏️ Suggested docstring tweak
-// TestFileReader_Read_CommitMode_MonorepoSubdirPath reproduces `#287` at the
-// git-show layer: in a monorepo, git reports paths relative to the repo root
-// (e.g. "subproject1/src/models/request_meta.py"). With RepoDir anchored at the
-// git top-level (the fix), `git show HEAD:<root-relative-path>` must resolve —
-// this is the exact command that failed in the issue.
+// TestFileReader_Read_CommitMode_MonorepoSubdirPath verifies that, once RepoDir
+// is anchored at the git top-level (see TestResolveWorkingDir_MonorepoSubdir for
+// the actual `#287` anchoring regression guard), `git show HEAD:<root-relative-path>`
+// resolves correctly for multi-segment paths in both commit and workspace modes.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/tool/filereader_read_test.go` around lines 220 - 273, The test
name/comment overstates that TestFileReader_Read_CommitMode_MonorepoSubdirPath
reproduces the `#287` anchoring regression, but the current setup uses RepoDir at
the git root so it would pass even without the fix. Update the docstring in
TestFileReader_Read_CommitMode_MonorepoSubdirPath (and any nearby comments) to
describe it as coverage for root-relative commit/workspace paths in a monorepo,
not the anchoring bug itself, and avoid claiming it exercises the exact git-show
failure from `#287`.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cmd/opencodereview/git.go`:
- Around line 15-22: runGitCmdStdout currently uses exec.Command without any
cancellation, so a stuck git process can hang callers indefinitely. Update
runGitCmdStdout to take a context and use exec.CommandContext, matching the
timeout/cancellation pattern already used by runGitCmd, and then adjust any call
sites as needed so both helpers share the same subprocess lifecycle behavior.

In `@internal/tool/filereader_read_test.go`:
- Around line 220-273: The test name/comment overstates that
TestFileReader_Read_CommitMode_MonorepoSubdirPath reproduces the `#287` anchoring
regression, but the current setup uses RepoDir at the git root so it would pass
even without the fix. Update the docstring in
TestFileReader_Read_CommitMode_MonorepoSubdirPath (and any nearby comments) to
describe it as coverage for root-relative commit/workspace paths in a monorepo,
not the anchoring bug itself, and avoid claiming it exercises the exact git-show
failure from `#287`.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ee81d5c6-4694-412e-acd7-ea6f86612fa0

📥 Commits

Reviewing files that changed from the base of the PR and between 1e050f0 and 1462a5e.

📒 Files selected for processing (5)
  • cmd/opencodereview/git.go
  • cmd/opencodereview/review_cmd.go
  • cmd/opencodereview/shared.go
  • cmd/opencodereview/shared_test.go
  • internal/tool/filereader_read_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/opencodereview/shared.go

Since alibaba#287 anchored RepoDir at the git top-level, ocr review from a
monorepo subdirectory loads the repo-root .opencodereview/rule.json
rather than a subdir-local one. Call out this user-visible behavior at
loadProjectRule so the scope change isn't a surprise (review feedback).
@codeant-ai

codeant-ai Bot commented Jul 7, 2026

Copy link
Copy Markdown

CodeAnt AI is running Incremental review

@codeant-ai

codeant-ai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@greptile-apps greptile-apps 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.

chethanuk has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

file_read call failures in a monorepo

2 participants