Skip to content

fix(sdk): M1 SDK sweep fixes - macro hardening, doc fidelity#246

Merged
mfw78 merged 3 commits into
dev/m1from
fix/m1-sdk-sweep
Jul 15, 2026
Merged

fix(sdk): M1 SDK sweep fixes - macro hardening, doc fidelity#246
mfw78 merged 3 commits into
dev/m1from
fix/m1-sdk-sweep

Conversation

@mfw78

@mfw78 mfw78 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

What

Rewrites docs/migration/0.1-to-0.2.md section 7 to match the SDK surface that actually shipped (0.2 ships host traits, typed errors, and the single #[nexum_sdk::module] attribute; 0.1 never had an SDK crate at all), and adds an explicit note that Signer/Messaging/RemoteStore/provider()/#[shepherd::module] never shipped. Retargets doc 05's cross-link text from "rename table" to "what changed".

Hardens the #[nexum_sdk::module] macro (crates/nexum-macros/src/lib.rs) to reject, each with a targeted compile error, any on_-prefixed method not in the HANDLERS set (previously a silent no-op for typo'd handlers), trait impls, generic impls, and impls with zero recognised handlers.

Qualifies doc 05's testing-story claim to the SDK side of things, documenting nexum-runtime's feature-gated test_utils::TestRuntime as the separate in-tree component-level harness that sits outside the module-author SDK contract. Also corrects doc 05's CowApiHost parenthetical (submit_order, cow_api_request), the crate trees, and the first #[nexum::module] mention to name the real nexum_sdk path.

Adds an "Authoring a module" section to docs/sdk.md documenting the #[nexum_sdk::module] attribute and its handler set, and includes nexum-macros in the rustdoc command.

Why

Stacked QA fixes for the M1 SDK sweep (part of #136): the migration doc and doc 05 had drifted from what actually shipped, and the module macro silently swallowed typo'd or malformed handler methods instead of failing at compile time. Fixing both keeps the docs trustworthy for module authors and closes a real correctness gap in the macro. This PR is stacked on docs/m1-sdk-design-rewrite (its base branch).

Testing

All run inside nix develop --command, with --locked and --config 'build.target-dir="/code/nxm/runtime/target"':

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • RUSTDOCFLAGS=-D warnings cargo doc --workspace --no-deps
  • cargo build --release --target wasm32-wasip2 for example, twap-monitor, ethflow-watcher, price-alert, balance-tracker, stop-loss, flaky-bomb, fuel-bomb, memory-bomb
  • cargo test --workspace --all-features --no-fail-fast
  • Probe-verified the macro's new compile errors for a typo'd handler, a trait impl, a generic impl, and a zero-handler impl

AI Assistance

Claude (Opus) used for the implementation.

@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from edd46ba to af4a126 Compare July 7, 2026 23:12
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from 4cff6f2 to b13ab15 Compare July 7, 2026 23:12
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from af4a126 to ef2e37a Compare July 8, 2026 00:42
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from b13ab15 to 769b1a1 Compare July 8, 2026 00:42
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from ef2e37a to f33abe9 Compare July 8, 2026 01:19
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from 769b1a1 to ce23c56 Compare July 8, 2026 01:19
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from f33abe9 to 41018ab Compare July 8, 2026 01:44
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from ce23c56 to 3f4c6da Compare July 8, 2026 01:44
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from 41018ab to 1554feb Compare July 8, 2026 02:10
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from 3f4c6da to 69fcae9 Compare July 8, 2026 02:10
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from 1554feb to 9285d37 Compare July 8, 2026 02:19
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from 69fcae9 to ddc7774 Compare July 8, 2026 02:19
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from 9285d37 to ceab8bd Compare July 8, 2026 02:22
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from ddc7774 to a640b7a Compare July 8, 2026 02:23
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from ceab8bd to eaab2ce Compare July 8, 2026 03:03
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from a640b7a to 2176ef6 Compare July 8, 2026 03:03
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from eaab2ce to 6168e79 Compare July 8, 2026 04:59
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from 2176ef6 to 851e779 Compare July 8, 2026 04:59
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from 6168e79 to 319f48e Compare July 8, 2026 05:31
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from 851e779 to a35e537 Compare July 8, 2026 05:31
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from 319f48e to 93b1a7d Compare July 8, 2026 06:21
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from a35e537 to 7f4ee70 Compare July 8, 2026 06:21
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from 93b1a7d to bfd97b4 Compare July 8, 2026 06:40
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from 7f4ee70 to e5454cd Compare July 8, 2026 06:40
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from bfd97b4 to 6c22e84 Compare July 8, 2026 07:06
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from e5454cd to a7ba3d3 Compare July 8, 2026 07:07
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from 6c22e84 to 489bea6 Compare July 8, 2026 07:21
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from a7ba3d3 to 565c768 Compare July 8, 2026 07:21
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from 489bea6 to 078faf1 Compare July 8, 2026 07:36
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from 565c768 to 296102e Compare July 8, 2026 07:36
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from 7044e1f to 127ccf3 Compare July 8, 2026 09:02
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from 90f051f to 9e2a2ce Compare July 8, 2026 09:02
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from 127ccf3 to 7f54893 Compare July 8, 2026 09:18
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from 9e2a2ce to 978b1bd Compare July 8, 2026 09:18
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from 7f54893 to aafc6bb Compare July 8, 2026 12:10
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from 978b1bd to 9d1db95 Compare July 8, 2026 12:10
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from aafc6bb to e73d859 Compare July 8, 2026 12:20
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from 9d1db95 to ff616ec Compare July 8, 2026 12:20
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from e73d859 to 23b9b9b Compare July 8, 2026 12:49
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from ff616ec to 73029f4 Compare July 8, 2026 12:50
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from 23b9b9b to cc9d464 Compare July 8, 2026 13:40
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from 73029f4 to 374d085 Compare July 8, 2026 13:40
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from cc9d464 to f21768f Compare July 8, 2026 13:59
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from 374d085 to 5740e54 Compare July 8, 2026 13:59
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from f21768f to ac21033 Compare July 8, 2026 14:08
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from 5740e54 to a8430a4 Compare July 8, 2026 14:08

@lgahdl lgahdl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good hardening. Three items below.

Comment on lines +42 to 45
/// namespace), and the crate root must not shadow std prelude names
/// such as `Result`, `Vec`, or `Ok` (wit-bindgen's generated `Guest`
/// trait refers to them unqualified).
#[proc_macro_attribute]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The second corollary may be inaccurate: the macro's own quote! output already uses ::core::result::Result, ::std::vec::Vec, and ::core::result::Result::Ok — fully qualified paths — so shadowing those names in the crate root would not break the macro-emitted code. The constraint, if real, comes from the wit_bindgen::generate! expansion itself, not from "wit-bindgen's generated Guest trait" broadly. Worth verifying which names generate! actually emits unqualified before documenting this as a constraint; if it turns out the expansion is also hygienic, the corollary can be dropped.

Suggested change
/// namespace), and the crate root must not shadow std prelude names
/// such as `Result`, `Vec`, or `Ok` (wit-bindgen's generated `Guest`
/// trait refers to them unqualified).
#[proc_macro_attribute]
/// `CARGO_MANIFEST_DIR`. One corollary: the consuming crate must
/// declare `wit-bindgen` as a direct dependency (the emitted
/// `wit_bindgen::generate!` call resolves against the consumer's
/// namespace, not `nexum-macros`'s).

Comment on lines +93 to +96
format!(
"`{name}` is not a recognised #[nexum_sdk::module] handler; expected one \
of {HANDLERS:?} (rename helpers so they do not start with `on_`)"
),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The error tells the user to rename, but the lower-friction fix is to move the helper to a separate impl block — the macro only inspects the single attributed impl. A user with a well-named on_retry_cooldown_expired helper would prefer that over renaming.

Suggested change
format!(
"`{name}` is not a recognised #[nexum_sdk::module] handler; expected one \
of {HANDLERS:?} (rename helpers so they do not start with `on_`)"
),
format!(
"`{name}` is not a recognised #[nexum_sdk::module] handler; \
expected one of {HANDLERS:?}. Move helpers that start with \
`on_` to a separate `impl` block, or rename them."
),

synchronous `fn`s; there is no `async` support, no `block_on`, and
no separate `#[shepherd::module]`.

Earlier drafts of this section described a richer 0.2 surface

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

"Earlier drafts" is ambiguous — it reads as earlier commits of this file (stale docs) rather than features that were planned and cut. A reader who wrote code against those APIs gets a different message from each reading.

Suggested change
Earlier drafts of this section described a richer 0.2 surface
This section previously described a richer 0.2 surface

@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from ac21033 to 5281ffa Compare July 8, 2026 22:33
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch 2 times, most recently from 1795182 to f7f2f3a Compare July 8, 2026 23:05
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from 5281ffa to eeb9deb Compare July 8, 2026 23:05
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from f7f2f3a to 8d59644 Compare July 8, 2026 23:24
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch 2 times, most recently from 428db31 to e205b8b Compare July 8, 2026 23:29
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from 8d59644 to acaa0f8 Compare July 8, 2026 23:29
@mfw78 mfw78 force-pushed the docs/m1-sdk-design-rewrite branch from e205b8b to ef44329 Compare July 9, 2026 02:09
@mfw78 mfw78 force-pushed the fix/m1-sdk-sweep branch from acaa0f8 to 4e2ce66 Compare July 9, 2026 02:09
mfw78 added 3 commits July 15, 2026 00:08
A method named on_blocks (or any other on_-prefixed typo) previously
compiled as an ordinary helper while its event silently no-opped; the
only signal was a dead_code warning that vanishes on pub items.
Reserve the on_ prefix for the recognised handler set and error on
anything else.

Also reject trait impls, generic impls, and impls with no recognised
handlers - all previously slipped past the self-type guard and failed
later with incidental, unhygienic errors (or compiled into a do-nothing
module). Document the wit-bindgen direct-dependency and prelude-
shadowing invariants inherited from the generated glue.
Section 7 still described the superseded Signer/Messaging/RemoteStore/
provider() vision - APIs that never shipped - and a #[shepherd::module]
macro that does not exist, while doc 05 endorsed it as the authoritative
0.1 -> 0.2 SDK table. Replace it with the real story: 0.1 had no SDK
crate, 0.2 ships nexum-sdk/shepherd-sdk host traits, typed errors, and
the single #[nexum_sdk::module] attribute. Point doc 05's cross-link
text at what the section now says, and fix doc 05 details flagged by
the sweep: the CowApiHost parenthetical (submit_order, cow_api_request),
the crate trees (proptests.rs in both SDK crates), the testing-story
claim (nexum-runtime's feature-gated test_utils::TestRuntime is an
in-tree component-level harness), and the first #[nexum::module]
mention now names the real nexum_sdk path.
sdk.md is doc 05's designated day-to-day reference but still presented
the pre-macro bind_host_via_wit_bindgen! flow as the authoring pattern.
Add an authoring section covering the attribute and its handler set,
mention it in the intro, and include nexum-macros in the rustdoc
command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-train Part of the current stacked PR train; lands in sequence, do not merge out of order.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants