package validation import ( "io/fs" "os" "path" "path/filepath" "regexp" "strings" "testing" ) // This deliberately checks local Markdown destinations, not external services. // It also runs unchanged from an unpacked source archive. func TestDistributionDocuments(t *testing.T) { root := os.DirFS("../..") for _, required := range []string{ "README.md", "AGENTS.md", "LICENSE", "COPYRIGHT", "VERSION", "go.mod", "go.sum", "catalog.json", "docs/catalog.md", "docs/validation.md", "docs/compatibility.md", "docs/development.md", "docs/release.md", "docs/inventory.md", "docs/oss/attribution.md", "scripts/check.sh", ".woodpecker.yml", } { if _, err := fs.Stat(root, required); err != nil { t.Errorf("required distribution content %s: %v", required, err) } } set := loadSet(t) for _, record := range set.Catalog.Schemas { if _, err := fs.Stat(root, path.Join(path.Dir(record.Path), "semantics.md")); err != nil { t.Error(err) } entries, err := fs.ReadDir(root, path.Join(path.Dir(record.Path), "examples")) if err != nil || len(entries) == 0 { t.Errorf("%s missing examples: %v", record.Path, err) } } version, err := fs.ReadFile(root, "VERSION") if err != nil { t.Fatal(err) } if _, err := fs.Stat(root, "docs/releases/"+strings.TrimSpace(string(version))+".md"); err != nil { t.Errorf("version-matched release note: %v", err) } link := regexp.MustCompile(`\[[^\]]*\]\(([^)]+)\)`) err = fs.WalkDir(root, ".", func(file string, entry fs.DirEntry, err error) error { if err != nil { return err } if entry.IsDir() { if entry.Name() == ".git" || entry.Name() == "dist" { return fs.SkipDir } return nil } if filepath.Ext(file) != ".md" { return nil } data, err := fs.ReadFile(root, file) if err != nil { return err } for _, match := range link.FindAllSubmatch(data, -1) { destination := string(match[1]) if strings.Contains(destination, "://") || strings.HasPrefix(destination, "#") { continue } destination, _, _ = strings.Cut(destination, "#") if _, err := fs.Stat(root, path.Join(path.Dir(file), destination)); err != nil { t.Errorf("%s links to missing %s: %v", file, destination, err) } } return nil }) if err != nil { t.Fatal(err) } }