package wire import ( "os/exec" "strings" "testing" ) // The protocol is shared by two layers that may not import each other, and it // can only be shared because it reaches for nothing itself: no domain, no // configuration, no path resolution, no third party. One import from any of // those would drag every user of this package into that layer — which is the // whole reason these shapes were lifted out of the transport rather than left // there for the bridge to reimplement. // // 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 shapes and 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": "a shape reads no file and no environment", "os/exec": "nothing here shells out", "io": "nothing here is a stream", "time": "a timestamp crosses as the string the tracker sent", } 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) } } }