From 86f3a7ffdfaefae098418d5ae193232fb52641f8 Mon Sep 17 00:00:00 2001 From: adssib <75389300+adssib@users.noreply.github.com> Date: Sat, 21 Nov 2026 15:00:13 -0500 Subject: [PATCH 1/2] a shape guard for every kind, anchors for living pages A read that finds far fewer items than the read before, or none, or a living page without one of its source's anchors, fails with plugin.ErrShapeChanged: never stored, never read as removals. Shape.NothingToRead turns a run of releases with nothing to read into the same signal for whoever runs a versioned source. Anchors declared, checked on the live pages, for OpenAI, Anthropic, Gemini, Vertex AI, GitHub Actions, Cloudflare and Salesforce. Co-Authored-By: Claude Opus 5.5 Signed-off-by: adssib <75389300+adssib@users.noreply.github.com> --- AGENTS.md | 2 +- core/diff/diff.go | 14 ++ core/extract/feed.go | 16 +++ core/kit/notices.go | 3 + core/plugin/plugin_test.go | 2 + core/plugin/provider.go | 23 +++- core/plugin/provider_test.go | 30 +++++ core/plugin/shape.go | 162 +++++++++++++++++++++++ core/plugin/shape_test.go | 72 ++++++++++ docs/how-it-works.md | 2 +- docs/writing-a-plugin.md | 25 +++- kinds/apisurface/apisurface.go | 23 +++- kinds/apisurface/shape_test.go | 41 ++++++ kinds/catalog/commands.go | 22 ++- kinds/catalog/shape_test.go | 62 +++++++++ kinds/catalog/upcoming.go | 21 ++- kinds/changelog/changelog.go | 25 +++- kinds/changelog/json.go | 14 ++ kinds/changelog/parse.go | 24 ++++ kinds/changelog/shape_test.go | 98 ++++++++++++++ kinds/migrationguide/migrationguide.go | 14 +- kinds/migrationguide/shape_test.go | 56 ++++++++ kinds/notices/eol/eol.go | 11 ++ kinds/notices/feed/feed.go | 50 +++++-- kinds/notices/notices.go | 72 +++++++--- kinds/notices/noticestest/noticestest.go | 14 +- kinds/notices/retire/notices.go | 15 ++- kinds/notices/shape_test.go | 111 ++++++++++++++++ kinds/openapi/openapi.go | 25 +++- kinds/openapi/shape_test.go | 52 ++++++++ providers/anthropic/provider.go | 5 +- providers/cloudflare/provider.go | 5 +- providers/github/actions_test.go | 23 ++++ providers/github/provider.go | 5 +- providers/google/provider.go | 15 ++- providers/openai/models_read_test.go | 52 ++++++-- providers/openai/provider.go | 5 +- providers/salesforce/provider.go | 7 +- providers/salesforce/rest_api_test.go | 4 +- 39 files changed, 1151 insertions(+), 71 deletions(-) create mode 100644 core/plugin/shape.go create mode 100644 core/plugin/shape_test.go create mode 100644 kinds/apisurface/shape_test.go create mode 100644 kinds/catalog/shape_test.go create mode 100644 kinds/changelog/shape_test.go create mode 100644 kinds/migrationguide/shape_test.go create mode 100644 kinds/notices/shape_test.go create mode 100644 kinds/openapi/shape_test.go diff --git a/AGENTS.md b/AGENTS.md index 3910f0a..84ea36f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -53,7 +53,7 @@ Go module `github.com/patch-it-dev/patch-it-plugins`; the only dependency is `go ``` core/plugin/ the Plugin interface (Extract) in its two shapes, Versioned (ListVersions, ReadAt) and Living (Read); - ErrNothingToRead; the registry of providers and sources, Env, Result + ErrNothingToRead; the shape guard (Shape, anchors, ErrShapeChanged); the registry, Env, Result core/fetch/ the HTTP fetch with retries and the ETag / Last-Modified cache core/github/ the newest release / commit on GitHub, and a commit's SHA and date (one place) core/versions/ every version of a source: GitHub releases, tags and commits, PyPI, npm diff --git a/core/diff/diff.go b/core/diff/diff.go index e675458..6fd8665 100644 --- a/core/diff/diff.go +++ b/core/diff/diff.go @@ -82,6 +82,20 @@ func Parse(data []byte) (*Spec, error) { return &Spec{Version: version, doc: doc}, nil } +// Operations is how many operations the spec has: every method under every +// path. What the shape guard counts. +func (s *Spec) Operations() int { + n := 0 + for _, item := range obj(s.doc["paths"]) { + for _, m := range methods { + if _, ok := obj(item)[m]; ok { + n++ + } + } + } + return n +} + // methods are the operation keys a path item can hold. Anything else under a // path (parameters, servers, summary) is not an operation. var methods = []string{"get", "put", "post", "delete", "patch", "head", "options", "trace"} diff --git a/core/extract/feed.go b/core/extract/feed.go index 22b0d02..924af68 100644 --- a/core/extract/feed.go +++ b/core/extract/feed.go @@ -121,6 +121,22 @@ func ParseFeed(b []byte) ([]Entry, error) { return out, nil } +// FeedTitle is an RSS channel's or an Atom feed's own title, as text: "" +// when b isn't one or has none. +func FeedTitle(b []byte) string { + var f struct { + RSS string `xml:"channel>title"` + Atom string `xml:"title"` + } + if err := xml.Unmarshal(b, &f); err != nil { + return "" + } + if f.RSS != "" { + return Text(f.RSS) + } + return Text(f.Atom) +} + func trimAll(ss []string) []string { var out []string for _, s := range ss { diff --git a/core/kit/notices.go b/core/kit/notices.go index b7f5aee..6790b67 100644 --- a/core/kit/notices.go +++ b/core/kit/notices.go @@ -8,4 +8,7 @@ type Notices interface { // Count is how many notices were read: what the shape guard compares // with the last read. Count() int + // Has says whether entry is among what was read, as the reader names + // an entry: what a source's anchors (plugin.Anchor) are checked with. + Has(entry string) bool } diff --git a/core/plugin/plugin_test.go b/core/plugin/plugin_test.go index e389e94..f6ff94e 100644 --- a/core/plugin/plugin_test.go +++ b/core/plugin/plugin_test.go @@ -18,6 +18,8 @@ type testPlugin struct { func (p testPlugin) Name() string { return p.name } +func (p testPlugin) WithShape(Shape) Plugin { return p } + func (p testPlugin) Read(_ context.Context, env Env, _ Snapshot) (Snapshot, error) { if p.err != nil { return Snapshot{}, p.err diff --git a/core/plugin/provider.go b/core/plugin/provider.go index adc7dbe..7e4cf83 100644 --- a/core/plugin/provider.go +++ b/core/plugin/provider.go @@ -117,8 +117,13 @@ type Source struct { // sources without a table kept elsewhere. Only names checked by hand; // none is fine when no package maps to the source. Packages []string + // Shape is what the shape guard checks this source's reads against: the + // kind's defaults when zero, anchors for a living page (Shape). Set with + // a comment saying why, and for an anchor where it is on the page. + Shape Shape // Plugin runs it. Its Name is the source's id ("algolia/search-api"), - // which every event's `api` carries. + // which every event's `api` carries. RegisterProvider replaces it with + // the same plugin given Shape (Guarded.WithShape). Plugin Plugin } @@ -145,8 +150,10 @@ func RegisterProvider(p Provider) { panic("plugin: " + err.Error()) } for i := range p.Sources { - p.Sources[i].Kind = KindOf(p.Sources[i].Plugin) - p.Sources[i].Page = PageOf(p.ID) + s := &p.Sources[i] + s.Kind = KindOf(s.Plugin) + s.Page = PageOf(p.ID) + s.Plugin = s.Plugin.(Guarded).WithShape(s.Shape) } mu.Lock() defer mu.Unlock() @@ -197,6 +204,8 @@ func (p Provider) check() error { return fmt.Errorf("source %q has no Plugin", id) case shape(s.Plugin) == "": return fmt.Errorf("source %q: its plugin must be exactly one of plugin.Versioned (ListVersions, ReadAt) or plugin.Living (Read)", id) + case !isGuarded(s.Plugin): + return fmt.Errorf("source %q: its plugin (kinds/%s) doesn't run the shape guard: every kind implements plugin.Guarded", id, KindOf(s.Plugin)) case s.Plugin.Name() != id: return fmt.Errorf("source %q: its plugin's Name is %q; a plugin is named by its source's id", id, s.Plugin.Name()) case !slices.Contains(Layers(), s.Layer): @@ -210,6 +219,9 @@ func (p Provider) check() error { case s.Kind != "" && s.Kind != KindOf(s.Plugin): return fmt.Errorf("source %q: Kind %q, but its plugin is in kinds/%s", id, s.Kind, KindOf(s.Plugin)) } + if err := s.Shape.check(shape(s.Plugin)); err != nil { + return fmt.Errorf("source %q: %w", id, err) + } for _, u := range s.URLs { if !absolute(u) { return fmt.Errorf("source %q: URL %q isn't absolute", id, u) @@ -240,6 +252,11 @@ func shape(p Plugin) string { return "" } +func isGuarded(p Plugin) bool { + _, ok := p.(Guarded) + return ok +} + func absolute(u string) bool { parsed, err := url.Parse(u) return err == nil && (parsed.Scheme == "https" || parsed.Scheme == "http") && parsed.Host != "" diff --git a/core/plugin/provider_test.go b/core/plugin/provider_test.go index 856e7a1..f76bb56 100644 --- a/core/plugin/provider_test.go +++ b/core/plugin/provider_test.go @@ -11,6 +11,16 @@ type fake struct{ name string } func (f fake) Name() string { return f.name } func (fake) Read(context.Context, Env, Snapshot) (Snapshot, error) { return Snapshot{}, nil } func (fake) Extract(context.Context, Env, Snapshot, Snapshot) (Result, error) { return Result{}, nil } +func (f fake) WithShape(Shape) Plugin { return f } + +// unguarded is a living plugin that doesn't run the shape guard: refused. +type unguarded struct{ name string } + +func (u unguarded) Name() string { return u.name } +func (unguarded) Read(context.Context, Env, Snapshot) (Snapshot, error) { return Snapshot{}, nil } +func (unguarded) Extract(context.Context, Env, Snapshot, Snapshot) (Result, error) { + return Result{}, nil +} // both is a plugin that is Versioned and Living: refused. type both struct{ fake } @@ -97,6 +107,26 @@ func TestRegisterProviderRefusesIncompleteMetadata(t *testing.T) { s.Plugin = neither{"x9/api"} return s }()}}, + "no shape guard": {ID: "x11", Name: "X", Category: CategoryAI, Homepage: "https://x.example", Sources: []Source{func() Source { + s := src("api", "x11") + s.Plugin = unguarded{"x11/api"} + return s + }()}}, + "undated anchor": {ID: "x12", Name: "X", Category: CategoryAI, Homepage: "https://x.example", Sources: []Source{func() Source { + s := src("api", "x12") + s.Shape.Anchors = []Anchor{{Entry: "gpt-4"}} + return s + }()}}, + "three anchors": {ID: "x13", Name: "X", Category: CategoryAI, Homepage: "https://x.example", Sources: []Source{func() Source { + s := src("api", "x13") + s.Shape.Anchors = []Anchor{{"a", "2026-11-21"}, {"b", "2026-11-21"}, {"c", "2026-11-21"}} + return s + }()}}, + "ratio above 1": {ID: "x14", Name: "X", Category: CategoryAI, Homepage: "https://x.example", Sources: []Source{func() Source { + s := src("api", "x14") + s.Shape.MinRatio = 1.5 + return s + }()}}, "wrong page": {ID: "x10", Name: "X", Category: CategoryAI, Homepage: "https://x.example", Sources: []Source{func() Source { s := src("api", "x10") s.Page = "providers/x10.md" // not providers/x10/README.md diff --git a/core/plugin/shape.go b/core/plugin/shape.go new file mode 100644 index 0000000..82ad99f --- /dev/null +++ b/core/plugin/shape.go @@ -0,0 +1,162 @@ +package plugin + +import ( + "errors" + "fmt" + "regexp" + "strings" +) + +// ErrShapeChanged is what a plugin returns, wrapped, when a read doesn't look +// like the source it reads any more: a page that lost most of what the read +// before found, a page without an entry its source declares it always has +// (an anchor), or a versioned source whose newest releases all have nothing +// to read after ones that did. The source most likely changed its layout, or +// something else is served in its place, so the read is refused: never +// stored, never read as removals. errors.Is finds it through any wrapping, +// and whoever runs the plugin reports it (patch-it's hosted ingestion +// service opens an issue in this repo). +var ErrShapeChanged = errors.New("the source's shape changed") + +// Shape is what a source declares about its own reads, for the shape guard +// every kind runs (Guarded). The zero value is the kind's defaults, which fit +// most sources: a source sets a field only with a reason, in a comment next +// to it in its provider.go. +type Shape struct { + // MinRatio: a read that finds fewer than MinRatio times what the read + // before found fails with ErrShapeChanged. 0 is the kind's default (its + // DefaultMinRatio). Compared only when the read before found at least + // MinItemsCompared; a read that finds nothing after one that found + // anything always fails. + MinRatio float64 + // Anchors are one or two entries a living source's page always lists, + // so a read without one fails with ErrShapeChanged. Each is declared by + // hand after checking the live page, with the date checked: never taken + // from a saved copy. Living sources only. + Anchors []Anchor + // NothingToReadAfter: a versioned source whose newest this many releases + // in a row have nothing to read (ErrNothingToRead), after one that had + // something, is a shape signal (NothingToRead). 0 is + // DefaultNothingToReadAfter. + NothingToReadAfter int +} + +// Anchor is one entry a living page always lists, as its kind's reader names +// an entry (a model id on a deprecations page, an API version on an +// end-of-life table, the feed's own title or an entry's title on a feed). +type Anchor struct { + Entry string + // Checked is the day the entry was seen on the live page: YYYY-MM-DD. + Checked string +} + +const ( + // MinItemsCompared is the smallest read before that MinRatio is + // compared with: below it, a few legitimate removals are a large share. + MinItemsCompared = 10 + // DefaultNothingToReadAfter is Shape.NothingToReadAfter's default. + DefaultNothingToReadAfter = 3 + // MaxAnchors is how many anchors a source may declare: one or two + // entries that won't leave the page, not a copy of it. + MaxAnchors = 2 +) + +// Guarded is a plugin that runs the shape guard with its source's Shape. +// Every kind is one: RegisterProvider refuses a plugin that isn't, and hands +// each registered plugin its source's Shape through WithShape. A plugin +// built by hand and never given a Shape (a golden test over trimmed copies, +// far smaller than the real releases) runs no guard: the guard's methods +// are nil-safe, and a kind keeps a *Shape that is nil until WithShape. +type Guarded interface { + Plugin + // WithShape is the plugin with s as its source's Shape. + WithShape(s Shape) Plugin +} + +// CheckCount is the shape guard on how much a read found: now items, against +// before found by the read before (before < 0: there was none). kindDefault +// is the kind's ratio, used when the source sets none. what names the items +// for the error ("operations", "retirements"). +func (s *Shape) CheckCount(what string, kindDefault float64, before, now int) error { + if s == nil || before <= 0 { + return nil + } + if now == 0 { + return fmt.Errorf("%w: the read found no %s, the read before found %d", ErrShapeChanged, what, before) + } + ratio := s.MinRatio + if ratio == 0 { + ratio = kindDefault + } + if before >= MinItemsCompared && float64(now) < ratio*float64(before) { + return fmt.Errorf("%w: the read found %d %s, the read before found %d (less than %.0f%%)", ErrShapeChanged, now, what, before, ratio*100) + } + return nil +} + +// CheckAnchors is the shape guard on what a read found: every anchor the +// source declares must be among it (has). +func (s *Shape) CheckAnchors(has func(entry string) bool) error { + if s == nil { + return nil + } + var missing []string + for _, a := range s.Anchors { + if !has(a.Entry) { + missing = append(missing, fmt.Sprintf("%q (seen on %s)", a.Entry, a.Checked)) + } + } + if len(missing) > 0 { + return fmt.Errorf("%w: the page no longer lists %s", ErrShapeChanged, strings.Join(missing, ", ")) + } + return nil +} + +// NothingToRead is the shape guard on a versioned source's releases, for +// whoever runs it: read says, for each release extracted, oldest first, +// whether it had something to read (false: ErrNothingToRead). When the newest +// NothingToReadAfter (or more) in a row had nothing, after one that had +// something, the source probably moved its changelog or guide or changed its +// layout: the error wraps ErrShapeChanged, not ErrNothingToRead. A source +// that has never had anything to read isn't flagged: nothing says it ever +// could be. +func (s Shape) NothingToRead(read []bool) error { + n := s.NothingToReadAfter + if n == 0 { + n = DefaultNothingToReadAfter + } + run := 0 + for i := len(read) - 1; i >= 0; i-- { + if read[i] { + if run >= n { + return fmt.Errorf("%w: the newest %d releases in a row have nothing to read, after one that had", ErrShapeChanged, run) + } + return nil + } + run++ + } + return nil +} + +var day = regexp.MustCompile(`^\d{4}-\d{2}-\d{2}$`) + +// check is what a Shape must be, for a source of the given shape ("living" +// or "versioned"). +func (s Shape) check(shape string) error { + switch { + case s.MinRatio < 0 || s.MinRatio > 1: + return fmt.Errorf("Shape.MinRatio %v isn't between 0 and 1", s.MinRatio) + case s.NothingToReadAfter < 0: + return fmt.Errorf("Shape.NothingToReadAfter %d is negative", s.NothingToReadAfter) + case len(s.Anchors) > MaxAnchors: + return fmt.Errorf("%d anchors, at most %d", len(s.Anchors), MaxAnchors) + case len(s.Anchors) > 0 && shape != "living": + return errors.New("anchors are for living pages; a versioned source's releases are guarded by count and NothingToRead") + } + for _, a := range s.Anchors { + if strings.TrimSpace(a.Entry) == "" || !day.MatchString(a.Checked) { + return fmt.Errorf("anchor %q: an entry and the day it was checked (YYYY-MM-DD) are both required", a.Entry) + } + } + return nil +} diff --git a/core/plugin/shape_test.go b/core/plugin/shape_test.go new file mode 100644 index 0000000..f39d628 --- /dev/null +++ b/core/plugin/shape_test.go @@ -0,0 +1,72 @@ +package plugin + +import ( + "errors" + "testing" +) + +func TestCheckCount(t *testing.T) { + if err := (*Shape)(nil).CheckCount("items", 0.9, 77, 0); err != nil { + t.Errorf("no shape, no guard: %v", err) + } + for _, c := range []struct { + name string + shape Shape + before, now int + changed bool + }{ + {"first read", Shape{}, -1, 0, false}, + {"nothing before", Shape{}, 0, 0, false}, + {"same", Shape{}, 77, 77, false}, + {"grew", Shape{}, 77, 90, false}, + {"a few removed", Shape{}, 77, 72, false}, + {"most gone", Shape{}, 77, 20, true}, + {"none left of a few", Shape{}, 3, 0, true}, + {"a few of a few: not compared", Shape{}, 4, 1, false}, + {"the source's own ratio", Shape{MinRatio: 0.2}, 77, 20, false}, + } { + err := (&c.shape).CheckCount("items", 0.9, c.before, c.now) + if got := errors.Is(err, ErrShapeChanged); got != c.changed { + t.Errorf("%s: %v, want changed %v", c.name, err, c.changed) + } + } +} + +func TestCheckAnchors(t *testing.T) { + s := Shape{Anchors: []Anchor{{Entry: "gpt-4-0613", Checked: "2026-11-21"}}} + has := func(e string) bool { return e == "gpt-4-0613" } + if err := (*Shape)(nil).CheckAnchors(func(string) bool { return false }); err != nil { + t.Errorf("no shape, no guard: %v", err) + } + if err := s.CheckAnchors(has); err != nil { + t.Errorf("anchor present: %v", err) + } + if err := s.CheckAnchors(func(string) bool { return false }); !errors.Is(err, ErrShapeChanged) { + t.Errorf("anchor missing: %v", err) + } +} + +// Nothing to read on the newest releases in a row, after one that had +// something: a shape signal, not ErrNothingToRead. +func TestNothingToRead(t *testing.T) { + for _, c := range []struct { + name string + read []bool + changed bool + }{ + {"every release read", []bool{true, true, true}, false}, + {"one release without a section", []bool{true, false, true}, false}, + {"two in a row", []bool{true, true, false, false}, false}, + {"three in a row after a read", []bool{true, true, false, false, false}, true}, + {"never had anything", []bool{false, false, false, false}, false}, + {"recovered", []bool{true, false, false, false, true}, false}, + } { + err := Shape{}.NothingToRead(c.read) + if errors.Is(err, ErrShapeChanged) != c.changed || errors.Is(err, ErrNothingToRead) { + t.Errorf("%s: %v, want changed %v", c.name, err, c.changed) + } + } + if err := (Shape{NothingToReadAfter: 5}).NothingToRead([]bool{true, false, false, false}); err != nil { + t.Errorf("the source's own count: %v", err) + } +} diff --git a/docs/how-it-works.md b/docs/how-it-works.md index b88ce50..a26e8ea 100644 --- a/docs/how-it-works.md +++ b/docs/how-it-works.md @@ -21,7 +21,7 @@ There's no list in this repo: `make plugins` prints every provider and source fr | Path | What's there | |---|---| -| [`core/plugin/`](../core/plugin/) | The `Plugin` interface (`Extract`) in its two shapes, `Versioned` (`ListVersions`, `ReadAt`) and `Living` (`Read`); `ErrNothingToRead`; the registry of providers and sources (`RegisterProvider`, `Lookup`, `LookupSource`, `Providers`), `Env`, `Result` | +| [`core/plugin/`](../core/plugin/) | The `Plugin` interface (`Extract`) in its two shapes, `Versioned` (`ListVersions`, `ReadAt`) and `Living` (`Read`); `ErrNothingToRead`; the shape guard every kind runs (`Shape`, anchors, `ErrShapeChanged`); the registry of providers and sources (`RegisterProvider`, `Lookup`, `LookupSource`, `Providers`), `Env`, `Result` | | [`core/versions/`](../core/versions/) | Every version of a source: GitHub releases, tags and commits, PyPI, npm | | [`kinds/`](../kinds/) | How to read: one package per kind (openapi, changelog, notices, migrationguide, catalog, apisurface), each with its readers and a test helper package; no kind imports a provider | | [`providers/`](../providers/) | What to read: one folder per provider, `providers//` with `provider.go` (its registration), `README.md` (its page: why each source, what it reads), any code only it needs, `testdata/` and its tests; [`providers/all`](../providers/all/) imports every one, and its tests check the folders and the import graph | diff --git a/docs/writing-a-plugin.md b/docs/writing-a-plugin.md index 475cdec..2cac215 100644 --- a/docs/writing-a-plugin.md +++ b/docs/writing-a-plugin.md @@ -129,7 +129,7 @@ type Result struct { A plugin **stores nothing** and reads nothing back: whoever runs it (patch-it's hosted ingestion service, or the test kit) stores the events and keeps the snapshot the next comparison starts from. -When a release or a page has no part the reader can use (a changelog with no section for the release, a migration guide with no table of removals, a page with no table of notices), return `plugin.ErrNothingToRead`, wrapped with what was missing (`fmt.Errorf("no heading for release %s: %w", v, plugin.ErrNothingToRead)`). For a release that's normal, and the runner skips the pair instead of retrying it; it finds the error with `errors.Is`. Any other error is a failure, retried next run. +When a release or a page has no part the reader can use (a changelog with no section for the release, a migration guide with no table of removals, a page with no table of notices), return `plugin.ErrNothingToRead`, wrapped with what was missing (`fmt.Errorf("no heading for release %s: %w", v, plugin.ErrNothingToRead)`). For a release that's normal, and the runner skips the pair instead of retrying it; it finds the error with `errors.Is`. A living page with nothing to read is never normal: the notices kind turns it into `plugin.ErrShapeChanged` (see [the shape guard](#when-the-source-changes-its-layout-the-shape-guard-and-anchors)). Any other error is a failure, retried next run. ### A source with versions: `plugin.Versioned` @@ -181,6 +181,29 @@ func init() { `Packages` are the published packages the source covers, `:` (`pypi:stripe`, `npm:@vercel/sdk`): the package itself for a package or SDK source, the provider's official SDKs for an API source. `plugin.ForPackage` finds a package's sources, so a customer's lockfile maps to sources with no table kept anywhere else. List only names you checked; none is fine. +### When the source changes its layout: the shape guard and anchors + +A source that redesigns its page, moves its changelog or reshapes its spec must never read as "nothing changed", and never as "everything was removed". Every kind runs a **shape guard** ([`core/plugin/shape.go`](../core/plugin/shape.go)), and a read it refuses fails with `plugin.ErrShapeChanged`: nothing is stored, no event is made, and patch-it's hosted ingestion service reports the source as failing (after repeated failures it opens an issue in this repo labelled `source-health`). + +- **Count.** Each kind counts what one read found and compares it with the read before: a notices page's notices, a feed's entries, a spec's operations, a changelog file's release headings, a JSON changelog's days, a catalog's command files or upcoming entries, a package's public names. A read with fewer than the kind's ratio of the read before (`DefaultMinRatio` in each kind: 0.9 for a notices page, a changelog or a JSON changelog, 0.5 for a feed, a spec or a package surface, 0.8 for a command catalog, 0.25 for a file of upcoming changes), or with none after one that had some, fails. The ratio is compared only when the read before found at least `plugin.MinItemsCompared` items. A migration guide is one document per major, so it has no count to compare. +- **Nothing to read, release after release.** For a versioned source, `ErrNothingToRead` on one release is normal. The runner keeps, oldest first, whether each release had something to read and calls `Shape.NothingToRead`: the newest `NothingToReadAfter` releases in a row (3 by default) with nothing, after one that had something, is `ErrShapeChanged` (a moved changelog, a guide no longer shipped), not more skipped pairs. +- **Anchors** (living pages only). A source names one or two entries its page always lists, so a page that still parses but no longer carries what the source reads fails too. An anchor is an entry as the kind's reader names it: a model id on a deprecations page, a version number on an end-of-life table, the feed's own title (a feed drops its oldest entries, so its title is what stays) or an entry's title. Check each one on the **live page** and write it in `provider.go` by hand, with a comment saying where it is on the page and the date you checked it (`Checked`). Never derive an anchor from the saved copy in `testdata/`. `noticestest.Golden` checks the anchors are on the saved page too. + +The source's `Shape` (on its `plugin.Source`) holds its anchors and any ratio or count of its own; leave it zero for the kind's defaults, and set a field only with a comment saying why: + +```go +{ + ID: "models", Layer: plugin.LayerAIModels, + // ... + // Anchors: two models in the page's "Past deprecations" table, which keeps + // every shutdown (gpt-4-0613: Oct 23, 2026; gpt-3.5-turbo-0301: Sep 13, 2024). + Shape: plugin.Shape{Anchors: []plugin.Anchor{{Entry: "gpt-4-0613", Checked: "2026-11-21"}, {Entry: "gpt-3.5-turbo-0301", Checked: "2026-11-21"}}}, + Plugin: notices.Plugin{Page: Models, Archiver: kit.Wayback{}}, +}, +``` + +`RegisterProvider` hands each plugin its source's `Shape` (`plugin.Guarded.WithShape`) and refuses a plugin that doesn't take one: a new kind implements `WithShape` and calls `Shape.CheckCount` (and, for a living page, `Shape.CheckAnchors`) before it reads a single change. A plugin built by hand in a test isn't guarded unless the test gives it a `Shape`: golden tests read trimmed copies, far smaller than the real releases, so a test of the guard calls `WithShape` itself (each kind has one with a redesigned or shrunken input). + ### Fetching: `env.Get` and `core/kit/` - Fetch **only** with `env.Get`. It caches by `ETag` / `Last-Modified`, retries, and in tests serves saved files. `CI_go` fails a package outside `core/fetch/` and `core/kit/` that imports `net/http`. diff --git a/kinds/apisurface/apisurface.go b/kinds/apisurface/apisurface.go index 3a9daf3..22f15aa 100644 --- a/kinds/apisurface/apisurface.go +++ b/kinds/apisurface/apisurface.go @@ -50,10 +50,25 @@ type Package struct { // Plugin reads one package's releases. type Plugin struct { Package Package + + shape *plugin.Shape // the source's, set by RegisterProvider (WithShape); nil: no guard } +// DefaultMinRatio is the shape guard's ratio for a package's surface: a +// release whose public API reads as less than half the one before is a +// package that moved its code (a new top-level module, declarations +// shipped elsewhere) or a reader that no longer finds it, not half an API +// removed. A source that does shrink that much on purpose sets its own. +const DefaultMinRatio = 0.5 + func (p Plugin) Name() string { return p.Package.ID } +// WithShape is p guarding its pairs with s. +func (p Plugin) WithShape(s plugin.Shape) plugin.Plugin { + p.shape = &s + return p +} + // ListVersions is every final release on the registry, oldest first. func (p Plugin) ListVersions(ctx context.Context, env plugin.Env) ([]plugin.Version, error) { switch p.Package.Ecosystem { @@ -128,6 +143,9 @@ func (p Plugin) Extract(_ context.Context, env plugin.Env, from, to plugin.Snaps if err := json.Unmarshal(to.Content, &b); err != nil { return plugin.Result{}, fmt.Errorf("reading the %s %s surface: %w", p.Package.Name, to.Version.ID, err) } + if err := p.shape.CheckCount("public names", DefaultMinRatio, len(a.Surface), len(b.Surface)); err != nil { + return plugin.Result{}, fmt.Errorf("the %s %s surface: %w", p.Package.Name, to.Version.ID, err) + } now := env.Now().UTC() var events []event.Event var rejected []error @@ -147,7 +165,10 @@ func (p Plugin) Extract(_ context.Context, env plugin.Env, from, to plugin.Snaps return plugin.Result{Events: events, Rejected: rejected}, nil } -var _ plugin.Versioned = Plugin{} +var ( + _ plugin.Versioned = Plugin{} + _ plugin.Guarded = Plugin{} +) // event is one change as a change event. func (p Plugin) event(c Change, from, to plugin.Snapshot, fromFile, toFile string, now time.Time) event.Event { diff --git a/kinds/apisurface/shape_test.go b/kinds/apisurface/shape_test.go new file mode 100644 index 0000000..0ee009d --- /dev/null +++ b/kinds/apisurface/shape_test.go @@ -0,0 +1,41 @@ +package apisurface + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "testing" + "time" + + "github.com/patch-it-dev/patch-it-plugins/core/plugin" + "github.com/patch-it-dev/patch-it-plugins/kinds/apisurface/pysurface" +) + +func release(id string, n int) plugin.Snapshot { + s := pysurface.Surface{} + for i := 0; i < n; i++ { + s[fmt.Sprintf("acme.f%d", i)] = sym("function") + } + b, _ := json.Marshal(Release{Artifact: "acme-" + id + ".whl", Surface: s}) + return plugin.Snapshot{Version: plugin.Version{ID: id}, Content: b, SourceURL: "https://x.test/acme-" + id + ".whl"} +} + +// A release whose public API reads as a fraction of the one before (the +// code moved to a new top-level module, or the declarations aren't where the +// reader looks any more) fails the shape guard: no symbol is read as removed. +func TestASurfaceThatShrankChangedShape(t *testing.T) { + env := plugin.Env{Now: time.Now} + p := Plugin{Package: Package{ID: "acme/python-surface", Name: "acme", Ecosystem: "pypi", Module: "acme"}} + res, err := p.WithShape(plugin.Shape{}).Extract(context.Background(), env, release("1.0.0", 60), release("2.0.0", 3)) + if !errors.Is(err, plugin.ErrShapeChanged) || len(res.Events) != 0 { + t.Errorf("60 -> 3 names: %v, %d events", err, len(res.Events)) + } + if _, err := p.WithShape(plugin.Shape{}).Extract(context.Background(), env, release("1.0.0", 60), release("2.0.0", 0)); !errors.Is(err, plugin.ErrShapeChanged) { + t.Errorf("60 -> 0 names: %v", err) + } + res, err = p.WithShape(plugin.Shape{}).Extract(context.Background(), env, release("1.0.0", 60), release("2.0.0", 55)) + if err != nil || len(res.Events) != 5 { + t.Errorf("60 -> 55 names: %v, %d events, want 5 removals", err, len(res.Events)) + } +} diff --git a/kinds/catalog/commands.go b/kinds/catalog/commands.go index f027d94..a5761e5 100644 --- a/kinds/catalog/commands.go +++ b/kinds/catalog/commands.go @@ -39,10 +39,24 @@ type Commands struct { // Release matches a final release's tag; its first submatch is the // version. Release *regexp.Regexp + + shape *plugin.Shape // the source's, set by RegisterProvider (WithShape); nil: no guard } +// CommandsMinRatio is the shape guard's ratio for a command catalog: a +// release that keeps fewer than 80% of the command files of the one before +// moved or reorganized the directory; read as removals, it would be most of +// the catalog. +const CommandsMinRatio = 0.8 + func (c Commands) Name() string { return c.API } +// WithShape is c guarding its pairs with s. +func (c Commands) WithShape(s plugin.Shape) plugin.Plugin { + c.shape = &s + return c +} + // ListingURL is GitHub's listing of the directory at a ref. func (c Commands) ListingURL(ref string) string { return fmt.Sprintf("%s/repos/%s/contents/%s?ref=%s", github.API, c.Repo, c.Dir, url.QueryEscape(ref)) @@ -118,6 +132,9 @@ func (c Commands) Extract(ctx context.Context, env plugin.Env, from, to plugin.S if err := json.Unmarshal(to.Content, &after); err != nil { return plugin.Result{}, fmt.Errorf("reading %s: %w", to.SourceURL, err) } + if err := c.shape.CheckCount("command files", CommandsMinRatio, len(before), len(after)); err != nil { + return plugin.Result{}, fmt.Errorf("reading %s: %w", to.SourceURL, err) + } var made []event.Event for _, file := range before { if slices.Contains(after, file) { @@ -181,4 +198,7 @@ func command(body []byte) (name, entry string, err error) { return name, entry, nil } -var _ plugin.Versioned = Commands{} +var ( + _ plugin.Versioned = Commands{} + _ plugin.Guarded = Commands{} +) diff --git a/kinds/catalog/shape_test.go b/kinds/catalog/shape_test.go new file mode 100644 index 0000000..bdfcb24 --- /dev/null +++ b/kinds/catalog/shape_test.go @@ -0,0 +1,62 @@ +package catalog + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "regexp" + "testing" + "time" + + "github.com/patch-it-dev/patch-it-plugins/core/plugin" +) + +func snap(id string, v any) plugin.Snapshot { + b, _ := json.Marshal(v) + return plugin.Snapshot{Version: plugin.Version{ID: id, Ref: id}, Content: b, SourceURL: "https://x.test/" + id} +} + +func files(n int) []string { + var out []string + for i := 0; i < n; i++ { + out = append(out, fmt.Sprintf("cmd%d.json", i)) + } + return out +} + +// A release whose command directory lost most of its files moved or +// reorganized it: read as removals it would be most of the catalog, so it +// fails the shape guard before a single file is fetched. +func TestACatalogThatLostMostCommandsChangedShape(t *testing.T) { + env := plugin.Env{Now: time.Now, Get: func(_ context.Context, u string) ([]byte, error) { + return nil, fmt.Errorf("fetched %s", u) + }} + c := Commands{API: "acme/commands", Ecosystem: "acme", Package: "acme", Repo: "acme/acme", Dir: "commands", Release: regexp.MustCompile(`^v(.*)$`)} + res, err := c.WithShape(plugin.Shape{}).Extract(context.Background(), env, snap("8.0.0", files(200)), snap("8.2.0", files(20))) + if !errors.Is(err, plugin.ErrShapeChanged) || len(res.Events) != 0 { + t.Errorf("200 -> 20 command files: %v, %d events", err, len(res.Events)) + } +} + +// A file of upcoming changes that suddenly lists nothing (reformatted, or +// emptied by a bad commit) fails the guard; entries leaving in a batch when +// their date passes don't. +func TestUpcomingChangesThatVanishedChangedShape(t *testing.T) { + env := plugin.Env{Now: time.Now} + entries := func(n int) map[string][]map[string]string { + out := map[string][]map[string]string{} + for i := 0; i < n; i++ { + d := fmt.Sprintf("2027-%02d-01", i%12+1) + out[d] = append(out[d], map[string]string{"location": fmt.Sprintf("Thing.field%d", i), "date": d + "T00:00:00+00:00", "criticality": "breaking"}) + } + return out + } + u := UpcomingChanges{API: "acme/graphql", Vendor: "Acme", Repo: "acme/acme", Path: "upcoming.json", Endpoint: "POST /graphql"}.WithShape(plugin.Shape{}) + if _, err := u.Extract(context.Background(), env, snap("2026-11-01", entries(40)), snap("2026-11-02", map[string]any{})); !errors.Is(err, plugin.ErrShapeChanged) { + t.Errorf("40 -> 0 entries: %v", err) + } + if _, err := u.Extract(context.Background(), env, snap("2026-11-01", entries(40)), snap("2026-11-02", entries(20))); err != nil { + t.Errorf("40 -> 20 entries, a batch shipped: %v", err) + } +} diff --git a/kinds/catalog/upcoming.go b/kinds/catalog/upcoming.go index 4413f51..ff9652e 100644 --- a/kinds/catalog/upcoming.go +++ b/kinds/catalog/upcoming.go @@ -42,10 +42,23 @@ type UpcomingChanges struct { // Endpoint is the GraphQL endpoint as an operation: every query and // mutation is a POST to it ("POST /graphql"). Endpoint string + + shape *plugin.Shape // the source's, set by RegisterProvider (WithShape); nil: no guard } +// UpcomingMinRatio is the shape guard's ratio for a file of upcoming +// changes: entries leave it in batches when their date passes, so only a +// file left with under a quarter of its entries (or none) changed shape. +const UpcomingMinRatio = 0.25 + func (u UpcomingChanges) Name() string { return u.API } +// WithShape is u guarding its pairs with s. +func (u UpcomingChanges) WithShape(s plugin.Shape) plugin.Plugin { + u.shape = &s + return u +} + // FileURL is the file at a commit: its own provenance. func (u UpcomingChanges) FileURL(sha string) string { return fmt.Sprintf("%s/%s/%s/%s", github.Raw, u.Repo, sha, u.Path) @@ -126,6 +139,9 @@ func (u UpcomingChanges) Extract(_ context.Context, env plugin.Env, from, to plu if err != nil { return plugin.Result{}, fmt.Errorf("reading %s: %w", to.SourceURL, err) } + if err := u.shape.CheckCount("entries", UpcomingMinRatio, len(before), len(after)); err != nil { + return plugin.Result{}, fmt.Errorf("reading %s: %w", to.SourceURL, err) + } had := map[string]bool{} for _, e := range before { had[e.key()] = true @@ -187,4 +203,7 @@ func (u UpcomingChanges) subject(location string) (event.Subject, bool) { Schema: typ, Property: rest}, true } -var _ plugin.Versioned = UpcomingChanges{} +var ( + _ plugin.Versioned = UpcomingChanges{} + _ plugin.Guarded = UpcomingChanges{} +) diff --git a/kinds/changelog/changelog.go b/kinds/changelog/changelog.go index 63121a8..147e576 100644 --- a/kinds/changelog/changelog.go +++ b/kinds/changelog/changelog.go @@ -229,6 +229,21 @@ func (f File) added(sections []Section) map[string]bool { type Plugin struct { File File Log Log + + shape *plugin.Shape // the source's, set by RegisterProvider (WithShape); nil: no guard +} + +// DefaultMinRatio is the shape guard's ratio for a changelog file or a JSON +// changelog: both keep every past release or day, so one that has fewer +// than 90% of what it had at the version before was moved, split or +// reformatted. A release's notes on GitHub are one release each: nothing to +// compare, so only Shape.NothingToRead guards them. +const DefaultMinRatio = 0.9 + +// WithShape is p guarding its pairs with s. +func (p Plugin) WithShape(s plugin.Shape) plugin.Plugin { + p.shape = &s + return p } // isLog is a JSON changelog. @@ -305,6 +320,11 @@ func (p Plugin) Extract(_ context.Context, env plugin.Env, from, to plugin.Snaps } f := p.File f.Release, f.Tag = to.Version.ID, to.Version.Ref + if !f.Notes && from.Content != nil { + if err := p.shape.CheckCount("release headings", DefaultMinRatio, Releases(from.Content), Releases(to.Content)); err != nil { + return plugin.Result{}, fmt.Errorf("reading %s: %w", f.Cite(), err) + } + } heading, findings, err := f.Read(to.Content) if err != nil { return plugin.Result{}, fmt.Errorf("reading %s: %w", f.Cite(), err) @@ -351,7 +371,10 @@ func (p Plugin) Extract(_ context.Context, env plugin.Env, from, to plugin.Snaps return plugin.Result{Events: events, Rejected: rejected}, nil } -var _ plugin.Versioned = Plugin{} +var ( + _ plugin.Versioned = Plugin{} + _ plugin.Guarded = Plugin{} +) func describe(f File, c Change) string { names := "`" + strings.Join(c.Symbols, "`, `") + "`" diff --git a/kinds/changelog/json.go b/kinds/changelog/json.go index 5893b56..b53202a 100644 --- a/kinds/changelog/json.go +++ b/kinds/changelog/json.go @@ -202,6 +202,11 @@ func (p Plugin) readLog(ctx context.Context, env plugin.Env, v plugin.Version) ( // compared with. func (p Plugin) extractLog(env plugin.Env, from, to plugin.Snapshot) (plugin.Result, error) { l := p.Log + if from.Content != nil { + if err := p.shape.CheckCount("days", DefaultMinRatio, days(from.Content), days(to.Content)); err != nil { + return plugin.Result{}, fmt.Errorf("reading %s: %w", to.SourceURL, err) + } + } findings, err := l.Read(to.Content) if err != nil { return plugin.Result{}, fmt.Errorf("reading %s: %w", to.SourceURL, err) @@ -251,6 +256,15 @@ func (p Plugin) extractLog(env plugin.Env, from, to plugin.Snapshot) (plugin.Res return plugin.Result{Events: events, Rejected: rejected}, nil } +// days is how many days the file lists, 0 when it isn't a list. +func days(b []byte) int { + var ds []json.RawMessage + if json.Unmarshal(b, &ds) != nil { + return 0 + } + return len(ds) +} + // key is what makes two findings the same change: an endpoint's API version // deprecated, or removed. func (f LogFinding) key() string { return string(f.ChangeType) + " " + f.Operation + " " + f.Version } diff --git a/kinds/changelog/parse.go b/kinds/changelog/parse.go index 5e6f6dd..3391687 100644 --- a/kinds/changelog/parse.go +++ b/kinds/changelog/parse.go @@ -120,6 +120,30 @@ func sections(body []string, rst bool, heading *regexp.Regexp) []Section { return out } +// Releases is how many releases a changelog file heads: Markdown release +// headings, or else reStructuredText release titles. What the shape guard +// counts: a changelog keeps every past release, so a file that heads far +// fewer than at the release before was moved, split or reformatted. +func Releases(file []byte) int { + lines := strings.Split(strings.ReplaceAll(string(file), "\r\n", "\n"), "\n") + md, rst := 0, 0 + for i, l := range lines { + if mdRelease.MatchString(l) { + md++ + } + if i+1 < len(lines) { + t, u := strings.TrimSpace(l), strings.TrimSpace(lines[i+1]) + if rstRelease.MatchString(t) && rstUnderline.MatchString(u) && len(u) >= len(t) { + rst++ + } + } + } + if md > 0 { + return md + } + return rst +} + // releaseLines are release's heading and the lines under it, up to the next // release's, and whether the file is reStructuredText. func releaseLines(lines []string, release string) (string, []string, bool, error) { diff --git a/kinds/changelog/shape_test.go b/kinds/changelog/shape_test.go new file mode 100644 index 0000000..680c604 --- /dev/null +++ b/kinds/changelog/shape_test.go @@ -0,0 +1,98 @@ +package changelog + +import ( + "context" + "errors" + "fmt" + "strings" + "testing" + "time" + + "github.com/patch-it-dev/patch-it-plugins/core/plugin" +) + +// changelogFile is a Keep a Changelog file heading releases 1.0.0 to 1..0, newest first. +func changelogFile(n int) []byte { + var b strings.Builder + b.WriteString("# Changelog\n\n") + for i := n - 1; i >= 0; i-- { + fmt.Fprintf(&b, "## [1.%d.0] - 2026-01-%02d\n\n### Fixed\n\n- a fix\n\n", i, i%28+1) + } + return []byte(b.String()) +} + +func at(release string, content []byte) plugin.Snapshot { + return plugin.Snapshot{Version: plugin.Version{ID: release, Ref: "v" + release}, Content: content, SourceURL: "https://x.test/" + release} +} + +// A changelog moved elsewhere leaves a stub at the old path: far fewer +// release headings than the release before is a shape change, not "nothing +// to read" for this release. +func TestAMovedChangelogChangedShape(t *testing.T) { + env := plugin.Env{Now: time.Now} + p := Plugin{File: File{API: "acme/acme", Package: "acme", Ecosystem: "pypi", Module: "acme", Repo: "acme/acme", TagPrefix: "v", Path: "CHANGELOG.md"}} + guarded := p.WithShape(plugin.Shape{}) + stub := []byte("# Changelog\n\nThe changelog moved to docs/changes.md.\n") + _, err := guarded.Extract(context.Background(), env, at("1.11.0", changelogFile(12)), at("1.12.0", stub)) + if !errors.Is(err, plugin.ErrShapeChanged) || errors.Is(err, plugin.ErrNothingToRead) { + t.Errorf("moved: %v, want ErrShapeChanged only", err) + } + // Reformatted: the same releases under headings the reader no longer knows. + reformatted := []byte(strings.ReplaceAll(string(changelogFile(13)), "## [", "**Release [")) + if _, err := guarded.Extract(context.Background(), env, at("1.11.0", changelogFile(12)), at("1.12.0", reformatted)); !errors.Is(err, plugin.ErrShapeChanged) { + t.Errorf("reformatted: %v", err) + } + // The next release, one more heading: read as before. + if _, err := guarded.Extract(context.Background(), env, at("1.11.0", changelogFile(12)), at("1.12.0", changelogFile(13))); err != nil { + t.Errorf("next release: %v", err) + } + // Built by hand, no Shape: no guard, the stub is only nothing to read. + if _, err := p.Extract(context.Background(), env, at("1.11.0", changelogFile(12)), at("1.12.0", stub)); !errors.Is(err, plugin.ErrNothingToRead) { + t.Errorf("unguarded: %v", err) + } +} + +// A JSON changelog keeps every day: one with far fewer days changed shape. +func TestAJSONChangelogThatLostItsDaysChangedShape(t *testing.T) { + env := plugin.Env{Now: time.Now} + days := func(n int) []byte { + var ds []string + for i := 0; i < n; i++ { + ds = append(ds, fmt.Sprintf(`{"date": "2026-01-%02d", "paths": []}`, i+1)) + } + return []byte("[" + strings.Join(ds, ",") + "]") + } + p := Plugin{Log: Log{API: "acme/api", Vendor: "Acme", Name: "Acme API", Repo: "acme/api", Path: "changelog.json"}}.WithShape(plugin.Shape{}) + if _, err := p.Extract(context.Background(), env, at("2026-01-20", days(20)), at("2026-01-21", days(2))); !errors.Is(err, plugin.ErrShapeChanged) { + t.Errorf("20 -> 2 days: %v", err) + } + if _, err := p.Extract(context.Background(), env, at("2026-01-20", days(20)), at("2026-01-21", days(21))); err != nil { + t.Errorf("20 -> 21 days: %v", err) + } +} + +// Release notes on GitHub are one release each: a run of releases with no +// notes after ones that had some is the runner's shape signal +// (Shape.NothingToRead), never the kind's. +func TestReleasesWithNoNotesInARowAreAShapeSignal(t *testing.T) { + env := plugin.Env{Now: time.Now} + p := Plugin{File: File{API: "acme/acme", Package: "acme", Ecosystem: "pypi", Module: "acme", Repo: "acme/acme", TagPrefix: "v", Notes: true}}.WithShape(plugin.Shape{}) + notes := func(tag, body string) []byte { + return []byte(fmt.Sprintf(`{"tag_name": "v%s", "body": %q}`, tag, body)) + } + var read []bool + prev := at("1.0.0", notes("1.0.0", "## Fixed\n\n- a fix\n")) + for i, body := range []string{"## Fixed\n\n- a fix\n", "", "", ""} { + release := fmt.Sprintf("1.%d.0", i+1) + cur := at(release, notes(release, body)) + _, err := p.Extract(context.Background(), env, prev, cur) + if err != nil && !errors.Is(err, plugin.ErrNothingToRead) { + t.Fatalf("%s: %v", release, err) + } + read = append(read, err == nil) + prev = cur + } + if err := (plugin.Shape{}).NothingToRead(read); !errors.Is(err, plugin.ErrShapeChanged) { + t.Errorf("%v: %v, want ErrShapeChanged", read, err) + } +} diff --git a/kinds/migrationguide/migrationguide.go b/kinds/migrationguide/migrationguide.go index 1c75bd5..6a8ca66 100644 --- a/kinds/migrationguide/migrationguide.go +++ b/kinds/migrationguide/migrationguide.go @@ -41,12 +41,21 @@ type Guide interface { } // Plugin reads one source's migration guide. +// +// Each major's guide is its own document, so a guide is never compared with +// the one before: the shape guard here is the runner's +// Shape.NothingToRead over the releases (a guide that stops being found). type Plugin struct { Guide Guide } func (p Plugin) Name() string { return p.Guide.Slug() } +// WithShape is p as it is: a guide has no count to compare, and whoever +// runs it reads the source's NothingToReadAfter from the registry +// (plugin.LookupSource) for Shape.NothingToRead. +func (p Plugin) WithShape(plugin.Shape) plugin.Plugin { return p } + // ListVersions is every release of the source, oldest first. func (p Plugin) ListVersions(ctx context.Context, env plugin.Env) ([]plugin.Version, error) { return p.Guide.Releases(ctx, env) @@ -88,4 +97,7 @@ func (p Plugin) Extract(_ context.Context, env plugin.Env, from, to plugin.Snaps return plugin.Result{Events: events, Rejected: rejected}, nil } -var _ plugin.Versioned = Plugin{} +var ( + _ plugin.Versioned = Plugin{} + _ plugin.Guarded = Plugin{} +) diff --git a/kinds/migrationguide/shape_test.go b/kinds/migrationguide/shape_test.go new file mode 100644 index 0000000..c9bc969 --- /dev/null +++ b/kinds/migrationguide/shape_test.go @@ -0,0 +1,56 @@ +package migrationguide + +import ( + "context" + "errors" + "testing" + "time" + + "github.com/patch-it-dev/patch-it-plugins/core/event" + "github.com/patch-it-dev/patch-it-plugins/core/fetch" + "github.com/patch-it-dev/patch-it-plugins/core/plugin" +) + +// guide is a migration guide at every major's tag, served from memory. +type guide struct{} + +func (guide) Slug() string { return "acme/python-sdk" } +func (guide) Releases(context.Context, plugin.Env) ([]plugin.Version, error) { + return nil, nil +} +func (guide) GuideURL(_ context.Context, _ plugin.Env, v plugin.Version) (string, error) { + return "https://x.test/" + v.Ref + "/MIGRATION.md", nil +} +func (guide) Read([]byte, string, plugin.Version, plugin.Version, time.Time) ([]event.Event, []error, error) { + return nil, nil, nil +} + +// A guide that every new major used to have and the newest majors don't (it +// moved, or the repo dropped it) is a shape signal over the releases +// (Shape.NothingToRead), not three quiet majors. +func TestAGuideThatStoppedBeingFoundIsAShapeSignal(t *testing.T) { + served := map[string]bool{"v1.0.0": true, "v2.0.0": true} + env := plugin.Env{Now: time.Now, Get: func(_ context.Context, u string) ([]byte, error) { + for ref := range served { + if u == "https://x.test/"+ref+"/MIGRATION.md" { + return []byte("# Migrating"), nil + } + } + return nil, &fetch.StatusError{URL: u, StatusCode: 404} + }} + p := Plugin{Guide: guide{}}.WithShape(plugin.Shape{}).(plugin.Versioned) + var read []bool + for _, ref := range []string{"v1.0.0", "v2.0.0", "v3.0.0", "v4.0.0", "v5.0.0"} { + _, err := p.ReadAt(context.Background(), env, plugin.Version{ID: ref[1:], Ref: ref}) + if err != nil && !errors.Is(err, plugin.ErrNothingToRead) { + t.Fatalf("%s: %v", ref, err) + } + read = append(read, err == nil) + } + if err := (plugin.Shape{}).NothingToRead(read); !errors.Is(err, plugin.ErrShapeChanged) { + t.Errorf("%v: %v, want ErrShapeChanged", read, err) + } + if err := (plugin.Shape{}).NothingToRead(read[:4]); err != nil { + t.Errorf("two majors without a guide: %v, not yet a signal", err) + } +} diff --git a/kinds/notices/eol/eol.go b/kinds/notices/eol/eol.go index 9f86218..a335659 100644 --- a/kinds/notices/eol/eol.go +++ b/kinds/notices/eol/eol.go @@ -167,6 +167,17 @@ type Read []Finding // Count is how many findings the page gave. func (r Read) Count() int { return len(r) } +// Has says whether entry is a version number a row names ("30.0") or a row's +// own label ("Versions 21.0 through 30.0"). +func (r Read) Has(entry string) bool { + for _, f := range r { + if f.Version == entry || f.Row == entry { + return true + } + } + return false +} + // Slug is the source id the events carry: "salesforce/rest-api". func (pg Page) Slug() string { return pg.API } diff --git a/kinds/notices/feed/feed.go b/kinds/notices/feed/feed.go index 46b55f8..5201f50 100644 --- a/kinds/notices/feed/feed.go +++ b/kinds/notices/feed/feed.go @@ -23,6 +23,7 @@ package feed import ( "fmt" "log" + "slices" "time" "github.com/patch-it-dev/patch-it-plugins/core/event" @@ -57,24 +58,39 @@ type Finding struct { // Findings reads every entry of a feed. func (f Feed) Findings(b []byte) ([]Finding, error) { - entries, err := extract.ParseFeed(b) + found, err := f.Find(b) if err != nil { return nil, err } - var out []Finding - for _, e := range entries { - out = append(out, f.Read(e)...) - } - return out, nil + return found.(Findings).Found, nil } // What the notices kind (kinds/notices) asks of a feed. -// Findings are what one read of a feed found, dropped entries included. -type Findings []Finding +// Findings are what one read of a feed found: the feed's title, every +// entry's title, and the findings, dropped ones included. +type Findings struct { + Title string + Entries []string + Found []Finding +} + +// Count is how many entries the feed has: a feed keeps its newest entries, +// so their number stays about the same from one read to the next even when +// none of them is a finding. +func (fs Findings) Count() int { return len(fs.Entries) } + +// Has says whether entry is the feed's own title or an entry's title. A feed +// drops its oldest entries as new ones come, so its title is the anchor that +// stays: it says the URL still serves the feed it did. +func (fs Findings) Has(entry string) bool { + return fs.Title == entry || slices.Contains(fs.Entries, entry) +} -// Count is how many findings the feed gave. -func (fs Findings) Count() int { return len(fs) } +// MinRatio is the shape guard's ratio for a feed: its window of newest +// entries can shrink when a vendor trims it, so only a drop below half is a +// change of shape. +func (Feed) MinRatio() float64 { return 0.5 } // Slug is the source id the events carry: "github/actions". func (f Feed) Slug() string { return f.API } @@ -84,8 +100,16 @@ func (f Feed) PageURL() string { return f.URL } // Find reads every entry of the feed. func (f Feed) Find(b []byte) (kit.Notices, error) { - fs, err := f.Findings(b) - return Findings(fs), err + entries, err := extract.ParseFeed(b) + if err != nil { + return nil, err + } + out := Findings{Title: extract.FeedTitle(b)} + for _, e := range entries { + out.Entries = append(out.Entries, e.Title) + out.Found = append(out.Found, f.Read(e)...) + } + return out, nil } // Events are an event per finding, citing citeURL; one of a version-pair type @@ -94,7 +118,7 @@ func (f Feed) Find(b []byte) (kit.Notices, error) { func (f Feed) Events(found kit.Notices, citeURL, previous string, now time.Time) ([]event.Event, []error) { var events []event.Event var rejected []error - for _, fd := range found.(Findings) { + for _, fd := range found.(Findings).Found { if fd.Dropped != "" { log.Printf("%s: dropped %s: %s", f.API, fd.Entry, fd.Dropped) continue diff --git a/kinds/notices/notices.go b/kinds/notices/notices.go index 2ab52db..d03d0d3 100644 --- a/kinds/notices/notices.go +++ b/kinds/notices/notices.go @@ -9,17 +9,20 @@ // (kit.Cite); Extract makes the events from that snapshot, so each cites what // it quotes, keeping only the notices the read before didn't have. // -// Two options a reader turns on with a method: ShapeGuard (a read with fewer -// than 90% of the last one's notices is an error: the page changed shape), -// and ArchiveWhenBlocked (a live page that answers one of the statuses its +// Every read runs the shape guard (plugin.Shape) before anything is kept: +// a read that finds fewer than DefaultMinRatio of the notices the read +// before found (a reader can set its own ratio with a MinRatio method: a +// feed's is lower), or that misses one of the source's anchors, fails with +// plugin.ErrShapeChanged. One option a reader turns on with a method: +// ArchiveWhenBlocked (a live page that answers one of the statuses its // provider blocks plain fetches with is read from a fresh Wayback Machine // snapshot instead). // // A living page that can't be read is a failed run, never "nothing // changed": a page with no notices to read (plugin.ErrNothingToRead from its // reader) is the page changing shape or a block page served in its place, -// so Read returns it as a plain error, which errors.Is doesn't take for -// nothing to read. +// so Read returns it as plugin.ErrShapeChanged, which errors.Is doesn't take +// for nothing to read. package notices import ( @@ -51,9 +54,13 @@ type Page interface { Events(found kit.Notices, citeURL, previous string, now time.Time) ([]event.Event, []error) } -// shapeGuarded is a Page whose read with far fewer notices than the last -// is an error. -type shapeGuarded interface{ ShapeGuard() bool } +// DefaultMinRatio is the shape guard's ratio for a notices page: past +// notices stay on the page, so a real drop is rare, and a read with fewer +// than 90% of the last read's notices means a table or a column changed. +const DefaultMinRatio = 0.9 + +// ratioed is a Page with a shape-guard ratio of its own. +type ratioed interface{ MinRatio() float64 } // archivedWhenBlocked is a Page read from a fresh Wayback Machine snapshot // when the live page refuses a plain fetch: ArchiveWhenBlocked is the HTTP @@ -64,10 +71,18 @@ type archivedWhenBlocked interface{ ArchiveWhenBlocked() []int } type Plugin struct { Page Page Archiver kit.Archiver + + shape *plugin.Shape // the source's, set by RegisterProvider (WithShape); nil: no guard } func (p Plugin) Name() string { return p.Page.Slug() } +// WithShape is p guarding its reads with s. +func (p Plugin) WithShape(s plugin.Shape) plugin.Plugin { + p.shape = &s + return p +} + // Read reads the page as it is now. A page that hashes as it did at last // (CompareHash) returns last: one GET (a 304 with the HTTP cache), no // snapshot. Otherwise the page is snapshotted in the Wayback Machine and the @@ -90,18 +105,13 @@ func (p Plugin) Read(ctx context.Context, env plugin.Env, last plugin.Snapshot) if errors.Is(err, plugin.ErrNothingToRead) { // Not a skip: the page this source reads holds no notices, so it // changed shape or something else was served in its place. - return plugin.Snapshot{}, fmt.Errorf("reading %s: the page has no notices to read, it may be blocked or have changed shape: %v", url, err) + return plugin.Snapshot{}, fmt.Errorf("reading %s: %w: the page has no notices to read, it may be blocked: %v", url, plugin.ErrShapeChanged, err) } if err != nil { return plugin.Snapshot{}, fmt.Errorf("reading %s: %w", url, err) } - // A provider renaming a column makes its table unreadable, and the read - // would quietly find fewer notices. Past notices stay on the page, so a - // real drop is rare: fail loudly instead of keeping a partial list. - if g, ok := pg.(shapeGuarded); ok && g.ShapeGuard() && last.Content != nil { - if before, err := pg.Find(last.Content); err == nil && want.Count()*10 < before.Count()*9 { - return plugin.Snapshot{}, fmt.Errorf("%s now lists %d notices, %d at %s: the page's shape may have changed", url, want.Count(), before.Count(), last.SourceURL) - } + if err := p.guard(want, last); err != nil { + return plugin.Snapshot{}, fmt.Errorf("reading %s: %w", url, err) } snapURL, snap := archived, live if snapURL == "" { @@ -115,6 +125,31 @@ func (p Plugin) Read(ctx context.Context, env plugin.Env, last plugin.Snapshot) return plugin.Snapshot{Version: v, Content: snap, SourceURL: snapURL, CompareHash: hash}, nil } +// guard is the shape guard on a read that found want, after the read that +// kept last: every anchor is there, and want isn't far fewer notices than +// last's. A provider renaming a column makes its table unreadable, and the +// read would quietly find fewer notices: fail loudly instead of keeping a +// partial list. +func (p Plugin) guard(want kit.Notices, last plugin.Snapshot) error { + if err := p.shape.CheckAnchors(want.Has); err != nil { + return err + } + before := -1 + if last.Content != nil { + if b, err := p.Page.Find(last.Content); err == nil { + before = b.Count() + } + } + ratio := DefaultMinRatio + if r, ok := p.Page.(ratioed); ok { + ratio = r.MinRatio() + } + if err := p.shape.CheckCount("notices", ratio, before, want.Count()); err != nil { + return fmt.Errorf("%w (the read before: %s)", err, last.SourceURL) + } + return nil +} + // fetch reads the live page. When the page's reader asks for it // (ArchiveWhenBlocked) and the provider's own site blocks a plain fetch with // one of the statuses the reader names (Salesforce's docs site: 403 on @@ -195,4 +230,7 @@ func (p Plugin) events(s plugin.Snapshot, previous string, now time.Time) ([]eve return events, rejected, nil } -var _ plugin.Living = Plugin{} +var ( + _ plugin.Living = Plugin{} + _ plugin.Guarded = Plugin{} +) diff --git a/kinds/notices/noticestest/noticestest.go b/kinds/notices/noticestest/noticestest.go index be92fdb..d0b8089 100644 --- a/kinds/notices/noticestest/noticestest.go +++ b/kinds/notices/noticestest/noticestest.go @@ -7,11 +7,14 @@ import ( "testing" "github.com/patch-it-dev/patch-it-plugins/core/kit/kittest" + "github.com/patch-it-dev/patch-it-plugins/core/plugin" "github.com/patch-it-dev/patch-it-plugins/kinds/notices" ) -// Golden reads the page saved as file through the whole plugin and compares -// every event with testdata/golden/.json. The archive +// Golden reads the page saved as file through the whole plugin, guarded by +// its registered source's Shape (so the anchors it declares must be on the +// saved page too), and compares every event with +// testdata/golden/.json. The archive // serves the same copy as the snapshot, so the events cite it; kittest's // second read of the unchanged page asks for no second snapshot and stores // nothing new. @@ -27,7 +30,12 @@ func GoldenFile(t *testing.T, page notices.Page, file, golden string) { t.Helper() saved := kittest.Pages{page.PageURL(): file} archive := &kittest.Archive{T: t, Pages: saved} - got := kittest.Page(t, kittest.Env(t, saved), notices.Plugin{Page: page, Archiver: archive}) + src, ok := plugin.LookupSource(page.Slug()) + if !ok { + t.Fatalf("%s isn't registered", page.Slug()) + } + p := notices.Plugin{Page: page, Archiver: archive}.WithShape(src.Source.Shape).(plugin.Living) + got := kittest.Page(t, kittest.Env(t, saved), p) if archive.Calls != 1 { t.Errorf("%d snapshots, want 1: the second read's page is unchanged", archive.Calls) } diff --git a/kinds/notices/retire/notices.go b/kinds/notices/retire/notices.go index 774b9b9..3a8e300 100644 --- a/kinds/notices/retire/notices.go +++ b/kinds/notices/retire/notices.go @@ -15,6 +15,16 @@ type Retirements []Retirement // Count is how many retirements the page lists. func (rs Retirements) Count() int { return len(rs) } +// Has says whether entry is a retired model's name. +func (rs Retirements) Has(entry string) bool { + for _, r := range rs { + if r.Model == entry { + return true + } + } + return false +} + // Slug is the source id the events carry: "openai/models". func (p Page) Slug() string { return p.API } @@ -32,8 +42,3 @@ func (p Page) Find(page []byte) (kit.Notices, error) { func (p Page) Events(found kit.Notices, citeURL, _ string, now time.Time) ([]event.Event, []error) { return Events(p, found.(Retirements), citeURL, now) } - -// ShapeGuard is on: past retirements stay on the page, so a read with far -// fewer than the last one means the table changed shape, not that models -// came back. -func (Page) ShapeGuard() bool { return true } diff --git a/kinds/notices/shape_test.go b/kinds/notices/shape_test.go new file mode 100644 index 0000000..83403ec --- /dev/null +++ b/kinds/notices/shape_test.go @@ -0,0 +1,111 @@ +package notices + +import ( + "context" + "errors" + "fmt" + "slices" + "strings" + "testing" + "time" + + "github.com/patch-it-dev/patch-it-plugins/core/event" + "github.com/patch-it-dev/patch-it-plugins/core/kit" + "github.com/patch-it-dev/patch-it-plugins/core/plugin" +) + +// lines is a page of notices, one name per line; an empty page has none to +// read. +type lines struct{ ratio float64 } + +type names []string + +func (n names) Count() int { return len(n) } +func (n names) Has(entry string) bool { return slices.Contains(n, entry) } + +func (lines) Slug() string { return "acme/models" } +func (lines) PageURL() string { return "https://x.test/deprecations" } +func (lines) Find(page []byte) (kit.Notices, error) { + var out names + for _, l := range strings.Split(strings.TrimSpace(string(page)), "\n") { + if l != "" { + out = append(out, l) + } + } + if len(out) == 0 { + return nil, fmt.Errorf("no table: %w", plugin.ErrNothingToRead) + } + return out, nil +} +func (lines) Events(kit.Notices, string, string, time.Time) ([]event.Event, []error) { return nil, nil } + +// withRatio is a reader with a ratio of its own, as a feed has. +type withRatio struct{ lines } + +func (withRatio) MinRatio() float64 { return 0.5 } + +// sameArchive serves the page it is given as the snapshot. +type sameArchive struct{ page *string } + +func (a sameArchive) Snapshot(context.Context, string) (string, []byte, error) { + return "https://web.archive.org/web/1/x", []byte(*a.page), nil +} + +func page(n int, extra ...string) string { + var out []string + for i := 0; i < n; i++ { + out = append(out, fmt.Sprintf("model-%d", i)) + } + return strings.Join(append(out, extra...), "\n") +} + +// read reads now after a read of before, with the source's shape. +func read(pg Page, shape plugin.Shape, before, now string) error { + cur := before + env := plugin.Env{Now: time.Now, Get: func(context.Context, string) ([]byte, error) { return []byte(cur), nil }} + p := Plugin{Page: pg, Archiver: sameArchive{&cur}}.WithShape(shape).(plugin.Living) + last, err := p.Read(context.Background(), env, plugin.Snapshot{}) + if err != nil { + return fmt.Errorf("first read: %w", err) + } + cur = now + _, err = p.Read(context.Background(), env, last) + return err +} + +func TestTheShapeGuardOnALivingPage(t *testing.T) { + anchored := plugin.Shape{Anchors: []plugin.Anchor{{Entry: "model-0", Checked: "2026-11-21"}}} + for _, c := range []struct { + name string + pg Page + shape plugin.Shape + before, now string + changed bool + }{ + {"unchanged count", lines{}, plugin.Shape{}, page(40), page(40, "new-model"), false}, + {"a renamed column hid most rows", lines{}, plugin.Shape{}, page(40), page(10), true}, + {"a redesigned page with no table", lines{}, plugin.Shape{}, page(40), "", true}, + {"a few rows fewer, under the kind's 90%", lines{}, plugin.Shape{}, page(40), page(30), true}, + {"the same, with the source's own ratio", lines{}, plugin.Shape{MinRatio: 0.7}, page(40), page(30), false}, + {"a feed's window shrank a little", withRatio{}, plugin.Shape{}, page(40), page(30), false}, + {"a feed lost most entries", withRatio{}, plugin.Shape{}, page(40), page(10), true}, + {"the anchor is there", lines{}, anchored, page(40), page(41), false}, + {"the anchor is gone", lines{}, anchored, page(40), strings.Replace(page(41), "model-0\n", "", 1), true}, + } { + err := read(c.pg, c.shape, c.before, c.now) + if errors.Is(err, plugin.ErrShapeChanged) != c.changed { + t.Errorf("%s: %v, want changed %v", c.name, err, c.changed) + } + } + // An anchor is checked on a first read too. + cur := page(5) + env := plugin.Env{Now: time.Now, Get: func(context.Context, string) ([]byte, error) { return []byte(cur), nil }} + p := Plugin{Page: lines{}, Archiver: sameArchive{&cur}}.WithShape(plugin.Shape{Anchors: []plugin.Anchor{{Entry: "gpt-4", Checked: "2026-11-21"}}}).(plugin.Living) + if _, err := p.Read(context.Background(), env, plugin.Snapshot{}); !errors.Is(err, plugin.ErrShapeChanged) { + t.Errorf("first read without the anchor: %v", err) + } + // Built by hand, no Shape: no guard. + if _, err := (Plugin{Page: lines{}, Archiver: sameArchive{&cur}}).Read(context.Background(), env, plugin.Snapshot{}); err != nil { + t.Errorf("unguarded: %v", err) + } +} diff --git a/kinds/openapi/openapi.go b/kinds/openapi/openapi.go index 72aeb8b..460ddd1 100644 --- a/kinds/openapi/openapi.go +++ b/kinds/openapi/openapi.go @@ -45,10 +45,23 @@ type Plugin struct { // spec, not a release removing an API (Elasticsearch removes APIs in a // new minor or major, never in a patch). RemovalsNeedANewVersion bool + + shape *plugin.Shape // the source's, set by RegisterProvider (WithShape); nil: no guard } +// DefaultMinRatio is the shape guard's ratio for a spec: a release that +// keeps fewer than half the operations of the one before is a spec split +// into files, moved or truncated, not an API removing half of itself. +const DefaultMinRatio = 0.5 + func (p Plugin) Name() string { return p.Adapter.API() } +// WithShape is p guarding its pairs with s. +func (p Plugin) WithShape(s plugin.Shape) plugin.Plugin { + p.shape = &s + return p +} + // ListVersions is every release of the spec, oldest first, when the adapter // can list them (adapter.Lister); otherwise only the newest (LatestTag). func (p Plugin) ListVersions(ctx context.Context, _ plugin.Env) ([]plugin.Version, error) { @@ -80,18 +93,25 @@ func (p Plugin) ReadAt(ctx context.Context, _ plugin.Env, v plugin.Version) (plu // Extract diffs two snapshots of the spec into events, with to's version and // from's as previous_version. A zero from is an empty spec before the first. +// A to with far fewer operations than from fails the shape guard +// (plugin.ErrShapeChanged): no removal is read from it. func (p Plugin) Extract(ctx context.Context, env plugin.Env, from, to plugin.Snapshot) (plugin.Result, error) { var oldParsed *diff.Spec + before := -1 if !from.IsZero() { var err error if oldParsed, err = diff.Parse(from.Content); err != nil { return plugin.Result{}, fmt.Errorf("parsing the %s spec at %s: %w", p.Adapter.API(), from.Version.ID, err) } + before = oldParsed.Operations() } newParsed, err := diff.Parse(to.Content) if err != nil { return plugin.Result{}, fmt.Errorf("parsing the %s spec at %s: %w", p.Adapter.API(), to.Version.ID, err) } + if err := p.shape.CheckCount("operations", DefaultMinRatio, before, newParsed.Operations()); err != nil { + return plugin.Result{}, fmt.Errorf("the %s spec at %s: %w", p.Adapter.API(), to.Version.ID, err) + } events, errs := p.events(oldParsed, newParsed, from.Content, to.Content, normalize.Source{ API: p.Adapter.API(), Version: to.Version.ID, @@ -104,7 +124,10 @@ func (p Plugin) Extract(ctx context.Context, env plugin.Env, from, to plugin.Sna return plugin.Result{Events: events, Rejected: errs}, nil } -var _ plugin.Versioned = Plugin{} +var ( + _ plugin.Versioned = Plugin{} + _ plugin.Guarded = Plugin{} +) // events diffs two parsed specs into events, applying Keep, and pointing each // event's source_pointer into the published file when the adapter reshaped it. diff --git a/kinds/openapi/shape_test.go b/kinds/openapi/shape_test.go new file mode 100644 index 0000000..f26b992 --- /dev/null +++ b/kinds/openapi/shape_test.go @@ -0,0 +1,52 @@ +package openapi + +import ( + "context" + "errors" + "fmt" + "strings" + "testing" + "time" + + "github.com/patch-it-dev/patch-it-plugins/core/plugin" +) + +// spec is an OpenAPI document with n operations, GET /things/0 to n-1. +func spec(version string, n int) []byte { + var paths []string + for i := 0; i < n; i++ { + paths = append(paths, fmt.Sprintf(`"/things/%d": {"get": {"operationId": "get%d", "responses": {"200": {"description": "ok"}}}}`, i, i)) + } + return []byte(`{"openapi": "3.0.0", "info": {"version": "` + version + `"}, "paths": {` + strings.Join(paths, ",") + `}}`) +} + +func specPair(fromN, toN int) (plugin.Snapshot, plugin.Snapshot) { + return plugin.Snapshot{Version: plugin.Version{ID: "1"}, Content: spec("1", fromN), SourceURL: "https://x.test/1"}, + plugin.Snapshot{Version: plugin.Version{ID: "2"}, Content: spec("2", toN), SourceURL: "https://x.test/2"} +} + +// A spec that lost most of its operations in one release (split into files, +// moved, truncated) fails the shape guard: no removal is read from it. +func TestASpecThatLostMostOperationsChangedShape(t *testing.T) { + env := plugin.Env{Now: time.Now} + guarded := Plugin{Adapter: fakeAdapter{}}.WithShape(plugin.Shape{}) + from, to := specPair(40, 4) + res, err := guarded.Extract(context.Background(), env, from, to) + if !errors.Is(err, plugin.ErrShapeChanged) || len(res.Events) != 0 { + t.Errorf("40 -> 4 operations: err %v, %d events; want ErrShapeChanged and none", err, len(res.Events)) + } + from, to = specPair(40, 0) + if _, err := guarded.Extract(context.Background(), env, from, to); !errors.Is(err, plugin.ErrShapeChanged) { + t.Errorf("40 -> 0 operations: %v", err) + } + // A release that removes a few is a release. + from, to = specPair(40, 37) + if _, err := guarded.Extract(context.Background(), env, from, to); err != nil { + t.Errorf("40 -> 37 operations: %v", err) + } + // The source's own ratio. + from, to = specPair(40, 4) + if _, err := (Plugin{Adapter: fakeAdapter{}}).WithShape(plugin.Shape{MinRatio: 0.05}).Extract(context.Background(), env, from, to); err != nil { + t.Errorf("with MinRatio 0.05: %v", err) + } +} diff --git a/providers/anthropic/provider.go b/providers/anthropic/provider.go index 85fd37a..fad8b77 100644 --- a/providers/anthropic/provider.go +++ b/providers/anthropic/provider.go @@ -24,7 +24,10 @@ func init() { Watches: "Model deprecations and retirement dates (Messages API models)", URLs: []string{"https://platform.claude.com/docs/en/about-claude/model-deprecations"}, Packages: []string{"pypi:anthropic", "npm:@anthropic-ai/sdk"}, - Plugin: notices.Plugin{Page: Models, Archiver: kit.Wayback{}}, + // Anchors: two retired models in the page's tables, which keep every + // retirement (claude-3-opus-20240229: Jan 5, 2026; claude-2.1: Jul 21, 2025). + Shape: plugin.Shape{Anchors: []plugin.Anchor{{Entry: "claude-3-opus-20240229", Checked: "2026-11-21"}, {Entry: "claude-2.1", Checked: "2026-11-21"}}}, + Plugin: notices.Plugin{Page: Models, Archiver: kit.Wayback{}}, }, { ID: "python-sdk", Layer: plugin.LayerSDK, diff --git a/providers/cloudflare/provider.go b/providers/cloudflare/provider.go index 7871bc3..c5980a9 100644 --- a/providers/cloudflare/provider.go +++ b/providers/cloudflare/provider.go @@ -31,7 +31,10 @@ func init() { Watches: "REST API operations Cloudflare deprecates, breaking on their end-of-life date when it gives one", URLs: []string{"https://developers.cloudflare.com/fundamentals/api/reference/deprecations/index.xml"}, Packages: []string{"pypi:cloudflare", "npm:cloudflare"}, - Plugin: notices.Plugin{Page: API, Archiver: kit.Wayback{}}, + // Anchor: the feed's own title. It keeps the newest 50 announcements, so + // the oldest can leave; the title says the URL still serves this feed. + Shape: plugin.Shape{Anchors: []plugin.Anchor{{Entry: "Changelog | API deprecations", Checked: "2026-11-21"}}}, + Plugin: notices.Plugin{Page: API, Archiver: kit.Wayback{}}, }, changelog.SDK("typescript", Typescript, "npm:cloudflare"), changelog.SDK("python", Python, "pypi:cloudflare"), diff --git a/providers/github/actions_test.go b/providers/github/actions_test.go index 453ccdd..567567f 100644 --- a/providers/github/actions_test.go +++ b/providers/github/actions_test.go @@ -1,11 +1,13 @@ package github import ( + "errors" "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/core/plugin" "github.com/patch-it-dev/patch-it-plugins/kinds/notices/feed" "github.com/patch-it-dev/patch-it-plugins/kinds/notices/noticestest" ) @@ -17,6 +19,27 @@ func TestActionsGolden(t *testing.T) { noticestest.Golden(t, Actions, "testdata/github-changelog-actions.rss.xml") } +// The URL serving another feed (the label renamed or dropped, the changelog's +// main feed served instead) reads fine as a feed: only the anchor, the +// feed's own title, says it isn't the Actions label any more. +func TestActionsAnotherFeedChangedShape(t *testing.T) { + saved := string(kittest.Read(t, "testdata/github-changelog-actions.rss.xml")) + src, _ := plugin.LookupSource(Actions.API) + for name, page := range map[string]string{ + "saved": saved, + "another feed": strings.Replace(saved, "Use Case: actions - GitHub Changelog", "The GitHub Blog", 1), + } { + found, err := Actions.Find([]byte(page)) + if err != nil { + t.Fatal(err) + } + err = src.Source.Shape.CheckAnchors(found.Has) + if changed := errors.Is(err, plugin.ErrShapeChanged); changed != (name != "saved") { + t.Errorf("%s: %v", name, err) + } + } +} + // What the feed's marked entries came to, kept and dropped: the golden files // pin the events, this pins that the unsure ones were dropped, not guessed. func TestActionsUnsureEntriesAreDropped(t *testing.T) { diff --git a/providers/github/provider.go b/providers/github/provider.go index 40ca51d..7836476 100644 --- a/providers/github/provider.go +++ b/providers/github/provider.go @@ -29,7 +29,10 @@ func init() { ID: "actions", Layer: plugin.LayerCI, Watches: "GitHub Actions retirements, such as runner images and the `runs-on` labels they remove", URLs: []string{"https://github.blog/changelog/label/actions/feed/"}, - Plugin: notices.Plugin{Page: Actions, Archiver: kit.Wayback{}}, + // Anchor: the feed's own title. The label's feed keeps its newest 10 posts, + // so no post stays; the title says the URL still serves the Actions label. + Shape: plugin.Shape{Anchors: []plugin.Anchor{{Entry: "Use Case: actions - GitHub Changelog", Checked: "2026-11-21"}}}, + Plugin: notices.Plugin{Page: Actions, Archiver: kit.Wayback{}}, }, { ID: "graphql", Layer: plugin.LayerAPI, diff --git a/providers/google/provider.go b/providers/google/provider.go index f96c633..ca12b9e 100644 --- a/providers/google/provider.go +++ b/providers/google/provider.go @@ -18,21 +18,30 @@ func init() { ID: "vertex-ai-models", Layer: plugin.LayerAIModels, Watches: "Generative AI model deprecations on Vertex AI", URLs: []string{"https://docs.cloud.google.com/feeds/generative-ai-on-vertex-ai-release-notes.xml"}, - Plugin: notices.Plugin{Page: VertexAIModels, Archiver: kit.Wayback{}}, + // Anchor: the feed's own title. A release-notes feed drops its oldest + // entries, so no entry stays; the title says the URL still serves this feed. + Shape: plugin.Shape{Anchors: []plugin.Anchor{{Entry: "Generative AI on Vertex AI - Release notes", Checked: "2026-11-21"}}}, + Plugin: notices.Plugin{Page: VertexAIModels, Archiver: kit.Wayback{}}, }, { ID: "gemini-models", Layer: plugin.LayerAIModels, Watches: "Gemini API model shutdown dates (the earliest Google gives) and their replacements, from Google's own deprecations table", URLs: []string{"https://ai.google.dev/gemini-api/docs/deprecations", "https://aistudio.google.com/docs/deprecations"}, Packages: []string{"pypi:google-genai", "npm:@google/genai"}, - Plugin: notices.Plugin{Page: GeminiModels, Archiver: kit.Wayback{}}, + // Anchors: two shut-down models in the page's tables, which keep past + // shutdowns (gemini-2.0-flash: Jun 1, 2026; embedding-001: Oct 30, 2025). + Shape: plugin.Shape{Anchors: []plugin.Anchor{{Entry: "gemini-2.0-flash", Checked: "2026-11-21"}, {Entry: "embedding-001", Checked: "2026-11-21"}}}, + Plugin: notices.Plugin{Page: GeminiModels, Archiver: kit.Wayback{}}, }, { ID: "vertex-model-retirements", Layer: plugin.LayerAIModels, Watches: "Vertex AI (Gemini Enterprise Agent Platform) model retirement dates and replacements, from Google Cloud's model versions tables", URLs: []string{"https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/model-versions"}, Packages: []string{"pypi:google-genai", "pypi:google-cloud-aiplatform", "npm:@google/genai"}, - Plugin: notices.Plugin{Page: VertexModelRetirements, Archiver: kit.Wayback{}}, + // Anchors: two retired models in the page's tables, which keep past + // retirements (gemini-1.5-pro-002: Sep 24, 2025; text-bison: Apr 21, 2025). + Shape: plugin.Shape{Anchors: []plugin.Anchor{{Entry: "gemini-1.5-pro-002", Checked: "2026-11-21"}, {Entry: "text-bison", Checked: "2026-11-21"}}}, + Plugin: notices.Plugin{Page: VertexModelRetirements, Archiver: kit.Wayback{}}, }, apisurface.PyPI(GenaiPythonSurface, plugin.LayerSDK, "https://github.com/googleapis/python-genai"), apisurface.NPM(GenaiJSSurface, "https://github.com/googleapis/js-genai"), diff --git a/providers/openai/models_read_test.go b/providers/openai/models_read_test.go index 36a3ad8..263756e 100644 --- a/providers/openai/models_read_test.go +++ b/providers/openai/models_read_test.go @@ -2,6 +2,7 @@ package openai import ( "context" + "errors" "fmt" "strings" "testing" @@ -124,19 +125,46 @@ func TestRetirementsStoreNothingWithoutASnapshotThatHoldsThem(t *testing.T) { } } -// A renamed column hides a table: the run must fail, not store a shorter list. -func TestRetirementsRefuseAPageThatLostMostOfItsTables(t *testing.T) { - ctx, s, calls := context.Background(), openStore(t), 0 - withPage(t, deprecations, fakeArchive{content: deprecations, calls: &calls}) - if _, err := retirements(ctx, s, Models); err != nil { - t.Fatal(err) +// A renamed column hides a table: the run must fail with ErrShapeChanged, +// not store a shorter list. And a page that still reads but no longer lists +// an anchor the source declares (provider.go) fails the same way. +func TestRetirementsRefuseAPageThatChangedShape(t *testing.T) { + page := string(read(t, "openai-deprecations.md")) + for name, changed := range map[string]string{ + "a renamed column hides the past table": strings.Replace(page, "Listed replacement", "Successor", 1), + "an anchor is gone": strings.Replace(page, "`gpt-3.5-turbo-0301`", "`gpt-3.5-turbo-0302`", 1), + } { + ctx, s, calls := context.Background(), openStore(t), 0 + withPage(t, page, fakeArchive{content: page, calls: &calls}) + if _, err := registeredRetirements(ctx, t, s); err != nil { + t.Fatal(err) + } + first, _ := s.All() + withPage(t, changed, fakeArchive{content: changed, calls: &calls}) + if _, err := registeredRetirements(ctx, t, s); !errors.Is(err, plugin.ErrShapeChanged) { + t.Errorf("%s: want ErrShapeChanged, got %v", name, err) + } + if events, _ := s.All(); len(events) != len(first) { + t.Errorf("%s: %d events, want only the first read's %d", name, len(events), len(first)) + } + } +} + +// registeredRetirements is retirements with the plugin as registered: the +// shape guard on, with the source's anchors. +func registeredRetirements(ctx context.Context, t *testing.T, s *store) (bool, error) { + src, ok := plugin.LookupSource("openai/models") + if !ok { + t.Fatal("openai/models isn't registered") } - renamed := strings.Replace(deprecations, "Substitute model", "Successor", 1) + strings.Replace(strings.Replace(deprecations, "gpt-4-0613` \\| `gpt-4", "gpt-4o-old", 1), "Substitute model", "Recommended replacement", 1) - withPage(t, renamed, fakeArchive{content: renamed, calls: &calls}) - if _, err := retirements(ctx, s, Models); err == nil || !strings.Contains(err.Error(), "shape may have changed") { - t.Fatalf("want the shape error, got %v", err) + env := plugin.Env{ + Get: func(context.Context, string) ([]byte, error) { return []byte(current.live), nil }, + Now: time.Now, } - if events, _ := s.All(); len(events) != 2 { - t.Errorf("%d events, want only the first run's 2", len(events)) + p := notices.Plugin{Page: Models, Archiver: current.archive}.WithShape(src.Source.Shape).(plugin.Living) + kept, rejected, err := kittest.ReadPage(ctx, env, s.Mem, p, s.kept) + if err == nil { + s.kept = kept } + return rejected, err } diff --git a/providers/openai/provider.go b/providers/openai/provider.go index 92d6832..cd0fed3 100644 --- a/providers/openai/provider.go +++ b/providers/openai/provider.go @@ -29,7 +29,10 @@ func init() { Watches: "Model deprecations and shutdown dates (Chat Completions and Responses text models)", URLs: []string{"https://developers.openai.com/api/docs/deprecations"}, Packages: []string{"pypi:openai", "npm:openai"}, - Plugin: notices.Plugin{Page: Models, Archiver: kit.Wayback{}}, + // Anchors: two models in the page's "Past deprecations" table, which keeps + // every shutdown (gpt-4-0613: Oct 23, 2026; gpt-3.5-turbo-0301: Sep 13, 2024). + Shape: plugin.Shape{Anchors: []plugin.Anchor{{Entry: "gpt-4-0613", Checked: "2026-11-21"}, {Entry: "gpt-3.5-turbo-0301", Checked: "2026-11-21"}}}, + Plugin: notices.Plugin{Page: Models, Archiver: kit.Wayback{}}, }, apisurface.PyPI(PythonSurface, plugin.LayerSDK, "https://github.com/openai/openai-python"), apisurface.NPM(NodeSurface, "https://github.com/openai/openai-node"), diff --git a/providers/salesforce/provider.go b/providers/salesforce/provider.go index 4b7b7ab..48e3c92 100644 --- a/providers/salesforce/provider.go +++ b/providers/salesforce/provider.go @@ -18,7 +18,12 @@ func init() { ID: "rest-api", Layer: plugin.LayerAPI, Watches: "REST API version ranges deprecated and retired, from Salesforce's own API end-of-life policy page", URLs: []string{"https://developer.salesforce.com/docs/platform/api-rest/guide/api-rest-eol.html"}, - Plugin: notices.Plugin{Page: RESTAPI, Archiver: kit.Wayback{}}, + // Anchors: two retired versions, from the table's "Versions 7.0 through + // 20.0" and "Versions 21.0 through 30.0" rows. The live page answers 403, + // so checked on the Wayback Machine's capture of 2026-11-20, what the + // plugin itself reads when it is blocked (ArchiveWhenBlocked). + Shape: plugin.Shape{Anchors: []plugin.Anchor{{Entry: "20.0", Checked: "2026-11-21"}, {Entry: "30.0", Checked: "2026-11-21"}}}, + Plugin: notices.Plugin{Page: RESTAPI, Archiver: kit.Wayback{}}, }, }, }) diff --git a/providers/salesforce/rest_api_test.go b/providers/salesforce/rest_api_test.go index 45a634c..841a7d6 100644 --- a/providers/salesforce/rest_api_test.go +++ b/providers/salesforce/rest_api_test.go @@ -30,7 +30,9 @@ func TestEOLRegistersItself(t *testing.T) { func TestEOLGolden(t *testing.T) { saved := kittest.Pages{RESTAPI.URL: "testdata/salesforce-api-rest-eol-2026-10-31.html"} archive := &kittest.Archive{T: t, Pages: saved} - got := kittest.Page(t, kittest.Env(t, saved), notices.Plugin{Page: RESTAPI, Archiver: archive}) + src, _ := plugin.LookupSource(RESTAPI.API) + p := notices.Plugin{Page: RESTAPI, Archiver: archive}.WithShape(src.Source.Shape).(plugin.Living) // its anchors on the saved page too + got := kittest.Page(t, kittest.Env(t, saved), p) if archive.Calls != 1 { t.Errorf("%d snapshots, want 1: the second read's page is unchanged", archive.Calls) } From 0fa55cfe8826064702253dd4b5d5ef0821802179 Mon Sep 17 00:00:00 2001 From: adssib <75389300+adssib@users.noreply.github.com> Date: Sat, 21 Nov 2026 15:16:58 -0500 Subject: [PATCH 2/2] anchors on the provider pages; count the more numerous release headings; when a drop is real Co-Authored-By: Claude Opus 5.5 Signed-off-by: adssib <75389300+adssib@users.noreply.github.com> --- docs/writing-a-plugin.md | 2 ++ kinds/changelog/parse.go | 10 ++++------ providers/anthropic/README.md | 1 + providers/cloudflare/README.md | 1 + providers/github/README.md | 1 + providers/google/README.md | 3 +++ providers/openai/README.md | 1 + providers/salesforce/README.md | 1 + 8 files changed, 14 insertions(+), 6 deletions(-) diff --git a/docs/writing-a-plugin.md b/docs/writing-a-plugin.md index 2cac215..f66218d 100644 --- a/docs/writing-a-plugin.md +++ b/docs/writing-a-plugin.md @@ -202,6 +202,8 @@ The source's `Shape` (on its `plugin.Source`) holds its anchors and any ratio or }, ``` +**When a drop is real** (a vendor really trims its changelog at a new major, or really splits its spec), the source fails on every run until someone decides, and the hosted ingestion service opens an issue here. Look first for where the rest went: a moved or split source is a new URL or a second source, not a smaller one. Only when the source really is smaller now, set that source's `MinRatio` low enough to pass, with a comment saying what dropped, when, and why it's real. + `RegisterProvider` hands each plugin its source's `Shape` (`plugin.Guarded.WithShape`) and refuses a plugin that doesn't take one: a new kind implements `WithShape` and calls `Shape.CheckCount` (and, for a living page, `Shape.CheckAnchors`) before it reads a single change. A plugin built by hand in a test isn't guarded unless the test gives it a `Shape`: golden tests read trimmed copies, far smaller than the real releases, so a test of the guard calls `WithShape` itself (each kind has one with a redesigned or shrunken input). ### Fetching: `env.Get` and `core/kit/` diff --git a/kinds/changelog/parse.go b/kinds/changelog/parse.go index 3391687..ef55774 100644 --- a/kinds/changelog/parse.go +++ b/kinds/changelog/parse.go @@ -120,8 +120,9 @@ func sections(body []string, rst bool, heading *regexp.Regexp) []Section { return out } -// Releases is how many releases a changelog file heads: Markdown release -// headings, or else reStructuredText release titles. What the shape guard +// Releases is how many releases a changelog file heads: its Markdown +// release headings or its reStructuredText release titles, whichever it has +// more of (a stray "# 1 …" line in an RST file doesn't make it count 1). What the shape guard // counts: a changelog keeps every past release, so a file that heads far // fewer than at the release before was moved, split or reformatted. func Releases(file []byte) int { @@ -138,10 +139,7 @@ func Releases(file []byte) int { } } } - if md > 0 { - return md - } - return rst + return max(md, rst) } // releaseLines are release's heading and the lines under it, up to the next diff --git a/providers/anthropic/README.md b/providers/anthropic/README.md index 7bfe44f..3eb57c8 100644 --- a/providers/anthropic/README.md +++ b/providers/anthropic/README.md @@ -48,6 +48,7 @@ Kind: `notices` (`kinds/notices`), reading with the deprecations-page reader, `k - **Why this one:** it's Anthropic's own deprecation history, one table per announcement (retirement date, deprecated model, recommended replacement), served as markdown. `robots.txt` disallows only `/api/`. - **Alternatives considered:** the models API (`GET /v1/models`: what exists now, no dates); release notes and emails (not a complete list); the old docs.anthropic.com URL (redirects here). - **Quote:** "| November 30, 2026 | `claude-sonnet-4-5-20250929` | `claude-sonnet-5-5` |" (Deprecation history, 2026-09-30: Claude Sonnet 4.5 model). +- **Anchors** (checked 2026-11-21, declared in `provider.go`): `claude-3-opus-20240229` and `claude-2.1`, two retired models the page keeps. A read without them fails as a change of layout, never as nothing new. ### How the provider announces changes diff --git a/providers/cloudflare/README.md b/providers/cloudflare/README.md index 9988127..75c7d92 100644 --- a/providers/cloudflare/README.md +++ b/providers/cloudflare/README.md @@ -26,6 +26,7 @@ Kind: `notices` (`kinds/notices`), with the feed reader (`kinds/notices/feed`) a - **The [changelog](https://developers.cloudflare.com/changelog/) feed.** It covers every product, mostly announcements; the deprecations page is its API part. - **The SDKs** (`cloudflare` on PyPI and npm). They're generated from the spec. The Python SDK's `CHANGELOG.md` lists SDK-level breaking changes (removed methods and types), which is a different subject. - **Quote:** "End of life date: September 27, 2026" and "After this date, the legacy endpoints will no longer be available." (Legacy Registrar Domain Management API) +- **Anchors** (checked 2026-11-21, declared in `provider.go`): the feed's own title, "Changelog | API deprecations" (its oldest of 50 entries can roll off). A read without them fails as a change of layout, never as nothing new. ### How the provider announces changes diff --git a/providers/github/README.md b/providers/github/README.md index 99969bf..d97c7fa 100644 --- a/providers/github/README.md +++ b/providers/github/README.md @@ -48,6 +48,7 @@ Kind: `notices` (`kinds/notices`), with the feed reader (`kinds/notices/feed`) a - **Why this one:** it's GitHub's own changelog feed, built to be machine-read, with labels (`Retired`) as RSS categories. Retirement posts list the affected labels in a fixed shape and give the date. - **Alternatives considered:** the [actions/runner-images](https://github.com/actions/runner-images) repo's announcement issues (detailed, but issue text varies and they're not a feed); the full GitHub changelog feed (every product, much noisier); the runner images README (says what exists now, not when it goes). - **Quote:** "The macOS 14 runner image will be retired on November 2, 2026." +- **Anchors** (checked 2026-11-21, declared in `provider.go`): the feed's own title, "Use Case: actions - GitHub Changelog" (its 10 posts roll off). A read without them fails as a change of layout, never as nothing new. ### How the provider announces changes diff --git a/providers/google/README.md b/providers/google/README.md index 89e4353..213e238 100644 --- a/providers/google/README.md +++ b/providers/google/README.md @@ -19,6 +19,7 @@ Kind: `notices` (`kinds/notices`), with the deprecations-table reader (`kinds/no - **Vertex AI's model versions page** (`google/vertex-model-retirements`): the same models on Google Cloud, with Google Cloud's own retirement dates, which differ from the Gemini API's (gemini-2.5-pro: 2026-10-20 on Vertex AI, 2026-12-01 here). A separate source: a repo reaches one or the other. - **The Gemini API's models list** (`GET /v1beta/models`): what's served now, with no dates. - **Quote:** "| `gemini-2.0-flash` | February 5, 2025 | June 1, 2026 | `gemini-3.6-flash` |" (Gemini 2.0 models, Deprecated models), and above the tables: "The shutdown dates listed in the table indicate the earliest possible dates on which a model might be retired". +- **Anchors** (checked 2026-11-21, declared in `provider.go`): `gemini-2.0-flash` and `embedding-001`, two shut-down models the page keeps. A read without them fails as a change of layout, never as nothing new. ### How the provider announces changes @@ -128,6 +129,7 @@ Kind: `notices` (`kinds/notices`), with the deprecations-table reader (`kinds/no - **The deprecations page** (`docs.cloud.google.com/vertex-ai/generative-ai/docs/deprecations`): SDK modules and features, not model dates. - **The Gemini API deprecations page** (`google/gemini-models`): the Gemini API's own dates, which differ. - **Quote:** "| `veo-3.0-generate-001` | July 29, 2025 | June 30, 2026 | `veo-3.1-generate-001` |" (Retired models). +- **Anchors** (checked 2026-11-21, declared in `provider.go`): `gemini-1.5-pro-002` and `text-bison`, two retired models the page keeps. A read without them fails as a change of layout, never as nothing new. ### How the provider announces changes @@ -158,6 +160,7 @@ Kind: `notices` (`kinds/notices`), with the feed reader (`kinds/notices/feed`) a - **Why this one:** it's Google's own release notes as a feed, one entry per day, each change under a heading naming its kind (`Deprecated`), and deprecations come with a table of discontinued endpoints and replacements. - **Alternatives considered:** the model versions and lifecycle docs page (HTML, rewritten in place, no history); the Google Cloud deprecations page (all of Cloud, prose); the models list API (what exists now, not when it stops). - **Quote:** "We recommend updating your model endpoints before June 30, 2026, to avoid service disruption." (Deprecated: Imagen generation GA endpoints deprecation). +- **Anchors** (checked 2026-11-21, declared in `provider.go`): the feed's own title, "Generative AI on Vertex AI - Release notes" (its entries roll off). A read without them fails as a change of layout, never as nothing new. ### How the provider announces changes diff --git a/providers/openai/README.md b/providers/openai/README.md index 21b9aa2..814fc2c 100644 --- a/providers/openai/README.md +++ b/providers/openai/README.md @@ -61,6 +61,7 @@ Kind: `notices` (`kinds/notices`), reading with the deprecations-page reader, `k - **Why this one:** it's OpenAI's own list of every deprecation: a table of upcoming shutdowns and one of past ones, each row a shutdown date, the models, a status, the recommended replacement and the notice date. The markdown version is machine-readable without scraping HTML. `robots.txt` allows it. - **Alternatives considered:** the models list API (`GET /v1/models`: says what exists now, not when it stops); OpenAI's blog and email notices (announce only some changes, no table); the old `platform.openai.com/docs/deprecations` URL (redirects here). - **Quote:** "| **Dec 11, 2026** | `gpt-5`, `gpt-5-2025-08-07` | Deprecated | `gpt-6.1-sol` | Jun 11, 2026 |" ("Upcoming deprecations", 2026-11-21). +- **Anchors** (checked 2026-11-21, declared in `provider.go`): `gpt-4-0613` and `gpt-3.5-turbo-0301`, two models in the "Past deprecations" table. A read without them fails as a change of layout, never as nothing new. ### How the provider announces changes diff --git a/providers/salesforce/README.md b/providers/salesforce/README.md index 717c955..d95e9fb 100644 --- a/providers/salesforce/README.md +++ b/providers/salesforce/README.md @@ -21,6 +21,7 @@ Kind: `notices` (`kinds/notices`), with the end-of-life reader (`kinds/notices/e - **The docs site's JSON content API** (`https://developer.salesforce.com/docs/get_document_content/api_rest/api_rest_eol.htm/en-us/`, the older "atlas" REST API Developer Guide; `get_document/atlas.en-us.api_rest.meta` names the newest doc version). It answers a plain GET (checked 2026-11-21), but it lags the live page: its newest version, 262.0 (Summer '26), lists versions 31.0 through 66.0 as supported and has no row for the 31.0–40.0 deprecation the live page announces, so it would miss exactly what this source is for. - **The retirement-detail sub-pages** the main table links to (e.g. "Salesforce Platform API Versions 31.0 through 40.0 Retirement"), each its own Salesforce Help article. The main page already states the same range, status and season; reading only it keeps one source of truth and one snapshot per run. - **Quote:** "As of Summer ’25, these versions are retired and unavailable." (versions 21.0 through 30.0, a real, already-happened retirement) +- **Anchors** (checked 2026-11-21, declared in `provider.go`): versions `20.0` and `30.0`, two retired version ranges' rows (checked on the Wayback Machine's capture of 2026-11-20: the live page answers 403). A read without them fails as a change of layout, never as nothing new. ### How the provider announces changes