feat(graph): add Flask route resolver - #177
Open
abhinav-phi wants to merge 1 commit into
Open
Conversation
Connect decorator-defined Flask routes to their handler functions. The resolver recognizes @app.route() with and without an explicit methods list (GET is the default), shortcut decorators, and the same decorators on Blueprint instances, emitting one stable route node per explicitly declared HTTP method. Flask path converters such as /users/<int:user_id> are preserved verbatim — they are the route's identity, and normalizing them would collide distinct routes. Detection keys on a staged Python module actually importing flask rather than dependency manifests: the detection context sees only staged corpus files, and manifests are not staged. An import is the reliable observable and 'flask_restful' does not match. Same-file handlers resolve only when unambiguous; missing, cross-file, and duplicate handlers stay unresolved. No identity, reconciliation, schema, or drift-semantics changes. Resolves mex-memory#112
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.
Resolves #112.
What
A bounded Flask framework resolver following the
express.tsreference pattern. It recognizes:@app.route("/path")— GET by default, andmethods=["GET", "POST"]fanned out to one stable route node per explicitly declared method@app.get(),@app.post(),@app.put(),@app.patch(),@app.delete(),@app.options(),@app.head()Blueprintinstances (prefix composition acrossregister_blueprint()stays out of scope, per the issue)Flask path converters such as
/users/<int:user_id>are preserved verbatim — they are the route's identity, and normalizing them would collide distinct routes. Sync andasync defhandlers both bind; stacked decorators, and blank/comment lines between decorator anddef(legal in Python), are handled. Same-file handlers resolve only when unambiguous; missing, cross-file, and duplicate handlers stay unresolved.One deliberate deviation from the issue text
The issue says to detect Flask from
pyproject.tomlor requirements files. Those manifests are not staged corpus files — the detection context'sgetAllFiles()/readFile()only see staged sources plus package/tsconfig config globs — so a manifest-baseddetect()would return false on every real build while still passing fake-context unit tests. Detection here instead keys on a staged Python module actually importing flask (import flask,from flask import ...,from flask.views import ...), which the context genuinely observes and which every Flask project has.flask_restfuland friends do not match. This is verified end-to-end by the integration test, which builds a real graph over a Flask fixture and asserts the persisted route nodes and framework-resolved edges.Worth flagging for review: the open FastAPI resolver PR (#113) uses the manifest-based
detect()and would have the same blind spot in real builds.Tests
resolver-flask.test.ts(9): positive/negative detection (includingflask_restful), route fan-out with converters preserved, custom instance names with dynamic paths and foreign receivers skipped, resolution of functions and methods, missing/cross-file/ambiguous left unresolved, non-Python files ignored, registry registration.resolver-flask-integration.test.ts(1): realrebuildGraphover a Flask fixture — route nodes persist with stableflask-routeidentity and both methods resolve to the handler through framework edges.npm run typecheck,npm run buildpass; targeted suites green. The three failures intest/graph-integration.test.tson my Windows machine reproduce identically on cleanmain(symlink/WAL environment noise) and are unrelated.No identity, reconciliation, schema, or drift-semantics changes are included.