mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
fix: clarify system-install doctor alias and shim path checks
Use UserBinDir for PATH checks and pass aliases as not required under system install without treating that as active interception. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+9
-11
@@ -30,6 +30,8 @@ const (
|
||||
checkProtectionNpm = "protection-npm"
|
||||
checkProtectionPip = "protection-pip"
|
||||
checkCA = "ca-cert"
|
||||
|
||||
aliasesInstalledMessage = "Shell aliases installed"
|
||||
)
|
||||
|
||||
func NewDoctorCommand() *cobra.Command {
|
||||
@@ -100,7 +102,7 @@ func runCoreChecks(cfg *config.RuntimeConfig) []doctor.CheckResult {
|
||||
if err != nil {
|
||||
return doctor.CheckResult{
|
||||
Status: doctor.StatusWarn,
|
||||
Message: "Event log directory not found (PMG still runs without event logs)",
|
||||
Message: "Event log directory not found",
|
||||
}
|
||||
}
|
||||
if !info.IsDir() {
|
||||
@@ -138,13 +140,13 @@ func runCoreChecks(cfg *config.RuntimeConfig) []doctor.CheckResult {
|
||||
if installed {
|
||||
return doctor.CheckResult{
|
||||
Status: doctor.StatusPass,
|
||||
Message: "Shell aliases installed",
|
||||
Message: aliasesInstalledMessage,
|
||||
}
|
||||
}
|
||||
if shim.SystemShimsInstalled() {
|
||||
return doctor.CheckResult{
|
||||
Status: doctor.StatusWarn,
|
||||
Message: "Aliases not installed (optional with system shims)",
|
||||
Status: doctor.StatusPass,
|
||||
Message: "No aliases (system install)",
|
||||
}
|
||||
}
|
||||
return doctor.CheckResult{
|
||||
@@ -196,11 +198,7 @@ func runCoreChecks(cfg *config.RuntimeConfig) []doctor.CheckResult {
|
||||
Message: "System shim directory is in PATH",
|
||||
}
|
||||
}
|
||||
userDir := ""
|
||||
if home, err := os.UserHomeDir(); err == nil {
|
||||
userDir = filepath.Join(home, ".pmg", "bin")
|
||||
}
|
||||
if pathContainsDir(pathEntries, userDir) {
|
||||
if userDir, err := shim.UserBinDir(); err == nil && pathContainsDir(pathEntries, userDir) {
|
||||
return doctor.CheckResult{
|
||||
Status: doctor.StatusPass,
|
||||
Message: "Shim directory is in PATH",
|
||||
@@ -346,10 +344,10 @@ func runProtectionChecks(coreResults []doctor.CheckResult) []doctor.CheckResult
|
||||
|
||||
func isInterceptionActive(coreResults []doctor.CheckResult) bool {
|
||||
for _, r := range coreResults {
|
||||
if r.Name == checkShellAliases && r.Status == doctor.StatusPass {
|
||||
if r.Name == checkShimInPath && r.Status == doctor.StatusPass {
|
||||
return true
|
||||
}
|
||||
if r.Name == checkShimInPath && r.Status == doctor.StatusPass {
|
||||
if r.Name == checkShellAliases && r.Status == doctor.StatusPass && r.Message == aliasesInstalledMessage {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,20 @@ func TestPathContainsDir(t *testing.T) {
|
||||
assert.False(t, pathContainsDir([]string{"/usr/bin"}, ""))
|
||||
}
|
||||
|
||||
func TestSystemShimsWithoutPathDoNotActivateInterception(t *testing.T) {
|
||||
func TestSystemInstallAliasesPassDoesNotActivateInterception(t *testing.T) {
|
||||
results := []doctor.CheckResult{
|
||||
{Name: checkShellAliases, Status: doctor.StatusWarn},
|
||||
{Name: checkShellAliases, Status: doctor.StatusPass, Message: "No aliases (system install)"},
|
||||
{Name: checkShimInPath, Status: doctor.StatusFail},
|
||||
}
|
||||
|
||||
assert.False(t, isInterceptionActive(results))
|
||||
}
|
||||
|
||||
func TestAliasesInstalledActivatesInterception(t *testing.T) {
|
||||
results := []doctor.CheckResult{
|
||||
{Name: checkShellAliases, Status: doctor.StatusPass, Message: aliasesInstalledMessage},
|
||||
{Name: checkShimInPath, Status: doctor.StatusFail},
|
||||
}
|
||||
|
||||
assert.True(t, isInterceptionActive(results))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user