Skip to content

refactor(server): extract every route arm into a named handler (#1344) - #1458

Merged
ajianaz merged 2 commits into
developfrom
refactor/extract-route-handlers-1344
Oct 15, 2026
Merged

ajianaz merged 2 commits into
developfrom
refactor/extract-route-handlers-1344

Conversation

@ajianaz

@ajianaz ajianaz commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

What

PR 1 of 2 for #1344. It is a pure move with no behaviour change.

  • Module split. crates/uteke-server/src/handlers.rs becomes handlers/mod.rs plus nine domain modules. mod.rs keeps route, the shared helpers and the existing tests.

    Module Handlers
    health 3
    memory 16
    namespaces 3
    tags 3
    rooms 18
    docs 8
    graph 8
    maintenance 18
    mcp 1
  • Handlers. Each of the 78 route arms is now a named function fn <verb>_<path>(c: &mut Call) -> Response, for example post_recall or get_room_memories.

  • Call. This new struct carries what the arms used from route'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_rows asserts that the match arms and api_registry::ENDPOINTS are 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.rs is compiled in both the lib (for docgen) and the bin. A handler field on Endpoint therefore cannot reference bin-only types. PR 2 will use a bin-side (method, path, handler) table checked against ENDPOINTS, or move context/handlers into the lib.

Testing

  • Body equivalence, checked by an independent review with its own token-level comparator. All 78 handler bodies are token-identical to the old arms (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;
    • 10 & borrows dropped where &uteke / &path became &Uteke / &str, because clippy flagged them as needless. Same callee input.
  • Commands:
    • cargo test --workspace: all suites pass. uteke-server bin tests go from 124 to 125 (the new test).
    • cargo fmt --all -- --check and cargo clippy --workspace --all-targets -- -D warnings: clean.
    • cargo run -p docgen && git diff --exit-code docs/: no diff, so docs/core-contract.json and docs/api-reference.md are identical.
  • Rebase: rebased on develop after security(deps): bump rustls to 0.23.46 (RUSTSEC-2026-0346..0349) #1455. The tests and docgen were re-run after the rebase, with the same results.

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.
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 2c2a2eb into develop Oct 15, 2026
15 checks passed
@ajianaz
ajianaz deleted the refactor/extract-route-handlers-1344 branch October 15, 2026 03:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant