Skip to content

feat(routes): cora routes command + fix route detection - #454

Merged
ajianaz merged 2 commits into
developfrom
feat/438-routes-command
Aug 1, 2026
Merged

feat(routes): cora routes command + fix route detection#454
ajianaz merged 2 commits into
developfrom
feat/438-routes-command

Conversation

@ajianaz

@ajianaz ajianaz commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implements the primary acceptance criterion of #438 — a cora routes command that lists detected HTTP endpoints — and fixes two correctness bugs in the existing route detection that produced wrong handler names and dropped the HTTP method.

Closes #438.

What changed

Detection fixes (src/index/extract.rs::detect_routes)

Route detection already existed and was wired into indexing, but the extracted data was wrong:

Before After
source = "get" for every Axum route (group 2 = method fn) source = "health_check" (group 3 = handler)
target = "/api/health" (method dropped) target = "GET /api/health"
source = "routes" for routes::health::health_check source = "health_check" (final segment)
  • Axum/Actix handler is now capture group 3 (the actual handler), not group 2 (the method fn like get/post).
  • HTTP method is captured and prefixed to the target.
  • Fully-qualified handler paths (routes::health::health_check) are captured in full ([\w:]+) and reduced to the final segment so the edge source matches the indexed function symbol.
  • Removed the dead extract_http_method helper — it checked the regex string for a label substring that never appeared, so it always returned "".

New command (src/commands/routes.rs)

cora routes                 # list all detected endpoints
cora routes --method GET    # filter by HTTP method (case-insensitive)
cora routes --prefix /api   # filter by path prefix
cora routes --json          # structured output

Routes already appear in cora arch edge distribution (kind = ROUTE).

Verification

End-to-end against the hompimpah Axum backend (10 routes):

$ cora routes
Detected HTTP routes (10)
──────────────────────────────────────────────────────
  GET     /api/health                               health_check → server/src/lib.rs:47
  GET     /api/auth/providers                       list_providers → server/src/lib.rs:48
  GET     /api/auth/{provider}/login                login → server/src/lib.rs:49
  POST    /api/auth/logout                          logout → server/src/lib.rs:51
  POST    /api/progress                             submit_progress → server/src/lib.rs:53
  ...

$ cora routes --method POST
  POST    /api/auth/logout                          logout → server/src/lib.rs:51
  POST    /api/progress                             submit_progress → server/src/lib.rs:53

Checks

  • cargo fmt --all -- --check
  • cargo clippy --all-targets -- -D warnings
  • cargo test ✅ (785 tests, including +6 detect_routes and +4 routes tests)
  • Pre-commit cora review ✅ passed on this diff

Out of scope (follow-ups)

Two secondary criteria from #438 are not addressed here and warrant separate work:

  • Routes as symbols in brain search — routes are currently edges, and brain searches the symbols table. Surfacing them needs a Route symbol kind.
  • cora query "/api/users -> *" tracing route → handlercora query reads the call_graph table, while ROUTE edges live in edges. Only cora trace/cora impact (the _edges variants) traverse ROUTE today.

These are tracked conceptally in #438 and can be follow-up issues.

Related

ajianaz added 2 commits August 1, 2026 23:03
Implements the primary acceptance criterion of #438: list detected HTTP
endpoints as first-class graph data. Route detection (Axum, Actix-web, Go
net/http/chi, Express/Fastify, Flask/FastAPI) already existed and was wired
into indexing, but (a) the handler name and HTTP method were extracted
incorrectly, and (b) there was no CLI to surface the results.

Detection fixes (index/extract.rs::detect_routes):
- Axum/Actix handler is now capture group 3 (the actual handler), not group 2
  (the method fn like get/post). Previously every route source was the
  literal string "get".
- HTTP method is now captured and prefixed to the target, so routes read
  "GET /api/users" instead of a bare "/api/users".
- Fully-qualified handler paths (e.g. routes::health::health_check) are now
  captured in full and reduced to their final segment, so the edge source
  matches the indexed function symbol (health_check).
- Removed the dead/buggy extract_http_method helper: it checked the regex
  string for a label substring that never appeared, so it always returned "".

New command (commands/routes.rs, wired in main.rs + commands/mod.rs):
- cora routes              list all detected endpoints
- cora routes --method GET filter by HTTP method (case-insensitive)
- cora routes --prefix /api filter by path prefix
- cora routes --json       structured output

Routes already appear in `cora arch` edge distribution (kind = ROUTE).

Tests: +6 detect_routes tests (axum simple/FQ handler, actix, express, empty,
unknown language) and +4 routes command tests (target splitting). Full suite
green (785 tests), clippy clean (-D warnings), fmt clean.

Verified end-to-end against the hompimpah Axum backend: 10 routes detected
with correct handlers (health_check, submit_progress, login, ...) and methods.

Refs #438.
CI runs a newer rustfmt than my local 1.9.0-stable (2026-05-25); the Format
check flagged chain-breaking differences in the new detect_routes tests.
Updated local toolchain to rustc 1.97.1 (2026-07-14, matches CI) and
re-applied cargo fmt. No logic change.
@ajianaz
ajianaz merged commit 09cd704 into develop Aug 1, 2026
18 of 19 checks passed
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.

Detect HTTP routes as graph symbols

1 participant