Skip to content

feat(graph): add Flask route resolver - #177

Open
abhinav-phi wants to merge 1 commit into
mex-memory:mainfrom
abhinav-phi:feat/flask-route-resolver
Open

feat(graph): add Flask route resolver#177
abhinav-phi wants to merge 1 commit into
mex-memory:mainfrom
abhinav-phi:feat/flask-route-resolver

Conversation

@abhinav-phi

Copy link
Copy Markdown
Contributor

Resolves #112.

What

A bounded Flask framework resolver following the express.ts reference pattern. It recognizes:

  • @app.route("/path") — GET by default, and methods=["GET", "POST"] fanned out to one stable route node per explicitly declared method
  • shortcut decorators @app.get(), @app.post(), @app.put(), @app.patch(), @app.delete(), @app.options(), @app.head()
  • the same decorators on Blueprint instances (prefix composition across register_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 and async def handlers both bind; stacked decorators, and blank/comment lines between decorator and def (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.toml or requirements files. Those manifests are not staged corpus files — the detection context's getAllFiles()/readFile() only see staged sources plus package/tsconfig config globs — so a manifest-based detect() 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_restful and 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 (including flask_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): real rebuildGraph over a Flask fixture — route nodes persist with stable flask-route identity and both methods resolve to the handler through framework edges.

npm run typecheck, npm run build pass; targeted suites green. The three failures in test/graph-integration.test.ts on my Windows machine reproduce identically on clean main (symlink/WAL environment noise) and are unrelated.

No identity, reconciliation, schema, or drift-semantics changes are included.

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
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.

[Flask] Add route resolver

1 participant