From bdea3f9b0c9ce04901b2ebde4d9acbbcdac7807d Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Wed, 18 Nov 2026 17:12:28 -0300 Subject: [PATCH 1/9] go fix: the toolchain's modernizers, which lint does not run Co-Authored-By: Claude Opus 5.5 --- cmd/deadgate/main.go | 3 +-- cmd/ghatrace/main.go | 5 ++--- cmd/linkweight/main.go | 5 ++--- cmd/mutate/example_test.go | 2 +- cmd/proven/main.go | 8 +++----- cmd/proven/main_test.go | 9 ++++----- cmd/refs/main.go | 5 ++--- internal/exposure/history.go | 5 ++--- internal/gencache/gencache.go | 3 +-- internal/gencache/gencache_test.go | 5 ++--- internal/mutate/cache.go | 4 ++-- internal/mutate/cgroup_linux.go | 2 +- internal/mutate/cover.go | 7 +++---- internal/mutate/mutate.go | 10 +++++----- internal/mutate/runner.go | 18 ++++++------------ internal/mutate/tree.go | 2 +- internal/proven/github.go | 7 +++---- internal/refs/refs.go | 6 +++--- internal/sfw/check.go | 2 +- internal/shell/shell.go | 4 ++-- internal/taskgate/taskfile.go | 2 +- internal/taskgate/taskgate.go | 4 ++-- sbom/builders.go | 4 ++-- versions/gate/gate.go | 2 +- 24 files changed, 53 insertions(+), 71 deletions(-) diff --git a/cmd/deadgate/main.go b/cmd/deadgate/main.go index 659ff78..7887300 100644 --- a/cmd/deadgate/main.go +++ b/cmd/deadgate/main.go @@ -136,8 +136,7 @@ func trimDots(skipped []string) []string { // sh is a command's standard output; what it said on standard error is in the error. func sh(name string, args ...string) (string, error) { out, err := exec.Command(name, args...).Output() //nolint:gosec // go and the deadcode binary the caller names, over its own module - var exit *exec.ExitError - if errors.As(err, &exit) { + if exit, ok := errors.AsType[*exec.ExitError](err); ok { return "", fmt.Errorf("%s %s: %w: %s", name, strings.Join(args, " "), err, strings.TrimSpace(string(exit.Stderr))) } if err != nil { diff --git a/cmd/ghatrace/main.go b/cmd/ghatrace/main.go index d42cb4f..33c745e 100644 --- a/cmd/ghatrace/main.go +++ b/cmd/ghatrace/main.go @@ -39,8 +39,7 @@ import ( func main() { err := run(context.Background(), os.Args[1:]) // mutate-exempt: main's way in; run is what the tests drive - var exit exitError - if errors.As(err, &exit) { + if exit, ok := errors.AsType[exitError](err); ok { os.Exit(int(exit)) } if err != nil { // mutate-exempt: main's way out; run is what the tests drive @@ -337,7 +336,7 @@ func withJSON(argv []string) []string { // go test command in one argument. func verbose(args []string) bool { for _, a := range args { - for _, word := range strings.Fields(a) { + for word := range strings.FieldsSeq(a) { switch strings.TrimLeft(word, "-") { case "v", "v=true", "test.v", "test.v=true": return true diff --git a/cmd/linkweight/main.go b/cmd/linkweight/main.go index 288ee65..2576eec 100644 --- a/cmd/linkweight/main.go +++ b/cmd/linkweight/main.go @@ -99,7 +99,7 @@ func measure(rootsPattern string, skipped []string, tags string, progress io.Wri return nil, err } var roots []string - for _, m := range strings.Fields(mains) { + for m := range strings.FieldsSeq(mains) { rel := strings.TrimPrefix(strings.TrimPrefix(m, module), "/") if !slices.Contains(skipped, "./"+rel) { roots = append(roots, m) @@ -191,8 +191,7 @@ func notEdges(path string) string { // sh is a command's standard output; what it said on standard error is in the error. func sh(name string, args ...string) (string, error) { out, err := exec.Command(name, args...).Output() //nolint:gosec // go, over the caller's own module - var exit *exec.ExitError - if errors.As(err, &exit) { + if exit, ok := errors.AsType[*exec.ExitError](err); ok { return "", fmt.Errorf("%s %s: %w: %s", name, strings.Join(args, " "), err, strings.TrimSpace(string(exit.Stderr))) } if err != nil { diff --git a/cmd/mutate/example_test.go b/cmd/mutate/example_test.go index f90a975..4002db2 100644 --- a/cmd/mutate/example_test.go +++ b/cmd/mutate/example_test.go @@ -89,7 +89,7 @@ func TestTheExampleTheSiteShows(t *testing.T) { func abridged(out string) string { var head, edits, tail []string verdict := false - for _, line := range strings.Split(out, "\n") { + for line := range strings.SplitSeq(out, "\n") { switch { case verdict: tail = append(tail, line) diff --git a/cmd/proven/main.go b/cmd/proven/main.go index 91f3a3d..d5e4378 100644 --- a/cmd/proven/main.go +++ b/cmd/proven/main.go @@ -22,6 +22,7 @@ import ( "net/url" "os" "os/exec" + "slices" "sort" "strings" @@ -273,11 +274,8 @@ func base(ctx context.Context, gh proven.GitHub, trees proven.Trees, sha, ref, m } var passed []proven.Run for _, r := range runs { - for _, e := range events { - if r.Event == e { - passed = append(passed, r) - break - } + if slices.Contains(events, r.Event) { + passed = append(passed, r) } } history, err := proven.FirstParent(ctx, ".", sha, depth) diff --git a/cmd/proven/main_test.go b/cmd/proven/main_test.go index 33c5998..7e6a8a5 100644 --- a/cmd/proven/main_test.go +++ b/cmd/proven/main_test.go @@ -16,7 +16,6 @@ import ( "github.com/stretchr/testify/require" "github.com/spin-stack/go-tools/internal/gittest" - "github.com/spin-stack/go-tools/internal/proven" ) // stdout is what f printed to os.Stdout. @@ -307,12 +306,12 @@ func TestTestsAreWhatTheAnsweringRunsLogged(t *testing.T) { {Workflow: "kvm.yml", ID: 30, URL: "u30", Conclusion: "failure", Head: f.main[1]}, }, Tests: []evidenceOf{ - {Test: proven.Test{Name: "TestA", Passed: true, Seconds: 1.5}, evidenceJob: fleet}, - {Test: proven.Test{Name: "TestA", Passed: true, Seconds: 1.4}, evidenceJob: evidenceJob{Workflow: "kvm.yml", Run: 30, Job: "e2e-verify:1/1"}}, - {Test: proven.Test{Name: "TestB", Passed: false, Seconds: 2}, evidenceJob: evidenceJob{Workflow: "kvm.yml", Run: 30, Job: "e2e-verify:1/1"}}, + {Name: "TestA", Passed: true, Seconds: 1.5, evidenceJob: fleet}, + {Name: "TestA", Passed: true, Seconds: 1.4, Workflow: "kvm.yml", Run: 30, Job: "e2e-verify:1/1"}, + {Name: "TestB", Passed: false, Seconds: 2, Workflow: "kvm.yml", Run: 30, Job: "e2e-verify:1/1"}, }, // What job 42's test timed, beside the machine it ran on. - Measures: []evidenceMeasure{{Measure: proven.Measure{Name: "boot_to_running_ms", Value: 12345}, evidenceJob: fleet}}, + Measures: []evidenceMeasure{{Name: "boot_to_running_ms", Value: 12345, evidenceJob: fleet}}, }, got) assert.Contains(t, f.asked, "/repos/o/r/actions/jobs/41/logs", "a job whose log is gone is asked, and says nothing") diff --git a/cmd/refs/main.go b/cmd/refs/main.go index fe798e8..fe47f6f 100644 --- a/cmd/refs/main.go +++ b/cmd/refs/main.go @@ -122,8 +122,7 @@ func taskLister(root string, task []string) refs.TaskLister { cmd.Env = append(os.Environ(), "NO_COLOR=1") out, err := cmd.Output() if err != nil { - var exit *exec.ExitError - if errors.As(err, &exit) { + if exit, ok := errors.AsType[*exec.ExitError](err); ok { return nil, fmt.Errorf("refs: %s -d %s --list-all --json --no-status: %w\n%s", strings.Join(task, " "), dir, err, exit.Stderr) } return nil, fmt.Errorf("refs: running %s: %w", strings.Join(task, " "), err) @@ -152,7 +151,7 @@ func git(root string, args ...string) ([]string, error) { return nil, fmt.Errorf("refs: git %s: %w", strings.Join(args, " "), err) } var lines []string - for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") { + for line := range strings.SplitSeq(strings.TrimSpace(string(out)), "\n") { if line != "" { lines = append(lines, line) } diff --git a/internal/exposure/history.go b/internal/exposure/history.go index 02e6574..5a2c4eb 100644 --- a/internal/exposure/history.go +++ b/internal/exposure/history.go @@ -212,14 +212,13 @@ func patches(dir string, each func(commit, file string, kind added, line string) func lines(dir string, args ...string) ([]string, error) { raw, err := exec.Command("git", append([]string{"-C", dir}, args...)...).Output() if err != nil { - var exit *exec.ExitError - if errors.As(err, &exit) { + if exit, ok := errors.AsType[*exec.ExitError](err); ok { return nil, fmt.Errorf("git %s: %w: %s", strings.Join(args, " "), err, strings.TrimSpace(string(exit.Stderr))) } return nil, fmt.Errorf("git %s: %w", strings.Join(args, " "), err) } var out []string - for _, l := range strings.Split(string(raw), "\n") { + for l := range strings.SplitSeq(string(raw), "\n") { if l != "" { out = append(out, l) } diff --git a/internal/gencache/gencache.go b/internal/gencache/gencache.go index e37e9c0..96776fd 100644 --- a/internal/gencache/gencache.go +++ b/internal/gencache/gencache.go @@ -512,8 +512,7 @@ func abs(dir, file string) string { } func stderr(err error) error { - var ee *exec.ExitError - if errors.As(err, &ee) { + if ee, ok := errors.AsType[*exec.ExitError](err); ok { return fmt.Errorf("%w: %s", err, bytes.TrimSpace(ee.Stderr)) } return err diff --git a/internal/gencache/gencache_test.go b/internal/gencache/gencache_test.go index 5401623..6fe59ac 100644 --- a/internal/gencache/gencache_test.go +++ b/internal/gencache/gencache_test.go @@ -2,6 +2,7 @@ package gencache import ( "bytes" + "maps" "os" "os/exec" "path/filepath" @@ -120,9 +121,7 @@ func newModule(t *testing.T, extra map[string]string) string { mod = []byte("module example.com/m" + string(mod[bytes.IndexByte(mod, '\n'):])) files := map[string]string{"go.mod": string(mod), "go.sum": string(sum)} for _, set := range []map[string]string{fixture, extra} { - for name, body := range set { - files[name] = body - } + maps.Copy(files, set) } writeTree(t, dir, files) return dir diff --git a/internal/mutate/cache.go b/internal/mutate/cache.go index 0efbbf7..f4db02c 100644 --- a/internal/mutate/cache.go +++ b/internal/mutate/cache.go @@ -238,7 +238,7 @@ func listModule(root string) (*moduleGraph, error) { dirOf := map[string]string{} type row struct{ dir, imports, tests string } var rows []row - for _, line := range strings.Split(string(out), "\n") { + for line := range strings.SplitSeq(string(out), "\n") { fields := strings.Split(line, "\t") if len(fields) != 4 { continue @@ -248,7 +248,7 @@ func listModule(root string) (*moduleGraph, error) { } local := func(paths string) []string { var dirs []string - for _, p := range strings.Fields(paths) { + for p := range strings.FieldsSeq(paths) { if d, ok := dirOf[p]; ok { dirs = append(dirs, d) } diff --git a/internal/mutate/cgroup_linux.go b/internal/mutate/cgroup_linux.go index 8f3f9b0..5697202 100644 --- a/internal/mutate/cgroup_linux.go +++ b/internal/mutate/cgroup_linux.go @@ -75,7 +75,7 @@ func takeOver(dir string) error { if readErr != nil { return readErr } - for _, pid := range strings.Fields(string(procs)) { + for pid := range strings.FieldsSeq(string(procs)) { // ESRCH: gone since it was listed, which leaves nothing to move. if err := set(lead, "cgroup.procs", pid); err != nil && !errors.Is(err, syscall.ESRCH) { return err diff --git a/internal/mutate/cover.go b/internal/mutate/cover.go index 6daa860..e7e99fc 100644 --- a/internal/mutate/cover.go +++ b/internal/mutate/cover.go @@ -4,6 +4,7 @@ import ( "bufio" "cmp" "fmt" + "maps" "os" "os/exec" "path/filepath" @@ -92,7 +93,7 @@ func Cover(dir, timeout string, slots chan *Tree) (*Coverage, error) { return nil, fmt.Errorf("mutate: listing %s's tests: %w", dir, err) } var tests []string - for _, name := range strings.Fields(string(listed)) { + for name := range strings.FieldsSeq(string(listed)) { if strings.HasPrefix(name, "Test") { tests = append(tests, name) } @@ -149,9 +150,7 @@ func Cover(dir, timeout string, slots chan *Tree) (*Coverage, error) { c.failing[test] = true } // Every profile of one binary counts the same blocks. - for file, s := range blocks { - c.blocks[file] = s - } + maps.Copy(c.blocks, blocks) for file, s := range spans { if c.reached[file] == nil { c.reached[file] = map[string][]span{} diff --git a/internal/mutate/mutate.go b/internal/mutate/mutate.go index 829ef31..a7ccb36 100644 --- a/internal/mutate/mutate.go +++ b/internal/mutate/mutate.go @@ -66,7 +66,7 @@ func Changed(base string) (map[string]map[int]bool, error) { } changed := map[string]map[int]bool{} file := "" - for _, line := range strings.Split(string(out), "\n") { + for line := range strings.SplitSeq(string(out), "\n") { switch { case strings.HasPrefix(line, "+++ b/"): file = strings.TrimPrefix(line, "+++ b/") @@ -92,7 +92,7 @@ func Changed(base string) (map[string]map[int]bool, error) { if err != nil { return nil, fmt.Errorf("reading what is not committed yet: %w", err) } - for _, path := range strings.Fields(string(untracked)) { + for path := range strings.FieldsSeq(string(untracked)) { if !asked(path) { continue } @@ -119,7 +119,7 @@ func asked(path string) bool { if !strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "_test.go") { return false } - for _, dir := range strings.Split(pathpkg.Dir(path), "/") { + for dir := range strings.SplitSeq(pathpkg.Dir(path), "/") { if dir == "testdata" || strings.HasPrefix(dir, ".") && dir != "." || strings.HasPrefix(dir, "_") { return false } @@ -750,7 +750,7 @@ func Run(m Mutation, a Asked) (Outcome, string, error) { if err != nil { return 0, said.String(), fmt.Errorf("mutate: listing %s: %w", strings.Join(set.pkgs, " "), err) } - for _, line := range strings.Split(strings.TrimSpace(string(listed)), "\n") { + for line := range strings.SplitSeq(strings.TrimSpace(string(listed)), "\n") { path, pkgDir, _ := strings.Cut(line, " ") outcome, err := runPackage(tree, path, pkgDir, set.dir, set.what, set.only, timeout, a.Overlay, &said) if err != nil || outcome != Survived { @@ -857,7 +857,7 @@ func Importers() (map[string][]string, error) { // path it or its tests import. func importersFrom(prefix, listing string) map[string][]string { byDir := map[string][]string{} - for _, line := range strings.Split(listing, "\n") { + for line := range strings.SplitSeq(listing, "\n") { fields := strings.Fields(line) if len(fields) == 0 || !strings.HasPrefix(fields[0], prefix) { continue diff --git a/internal/mutate/runner.go b/internal/mutate/runner.go index 4b0b1a4..b036b11 100644 --- a/internal/mutate/runner.go +++ b/internal/mutate/runner.go @@ -64,13 +64,11 @@ func RunAll(chosen []Mutation, importers map[string][]string, timeout string, jo results := make(chan result) var wg sync.WaitGroup for i, dir := range dirs { - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { p := pkgRun{dir: dir, work: filepath.Join(work, strconv.Itoa(i)), timeout: timeout, slots: slots, builds: b, importers: importers[filepath.ToSlash(dir)], results: results, out: w} p.run(byDir[dir], covers) - }() + }) } go func() { wg.Wait(); close(results) }() @@ -147,17 +145,13 @@ func (p pkgRun) run(ms []Mutation, covers *coverages) { } var wg sync.WaitGroup for _, m := range s.Built { - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { outcome, err := p.built(m, s, c) p.results <- result{m: m, outcome: outcome, err: err} - }() + }) } for i, m := range s.Alone { - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { // Measured before a slot is taken: the measuring takes slots of its own, and holding // one while waiting on the others is how a budget of one never finishes. reaching := covers.of(p.dir) @@ -165,7 +159,7 @@ func (p pkgRun) run(ms []Mutation, covers *coverages) { defer func() { p.slots <- tree }() outcome, err := runAlone(m, filepath.Join(p.work, "alone-"+strconv.Itoa(i)), p.timeout, reaching, p.importers, tree, p.out) p.results <- result{m: m, outcome: outcome, err: err} - }() + }) } wg.Wait() } diff --git a/internal/mutate/tree.go b/internal/mutate/tree.go index 932e801..5cc04d6 100644 --- a/internal/mutate/tree.go +++ b/internal/mutate/tree.go @@ -184,7 +184,7 @@ func moduleFiles(root string) ([]string, error) { return nil, fmt.Errorf("git %s: %w", strings.Join(args, " "), err) } ignored := slices.Contains(args, "--ignored") - for _, path := range strings.Split(string(said), "\x00") { + for path := range strings.SplitSeq(string(said), "\x00") { dir := strings.HasSuffix(path, "/") // An ignored file is a build's or a run's output, which no test reads in place of // the source; a directory may be what one does read, node_modules or a checkout. diff --git a/internal/proven/github.go b/internal/proven/github.go index d20ba22..117f526 100644 --- a/internal/proven/github.go +++ b/internal/proven/github.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "io" + "maps" "net/http" "net/url" "os/exec" @@ -27,9 +28,7 @@ type GitHub struct { // head_sha, as the API names them - newest first. func (g GitHub) Runs(ctx context.Context, workflow string, query url.Values, limit int) ([]Run, error) { q := url.Values{} - for k, v := range query { - q[k] = v - } + maps.Copy(q, query) q.Set("per_page", strconv.Itoa(limit)) var page struct { Runs []Run `json:"workflow_runs"` @@ -231,7 +230,7 @@ func FirstParent(ctx context.Context, root, sha string, n int) ([]Commit, error) return nil, fmt.Errorf("git log %s in %s: %w", sha, root, err) } var commits []Commit - for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") { + for line := range strings.SplitSeq(strings.TrimSpace(string(out)), "\n") { if h, t, ok := strings.Cut(line, " "); ok { commits = append(commits, Commit{SHA: h, Tree: t}) } diff --git a/internal/refs/refs.go b/internal/refs/refs.go index 2829261..ba18f86 100644 --- a/internal/refs/refs.go +++ b/internal/refs/refs.go @@ -270,11 +270,11 @@ func globResolves(root, pattern string) bool { // literalPrefix is the directory part of the pattern before its first wildcard. func literalPrefix(pattern string) string { - i := strings.IndexByte(pattern, '*') - if i < 0 { // mutate-exempt: a pattern starts with a top-level directory, so a * is never at 0 + before, _, ok := strings.Cut(pattern, "*") + if !ok { // mutate-exempt: a pattern starts with a top-level directory, so a * is never at 0 return pattern } - if j := strings.LastIndexByte(pattern[:i], '/'); j >= 0 { + if j := strings.LastIndexByte(before, '/'); j >= 0 { return pattern[:j] } return "." diff --git a/internal/sfw/check.go b/internal/sfw/check.go index 84e6a31..1f91ec8 100644 --- a/internal/sfw/check.go +++ b/internal/sfw/check.go @@ -245,7 +245,7 @@ func commands(k kind, raw []byte) ([]shell.Line, error) { func segments(text string) []string { text = strings.NewReplacer("$(", "\n", "`", "\n", ")", "\n", "&&", "\n", "||", "\n", ";", "\n", "|", "\n").Replace(text) var out []string - for _, s := range strings.Split(text, "\n") { + for s := range strings.SplitSeq(text, "\n") { s = strings.TrimSpace(s) s = strings.TrimSpace(strings.TrimPrefix(s, "RUN ")) if s != "" { diff --git a/internal/shell/shell.go b/internal/shell/shell.go index 8bd7c84..b808330 100644 --- a/internal/shell/shell.go +++ b/internal/shell/shell.go @@ -23,8 +23,8 @@ func Lines(text string, first int) []Line { if strings.HasPrefix(strings.TrimSpace(l), "#") { continue } - if strings.HasSuffix(l, "\\") { - cur.WriteString(strings.TrimSuffix(l, "\\") + " ") + if before, ok := strings.CutSuffix(l, "\\"); ok { + cur.WriteString(before + " ") continue } cur.WriteString(l) diff --git a/internal/taskgate/taskfile.go b/internal/taskgate/taskfile.go index 75f6a90..08d9cb3 100644 --- a/internal/taskgate/taskfile.go +++ b/internal/taskgate/taskfile.go @@ -256,7 +256,7 @@ func isShell(rel string, raw []byte) bool { // are scripts is read from the files. func called(rel, line string, listed map[string]bool) []string { var out []string - for _, w := range strings.Fields(line) { + for w := range strings.FieldsSeq(line) { w = strings.Trim(w, `"'()$;&|`) for _, p := range []string{path.Join(path.Dir(rel), w), path.Clean(w)} { if listed[p] { diff --git a/internal/taskgate/taskgate.go b/internal/taskgate/taskgate.go index 26439a4..4c563a0 100644 --- a/internal/taskgate/taskgate.go +++ b/internal/taskgate/taskgate.go @@ -92,7 +92,7 @@ func Check(root string, limits Limits, known map[string]bool) ([]Finding, error) } listed := map[string]bool{} var workflows, taskfiles []string - for _, rel := range strings.Fields(string(out)) { + for rel := range strings.FieldsSeq(string(out)) { listed[rel] = true switch { case workflow(rel): @@ -259,7 +259,7 @@ func isTask(line string) bool { if !strings.HasPrefix(line+" ", "task ") { return false } - for _, w := range strings.Fields(line) { + for w := range strings.FieldsSeq(line) { // One command: a second one after it is shell around the task, not the task. if w == "&&" || w == "||" || w == ";" || w == "|" || strings.HasPrefix(w, ">") { return false diff --git a/sbom/builders.go b/sbom/builders.go index 4b1f317..df5cbe5 100644 --- a/sbom/builders.go +++ b/sbom/builders.go @@ -157,9 +157,9 @@ func Dpkg(raw []byte, distro string) ([]cdx.Component, error) { // has gone out of step with the build. func Apk(raw []byte, distro string, only []string) (shipped, built []cdx.Component, err error) { seen := map[string]bool{} - for _, block := range strings.Split(string(raw), "\n\n") { + for block := range strings.SplitSeq(string(raw), "\n\n") { var name, version, arch string - for _, line := range strings.Split(block, "\n") { + for line := range strings.SplitSeq(block, "\n") { k, v, _ := strings.Cut(line, ":") switch k { case "P": diff --git a/versions/gate/gate.go b/versions/gate/gate.go index 9ab92dd..7d622ab 100644 --- a/versions/gate/gate.go +++ b/versions/gate/gate.go @@ -91,7 +91,7 @@ func (g Gate) Check() error { for _, re := range reads { // mutate-exempt: any n below zero is every match. for _, m := range re.FindAllStringSubmatch(files[rel], -1) { - for _, n := range strings.Fields(m[1]) { + for n := range strings.FieldsSeq(m[1]) { if _, err := v.Get(n); err != nil && !used[n] { errs = append(errs, fmt.Errorf("%s reads %s: %w", rel, n, err)) } From 07ad5f9ed5ad3ebf14362238903bbd20de43061e Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Wed, 18 Nov 2026 17:17:54 -0300 Subject: [PATCH 2/9] mutate, gencache: a map's keys in order are slices.Sorted(maps.Keys) Co-Authored-By: Claude Opus 5.5 --- internal/gencache/gencache.go | 10 +++------- internal/mutate/cache.go | 10 +++------- internal/mutate/schema.go | 8 +++----- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/internal/gencache/gencache.go b/internal/gencache/gencache.go index 96776fd..16c58cd 100644 --- a/internal/gencache/gencache.go +++ b/internal/gencache/gencache.go @@ -16,12 +16,13 @@ import ( "go/parser" "go/token" "io" + "maps" "os" "os/exec" "path" "path/filepath" "regexp" - "sort" + "slices" "strconv" "strings" "sync" @@ -349,12 +350,7 @@ func (r *run) key(ctx context.Context, s step) (string, string) { dirs[dep] = q.Dir } } - names := make([]string, 0, len(dirs)) - for name := range dirs { - names = append(names, name) - } - sort.Strings(names) - for _, name := range names { + for _, name := range slices.Sorted(maps.Keys(dirs)) { own, err := r.dirHash(dirs[name], tests) if err != nil { return "", "a file it reads cannot be read" diff --git a/internal/mutate/cache.go b/internal/mutate/cache.go index f4db02c..f88ae46 100644 --- a/internal/mutate/cache.go +++ b/internal/mutate/cache.go @@ -6,11 +6,12 @@ import ( "errors" "fmt" "io/fs" + "maps" "os" "os/exec" "path/filepath" "runtime/debug" - "sort" + "slices" "strings" "sync" ) @@ -289,10 +290,5 @@ func (g *moduleGraph) closure(roots []string) []string { walk(t) } } - out := make([]string, 0, len(seen)) - for d := range seen { - out = append(out, d) - } - sort.Strings(out) - return out + return slices.Sorted(maps.Keys(seen)) } diff --git a/internal/mutate/schema.go b/internal/mutate/schema.go index 671393e..c8afbd2 100644 --- a/internal/mutate/schema.go +++ b/internal/mutate/schema.go @@ -7,10 +7,12 @@ import ( "go/ast" "go/parser" "go/token" + "maps" "os" "os/exec" "path/filepath" "regexp" + "slices" "sort" "strconv" "strings" @@ -325,11 +327,7 @@ func writeSchema(dir string, ms []Mutation, work string) (string, error) { for _, m := range ms { byFile[m.File] = append(byFile[m.File], m) } - files := make([]string, 0, len(byFile)) - for file := range byFile { - files = append(files, file) - } - sort.Strings(files) + files := slices.Sorted(maps.Keys(byFile)) replace := map[string]string{} for i, file := range files { source, err := os.ReadFile(file) //nolint:gosec // a file of this repository's diff From b3c16c65a6d580dae5fb58d4e0921dc3ac9eb90e Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Wed, 18 Nov 2026 17:13:32 -0300 Subject: [PATCH 3/9] refs, taskgate: a sorted list without its repeats is slices.Compact Co-Authored-By: Claude Opus 5.5 --- internal/refs/refs.go | 14 ++------------ internal/taskgate/taskfile.go | 18 +++--------------- 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/internal/refs/refs.go b/internal/refs/refs.go index ba18f86..7572914 100644 --- a/internal/refs/refs.go +++ b/internal/refs/refs.go @@ -24,6 +24,7 @@ import ( "path" "path/filepath" "regexp" + "slices" "sort" "strings" ) @@ -151,7 +152,7 @@ func Check(o Options) ([]Finding, error) { } sort.Slice(found, func(i, j int) bool { return found[i].Key() < found[j].Key() }) - return dedupe(found), nil + return slices.CompactFunc(found, func(a, b Finding) bool { return a.Key() == b.Key() }), nil } func taskNames(o Options, rootTasks []string, dir string) (map[string]bool, error) { @@ -300,17 +301,6 @@ func globRegexp(pattern string) (*regexp.Regexp, error) { return regexp.Compile(b.String()) } -func dedupe(in []Finding) []Finding { - var out []Finding - for i, f := range in { - if i > 0 && in[i-1].Key() == f.Key() { - continue - } - out = append(out, f) - } - return out -} - // TaskCommand is how to run the Task a TaskLister asks: exe when one is named, else the Task the // module's go.mod pins, else task on PATH. A repository that takes Task as a go.mod tool runs it as // `go tool task`, which puts no task on PATH. `go tool -n task` says whether go.mod pins one, but diff --git a/internal/taskgate/taskfile.go b/internal/taskgate/taskfile.go index 08d9cb3..2e639ff 100644 --- a/internal/taskgate/taskfile.go +++ b/internal/taskgate/taskfile.go @@ -5,7 +5,7 @@ import ( "path" "path/filepath" "regexp" - "sort" + "slices" "strings" "go.yaml.in/yaml/v3" @@ -103,7 +103,8 @@ func tasks(root string, files []string, listed map[string]bool, limits Limits) ( } } } - s.Reads = unique(s.Reads) + slices.Sort(s.Reads) + s.Reads = slices.Compact(s.Reads) if (limits.Script > 0 && s.Lines > limits.Script) || len(s.Reads) > 0 { findings = append(findings, *s) } @@ -267,16 +268,3 @@ func called(rel, line string, listed map[string]bool) []string { } return out } - -func unique(words []string) []string { - seen := map[string]bool{} - var out []string - for _, w := range words { - if !seen[w] { - seen[w] = true - out = append(out, w) - } - } - sort.Strings(out) - return out -} From 85593718820703e9b65b4014cd4ecb37b9ad83e5 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Wed, 18 Nov 2026 17:13:47 -0300 Subject: [PATCH 4/9] proven, ghatrace: the first value that is set is cmp.Or Co-Authored-By: Claude Opus 5.5 --- cmd/ghatrace/main.go | 4 +--- cmd/proven/main.go | 11 +++++------ ghatrace/span.go | 9 +++------ 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/cmd/ghatrace/main.go b/cmd/ghatrace/main.go index 33c745e..2f87374 100644 --- a/cmd/ghatrace/main.go +++ b/cmd/ghatrace/main.go @@ -265,9 +265,7 @@ func span(ctx context.Context, args []string) error { if len(argv) == 0 { return errors.New("span: a command is needed after --") } - if *name == "" { - *name = strings.Join(argv, " ") - } + *name = cmp.Or(*name, strings.Join(argv, " ")) cmd := exec.CommandContext(ctx, argv[0], argv[1:]...) //nolint:gosec // the command the caller asked to run cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr return timed(cmd, *name, nil) diff --git a/cmd/proven/main.go b/cmd/proven/main.go index d5e4378..6cfc63d 100644 --- a/cmd/proven/main.go +++ b/cmd/proven/main.go @@ -14,6 +14,7 @@ package main import ( + "cmp" "context" "encoding/json" "errors" @@ -96,12 +97,10 @@ func run(ctx context.Context, argv []string) error { } else if *sha == "HEAD" { return fmt.Errorf("-sha or GITHUB_SHA names the commit; HEAD: %w", err) } - gh := proven.GitHub{API: "https://api.github.com", Repo: *repo, Token: os.Getenv("GH_TOKEN")} - if api := os.Getenv("GITHUB_API_URL"); api != "" { - gh.API = api - } - if gh.Token == "" { - gh.Token = os.Getenv("GITHUB_TOKEN") + gh := proven.GitHub{ + API: cmp.Or(os.Getenv("GITHUB_API_URL"), "https://api.github.com"), + Repo: *repo, + Token: cmp.Or(os.Getenv("GH_TOKEN"), os.Getenv("GITHUB_TOKEN")), } trees := proven.TreesOf(".", gh) ev := strings.Split(*events, ",") diff --git a/ghatrace/span.go b/ghatrace/span.go index 3cc9083..6b9913f 100644 --- a/ghatrace/span.go +++ b/ghatrace/span.go @@ -5,6 +5,7 @@ package ghatrace import ( "bufio" + "cmp" "encoding/json" "errors" "fmt" @@ -50,12 +51,8 @@ func Record(s Span) error { if path == "" { return nil } - if s.Runner == "" { - s.Runner = os.Getenv("RUNNER_NAME") - } - if s.Job == "" { - s.Job = os.Getenv("GITHUB_JOB") - } + s.Runner = cmp.Or(s.Runner, os.Getenv("RUNNER_NAME")) + s.Job = cmp.Or(s.Job, os.Getenv("GITHUB_JOB")) line, err := json.Marshal(s) if err != nil { return err From aa53b7da9c2ef9bac6d114208f7568cc877896dd Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Wed, 18 Nov 2026 17:13:58 -0300 Subject: [PATCH 5/9] exposure: the allowlist is allow.Split, with * in its key Co-Authored-By: Claude Opus 5.5 --- internal/exposure/secrets.go | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/internal/exposure/secrets.go b/internal/exposure/secrets.go index 5981d23..e52899f 100644 --- a/internal/exposure/secrets.go +++ b/internal/exposure/secrets.go @@ -4,7 +4,8 @@ import ( "encoding/json" "fmt" "os" - "sort" + + "github.com/spin-stack/go-tools/internal/allow" ) // Secrets is gitleaks' JSON report as findings, one for each secret it found, each of kind @@ -37,22 +38,10 @@ func Secrets(report string, onDefault func(commit string) bool) ([]Finding, erro // allowlist's keys that answer nothing any more, sorted. A key answers a finding by its kind // and value, or by ` *` for every value of the kind. func Explain(allowed map[string]bool, found []Finding) (unexplained []Finding, stale []string) { - used := map[string]bool{} - for _, f := range found { - switch k, any := f.Key(), f.Kind+" *"; { - case allowed[k]: - used[k] = true - case allowed[any]: - used[any] = true - default: - unexplained = append(unexplained, f) - } - } - for k := range allowed { - if !used[k] { - stale = append(stale, k) + return allow.Split(allowed, found, func(f Finding) string { + if allowed[f.Key()] { + return f.Key() } - } - sort.Strings(stale) - return unexplained, stale + return f.Kind + " *" + }) } From 86607575520377944ea729aa00cd27b8dc5ed50a Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Wed, 18 Nov 2026 17:14:25 -0300 Subject: [PATCH 6/9] fetch: FileSum is the one SHA-256 of a fetched file, for toolcache, upstream and sfw Co-Authored-By: Claude Opus 5.5 --- internal/fetch/fetch.go | 16 ++++++++++++++++ internal/sfw/binary.go | 19 ++----------------- internal/toolcache/toolcache.go | 17 +---------------- versions/upstream/upstream.go | 18 ++---------------- 4 files changed, 21 insertions(+), 49 deletions(-) diff --git a/internal/fetch/fetch.go b/internal/fetch/fetch.go index ee4dfd7..37257f0 100644 --- a/internal/fetch/fetch.go +++ b/internal/fetch/fetch.go @@ -6,6 +6,8 @@ package fetch import ( "context" + "crypto/sha256" + "encoding/hex" "errors" "fmt" "io" @@ -337,3 +339,17 @@ func cause(ctx context.Context, err error) error { } return err } + +// FileSum is the SHA-256 of the file at p, in hex: what a pin names, for the file a fetch wrote. +func FileSum(p string) (string, error) { + f, err := os.Open(p) //nolint:gosec // a file the caller fetched, to check against its pin + if err != nil { + return "", err + } + defer func() { _ = f.Close() }() // read-only + h := sha256.New() + if _, err := io.Copy(h, f); err != nil { + return "", err + } + return hex.EncodeToString(h.Sum(nil)), nil +} diff --git a/internal/sfw/binary.go b/internal/sfw/binary.go index 28f9fdf..fbcd75b 100644 --- a/internal/sfw/binary.go +++ b/internal/sfw/binary.go @@ -6,15 +6,13 @@ package sfw import ( "context" - "crypto/sha256" - "encoding/hex" "errors" "fmt" - "io" "io/fs" "os" "path/filepath" + "github.com/spin-stack/go-tools/internal/fetch" "github.com/spin-stack/go-tools/versions" "github.com/spin-stack/go-tools/versions/upstream" ) @@ -38,7 +36,7 @@ func Entry(v *versions.Versions, goos, goarch string) (versions.Entry, error) { func Binary(ctx context.Context, e versions.Entry, cache string) (string, error) { dir := filepath.Join(cache, e.Pin) path := filepath.Join(dir, "sfw") - switch sum, err := sha256File(path); { + switch sum, err := fetch.FileSum(path); { case err == nil && sum == e.Pin: return path, nil case err != nil && !errors.Is(err, fs.ErrNotExist): @@ -73,16 +71,3 @@ func Binary(ctx context.Context, e versions.Entry, cache string) (string, error) } return path, nil } - -func sha256File(path string) (string, error) { - f, err := os.Open(path) //nolint:gosec // the cache's own file, under a directory named by its pin - if err != nil { - return "", err - } - defer func() { _ = f.Close() }() // read-only - h := sha256.New() - if _, err := io.Copy(h, f); err != nil { - return "", err - } - return hex.EncodeToString(h.Sum(nil)), nil -} diff --git a/internal/toolcache/toolcache.go b/internal/toolcache/toolcache.go index 8bc3da1..ecd4478 100644 --- a/internal/toolcache/toolcache.go +++ b/internal/toolcache/toolcache.go @@ -10,8 +10,6 @@ import ( "archive/tar" "compress/gzip" "context" - "crypto/sha256" - "encoding/hex" "errors" "fmt" "io" @@ -63,7 +61,7 @@ func install(ctx context.Context, e versions.Entry, root, goos, goarch string) ( if err != nil { return "", fmt.Errorf("toolcache: %s: %w", e.Name, err) } - if got, err := sum(archive.Name()); err != nil || got != e.Pin { + if got, err := fetch.FileSum(archive.Name()); err != nil || got != e.Pin { return "", errors.Join(err, fmt.Errorf("toolcache: %s is not what versions.yaml pins: its SHA-256 is %s", e.URL(), got)) } part, err := os.MkdirTemp(filepath.Dir(dir), e.Pin+".*.part") @@ -242,16 +240,3 @@ func write(target string, r io.Reader, mode fs.FileMode) error { _, err = io.Copy(out, r) //nolint:gosec // an archive this package checked against its pin, not one a stranger sent return errors.Join(err, out.Close()) } - -func sum(p string) (string, error) { - f, err := os.Open(p) //nolint:gosec // the archive this package just downloaded - if err != nil { - return "", err - } - defer func() { _ = f.Close() }() // read-only - h := sha256.New() - if _, err := io.Copy(h, f); err != nil { - return "", err - } - return hex.EncodeToString(h.Sum(nil)), nil -} diff --git a/versions/upstream/upstream.go b/versions/upstream/upstream.go index 9337c9d..3511bbc 100644 --- a/versions/upstream/upstream.go +++ b/versions/upstream/upstream.go @@ -270,7 +270,7 @@ func PinnedFile(ctx context.Context, e versions.Entry, dir string) (string, erro return "", err } file := filepath.Join(dir, path.Base(e.URL())) - if got, err := fileSum(file); err == nil && got == e.Pin { + if got, err := fetch.FileSum(file); err == nil && got == e.Pin { return file, nil } if err := os.MkdirAll(dir, 0o750); err != nil { @@ -288,7 +288,7 @@ func PinnedFile(ctx context.Context, e versions.Entry, dir string) (string, erro if err != nil { return "", fmt.Errorf("versions: %s: %w", e.Name, err) } - got, err := fileSum(part.Name()) + got, err := fetch.FileSum(part.Name()) if err != nil { // mutate-exempt: the file this function just wrote and closed return "", fmt.Errorf("versions: %w", err) } @@ -301,20 +301,6 @@ func PinnedFile(ctx context.Context, e versions.Entry, dir string) (string, erro return file, nil } -// fileSum is the SHA-256 of the file at p. -func fileSum(p string) (string, error) { - f, err := os.Open(p) //nolint:gosec // the cache's own file - if err != nil { - return "", err - } - defer func() { _ = f.Close() }() // read-only - h := sha256.New() - if _, err := io.Copy(h, f); err != nil { - return "", err - } - return hex.EncodeToString(h.Sum(nil)), nil -} - func run(ctx context.Context, name string, args ...string) (string, error) { var stderr strings.Builder cmd := exec.CommandContext(ctx, name, args...) From f74bfcd698d65e7512a158a291c247361f6155bc Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Wed, 18 Nov 2026 17:14:58 -0300 Subject: [PATCH 7/9] mutate: the cache is asked from one goroutine, and takes no lock Co-Authored-By: Claude Opus 5.5 --- internal/mutate/cache.go | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/internal/mutate/cache.go b/internal/mutate/cache.go index f88ae46..2741c0d 100644 --- a/internal/mutate/cache.go +++ b/internal/mutate/cache.go @@ -13,7 +13,6 @@ import ( "runtime/debug" "slices" "strings" - "sync" ) // Cache keeps the edits a run's tests refused, so the next run over the same code does not ask @@ -30,9 +29,7 @@ import ( // Only refusals are kept. A survivor fails the run and is the next one's question; an edit that // did not build costs a failed build, which is what asking the cache would save. type Cache struct { - dir string - - mu sync.Mutex + dir string modules map[string]*moduleGraph // by the module's root digests map[string]string // a package directory's files, by directory keys map[int]string // by Mutation.ID, from Known for Keep @@ -54,9 +51,7 @@ func (c *Cache) Known(chosen []Mutation, importers map[string][]string) (fresh, if err != nil { return nil, nil, err } - c.mu.Lock() c.keys[m.ID] = key - c.mu.Unlock() if _, err := os.Stat(c.path(key)); err == nil { refused = append(refused, m) continue @@ -69,9 +64,7 @@ func (c *Cache) Known(chosen []Mutation, importers map[string][]string) (fresh, // Keep records each of refused, which Known was asked about, as refused. func (c *Cache) Keep(refused []Mutation) error { for _, m := range refused { - c.mu.Lock() key, ok := c.keys[m.ID] - c.mu.Unlock() if !ok { return fmt.Errorf("mutate: %s was not looked up in the cache", m) } @@ -142,9 +135,7 @@ func toolVersion() string { // dirDigest is the files directly in dir, and everything under its testdata, by name and content. func (c *Cache) dirDigest(dir string) (string, error) { - c.mu.Lock() digest, ok := c.digests[dir] - c.mu.Unlock() if ok { return digest, nil } @@ -174,9 +165,7 @@ func (c *Cache) dirDigest(dir string) (string, error) { return "", fmt.Errorf("mutate: the cache: %w", err) } digest = hex.EncodeToString(h.Sum(nil)) - c.mu.Lock() c.digests[dir] = digest - c.mu.Unlock() return digest, nil } @@ -203,9 +192,7 @@ type moduleGraph struct { // module is the graph of the module dir is in, listed once. func (c *Cache) module(dir string) (*moduleGraph, error) { - c.mu.Lock() g, ok := c.modules[dir] - c.mu.Unlock() if ok { return g, nil } @@ -213,17 +200,13 @@ func (c *Cache) module(dir string) (*moduleGraph, error) { if err != nil { return nil, fmt.Errorf("mutate: the cache: %w", err) } - c.mu.Lock() g, ok = c.modules[root] - c.mu.Unlock() if !ok { if g, err = listModule(root); err != nil { return nil, err } } - c.mu.Lock() c.modules[root], c.modules[dir] = g, g - c.mu.Unlock() return g, nil } From fce5caceb3e42a9a8cf15e1163dbef243c17a80e Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Wed, 18 Nov 2026 17:15:56 -0300 Subject: [PATCH 8/9] mutate: one testArgs for Run and Ask, the targeted allowance in it Co-Authored-By: Claude Opus 5.5 --- internal/mutate/mutate.go | 31 ++++++++++++++++--------------- internal/mutate/schema.go | 11 +---------- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/internal/mutate/mutate.go b/internal/mutate/mutate.go index a7ccb36..213ca34 100644 --- a/internal/mutate/mutate.go +++ b/internal/mutate/mutate.go @@ -676,6 +676,20 @@ const ( // targetedTimeout is how long the tests that reach a mutated line may take. const targetedTimeout = "1m" +// testArgs are a test binary's flags: every test under timeout, or only those named, under +// targetedTimeout. The few tests that reach the line ran in a fraction of timeout unmutated: an +// edit that makes one loop for ever is refused as soon as targetedTimeout runs out, not after the +// package's whole allowance. +func testArgs(timeout string, only []string) []string { + // mutate-exempt: which allowance a run gets; only a test an edit hangs tells them apart, and + // only after a minute of it. + if len(only) == 0 { + return []string{"-test.count=1", "-test.failfast", "-test.v", "-test.timeout", timeout} + } + return []string{"-test.count=1", "-test.failfast", "-test.v", "-test.timeout", targetedTimeout, + "-test.run", "^(" + strings.Join(only, "|") + ")$"} +} + // Asked is how one mutation is put to the tests. type Asked struct { // Overlay is the file Overlay made, which has the mutation built in the file's place; empty @@ -735,15 +749,6 @@ func Run(m Mutation, a Asked) (Outcome, string, error) { } var said strings.Builder for _, set := range runs { - timeout := a.Timeout - // mutate-exempt: which allowance a run gets; only a test an edit hangs tells them apart, - // and only after a minute of it. - if len(set.only) > 0 { - // The few tests that reach the line, which ran in a fraction of this unmutated: an edit - // that makes one loop for ever is refused as soon as this runs out, not after the - // package's whole allowance. - timeout = targetedTimeout - } list := exec.Command("go", append([]string{"list", "-f", "{{.ImportPath}} {{.Dir}}"}, set.pkgs...)...) //nolint:gosec // go list over this repository's packages list.Dir = set.dir listed, err := output("listing", list) @@ -752,7 +757,7 @@ func Run(m Mutation, a Asked) (Outcome, string, error) { } for line := range strings.SplitSeq(strings.TrimSpace(string(listed)), "\n") { path, pkgDir, _ := strings.Cut(line, " ") - outcome, err := runPackage(tree, path, pkgDir, set.dir, set.what, set.only, timeout, a.Overlay, &said) + outcome, err := runPackage(tree, path, pkgDir, set.dir, set.what, set.only, a.Timeout, a.Overlay, &said) if err != nil || outcome != Survived { return outcome, said.String(), err } @@ -785,11 +790,7 @@ func runPackage(tree *Tree, path, pkgDir, dir, what string, only []string, timeo if _, err := os.Stat(bin); err != nil { return Survived, nil //nolint:nilerr // no test binary: the package has no tests } - args = []string{"-test.count=1", "-test.failfast", "-test.v", "-test.timeout", timeout} - if len(only) > 0 { - args = append(args, "-test.run", "^("+strings.Join(only, "|")+")$") - } - run := exec.Command(bin, args...) //nolint:gosec // a test binary this run built + run := exec.Command(bin, testArgs(timeout, only)...) //nolint:gosec // a test binary this run built run.Env = testEnv() var runErr error if err := tree.in(pkgDir, func(at, tmp string) { diff --git a/internal/mutate/schema.go b/internal/mutate/schema.go index c8afbd2..bb6b522 100644 --- a/internal/mutate/schema.go +++ b/internal/mutate/schema.go @@ -366,16 +366,7 @@ func writeSchema(dir string, ms []Mutation, work string) (string, error) { // switched on, stopping at the first test that fails: only, when it names any, and every test // when it is nil. func Ask(tree *Tree, bin, dir string, id int, timeout string, only []string) (Outcome, string, error) { - // mutate-exempt: which allowance a run gets; only a test an edit hangs tells them apart, and - // only after a minute of it. - if len(only) > 0 { - timeout = targetedTimeout - } - args := []string{"-test.count=1", "-test.failfast", "-test.v", "-test.timeout", timeout} - if len(only) > 0 { - args = append(args, "-test.run", "^("+strings.Join(only, "|")+")$") - } - cmd := exec.Command(bin, args...) //nolint:gosec // a test binary this run built + cmd := exec.Command(bin, testArgs(timeout, only)...) //nolint:gosec // a test binary this run built cmd.Env = testEnv(switchEnv + "=" + strconv.Itoa(id)) var ( out []byte From 841dadfb52b5d95377f9e25184445abcc4d7234f Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Wed, 18 Nov 2026 17:16:00 -0300 Subject: [PATCH 9/9] refs: no exempt on a strings.Cut's ok, which no edit of mutate's turns into the same answer Co-Authored-By: Claude Opus 5.5 --- internal/refs/refs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/refs/refs.go b/internal/refs/refs.go index 7572914..834c403 100644 --- a/internal/refs/refs.go +++ b/internal/refs/refs.go @@ -272,7 +272,7 @@ func globResolves(root, pattern string) bool { // literalPrefix is the directory part of the pattern before its first wildcard. func literalPrefix(pattern string) string { before, _, ok := strings.Cut(pattern, "*") - if !ok { // mutate-exempt: a pattern starts with a top-level directory, so a * is never at 0 + if !ok { return pattern } if j := strings.LastIndexByte(before, '/'); j >= 0 {