Repository navigation
refactor(server): extract every route arm into a named handler (#1344) - #1458
Merged
Merged
Conversation
route() keeps the shared preflight (version prefix, Host guard, CORS preflight, auth, read-only gate, registry 404), then packs the per-request state into a Call and dispatches with one line per route. Each former match arm is now a function in a domain module under handlers/ (health, memory, namespaces, tags, rooms, docs, graph, maintenance, mcp). Pure move: arm order, the (method, path) set and the bodies are unchanged apart from rustfmt reflow and dropping borrows that clippy flags now that path and uteke are already references.
…es (#1344) every_registry_row_has_a_handler_arm only proves each row reaches a handler. The new test reads the one-line-per-route dispatch match from handlers/mod.rs and asserts its (method, path) set equals api_registry::ENDPOINTS with no duplicates, so an arm without a row is caught too. The registry's sync comment now points at handlers/mod.rs.
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
PR 1 of 2 for #1344. It is a pure move with no behaviour change.
Module split.
crates/uteke-server/src/handlers.rsbecomeshandlers/mod.rsplus nine domain modules.mod.rskeepsroute, the shared helpers and the existing tests.healthmemorynamespacestagsroomsdocsgraphmaintenancemcpHandlers. Each of the 78 route arms is now a named function
fn <verb>_<path>(c: &mut Call) -> Response, for examplepost_recallorget_room_memories.Call. This new struct carries what the arms used fromroute's scope:uteke,ctx,req,path(query intact),api_version,health_anonymous,read_only.Dispatch. The match is one line per route, with the same 78
(method, path)pairs in the same order. The preflight is byte-identical: API version, Host guard, auth, read-only gate, registry 404 and the lock.New test.
dispatch_match_routes_equal_the_registry_rowsasserts that the match arms andapi_registry::ENDPOINTSare the same set, both ways. It also catches an arm without a registry row, which the existing runtime test could not.Why
#1344: the router's 2.8k-line match carried every endpoint's logic inline. Extracting named handlers with one uniform signature is the step before PR 2, where the route table drives dispatch and the match goes away. Doing it as a separate pure move keeps both PRs reviewable.
Note for PR 2:
api_registry.rsis compiled in both the lib (for docgen) and the bin. Ahandlerfield onEndpointtherefore cannot reference bin-only types. PR 2 will use a bin-side(method, path, handler)table checked againstENDPOINTS, or movecontext/handlersinto the lib.Testing
git show de1c78a:crates/uteke-server/src/handlers.rs) except for two kinds of difference:{}around arm bodies that rustfmt added or removed after re-indenting;&borrows dropped where&uteke/&pathbecame&Uteke/&str, because clippy flagged them as needless. Same callee input.cargo test --workspace: all suites pass. uteke-server bin tests go from 124 to 125 (the new test).cargo fmt --all -- --checkandcargo clippy --workspace --all-targets -- -D warnings: clean.cargo run -p docgen && git diff --exit-code docs/: no diff, sodocs/core-contract.jsonanddocs/api-reference.mdare identical.