Discover joined home/workroot with Dirname without checking the result was absolute, so an empty home (the fallback main.go uses when os.UserHomeDir fails) or a relative workroot resolved against the process's working directory instead of a real root, silently loading whatever .agents/skills happened to be there as "personal" or "project". Skip any root whose joined path is not absolute, silently: an unknown home is not a user error, and neither root existing is already normal. Fix round 1 of 5, addressing an Important review finding from Task 6. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Showing 2 changed files with 35 additions and 0 deletions.
| @@ -62,6 +62,13 @@ func Discover(home, workroot string) ([]Skill, []error) { | ||
| 62 | 62 | {filepath.Join(home, Dirname), "personal"}, |
| 63 | 63 | {filepath.Join(workroot, Dirname), "project"}, |
| 64 | 64 | } { |
| 65 | + if !filepath.IsAbs(r.dir) { | |
| 66 | + // home or workroot was empty or relative, so this root would | |
| 67 | + // resolve against the process's working directory instead of a | |
| 68 | + // real personal or project root. An unknown home is not a user | |
| 69 | + // error, so this is silently skipped rather than reported. | |
| 70 | + continue | |
| 71 | + } | |
| 65 | 72 | found, probs := scan(r.dir, r.source) |
| 66 | 73 | problems = append(problems, probs...) |
| 67 | 74 | for _, s := range found { |
| @@ -195,6 +195,34 @@ symlinked body | ||
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | + func TestEmptyHomeDoesNotScanWorkingDirectory(t *testing.T) { | |
| 199 | + cwd := t.TempDir() | |
| 200 | + write(t, filepath.Join(cwd, ".agents", "skills"), "leaky", wellFormed2()) | |
| 201 | + t.Chdir(cwd) | |
| 202 | + | |
| 203 | + found, problems := Discover("", t.TempDir()) | |
| 204 | + if len(found) != 0 { | |
| 205 | + t.Fatalf("found %+v, want none", found) | |
| 206 | + } | |
| 207 | + if len(problems) != 0 { | |
| 208 | + t.Fatalf("problems: %v", problems) | |
| 209 | + } | |
| 210 | + } | |
| 211 | + | |
| 212 | + func TestRelativeWorkrootDoesNotScanWorkingDirectory(t *testing.T) { | |
| 213 | + cwd := t.TempDir() | |
| 214 | + write(t, filepath.Join(cwd, ".agents-probe-relative", ".agents", "skills"), "leaky", wellFormed2()) | |
| 215 | + t.Chdir(cwd) | |
| 216 | + | |
| 217 | + found, problems := Discover(t.TempDir(), ".agents-probe-relative") | |
| 218 | + if len(found) != 0 { | |
| 219 | + t.Fatalf("found %+v, want none", found) | |
| 220 | + } | |
| 221 | + if len(problems) != 0 { | |
| 222 | + t.Fatalf("problems: %v", problems) | |
| 223 | + } | |
| 224 | + } | |
| 225 | + | |
| 198 | 226 | func TestSortedByName(t *testing.T) { |
| 199 | 227 | home, work := t.TempDir(), t.TempDir() |
| 200 | 228 | root := filepath.Join(home, ".agents", "skills") |