-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathisolation_test.go
More file actions
88 lines (82 loc) Β· 2.02 KB
/
Copy pathisolation_test.go
File metadata and controls
88 lines (82 loc) Β· 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package metaai
import (
"io/fs"
"os"
"path/filepath"
"regexp"
"strings"
"testing"
)
func TestModuleIsSelfContained(t *testing.T) {
requiredFiles := []string{
".env.example",
".gitattributes",
".github/workflows/ci.yml",
".gitignore",
"LICENSE",
"Makefile",
}
for _, path := range requiredFiles {
if _, err := os.Stat(path); err != nil {
t.Errorf("standalone project file %q is unavailable: %v", path, err)
}
}
}
func TestModuleHasNoLegacyRuntimeCoupling(t *testing.T) {
legacyRuntime := regexp.MustCompile(`(?i)` + "py" + `thon|\.py\b|pyproject|requirements\.txt`)
textExtensions := map[string]bool{
".go": true, ".html": true, ".md": true, ".mod": true,
".toml": true, ".yaml": true, ".yml": true,
}
err := filepath.WalkDir(".", func(path string, entry fs.DirEntry, walkErr error) error {
if walkErr != nil {
return walkErr
}
if entry.IsDir() {
// Skip tooling metadata, VCS, node_modules and built frontends.
name := entry.Name()
if path == ".codebase-memory" || path == ".git" || path == ".serena" || name == "node_modules" || name == "dist" {
return filepath.SkipDir
}
return nil
}
if !textExtensions[filepath.Ext(path)] {
return nil
}
if path == "isolation_test.go" {
return nil
}
content, err := os.ReadFile(path)
if err != nil {
return err
}
if legacyRuntime.Match(content) {
t.Errorf("legacy runtime reference found in %s", path)
}
if strings.Contains(string(content), "../") {
t.Errorf("parent-project reference found in %s", path)
}
return nil
})
if err != nil {
t.Fatal(err)
}
}
func TestModuleDoesNotContainBuiltExecutables(t *testing.T) {
entries, err := os.ReadDir(".")
if err != nil {
t.Fatal(err)
}
for _, entry := range entries {
if entry.IsDir() || filepath.Ext(entry.Name()) != "" {
continue
}
info, err := entry.Info()
if err != nil {
t.Fatal(err)
}
if info.Mode().IsRegular() && info.Mode().Perm()&0o111 != 0 {
t.Errorf("built executable %q must not be stored in the module", entry.Name())
}
}
}