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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ The table between the `plugins:start` and `plugins:end` markers is also publishe
| [`urllib3`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/urllib3.md) | urllib3 | Removals and deprecations in release 2.0.0 | `changelog` | [urllib3/urllib3 CHANGES.rst](https://github.com/urllib3/urllib3/blob/2.0.0/CHANGES.rst) | live |
| [`github-actions`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/github-actions.md) | GitHub | GitHub Actions retirements, such as runner images and the `runs-on` labels they remove | `feed` | [GitHub changelog, Actions label (RSS)](https://github.blog/changelog/label/actions/feed/) | live |
| [`vertex-ai-models`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/vertex-ai-models.md) | Google | Generative AI model deprecations on Vertex AI | `feed` | [Vertex AI generative AI release notes (Atom)](https://docs.cloud.google.com/feeds/generative-ai-on-vertex-ai-release-notes.xml) | live |
| [`redis`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/redis.md) | Redis | Commands removed entirely from Redis's own command catalog between two snapshots | `catalog` | [redis/redis-doc `commands.json`](https://github.com/redis/redis-doc/blob/master/commands.json) | live |
| [`cloudflare`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/cloudflare.md) | Cloudflare | REST API operations Cloudflare deprecates, breaking on their end-of-life date when it gives one | `feed` | [Cloudflare API deprecations (RSS)](https://developers.cloudflare.com/fundamentals/api/reference/deprecations/index.xml) | paused: merged, not in a tagged release yet, so patch-it's hosted ingestion service doesn't run it |
<!-- plugins:end -->

Expand All @@ -37,7 +38,7 @@ The table between the `plugins:start` and `plugins:end` markers is also publishe
| Plugin | The id you pass as `--api` and the `api` field on every event it emits. Lowercase, unique. |
| Provider | Whose API, SDK or package it is. |
| What it watches | The kind of change it reports, in a few words. |
| Format plugin | Which shared reader it is built on: `openapi` (a spec per release, diffed), `retirements` (a deprecations page), `migrationguide` (an SDK's migration guide), `removedmembers` (a package's table of removed members), `changelog` (a release changelog file), `feed` (an RSS or Atom feed), `apichangelog` (a vendor's machine-readable API changelog, in JSON). |
| Format plugin | Which shared reader it is built on: `openapi` (a spec per release, diffed), `retirements` (a deprecations page), `migrationguide` (an SDK's migration guide), `removedmembers` (a package's table of removed members), `changelog` (a release changelog file), `feed` (an RSS or Atom feed), `catalog` (a structured JSON catalog of names, diffed between two snapshots). |
| Source | The provider's own public page or file the plugin reads. Every event links back to it. |
| Status | `live`: runs every day in patch-it's hosted service. `planned`: accepted, not written yet. `paused`: registered but not run, with the reason in the row. |

Expand Down
1 change: 1 addition & 0 deletions docs/writing-a-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Never scrape what the provider's `robots.txt` or terms disallow, and never read
| `plugins/removedmembers` | A package's table of removed members at a release tag | A `removedmembers.Guide` |
| `plugins/changelog` | A `CHANGELOG.md` / `CHANGES.rst` / `HISTORY.rst` at a release tag | A `changelog.File` |
| `plugins/feed` | An RSS or Atom feed | A `feed.Feed` with a reader for that vendor's entries |
| `plugins/catalog` | A flat JSON catalog, one entry per name, with no release tags to pin — a commit SHA stands in | A `catalog.Catalog`, diffed between two snapshots for names that disappeared entirely |
| `plugins/apichangelog` | A vendor's machine-readable API changelog in JSON (per day, endpoint and API version, oasdiff change codes), at the commit that last changed it | An `apichangelog.Log` |

## 3. The interface
Expand Down
1 change: 1 addition & 0 deletions plugins/all/all.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Package all imports every plugin, so each registers itself: a program that
// runs plugins imports this one package. A new plugin package is added here
// (TestEveryPluginIsImported fails until it is).
package all

import (
_ "github.com/patch-it-dev/patch-it-plugins/plugins/catalog"
_ "github.com/patch-it-dev/patch-it-plugins/plugins/apichangelog"
_ "github.com/patch-it-dev/patch-it-plugins/plugins/changelog"
_ "github.com/patch-it-dev/patch-it-plugins/plugins/feed"
Expand Down
228 changes: 228 additions & 0 deletions plugins/catalog/catalog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
// Package catalog is the source plugin for a provider that publishes its
// whole command or endpoint surface as one structured JSON file, one entry
// keyed by name: fetch the newest snapshot, diff it against the last one
// seen (or two given snapshots, to replay a historical change), and report
// every name that disappeared entirely between them. Unlike openapi's typed
// spec, an entry here is opaque: no request or response shape to walk, just
// whether the name is still there. Redis first: its command surface has no
// OpenAPI spec, but redis-doc's commands.json is the real, machine-readable
// file redis.io's own command reference is generated from.
//
// Precision over recall: a name that moves to a different key (a genuine
// rename) reads as one removal and one addition, same as any other. This
// never guesses a rename from two disappearances and appearances landing in
// the same diff; it only ever reports what's gone.
package catalog

import (
"context"
"encoding/json"
"fmt"
"log"
"sort"
"time"

"github.com/patch-it-dev/patch-it-plugins/event"
"github.com/patch-it-dev/patch-it-plugins/plugin"
)

func init() {
plugin.Register(Plugin{Catalog: Redis})
}

// Catalog is one provider's command or endpoint catalog: a single JSON
// object, one key per entry, fetched at a git ref.
type Catalog struct {
API string // the events' api: "redis"
Ecosystem string // the package_release subject's ecosystem: "redis"
Package string // the package_release subject's package: "redis"
Repo string // owner/name on GitHub the catalog lives in
Path string // the catalog's path in the repo
RefsURL string // GitHub's commits API, for the newest ref: .../commits/<branch>
}

// Redis is redis-doc's commands.json, regenerated from each real Redis
// release and read by redis.io's own command reference (checked 2026-11-18).
// The repo has no tags, so a ref here is a commit SHA, not a release.
var Redis = Catalog{
API: "redis", Ecosystem: "redis", Package: "redis",
Repo: "redis/redis-doc", Path: "commands.json",
RefsURL: "https://api.github.com/repos/redis/redis-doc/commits/master",
}

// URL is the catalog as it was at ref: its own provenance.
func (c Catalog) URL(ref string) string {
return fmt.Sprintf("https://raw.githubusercontent.com/%s/%s/%s", c.Repo, ref, c.Path)
}

// parse reads the catalog as a flat map of name to its raw entry: every
// field of an entry (arity, complexity, ACL categories...) is unread, except
// where an entry's own bytes become an event's excerpt.
func parse(data []byte) (map[string]json.RawMessage, error) {
var out map[string]json.RawMessage
if err := json.Unmarshal(data, &out); err != nil {
return nil, fmt.Errorf("parsing catalog: %w", err)
}
return out, nil
}

// removed is every name of old that new doesn't have, sorted so the result
// (and the fingerprints built from it) don't depend on map order.
func removed(old, new map[string]json.RawMessage) []string {
var out []string
for name := range old {
if _, ok := new[name]; !ok {
out = append(out, name)
}
}
sort.Strings(out)
return out
}

// Plugin reads one catalog.
type Plugin struct {
Catalog Catalog
}

func (p Plugin) Name() string { return p.Catalog.API }

// Run diffs the newest snapshot against whatever was last stored.
func (p Plugin) Run(ctx context.Context, env plugin.Env) (plugin.Result, error) {
c := p.Catalog
ref, err := p.latestRef(ctx, env)
if err != nil {
return plugin.Result{}, err
}
newContent, err := env.Get(ctx, c.URL(ref))
if err != nil {
return plugin.Result{}, fmt.Errorf("fetching %s: %w", c.URL(ref), err)
}
last, err := env.Baselines.LastSpec(c.API)
if err != nil {
return plugin.Result{}, fmt.Errorf("loading last catalog: %w", err)
}
if last != nil && last.SHA256 == plugin.SHA256(newContent) {
log.Printf("%s: no change (%s)", c.API, ref)
return plugin.Result{}, nil
}

var oldContent []byte
var from string
if last != nil {
oldContent, from = last.Content, last.Tag
}
now := env.Now()
events, rejected, err := p.events(oldContent, newContent, from, ref, now)
if err != nil {
return plugin.Result{}, err
}
return plugin.Result{
Label: ref,
Events: events,
Rejected: rejected,
Baselines: []plugin.Spec{plugin.Baseline(c.API, ref, ref, c.URL(ref), newContent, false, now)},
}, nil
}

// Replay diffs two given snapshots. Both are saved marked as replays, so the
// normal-run baseline never moves; the events are stored like any others.
func (p Plugin) Replay(ctx context.Context, env plugin.Env, from, to string) (plugin.Result, error) {
c := p.Catalog
oldContent, err := env.Get(ctx, c.URL(from))
if err != nil {
return plugin.Result{}, fmt.Errorf("fetching %s: %w", c.URL(from), err)
}
newContent, err := env.Get(ctx, c.URL(to))
if err != nil {
return plugin.Result{}, fmt.Errorf("fetching %s: %w", c.URL(to), err)
}
now := env.Now()
events, rejected, err := p.events(oldContent, newContent, from, to, now)
if err != nil {
return plugin.Result{}, err
}
return plugin.Result{
Label: to,
Events: events,
Rejected: rejected,
Baselines: []plugin.Spec{
plugin.Baseline(c.API, from, from, c.URL(from), oldContent, true, now),
plugin.Baseline(c.API, to, to, c.URL(to), newContent, true, now),
},
}, nil
}

// latestRef asks GitHub for the catalog repo's newest commit.
func (p Plugin) latestRef(ctx context.Context, env plugin.Env) (string, error) {
body, err := env.Get(ctx, p.Catalog.RefsURL)
if err != nil {
return "", fmt.Errorf("looking up the newest commit: %w", err)
}
var commit struct {
SHA string `json:"sha"`
}
if err := json.Unmarshal(body, &commit); err != nil {
return "", fmt.Errorf("parsing the commit lookup: %w", err)
}
if commit.SHA == "" {
return "", fmt.Errorf("the commit lookup named no sha")
}
return commit.SHA, nil
}

// events diffs two parsed snapshots into events. oldContent is empty on a
// plugin's first run (no baseline yet): diffing against no snapshot reports
// nothing, the same as an unchanged one.
func (p Plugin) events(oldContent, newContent []byte, from, to string, now time.Time) ([]event.EventV2, []error, error) {
c := p.Catalog
newEntries, err := parse(newContent)
if err != nil {
return nil, nil, fmt.Errorf("parsing %s: %w", c.URL(to), err)
}
var oldEntries map[string]json.RawMessage
if len(oldContent) > 0 {
oldEntries, err = parse(oldContent)
if err != nil {
return nil, nil, fmt.Errorf("parsing %s: %w", c.URL(from), err)
}
}

var events []event.EventV2
var rejected []error
for _, name := range removed(oldEntries, newEntries) {
subject := event.Subject{
Type: event.SubjectPackageRelease, Ecosystem: c.Ecosystem, Package: c.Package,
Change: event.PackageRemovedSymbol, Symbols: []string{name},
}
e := event.EventV2{
API: c.API, Version: to, PreviousVersion: from,
ChangeType: event.ChangeTypeBreaking,
Breaking: true,
Subject: subject,
Description: fmt.Sprintf("%s no longer exists: calling it now fails.", name),
SourceURL: c.URL(from),
SourceExcerpt: excerpt(name, oldEntries[name]),
Confidence: 1.0,
DetectedAt: now,
}
e.Fingerprint = event.FingerprintV2(e.API, e.Version, e.ChangeType, subject, "")
if err := e.Validate(); err != nil {
rejected = append(rejected, fmt.Errorf("%s: %w", name, err))
continue
}
events = append(events, e)
}
return events, rejected, nil
}

// excerpt quotes the entry exactly as the old snapshot had it: the evidence
// that name existed, in the catalog's own shape. Capped at the contract's
// 2000-character limit, the entry's closing braces never cut off: nested
// command-line arguments can run long.
func excerpt(name string, raw json.RawMessage) string {
s := fmt.Sprintf("%q: %s", name, string(raw))
if r := []rune(s); len(r) > 2000 {
s = string(r[:1999]) + "…"
}
return s
}
116 changes: 116 additions & 0 deletions plugins/catalog/catalog_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package catalog

import (
"context"
"testing"
"time"

"github.com/patch-it-dev/patch-it-plugins/event"
"github.com/patch-it-dev/patch-it-plugins/kit/kittest"
"github.com/patch-it-dev/patch-it-plugins/plugin"
)

// The two commits redis-doc's own history shows the removal happen between:
// PR #1697 dropped FUNCTION CREATE and FUNCTION INFO from commands.json on
// 2022-01-24 (checked 2026-11-18), replacing the single-function CREATE with
// a whole-library LOAD. Neither command ever reached a tagged Redis release
// (not even 7.0's first release candidate, which shipped a week later with
// neither in its own src/commands/): a real removal, but one that happened
// before any user could depend on it, not a production break.
const (
oldRef = "cc0427b3c3671e90b92f1ad2fe4e835fd32cd3c9"
newRef = "06f3598f39c7ca86dbdb0aa1668cfdd1b82b908d"
)

func env(s *kittest.Mem, pages kittest.Pages, t *testing.T) plugin.Env {
return plugin.Env{Baselines: s, Get: pages.Get(t), Now: time.Now}
}

func fixturePages() kittest.Pages {
return kittest.Pages{
Redis.URL(oldRef): "testdata/redis-doc-cc0427b.json",
Redis.URL(newRef): "testdata/redis-doc-06f3598.json",
}
}

// The golden test and the replay fixture in one: testdata/redis-doc-cc0427b.json
// and redis-doc-06f3598.json are real, trimmed excerpts of redis-doc's
// commands.json at those two commits (checked 2026-11-18). Between them,
// FUNCTION CREATE and FUNCTION INFO disappear, FUNCTION LOAD appears, and GET
// (an unrelated, long-lived command) is unchanged. This is the pair the
// plugin's Replay from oldRef to newRef recreates.
func TestReplayRecreatesTheRealFunctionCommandRemoval(t *testing.T) {
ctx := context.Background()
s := kittest.NewMem()
e := env(s, fixturePages(), t)

rejected, err := kittest.Replay(ctx, e, s, Plugin{Catalog: Redis}, oldRef, newRef)
if err != nil || rejected {
t.Fatalf("replay: rejected=%v err=%v", rejected, err)
}

events, err := s.All()
if err != nil {
t.Fatalf("reading events: %v", err)
}
// Precision over recall: GET (unchanged) and FUNCTION LOAD (added, not
// removed) must produce nothing. Only the two real removals should.
got := map[string]bool{}
for _, ev := range events {
if len(ev.Subject.Symbols) != 1 {
t.Fatalf("event with %d symbols, want exactly 1: %+v", len(ev.Subject.Symbols), ev)
}
got[ev.Subject.Symbols[0]] = true
}
want := map[string]bool{"FUNCTION CREATE": true, "FUNCTION INFO": true}
if len(got) != len(want) {
t.Fatalf("stored %v, want exactly %v (GET and FUNCTION LOAD must drop silently)", got, want)
}
for name := range want {
if !got[name] {
t.Errorf("missing an event for %s", name)
}
}

// Acceptance criteria: every event carries source_url and a non-empty
// source_excerpt, is marked breaking, and is placed on the real refs.
for _, ev := range events {
if ev.API != "redis" || ev.Version != newRef || ev.PreviousVersion != oldRef {
t.Errorf("event %v: api=%s version=%s previous_version=%s, want redis %s from %s",
ev.Subject.Symbols, ev.API, ev.Version, ev.PreviousVersion, newRef, oldRef)
}
if ev.ChangeType != event.ChangeTypeBreaking || !ev.Breaking {
t.Errorf("event %v: change_type=%s breaking=%v, want breaking", ev.Subject.Symbols, ev.ChangeType, ev.Breaking)
}
if ev.SourceURL != Redis.URL(oldRef) {
t.Errorf("event %v: source_url=%s, want the old snapshot, where the removed command is still evidenced", ev.Subject.Symbols, ev.SourceURL)
}
if ev.SourceExcerpt == "" {
t.Errorf("event %v: missing source_excerpt", ev.Subject.Symbols)
}
}

// Replaying the same pair again must not duplicate the events.
if _, err := kittest.Replay(ctx, e, s, Plugin{Catalog: Redis}, oldRef, newRef); err != nil {
t.Fatalf("second replay: %v", err)
}
if again, _ := s.All(); len(again) != len(events) {
t.Errorf("repeating the replay added events: %d -> %d", len(events), len(again))
}
}

// Run's own path: looking up the newest commit, then diffing it against
// whatever was last stored. A first run has no baseline to diff against, so
// it reports nothing (same as an unchanged one) and just saves one.
// kittest.Ingest reruns this, so a second run that found anything new would
// fail it too.
func TestRunFindsNothingOnAFirstRunAndStaysQuietOnARerun(t *testing.T) {
pages := kittest.Pages{
Redis.RefsURL: "testdata/commits-master.json",
Redis.URL(newRef): "testdata/redis-doc-06f3598.json",
}
events := kittest.Ingest(t, Plugin{Catalog: Redis}, pages)
if len(events) != 0 {
t.Errorf("first run found %d events, want 0: there is nothing yet to diff against", len(events))
}
}
11 changes: 11 additions & 0 deletions plugins/catalog/registered_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package catalog

import (
"testing"

"github.com/patch-it-dev/patch-it-plugins/kit/kittest"
)

func TestRegistersItself(t *testing.T) {
kittest.Registered(t, Plugin{Catalog: Redis})
}
Loading
Loading