mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
Contributing's table of the checks on owners is generated from ownerDocs (TestOwnersDoc, -update), and TestOwnersAgree checks every owner the structure test names has its row; the agent home-folder literals come from agents.Defs. Contributing's index splits into topic pages (structure, extending, cli, tests, docs), with the batch's own Contributing changes in the pages that now hold their sections. Co-Authored-By: Claude Opus 5.5 <[email protected]>
95 lines
3.0 KiB
Go
95 lines
3.0 KiB
Go
package cli
|
|
|
|
import (
|
|
"io/fs"
|
|
"os"
|
|
"path/filepath"
|
|
"regexp"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/devvmhq/devvm/internal/image"
|
|
)
|
|
|
|
// listedToolchains are the files that may list every toolchain: the
|
|
// toolchains page, which owns the list. A list about something else, such
|
|
// as what an e2e image holds, gets its file here with why.
|
|
func listedToolchains() []string {
|
|
return []string{
|
|
"docs/content/docs/using/toolchains.md",
|
|
// the e2e images' contents and the e2e sections' tools, not the
|
|
// toolchains' list
|
|
"docs/content/docs/using/from.md",
|
|
"docs/content/docs/contributing/tests.md",
|
|
// the shared tools' table, ToolDef's fields
|
|
"docs/content/docs/contributing/structure.md",
|
|
// adding a toolchain: the toolchains that need nothing but mise, and
|
|
// the steps of those that need more
|
|
"docs/content/docs/contributing/extending.md",
|
|
}
|
|
}
|
|
|
|
// sentencesOf is text's sentences: each line's, split at sentenceEnd.
|
|
func sentencesOf(text string) []string {
|
|
var out []string
|
|
for line := range strings.SplitSeq(text, "\n") {
|
|
out = append(out, sentenceEnd.Split(line, -1)...)
|
|
}
|
|
return out
|
|
}
|
|
|
|
// The toolchains are listed once, on the toolchains page: a sentence
|
|
// elsewhere in the docs, the README, the in-VM guide and scripts, base's
|
|
// scripts, the messages or the issue forms that names three or more of
|
|
// image.Toolchains links to that page instead, or gives one example, so a
|
|
// new toolchain changes one list.
|
|
func TestToolchainsListedOnce(t *testing.T) {
|
|
files := []string{filepath.Join(repoRoot, "README.md"), filepath.Join(repoRoot, "assets", "layers", "base.sh")}
|
|
for _, dir := range []string{"docs/content", "assets/guest", ".github/ISSUE_TEMPLATE"} {
|
|
err := filepath.WalkDir(filepath.Join(repoRoot, dir), func(path string, d fs.DirEntry, err error) error {
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if d.IsDir() && d.Name() == "cli" {
|
|
return filepath.SkipDir // generated from the help
|
|
}
|
|
if !d.IsDir() && (strings.HasSuffix(path, ".md") || strings.HasSuffix(path, ".yml") || strings.HasSuffix(path, ".sh")) {
|
|
files = append(files, path)
|
|
}
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
files = append(files, filepath.Join(repoRoot, "locales", "en.toml"))
|
|
names := make([]*regexp.Regexp, len(image.Toolchains))
|
|
for i, n := range image.Toolchains {
|
|
// the name as a word, not part of a file's name such as
|
|
// .node-version, go.mod or rust-toolchain.toml
|
|
names[i] = regexp.MustCompile(`(?:^|[^\w./-])` + regexp.QuoteMeta(n) + `(?:$|[^\w./-]|\.\s|\.$)`)
|
|
}
|
|
for _, path := range files {
|
|
rel, _ := filepath.Rel(repoRoot, path)
|
|
if slices.Contains(listedToolchains(), filepath.ToSlash(rel)) {
|
|
continue
|
|
}
|
|
data, err := os.ReadFile(path) //nolint:gosec // G304 the repo's own files
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, s := range sentencesOf(string(data)) {
|
|
n := 0
|
|
for _, re := range names {
|
|
if re.MatchString(s) {
|
|
n++
|
|
}
|
|
}
|
|
if n >= 3 {
|
|
t.Errorf("%s lists the toolchains (%q): link the toolchains page instead, or give one example", rel, strings.TrimSpace(s))
|
|
}
|
|
}
|
|
}
|
|
}
|