package mirror import ( "os/exec" "strings" "testing" ) // This package repairs a filesystem layout and knows nothing else. It has no // business with an issue, a tracker, a login or a configuration file, and the // moment it imports one of them it stops being a thing that can be run over any // directory on the machine. // // The dependency walk, so a helper pulled in three packages deep is caught as // the same violation as one written at the top of a file. func TestMirrorDependsOnNothing(t *testing.T) { out, err := exec.Command("go", "list", "-deps", ".").Output() if err != nil { t.Fatalf("go list: %v", err) } for _, dep := range strings.Fields(string(out)) { if dep == "git.noodles.cam/claude-skills/marketplace/cli/internal/mirror" { continue } // A standard-library import path has no dot in its first element, // because it has no domain name in front of it. if first, _, _ := strings.Cut(dep, "/"); strings.Contains(first, ".") { t.Errorf("mirror imports %s — this walks a directory, and nothing else belongs here", dep) } } } // The other half: os and net/http are standard library, so "no third-party // imports" would not catch a request or a shell-out written by hand here. os // itself is the point of this package, so it is the one that is allowed. // // DIRECT imports, not the dependency walk — fmt reaches os on its own, and the // question this asks is what THIS package reaches for. func TestMirrorNeitherDialsNorShellsOut(t *testing.T) { forbidden := map[string]string{ "net/http": "a documentation convention is not fetched from anywhere", "net": "a documentation convention is not fetched from anywhere", "os/exec": "the repair is syscalls, not a shell — that is the whole reason it left bash", "encoding/json": "the hook's JSON is the command layer's business, not this one's", "time": "nothing here has a clock in it", } out, err := exec.Command("go", "list", "-f", `{{join .Imports "\n"}}`, ".").Output() if err != nil { t.Fatalf("go list: %v", err) } for _, dep := range strings.Fields(string(out)) { if why, bad := forbidden[dep]; bad { t.Errorf("mirror imports %s — %s", dep, why) } } }