Repository navigation
test(protocol): public API stability snapshot via public_api + insta (#304) - #734
Conversation
Gas snapshotGas changes vs baseRun: 26722752908 |
Contracts coverageLine coverage: 87.67% (1693/1931 lines) |
There was a problem hiding this comment.
Code Review
This pull request introduces a public API stability snapshot test for the decdn-protocol crate to guard against unintended changes to its exported surface. It integrates public-api, rustdoc-json, rustup-toolchain, and insta snapshot testing, gating the slow test behind a new public-api-test feature. Feedback was provided to correct a contradiction in the Cargo.toml comment, which incorrectly describes how the nightly toolchain version is tracked compared to the actual pinned implementation in the test file.
There was a problem hiding this comment.
Pull request overview
Adds a feature-gated public_api + insta snapshot test for decdn-protocol so exported protocol APIs are checked in CI and intentional API changes require a committed snapshot update.
Changes:
- Adds
decdn-protocolpublic API snapshot test and baseline. - Adds workspace dev-dependencies and a
public-api-testgated test target. - Adds CI and contributor documentation for running/updating the snapshot.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
crates/protocol/tests/public_api.rs |
New public API snapshot test using pinned nightly rustdoc JSON generation. |
crates/protocol/tests/snapshots/public_api__public_api.snap |
Initial baseline for the exported decdn-protocol API surface. |
crates/protocol/Cargo.toml |
Adds dev-dependencies, feature gate, and required-feature test target. |
Cargo.toml |
Adds centralized workspace dependencies for the snapshot tooling. |
Cargo.lock |
Locks new direct and transitive dependencies. |
CONTRIBUTING.md |
Documents how to run and update the public API snapshot. |
.github/workflows/ci.yml |
Adds the PR-blocking public API CI job and wires it into CI success. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 89.49% (was 89.49%, ● 0.00%) — 23784/26577 lines No coverage data for changed Rust files. History
|
…304) Snapshot `decdn-protocol`'s exported surface (wire types, ALPN definitions) with `public_api` + `insta` so any unintended change to the public API fails CI and surfaces as a reviewable `.snap` diff instead of breaking a downstream consumer's build. Scoped to `decdn-protocol` only per the issue's 2026-05-16 re-assessment; other crates stay deferred until their surfaces settle. - Add dev-deps (`public-api`, `rustdoc-json`, `insta`) via the workspace's centralized `[workspace.dependencies]`. - Gate the test behind a `public-api-test` feature + `required-features` test target so it stays out of the default `cargo nextest --workspace` coverage run. - Write the test anti-panic compliant (`?` + `Result`, no `unwrap`), satisfying the workspace `unwrap_used`/`panic` clippy denies without a per-module allow. - No nightly toolchain. `public-api` parses rustdoc JSON, nominally a nightly-only feature, but we emit it with the workspace's pinned *stable* toolchain by passing `RUSTC_BOOTSTRAP=1` to the spawned `cargo rustdoc`. This is deterministic and more stable than tracking `nightly`: the rustdoc-JSON `format_version` is frozen to whatever our pinned stable emits (57, matching the `rustdoc-types` 0.57.x `public-api` parses). It also sidesteps the MSRV collision — `public_api::MINIMUM_NIGHTLY_RUST_VERSION` is rustc 1.90, which cargo rejects against the workspace `rust-version = "1.95"`. - Add a dedicated, PR-blocking `public-api` CI job (clean env, same pinned stable toolchain) wired into `ci-success` needs + allowed-skips. - Document the update workflow in CONTRIBUTING.md. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
3e609a8 to
a22ef76
Compare
The `public-api` job gates on the `rust` paths-filter, which matched no snapshot files — so a PR hand-editing only the committed `*.snap` baseline would skip the job that validates it and merge a stale/incorrect baseline. Add `**/*.snap` to the rust filter to close the bypass. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
What
Adds a
public_api+instasnapshot test guardingdecdn-protocol's exported surface (wire types, ALPN definitions). Any unintended change to the public API now fails CI and shows up as a reviewable.snapdiff instead of breaking a downstream consumer's build.Scoped to
decdn-protocolonly, per the issue's 2026-05-16 re-assessment.cache,gossip,incentive,reputationstay deferred until their surfaces settle;node/cliare binaries and excluded. Closes theprotocol-only deliverable of #304 (issue stays open for the deferred crates).How
Dev-deps (
public-api,rustdoc-json,insta) added via the workspace's centralized[workspace.dependencies].cargo denypasses (all MIT/Apache-2.0).Feature-gated behind
public-api-test+ arequired-featurestest target, so it stays out of the defaultcargo nextest run --workspacecoverage run.Anti-panic compliant: written with
?+Result<(), Box<dyn Error>>, nounwrap/expect— satisfies the workspace clippy denies without a per-module allow.No nightly toolchain.
public-apiparses rustdoc JSON, which is nominally a nightly-only feature (-Z unstable-options --output-format json). Instead of pulling nightly into the project, the test emits the JSON with the workspace's pinned stable toolchain by passingRUSTC_BOOTSTRAP=1to the spawnedcargo rustdoc. This is:format_versionis frozen to whatever our pinned stable emits (57, matching therustdoc-types0.57.x thatpublic-apiparses), rather than drifting withnightly.~/.rustupcache step, no pinned-date/cache-key sync.public_api::MINIMUM_NIGHTLY_RUST_VERSIONis rustc 1.90, which cargo rejects against ourrust-version = "1.95".The one coupling to watch: a deliberate workspace toolchain bump can change rustdoc's JSON
format_version, which may require bumpingpublic-apiand regenerating the.snapin the same PR (documented in the test header).CI: dedicated, PR-blocking
public-apijob on the same pinned stable toolchain, wired intoci-successneeds+allowed-skips.Docs: update workflow added to
CONTRIBUTING.md§ Public API snapshot.Resolves the issue's open questions: per-crate test, all-features pass (protocol has no feature-gated public items today).
Update workflow
The
.snapdiff must land in the same PR as the API change.Verification
cargo nextest run -p decdn-protocol --features public-api-test— passes on stable against committed baseline (~7s)cargo nextest list --workspace— snapshot test absent from default runcargo clippy -p decdn-protocol --features public-api-test --all-targets -- -D warnings— cleancargo deny check— advisories/bans/licenses/sources okcargo fmt --all --check— cleanpub consttolib.rsfails the snapshot with the exact added line; reverts clean🤖 Generated with Claude Code