Files
lifeos-dev/tests/route_report.py

66 lines
2.1 KiB
Python

"""
Route Registry Report
=====================
Run inside the container to see exactly what the introspection engine
discovers from the live app. Use this to verify before running tests.
Usage:
docker exec lifeos-dev python -m tests.route_report
"""
from __future__ import annotations
import sys
sys.path.insert(0, "/app")
from tests.registry import ALL_ROUTES, ROUTE_REGISTRY, PREFIX_TO_SEED # noqa: E402
from tests.introspect import dump_registry_report, RouteKind # noqa: E402
from main import app # noqa: E402
def main():
print(dump_registry_report(app))
reg = ROUTE_REGISTRY
print("\n" + "=" * 70)
print("SUMMARY")
print("=" * 70)
print(f" Total routes: {len(reg['all'])}")
print(f" GET (no params): {len(reg['get_no_params'])}")
print(f" GET (with params): {len(reg['get_with_params'])}")
print(f" POST create: {len(reg['post_create'])}")
print(f" POST edit: {len(reg['post_edit'])}")
print(f" POST delete: {len(reg['post_delete'])}")
print(f" POST action/toggle: {len(reg['post_action'])}")
print(f" Entity prefixes: {len(reg['by_prefix'])}")
print()
# Warn about POST routes with no discovered form fields
for r in reg["post_create"]:
if not r.form_fields:
print(f" WARNING: {r.path} has no discovered Form() fields")
for r in reg["post_edit"]:
if not r.form_fields:
print(f" WARNING: {r.path} has no discovered Form() fields")
# Show seed mapping coverage
print()
print("PREFIX_TO_SEED coverage:")
print("-" * 70)
for prefix in sorted(reg["by_prefix"].keys()):
has_seed = prefix in PREFIX_TO_SEED and PREFIX_TO_SEED[prefix] is not None
marker = "OK" if has_seed else "SKIP (no seed)"
print(f" {prefix:30s} {marker}")
print()
print("Form field details for create routes:")
print("-" * 70)
for r in reg["post_create"]:
if r.form_fields:
fields = [f" {f.name}: {f.annotation}{'*' if f.required else ''}" for f in r.form_fields]
print(f"\n {r.path}")
print("\n".join(fields))
if __name__ == "__main__":
main()