Take the build agent and the toolchain images out of the catalogue's prose, and refuse the word where it comes back outside the one module still naming it (issue 1295, E6)
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# The modules of the catalogue whose texts still name the build agent or the toolchain images, and why (checks/words,
|
||||
# buildagent_test.go). One module directory a line, with its reason after a #. It only shrinks.
|
||||
modules/mesh-build-go # build.go:45 says "the build agent's recipe" in a step's description: the asks lane's module (issue 1887), not E6's to edit
|
||||
@@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// The build agent and the toolchain images are gone (novox/hq ADR 0524 §5, issue 1295 and E6 of milestone R4g): no text a module
|
||||
// can show names them. Where the word stands for a reason that is another lane's or still waits for its change, buildagent-allowed
|
||||
// names the module's directory with that reason and the date it is dated from; the list only shrinks: a directory on it that no
|
||||
// longer names the word is refused, so the line is taken out.
|
||||
var gone = []string{"build-agent", "build agent", "toolchain image"}
|
||||
|
||||
func allowedModules(t *testing.T) map[string]string {
|
||||
t.Helper()
|
||||
raw, err := os.ReadFile("buildagent-allowed")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
out := map[string]string{}
|
||||
for _, line := range strings.Split(string(raw), "\n") {
|
||||
entry, why, _ := strings.Cut(line, "#")
|
||||
if entry = strings.TrimSpace(entry); entry != "" && !strings.HasPrefix(line, "#") {
|
||||
if strings.TrimSpace(why) == "" {
|
||||
t.Fatalf("%q is allowed without a reason", entry)
|
||||
}
|
||||
out[entry] = strings.TrimSpace(why)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func TestNoTextOfTheCatalogueNamesTheBuildAgentOutsideTheModulesAllowed(t *testing.T) {
|
||||
texts, _, err := collect("../..")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
allowed := allowedModules(t)
|
||||
seen := map[string]bool{}
|
||||
for _, f := range check(gone, texts) {
|
||||
module := f
|
||||
if rest, ok := strings.CutPrefix(f, "modules/"); ok {
|
||||
module = "modules/" + strings.SplitN(rest, "/", 2)[0]
|
||||
}
|
||||
if _, ok := allowed[module]; ok {
|
||||
seen[module] = true
|
||||
continue
|
||||
}
|
||||
t.Errorf("%s (the build agent and the toolchain images are gone: say what stands in their place)", f)
|
||||
}
|
||||
for module, why := range allowed {
|
||||
if !seen[module] {
|
||||
t.Errorf("buildagent-allowed names %s (%s), which names the word no more: take the line out, so it cannot come back", module, why)
|
||||
}
|
||||
}
|
||||
}
|
||||
+42
-35
@@ -58,41 +58,7 @@ func run(root string) int {
|
||||
fmt.Fprintln(os.Stderr, "words: retired-words lists no word — the check would pass on anything")
|
||||
return 2
|
||||
}
|
||||
var texts []text
|
||||
files := 0
|
||||
err = filepath.WalkDir(filepath.Join(root, "modules"), func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if d.IsDir() {
|
||||
switch d.Name() {
|
||||
case "node_modules", "dist", "vendor", "test", "tests", "testdata", ".git":
|
||||
return filepath.SkipDir
|
||||
}
|
||||
return nil
|
||||
}
|
||||
rel, _ := filepath.Rel(root, path)
|
||||
name := d.Name()
|
||||
var found []text
|
||||
switch {
|
||||
case strings.HasSuffix(name, "_test.go"), strings.Contains(name, ".test."), strings.Contains(name, ".spec."):
|
||||
return nil
|
||||
case strings.HasSuffix(name, ".go"):
|
||||
found, err = goStrings(path, rel)
|
||||
case strings.HasSuffix(name, ".ts"), strings.HasSuffix(name, ".js"), strings.HasSuffix(name, ".mjs"):
|
||||
found, err = scriptStrings(path, rel)
|
||||
case name == "module.json":
|
||||
found, err = jsonStrings(path, rel)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %w", rel, err)
|
||||
}
|
||||
files++
|
||||
texts = append(texts, found...)
|
||||
return nil
|
||||
})
|
||||
texts, files, err := collect(root)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "words:", err)
|
||||
return 2
|
||||
@@ -128,6 +94,47 @@ func run(root string) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// collect reads every text a module can show under root: the strings of its own code that is not a test, and every string of
|
||||
// its manifests.
|
||||
func collect(root string) ([]text, int, error) {
|
||||
var texts []text
|
||||
files := 0
|
||||
err := filepath.WalkDir(filepath.Join(root, "modules"), func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if d.IsDir() {
|
||||
switch d.Name() {
|
||||
case "node_modules", "dist", "vendor", "test", "tests", "testdata", ".git":
|
||||
return filepath.SkipDir
|
||||
}
|
||||
return nil
|
||||
}
|
||||
rel, _ := filepath.Rel(root, path)
|
||||
name := d.Name()
|
||||
var found []text
|
||||
switch {
|
||||
case strings.HasSuffix(name, "_test.go"), strings.Contains(name, ".test."), strings.Contains(name, ".spec."):
|
||||
return nil
|
||||
case strings.HasSuffix(name, ".go"):
|
||||
found, err = goStrings(path, rel)
|
||||
case strings.HasSuffix(name, ".ts"), strings.HasSuffix(name, ".js"), strings.HasSuffix(name, ".mjs"):
|
||||
found, err = scriptStrings(path, rel)
|
||||
case name == "module.json":
|
||||
found, err = jsonStrings(path, rel)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %w", rel, err)
|
||||
}
|
||||
files++
|
||||
texts = append(texts, found...)
|
||||
return nil
|
||||
})
|
||||
return texts, files, err
|
||||
}
|
||||
|
||||
// readList reads retired-words: one word or phrase a line; blank lines and lines starting with # are not words.
|
||||
func readList(path string) ([]string, error) {
|
||||
f, err := os.Open(path)
|
||||
|
||||
Reference in New Issue
Block a user