Skip to content

feat: Flask route model for the test-session gates - #261

Merged
ffroliva merged 22 commits into
release/0.8.0from
feat/0.8.0-f1
Nov 21, 2026
Merged

ffroliva merged 22 commits into
release/0.8.0from
feat/0.8.0-f1

Conversation

@ffroliva

Copy link
Copy Markdown
Owner

Summary

Closes #75 for the test-session gates; the Flask console, request correlation and an example app continue in #260.

  • sharpit.flask: an AppIntrospector for Flask 2.3.3 and later over app.url_map. Werkzeug parameters
    (<id>, <int:id>, <path:p>, <uuid:u>, any(...), custom converters) become {id}; blueprint routes,
    blueprints registered twice under different names, the static endpoint and callable-object views are kept;
    views are never called.
  • Introspection reads statically (inspect.getattr_static, the instance dictionary through object.__getattribute__)
    so it never runs host code: a Flask subclass's __getattribute__ and a rule's properties are not evaluated; a value
    that is a descriptor is treated as unreadable and degrades instead of crashing.
  • The pytest plugin finds Flask through sys.modules (no sharpit module outside sharpit.flask imports Flask);
    --sharpit-app and autodetection recognise Flask applications. An application whose route map cannot be read is
    reported UNKNOWN with its reason, never as an empty pass.
  • sharpit.flask is added to the adapters and its import rule to tests/engine/test_import_boundary.py and
    AGENTS.md.
  • Limits, recorded in the lane plan and the docs: strict_slashes and subdomain or host matching have no field in the
    route model.
  • flask stays in the test extra only.

PR #207 also edits src/sharpit/pytest_plugin/apps.py; whichever merges second resolves the conflict.

Tests

Behaviour Test Red before the change
Flask app metadata and routes app metadata and model tests assert None is not None; assert [] == ['/ready']
The import rule for sharpit.flask bites planted import test assert [] == ["sharpit/engine/tools.py imports sharpit.flask.introspector"]
Reads run no host code test_routes_and_app_metadata_do_not_read_dynamic_flask_attributes, test_routes_do_not_evaluate_rule_properties ['__dict__', '__dict__'] == []; ['rule'] == []
An unreadable map is UNKNOWN test_explicit_flask_app_with_unreadable_map_is_unknown the unreadable-map reason was absent
Callable views are kept, never called test_callable_view_with_explicit_endpoint_is_kept_without_calling_it [] == ['/callable']

299 tests in tests/flask, tests/flask_gate, tests/pytest_plugin, the import boundary and code shape pass on
Flask 3.1.3; the Flask tests pass on Flask 2.3.3 with Werkzeug 2.3.8. Ruff, format and pyright pass.

Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
Signed-off-by: Flavio Oliva <ffroliva@gmail.com>
@ffroliva
ffroliva marked this pull request as ready for review November 21, 2026 03:43
@ffroliva
ffroliva merged commit 502e1f9 into release/0.8.0 Nov 21, 2026
47 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.

1 participant