package guards import ( "strings" "testing" ) // cgoSQLiteDriverForbidden reports whether imp is a cgo SQLite driver. // The stack is cgo-free by design (AGENTS.md / Deploys: "One binary, // CGO_ENABLED=0, cgo-free SQLite. A cgo driver sneaking in is a bug."), // so either of these landing in go.mod's dependency graph is a bug, not // a style preference. func cgoSQLiteDriverForbidden(imp string) bool { return strings.HasPrefix(imp, "github.com/glebarez/") || imp == "gorm.io/driver/sqlite" } // TestNoCgoSQLiteDriver walks every .go file's import block and fails // on any import of glebarez/* or gorm.io/driver/sqlite. func TestNoCgoSQLiteDriver(t *testing.T) { root := repoRoot(t) for _, path := range goFiles(t, root) { rel := relPath(t, root, path) for _, imp := range fileImports(t, path) { if cgoSQLiteDriverForbidden(imp) { t.Errorf("%s: imports %q, a cgo SQLite driver forbidden by AGENTS.md (Deploys: cgo-free SQLite)", rel, imp) } } } } // preMoveRastrillo is rastrillo's module path before it moved to // amadan.net/rastrillo/rastrillo (v0.25.0). Nothing after v0.23.0 was // released under it, so code importing it gets no rastrillo fix — which // is how Sheets kept zooming iOS on every tap for a month after rastrillo // fixed it (polish audit r3, item 1). const preMoveRastrillo = "github.com/carlosframework/rastrillo" // preMoveAllowed is the one file that may still import it, and why: // rastrillo/native's server takes the old path's *sessions.Sessions. // Delete the entry when native/server moves. var preMoveAllowed = map[string]string{ "internal/sheets/native.go": preMoveRastrillo + "/sessions", } // TestNoPreMoveRastrillo fails on any import of rastrillo's old module // path outside preMoveAllowed. func TestNoPreMoveRastrillo(t *testing.T) { root := repoRoot(t) for _, path := range goFiles(t, root) { rel := relPath(t, root, path) for _, imp := range fileImports(t, path) { if importUnder(imp, preMoveRastrillo) && preMoveAllowed[rel] != imp { t.Errorf("%s: imports %q, rastrillo's frozen pre-move path; use amadan.net/rastrillo/rastrillo", rel, imp) } } } }