diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 173764d..30b6631 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -11,7 +11,7 @@ - [ ] One pinned drop test: a realistic input that produces no event - [ ] `providers/.md` written or updated from `providers/_template.md`, including **Why this source** - [ ] Fetches only through `env.Get` / `kit/` -- [ ] `go build ./... && go vet ./... && gofmt -l . && go test -race ./...` pass locally +- [ ] `make check` passes locally (and `make plugins-json` was run if a plugin or its row changed) - [ ] Nothing private: no credentials, internal hosts, private links, customer names ## Notes for the reviewer diff --git a/.github/workflows/CI_go.yml b/.github/workflows/CI_go.yml index 195f7b3..2321c5b 100644 --- a/.github/workflows/CI_go.yml +++ b/.github/workflows/CI_go.yml @@ -2,6 +2,7 @@ # detector. Two guards keep plugins self-contained: # - imports: only this module, the standard library and the approved dependencies; # - network: net/http only in the fetch layer (fetch/, kit/, adapter/). +# The steps are Makefile targets, so `make check` runs exactly this locally. # Until the Go code lands there is no go.mod, and every step after the first is skipped # with a notice, so the check passes. name: CI_go @@ -43,57 +44,38 @@ jobs: go-version-file: go.mod cache-dependency-path: go.sum + # Each step is a Makefile target; `make check` runs the same ones (plus + # the internal-names check) locally. - name: go.mod and go.sum are tidy if: steps.go.outputs.present == 'true' - run: | - go mod tidy - if ! git diff --exit-code -- go.mod go.sum; then - echo "::error file=go.mod::go.mod/go.sum are not tidy. Run 'go mod tidy' and commit the result." - exit 1 - fi + run: make tidy - name: go build if: steps.go.outputs.present == 'true' - run: go build ./... + run: make build - name: gofmt if: steps.go.outputs.present == 'true' - run: | - unformatted=$(gofmt -l .) - if [ -n "$unformatted" ]; then - for f in $unformatted; do echo "::error file=$f::not gofmt-formatted. Run 'gofmt -w .'."; done - exit 1 - fi + run: make fmt - name: go vet if: steps.go.outputs.present == 'true' - run: go vet ./... + run: make vet - # An allowlist, so a plugin can't pull in a database driver, a cloud SDK or - # anything private. Adding a dependency means adding it here, in review. + # An allowlist (ALLOWED in the Makefile), so a plugin can't pull in a + # database driver, a cloud SDK or anything private. Adding a dependency + # means adding it there, in review. - name: imports are this module, the standard library or approved if: steps.go.outputs.present == 'true' - run: | - module=$(go list -m) - allowed="^($module(/|$)|gopkg\.in/yaml\.v3$)" - others=$(go list -deps -test -f '{{if not .Standard}}{{.ImportPath}}{{end}}' ./... | sed 's/ \[.*//' | sort -u | grep -vE "$allowed" || true) - if [ -n "$others" ]; then - echo "::error::imports outside the allowlist (CI_go.yml):"; echo "$others"; exit 1 - fi + run: make imports # Plugins fetch through env.Get / kit, never on their own. - name: net/http only in the fetch layer if: steps.go.outputs.present == 'true' - run: | - module=$(go list -m) - bad=$(go list -f '{{.ImportPath}} {{join .Imports " "}}' ./... \ - | grep -E '(^| )net/http( |$)' | cut -d' ' -f1 \ - | grep -vE "^$module/(fetch|kit|adapter)(/|$)" || true) - if [ -n "$bad" ]; then - echo "::error::these packages import net/http; fetch through env.Get or kit instead:"; echo "$bad"; exit 1 - fi + run: make nethttp # -race: the fetcher and the tests' HTTP servers run on other goroutines. + # Also fails when docs/plugins.json is out of date (make plugins-json). - name: go test if: steps.go.outputs.present == 'true' - run: go test -race -count=1 ./... + run: make test diff --git a/AGENTS.md b/AGENTS.md index 1876402..d5a2efb 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -6,7 +6,7 @@ Rules for AI coding agents (and humans) working in this repo. `CLAUDE.md` import **If you add a plugin, add its row to [`docs/plugins.md`](docs/plugins.md) in the same PR. If you change a plugin's id, provider, source, what it watches, format plugin or status, update its row in the same PR. If you remove one, remove its row.** -The list of supported APIs on docs.patch-it.dev is generated from that file, so a plugin missing from it doesn't exist as far as users can tell. No CI check enforces this: you are the check. Before you finish, compare the registered plugins with the table and say in the PR that you did. +The list of supported APIs on docs.patch-it.dev is generated from that file, so a plugin missing from it doesn't exist as far as users can tell. Then run `make plugins-json`: it regenerates [`docs/plugins.json`](docs/plugins.json) from the plugin registry and the table, and fails if a registered plugin has no row (or a row has no plugin, a wrong format or no provider page). `go test` fails while `docs/plugins.json` is out of date. The check can't tell whether a row's words are right: you are that check. Say in the PR that you compared them. Keep the table between the `` and `` markers a plain Markdown table, one row per plugin, absolute links only (the docs site copies it verbatim). @@ -33,29 +33,33 @@ Refer to the service that runs these plugins as "patch-it's hosted ingestion ser ## Commands +**Run `make check` before you say you're done.** It runs exactly what `CI_go` runs (each CI step is a Makefile target) plus the internal-names check over every tracked file; if it passes locally, those checks pass in CI. + ```sh -go build ./... -go vet ./... -gofmt -l . # must print nothing -go test -race ./... -python3 scripts/leak_guard.py --all # the internal-names check over every tracked file +make check # tidy, build, gofmt, vet, the import allowlist, the net/http guard, go test -race, leak guard +make check PATCH_IT=../patch-it # also CI_contract: contract/fixtures/ against a patch-it checkout +make plugins-json # regenerate docs/plugins.json after adding or changing a plugin or its row ``` +One target at a time: `make tidy`, `make build`, `make fmt`, `make vet`, `make imports`, `make nethttp`, `make test`, `make leak-guard`, `make contract`. Use `make GO=/path/to/go check` for another Go. + ## Layout Go module `github.com/patch-it-dev/patch-it-plugins`; the only dependency is `gopkg.in/yaml.v3`. ``` plugin/ the Plugin interface, the registry, Env, Result, Spec (baselines) +cmd/list-plugins/ writes docs/plugins.json (make plugins-json); internal/pluginlist/ is its logic plugins// one package per format plugin: openapi, retirements, migrationguide, - removedmembers, changelog, feed, apichangelog; plugins/all imports every one + removedmembers, changelog, feed, apichangelog, catalog; plugins/all imports every one kit/ kit/kittest/ Unchanged, Cite, Wayback; the test kit (Mem, Pages, Ingest, Golden) event/ migrate/ the change-event types from patch-it's contract (v1 + v2), v1 -> v2 fetch/ the HTTP fetch with retries and the ETag / Last-Modified cache diff/ normalize/ hint/ adapter/ the OpenAPI diff engine and the spec adapters retire/ sdkguide/ deprecations-page and migration-guide readers contract/fixtures/ a copy of patch-it's change-event fixtures (CI_contract checks it) -docs/plugins.md the list of supported plugins (Rule 1) +docs/plugins.md the list of supported plugins (Rule 1); docs/plugins.json is generated from it +Makefile make check (what CI_go runs, plus the leak guard), make plugins-json docs/ contributor docs, including writing-a-plugin.md providers/.md one page per provider scripts/ leak_guard.py (hashed internal names), check_contract.py diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 44ff553..d3a6435 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,7 +4,7 @@ Thanks for helping patch-it watch more APIs. This file is the rulebook; [docs/wr ## The rules -1. **Add your plugin to [docs/plugins.md](docs/plugins.md).** Every new plugin gets a row; every change to a plugin's id, provider, source, what it watches or status updates its row. The list on docs.patch-it.dev is built from that file, so a plugin that isn't listed is invisible to users. +1. **Add your plugin to [docs/plugins.md](docs/plugins.md).** Every new plugin gets a row; every change to a plugin's id, provider, source, what it watches or status updates its row. The list on docs.patch-it.dev is built from that file, so a plugin that isn't listed is invisible to users. Then run `make plugins-json` to regenerate [`docs/plugins.json`](docs/plugins.json); it fails if the registry and the table disagree, and the tests fail while the JSON is out of date. 2. **Fetch only through the environment.** Plugins get their sources from `env.Get` or the helpers in `kit/`, never from `net/http` directly, the filesystem or a database. That keeps tests offline and lets the hosted service cache, retry and rate-limit politely. 3. **Every plugin has a golden test** over a real saved copy of its source: `testdata/` in, `testdata/golden/.json` out. `testdata/README.md` lists each file with its URL, the date you fetched it, its license, and a short quote of the part your plugin reads. Keep openly licensed files whole; trim vendor documentation pages to what the test needs. 4. **Precision over recall.** A missed change is a bug we can fix later. A wrong change becomes a wrong pull request in someone's repo. When in doubt, don't emit. @@ -26,7 +26,7 @@ That adds `Signed-off-by: Your Name `, matching the commit's au - One plugin or one fix per PR. Fill in the PR template's checklist. - Commit subjects: short, lowercase, imperative (`add the foo plugin`, `fix stripe hint parsing`). -- Run the tests before you push (see [README](README.md#run-the-tests)). +- **Run `make check` before you push.** It runs exactly what `CI_go` runs (tidy, build, gofmt, vet, the import allowlist, the `net/http` guard, `go test -race`) plus the internal-names check, so a green `make check` means those CI checks pass. - A maintainer listed in `.github/CODEOWNERS` reviews every PR. - **Reviews:** Claude also reviews each PR against the rules above, once, when it's opened or marked ready. PRs from forks get no secrets, so for those a maintainer comments `@claude review` and Claude reviews it read-only (it never runs a fork's code). Only maintainers can call `@claude`. Claude's review helps; a maintainer still decides. @@ -34,7 +34,7 @@ That adds `Signed-off-by: Your Name `, matching the commit's au | Workflow | What it checks | |---|---| -| `CI_go` | `go mod tidy`, build, vet, gofmt, `go test -race`; plugins import only this module, the standard library and approved dependencies; `net/http` only in the fetch layer | +| `CI_go` | `go mod tidy`, build, vet, gofmt, `go test -race` (including that `docs/plugins.json` is up to date); plugins import only this module, the standard library and approved dependencies; `net/http` only in the fetch layer. Each step is a [Makefile](Makefile) target: `make check` runs them all locally | | `CI_dco` | Every commit in the PR is signed off by its author | | `CI_leak_guard` | gitleaks over the PR's commits, and a check for known internal names (stored as hashes only). Also runs weekly over the whole repo | | `Claude Code Review` | Claude reviews the PR against the rules above, once (PRs from this repo's branches; forks: a maintainer comments `@claude review`). Advisory, not a required check | diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f507bd9 --- /dev/null +++ b/Makefile @@ -0,0 +1,81 @@ +# `make check` is what CI runs on every pull request: the CI_go steps (each one +# is a target here, and CI_go calls these same targets), the internal-names +# check of CI_leak_guard over every tracked file, and CI_contract's fixture +# comparison when you point it at a patch-it checkout. Run it before you open a PR. +# +# make check everything below, in CI's order +# make check PATCH_IT=../patch-it also compare contract/fixtures/ with patch-it's +# make plugins-json regenerate docs/plugins.json from the registry and docs/plugins.md +# +# The `::error` lines are GitHub annotations; locally they're plain messages. + +GO ?= go +PYTHON ?= python3 + +# Packages allowed outside the standard library: this module and the approved +# dependencies. Adding a dependency means adding it here, in review. +MODULE := github.com/patch-it-dev/patch-it-plugins +ALLOWED := ^($(MODULE)(/|$$)|gopkg\.in/yaml\.v3$$) + +.PHONY: check tidy build fmt vet imports nethttp test leak-guard contract plugins-json + +check: tidy build fmt vet imports nethttp test leak-guard contract + @echo "make check: all passed" + +# go.mod and go.sum are tidy. +tidy: + $(GO) mod tidy + @git diff --exit-code -- go.mod go.sum || { echo "::error file=go.mod::go.mod/go.sum are not tidy. Run 'go mod tidy' and commit the result."; exit 1; } + +build: + $(GO) build ./... + +fmt: + @unformatted=$$(gofmt -l .); \ + if [ -n "$$unformatted" ]; then \ + for f in $$unformatted; do echo "::error file=$$f::not gofmt-formatted. Run 'gofmt -w $$f'."; done; \ + exit 1; \ + fi + +vet: + $(GO) vet ./... + +# An allowlist, so a plugin can't pull in a database driver, a cloud SDK or +# anything private. +imports: + @others=$$($(GO) list -deps -test -f '{{if not .Standard}}{{.ImportPath}}{{end}}' ./... | sed 's/ \[.*//' | sort -u | grep -vE '$(ALLOWED)' || true); \ + if [ -n "$$others" ]; then \ + echo "::error::imports outside the allowlist (Makefile, ALLOWED):"; echo "$$others"; exit 1; \ + fi + +# Plugins fetch through env.Get / kit, never on their own. +nethttp: + @bad=$$($(GO) list -f '{{.ImportPath}} {{join .Imports " "}}' ./... \ + | grep -E '(^| )net/http( |$$)' | cut -d' ' -f1 \ + | grep -vE '^$(MODULE)/(fetch|kit|adapter)(/|$$)' || true); \ + if [ -n "$$bad" ]; then \ + echo "::error::these packages import net/http; fetch through env.Get or kit instead:"; echo "$$bad"; exit 1; \ + fi + +# -race: the fetcher and the tests' HTTP servers run on other goroutines. +# Includes the check that docs/plugins.json is up to date (internal/pluginlist). +test: + $(GO) test -race -count=1 ./... + +# CI_leak_guard checks only what a PR adds (plus gitleaks); this checks every +# tracked file. +leak-guard: + $(PYTHON) scripts/leak_guard.py --all + +# CI_contract: contract/fixtures/ hold the same events as patch-it's fixtures/. +# Needs a patch-it checkout; skipped without one, as CI_contract skips while +# patch-it can't be read anonymously. +contract: + @if [ -n "$(PATCH_IT)" ]; then \ + $(PYTHON) scripts/check_contract.py "$(PATCH_IT)/fixtures"; \ + else \ + echo "contract: skipped (make check PATCH_IT= compares contract/fixtures/)"; \ + fi + +plugins-json: + $(GO) run ./cmd/list-plugins diff --git a/README.md b/README.md index 24cdd88..7346417 100644 --- a/README.md +++ b/README.md @@ -39,13 +39,10 @@ See **[docs/plugins.md](docs/plugins.md)**. The same list is on [docs.patch-it.d ## Run the tests -Go (the version in `go.mod`), no other setup: +Go (the version in `go.mod`), `make` and Python 3, no other setup: ```sh -go build ./... -go vet ./... -gofmt -l . # prints nothing when formatted -go test -race ./... +make check # what CI runs: tidy, build, gofmt, vet, import and net/http guards, go test -race, leak guard ``` The tests are offline: every plugin's test reads a saved copy of its source from `testdata/` and compares the events with a golden file. One package: `go test ./plugins/feed`. After an intended change to a plugin's output, `go test ./plugins/ -update` rewrites its golden files; review that diff like code. diff --git a/cmd/list-plugins/main.go b/cmd/list-plugins/main.go new file mode 100644 index 0000000..9932074 --- /dev/null +++ b/cmd/list-plugins/main.go @@ -0,0 +1,55 @@ +// Command list-plugins writes docs/plugins.json: every registered plugin +// joined with its row in docs/plugins.md (id, provider, what it watches, +// format plugin, source URL, status, provider page). It fails when the +// registry and the table disagree. Run it from the repo root: +// +// go run ./cmd/list-plugins # rewrite docs/plugins.json (make plugins-json) +// go run ./cmd/list-plugins -check # fail if docs/plugins.json is out of date (make check) +// go run ./cmd/list-plugins -o - # print it +package main + +import ( + "bytes" + "flag" + "fmt" + "os" + "path/filepath" + + "github.com/patch-it-dev/patch-it-plugins/internal/pluginlist" + _ "github.com/patch-it-dev/patch-it-plugins/plugins/all" +) + +func main() { + root := flag.String("root", ".", "the repo root") + out := flag.String("o", pluginlist.JSON, "where to write the list, relative to -root; - for stdout") + check := flag.Bool("check", false, "don't write: fail if the file differs from what would be written") + flag.Parse() + if err := run(*root, *out, *check); err != nil { + fmt.Fprintln(os.Stderr, "list-plugins:", err) + os.Exit(1) + } +} + +func run(root, out string, check bool) error { + plugins, err := pluginlist.List(root) + if err != nil { + return err + } + b, err := pluginlist.Marshal(plugins) + if err != nil { + return err + } + if out == "-" { + _, err := os.Stdout.Write(b) + return err + } + path := filepath.Join(root, out) + if check { + have, err := os.ReadFile(path) + if err != nil || !bytes.Equal(have, b) { + return fmt.Errorf("%s is out of date: run `make plugins-json` and commit it", out) + } + return nil + } + return os.WriteFile(path, b, 0o644) +} diff --git a/docs/README.md b/docs/README.md index 0ed2192..126dc8f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -3,6 +3,7 @@ | Page | What's in it | |---|---| | [plugins.md](plugins.md) | Every supported plugin: id, provider, what it watches, source. Also published on [docs.patch-it.dev](https://docs.patch-it.dev/supported-apis/plugins/). | +| [plugins.json](plugins.json) | The same list as JSON, generated by `make plugins-json` from the plugin registry and plugins.md. Don't edit by hand. | | [writing-a-plugin.md](writing-a-plugin.md) | How to add a provider: the `Plugin` interface, fetching through `env.Get` and `kit/`, saving the source, the golden test with `kittest`, the provider page and the plugin list. | | [../providers/](../providers/) | One page per provider: why that source, what the plugin reads and ignores. | diff --git a/docs/plugins.json b/docs/plugins.json new file mode 100644 index 0000000..b7eb317 --- /dev/null +++ b/docs/plugins.json @@ -0,0 +1,207 @@ +{ + "_comment": "Generated from the plugin registry and docs/plugins.md by `make plugins-json` (go run ./cmd/list-plugins). Don't edit by hand.", + "$schema": "./plugins.schema.json", + "count": 20, + "plugins": [ + { + "id": "algolia-ingestion", + "provider": "Algolia", + "layer": "api", + "watches": "Ingestion API operations deprecated, and deprecated operations removed, between releases of the spec", + "format": "openapi", + "source_url": "https://github.com/algolia/api-clients-automation", + "status": "live", + "provider_page": "providers/algolia.md" + }, + { + "id": "algolia-recommend", + "provider": "Algolia", + "layer": "api", + "watches": "Recommend API operations deprecated, and deprecated operations removed, between releases of the spec", + "format": "openapi", + "source_url": "https://github.com/algolia/api-clients-automation", + "status": "live", + "provider_page": "providers/algolia.md" + }, + { + "id": "algolia-search", + "provider": "Algolia", + "layer": "api", + "watches": "Search API operations deprecated, and deprecated operations removed, between releases of the spec", + "format": "openapi", + "source_url": "https://github.com/algolia/api-clients-automation", + "status": "live", + "provider_page": "providers/algolia.md" + }, + { + "id": "anthropic", + "provider": "Anthropic", + "layer": "sdk", + "watches": "Parameters removed from `messages.create()` and friends in the Python SDK 1.0", + "format": "migrationguide", + "source_url": "https://github.com/anthropics/anthropic-sdk-python/blob/v1.0.0/MIGRATION.md", + "status": "live", + "provider_page": "providers/anthropic.md" + }, + { + "id": "anthropic-models", + "provider": "Anthropic", + "layer": "ai-models", + "watches": "Model deprecations and retirement dates (Messages API models)", + "format": "retirements", + "source_url": "https://platform.claude.com/docs/en/about-claude/model-deprecations", + "status": "live", + "provider_page": "providers/anthropic-models.md" + }, + { + "id": "cloudflare", + "provider": "Cloudflare", + "layer": "api", + "watches": "REST API operations Cloudflare deprecates, breaking on their end-of-life date when it gives one", + "format": "feed", + "source_url": "https://developers.cloudflare.com/fundamentals/api/reference/deprecations/index.xml", + "status": "live", + "provider_page": "providers/cloudflare.md" + }, + { + "id": "datadog", + "provider": "Datadog", + "layer": "api", + "watches": "API v2 changes between OpenAPI spec releases", + "format": "openapi", + "source_url": "https://github.com/DataDog/datadog-api-client-python", + "status": "live", + "provider_page": "providers/datadog.md" + }, + { + "id": "github", + "provider": "GitHub", + "layer": "api", + "watches": "REST API changes between dated API versions", + "format": "openapi", + "source_url": "https://github.com/github/rest-api-description", + "status": "live", + "provider_page": "providers/github.md" + }, + { + "id": "github-actions", + "provider": "GitHub", + "layer": "ci", + "watches": "GitHub Actions retirements, such as runner images and the `runs-on` labels they remove", + "format": "feed", + "source_url": "https://github.blog/changelog/label/actions/feed/", + "status": "live", + "provider_page": "providers/github-actions.md" + }, + { + "id": "gitlab", + "provider": "GitLab", + "layer": "api", + "watches": "REST API changes between releases, request side only (what callers send)", + "format": "openapi", + "source_url": "https://gitlab.com/gitlab-org/gitlab/-/tree/master/doc/api/openapi", + "status": "live", + "provider_page": "providers/gitlab.md" + }, + { + "id": "mongodb-atlas", + "provider": "MongoDB", + "layer": "api", + "watches": "Atlas Administration API versions deprecated and removed at their sunset date, per endpoint, from MongoDB's own API changelog", + "format": "apichangelog", + "source_url": "https://github.com/mongodb/openapi/blob/main/changelog/changelog.json", + "status": "live", + "provider_page": "providers/mongodb-atlas.md" + }, + { + "id": "numpy", + "provider": "NumPy", + "layer": "package", + "watches": "Members removed or renamed in the main namespace in NumPy 2.0", + "format": "removedmembers", + "source_url": "https://github.com/numpy/numpy/blob/v2.0.0/doc/source/numpy_2_0_migration_guide.rst", + "status": "live", + "provider_page": "providers/numpy.md" + }, + { + "id": "openai-models", + "provider": "OpenAI", + "layer": "ai-models", + "watches": "Model deprecations and shutdown dates (Chat Completions and Responses text models)", + "format": "retirements", + "source_url": "https://developers.openai.com/api/docs/deprecations", + "status": "live", + "provider_page": "providers/openai-models.md" + }, + { + "id": "redis", + "provider": "Redis", + "layer": "runtime", + "watches": "Commands removed entirely from Redis's own command catalog between two snapshots", + "format": "catalog", + "source_url": "https://github.com/redis/redis-doc/blob/master/commands.json", + "status": "live", + "provider_page": "providers/redis.md" + }, + { + "id": "stripe", + "provider": "Stripe", + "layer": "api", + "watches": "REST API changes between OpenAPI spec releases (removed and renamed endpoints, parameters and fields), with migration hints from Stripe's API changelog", + "format": "openapi", + "source_url": "https://github.com/stripe/openapi", + "status": "live", + "provider_page": "providers/stripe.md" + }, + { + "id": "supabase", + "provider": "Supabase", + "layer": "api", + "watches": "Management API operations deprecated, and deprecated operations removed, between commits of the spec", + "format": "openapi", + "source_url": "https://github.com/supabase/supabase", + "status": "live", + "provider_page": "providers/supabase.md" + }, + { + "id": "textual", + "provider": "Textual", + "layer": "package", + "watches": "Removals and breaking changes in release 0.86.0", + "format": "changelog", + "source_url": "https://github.com/Textualize/textual/blob/v0.86.0/CHANGELOG.md", + "status": "live", + "provider_page": "providers/textual.md" + }, + { + "id": "urllib3", + "provider": "urllib3", + "layer": "package", + "watches": "Removals and deprecations in release 2.0.0", + "format": "changelog", + "source_url": "https://github.com/urllib3/urllib3/blob/2.0.0/CHANGES.rst", + "status": "live", + "provider_page": "providers/urllib3.md" + }, + { + "id": "vercel", + "provider": "Vercel", + "layer": "api", + "watches": "REST API operations deprecated, and deprecated operations removed, between SDK releases of the spec", + "format": "openapi", + "source_url": "https://github.com/vercel/sdk", + "status": "live", + "provider_page": "providers/vercel.md" + }, + { + "id": "vertex-ai-models", + "provider": "Google", + "layer": "ai-models", + "watches": "Generative AI model deprecations on Vertex AI", + "format": "feed", + "source_url": "https://docs.cloud.google.com/feeds/generative-ai-on-vertex-ai-release-notes.xml", + "status": "live", + "provider_page": "providers/vertex-ai-models.md" + } + ] +} diff --git a/docs/plugins.md b/docs/plugins.md index a538a4b..ef0bbc9 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -4,31 +4,31 @@ Every source patch-it watches is one plugin. This is the list of them: **if a pl Each plugin's id links to its provider page in [`providers/`](../providers/): why that source, what the plugin reads and ignores, and its known gaps. How to add one: [writing-a-plugin.md](writing-a-plugin.md). -The table between the `plugins:start` and `plugins:end` markers is also published on [docs.patch-it.dev](https://docs.patch-it.dev/supported-apis/plugins/): the docs site reads this file from `main` when it builds. Keep it a plain Markdown table, one row per plugin, with absolute links only. +The table between the `plugins:start` and `plugins:end` markers is also published on [docs.patch-it.dev](https://docs.patch-it.dev/supported-apis/plugins/): the docs site reads this file from `main` when it builds. Keep it a plain Markdown table, one row per plugin, with absolute links only. [`plugins.json`](plugins.json) is the same list as JSON (id, provider, layer, format, source URL, status, provider page; schema in [`plugins.schema.json`](plugins.schema.json)), generated by `make plugins-json`. -| Plugin (`--api`) | Provider | What it watches | Format plugin | Source | Status | -|---|---|---|---|---|---| -| [`stripe`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/stripe.md) | Stripe | REST API changes between OpenAPI spec releases (removed and renamed endpoints, parameters and fields), with migration hints from Stripe's API changelog | `openapi` | [stripe/openapi](https://github.com/stripe/openapi) | live | -| [`datadog`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/datadog.md) | Datadog | API v2 changes between OpenAPI spec releases | `openapi` | [DataDog/datadog-api-client-python](https://github.com/DataDog/datadog-api-client-python) (`.generator/schemas/v2/openapi.yaml`) | live | -| [`github`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/github.md) | GitHub | REST API changes between dated API versions | `openapi` | [github/rest-api-description](https://github.com/github/rest-api-description) | live | -| [`gitlab`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/gitlab.md) | GitLab | REST API changes between releases, request side only (what callers send) | `openapi` | [gitlab-org/gitlab `doc/api/openapi`](https://gitlab.com/gitlab-org/gitlab/-/tree/master/doc/api/openapi) | live | -| [`vercel`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/vercel.md) | Vercel | REST API operations deprecated, and deprecated operations removed, between SDK releases of the spec | `openapi` | [vercel/sdk](https://github.com/vercel/sdk) (`vercel-spec.json`) | paused: merged, not in a tagged release yet, so patch-it's hosted ingestion service doesn't run it | -| [`supabase`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/supabase.md) | Supabase | Management API operations deprecated, and deprecated operations removed, between commits of the spec | `openapi` | [supabase/supabase](https://github.com/supabase/supabase) (`apps/docs/spec/api_v1_openapi.json`) | paused: merged, not in a tagged release yet, so patch-it's hosted ingestion service doesn't run it | -| [`algolia-search`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/algolia.md) | Algolia | Search API operations deprecated, and deprecated operations removed, between releases of the spec | `openapi` | [algolia/api-clients-automation](https://github.com/algolia/api-clients-automation) (`specs/bundled/search.yml`) | paused: merged, not in a tagged release yet, so patch-it's hosted ingestion service doesn't run it | -| [`algolia-ingestion`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/algolia.md) | Algolia | Ingestion API operations deprecated, and deprecated operations removed, between releases of the spec | `openapi` | [algolia/api-clients-automation](https://github.com/algolia/api-clients-automation) (`specs/bundled/ingestion.yml`) | paused: merged, not in a tagged release yet, so patch-it's hosted ingestion service doesn't run it | -| [`algolia-recommend`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/algolia.md) | Algolia | Recommend API operations deprecated, and deprecated operations removed, between releases of the spec | `openapi` | [algolia/api-clients-automation](https://github.com/algolia/api-clients-automation) (`specs/bundled/recommend.yml`) | paused: merged, not in a tagged release yet, so patch-it's hosted ingestion service doesn't run it | -| [`mongodb-atlas`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/mongodb-atlas.md) | MongoDB | Atlas Administration API versions deprecated and removed at their sunset date, per endpoint, from MongoDB's own API changelog | `apichangelog` | [mongodb/openapi `changelog/changelog.json`](https://github.com/mongodb/openapi/blob/main/changelog/changelog.json) | paused: merged, not in a tagged release yet, so patch-it's hosted ingestion service doesn't run it | -| [`openai-models`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/openai-models.md) | OpenAI | Model deprecations and shutdown dates (Chat Completions and Responses text models) | `retirements` | [OpenAI deprecations](https://developers.openai.com/api/docs/deprecations) | live | -| [`anthropic-models`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/anthropic-models.md) | Anthropic | Model deprecations and retirement dates (Messages API models) | `retirements` | [Anthropic model deprecations](https://platform.claude.com/docs/en/about-claude/model-deprecations) | live | -| [`anthropic`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/anthropic.md) | Anthropic | Parameters removed from `messages.create()` and friends in the Python SDK 1.0 | `migrationguide` | [anthropic-sdk-python MIGRATION.md](https://github.com/anthropics/anthropic-sdk-python/blob/v1.0.0/MIGRATION.md) | live | -| [`numpy`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/numpy.md) | NumPy | Members removed or renamed in the main namespace in NumPy 2.0 | `removedmembers` | [NumPy 2.0 migration guide](https://github.com/numpy/numpy/blob/v2.0.0/doc/source/numpy_2_0_migration_guide.rst) | live | -| [`textual`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/textual.md) | Textual | Removals and breaking changes in release 0.86.0 | `changelog` | [Textualize/textual CHANGELOG.md](https://github.com/Textualize/textual/blob/v0.86.0/CHANGELOG.md) | live | -| [`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 | +| Plugin (`--api`) | Provider | Layer | What it watches | Format plugin | Source | Status | +|---|---|---|---|---|---|---| +| [`stripe`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/stripe.md) | Stripe | API | REST API changes between OpenAPI spec releases (removed and renamed endpoints, parameters and fields), with migration hints from Stripe's API changelog | `openapi` | [stripe/openapi](https://github.com/stripe/openapi) | live | +| [`datadog`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/datadog.md) | Datadog | API | API v2 changes between OpenAPI spec releases | `openapi` | [DataDog/datadog-api-client-python](https://github.com/DataDog/datadog-api-client-python) (`.generator/schemas/v2/openapi.yaml`) | live | +| [`github`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/github.md) | GitHub | API | REST API changes between dated API versions | `openapi` | [github/rest-api-description](https://github.com/github/rest-api-description) | live | +| [`gitlab`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/gitlab.md) | GitLab | API | REST API changes between releases, request side only (what callers send) | `openapi` | [gitlab-org/gitlab `doc/api/openapi`](https://gitlab.com/gitlab-org/gitlab/-/tree/master/doc/api/openapi) | live | +| [`vercel`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/vercel.md) | Vercel | API | REST API operations deprecated, and deprecated operations removed, between SDK releases of the spec | `openapi` | [vercel/sdk](https://github.com/vercel/sdk) (`vercel-spec.json`) | live | +| [`supabase`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/supabase.md) | Supabase | API | Management API operations deprecated, and deprecated operations removed, between commits of the spec | `openapi` | [supabase/supabase](https://github.com/supabase/supabase) (`apps/docs/spec/api_v1_openapi.json`) | live | +| [`algolia-search`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/algolia.md) | Algolia | API | Search API operations deprecated, and deprecated operations removed, between releases of the spec | `openapi` | [algolia/api-clients-automation](https://github.com/algolia/api-clients-automation) (`specs/bundled/search.yml`) | live | +| [`algolia-ingestion`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/algolia.md) | Algolia | API | Ingestion API operations deprecated, and deprecated operations removed, between releases of the spec | `openapi` | [algolia/api-clients-automation](https://github.com/algolia/api-clients-automation) (`specs/bundled/ingestion.yml`) | live | +| [`algolia-recommend`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/algolia.md) | Algolia | API | Recommend API operations deprecated, and deprecated operations removed, between releases of the spec | `openapi` | [algolia/api-clients-automation](https://github.com/algolia/api-clients-automation) (`specs/bundled/recommend.yml`) | live | +| [`mongodb-atlas`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/mongodb-atlas.md) | MongoDB | API | Atlas Administration API versions deprecated and removed at their sunset date, per endpoint, from MongoDB's own API changelog | `apichangelog` | [mongodb/openapi `changelog/changelog.json`](https://github.com/mongodb/openapi/blob/main/changelog/changelog.json) | live | +| [`openai-models`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/openai-models.md) | OpenAI | AI models | Model deprecations and shutdown dates (Chat Completions and Responses text models) | `retirements` | [OpenAI deprecations](https://developers.openai.com/api/docs/deprecations) | live | +| [`anthropic-models`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/anthropic-models.md) | Anthropic | AI models | Model deprecations and retirement dates (Messages API models) | `retirements` | [Anthropic model deprecations](https://platform.claude.com/docs/en/about-claude/model-deprecations) | live | +| [`anthropic`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/anthropic.md) | Anthropic | SDK | Parameters removed from `messages.create()` and friends in the Python SDK 1.0 | `migrationguide` | [anthropic-sdk-python MIGRATION.md](https://github.com/anthropics/anthropic-sdk-python/blob/v1.0.0/MIGRATION.md) | live | +| [`numpy`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/numpy.md) | NumPy | package | Members removed or renamed in the main namespace in NumPy 2.0 | `removedmembers` | [NumPy 2.0 migration guide](https://github.com/numpy/numpy/blob/v2.0.0/doc/source/numpy_2_0_migration_guide.rst) | live | +| [`textual`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/textual.md) | Textual | package | Removals and breaking changes in release 0.86.0 | `changelog` | [Textualize/textual CHANGELOG.md](https://github.com/Textualize/textual/blob/v0.86.0/CHANGELOG.md) | live | +| [`urllib3`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/urllib3.md) | urllib3 | package | 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 | CI | 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 | AI models | 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 | runtime | 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 | API | 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) | live | ## The columns @@ -37,9 +37,10 @@ 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. | +| Layer | Which kind of dependency it covers: `API`, `SDK`, `package`, `runtime`, `CI` or `AI models`. | | 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), `catalog` (a structured JSON catalog of names, diffed between two snapshots). | +| 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), `apichangelog` (a vendor's machine-readable API changelog, in JSON). | | 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. | +| Status | `live`: in the code on `main`. patch-it's hosted ingestion service runs it daily from the next release, which is cut automatically. `planned`: accepted, not written yet. `paused`: in the code but deliberately switched off, with the reason in the row. | Some plugins read one pinned release (`anthropic` 1.0.0, `numpy` 2.0.0, `textual` 0.86.0, `urllib3` 2.0.0): a newer release of the same package is a new entry in that plugin, not a new row, unless it changes the format. diff --git a/docs/plugins.schema.json b/docs/plugins.schema.json new file mode 100644 index 0000000..6399a73 --- /dev/null +++ b/docs/plugins.schema.json @@ -0,0 +1,33 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/patch-it-dev/patch-it-plugins/blob/main/docs/plugins.schema.json", + "title": "patch-it plugins", + "description": "docs/plugins.json: every registered plugin, generated by `make plugins-json` from the plugin registry and docs/plugins.md.", + "type": "object", + "required": ["_comment", "$schema", "count", "plugins"], + "additionalProperties": false, + "properties": { + "_comment": { "type": "string" }, + "$schema": { "type": "string" }, + "count": { "type": "integer", "description": "How many plugins are listed." }, + "plugins": { + "type": "array", + "items": { + "type": "object", + "required": ["id", "provider", "layer", "watches", "format", "source_url", "status", "provider_page"], + "additionalProperties": false, + "properties": { + "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]*$", "description": "The plugin's --api id and every event's api field." }, + "provider": { "type": "string", "minLength": 1 }, + "layer": { "type": "string", "enum": ["api", "sdk", "package", "runtime", "ci", "ai-models"] }, + "watches": { "type": "string", "minLength": 1 }, + "format": { "type": "string", "enum": ["openapi", "retirements", "migrationguide", "removedmembers", "changelog", "feed", "apichangelog", "catalog"] }, + "source_url": { "type": "string", "pattern": "^https://" }, + "status": { "type": "string", "enum": ["live", "paused", "planned"] }, + "status_note": { "type": "string", "description": "Why, for a paused plugin." }, + "provider_page": { "type": "string", "pattern": "^providers/[a-z0-9][a-z0-9.-]*\\.md$", "description": "One page per provider: plugins of the same provider may share it." } + } + } + } + } +} diff --git a/docs/writing-a-plugin.md b/docs/writing-a-plugin.md index 5b8a1f9..241d1c5 100644 --- a/docs/writing-a-plugin.md +++ b/docs/writing-a-plugin.md @@ -117,14 +117,12 @@ Copy [`providers/_template.md`](../providers/_template.md) to `providers/.m ## 8. Add the row to `docs/plugins.md` -**Not optional** ([AGENTS.md](../AGENTS.md) rule 1). Add one row between the `plugins:start` and `plugins:end` markers: the id linked to its provider page, the provider, what it watches, the format plugin, the source, the status. Absolute links only: the docs site copies the table as it is. Changing a plugin's id, source or what it watches updates its row in the same PR. +**Not optional** ([AGENTS.md](../AGENTS.md) rule 1). Add one row between the `plugins:start` and `plugins:end` markers: the id linked to its provider page, the provider, what it watches, the format plugin, the source, the status. Absolute links only: the docs site copies the table as it is. Changing a plugin's id, source or what it watches updates its row in the same PR. Then run `make plugins-json` to regenerate `docs/plugins.json`; it fails, naming the problem, if the registry and the table disagree. ## 9. Check and open the PR ```sh -go build ./... && go vet ./... && gofmt -l . && go test -race ./... -go mod tidy # no diff -python3 scripts/leak_guard.py --all +make check # what CI runs, plus the leak guard git commit -s -m "add the foo plugin" # DCO sign-off ``` diff --git a/internal/pluginlist/pluginlist.go b/internal/pluginlist/pluginlist.go new file mode 100644 index 0000000..92418b6 --- /dev/null +++ b/internal/pluginlist/pluginlist.go @@ -0,0 +1,224 @@ +// Package pluginlist joins the plugin registry with the table in +// docs/plugins.md: the registry says which plugins exist and which format +// plugin each is built on, the table says who the provider is, what it +// watches, its source and its status. List checks that the two agree, so a +// plugin missing from the table (AGENTS.md rule 1) fails `make check`. +package pluginlist + +import ( + "bytes" + "encoding/json" + "errors" + "fmt" + "os" + "path" + "path/filepath" + "reflect" + "regexp" + "slices" + "strings" + + "github.com/patch-it-dev/patch-it-plugins/plugin" +) + +// Table is the plugin list, relative to the repo root. +const Table = "docs/plugins.md" + +// JSON is the generated list, relative to the repo root. +const JSON = "docs/plugins.json" + +// The markers around the table in Table. +const ( + StartMarker = "" + EndMarker = "" +) + +// Row is one row of the table, as written. +type Row struct { + ID string // the plugin id, without the backticks and link + Page string // the provider page it links to: "algolia" for providers/algolia.md + Provider string + Layer string // as written: "API", "AI models" + Watches string + Format string + Source string // the cell, as written + Status string // the cell, as written: "live", "paused: why" +} + +// Plugin is one entry of docs/plugins.json. +type Plugin struct { + ID string `json:"id"` + Provider string `json:"provider"` + Layer string `json:"layer"` // api, sdk, package, runtime, ci or ai-models + Watches string `json:"watches"` + Format string `json:"format"` + SourceURL string `json:"source_url"` + Status string `json:"status"` // live, paused or planned + StatusNote string `json:"status_note,omitempty"` // why, for paused + ProviderPage string `json:"provider_page"` // relative to the repo root +} + +// File is docs/plugins.json. +type File struct { + Comment string `json:"_comment"` + Schema string `json:"$schema"` + Count int `json:"count"` + Plugins []Plugin `json:"plugins"` +} + +var ( + cellID = regexp.MustCompile("^\\[`([a-z0-9][a-z0-9.-]*)`\\]\\(https://github\\.com/patch-it-dev/patch-it-plugins/blob/main/providers/([^)]+)\\.md\\)$") + cellFmt = regexp.MustCompile("^`([a-z]+)`$") + link = regexp.MustCompile(`\]\((https?://[^)\s]+)\)`) + statuses = []string{"live", "paused", "planned"} +) + +// Layers are the kinds of dependency a plugin covers: the table's word to +// the JSON's. +var Layers = map[string]string{ + "API": "api", + "SDK": "sdk", + "package": "package", + "runtime": "runtime", + "CI": "ci", + "AI models": "ai-models", +} + +// Statuses are the values of a plugin's status. +func Statuses() []string { return slices.Clone(statuses) } + +// ReadTable reads the rows between the markers of the plugin list. +func ReadTable(md []byte) ([]Row, error) { + start := bytes.Index(md, []byte(StartMarker)) + end := bytes.Index(md, []byte(EndMarker)) + if start < 0 || end < start { + return nil, fmt.Errorf("%s: no %s ... %s block", Table, StartMarker, EndMarker) + } + var rows []Row + lines := strings.Split(string(md[start+len(StartMarker):end]), "\n") + for _, l := range lines { + l = strings.TrimSpace(l) + if !strings.HasPrefix(l, "|") || strings.HasPrefix(l, "|---") || strings.HasPrefix(l, "| Plugin") { + continue + } + cells := splitRow(l) + if len(cells) != 7 { + return nil, fmt.Errorf("%s: row %q has %d cells, want 7", Table, l, len(cells)) + } + m := cellID.FindStringSubmatch(cells[0]) + if m == nil { + return nil, fmt.Errorf("%s: plugin cell %q is not [`id`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/.md)", Table, cells[0]) + } + f := cellFmt.FindStringSubmatch(cells[4]) + if f == nil { + return nil, fmt.Errorf("%s: %s: format cell %q is not `format`", Table, m[1], cells[4]) + } + rows = append(rows, Row{ID: m[1], Page: m[2], Provider: cells[1], Layer: cells[2], Watches: cells[3], Format: f[1], Source: cells[5], Status: cells[6]}) + } + return rows, nil +} + +// splitRow splits "| a | b |" into its cells. A cell holding a pipe would +// have to escape it (\|); none does, and the docs site copies the table as is. +func splitRow(l string) []string { + l = strings.TrimSuffix(strings.TrimPrefix(l, "|"), "|") + var cells []string + for _, c := range strings.Split(l, "|") { + cells = append(cells, strings.TrimSpace(c)) + } + return cells +} + +// Format is the format plugin a registered plugin is built on: the name of +// the package under plugins/ its type is defined in. +func Format(p plugin.Plugin) string { + t := reflect.TypeOf(p) + for t.Kind() == reflect.Pointer { + t = t.Elem() + } + return path.Base(t.PkgPath()) +} + +// List joins the registered plugins with the table under root and checks +// they agree: every registered plugin has a row with its format, every row is +// registered (unless it's planned), and every plugin has a provider page. +// The plugins come out sorted by id. +func List(root string) ([]Plugin, error) { + md, err := os.ReadFile(filepath.Join(root, Table)) + if err != nil { + return nil, err + } + rows, err := ReadTable(md) + if err != nil { + return nil, err + } + var errs []error + byID := map[string]Row{} + for _, r := range rows { + if _, dup := byID[r.ID]; dup { + errs = append(errs, fmt.Errorf("%s: %s has two rows", Table, r.ID)) + } + byID[r.ID] = r + } + registered := map[string]string{} + for _, name := range plugin.Names() { + p, _ := plugin.Lookup(name) + registered[name] = Format(p) + if _, ok := byID[name]; !ok { + errs = append(errs, fmt.Errorf("%s is registered but has no row in %s: add one (AGENTS.md rule 1), then run `make plugins-json`", name, Table)) + } + } + var out []Plugin + for _, r := range rows { + status, note, _ := strings.Cut(r.Status, ":") + status, note = strings.TrimSpace(status), strings.TrimSpace(note) + if !slices.Contains(statuses, status) { + errs = append(errs, fmt.Errorf("%s: %s: status %q is not live, paused or planned", Table, r.ID, r.Status)) + } + layer, known := Layers[r.Layer] + if !known { + errs = append(errs, fmt.Errorf("%s: %s: layer %q is not one of API, SDK, package, runtime, CI, AI models", Table, r.ID, r.Layer)) + } + format, ok := registered[r.ID] + switch { + case !ok && status != "planned": + errs = append(errs, fmt.Errorf("%s: %s has a row but no plugin registers it: mark it planned, or remove the row", Table, r.ID)) + case ok && format != r.Format: + errs = append(errs, fmt.Errorf("%s: %s says format %q, but the plugin is in plugins/%s", Table, r.ID, r.Format, format)) + } + // One page per provider: the algolia-* plugins share providers/algolia.md. + page := "providers/" + r.Page + ".md" + if _, err := os.Stat(filepath.Join(root, page)); err != nil { + errs = append(errs, fmt.Errorf("%s: %s links to %s, which doesn't exist (copy providers/_template.md)", Table, r.ID, page)) + } + src := link.FindStringSubmatch(r.Source) + if src == nil { + errs = append(errs, fmt.Errorf("%s: %s: the source cell has no absolute link", Table, r.ID)) + src = []string{"", ""} + } + out = append(out, Plugin{ + ID: r.ID, Provider: r.Provider, Layer: layer, Watches: r.Watches, Format: r.Format, + SourceURL: src[1], Status: status, StatusNote: note, ProviderPage: page, + }) + } + if len(errs) > 0 { + return nil, errors.Join(errs...) + } + slices.SortFunc(out, func(a, b Plugin) int { return strings.Compare(a.ID, b.ID) }) + return out, nil +} + +// Marshal is docs/plugins.json for plugins, ending in a newline. +func Marshal(plugins []Plugin) ([]byte, error) { + var buf bytes.Buffer + enc := json.NewEncoder(&buf) + enc.SetIndent("", " ") + enc.SetEscapeHTML(false) + err := enc.Encode(File{ + Comment: "Generated from the plugin registry and docs/plugins.md by `make plugins-json` (go run ./cmd/list-plugins). Don't edit by hand.", + Schema: "./plugins.schema.json", + Count: len(plugins), + Plugins: plugins, + }) + return buf.Bytes(), err +} diff --git a/internal/pluginlist/pluginlist_test.go b/internal/pluginlist/pluginlist_test.go new file mode 100644 index 0000000..3c96ac0 --- /dev/null +++ b/internal/pluginlist/pluginlist_test.go @@ -0,0 +1,79 @@ +package pluginlist + +import ( + "bytes" + "os" + "path/filepath" + "strings" + "testing" + + _ "github.com/patch-it-dev/patch-it-plugins/plugins/all" +) + +const root = "../.." + +// The real table agrees with the registry, and docs/plugins.json is what +// `make plugins-json` writes from them. This is how CI_go (go test) catches a +// plugin added without its row, or a row changed without regenerating. +func TestPluginsJSONIsUpToDate(t *testing.T) { + plugins, err := List(root) + if err != nil { + t.Fatal(err) + } + want, err := Marshal(plugins) + if err != nil { + t.Fatal(err) + } + have, err := os.ReadFile(filepath.Join(root, JSON)) + if err != nil { + t.Fatalf("%v (run `make plugins-json`)", err) + } + if !bytes.Equal(have, want) { + t.Errorf("%s is out of date: run `make plugins-json` and commit it", JSON) + } +} + +func TestReadTable(t *testing.T) { + md := "intro\n" + StartMarker + "\n" + + "| Plugin (`--api`) | Provider | Layer | What it watches | Format plugin | Source | Status |\n" + + "|---|---|---|---|---|---|---|\n" + + "| [`foo-api`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/foo-api.md) | Foo | API | Removed endpoints | `openapi` | [foo/spec](https://github.com/foo/spec) (`openapi.json`) | paused: not released yet |\n" + + EndMarker + "\n" + rows, err := ReadTable([]byte(md)) + if err != nil { + t.Fatal(err) + } + want := Row{ID: "foo-api", Page: "foo-api", Provider: "Foo", Layer: "API", Watches: "Removed endpoints", Format: "openapi", + Source: "[foo/spec](https://github.com/foo/spec) (`openapi.json`)", Status: "paused: not released yet"} + if len(rows) != 1 || rows[0] != want { + t.Errorf("rows = %+v, want [%+v]", rows, want) + } +} + +func TestReadTableRejectsABadRow(t *testing.T) { + for name, row := range map[string]string{ + "relative link": "| [`foo`](../providers/foo.md) | Foo | API | x | `openapi` | [s](https://s.example) | live |", + "not a provider page": "| [`foo`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/docs/foo.md) | Foo | API | x | `openapi` | [s](https://s.example) | live |", + "missing a cell": "| [`foo`](https://github.com/patch-it-dev/patch-it-plugins/blob/main/providers/foo.md) | Foo | `openapi` | [s](https://s.example) | live |", + } { + md := StartMarker + "\n" + row + "\n" + EndMarker + if _, err := ReadTable([]byte(md)); err == nil { + t.Errorf("%s: no error", name) + } + } +} + +// A registered plugin with no row fails the list, naming the rule. +func TestListWantsARowPerPlugin(t *testing.T) { + dir := t.TempDir() + if err := os.MkdirAll(filepath.Join(dir, "docs"), 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(dir, Table), []byte(StartMarker+"\n"+EndMarker+"\n"), 0o644); err != nil { + t.Fatal(err) + } + _, err := List(dir) + if err == nil || !strings.Contains(err.Error(), "stripe is registered but has no row") { + t.Errorf("err = %v, want stripe's missing row", err) + } +} diff --git a/internal/pluginlist/schema_test.go b/internal/pluginlist/schema_test.go new file mode 100644 index 0000000..6cbc729 --- /dev/null +++ b/internal/pluginlist/schema_test.go @@ -0,0 +1,157 @@ +package pluginlist + +import ( + "encoding/json" + "fmt" + "os" + "path/filepath" + "regexp" + "slices" + "testing" +) + +// docs/plugins.json validates against docs/plugins.schema.json. The checker +// below knows only the keywords that schema uses (type, required, +// properties, additionalProperties, items, enum, pattern, minLength): the +// module takes no dependency for a JSON Schema library. +func TestPluginsJSONMatchesTheSchema(t *testing.T) { + var schema, doc any + for file, v := range map[string]*any{"docs/plugins.schema.json": &schema, JSON: &doc} { + b, err := os.ReadFile(filepath.Join(root, file)) + if err != nil { + t.Fatal(err) + } + if err := json.Unmarshal(b, v); err != nil { + t.Fatalf("%s: %v", file, err) + } + } + for _, err := range validate(schema.(map[string]any), doc, "$") { + t.Error(err) + } +} + +// The schema's enums are the values the generator writes. +func TestSchemaEnumsMatchTheGenerator(t *testing.T) { + b, err := os.ReadFile(filepath.Join(root, "docs/plugins.schema.json")) + if err != nil { + t.Fatal(err) + } + var s struct { + Properties struct { + Plugins struct { + Items struct { + Properties map[string]struct { + Enum []string `json:"enum"` + } `json:"properties"` + } `json:"items"` + } `json:"plugins"` + } `json:"properties"` + } + if err := json.Unmarshal(b, &s); err != nil { + t.Fatal(err) + } + props := s.Properties.Plugins.Items.Properties + var layers []string + for _, l := range Layers { + layers = append(layers, l) + } + for name, want := range map[string][]string{"layer": layers, "status": Statuses()} { + got := slices.Sorted(slices.Values(props[name].Enum)) + if !slices.Equal(got, slices.Sorted(slices.Values(want))) { + t.Errorf("schema enum for %s = %v, want %v", name, got, want) + } + } + formats, err := filepath.Glob(filepath.Join(root, "plugins", "*")) + if err != nil { + t.Fatal(err) + } + for _, f := range formats { + if name := filepath.Base(f); name != "all" && !slices.Contains(props["format"].Enum, name) { + t.Errorf("format plugin %s is missing from the schema's format enum", name) + } + } +} + +func TestValidateCatchesABadDocument(t *testing.T) { + schema := map[string]any{ + "type": "object", "required": []any{"a"}, "additionalProperties": false, + "properties": map[string]any{"a": map[string]any{"type": "string", "enum": []any{"x"}}}, + } + for _, doc := range []any{ + map[string]any{}, + map[string]any{"a": "y"}, + map[string]any{"a": "x", "b": 1.0}, + []any{}, + } { + if len(validate(schema, doc, "$")) == 0 { + t.Errorf("%v: valid, want an error", doc) + } + } + if errs := validate(schema, map[string]any{"a": "x"}, "$"); len(errs) != 0 { + t.Errorf("valid document: %v", errs) + } +} + +func validate(s map[string]any, v any, at string) []error { + var errs []error + fail := func(format string, args ...any) { errs = append(errs, fmt.Errorf(at+": "+format, args...)) } + switch s["type"] { + case "object": + obj, ok := v.(map[string]any) + if !ok { + fail("want an object") + return errs + } + props, _ := s["properties"].(map[string]any) + for _, r := range asList(s["required"]) { + if _, ok := obj[r.(string)]; !ok { + fail("missing %q", r) + } + } + for k, child := range obj { + ps, ok := props[k].(map[string]any) + if !ok { + if s["additionalProperties"] == false { + fail("unexpected property %q", k) + } + continue + } + errs = append(errs, validate(ps, child, at+"."+k)...) + } + case "array": + arr, ok := v.([]any) + if !ok { + fail("want an array") + return errs + } + items, _ := s["items"].(map[string]any) + for i, child := range arr { + errs = append(errs, validate(items, child, fmt.Sprintf("%s[%d]", at, i))...) + } + case "integer": + if n, ok := v.(float64); !ok || n != float64(int64(n)) { + fail("want an integer") + } + case "string": + str, ok := v.(string) + if !ok { + fail("want a string") + return errs + } + if enum := asList(s["enum"]); enum != nil && !slices.Contains(enum, any(str)) { + fail("%q is not one of %v", str, enum) + } + if p, ok := s["pattern"].(string); ok && !regexp.MustCompile(p).MatchString(str) { + fail("%q doesn't match %s", str, p) + } + if n, ok := s["minLength"].(float64); ok && len(str) < int(n) { + fail("shorter than %v", n) + } + } + return errs +} + +func asList(v any) []any { + l, _ := v.([]any) + return l +} diff --git a/plugins/all/all.go b/plugins/all/all.go index 68867eb..e8bd0bd 100644 --- a/plugins/all/all.go +++ b/plugins/all/all.go @@ -4,8 +4,8 @@ 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/catalog" _ "github.com/patch-it-dev/patch-it-plugins/plugins/changelog" _ "github.com/patch-it-dev/patch-it-plugins/plugins/feed" _ "github.com/patch-it-dev/patch-it-plugins/plugins/migrationguide"