Complete the public facade adapter boundary
This commit is contained in:
64
internal/adapter/dependency_test.go
Normal file
64
internal/adapter/dependency_test.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package adapter_test
|
||||
|
||||
import (
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestScriptoriumAdaptersUseOnlyPublicFrameworkBoundary(t *testing.T) {
|
||||
_, testFile, _, ok := runtime.Caller(0)
|
||||
if !ok {
|
||||
t.Fatal("locate dependency guard source")
|
||||
}
|
||||
|
||||
adapterDir := filepath.Dir(testFile)
|
||||
directories := []string{
|
||||
filepath.Join(adapterDir, "cli"),
|
||||
filepath.Join(adapterDir, "http"),
|
||||
filepath.Join(adapterDir, "..", "format"),
|
||||
}
|
||||
forbidden := map[string]struct{}{
|
||||
"gitea.maximumdirect.net/eric/scriptorium/internal/domain": {},
|
||||
"gitea.maximumdirect.net/eric/scriptorium/internal/usecase": {},
|
||||
"gitea.maximumdirect.net/eric/scriptorium/internal/promptdef": {},
|
||||
"gitea.maximumdirect.net/eric/scriptorium/internal/prompt": {},
|
||||
"gitea.maximumdirect.net/eric/scriptorium/internal/profile": {},
|
||||
"gitea.maximumdirect.net/eric/scriptorium/internal/profile/builtin": {},
|
||||
"gitea.maximumdirect.net/eric/scriptorium/internal/validate": {},
|
||||
"gitea.maximumdirect.net/eric/scriptorium/internal/llm": {},
|
||||
"gitea.maximumdirect.net/eric/scriptorium/internal/artifact": {},
|
||||
}
|
||||
|
||||
for _, directory := range directories {
|
||||
entries, err := os.ReadDir(directory)
|
||||
if err != nil {
|
||||
t.Fatalf("read source directory %s: %v", directory, err)
|
||||
}
|
||||
for _, entry := range entries {
|
||||
if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".go") || strings.HasSuffix(entry.Name(), "_test.go") {
|
||||
continue
|
||||
}
|
||||
|
||||
path := filepath.Join(directory, entry.Name())
|
||||
file, err := parser.ParseFile(token.NewFileSet(), path, nil, parser.ImportsOnly)
|
||||
if err != nil {
|
||||
t.Fatalf("parse imports in %s: %v", path, err)
|
||||
}
|
||||
for _, imported := range file.Imports {
|
||||
importPath, err := strconv.Unquote(imported.Path.Value)
|
||||
if err != nil {
|
||||
t.Fatalf("parse import path in %s: %v", path, err)
|
||||
}
|
||||
if _, found := forbidden[importPath]; found {
|
||||
t.Errorf("%s directly imports forbidden framework package %s", path, importPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user