example: end-to-end walkthrough + fix rpc2_adapter set wrapper #105

Merged
timur merged 1 commit from walkthrough-example into development 2026-05-21 10:52:12 +00:00
Owner

Summary

Two related changes:

  1. example/recipe_server/crates/hero_recipes_examples/examples/01_walkthrough.rs — replaces the TODO placeholder 01_connect.rs with a runnable top-to-bottom tour of how a Hero service is built. Six steps, each prints what it's doing, runs in a tempdir:

    • 1. Scaffold a fresh service workspace (WorkspaceScaffolder::scaffold()) + print the tree.
    • 2. Show the OSchema input (Greeting [rootobject] + Hello service).
    • 3. Generate the OpenRPC spec via Schema::to_openrpc() — lists 7 auto-CRUD methods + 1 service method.
    • 4. Print an excerpt of the typed Rust SDK trait.
    • 5. Print the backend handler impl pattern.
    • 6. Live roundtripOsisRecipes::createrpc2_adapter::module_forServerBuilder::serve_httpClientBuilder::connect_http, then call recipe_list / recipe_list_full / recipe_exists through the typed trait.

    Run with: cargo run -p hero_recipes_examples --example 01_walkthrough

  2. rpc2_adapter::extract_data set fix — while writing step 6 I caught a bug in my own #98 code: the set branch was unwrapping params.data before passing the JSON downstream, but the OSchema dispatcher's recipe_rpc_set still calls params.get("data") and so failed with "Missing required parameter: data". Fix: always preserve the outer {"data": ..., "ctx": ...} wrapper. Tests replaced with two stricter ones that explicitly verify the wrapper survives.

Open follow-up documented in the walkthrough output

The SDK uses OTime(String) (transparent), the OSIS server stores epoch-integers — full Recipe ser/deser via recipe.set / recipe.get currently fails on the cross-side serde shape. Separate codegen issue, not in scope here. The walkthrough explicitly calls this out inline.

Test plan

  • cargo run -p hero_recipes_examples --example 01_walkthrough completes end-to-end with the expected printed output.
  • 9/9 rpc2_adapter tests + 138/138 generator unit tests pass.
## Summary Two related changes: 1. **`example/recipe_server/crates/hero_recipes_examples/examples/01_walkthrough.rs`** — replaces the TODO placeholder `01_connect.rs` with a runnable top-to-bottom tour of how a Hero service is built. Six steps, each prints what it's doing, runs in a tempdir: - **1.** Scaffold a fresh service workspace (`WorkspaceScaffolder::scaffold()`) + print the tree. - **2.** Show the OSchema input (Greeting [rootobject] + Hello service). - **3.** Generate the OpenRPC spec via `Schema::to_openrpc()` — lists 7 auto-CRUD methods + 1 service method. - **4.** Print an excerpt of the typed Rust SDK trait. - **5.** Print the backend handler impl pattern. - **6.** **Live roundtrip** — `OsisRecipes::create` → `rpc2_adapter::module_for` → `ServerBuilder::serve_http` → `ClientBuilder::connect_http`, then call `recipe_list` / `recipe_list_full` / `recipe_exists` through the typed trait. Run with: `cargo run -p hero_recipes_examples --example 01_walkthrough` 2. **`rpc2_adapter::extract_data` `set` fix** — while writing step 6 I caught a bug in my own #98 code: the `set` branch was unwrapping `params.data` before passing the JSON downstream, but the OSchema dispatcher's `recipe_rpc_set` still calls `params.get("data")` and so failed with "Missing required parameter: data". Fix: always preserve the outer `{"data": ..., "ctx": ...}` wrapper. Tests replaced with two stricter ones that explicitly verify the wrapper survives. ## Open follow-up documented in the walkthrough output The SDK uses `OTime(String)` (transparent), the OSIS server stores epoch-integers — full Recipe ser/deser via `recipe.set` / `recipe.get` currently fails on the cross-side serde shape. Separate codegen issue, not in scope here. The walkthrough explicitly calls this out inline. ## Test plan - [x] `cargo run -p hero_recipes_examples --example 01_walkthrough` completes end-to-end with the expected printed output. - [x] 9/9 rpc2_adapter tests + 138/138 generator unit tests pass.
example: end-to-end walkthrough + fix rpc2_adapter set wrapper
Some checks failed
Test / test (push) Failing after 2m3s
Test / test (pull_request) Failing after 1m49s
cd21b2767a
## 01_walkthrough.rs

Replaces the TODO placeholder 01_connect.rs with a runnable
top-to-bottom tour of how a Hero RPC service is built. Six
steps, each prints what it's doing:

  1. Scaffold a fresh service workspace into a tempdir
     (`WorkspaceScaffolder::scaffold()`), then print the tree.
  2. Show the OSchema input (Greeting [rootobject] + Hello service).
  3. Generate the OpenRPC spec from that schema directly via
     `Schema::to_openrpc()`, list all 8 methods — 7 auto-CRUD on
     Greeting + the Hello.greet service method.
  4. Print an excerpt of the generated typed Rust SDK trait.
  5. Print the backend handler impl pattern (CRUD auto, service
     methods you write).
  6. **Live in-process roundtrip** against the recipe_server domain:
     `OsisRecipes::create` → `rpc2_adapter::module_for` →
     `ServerBuilder::serve_http` → `ClientBuilder::connect_http`,
     then call `recipe_list` / `recipe_list_full` / `recipe_exists`
     through the typed trait.

Steps 1–5 are static (no compilation, just emission + printing).
Step 6 is fully live and exercises the same code paths a real
service binary follows — exactly what the design promised in #98.

The example documents one open follow-up: the SDK uses
`OTime(String)` (transparent) while the OSIS server stores
epoch-integers, so full-Recipe ser/deser via `recipe.set` /
`recipe.get` currently fails — a separate codegen issue, called
out inline in the walkthrough output.

## rpc2_adapter `set` data-extract fix

While writing step 6 I caught a bug in my own `extract_data` from
the #98 PR: the `"set"` branch was unwrapping `params.data`
before passing the JSON downstream, but the OSchema dispatcher's
`recipe_rpc_set` still calls `params.get("data")` and so failed
with "Missing required parameter: data". Fix: always preserve
the outer `{"data": ..., "ctx": ...}` wrapper when stringifying
for `set` — the dispatcher then finds `params.data` as expected
and `ctx` is a harmless extra key.

Tests updated: replaced the old asserts (which only checked
inner-field presence, so they passed even when the wrapper was
stripped) with two stricter ones that explicitly verify the
wrapper survives.

  - `extract_data_set_preserves_data_wrapper`
  - `extract_data_set_passes_through_ctx_alongside_data`

All 9 rpc2_adapter tests + 138 generator unit tests still pass.
timur merged commit f53491722e into development 2026-05-21 10:52:12 +00:00
timur deleted branch walkthrough-example 2026-05-21 10:52:12 +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!105
No description provided.