Repository navigation
Fix GetProjectRoot in GO - #16520
Fix GetProjectRoot in GO#16520
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthrough
ChangesProject root resolution
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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.
Inline comments:
In `@internal/utility/path.go`:
- Around line 26-29: `GetProjectRoot()` is treating `RAGFLOW_CONF_DIR` as a
project-root override even though the name suggests a conf directory, which
later causes `sql.go` to append an extra `conf` segment. Update the contract so
the symbol in `internal/utility/path.go` and its caller in `sql.go` agree:
either rename the env var to indicate project root override (for example,
`RAGFLOW_PROJECT_ROOT`) or change the caller to use the env value as the conf
path directly without joining `"conf"` again.
- Around line 30-37: The root/conf path resolution logic is inconsistent in the
path helper. Update the executable-path detection in the utility function that
calls os.Executable so it does not assume a <project_root>/bin layout and
instead resolves correctly for go test, go run, symlinks, and installed
binaries; also make RAGFLOW_CONF_DIR semantics consistent by treating it either
as the project root or the conf directory everywhere, but not both. Adjust the
callers that append "conf" so they no longer double-append when RAGFLOW_CONF_DIR
is set, and rename the test setup to use RAGFLOW_CONF_DIR instead of the old
RAG_PROJECT_BASE name.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5f54bd9c-ceba-4af0-9a1b-c96b1709837b
📒 Files selected for processing (2)
internal/engine/infinity/sql.gointernal/utility/path.go
53c24ae to
5aa750a
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
internal/utility/path.go (1)
33-40: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy liftExecutable-path fallback still breaks under
go test/go run/non-bin/layouts.
os.Executable()returns the test binary path undergo test(a temp directory), or thego runtemp build path — not<project_root>/bin/<binary>.filepath.Dir(filepath.Dir(exe))will silently resolve to an unrelated directory in those cases, and downstreamloadFieldMapping(sql.go) will get a wrongconfPath; since missing-file errors are swallowed (errors.Is(err, os.ErrNotExist)→ empty maps), this failure mode won't even surface as an error, just as unexpectedly empty mappings.This was already flagged in a previous review round and remains unresolved.
♻️ Possible fix direction
- // The binary is always at <project_root>/bin/, so going up 2 levels from - // the executable path gives the project root. - exe, err := os.Executable() - if err != nil { - return "." - } - return filepath.Dir(filepath.Dir(exe)) + // Fall back to resolving relative to this source file / working directory, + // or continue walking up for a go.mod marker, rather than assuming a + // fixed <project_root>/bin/ binary layout.🤖 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/utility/path.go` around lines 33 - 40, The fallback logic in the path helper still assumes the executable lives under a bin layout, which breaks for go test, go run, and other nonstandard executions. Update the logic in the executable-path helper (the function using os.Executable and filepath.Dir) to avoid deriving the project root from the binary path unless that layout is actually guaranteed, and prefer a more reliable source for the config root or an explicit fallback. Make sure the caller that builds confPath in loadFieldMapping can no longer receive a silently wrong directory.
🤖 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.
Duplicate comments:
In `@internal/utility/path.go`:
- Around line 33-40: The fallback logic in the path helper still assumes the
executable lives under a bin layout, which breaks for go test, go run, and other
nonstandard executions. Update the logic in the executable-path helper (the
function using os.Executable and filepath.Dir) to avoid deriving the project
root from the binary path unless that layout is actually guaranteed, and prefer
a more reliable source for the config root or an explicit fallback. Make sure
the caller that builds confPath in loadFieldMapping can no longer receive a
silently wrong directory.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 84e04410-c418-4e82-981e-924afbbb9aa1
📒 Files selected for processing (2)
internal/engine/infinity/sql.gointernal/utility/path.go
🚧 Files skipped from review as they are similar to previous changes (1)
- internal/engine/infinity/sql.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16520 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
5aa750a to
c63b461
Compare
c63b461 to
177b032
Compare
Summary
Fix GetProjectRoot in GO