Rust-TOPS
Rust-TOPS (Rust Testing and Optimization Protocol Suite) is a protocol: a written spec, a JSON Schema, per-crate class floors, and the practice layer in POLICIES.md. This repository is the public kit for adopting that protocol.
It is for Rust library and binary authors, and for the people who own their CI, who want one gate order: lint, tests, coverage, CRAP, mutation on the diff, then the extra layers the crate class names.
Protocol 1.1.0 adds the laws layer (RUST_TOPS.md §3.1). It checks an adopting crate against the Bend2 laws pack under laws/. For each law, the runner reads one fact from the crate's files or this gate run's reports and picks a case. bend then judges the case file, one program that imports LAWS.bend. A Refuse fails the gate. Fifteen of the 53 laws have fact readers. The other thirty-eight are reported not-evaluated, never as a pass. On this repository, required CI also proves all 53 laws with Bend 2.0.36 (TOFU-pinned) and rechecks them with Lean 4.34.0.
Pins
| Plane | Pin | Where |
|---|---|---|
| Protocol | 1.1.0 | RUST_TOPS.md, schema/rust-tops.schema.json |
| Package | 0.2.0 in this tree | workspace Cargo.toml. The last publish is still 0.1.4: git tag v0.1.4, crates.io cargo-tops 0.1.4 |
| This package | edition 2021, MSRV 1.99.1 | Cargo.toml; the msrv job uses Rust 1.99.1. Compiling this package needs Rust 1.99.1, and Cargo stops on an older compiler before the build. |
| Crate page | 0.1.4 published; this tree is 0.2.0 | docs.rs/cargo-tops |
| Tool lock | rustc 1.91.0, cargo-nextest 0.9.145, cargo-crap 0.5.0, cargo-deny 0.18 | rust-tops.lock |
| Bend | 2.0.36 TOFU | laws/bend.lock. The upstream release is mutable and unsigned (no checksum file, no signatures, no attestations). |
| Lean | 4.34.0 TOFU | laws/bend.lock archive lean-4.34.0-linux.tar.zst, used by bend PROOF.bend --verdict. |
The tool lock is the version set used to evaluate gates. It is a different number from the MSRV. config/rust-tops.lock.example is the same pin list, for copying into an adopting crate.
Quick start
Copy the files
The example instance is a parser-codec sketch: edition 2024, MSRV 1.88. Replace crate.class, crate.edition, crate.msrv, coverage floors, exemptions, and hot_paths. The sample hot paths are not a file list of examples/parser-codec (that fixture has src/varint.rs and no src/frame.rs).
In the workflow, replace {MSRV}, {PRIMARY_PKG}, {SYSDEPS}, and {FFI_FEATURE}. The copied workflow is a floor. See POLICIES.md.
Or install the orchestrator
--class accepts library-core (the default), parser-codec, no-std-embedded, unsafe-kernel, or binary-cli. init writes rust-tops.yaml (protocol 1.1.0, laws layer enabled at tier 0), rust-toolchain.toml (channel = crate.msrv), AGENTS.md, the drop-in configs, a class workflow at .github/workflows/rust-tops.yml, LAWS.bend, laws/bend.lock, and scripts/fetch-bend.sh. It does not write rust-tops.lock. The generated instance still starts from the parser-codec example (edition 2024, MSRV 1.88).
check reads rust-tops.yaml and checks protocol id, a non-empty version, a crate name, gates.crap.threshold_agent >= 1, and that class library-core keeps unexplained_survivors_max at 0.
gate runs enabled layers at or below --max-tier (default 1). --dry-run prints the commands and does not run them. A mapped tool missing from PATH fails the gate. The laws layer runs last, on the reports the other layers wrote. When Bend 2.0.36 is absent, gate fetches it by laws/bend.lock first.
Nix
{
inputs.rust-tops.url = "github:Hedronite/rust-tops";
outputs = { nixpkgs, rust-tops, ... }:
let
pkgs = import nixpkgs {
system = "aarch64-darwin";
overlays = [ rust-tops.overlays.default ];
};
in {
packages.aarch64-darwin.default = pkgs.cargo-tops;
# pkgs.rust-tops-laws -> $out/share/rust-tops/laws
};
}
overlays.default exposes cargo-tops and rust-tops-laws. Flake systems are aarch64-darwin, x86_64-darwin, aarch64-linux, and x86_64-linux. Intel macOS follows input nixpkgs-darwin-x64 (nixpkgs-26.05-darwin). The other systems follow nixos-unstable. devShells.default includes cargo-tops, rustc, cargo, clippy, and rustfmt.
nix flake check builds both packages, runs law-catalog-names, and on Linux runs bend-proof (the real Bend proof, fetched by the lock sha256). Darwin has no bend-proof attribute: the Bun binary was not verified in the Nix darwin sandbox, and that name is never a names-only pass. No GitHub Actions job runs nix flake check, so Nix is local feedback, not a gate. bend-gate.sh checks names, template bytes, and the Bend version, then runs bend PROOF.bend. A missing bend exits 1. BEND_GATE_NAMES_ONLY=1 is the local names-only opt-in and prints NAMES-ONLY (not a proof).
What you get
| Cargo alone | This kit | |
|---|---|---|
| Contract | Docs and tests you arrange | Protocol 1.1.0 and a draft 2020-12 JSON Schema |
| Class floors | None | Five profile files; the schema allows eleven class names |
| Drop-in configs | None | clippy, nextest, mutants, cargo-crap, cargo-deny, GitHub Actions floor |
| Orchestrator | You sequence the commands | cargo tops init, check, and gate |
| CI on this repo | — | fmt-clippy-deny, nextest, msrv, feature-matrix, coverage-crap, bend-proof, bend-verdict, bend-gate-matrix, plus law-diff. bend-proof-macos is informational |
| CRAP config | — | .cargo-crap.toml: threshold 6.0; excludes src/generated/**, tests/**, benches/**, examples/** |
| Bend2 | — | 53 laws, H-01 through H-53. The laws layer has bend judge fifteen against your crate; thirty-eight are not-evaluated. Required CI on this repo proves all 53 |
| Nix | — | Overlay and packages cargo-tops, rust-tops-laws |
What you do not get
| Claim | Reality |
|---|---|
| A test engine | cargo-tops shells out to cargo fmt, Clippy, nextest, cargo llvm-cov, cargo-crap, cargo-mutants, and cargo-deny. |
JSON Schema validation from cargo tops check |
That command is the typed check in the quick start. Point a draft 2020-12 validator at schema/rust-tops.schema.json to check an instance. |
Fuzz, Miri, Kani, loom, sanitizers, or Callgrind from cargo tops gate |
Those layer ids have no command mapping. The gate prints skip and continues. |
| Mutants, Darwin, or fuzz jobs in this repo | They are comments in .github/workflows/rust-tops.yml. The feature matrix checks cargo-tops and parser-codec with --no-default-features, and no-std-embedded both with --no-default-features and with --features std. |
| Every law judged on your crate | Fifteen laws have fact readers. Thirty-eight, including evidence_not_self_served, are reported not-evaluated and never count as a pass (RUST_TOPS.md §3.1). The schema names the laws layer; the laws live in LAWS.bend. Hard rows encode as Refuse; soft rows as Ack. Catalog: BEND2-INTEGRATION.md. |
A green gate when bend is absent |
Missing bend exits 1 (H-37). Names-only is the explicit opt-in BEND_GATE_NAMES_ONLY=1, and CI refuses that variable. |
cargo tops init for every schema class |
The CLI classes are the five named above. The schema also lists library-util, binary-service, concurrency-runtime, ffi-bridge, proc-macro, and workspace-root. Those six have no profile file and no --class value. |
| Published example crates | examples/parser-codec and examples/no-std-embedded set publish = false. |
| A written gate report | schema/gate-report.schema.json describes an optional report object. The CLI prints text and does not write that object. |
How it works
Write the oracle from the contract, then the smallest production code that meets it. A test taken from the function body freezes current behavior, including bugs. Splitting a function only to lower its CRAP score violates the spec's scar-guard.
Order for a gated change, from RUST_TOPS.md:
cargo fmt, Clippy with-D warnings,cargo deny check.cargo nextest(profileci) andcargo test --doc.cargo llvm-covwriting LCOV, thentest -son that file.cargo crap --lcovagainst that LCOV. The drop-in threshold is 6.0. Pass--lcovon the CLI.fail = trueis not a cargo-crap config field.cargo mutants --in-diff. The gate diffsorigin/main...HEAD.- Property tests, fuzz, Miri, Kani, and Callgrind when the crate class requires them.
cargo tops gatehas no commands for this step.
The protocol cap for new human-authored code is CRAP 4. The cap for new code written by a coding agent is CRAP 6. A class table can set other numbers: profiles/binary-cli.yaml uses human 6 and agent 8. Coverage floors live in rust-tops.yaml. The drop-in workflow does not pass --fail-under-lines.
| Path | Role |
|---|---|
RUST_TOPS.md |
Normative protocol 1.1.0 |
schema/ |
Draft 2020-12 schema for an instance, and a separate optional gate-report schema |
POLICIES.md |
CI floor and the checks harvested from applying the protocol |
config/rust-tops.example.yaml |
Example parser-codec instance |
config/drop-in/ |
Files to copy into an adopting crate |
profiles/ |
library-core, parser-codec, binary-cli, no-std-embedded, unsafe-kernel |
crates/cargo-tops |
The cargo-tops binary. Published templates live in crates/cargo-tops/templates/ |
examples/ |
Fixtures: a small frame and varint codec, and a no_std ring buffer |
AGENTS.md |
Harness for coding agents editing a crate under the protocol |
BEND2-INTEGRATION.md |
Candidate laws and their sources. The laws layer is spec §3.1 |
laws/ |
LAWS.bend, PROOF.bend, NAMES (H-01..H-53) |
flake.nix |
Nix overlay |
CHANGELOG.md |
Package history. Protocol 1.1.0 and package 0.2.0 are separate version planes |
Status
This tree is package 0.2.0 and protocol 1.1.0. The release notes are CHANGELOG.md [0.2.0]. Git tag v0.2.0 and the crates.io publish are not part of this change. Published cargo-tops is still 0.1.4 (tag v0.1.4, protocol 1.0.0).
This repository's workflow runs format and Clippy, cargo deny, nextest, doc tests, an MSRV check on 1.99.1, the feature matrix above, and a coverage job that fails when lcov.info or the CRAP JSON is empty. It also runs bend-proof, bend-verdict, and bend-gate-matrix. law-diff is a separate workflow. The workspace lint unsafe_code = "forbid" applies to cargo-tops and both fixtures.
The Bend2 pack is 53 laws. scripts/bend-gate.sh checks names and template bytes, requires bend 2.0.36 from laws/bend.lock, and uses the exit code of bend PROOF.bend as the verdict. On an adopting crate, the laws layer judges fifteen of them with bend, and thirty-eight are not-evaluated (RUST_TOPS.md §3.1). Moving a law into RUST_TOPS.md takes an explicit spec bump. Public RUST_TOPS.md still stops at §24; the draft §25 review gate is not part of this package.
Current limits:
cargo tops gateruns the mapped commands through tier 1.cargo tops initcovers five classes. The other six names exist in the schema and the spec table.bend-gate.shexits 1 whenbendis absent.- The
lawslayer has fact readers for fifteen of the 53 laws. The rest arenot-evaluated. bend-proof-macosis informational. A large Bend pack can overflow the macOS stack; this job does not changeulimit.- Flake support for
x86_64-darwintracksnixpkgs-26.05-darwin, because thenixos-unstablepin dropped Intel macOS. Darwinchecks.bend-proofis absent.
Contributing
Read RUST_TOPS.md and schema/rust-tops.schema.json before changing a gate. When prose and schema disagree, fix the schema, then the prose.
POLICIES.md is the CI floor. AGENTS.md is the editing harness. Bend2 work starts at laws/README.md and BEND2-INTEGRATION.md. Leave a law as written; do not weaken it so a proof passes.
Package history is CHANGELOG.md.
Credits and license
Built by Hedronite. Licensed under MIT OR Apache-2.0, at your option. See LICENSE, LICENSE-MIT, and LICENSE-APACHE.
The CRAP formula is Change Risk Anti-Patterns (2007), cited in RUST_TOPS.md. Names such as cargo-llvm-cov, cargo-mutants, cargo-crap, nextest, and cargo-deny refer to those tools.