Make composition and boundary tests extension-friendly

This commit is contained in:
2026-07-18 23:50:24 +00:00
parent d88bcb6070
commit 4f96abf42c
9 changed files with 148 additions and 102 deletions

View File

@@ -13,6 +13,7 @@ import (
)
const moduleImportPrefix = "gitea.maximumdirect.net/eric/notarius/internal/modules/"
const internalImportPrefix = "gitea.maximumdirect.net/eric/notarius/internal/"
func TestProductionImportBoundaries(t *testing.T) {
repositoryRoot := testRepositoryRoot(t)
@@ -252,6 +253,39 @@ func TestImportBoundaryRules(t *testing.T) {
importPath: moduleImportPrefix + "generic/chunk/units",
wantError: true,
},
{
name: "source production may import another core package",
filename: "internal/core/source/source.go",
sourcePackage: "source",
importPath: internalImportPrefix + "artifacts",
},
{
name: "source production cannot import framework",
filename: "internal/core/source/source.go",
sourcePackage: "source",
importPath: internalImportPrefix + "framework/contracts",
wantError: true,
},
{
name: "source production cannot import modules",
filename: "internal/core/source/source.go",
sourcePackage: "source",
importPath: moduleImportPrefix + "dnd",
wantError: true,
},
{
name: "chunkplan production may import framework",
filename: "internal/framework/chunkplan/store.go",
sourcePackage: "chunkplan",
importPath: internalImportPrefix + "framework/contracts",
},
{
name: "chunkplan production cannot import modules",
filename: "internal/framework/chunkplan/store.go",
sourcePackage: "chunkplan",
importPath: moduleImportPrefix + "dnd",
wantError: true,
},
{
name: "framework test may import module implementation",
filename: "internal/framework/pipeline/compatibility_test.go",
@@ -345,6 +379,9 @@ func checkImportBoundaries(repositoryRoot string, filename string) error {
}
func validateImport(filename string, sourcePackage string, importPath string) error {
if !strings.HasSuffix(filename, "_test.go") && strings.HasPrefix(filename, "internal/core/source/") && strings.HasPrefix(importPath, internalImportPrefix+"framework/") {
return importBoundaryViolation(filename, importPath, "core/source production code must not import framework or module implementations")
}
target, ok := moduleTargetForImport(importPath)
if !ok {
return nil
@@ -384,6 +421,12 @@ func validateImport(filename string, sourcePackage string, importPath string) er
}
return importBoundaryViolation(filename, importPath, "direct module imports from non-module tests are allowed only in CLI, core, and framework compatibility-test roots")
}
if strings.HasPrefix(filename, "internal/core/source/") && strings.HasPrefix(importPath, moduleImportPrefix) {
return importBoundaryViolation(filename, importPath, "core/source production code must not import framework or module implementations")
}
if strings.HasPrefix(filename, "internal/framework/chunkplan/") && strings.HasPrefix(importPath, moduleImportPrefix) {
return importBoundaryViolation(filename, importPath, "framework/chunkplan production code must not import module implementations")
}
if strings.HasPrefix(filename, "internal/framework/") || strings.HasPrefix(filename, "internal/core/") {
return importBoundaryViolation(filename, importPath, "core and framework production code must not import module implementations")
}