feat(parser): extract call-registration HTTP endpoints for JS/TS and Go - #956
feat(parser): extract call-registration HTTP endpoints for JS/TS and Go#956geeknik wants to merge 4 commits into
Conversation
Route handlers registered by a call — Express/Koa/Fastify
`app.get('/x', handler)` and Go net/http `http.HandleFunc('/x', handler)`
plus gin/echo/chi `r.GET('/x', handler)` — now emit an `Endpoint` node
and a `HANDLES` edge from the handler to the endpoint, mirroring the
existing Spring WebFlux emitter (`_emit_spring_webflux_endpoint`). This
makes call-registration handlers addressable by the existing
`handlers_of` / `endpoints_for` queries, uniformly with Spring MVC and
WebFlux.
Scope: named identifier handlers defined in the same file. Inline and
anonymous function handlers are left for a follow-up because they are not
their own graph nodes today. No schema change or migration — `Endpoint`
and `HANDLES` already exist and node/edge kinds are free-form TEXT.
Adds tests/test_call_registration_endpoints.py (Express, Go net/http,
gin, query round-trip, and non-route negative cases).
Claude-Session: https://claude.ai/code/session_01LjH35hKtHPMtzpJGzFN2Zp
Signed-off-by: geeknik <geeknik@protonmail.ch>
code-review-graph reviewOverall risk: 0.55 (MEDIUM) — 17 changed function(s)/class(es), 0 affected flow(s), 6 test gap(s) Risk-scored changes
Test gaps
Token savings: this graph-backed report used ~165,473 fewer tokens (~98%) than reading every changed file in full (estimated, chars/4 approximation). Powered by code-review-graph — local-first analysis; no code leaves the CI runner. |
Anonymous/inline function handlers passed to a call-registration route,
`app.post('/x', (req, res) => {...})` or Go
`http.HandleFunc('/x', func(...){})`, are now emitted as a synthetic
`Function` node spanning the inline body and used as the `HANDLES`
source. This makes anonymous route handlers, the Express majority,
addressable and analyzable uniformly with named handlers.
Extends tests/test_call_registration_endpoints.py with inline JS and Go
cases.
…hon)
Extends the call-registration extractor beyond Express/Go to more
frameworks:
- Object/dict route config (Hapi, Kibana, Fastify):
router.get({ path: '/x' }, handler)
- Django URLConf: path('x/', view), re_path(r'...', view), url(...)
- aiohttp / Flask: app.router.add_get('/x', h),
app.add_url_rule('/x', name, h)
The route path comes from a string literal or the path/url/route key of
an object/dict config; Django routes need no leading slash (require_slash
is off for those framework-specific callees). Handlers resolve for
same-file named/dotted references and inline functions.
Cross-file handler resolution (Django views in a separate module) and
class-based `.as_view()` handlers are follow-ups.
`mux.HandleFunc("GET /info", handler)` (Go 1.22 http.ServeMux) embeds
the HTTP method in the route pattern. The method is now split out of the
pattern and the path validated, so these register as GET/POST/... rather
than being rejected for lacking a leading slash. Bare "/legacy" patterns
still register as ANY.
|
Changes required: method names alone create false HTTP endpoints and inline handler identities collide. Parse |
What
Extract HTTP endpoints from call-registration web frameworks so their handlers become addressable like decorator/annotation routes:
app.get('/x', handler),router.post('/x', handler)http.HandleFunc('/x', handler), gin/echo/chir.GET('/x', handler)Each emits an
Endpointnode and aHANDLESedge (handler → endpoint), mirroring the existing_emit_spring_webflux_endpoint. The existinghandlers_of/endpoints_forqueries work with zero changes, so Spring MVC, Spring WebFlux, Express, Koa, Fastify, and Go are all handled uniformly.Why
Decorator/annotation routes (FastAPI
@app.get, Spring@GetMapping) are already captured, but call-registration routes were not, so their handlers were invisible as HTTP entrypoints.flows.detect_entry_pointseven carries(app|router)\.(get|post|...)patterns, but they only fire on a stamped decorator string, which call-registration never produces.How
_call_registration_arguments+_emit_call_registration_endpointnext to the WebFlux emitter._extract_callsat the JSmember_callbranch and the Go typed-call branch._JS_ROUTE_VERBS/_GO_ROUTE_VERBS.Scope / follow-up
Named identifier handlers defined in the file. Inline/anonymous handlers (
app.get('/x', (req,res)=>{...})) are a documented follow-up: they are not their own graph nodes today and need synthetic node creation in the same emitter.Safety
No schema change, no migration —
Endpoint/HANDLESalready exist and node/edge kinds are free-form TEXT. Detection requires a literal path starting with/plus an identifier handler, so non-route calls likecache.get('key')are ignored.Tests
Adds
tests/test_call_registration_endpoints.py(Express, Go net/http, gin,handlers_of/endpoints_forround-trip, negative cases). Existing parser/graph/flows suites pass unchanged locally (774 + 4).