From df296f00fb37263ebf57fe141f2dfb763f82eaa2 Mon Sep 17 00:00:00 2001 From: adssib <75389300+adssib@users.noreply.github.com> Date: Sat, 21 Nov 2026 13:43:05 -0500 Subject: [PATCH 1/4] import core/extract directly; drop the feed aliases Co-Authored-By: Claude Opus 5.5 Signed-off-by: adssib <75389300+adssib@users.noreply.github.com> --- cmd/new-plugin/formats.go | 7 +++++-- .../feed => core/extract}/feed_test.go | 12 ++++++------ kinds/notices/feed/extract.go | 19 ------------------- kinds/notices/feed/feed.go | 5 +++-- kinds/notices/feed/helpers.go | 5 +++-- kinds/openapi/openapi_test.go | 8 +++----- providers/cloudflare/api.go | 15 ++++++++------- providers/cloudflare/api_test.go | 7 ++++--- providers/github/actions.go | 13 +++++++------ providers/github/actions_test.go | 5 +++-- providers/google/vertex_ai_models.go | 19 ++++++++++--------- 11 files changed, 52 insertions(+), 63 deletions(-) rename {kinds/notices/feed => core/extract}/feed_test.go (74%) delete mode 100644 kinds/notices/feed/extract.go diff --git a/cmd/new-plugin/formats.go b/cmd/new-plugin/formats.go index 2a7df44..decc458 100644 --- a/cmd/new-plugin/formats.go +++ b/cmd/new-plugin/formats.go @@ -37,7 +37,10 @@ var formats = map[string]formatSpec{ layer: "api", def: `package {{.Package}} -import "github.com/patch-it-dev/patch-it-plugins/kinds/notices/feed" +import ( + "github.com/patch-it-dev/patch-it-plugins/core/extract" + "github.com/patch-it-dev/patch-it-plugins/kinds/notices/feed" +) // {{.Ident}} is {{.Provider}}'s feed of changes. // @@ -60,7 +63,7 @@ var {{.Ident}} = feed.Feed{ // an entry that isn't a breaking change or a deprecation. Precision over // recall: readCloudflareAPI in providers/cloudflare/api.go is a worked // example. -func read{{.Ident}}(e feed.Entry) []feed.Finding { +func read{{.Ident}}(e extract.Entry) []feed.Finding { return nil } `, diff --git a/kinds/notices/feed/feed_test.go b/core/extract/feed_test.go similarity index 74% rename from kinds/notices/feed/feed_test.go rename to core/extract/feed_test.go index 4193067..d67425f 100644 --- a/kinds/notices/feed/feed_test.go +++ b/core/extract/feed_test.go @@ -1,16 +1,16 @@ -package feed +package extract import ( "testing" ) -func TestParseRefusesWhatIsntAFeed(t *testing.T) { +func TestParseFeedRefusesWhatIsntAFeed(t *testing.T) { for name, b := range map[string]string{ "html": "moved", "no items": `x`, "no entry": `x`, } { - if _, err := Parse([]byte(b)); err == nil { + if _, err := ParseFeed([]byte(b)); err == nil { t.Errorf("%s: want an error, never zero events read as a quiet week", name) } } @@ -18,13 +18,13 @@ func TestParseRefusesWhatIsntAFeed(t *testing.T) { // RSS without content:encoded falls back to description; Atom takes the // alternate link and the category terms. -func TestParseReadsBothFormats(t *testing.T) { - r, err := Parse([]byte(`A & Bhttps://x.test/a +func TestParseFeedReadsBothFormats(t *testing.T) { + r, err := ParseFeed([]byte(`A & Bhttps://x.test/a Retired<p>text</p>`)) if err != nil || r[0].Title != "A & B" || r[0].HTML != "

text

" || r[0].Categories[0] != "Retired" || r[0].ID != "https://x.test/a" { t.Errorf("rss: %+v %v", r, err) } - a, err := Parse([]byte(`iT + a, err := ParseFeed([]byte(`iT <b>s</b>`)) if err != nil || a[0].Link != "https://x.test/e" || a[0].HTML != "s" || a[0].Categories[0] != "Deprecated" { diff --git a/kinds/notices/feed/extract.go b/kinds/notices/feed/extract.go deleted file mode 100644 index c7d14fe..0000000 --- a/kinds/notices/feed/extract.go +++ /dev/null @@ -1,19 +0,0 @@ -package feed - -import "github.com/patch-it-dev/patch-it-plugins/core/extract" - -// The feed and HTML helpers live in core/extract, for every reader; these -// names keep the readers here (and code that imports them) as they were. -type ( - Entry = extract.Entry - Section = extract.Section -) - -var ( - Parse = extract.ParseFeed - Text = extract.Text - Lines = extract.Lines - SplitBy = extract.SplitBy - Date = extract.Date - Codes = extract.Codes -) diff --git a/kinds/notices/feed/feed.go b/kinds/notices/feed/feed.go index 9f140c3..46b55f8 100644 --- a/kinds/notices/feed/feed.go +++ b/kinds/notices/feed/feed.go @@ -26,6 +26,7 @@ import ( "time" "github.com/patch-it-dev/patch-it-plugins/core/event" + "github.com/patch-it-dev/patch-it-plugins/core/extract" "github.com/patch-it-dev/patch-it-plugins/core/kit" ) @@ -40,7 +41,7 @@ type Feed struct { // Reader turns one entry into findings: what it can name for sure, and what // it drops. It returns nothing for an entry that isn't breaking or a // deprecation. -type Reader func(e Entry) []Finding +type Reader func(e extract.Entry) []Finding // Finding is one change a reader found in an entry, or one it dropped. type Finding struct { @@ -56,7 +57,7 @@ type Finding struct { // Findings reads every entry of a feed. func (f Feed) Findings(b []byte) ([]Finding, error) { - entries, err := Parse(b) + entries, err := extract.ParseFeed(b) if err != nil { return nil, err } diff --git a/kinds/notices/feed/helpers.go b/kinds/notices/feed/helpers.go index c269a79..7383af5 100644 --- a/kinds/notices/feed/helpers.go +++ b/kinds/notices/feed/helpers.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/patch-it-dev/patch-it-plugins/core/event" + "github.com/patch-it-dev/patch-it-plugins/core/extract" ) var ( @@ -36,12 +37,12 @@ func Dated(lines []string) (line, date string, ct event.ChangeType) { // The date after the words, not the first on the line: "deprecated // as of February 23, 2026 and will be shut down on August 23, 2026". if m := willStop.FindStringIndex(l); m != nil { - if d := Date(l[m[1]:]); d != "" { + if d := extract.Date(l[m[1]:]); d != "" { return l, d, event.ChangeTypeBreaking } } if m := willSoften.FindStringIndex(l); m != nil { - if d := Date(l[m[1]:]); d != "" { + if d := extract.Date(l[m[1]:]); d != "" { return l, d, event.ChangeTypeDeprecation } } diff --git a/kinds/openapi/openapi_test.go b/kinds/openapi/openapi_test.go index c8bd9d1..3c390cb 100644 --- a/kinds/openapi/openapi_test.go +++ b/kinds/openapi/openapi_test.go @@ -80,8 +80,6 @@ var specs = map[string]string{ "id":{"type":"string"},"latest_charge":{"type":"string"}}}}}}`, } -func openStore(*testing.T) *kittest.Mem { return kittest.NewMem() } - func storedEvents(t *testing.T, s *kittest.Mem) []string { t.Helper() events, err := s.All() @@ -99,7 +97,7 @@ func storedEvents(t *testing.T, s *kittest.Mem) []string { // stored as change events, once. func TestAPairStoresItsEventsOnce(t *testing.T) { ctx := context.Background() - s := openStore(t) + s := kittest.NewMem() if _, err := pair(ctx, s, fakeAdapter{specs: specs}, "v1", "v2"); err != nil { t.Fatalf("pair: %v", err) @@ -132,7 +130,7 @@ func TestAPairStoresItsEventsOnce(t *testing.T) { // hint source in these tests always errors: noChangelog). func TestIngestStoresEventsWhenTheChangelogIsUnreachable(t *testing.T) { ctx := context.Background() - s := openStore(t) + s := kittest.NewMem() if _, err := pair(ctx, s, fakeAdapter{specs: specs}, "v1", "v2"); err != nil { t.Fatalf("pair: %v", err) } @@ -152,7 +150,7 @@ func TestAPairAttachesMigrationHintsFromTheChangelog(t *testing.T) { }}} ctx := context.Background() - s := openStore(t) + s := kittest.NewMem() if _, err := pairWith(ctx, s, newPlugin(fakeAdapter{specs: specs}, withHints), "v1", "v2"); err != nil { t.Fatalf("pair: %v", err) } diff --git a/providers/cloudflare/api.go b/providers/cloudflare/api.go index 81e11cf..0f4964f 100644 --- a/providers/cloudflare/api.go +++ b/providers/cloudflare/api.go @@ -7,6 +7,7 @@ import ( "time" "github.com/patch-it-dev/patch-it-plugins/core/event" + "github.com/patch-it-dev/patch-it-plugins/core/extract" "github.com/patch-it-dev/patch-it-plugins/kinds/notices/feed" ) @@ -23,7 +24,7 @@ var API = feed.Feed{ Read: readCloudflareAPI, } -func readCloudflareAPI(e feed.Entry) []feed.Finding { +func readCloudflareAPI(e extract.Entry) []feed.Finding { title := strings.TrimPrefix(e.Title, "API deprecations - ") drop := func(why string) []feed.Finding { return []feed.Finding{{Entry: e.Link, Dropped: fmt.Sprintf("%q: %s", title, why)}} @@ -35,7 +36,7 @@ func readCloudflareAPI(e feed.Entry) []feed.Finding { return drop(`no "Deprecated APIs:" list of operations`) } - lines := feed.Lines(e.HTML) + lines := extract.Lines(e.HTML) for _, l := range lines { if cfNoAction.MatchString(l) { // The URL keeps working; only an SDK method moves (the Radar @@ -60,13 +61,13 @@ func readCloudflareAPI(e feed.Entry) []feed.Finding { } } for _, p := range cfParagraph.FindAllStringSubmatch(e.HTML, -1) { - if l := feed.Text(p[1]); cfStops.MatchString(l) { + if l := extract.Text(p[1]); cfStops.MatchString(l) { stopLine = l break } } - ct, date, dateLine := event.ChangeTypeDeprecation, feed.Date(depLine), depLine - if d := feed.Date(eolLine); d != "" && stopLine != "" { + ct, date, dateLine := event.ChangeTypeDeprecation, extract.Date(depLine), depLine + if d := extract.Date(eolLine); d != "" && stopLine != "" { ct, date, dateLine = event.ChangeTypeBreaking, d, eolLine } if date == "" { @@ -80,8 +81,8 @@ func readCloudflareAPI(e feed.Entry) []feed.Finding { var out []feed.Finding for _, li := range feed.ListItem.FindAllStringSubmatch(m[1], -1) { - codes := feed.Codes(li[1]) - text := feed.Text(li[1]) + codes := extract.Codes(li[1]) + text := extract.Text(li[1]) // One operation, in code, first, and at most a name after it: "GET // /path — List domains". Not "GET and POST /path", a hostname, nor // "POST /path — creating rules with action: audit_ssh is no longer diff --git a/providers/cloudflare/api_test.go b/providers/cloudflare/api_test.go index d130f12..185215d 100644 --- a/providers/cloudflare/api_test.go +++ b/providers/cloudflare/api_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/patch-it-dev/patch-it-plugins/core/event" + "github.com/patch-it-dev/patch-it-plugins/core/extract" "github.com/patch-it-dev/patch-it-plugins/core/kit/kittest" "github.com/patch-it-dev/patch-it-plugins/kinds/notices/feed" "github.com/patch-it-dev/patch-it-plugins/kinds/notices/noticestest" @@ -115,8 +116,8 @@ func TestCloudflareCounts(t *testing.T) { } } -func cfEntry(dates, items string) feed.Entry { - return feed.Entry{Title: "API deprecations - X", Link: "https://x.test/#x", Published: "Mon, 29 Jun 2026 00:00:00 GMT", +func cfEntry(dates, items string) extract.Entry { + return extract.Entry{Title: "API deprecations - X", Link: "https://x.test/#x", Published: "Mon, 29 Jun 2026 00:00:00 GMT", HTML: dates + "

Deprecated APIs:

\n
    \n" + items + "
\n

Replacement:

  • GET /new
"} } @@ -204,7 +205,7 @@ func TestCloudflareDates(t *testing.T) { if fs := readCloudflareAPI(noDates); len(fs) != 1 || fs[0].Dropped == "" { t.Errorf("no date at all: %+v, want dropped", fs) } - if fs := readCloudflareAPI(feed.Entry{Title: "API deprecations - Y", HTML: "

Affected APIs:

  • GET /a
"}); len(fs) != 1 || fs[0].Dropped == "" { + if fs := readCloudflareAPI(extract.Entry{Title: "API deprecations - Y", HTML: "

Affected APIs:

  • GET /a
"}); len(fs) != 1 || fs[0].Dropped == "" { t.Errorf("only affected APIs: %+v, want dropped", fs) } } diff --git a/providers/github/actions.go b/providers/github/actions.go index 9d1e979..81cbfa1 100644 --- a/providers/github/actions.go +++ b/providers/github/actions.go @@ -5,6 +5,7 @@ import ( "regexp" "github.com/patch-it-dev/patch-it-plugins/core/event" + "github.com/patch-it-dev/patch-it-plugins/core/extract" "github.com/patch-it-dev/patch-it-plugins/kinds/notices/feed" ) @@ -24,7 +25,7 @@ var runnerImage = regexp.MustCompile(`(?i)\brunner images?\b`) var labelsList = regexp.MustCompile(`(?is)

([^<]*following labels[^<]*)

\s*
    (.*?)
`) -func readGitHubActions(e feed.Entry) []feed.Finding { +func readGitHubActions(e extract.Entry) []feed.Finding { if !feed.Marked(e.Categories, "Retired", "Deprecation", "Deprecated", "Breaking change", "Breaking changes") { return nil } @@ -32,7 +33,7 @@ func readGitHubActions(e feed.Entry) []feed.Finding { if !runnerImage.MatchString(e.Title) { return drop("not a runner image retirement: no ci_runtime this reader can name") } - line, date, ct := feed.Dated(feed.Lines(e.HTML)) + line, date, ct := feed.Dated(extract.Lines(e.HTML)) if date == "" { return drop("no sentence giving the date the image is removed") } @@ -40,12 +41,12 @@ func readGitHubActions(e feed.Entry) []feed.Finding { if m == nil { return drop("lists no runner labels") } - intro := feed.Text(m[1]) + intro := extract.Text(m[1]) var out []feed.Finding for _, li := range feed.ListItem.FindAllStringSubmatch(m[2], -1) { - codes := feed.Codes(li[1]) - if len(codes) != 1 || feed.Text(li[1]) != codes[0] { - out = append(out, feed.Finding{Entry: e.Link, Dropped: fmt.Sprintf("label item %q isn't one plain label", feed.Text(li[1]))}) + codes := extract.Codes(li[1]) + if len(codes) != 1 || extract.Text(li[1]) != codes[0] { + out = append(out, feed.Finding{Entry: e.Link, Dropped: fmt.Sprintf("label item %q isn't one plain label", extract.Text(li[1]))}) continue } label := codes[0] diff --git a/providers/github/actions_test.go b/providers/github/actions_test.go index 8ecde7e..453ccdd 100644 --- a/providers/github/actions_test.go +++ b/providers/github/actions_test.go @@ -4,6 +4,7 @@ import ( "strings" "testing" + "github.com/patch-it-dev/patch-it-plugins/core/extract" "github.com/patch-it-dev/patch-it-plugins/core/kit/kittest" "github.com/patch-it-dev/patch-it-plugins/kinds/notices/feed" "github.com/patch-it-dev/patch-it-plugins/kinds/notices/noticestest" @@ -54,8 +55,8 @@ func TestActionsUnsureEntriesAreDropped(t *testing.T) { // Breaking only when the vendor says the thing stops on the date; softer // words downgrade to a deprecation, and no date drops the entry. func TestBreakingNeedsTheVendorToSayItStops(t *testing.T) { - entry := func(sentence string) feed.Entry { - return feed.Entry{Title: "Ubuntu 22.04 runner image retirement", Link: "https://x.test/e", Categories: []string{"Retired"}, + entry := func(sentence string) extract.Entry { + return extract.Entry{Title: "Ubuntu 22.04 runner image retirement", Link: "https://x.test/e", Categories: []string{"Retired"}, HTML: "

" + sentence + "

This deprecation includes the following labels:

  • ubuntu-22.04
"} } for sentence, want := range map[string]string{ diff --git a/providers/google/vertex_ai_models.go b/providers/google/vertex_ai_models.go index 067186b..6019610 100644 --- a/providers/google/vertex_ai_models.go +++ b/providers/google/vertex_ai_models.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/patch-it-dev/patch-it-plugins/core/event" + "github.com/patch-it-dev/patch-it-plugins/core/extract" "github.com/patch-it-dev/patch-it-plugins/kinds/notices/feed" ) @@ -27,13 +28,13 @@ var tableCell = regexp.MustCompile(`(?is)]*>(.*?)`) var plainModelID = regexp.MustCompile(`^[a-z0-9][a-z0-9.@_-]*$`) -func readVertexAI(e feed.Entry) []feed.Finding { +func readVertexAI(e extract.Entry) []feed.Finding { var out []feed.Finding - for _, s := range feed.SplitBy(e.HTML, 3) { + for _, s := range extract.SplitBy(e.HTML, 3) { if !feed.Marked([]string{s.Heading}, "Deprecated", "Breaking") { continue } - lines := feed.Lines(s.HTML) + lines := extract.Lines(s.HTML) drop := func(why string) { title := "" if len(lines) > 0 { @@ -61,17 +62,17 @@ func readVertexAI(e feed.Entry) []feed.Finding { if len(raw) < 2 { continue } - names := feed.Codes(raw[0][1]) - if len(names) != 1 || !plainModelID.MatchString(names[0]) || feed.Text(raw[0][1]) != names[0] { - drop(fmt.Sprintf("row %q doesn't name one model id", feed.Text(raw[0][1]))) + names := extract.Codes(raw[0][1]) + if len(names) != 1 || !plainModelID.MatchString(names[0]) || extract.Text(raw[0][1]) != names[0] { + drop(fmt.Sprintf("row %q doesn't name one model id", extract.Text(raw[0][1]))) continue } - name, migrate := names[0], feed.Text(raw[1][1]) + name, migrate := names[0], extract.Text(raw[1][1]) subject := event.Subject{Type: event.SubjectModel, Provider: "google", Name: name} hint := fmt.Sprintf("Google recommends: %s.", migrate) // Exactly one plain model, and not the model itself (the feed has a // row whose migration is its own name): anything else stays a hint. - if repl := feed.Codes(raw[1][1]); len(repl) == 1 && feed.Text(raw[1][1]) == repl[0] && repl[0] != name { + if repl := extract.Codes(raw[1][1]); len(repl) == 1 && extract.Text(raw[1][1]) == repl[0] && repl[0] != name { subject.Replacement = repl[0] hint = fmt.Sprintf("Use `%s` instead: Google's recommended migration.", repl[0]) } @@ -96,7 +97,7 @@ func readVertexAI(e feed.Entry) []feed.Finding { func cells(row string) []string { var out []string for _, c := range tableCell.FindAllStringSubmatch(row, -1) { - out = append(out, feed.Text(c[1])) + out = append(out, extract.Text(c[1])) } return out } From e31e0b6ca035c79d6b89f0c40341fbf9e332f4bb Mon Sep 17 00:00:00 2001 From: adssib <75389300+adssib@users.noreply.github.com> Date: Sat, 21 Nov 2026 13:43:05 -0500 Subject: [PATCH 2/4] fail on a package-level alias or forwarder Co-Authored-By: Claude Opus 5.5 Signed-off-by: adssib <75389300+adssib@users.noreply.github.com> --- AGENTS.md | 2 +- providers/all/aliases_test.go | 196 ++++++++++++++++++++++++++++++++++ 2 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 providers/all/aliases_test.go diff --git a/AGENTS.md b/AGENTS.md index dd752a0..3910f0a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -23,7 +23,7 @@ Refer to the service that runs these plugins as "patch-it's hosted ingestion ser ## Rules for plugin code -- **How to read is a kind; what to read is a provider.** `kinds//` reads one kind of source, written once, and imports no provider. `providers//` holds one provider and nothing about another: `provider.go` (its registration, built from the kinds' exported types), `README.md` (its page), any code only it needs (`.go`: an OpenAPI adapter, a feed's reader), `testdata/` and its tests. A provider imports only `core/` and `kinds/`. No folder per source, no forwarders: when code moves, the old path goes in the same change. `go test ./providers/all` checks all of this. +- **How to read is a kind; what to read is a provider.** `kinds//` reads one kind of source, written once, and imports no provider. `providers//` holds one provider and nothing about another: `provider.go` (its registration, built from the kinds' exported types), `README.md` (its page), any code only it needs (`.go`: an OpenAPI adapter, a feed's reader), `testdata/` and its tests. A provider imports only `core/` and `kinds/`. No folder per source, no forwarders: when code moves, the old path goes in the same change, and no package keeps a type alias (`type X = …`), a re-export (`var X = otherpkg.Y`) or a func that only calls another package's (a genuine one says why with `alias-ok: ` in its doc comment). `go test ./providers/all` checks all of this. - **Start a new source with `make new-plugin ARGS='--provider --name --source --kind '`** (`go run ./cmd/new-plugin`; [which kind](docs/which-kind.md)): it writes into `providers//`, a new folder or one more source in the existing one. Then fill in every `TODO(new-plugin)`; `make todos` (part of `make check` and CI_go) fails while one is left. - **Fetch only through the environment** (`env.Get` or `core/kit/`). No `net/http` outside the fetch layer, no filesystem outside `testdata/`, no database. diff --git a/providers/all/aliases_test.go b/providers/all/aliases_test.go new file mode 100644 index 0000000..6ac47c7 --- /dev/null +++ b/providers/all/aliases_test.go @@ -0,0 +1,196 @@ +package all + +import ( + "go/ast" + "go/parser" + "go/token" + "io/fs" + "path/filepath" + "strings" + "testing" +) + +// aliasOK marks a declaration this test lets through. Put it in the +// declaration's doc comment with the reason, e.g. +// +// // alias-ok: +const aliasOK = "alias-ok:" + +// No forwarders: when code moves, the old path goes in the same change and +// every caller imports the new one. So no file in this module, tests +// included, declares at package level +// +// - a type alias (type X = Y), +// - a var or const that only re-exports another package's symbol +// (var X = otherpkg.Y), +// - a func whose body only calls another package's func with its own +// parameters (func X(a, b T) R { return otherpkg.Y(a, b) }), +// +// unless its doc comment says why with "alias-ok: ". +func TestNoAliasesOrForwarders(t *testing.T) { + checked := 0 + err := filepath.WalkDir("../..", func(p string, d fs.DirEntry, err error) error { + if err != nil { + return err + } + if d.IsDir() && p != "../.." && (d.Name() == "testdata" || strings.HasPrefix(d.Name(), ".")) { + return filepath.SkipDir + } + if d.IsDir() || !strings.HasSuffix(p, ".go") { + return nil + } + fset := token.NewFileSet() + f, err := parser.ParseFile(fset, p, nil, parser.ParseComments) + if err != nil { + return err + } + checked++ + for _, what := range forwarders(f) { + t.Errorf("%s: %s. Delete it and point its callers at the real one, or say why it must stay with %q in its doc comment.", + fset.Position(what.pos), what.desc, aliasOK) + } + return nil + }) + if err != nil { + t.Fatal(err) + } + if checked < 100 { + t.Fatalf("checked only %d files; is the walk rooted at the module?", checked) + } +} + +type forwarder struct { + pos token.Pos + name string + desc string +} + +// forwarders lists the package-level aliases and re-exports in f. +func forwarders(f *ast.File) []forwarder { + imported := map[string]bool{} + for _, imp := range f.Imports { + path := strings.Trim(imp.Path.Value, `"`) + name := path[strings.LastIndex(path, "/")+1:] + if imp.Name != nil { + name = imp.Name.Name + } + imported[name] = true + } + // pkgSym says whether e is a bare otherpkg.Name. + pkgSym := func(e ast.Expr) bool { + sel, ok := e.(*ast.SelectorExpr) + if !ok { + return false + } + id, ok := sel.X.(*ast.Ident) + return ok && imported[id.Name] + } + allowed := func(docs ...*ast.CommentGroup) bool { + for _, d := range docs { + if d != nil && strings.Contains(d.Text(), aliasOK) { + return true + } + } + return false + } + + var out []forwarder + for _, decl := range f.Decls { + switch decl := decl.(type) { + case *ast.GenDecl: + for _, spec := range decl.Specs { + switch spec := spec.(type) { + case *ast.TypeSpec: + if spec.Assign.IsValid() && !allowed(decl.Doc, spec.Doc) { + out = append(out, forwarder{spec.Pos(), spec.Name.Name, "type alias " + spec.Name.Name}) + } + case *ast.ValueSpec: + for i, v := range spec.Values { + if pkgSym(v) && i < len(spec.Names) && !allowed(decl.Doc, spec.Doc) { + out = append(out, forwarder{spec.Pos(), spec.Names[i].Name, decl.Tok.String() + " " + spec.Names[i].Name + " re-exports another package's symbol"}) + } + } + } + } + case *ast.FuncDecl: + if decl.Recv == nil && decl.Body != nil && len(decl.Body.List) == 1 && !allowed(decl.Doc) { + if call := onlyCall(decl.Body.List[0]); call != nil && pkgSym(call.Fun) && passesParams(decl.Type.Params, call.Args) { + out = append(out, forwarder{decl.Pos(), decl.Name.Name, "func " + decl.Name.Name + " only forwards to another package's func"}) + } + } + } + } + return out +} + +// onlyCall is the call in `return f(...)` or `f(...)`, else nil. +func onlyCall(s ast.Stmt) *ast.CallExpr { + switch s := s.(type) { + case *ast.ReturnStmt: + if len(s.Results) == 1 { + c, _ := s.Results[0].(*ast.CallExpr) + return c + } + case *ast.ExprStmt: + c, _ := s.X.(*ast.CallExpr) + return c + } + return nil +} + +// passesParams says whether args are exactly the function's parameters, in order. +func passesParams(params *ast.FieldList, args []ast.Expr) bool { + var names []string + for _, fld := range params.List { + for _, n := range fld.Names { + names = append(names, n.Name) + } + } + if len(names) != len(args) { + return false + } + for i, a := range args { + id, ok := a.(*ast.Ident) + if !ok || id.Name != names[i] { + return false + } + } + return true +} + +// The check itself: each shape it refuses is caught, and the marker lets one through. +func TestForwardersCatchesEachShape(t *testing.T) { + src := `package p + +import ( + "strings" + x "example.com/extract" +) + +type A = x.Entry +type B = int + +var C = x.ParseFeed +const D = strings.Title + +func E(s string) string { return strings.ToUpper(s) } + +// alias-ok: kept on purpose, for the test +type F = x.Entry + +var G = x.ParseFeed("") +func H(s string) string { return strings.ToUpper(s + "!") } +func I(s string) string { return local(s) } +` + f, err := parser.ParseFile(token.NewFileSet(), "p.go", src, parser.ParseComments) + if err != nil { + t.Fatal(err) + } + var got []string + for _, w := range forwarders(f) { + got = append(got, w.name) + } + if want := "A B C D E"; strings.Join(got, " ") != want { + t.Errorf("caught %v, want %s", got, want) + } +} From cef0427331b2b738f8163bf4b0a07e6cbe356d49 Mon Sep 17 00:00:00 2001 From: adssib <75389300+adssib@users.noreply.github.com> Date: Sat, 21 Nov 2026 13:43:05 -0500 Subject: [PATCH 3/4] add the gitlab rest-api golden Co-Authored-By: Claude Opus 5.5 Signed-off-by: adssib <75389300+adssib@users.noreply.github.com> --- providers/gitlab/rest_api_test.go | 22 ++++- .../testdata/golden/gitlab-rest-api.json | 92 +++++++++++++++++++ 2 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 providers/gitlab/testdata/golden/gitlab-rest-api.json diff --git a/providers/gitlab/rest_api_test.go b/providers/gitlab/rest_api_test.go index e59c6af..30e8aa0 100644 --- a/providers/gitlab/rest_api_test.go +++ b/providers/gitlab/rest_api_test.go @@ -2,11 +2,13 @@ package gitlab import ( "context" + "fmt" "net/http" "net/http/httptest" "strings" "testing" + "github.com/patch-it-dev/patch-it-plugins/core/event" "github.com/patch-it-dev/patch-it-plugins/core/kit/kittest" "github.com/patch-it-dev/patch-it-plugins/kinds/openapi" "github.com/patch-it-dev/patch-it-plugins/kinds/openapi/openapitest" @@ -22,14 +24,14 @@ func gitlabPlugin(t *testing.T) (openapi.Plugin, string) { return openapi.Plugin{Adapter: GitLab{SpecURLTemplate: tmpl}, Keep: openapi.RequestSide}, tmpl } -// The golden test and the pair fixture in one: testdata/gitlab-v18.11.0-ee.yaml -// and gitlab-v19.0.0-ee.yaml are trimmed, unedited excerpts of GitLab's -// OpenAPI spec at those two tags (checked 2026-11-15). GitLab 19.0 removed app +// The golden test (testdata/golden/gitlab-rest-api.json) and the pair +// fixture in one: testdata/gitlab-v18.11.0-ee.yaml and gitlab-v19.0.0-ee.yaml +// are trimmed, unedited excerpts of GitLab's OpenAPI spec at those two tags (checked 2026-11-15). GitLab 19.0 removed app // passwords from the Bitbucket Cloud import API ("Using app passwords with // Bitbucket Cloud import GitLab API", announced 18.9, on // docs.gitlab.com/update/deprecations): bitbucket_username and // bitbucket_app_password are gone from POST /api/v4/import/bitbucket, and -// bitbucket_email and bitbucket_api_token became required. This is the pair +// bitbucket_email and bitbucket_api_token became required. This is the change // the pair v18.11.0-ee → v19.0.0-ee recreates. // // The excerpts also keep APIEntitiesBadge, whose id went from the generator's @@ -108,6 +110,18 @@ func TestGitLabPairRecreatesTheBitbucketAppPasswordRemoval(t *testing.T) { } } + // The golden file names the spec where GitLab publishes it, not the local + // server that stood in for it. + real := map[string]string{ + oldURL: fmt.Sprintf(gitlabSpecURLTemplate, "v18.11.0-ee"), + newURL: fmt.Sprintf(gitlabSpecURLTemplate, "v19.0.0-ee"), + } + golden := append([]event.Event(nil), events...) + for i := range golden { + golden[i].SourceURL = real[golden[i].SourceURL] + } + kittest.Golden(t, "testdata/golden/gitlab-rest-api.json", golden) + // Reading the same pair again must not duplicate the events. if _, err := kittest.Pair(ctx, openapitest.Env(s), s, p, "v18.11.0-ee", "v19.0.0-ee"); err != nil { t.Fatalf("second read of the pair: %v", err) diff --git a/providers/gitlab/testdata/golden/gitlab-rest-api.json b/providers/gitlab/testdata/golden/gitlab-rest-api.json new file mode 100644 index 0000000..8d65c9a --- /dev/null +++ b/providers/gitlab/testdata/golden/gitlab-rest-api.json @@ -0,0 +1,92 @@ +[ + { + "id": 1, + "fingerprint": "sha256:2410950b4abb96df49dcfc203160590970afd61d54b0cffd7c0f69aabd152eaa", + "api": "gitlab/rest-api", + "version": "19.0.0", + "previous_version": "18.11.0", + "change_type": "breaking", + "breaking": true, + "subject": { + "type": "api_operation", + "kind": "request_parameter", + "side": "request", + "operation": "POST /api/v4/import/bitbucket", + "property": "bitbucket_api_token" + }, + "description": "Property bitbucket_api_token is now required in POST /api/v4/import/bitbucket.", + "migration_hint": "Always send bitbucket_api_token.", + "source_url": "https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab/repository/files/doc%2Fapi%2Fopenapi%2Fopenapi_v3.yaml/raw?ref=v19.0.0-ee", + "source_pointer": "/components/schemas/RequestBody_f0e6af1da635/properties/bitbucket_api_token", + "source_excerpt": "{\"description\":\"BitBucket API token\",\"nullable\":true,\"type\":\"string\"}", + "confidence": 1, + "detected_at": "2026-11-14T12:00:00Z" + }, + { + "id": 2, + "fingerprint": "sha256:d16335c186904d97976bf0262d52068c03c6a288e845f1b2eedb596931d4b28f", + "api": "gitlab/rest-api", + "version": "19.0.0", + "previous_version": "18.11.0", + "change_type": "breaking", + "breaking": true, + "subject": { + "type": "api_operation", + "kind": "request_parameter", + "side": "request", + "operation": "POST /api/v4/import/bitbucket", + "property": "bitbucket_app_password" + }, + "description": "Property bitbucket_app_password removed from POST /api/v4/import/bitbucket.", + "source_url": "https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab/repository/files/doc%2Fapi%2Fopenapi%2Fopenapi_v3.yaml/raw?ref=v18.11.0-ee", + "source_pointer": "/components/schemas/RequestBody_a98aaa3a441e/properties/bitbucket_app_password", + "source_excerpt": "{\"description\":\"BitBucket app password\",\"nullable\":true,\"type\":\"string\"}", + "confidence": 1, + "detected_at": "2026-11-14T12:00:00Z" + }, + { + "id": 3, + "fingerprint": "sha256:1fdbf03d0d78186ce1a1a7ab19449afc6fb7e8158160d2777ce52a619f0d93e6", + "api": "gitlab/rest-api", + "version": "19.0.0", + "previous_version": "18.11.0", + "change_type": "breaking", + "breaking": true, + "subject": { + "type": "api_operation", + "kind": "request_parameter", + "side": "request", + "operation": "POST /api/v4/import/bitbucket", + "property": "bitbucket_email" + }, + "description": "Property bitbucket_email is now required in POST /api/v4/import/bitbucket.", + "migration_hint": "Always send bitbucket_email.", + "source_url": "https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab/repository/files/doc%2Fapi%2Fopenapi%2Fopenapi_v3.yaml/raw?ref=v19.0.0-ee", + "source_pointer": "/components/schemas/RequestBody_f0e6af1da635/properties/bitbucket_email", + "source_excerpt": "{\"description\":\"BitBucket email\",\"nullable\":true,\"type\":\"string\"}", + "confidence": 1, + "detected_at": "2026-11-14T12:00:00Z" + }, + { + "id": 4, + "fingerprint": "sha256:e7b0d1779f8ca483da00e7ca1dfb5d4cb5a6d80fea16e1ad99da5bd39b5296e0", + "api": "gitlab/rest-api", + "version": "19.0.0", + "previous_version": "18.11.0", + "change_type": "breaking", + "breaking": true, + "subject": { + "type": "api_operation", + "kind": "request_parameter", + "side": "request", + "operation": "POST /api/v4/import/bitbucket", + "property": "bitbucket_username" + }, + "description": "Property bitbucket_username removed from POST /api/v4/import/bitbucket.", + "source_url": "https://gitlab.com/api/v4/projects/gitlab-org%2Fgitlab/repository/files/doc%2Fapi%2Fopenapi%2Fopenapi_v3.yaml/raw?ref=v18.11.0-ee", + "source_pointer": "/components/schemas/RequestBody_a98aaa3a441e/properties/bitbucket_username", + "source_excerpt": "{\"description\":\"BitBucket username (for app passwords)\",\"nullable\":true,\"type\":\"string\"}", + "confidence": 1, + "detected_at": "2026-11-14T12:00:00Z" + } +] From 0c35a07e376168e9924a53121e1ab366869a4140 Mon Sep 17 00:00:00 2001 From: adssib <75389300+adssib@users.noreply.github.com> Date: Sat, 21 Nov 2026 13:53:22 -0500 Subject: [PATCH 4/4] read versioned import names in the alias check; review nits Co-Authored-By: Claude Opus 5.5 Signed-off-by: adssib <75389300+adssib@users.noreply.github.com> --- providers/all/aliases_test.go | 38 ++++++++++++++++++++++++++++--- providers/gitlab/rest_api_test.go | 9 ++++---- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/providers/all/aliases_test.go b/providers/all/aliases_test.go index 6ac47c7..0fcc4e7 100644 --- a/providers/all/aliases_test.go +++ b/providers/all/aliases_test.go @@ -69,8 +69,7 @@ type forwarder struct { func forwarders(f *ast.File) []forwarder { imported := map[string]bool{} for _, imp := range f.Imports { - path := strings.Trim(imp.Path.Value, `"`) - name := path[strings.LastIndex(path, "/")+1:] + name := importName(strings.Trim(imp.Path.Value, `"`)) if imp.Name != nil { name = imp.Name.Name } @@ -123,6 +122,34 @@ func forwarders(f *ast.File) []forwarder { return out } +// importName is the name an unnamed import is used by: the last element, +// without a major-version suffix (gopkg.in/yaml.v3 is yaml, example.com/x/v2 +// is x). +func importName(path string) string { + elems := strings.Split(path, "/") + name := elems[len(elems)-1] + if len(elems) > 1 && isMajor(name) { + name = elems[len(elems)-2] + } + if i := strings.Index(name, ".v"); i > 0 && isMajor(name[i+1:]) { + name = name[:i] + } + return name +} + +// isMajor says whether s is a major version element: v2, v3, ... +func isMajor(s string) bool { + if len(s) < 2 || s[0] != 'v' { + return false + } + for _, r := range s[1:] { + if r < '0' || r > '9' { + return false + } + } + return true +} + // onlyCall is the call in `return f(...)` or `f(...)`, else nil. func onlyCall(s ast.Stmt) *ast.CallExpr { switch s := s.(type) { @@ -165,6 +192,8 @@ func TestForwardersCatchesEachShape(t *testing.T) { import ( "strings" x "example.com/extract" + "gopkg.in/yaml.v3" + "example.com/sdk/v2" ) type A = x.Entry @@ -175,6 +204,9 @@ const D = strings.Title func E(s string) string { return strings.ToUpper(s) } +var J = yaml.Marshal +var K = sdk.Client + // alias-ok: kept on purpose, for the test type F = x.Entry @@ -190,7 +222,7 @@ func I(s string) string { return local(s) } for _, w := range forwarders(f) { got = append(got, w.name) } - if want := "A B C D E"; strings.Join(got, " ") != want { + if want := "A B C D E J K"; strings.Join(got, " ") != want { t.Errorf("caught %v, want %s", got, want) } } diff --git a/providers/gitlab/rest_api_test.go b/providers/gitlab/rest_api_test.go index 30e8aa0..62b1ca9 100644 --- a/providers/gitlab/rest_api_test.go +++ b/providers/gitlab/rest_api_test.go @@ -26,8 +26,9 @@ func gitlabPlugin(t *testing.T) (openapi.Plugin, string) { // The golden test (testdata/golden/gitlab-rest-api.json) and the pair // fixture in one: testdata/gitlab-v18.11.0-ee.yaml and gitlab-v19.0.0-ee.yaml -// are trimmed, unedited excerpts of GitLab's OpenAPI spec at those two tags (checked 2026-11-15). GitLab 19.0 removed app -// passwords from the Bitbucket Cloud import API ("Using app passwords with +// are trimmed, unedited excerpts of GitLab's OpenAPI spec at those two tags +// (checked 2026-11-15). GitLab 19.0 removed app passwords from the Bitbucket +// Cloud import API ("Using app passwords with // Bitbucket Cloud import GitLab API", announced 18.9, on // docs.gitlab.com/update/deprecations): bitbucket_username and // bitbucket_app_password are gone from POST /api/v4/import/bitbucket, and @@ -112,13 +113,13 @@ func TestGitLabPairRecreatesTheBitbucketAppPasswordRemoval(t *testing.T) { // The golden file names the spec where GitLab publishes it, not the local // server that stood in for it. - real := map[string]string{ + published := map[string]string{ oldURL: fmt.Sprintf(gitlabSpecURLTemplate, "v18.11.0-ee"), newURL: fmt.Sprintf(gitlabSpecURLTemplate, "v19.0.0-ee"), } golden := append([]event.Event(nil), events...) for i := range golden { - golden[i].SourceURL = real[golden[i].SourceURL] + golden[i].SourceURL = published[golden[i].SourceURL] } kittest.Golden(t, "testdata/golden/gitlab-rest-api.json", golden)