Method translators: OSchema → hero_rpc2 trait + Python dataclass methods (#60) #63

Merged
timur merged 1 commit from pr-60-method-translators into development 2026-05-19 13:39:10 +00:00
Owner

Closes #60.

Implements the §2 method translators left as follow-ups from #55:

  • crates/generator/src/build/emit/rust_rpc2.rs — OSchema → #[method(name=…)] async fn …(&self, ctx: Option<HeroRequestContext>, …) -> RpcResult<T> with inline WASM-style types; compile_error! stub removed.
  • crates/generator/src/build/emit/python_sdk.rs — OSchema → @dataclass(kw_only=True) + async client methods via a generated UdsJsonRpcTransport (httpx-on-UDS); # TODO stub removed.
  • crates/hero_rpc2/src/context.rs — added Serialize/Deserialize to HeroRequestContext so the locked trait shape survives jsonrpsee's Params::parse.
  • example/recipe_sdk_rpc2/ — new workspace crate that drives both emitters end-to-end and hosts the Python round-trip test.

10 new emitter unit tests pass; recipe_sdk_rpc2 builds; Python system.ping round-trips over UDS.

Closes #60. Implements the §2 method translators left as follow-ups from #55: - `crates/generator/src/build/emit/rust_rpc2.rs` — OSchema → `#[method(name=…)] async fn …(&self, ctx: Option<HeroRequestContext>, …) -> RpcResult<T>` with inline WASM-style types; `compile_error!` stub removed. - `crates/generator/src/build/emit/python_sdk.rs` — OSchema → `@dataclass(kw_only=True)` + async client methods via a generated `UdsJsonRpcTransport` (httpx-on-UDS); `# TODO` stub removed. - `crates/hero_rpc2/src/context.rs` — added `Serialize`/`Deserialize` to `HeroRequestContext` so the locked trait shape survives jsonrpsee's `Params::parse`. - `example/recipe_sdk_rpc2/` — new workspace crate that drives both emitters end-to-end and hosts the Python round-trip test. 10 new emitter unit tests pass; `recipe_sdk_rpc2` builds; Python `system.ping` round-trips over UDS.
feat(emit): #60 — OSchema → hero_rpc2 trait + Python dataclass methods
Some checks failed
Test / test (push) Failing after 2m15s
Test / test (pull_request) Failing after 3m58s
13dde8faf5
Finishes the §2 hybrid SDK story from #55. The rust_rpc2 and python_sdk
emitters previously wrote stubs with `compile_error!` / `# TODO` markers;
this commit translates every OSchema service method into:

  * a `#[method(name = "<svc>.<m>")] async fn …(&self,
    ctx: Option<HeroRequestContext>, …) -> RpcResult<T>` entry inside the
    `#[rpc(server, client)]` trait, with inlined WASM-style types so the
    SDK crate stays self-contained (no `hero_rpc_osis` dep);

  * an `async def <svc>_<m>(self, …) -> T:` method on the generated
    Python `<Domain>Client`, dispatching through a small
    `UdsJsonRpcTransport` (`httpx.AsyncClient` over UDS) shipped next to
    the per-domain modules.

`hero_rpc2::context::HeroRequestContext` gains `Serialize` / `Deserialize`
(with `#[serde(default)]`) so the locked trait shape (ctx as first arg)
survives jsonrpsee's `Params::parse` deserialisation while the existing
header-lift transport stays interoperable (JSON `null` → `None`).

A new workspace crate `example/recipe_sdk_rpc2` consumes the
`example/recipe_server` schema through the new emitters end-to-end:

  * `cargo build -p recipe_sdk_rpc2` compiles the generated trait +
    inline types — the original acceptance "recipe_server compiles
    end-to-end with the generated Rust client";
  * `cargo test -p recipe_sdk_rpc2 --features python-e2e` spins up a
    `hero_rpc2` HTTP-on-UDS server with a hand-registered `system.ping`
    method, subprocesses Python through the *generated*
    `UdsJsonRpcTransport`, and asserts the round-trip — the original
    acceptance "Python SDK round-trips a system.ping over UDS." The
    test skips gracefully when `python3` / `httpx` aren't on PATH so CI
    on bare images stays green.

Unit-test coverage in both emitters now spans the acceptance matrix:
scalar params, struct params, list returns, and the `ctx: Option<…>`
first argument. Method-name and case-conversion helpers are also tested
independently so regressions show up at the smallest possible blast
radius.

Refs: hero_rpc#60, hero_rpc#55, hero_skills#262.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
timur merged commit 2aab82c40e into development 2026-05-19 13:39:10 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lhumina_code/hero_rpc!63
No description provided.