Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions tools/testmask/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"maps"
"os"
"path"
"slices"
"strings"

Expand All @@ -29,9 +30,21 @@ var commonTriggerPatterns = []string{
"tools/task/",
}

// ignoredFiles lists files that never affect test results.
var ignoredFiles = []string{
// ignoredPatterns lists files that never affect test results. Patterns use
// path.Match syntax, and a trailing "/**" matches everything under a directory.
// Nested READMEs are not listed because many are test fixtures or embedded templates.
var ignoredPatterns = []string{
".agents/**",
".claude/**",
".cursor/**",
".github/CODEOWNERS",
".github/ISSUE_TEMPLATE/**",
".github/PULL_REQUEST_TEMPLATE.md",
".nextchanges/*/*.md",
"AGENTS.md",
"CHANGELOG.md",
"README.md",
"SECURITY.md",
}

type targetMapping struct {
Expand Down Expand Up @@ -106,13 +119,28 @@ func sourceToPrefix(src string) string {
return src
}

func isIgnored(file string) bool {
for _, pattern := range ignoredPatterns {
if dir, ok := strings.CutSuffix(pattern, "**"); ok {
if strings.HasPrefix(file, dir) {
return true
}
continue
}
if ok, _ := path.Match(pattern, file); ok {
return true
}
}
return false
}

// GetTargets matches files to targets based on patterns and returns the matched targets.
func GetTargets(files []string, mappings []targetMapping) []string {
targetSet := make(map[string]bool)
unmatchedFiles := []string{}

for _, file := range files {
if slices.Contains(ignoredFiles, file) {
if isIgnored(file) {
continue
}

Expand Down
34 changes: 34 additions & 0 deletions tools/testmask/targets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,40 @@ func TestGetTargets(t *testing.T) {
},
targets: []string{"test"},
},
{
name: "docs_and_agent_files_only",
files: []string{
".agents/rules/testing.md",
".claude/settings.json",
".cursor/rules/testing.mdc",
".github/PULL_REQUEST_TEMPLATE.md",
".nextchanges/cli/7483.md",
"AGENTS.md",
"README.md",
},
targets: []string{},
},
{
name: "acceptance_output_readme_not_ignored",
files: []string{
"acceptance/bundle/templates/default-python/classic/output/my_default_python/README.md",
},
targets: []string{"test"},
},
{
name: "embedded_template_readme_not_ignored",
files: []string{
"libs/template/templates/default-sql/template/{{.project_name}}/scratch/README.md",
},
targets: []string{"test"},
},
{
name: "nextchanges_version_not_ignored",
files: []string{
".nextchanges/version",
},
targets: []string{"test"},
},
}

for _, tt := range tests {
Expand Down
Loading