diff --git a/internal/engine/infinity/sql_test.go b/internal/engine/infinity/sql_test.go index 727d285a92..f072d1c47f 100644 --- a/internal/engine/infinity/sql_test.go +++ b/internal/engine/infinity/sql_test.go @@ -376,6 +376,12 @@ func TestLoadFieldMapping_ParsesAliases(t *testing.T) { } func TestLoadFieldMapping_EmptyNameDefaultsToInfinityMappingJSON(t *testing.T) { + // Ensure the test runs in an isolated project base so any repo file + // named "infinity_mapping.json" doesn't get picked up. + dir := t.TempDir() + os.Setenv("RAG_PROJECT_BASE", dir) + defer os.Unsetenv("RAG_PROJECT_BASE") + // Empty name → defaults to "infinity_mapping.json" (line 145). // We just verify the function doesn't panic and the file-not-found // path is taken silently. diff --git a/internal/utility/path.go b/internal/utility/path.go index b7baf93424..d913a26674 100644 --- a/internal/utility/path.go +++ b/internal/utility/path.go @@ -19,11 +19,15 @@ package utility import ( "os" "path/filepath" + "runtime" ) // GetProjectRoot returns the project root directory func GetProjectRoot() string { // Try environment variable first + if confDir := os.Getenv("RAGFLOW_CONF_DIR"); confDir != "" { + return confDir + } if d := os.Getenv("RAG_PROJECT_BASE"); d != "" { return d } @@ -31,8 +35,23 @@ func GetProjectRoot() string { return d } - // The binary is always at /bin/, so going up 2 levels from - // the executable path gives the project root. + // Find project root by looking for go.mod from this source file. + _, curFile, _, ok := runtime.Caller(0) + if ok { + dir := filepath.Dir(curFile) + for { + if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil { + return dir + } + parent := filepath.Dir(dir) + if parent == dir { + break + } + dir = parent + } + } + + // Deployment binaries are normally at /bin/. exe, err := os.Executable() if err != nil { return "."