package wire import ( "os/exec" "strings" "testing" ) // The identifiers are shared by two layers that may not import each other, and // they can only be shared because they reach for nothing themselves: no domain, // no configuration, no path resolution, no third party — the Gitea SDK // included. One import from any of those would drag every user of this package // into that layer, which is the whole reason an issue key is parsed here rather // than wherever it is first needed. // // 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 TestWireDependsOnNothing(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/wire" { continue } // A standard-library import path has no dot in its first element, // because it has no domain name in front of it. first, _, _ := strings.Cut(dep, "/") if strings.Contains(first, ".") { t.Errorf("the protocol imports %s — these are identifiers, and nothing else belongs here", dep) } } } // The other half: net/http and os are standard library, so "no third-party // imports" would not catch a transport or a file read written by hand here. // Name them. // // DIRECT imports, not the dependency walk — fmt reaches os on its own, and the // question this asks is what THIS package reaches for. func TestWireReachesNeitherTheNetworkNorTheDisk(t *testing.T) { forbidden := map[string]string{ "net/http": "an HTTP call belongs in the transport", "net": "an HTTP call belongs in the transport", "os": "an identifier reads no file and no environment", "os/exec": "nothing here shells out", "io": "nothing here is a stream", "time": "an address has no timestamp 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("wire imports %s — %s", dep, why) } } }