Skip to content

Fix GetProjectRoot in GO - #16520

Merged
JinHai-CN merged 1 commit into
infiniflow:mainfrom
qinling0210:fix_GetProjectRoot
Jul 1, 2026
Merged

JinHai-CN merged 1 commit into
infiniflow:mainfrom
qinling0210:fix_GetProjectRoot

Conversation

@qinling0210

Copy link
Copy Markdown
Contributor

Summary

Fix GetProjectRoot in GO

@qinling0210 qinling0210 self-assigned this Jul 1, 2026
@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a29eb5c4-22dc-4a21-8afc-535a08c680ed

📥 Commits

Reviewing files that changed from the base of the PR and between c63b461 and 177b032.

📒 Files selected for processing (2)
  • internal/engine/infinity/sql.go
  • internal/utility/path.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/utility/path.go
  • internal/engine/infinity/sql.go

📝 Walkthrough

Walkthrough

GetProjectRoot now resolves from the executable path and loadFieldMapping now uses that shared helper for its config path. The SQL engine’s local project-root helper was removed.

Changes

Project root resolution

Layer / File(s) Summary
Executable-based root derivation
internal/utility/path.go
GetProjectRoot now uses RAG_PROJECT_BASE, then RAG_DEPLOY_BASE, and otherwise derives the root from os.Executable() assuming a <project_root>/bin/ layout, with "." as the error fallback.
SQL config path uses shared utility
internal/engine/infinity/sql.go
loadFieldMapping imports internal/utility, resolves confPath with utility.GetProjectRoot(), and removes the old local projectBaseDir() helper.

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

Poem

Hop, hop, the root is found,
By executable path, not ground.
Into conf the bunny goes,
With fewer branches in its toes. 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description only repeats the title and lacks the required background or problem summary from the template. Expand the Summary with the bug context, why GetProjectRoot needed fixing, and the expected behavior after the change.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the change by stating that GetProjectRoot is being fixed in Go.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

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.

@qinling0210 qinling0210 added the ci Continue Integration label Jul 1, 2026
@qinling0210
qinling0210 marked this pull request as ready for review July 1, 2026 05:21
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 1, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8f24b30 and 53c24ae.

📒 Files selected for processing (2)
  • internal/engine/infinity/sql.go
  • internal/utility/path.go

Comment thread internal/utility/path.go Resolved
Comment thread internal/utility/path.go Resolved
@qinling0210
qinling0210 force-pushed the fix_GetProjectRoot branch from 53c24ae to 5aa750a Compare July 1, 2026 05:37

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
internal/utility/path.go (1)

33-40: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Executable-path fallback still breaks under go test/go run/non-bin/ layouts.

os.Executable() returns the test binary path under go test (a temp directory), or the go run temp build path — not <project_root>/bin/<binary>. filepath.Dir(filepath.Dir(exe)) will silently resolve to an unrelated directory in those cases, and downstream loadFieldMapping (sql.go) will get a wrong confPath; 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

📥 Commits

Reviewing files that changed from the base of the PR and between 53c24ae and 5aa750a.

📒 Files selected for processing (2)
  • internal/engine/infinity/sql.go
  • internal/utility/path.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/engine/infinity/sql.go

@codecov

codecov Bot commented Jul 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (b8e960e) to head (177b032).
⚠️ Report is 4 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@qinling0210
qinling0210 force-pushed the fix_GetProjectRoot branch from 5aa750a to c63b461 Compare July 1, 2026 07:18
@qinling0210
qinling0210 force-pushed the fix_GetProjectRoot branch from c63b461 to 177b032 Compare July 1, 2026 07:56
@JinHai-CN
JinHai-CN merged commit 5ba25a5 into infiniflow:main Jul 1, 2026
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants