generator: emit E2E tests for service-block methods — closeout of hero_rpc#131 #134
No reviewers
Labels
No labels
prio_critical
prio_low
type_bug
type_contact
type_issue
type_lead
type_question
type_story
type_task
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lhumina_code/hero_rpc!134
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "service-method-test-codegen"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
tests_emit.rsnow walksschema.servicesalongside the existing rootobject walk and emitstests/generated/<service_snake>_e2e.rsper service block (methods-only domains were previously short-circuited out).#[tokio::test] <svc>_<method>_round_tripper method. Each test spins up the service viaspin_up_service(), builds the typed SDK call with synthesised default arguments, and assertsOk(_)— proves the wire path round-trips and the handler is wired.<svc>_Rust ident is built fromservice_name.to_ascii_lowercase()to mirror the rpc2 trait emitter, so the generated tests resolve the right SDK methods.sync_tests_cargo_tomlnow syncs both rootobject and service-block[[test]]entries — rootobjects first (snake-sorted, each with its optional_find_e2esibling), then service entries.// SKIP: <reason>stub + aneprintln!warning at codegen time rather than failing the whole build.find_tests_emit.rswas still emitting the pre-#124let (svc, _data_dir)+svc.shutdown().awaitshape; aligned with the post-#124let svc = ...+ Drop-based cleanup so regenerated_find_e2e.rsfiles compile against the current lab subprocess driver.Audit before/after
service Greeter { greet, echo, add, concat, info }) produced zero generated tests. A hybrid schema (ServiceDefinition [rootobject]+service ServiceCatalog { list, get_by_name, list_by_interface, bootstrap, refactor, check, verify }) produced onlyservice_definition_e2e.rs; the 7 service methods got zero coverage.greeterschema → 5 generated tests (greeter_e2e.rs). Hybridcatalogschema →service_definition_e2e.rs+service_definition_find_e2e.rs(rootobject CRUD + indexed find) +servicecatalog_e2e.rswith 9 tests (one per method, including the newcount/clearadditions). All compile and link.Decisions taken without confirmation
service_name.to_ascii_lowercase()(soServiceCatalog.list→ SDK methodservicecatalog_list, notservice_catalog_list). The test emitter mirrors that exactly — pinned with a unit test (service_lowercasing_matches_rpc2_trait_emitter) so a future emitter rename can't silently desync the two sides.result.is_ok()rather than pinning a specific return value. Concrete return values are user-impl-dependent and richer per-method semantics belong in user-owned tests undertests/siblings — the codegen's job is to prove the wire path and handler are wired.// SKIPrather than build failure for methods whose params can't be defaulted. None of the canary methods (in hero_service: 14 methods acrossGreeter+ServiceCatalog) hit the skip path, but the safety net is there for future schemas.Test plan
cargo test -p hero_rpc_generator --lib— 150 tests pass (145 pre-existing + 5 new unit tests covering the methods-only emitter, list/option/enum defaulting, and the Cargo.toml entries order).cargo build --workspaceclean.greeter_e2e.rs(5 tests) + extendedservicecatalog_e2e.rs(9 tests, was 7) come up alongside the existing rootobject E2Es. Runtime exercise is gated on thelab service <name> --start --ephemeral --jsondriver landing on the host'slabbinary (out of scope here).Closes #131
Unblocks (META) #132 — six legacy
openrpc_client!services with no rootobjects can now migrate onto oschema codegen.hero_service-side validation: https://forge.ourworld.tf/lhumina_code/hero_service/pulls (PR opened in companion repo)
The workspace-root tests emitter (`OschemaBuilder::emit_tests_module`) previously short-circuited on domains with no rootobjects, so any schema declaring only `service Foo { ... }` blocks (or a hybrid domain's service methods alongside rootobject CRUD) ended up with zero generated coverage. Walk `schema.services` alongside the rootobject walk and emit `tests/generated/<service_snake>_e2e.rs` per service block. One `#[tokio::test] <svc_snake>_<method_snake>_round_trip` per method; each test spins up the service via the existing `spin_up_service()` helper, builds the typed SDK call with synthesised defaults, and asserts the call returns Ok(_) — proves the wire path round-trips and the handler is wired. Methods whose parameters can't be defaulted emit a `// SKIP` stub + an eprintln warning rather than failing the whole build. The `<svc>_` Rust ident is built from `service_name.to_ascii_lowercase()` to mirror the rpc2 trait emitter (`emit/rust_rpc2.rs::render_trait_method`), so the generated tests resolve the right SDK methods. `sync_tests_cargo_toml` now syncs both rootobject and service-block [[test]] entries — rootobjects first (snake-sorted, each with its optional `_find_e2e` sibling), then service entries (snake-sorted). First-scaffold output stays byte-identical for rootobject-only templates; the build.rs path picks up service additions on the next regen.