Skip to content

Check in rustfmt.toml and enforce formatting in CI - #190

Merged
aterga merged 3 commits into
mainfrom
arshavir/clever-allen-1bstzr
Sep 3, 2026
Merged

aterga merged 3 commits into
mainfrom
arshavir/clever-allen-1bstzr

Conversation

@aterga

@aterga aterga commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

CONTRIBUTING.md and this template both ask for cargo fmt --all before opening a PR, and the coding guidelines ask contributors to "keep the tree rustfmt-clean" — but no rustfmt.toml was checked in anywhere, and the tree was not clean. On stable 1.94.1 the documented step rewrote 18 files (4473 insertions, 1202 deletions), because rustfmt's stock fn_call_width/chain_width of 60 split the calls and method chains this codebase keeps on one line.

Following the instructions therefore meant either shipping a whole-repo reformat or hand-matching the surrounding style and skipping the step — which is what happened while preparing #189, where cargo fmt had to be reverted and the added lines matched by hand.

This checks in a config, applies the residual reformat it wants as its own commit, and adds a CI check so the drift cannot recur.

Important

The original config could not be recovered, because the tree was never rustfmt output. Please read "Why this config" below before reviewing the reformat — if you format with a toolchain or editor setting that is not in the repo, that config should be preferred over this one and the reformat redone against it.

Related issues

Follow-up to the formatting problem found while preparing #189.

Why this config

A coordinate-descent sweep over every stable rustfmt width knob — max_width, all six use_small_heuristics sub-widths, fn_params_layout, style_edition, ~0.4 s per trial, run to convergence — cannot make the tree clean:

Config Residual diff (lines)
No config (today) 10193
max_width = 100 (= the default) 10193
max_width = 100 + use_small_heuristics = "Max" (this PR) 6296
Best fit, max_width pinned to 100 5714
Best fit, max_width free 5992 (at max_width = 120)

It bottoms out around 5700 because the tree is hand-formatted to an approximate 100-column target, not machine-formatted. The decisive evidence: 403 checked-in lines exceed 100 columns, and some are ordinary breakable code, e.g. crates/imcp2-core/src/calls.rs:383 at 103 columns —

pub async fn resolve_did(agent: &Agent, canister: Principal, provided: Option<&str>) -> Option<String> {

rustfmt would never emit that at max_width = 100, and at max_width = 120 it joins hundreds of correctly-split lines elsewhere. So no config reproduces the tree, and the best-fitting one (fn_call_width = 95, chain_width = 75, struct_lit_width = 40, array_width = 90, single_line_if_else_max_width = 80) is a curve fit to inconsistent hand formatting rather than a style anyone chose — five magic numbers to buy 9 % less churn.

So the two settings here are the ones defensible on their own:

  • max_width = 100 — the budget the code is visibly written to; the line-length histogram falls off a cliff there (835 lines at 90–99, then 296, 73, 36 …).
  • use_small_heuristics = "Max" — the widened call/chain widths, which is exactly the difference identified in the report. The example line survives intact: src/metrics.rs:203 is still self.requests.with_label_values(&[route, method, &status]).inc();.

Being unable to recover the original config does not leave the repo stuck: one reviewed reformat ends drift that otherwise recurs for every contributor.

Changes

Two commits, deliberately separate so the reformat is reviewable on its own:

  • rustfmt.toml + residual reformat (25 files, 1661 insertions, 1482 deletions — against 4473/1202 with no config). Whitespace, line breaks and rustfmt's import ordering only; no behavioral change of any kind. The file carries comments explaining both settings and why they are one decision.
  • A fmt job in .github/workflows/ci.yml running cargo fmt --all -- --check. Its own job rather than a step in test, so a formatting nit does not hide the test results or vice versa; it compiles nothing, so it finishes in seconds in parallel and adds no wall-clock. No new third-party action — it reuses actions/checkout at the same pinned SHA as the other jobs and takes rustfmt from the runner's rustup, as they take cargo.

One tradeoff recorded in the workflow comment: the job tracks rolling stable, matching the sibling jobs, so a stable release that changes rustfmt's output can turn it red with no code change. The fix then is to re-run cargo fmt --all and commit, not to pin.

Testing

  • cargo build --locked --all-targets
  • cargo test --locked --all-targets — 270 tests pass, identical to main
  • cargo fmt --all / cargo clippy --all-targets — 11 clippy warnings, byte-identical count before and after the reformat, so all pre-existing and untouched by this PR
  • npm test --prefix monitoring/mcp-status — not run; the dashboard is unchanged

Verifying the stated goal on a fresh clone of this branch:

$ cargo fmt --all -- --check     # no output, exit 0 — no pending diff
$ cargo fmt --all                # the step CONTRIBUTING.md asks for
$ git status --porcelain | wc -l
0                                # touches no unrelated files

Also checked: formatting is idempotent (a second cargo fmt --all is a no-op), and the new CI job genuinely fails when deliberate drift is introduced — it was not just passing vacuously.

Checklist

  • I have read the Contributing guidelines.
  • Docs updated for any user-visible change — none needed: CONTRIBUTING.md's commands now work as written, so its text is correct without edits, and its "keep the tree rustfmt-clean" guideline becomes true and enforced rather than aspirational.
  • No secrets, credentials, or internal-only information are included.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FefdMpLRBQ7cLihuQsi3Mf


Generated by Claude Code

aterga and others added 2 commits September 3, 2026 13:01
CONTRIBUTING.md and the pull request template both ask for `cargo fmt
--all` before opening a PR, and the coding guidelines ask to "keep the
tree `rustfmt`-clean" — but no rustfmt config was checked in anywhere, and
the tree was not clean. On stable 1.94.1 the documented step rewrote 18
files (4473 insertions, 1202 deletions): rustfmt's stock `fn_call_width`
and `chain_width` of 60 split the calls and method chains this codebase
keeps on one line. Following the instructions therefore meant either
shipping a whole-repo reformat or hand-matching the surrounding style and
skipping the step, which is what happened while preparing #189.

No configuration reproduces the tree exactly, because the tree was never
rustfmt output. A coordinate-descent sweep over every stable width knob
(`max_width`, the six `use_small_heuristics` sub-widths, `fn_params_layout`,
`style_edition`) bottoms out around 5700 residual diff lines, and the
best-fitting combination is a curve fit to inconsistent hand formatting
rather than a style anyone chose. 403 checked-in lines exceed 100 columns,
among them breakable code such as `resolve_did` in `calls.rs` at 103 — a
signature rustfmt would never emit at `max_width = 100`.

So this checks in the two settings that are defensible on their own: the
100-column budget the code is visibly written to (the line-length
histogram falls off a cliff there), and the widened heuristics that keep
chains intact, which is the difference the report of this problem
identified. Being unable to recover a config does not leave the repo
stuck: one reviewed reformat ends drift that otherwise recurs for every
contributor.

The residual reformat those settings still want is applied here and
nothing else, so it is reviewable on its own — 25 files, 1661 insertions,
1482 deletions, against 4473/1202 with no config at all. Purely
whitespace and line breaks plus rustfmt's import ordering; `cargo build`,
`cargo test` (270 tests) and the 11 pre-existing clippy warnings are
unchanged. After it, `cargo fmt --all -- --check` is clean and idempotent
on a fresh clone.

If maintainers format with a toolchain or editor setting that is not in
the repo, that config should be preferred over this one — it can be
swapped in and the reformat redone against it.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FefdMpLRBQ7cLihuQsi3Mf
CI ran build, test, the PocketIC e2e suite and the internal-identifier
scan, but nothing checked formatting — so the rustfmt-clean tree
CONTRIBUTING.md asks for was a request with no enforcement behind it, and
it had already stopped being true. Checking in `rustfmt.toml` fixes the
tree once; this is what keeps it fixed, because without it the drift just
recurs and the next contributor to run the documented `cargo fmt --all`
inherits someone else's reformat.

A separate `fmt` job rather than a step in `test`: the two failures are
independent and each should stay readable when the other fires, and since
the job compiles nothing it runs in seconds in parallel, adding no
wall-clock. `--check` only reports, never rewrites, and the local
reproduction is the `cargo fmt --all` already documented.

No new third-party action: this reuses `actions/checkout` at the same
pinned SHA as the other jobs, and takes rustfmt from the runner's rustup
like they take cargo. The toolchain is rolling `stable`, matching the
sibling jobs, which does mean a stable release that changes rustfmt's
output can turn this red with no code change — the comment records that
the fix then is to re-run `cargo fmt --all`, not to pin.

Verified against this branch: the check passes on the formatted tree, and
fails as intended when deliberate drift is introduced.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FefdMpLRBQ7cLihuQsi3Mf
@aterga
aterga requested a balanced review from Copilot September 3, 2026 13:19
@aterga
aterga marked this pull request as ready for review September 3, 2026 13:19
@aterga
aterga requested a review from a team September 3, 2026 13:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The only unresolved comment is a non-blocking grammar nit.

Pull request overview

Adds workspace-wide rustfmt configuration, reformats Rust sources, and enforces formatting in CI.

Changes:

  • Adds rustfmt.toml with a 100-column width and maximum small-item heuristics.
  • Applies formatting across the workspace.
  • Adds a dedicated CI formatting check.
File summaries
File Description
tests/routers.rs Applies formatting.
src/metrics.rs Applies formatting.
src/main.rs Applies formatting.
src/lib.rs Applies formatting and import ordering.
src/e2e_handshake.rs Applies formatting.
rustfmt.toml Defines workspace formatting rules.
crates/imcp2-local/src/setup.rs Applies formatting.
crates/imcp2-local/src/server.rs Applies formatting.
crates/imcp2-local/src/main.rs Applies formatting.
crates/imcp2-local/src/login/tests.rs Applies formatting.
crates/imcp2-local/src/login/slot.rs Applies formatting.
crates/imcp2-local/src/login/routes.rs Applies formatting.
crates/imcp2-local/src/login/mod.rs Applies formatting.
crates/imcp2-local/src/e2e_local_login.rs Applies formatting.
crates/imcp2-core/src/tools.rs Applies formatting and import ordering.
crates/imcp2-core/src/skills.rs Applies formatting.
crates/imcp2-core/src/management.rs Applies formatting.
crates/imcp2-core/src/lib.rs Applies import/export ordering.
crates/imcp2-core/src/iiconnect.rs Applies formatting.
crates/imcp2-core/src/identities.rs Applies formatting.
crates/imcp2-core/src/e2e_canister_tools.rs Applies formatting.
crates/imcp2-core/src/discoverability.rs Applies formatting.
crates/imcp2-core/src/discover.rs Applies formatting.
crates/imcp2-core/src/compliance.rs Applies formatting.
crates/imcp2-core/src/calls.rs Applies formatting and import ordering.
.github/workflows/ci.yml Adds the formatting job; minor grammar nit: use “a rustfmt-clean” instead of “an rustfmt-clean.”
Review details
  • Files reviewed: 27/27 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread .github/workflows/ci.yml Resolved
Review nit: "an rustfmt-clean tree" should be "a rustfmt-clean tree" —
`rustfmt` starts with a consonant sound, so "an" is wrong. Comment text
only; the job itself is unchanged.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FefdMpLRBQ7cLihuQsi3Mf
Copilot AI review requested due to automatic review settings September 3, 2026 13:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The reviewed changes have no unresolved issues blocking approval.

Review details
  • Files reviewed: 27/27 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@aterga
aterga merged commit 82ca952 into main Sep 3, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants