Skip to content

refactor: consolidate Rust boilerplate and move runtime modules - #617

Open
pgherveou wants to merge 10 commits into
mainfrom
refactor/rust-review-fixes
Open

refactor: consolidate Rust boilerplate and move runtime modules#617
pgherveou wants to merge 10 commits into
mainfrom
refactor/rust-review-fixes

Conversation

@pgherveou

@pgherveou pgherveou commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

Replace handwritten declarative trait implementations with existing derives, share metadata macro expansion and platform-codegen traversal, and move runtime implementations/tests into modules. The nine commits separate each mechanical change; all 14 moved capability implementation bodies are byte-for-byte unchanged.

Validation:

  • cargo test --workspace --all-features --locked --offline: 1,260 passed, 20 ignored.
  • cargo +nightly clippy --workspace --all-targets --all-features -- -D warnings: passed.
  • Nightly formatting and the existing codegen golden/idempotence checks: passed.

The derive commit explicitly calls out redacted session Debug output and wrapped error-source propagation. The WASM generator cleanup changes only temporary argument allocation. No wire IDs or payload layouts change.

Review follow-up validation: all 833 server tests pass with all features, including the optional-secret redaction regression. Workspace Clippy (all targets/features), WASM server Clippy, and nightly formatting pass. Capability dependencies are explicit imports; all 14 implementation bodies remain unchanged.

Reuse derive_more Debug, Display and Error, standard Default, zeroization derives, and thiserror conversions already established in the workspace. Field annotations retain secret redaction and selective wiping; optional mnemonic Debug still distinguishes None from a redacted Some.

Session Debug now redacts entropy/private keys. Derived wrapped errors expose their sources. No session, authorization, storage, or transport control flow changes.
Extract the common pallet-call, constant and storage-value macro expansion used by metadata V14, V15 and V16. Keep version-specific extrinsic extensions and V16 view functions explicit. This removes repeated token expansion without changing collection order or decoded metadata.
Move the existing Rust bridge traversal into platform_callbacks and reuse it from the TypeScript callback emitter. Preserve the fixed-point walk over local aliases, fields, enum variants, stream items, and generic arguments; only the TypeScript boundary converts borrowed names into owned strings. Protocol normalization and frame-ID policy remain unchanged.
Keep owned argument vectors for asynchronous bridge calls and emit stack-backed slices for synchronous calls. Both use the same argument-expression builder. Update the generated bridge and golden fixture; callback payload encoding and invocation order stay the same.
Replace the unnamed platform/chat/permission-status tuple with a struct and destructure it at the two callers. Remove a redundant borrow and flatten an equivalent error-extraction conditional. Optional-adapter detection and runtime construction are unchanged.
Move existing product-facing trait implementations into capability modules and move the shared runtime fixture and signing tests into test modules. Preserve method bodies, validation order, visibility, and error mapping. No authorization helper extraction or lifecycle change is included in this commit.
@pgherveou
pgherveou force-pushed the refactor/rust-review-fixes branch from e03045d to 8e0f50f Compare September 6, 2026 06:01
@pgherveou pgherveou changed the title wip cleanup refactor: consolidate Rust boilerplate and move runtime modules Sep 6, 2026
@pgherveou

Copy link
Copy Markdown
Collaborator Author

@lore-bot-app review

@lore-bot-app

lore-bot-app Bot commented Sep 7, 2026

Copy link
Copy Markdown

Reading the diff and checking what the record says. Back in a few minutes.

@pgherveou
pgherveou marked this pull request as ready for review September 7, 2026 08:13
@pgherveou
pgherveou requested a review from a team September 7, 2026 08:13

@lore-bot-app lore-bot-app Bot 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.

TL;DR
Mechanical refactor: handwritten Debug/Display/Error/Drop/Default impls become derives, duplicated codegen and metadata-macro code is shared, and the 14 ProductRuntimeHost trait impls plus their tests move out of runtime.rs into runtime/capabilities/* and runtime/tests*. 0 blocking, 4 minor.

Summary
The diff replaces manual trait impls with derive_more (Debug with per-field #[debug("\"<redacted>\"")] for secret fields, Display, Error), zeroize::ZeroizeOnDrop, thiserror #[from], and #[derive(Default)]; extracts collect_local_bridge_payload_types into platform_callbacks.rs so the Rust WASM bridge and TS host-callback generators share one traversal; borrows sync JS callback args as &[..] instead of &vec![..]; factors a collect_pallets! macro out of the two metadata macros; and moves every product-facing capability impl into its own module under runtime/capabilities/, with tests moved to runtime/tests.rs and runtime/tests/signing.rs. I verified the move mechanically against the merge base (696fd73): all 14 impl blocks are byte-identical apart from module headers and one blank line in payment.rs, and test count is unchanged (120 before, 98 + 22 after). Four files were truncated from the diff I was given: runtime/tests.rs, runtime/tests/signing.rs, wasm.rs, wasm/generated_bridge.rs. I did not review the test bodies. From the local checkout, wasm.rs replaces a 3-tuple return with a WasmPlatformAdapters struct plus two clippy-style cleanups, and generated_bridge.rs is the 2-line &vec! to &[..] regeneration. I could not run cargo check/clippy in this sandbox, so compile and lint claims rest on the PR's own CI.

What the record says

  • This is PR #617, which Lore records as merged, with PR #618 stacked on it for the actual logic changes. The PR's claim that the 14 moved bodies are byte-for-byte identical checks out.
  • The move invalidates line anchors in the open issue #343 ("short-circuit confirmation gates at runtime.rs:1316, :1369, :1422"). Those gates now live in runtime/capabilities/signing.rs.
  • The repo's AGENTS.md asks for derive_more::Display over handwritten fmt::Display. This PR applies the same rule to Debug and Error, which is consistent with it.
  • Lore has no prior discussion of the Debug-redaction or zeroize design in truapi-host-cli, or of splitting runtime.rs. The record is silent there.

Concerns

  1. rust/crates/truapi-server/src/runtime.rs:828, :1006, :1236. Comments describing the Account, Chain, "Deferred product surfaces", and Notifications impls stayed behind after the impls moved and now sit above unrelated code (connected_session_ui_info, the PAYMENTS_NOT_IMPLEMENTED const, mod tests;). CLAUDE.md says comments describe only the current code. Move each to its impl in the capability module or delete it.
  2. rust/crates/truapi-server/src/host_logic/session.rs:32 and :38. #[debug("\"<redacted>\"")] on Option<[u8; 32]> prints the same text for None and Some, so a log line can no longer show whether a session has an entropy source or chat key. The same PR keeps the Option shape for ResolveSignerConfig::mnemonic in accounts.rs:88. Suggest the same pattern here so "Session secret missing" stays diagnosable.
  3. docs/issue-drafts/bulletin-preimage-in-core.md:306 still points Preimage::submit at truapi-server/src/runtime.rs; it is now in runtime/capabilities/preimage.rs. CLAUDE.md asks for an rg of old paths on every move.
  4. rust/crates/truapi-codegen/src/platform_callbacks.rs:210. collect_local_bridge_payload_types became pub(crate) without a doc comment. Its siblings to_camel_case and snake_case have one, and CLAUDE.md requires one on every pub item.

Questions for the author

  • The capability modules import the parent with use super::super::*;, so they depend on runtime.rs keeping every type import alive. Is that the intended long-term shape, or a stopgap until #618 lands and the modules get explicit imports?

Next: fix the three stale comment blocks in runtime.rs (about 5 minutes), then the Option redaction in session.rs.


🤖 Reviewed by Lore (Parity knowledge base) · 68 agent turns · 656.1s · knowledge as of 2026-09-07

Comment thread rust/crates/truapi-server/src/runtime.rs Outdated
Comment thread rust/crates/truapi-server/src/host_logic/session.rs Outdated
Comment thread rust/crates/truapi-codegen/src/platform_callbacks.rs
Keep capability descriptions beside their implementations, remove the obsolete deferred-surface narrative, and update the preimage draft and runtime layout documentation. Document the shared bridge traversal and its transitive payload closure. A repository-wide search found no other references to runtime.rs that need updating.
Use the existing derive_more Option redaction pattern for session entropy and chat keys. Debug retains None versus Some while redacting secret bytes, matching the CLI mnemonic diagnostic behavior. Test all four presence combinations in compact and alternate Debug output; all session tests pass.
Import protocol envelopes, platform types, and authority requests directly in each capability module. Shared runtime helpers remain explicit imports from their owner; the runtime no longer serves as an implicit prelude for every adapter. Move test-only protocol imports beside the fixtures.

All 14 capability implementation bodies remain byte-for-byte unchanged. The server all-features suite passes 833 tests, and workspace Clippy passes for every target and feature with warnings denied.
@pgherveou

Copy link
Copy Markdown
Collaborator Author

@copilot resolve the merge conflicts in this pull request

…fixes

# Conflicts:
#	rust/crates/truapi-server/src/wasm/generated_bridge.rs

Co-authored-by: pgherveou <521091+pgherveou@users.noreply.github.com>

Copilot AI commented Sep 7, 2026

Copy link
Copy Markdown

@copilot resolve the merge conflicts in this pull request

Resolved the merge conflict by accepting main’s removal of the generated WASM bridge, then finalized merge commit c268ec8. The generated outputs are recreated by scripts/codegen.sh; the truapi-server all-features test suite passes after generation.

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.

2 participants