Stop counting added generated-client methods as API breaks

Merged
JE
3d ago
+418-39

This PR edits a CI workflow (.github/workflows/test.yml, the api-compat job, which backs the required API Compatibility check). It changes what that check counts as breaking and adds a self-test step to the same job.

Why

Two kinds of routine change fail the gate today, and the printed remedy is the breaking label, which then lands on PRs that broke nothing. That stops the label meaning "a real break was looked at and accepted". It's the same reason the release Version constant was already partitioned out.

  1. Added operations. Every new endpoint adds methods to generated.ClientInterface and generated.ClientWithResponsesInterface: oapi-codegen emits one method per operation, two with a request body. apidiff counts a method added to an exported interface as incompatible.
    • The interfaces' implementations are generated.Client / generated.ClientWithResponses, generated beside them. pkg/basecamp holds the concrete *generated.ClientWithResponses, and nothing in the module accepts a caller's implementation.
    • The only route for an outside implementer is the exported ClientInterface field ClientWithResponses embeds, i.e. a hand-written fake. MIGRATING.md has said since #960 that the generated client is the only intended implementer.
  2. Provenance repins. scripts/sync-api-version.sh rewrites APIVersion from openapi.json's info.version, and sync-api-version-check holds the two in step. DefaultUserAgent follows from it by construction. apidiff counts any exported constant's value change as incompatible. For this constant, changing is its job.

Survey of all 121 breaking-labelled PRs (gate logs read from each PR's head; all 121 still available):

  • 83: the gate found nothing in Go (the label was for other SDKs).
  • 14: real Go breaks beyond these lines.
  • 12: only added methods on the two interfaces. Nine of them broke nothing in any SDK per their MIGRATING notes: #839, #847, #960, #1016, #1019, #1037, #1053, #1062, #1067. The other three carried other-SDK or unkeyed-literal breaks the label was right for: #898, #1057, #1061.
  • 7: an APIVersion repin. Under both partitions, none had any other Go incompatibility: #827, #883, #1015, #1059, #1068, #1075, #1125.

What changes

In the "Check for breaking API changes" step, these lines leave the verdict. They still print in their own sections and in "All API Changes".

  • Generated client interfaces. Only lines matching
    ^- \./pkg/generated\.(ClientInterface|ClientWithResponsesInterface)\.[A-Z][A-Za-z0-9_]*: added$
    
    That is: only added, only an exported method, only those two interfaces, only in ./pkg/generated. Removed or changed methods, an unexported method (added unexported method), a method added to any other interface (in generated or elsewhere), and a same-named interface in another package all still fail.
  • Version constants. Version and APIVersion are exempt only as value changed; removing, retyping or renaming either still fails.
    • DefaultUserAgent is exempt only when its old value is basecamp-sdk-go/<Version> (api:<APIVersion>) with the old values of whichever constant changed.
    • Its new value must be the same shape with their new values, and the other component unchanged.
    • A user-agent change with neither constant changing never passes.
    • Before this PR only Version was handled. The section is renamed "Version constants changed".

The reasoning for both is in the workflow comments.

Proof

scripts/test-api-compat-gate (make test-api-compat-gate, run in the api-compat job after apidiff is installed) works like this:

  • It pulls the step's own run: text out of the workflow and runs it with the pinned apidiff against scratch modules shaped like ./go.
  • Each case merges a change with --no-ff, the way refs/pull/N/merge is cut.
  • PR_NUMBER is empty, so the label is never read.

20 cases:

  • pass:
    • methods added to both interfaces, with their generated implementations
    • a release Version bump
    • an APIVersion repin
    • a release and a repin together
  • fail:
    • method removed from ClientInterface
    • signature changed on ClientWithResponsesInterface
    • method added to generated.HttpRequestDoer
    • method added to an interface in pkg/basecamp
    • method added to generated.ClientInterfaceV2
    • method added to a ClientInterface in another package
    • unexported method added to ClientInterface
    • an added operation next to a real break (still fails, and the adds still print in their own section)
    • APIVersion retyped
    • APIVersion removed
    • a user agent that doesn't follow a repin (wrong api value, rewritten prefix, (api:...) dropped)
    • a user-agent change with no constant change
    • a user agent whose old api or version component never matched the constant

Failing cases assert the line lands in the Breaking Changes section, not just somewhere in the output.

Mutation checks run locally:

MutationCases that fail
this PR's first head (no repin partition)4
main's workflow6
dropping : added$2
widening the package to pkg/[a-z]*1
matching any : added$5
exempting any user-agent change beside a constant change3
skipping the old-APIVersion check1
skipping the old-Version check1

Two mutations survive because a guard repeats another:

  • Removing [A-Z]. apidiff writes an unexported method as added unexported method, which the anchor already rejects.
  • Dropping the "a constant changed" guard on the user-agent check. With neither constant changing, the expected value equals the old one, which a changed line can't match.

On #1125 at bf8621a004375245aa54c1301d7804b8adc82c63, merged onto main 465da12a, this branch's step passes with no label:

### Version constants changed
- ./pkg/basecamp.APIVersion: value changed from "2026-11-05" to "2026-11-29"
- ./pkg/basecamp.DefaultUserAgent: value changed from "basecamp-sdk-go/0.40.0 (api:2026-11-05)" to "basecamp-sdk-go/0.40.0 (api:2026-11-29)"
### Generated client interfaces gained methods
- ./pkg/generated.ClientInterface.DeleteMyAvatar: added
- ./pkg/generated.ClientInterface.UpdateMyAvatarWithBody: added
- ./pkg/generated.ClientWithResponsesInterface.DeleteMyAvatarWithResponse: added
- ./pkg/generated.ClientWithResponsesInterface.UpdateMyAvatarWithBodyWithResponse: added
No breaking changes detected.