feat(bridge): add core.list_methods RPC for method discovery#7
feat(bridge): add core.list_methods RPC for method discovery#7Sanjays2402 wants to merge 1 commit into
Conversation
Adds a discoverable bridge endpoint that returns the canonical list of
every RPC method the current build understands. Lets external clients
(iOS app, future Android port, debug tooling) enumerate the surface at
runtime instead of grepping bridge.rs.
- New constant BRIDGE_METHODS (sorted, 119 entries) listing every
dispatcher arm.
- New RPC core.list_methods returning
{ schema, count, methods } under schema goose.bridge.methods-list.v1.
- Three new tests:
1. bridge_methods_constant_matches_dispatcher scans the live
dispatcher source and asserts the constant matches it exactly,
so the list cannot silently drift when new methods are added.
2. bridge_methods_constant_is_sorted_and_unique enforces the
documented ordering invariant.
3. core_list_methods_rpc_returns_full_method_set round-trips the
RPC through the bridge envelope and confirms the payload.
No behavioral change to existing methods. Non-breaking, additive.
… (fork method missing from PR #7 list)
| /// discoverability by external clients (the Swift app, future Android port, | ||
| /// debug tooling). | ||
| pub const BRIDGE_METHODS: &[&str] = &[ | ||
| "activity.apply_correction", |
There was a problem hiding this comment.
Manual constant requires two-site updates on every new method.
Whenever a bridge method is added, the developer must update both the dispatcher match arms and this constant. The drift test catches the omission at CI time, but only after a commit — there is no guard at editing time.
A cleaner approach: generate BRIDGE_METHODS at build time from a build script that parses the dispatcher, eliminating the manual step entirely. The drift test would then verify the build artifact rather than a hand-maintained list.
Note: the constant must be curated, not assumed-complete — not every match arm is a top-level RPC. The drift test only protects methods that are registered; it cannot detect a method added to the constant that was never wired into the dispatcher.
| #[test] | ||
| fn bridge_methods_constant_matches_dispatcher() { | ||
| let src = include_str!("bridge.rs"); | ||
| let start = src |
There was a problem hiding this comment.
Drift-test regex must exactly match the dispatch syntax or becomes a silent no-op.
The test scans bridge.rs source via include_str! and extracts method strings using string matching. If the formatting of match arms changes (multiline arms, macros, comments inside the block), the extraction may silently miss methods — the test passes while BRIDGE_METHODS is actually out of sync.
Suggest adding an assertion on the count of extracted methods as a sanity check:
assert!(
extracted.len() >= BRIDGE_METHODS.len(),
"Fewer methods extracted ({}) than registered ({}). \
The extraction regex may not match all dispatch arms.",
extracted.len(), BRIDGE_METHODS.len()
);This catches the regex silently going blind without requiring it to be perfectly accurate.
Also worth considering: whether some entries in BRIDGE_METHODS are internal-only debug RPCs that should not be advertised to all callers via core.list_methods. Authorization at a higher layer may be needed before this endpoint is surfaced externally.
… (fork method missing from PR #7 list)
What
Adds a discoverable bridge endpoint —
core.list_methods— that returns the canonical list of every RPC method the current build understands. Lets external clients (iOS app, future Android port, debug tooling, anyone wiring a new front end) enumerate the bridge surface at runtime instead of greppingbridge.rs.Why
The bridge currently exposes 119 RPC methods with no programmatic way to discover them. New clients have to read source. Worse, there's no compile-time guarantee that a manually maintained method list would stay in sync.
How
1. New public constant
BRIDGE_METHODS: &[&str]— sorted, 119 entries, one per dispatcher arm.2. New RPC
core.list_methods— returns{ "schema": "goose.bridge.methods-list.v1", "count": 119, "methods": ["activity.apply_correction", "activity.attach_interval", ...] }3. Drift-proof self-check tests:
bridge_methods_constant_matches_dispatcher— scans the live dispatcher source viainclude_str!and asserts the extracted method set equalsBRIDGE_METHODS. If anyone adds a new method without registering it in the constant, CI fails with a pointed message.bridge_methods_constant_is_sorted_and_unique— enforces the documented ordering / uniqueness invariant.core_list_methods_rpc_returns_full_method_set— round-trips the RPC throughhandle_bridge_requestand verifies envelope + payload, including thatcore.list_methodsis itself present in the list it advertises.Compatibility
Non-breaking, purely additive — no existing method is touched. The new schema
goose.bridge.methods-list.v1is independent ofgoose.bridge.response.v1.Tests
Full
cargo test --lib: 16 passed, 0 failed.cargo fmt --allapplied.cargo build --libclean.Files
Rust/core/src/bridge.rs—+251 / -0