Skip to content

Add public API stability snapshot tests via the public_api crate #304

Closed

Description

@alpergundogdu

Goal

Catch unintended breaking changes to our public Rust API by snapshotting it with public_api + insta, so any diff to the exported surface shows up in code review instead of in a downstream consumer's build.

The intended test pattern (for reference, not a prescription):

// Run with `INSTA_UPDATE=always cargo test` to update the public API snapshot
#[test]
fn public_api() {
    rustup_toolchain::install(public_api::MINIMUM_NIGHTLY_RUST_VERSION).unwrap();

    let rustdoc_json = rustdoc_json::Builder::default()
        .toolchain(public_api::MINIMUM_NIGHTLY_RUST_VERSION)
        .all_features(true)
        .build()
        .unwrap();

    let public_api = public_api::Builder::from_rustdoc_json(rustdoc_json)
        .omit_auto_derived_impls(true)
        .omit_auto_trait_impls(true)
        .omit_blanket_impls(true)
        .build()
        .unwrap();

    insta::assert_snapshot!(public_api);
}

Note: the snippet uses .unwrap(), which our workspace clippy config denies (unwrap_used). Whoever picks this up will need to either gate the test module so the lint doesn't fire on test-only code, or rewrite with proper error propagation (? + Result<(), Box<dyn Error>>).

What needs to happen

  • Decide which crates get the snapshot test. decdn-protocol is the obvious first target: it's the leaf crate other workspace crates and (eventually) external consumers depend on, and it owns the wire types. cache, gossip, incentive, reputation are candidates once their surfaces stabilize. node is a binary, so excluded.
  • Add dev-dependencies to each in-scope crate: public-api, rustdoc-json, rustup-toolchain, insta.
  • Add the test (one per crate) and commit the initial *.snap baseline alongside it.
  • Reconcile with the workspace anti-panic policy — see note above on .unwrap().
  • CI: ensure a nightly toolchain is available on the runner. rustup_toolchain::install will fetch it on demand, but the build step is slow (rustdoc JSON generation) — consider caching ~/.rustup or pinning the nightly used by public_api::MINIMUM_NIGHTLY_RUST_VERSION in rust-toolchain.toml or a CI step.
  • Document the update workflow in CONTRIBUTING.md: `INSTA_UPDATE=always cargo nextest run -p ` (or cargo insta review) when a public API change is intentional, and that the snapshot diff must appear in the same PR as the API change.

Open questions

  • Run with --all-features only, or also a no-features pass? all_features(true) matches the snippet, but if any crate gets feature-gated public items we may want both.
  • Do we want a single root-level integration test that walks each crate, or per-crate tests? Per-crate keeps cargo nextest run -p <crate> self-contained, which matches how the rest of the workspace is structured.
  • How does this interact with cargo deny / pre-commit? Probably no interaction, but worth confirming the new dev-deps don't trip license checks.

Why now

We're still pre-1.0 and breakage is expected, but protocol is already cross-crate load-bearing and any silent change to wire types or ALPN message definitions is exactly the kind of regression that would be cheap to catch here and expensive to debug otherwise.

Activity

  1. added
    kind:feature
    rust
    kind:test
    on Apr 27, 2026
  2. alpergundogdu commented on Apr 27, 2026

    @alpergundogdu
    ContributorAuthor

    Worth flagging: probably premature to land this right now. The crates are still in early implementation — protocol is the most stable surface and even it's actively gaining wire types — so a snapshot test would diff on nearly every commit and become noise rather than signal. Better to revisit once the public surface of at least one crate (likely protocol) has settled enough that an unexpected diff is genuinely a red flag worth reviewing.

  3. self-assigned this
    on May 6, 2026
  4. added
    status:blocked
    on May 14, 2026
  5. thiras commented on May 16, 2026

    @thiras
    Contributor

    Stability re-assessment (2026-05-16) — partially unblockable, scope to protocol

    Revisiting the "probably premature" concern with data. Conclusion: this is now unblockable for decdn-protocol only. The blanket objection ("would diff on nearly every commit") is no longer empirically true for protocol, but remains fully valid for every other candidate crate.

    Per-crate stability

    Crate src lines pub decls src commits/30d Last functional change Verdict
    protocol 928 32 7 (4 docs/ADR-only) #396 2026-05-05 (rate bound) Snapshot-ready
    gossip 1403 32 9 #231 2026-04-17, still growing Borderline-blocked
    reputation 598 10 1 #468 2026-05-08 (EWMA just landed) Blocked — too unformed, not stable
    incentive 2323 42 3 #567 2026-05-15 (voucher persist) Blocked — core economics in flux
    cache 6226 80 22 #564 2026-05-15 Blocked — highest churn in workspace

    protocol's last public-signature change was #396 (2026-05-05) — added MessageValidationError/validate()/MAX_RATE_PER_MB, removed ALPN_WATCHTOWER. The last 11 days are docs/ADR-only. Caveat: the gossip submodule inside protocol (NodeAnnounce, GossipEnvelope, LoadHint) was added ~1 month ago (#231) but has been settled since.

    Note reputation's low churn is immaturity, not stability — ADR 008 EWMA scoring only just landed (#468). A snapshot there would lock in a surface that's about to grow; don't read the low commit count as "settled".

    Cross-cutting blockers (independent of crate choice)

    1. No nightly toolchain. rust-toolchain.toml pins stable 1.95.0 (rustfmt+clippy only). public_api needs nightly rustdoc-JSON. rustup_toolchain::install fetches on-demand but is slow/uncached — CI needs an explicit pinned nightly step. This is the most concrete remaining blocker.
    2. Anti-panic policy collision. The reference snippet's .unwrap() chain fails workspace clippy (unwrap_used). Needs ? + Result<(), Box<dyn Error>> or a test-module lint gate.
    3. New dev-deps vs cargo deny. public-api, rustdoc-json, rustup-toolchain, insta not in tree today; license/advisory clearance unverified (low risk, unconfirmed).

    Recommendation

    • Land the snapshot test for decdn-protocol only, with nightly pinned in CI (not on-demand) and the anti-panic rewrite.
    • Keep this issue open with other crates explicitly deferred; revisit each as its surface settles (cache is furthest out — most active crate in the workspace).
    • This also resolves the "single root test vs per-crate" open question: start per-crate, matching cargo nextest run -p <crate>.

    Suggest the blocked label be narrowed/removed and the issue re-scoped to protocol-only as the first deliverable.

  6. thiras commented on May 31, 2026

    @thiras
    Contributor

    Implemented in #734 (merged 2026-05-31, commit aaa87a2).

    Scoped to decdn-protocol per the issue's 2026-05-16 re-assessment; other crates remain deferred until their surfaces settle. Delivered:

    • Snapshot test crates/protocol/tests/public_api.rs + committed baseline crates/protocol/tests/snapshots/public_api__public_api.snap
    • Dev-deps (public-api, rustdoc-json, insta) via [workspace.dependencies]
    • Gated behind a public-api-test feature + required-features target so it stays out of the default cargo nextest --workspace run
    • Anti-panic compliant (? + Result, no unwrap); stable toolchain via RUSTC_BOOTSTRAP=1 (no nightly)
    • Dedicated PR-blocking public-api CI job, wired into ci-success
    • Update workflow documented in CONTRIBUTING.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:featurekind:testprio:lowruststatus:blocked

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions