package guards import ( "testing" ) // calcHome is the formula engine's package tree — calc itself and any // subpackage of it (e.g. a future calc/functions). const calcHome = "internal/sheets/calc" // storeImport is the storage layer's own import path. Matched as a tree // (storeImport itself, or anything nested under it, e.g. a hypothetical // future store/schema) so a subpackage of store can't quietly slip past // an exact-equality check the way store's root package can't today. const storeImport = "amadan.net/oficina/sheets/internal/sheets/store" // sheetsImport is internal/sheets itself — the app/wiring package, not // its namespace. Deliberately matched by exact equality, not as a tree: // internal/sheets/format, /xlsx, /seal, /sealtest and /guards all live // under that same import prefix, and the rule as written ("internal/sheets // itself") names the one package, not everything nested under it. Widening // this to a tree match would silently forbid calc from importing any of // those siblings too — a real rule change, not a blind-spot fix, and one // nobody has decided to make. const sheetsImport = "amadan.net/oficina/sheets/internal/sheets" // TestCalcIsolatedFromStoreAndSheets fails on any file in the // internal/sheets/calc tree that imports the store package (or any // future subpackage of it) or internal/sheets itself. func TestCalcIsolatedFromStoreAndSheets(t *testing.T) { root := repoRoot(t) for _, path := range goFiles(t, root) { rel := relPath(t, root, path) if !inTree(rel, calcHome) { continue } for _, imp := range fileImports(t, path) { switch { case importUnder(imp, storeImport): t.Errorf("%s: imports %q, forbidden in %s (calc isolation)", rel, imp, calcHome) case imp == sheetsImport: t.Errorf("%s: imports %q, forbidden in %s (calc isolation)", rel, imp, calcHome) } } } }