Land admin password management and interpreter path fix pinned by Dev #211
@@ -6,6 +6,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"agent-system-backend/internal/execenv"
|
||||
@@ -137,6 +138,9 @@ func runDoctor(ctx context.Context, root *execenv.Root, py string, sandbox bool)
|
||||
if prefix := root.PythonPrefix(); prefix != "" {
|
||||
mounts = append(mounts, prefix)
|
||||
}
|
||||
if resolved, err := filepath.EvalSymlinks(py); err == nil {
|
||||
py = resolved
|
||||
}
|
||||
if err := execenv.Doctor(ctx, py, pyPath, nil, sandbox, mounts); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "env doctor:", err)
|
||||
return 1
|
||||
|
||||
@@ -203,7 +203,13 @@ func resolveInterpreter(name string) (string, error) {
|
||||
case "python3":
|
||||
if execPythonBin != "" {
|
||||
if st, err := os.Stat(execPythonBin); err == nil && !st.IsDir() {
|
||||
return execPythonBin, nil
|
||||
// current/bin/python3 是符号链接。沙箱用 tmpfs 盖住 /home 后只挂真实前缀,
|
||||
// 执行未解析的 current 路径会找不到文件。
|
||||
resolved, err := filepath.EvalSymlinks(execPythonBin)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return resolved, nil
|
||||
}
|
||||
return "", fmt.Errorf("python3: configured interpreter missing: %s", execPythonBin)
|
||||
}
|
||||
|
||||
@@ -213,6 +213,28 @@ func TestExecEnvIncludesSkillsRoot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveInterpreterFollowsManagedSymlink(t *testing.T) {
|
||||
prev := execPythonBin
|
||||
t.Cleanup(func() { execPythonBin = prev })
|
||||
dir := t.TempDir()
|
||||
link := filepath.Join(dir, "python3")
|
||||
if err := os.Symlink("/usr/bin/python3", link); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
execPythonBin = link
|
||||
got, err := resolveInterpreter("python3")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want, err := filepath.EvalSymlinks("/usr/bin/python3")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got != want {
|
||||
t.Fatalf("resolved %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInterpreterExecConfigForKernel(t *testing.T) {
|
||||
cfg := InterpreterExecConfig()
|
||||
if cfg == nil {
|
||||
|
||||
Reference in New Issue
Block a user