Bootstrap copied BFF and local accounts with public Sendico contracts (#34)

This commit is contained in:
Stephan D committed 2026-09-12 13:37:48 +02:00
1 parent 67dc5b5b1e
commit 7062672a87
556 files changed
+42291 -777

No files matched your search

@@ -0,0 +1,42 @@
package architecture
import (
"go/parser"
"go/token"
"io/fs"
"path/filepath"
"strconv"
"strings"
"testing"
)
// Provider access is HTTP only. Local Mongo repositories belong to SXCHNGE.
func TestNoSendicoRuntimeOrPrivateTransportImports(t *testing.T) {
err := filepath.WalkDir("../..", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() || filepath.Ext(path) != ".go" {
return nil
}
f, err := parser.ParseFile(token.NewFileSet(), path, nil, parser.ImportsOnly)
if err != nil {
return err
}
for _, im := range f.Imports {
name, err := strconv.Unquote(im.Path.Value)
if err != nil {
return err
}
for _, blocked := range []string{"github.com/tech/sendico/", "google.golang.org/grpc", "github.com/nats-io/", "/pkg/discovery", "/pkg/proto/"} {
if strings.Contains(name, blocked) {
t.Errorf("%s imports private provider transport or shared runtime: %s", path, name)
}
}
}
return nil
})
if err != nil {
t.Fatal(err)
}
}
@@ -0,0 +1,60 @@
package architecture
import (
"gopkg.in/yaml.v3"
"io/fs"
"os"
"path/filepath"
"strings"
"testing"
)
func TestPublicContractReferencesAreSelfContained(t *testing.T) {
root := filepath.Join("..", "..", "contracts", "sendico")
err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() || filepath.Ext(path) != ".yaml" {
return nil
}
data, err := os.ReadFile(path)
if err != nil {
return err
}
var doc yaml.Node
if err := yaml.Unmarshal(data, &doc); err != nil {
return err
}
var visit func(*yaml.Node)
visit = func(n *yaml.Node) {
if n.Kind == yaml.MappingNode {
for i := 0; i+1 < len(n.Content); i += 2 {
if n.Content[i].Value == "$ref" {
ref := strings.SplitN(n.Content[i+1].Value, "#", 2)[0]
if ref == "" {
continue
}
target := filepath.Clean(filepath.Join(filepath.Dir(path), ref))
relative, err := filepath.Rel(root, target)
if err != nil || strings.HasPrefix(relative, "..") || strings.Contains(ref, "://") {
t.Errorf("%s: nonlocal reference %s", path, ref)
continue
}
if _, err := os.Stat(target); err != nil {
t.Errorf("%s: missing reference %s", path, ref)
}
}
}
}
for _, child := range n.Content {
visit(child)
}
}
visit(&doc)
return nil
})
if err != nil {
t.Fatal(err)
}
}
@@ -0,0 +1,69 @@
package architecture
import (
"go/ast"
"go/parser"
"go/token"
"io/fs"
"path/filepath"
"strconv"
"testing"
)
// Keep the backend error-model guideline executable, including aliased imports.
func TestErrorConstructorsUseProjectModel(t *testing.T) {
root := filepath.Join("..", "..")
err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() || filepath.Ext(path) != ".go" {
return nil
}
fset := token.NewFileSet()
file, err := parser.ParseFile(fset, path, nil, 0)
if err != nil {
return err
}
imports := map[string]string{}
for _, imp := range file.Imports {
pkg, err := strconv.Unquote(imp.Path.Value)
if err != nil {
return err
}
if pkg != "errors" && pkg != "fmt" {
continue
}
alias := pkg
if imp.Name != nil {
alias = imp.Name.Name
}
if alias == "." {
t.Errorf("%s: dot import obscures error constructors", path)
}
imports[alias] = pkg
}
ast.Inspect(file, func(n ast.Node) bool {
call, ok := n.(*ast.CallExpr)
if !ok {
return true
}
sel, ok := call.Fun.(*ast.SelectorExpr)
if !ok {
return true
}
ident, ok := sel.X.(*ast.Ident)
if !ok {
return true
}
if (imports[ident.Name] == "errors" && sel.Sel.Name == "New") || (imports[ident.Name] == "fmt" && sel.Sel.Name == "Errorf") {
t.Errorf("%s: use backend/pkg/merrors", fset.Position(call.Pos()))
}
return true
})
return nil
})
if err != nil {
t.Fatal(err)
}
}