~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
test: repair post-FastAPI baseline checks (#6096)
LearningCircuit411f9fb44085
diff --git a/tests/news/test_news_service_contracts.py b/tests/news/test_news_service_contracts.pyindex 0829a91722..5ab4676efa 100644--- a/tests/news/test_news_service_contracts.py+++ b/tests/news/test_news_service_contracts.py@@ -677,12 +677,13 @@ class TestOverdueDetection:non-positive interval, so it is due again immediately. That is anunbounded run loop driven by a request-body field."""- before = datetime.now(timezone.utc)+ before_create = datetime.now(timezone.utc)result = news_api.create_subscription(user_id="alice",query="widgets",refresh_minutes=refresh_minutes,)+ after_create = datetime.now(timezone.utc)assert result["status"] == "success"assert result["refresh_minutes"] == refresh_minutes@@ -693,7 +694,12 @@ class TestOverdueDetection:.one())assert sub.refresh_interval_minutes == refresh_minutes- assert sub.next_refresh <= before + timedelta(seconds=1)+ offset = timedelta(minutes=refresh_minutes)+ assert (+ before_create + offset+ <= sub.next_refresh+ <= after_create + offset+ )# Due right away...due = (diff --git a/tests/research_library/routes/test_rag_routes_core_main_port.py b/tests/research_library/routes/test_rag_routes_core_main_port.pyindex b205c61532..ccc475c949 100644--- a/tests/research_library/routes/test_rag_routes_core_main_port.py+++ b/tests/research_library/routes/test_rag_routes_core_main_port.py@@ -14,9 +14,9 @@ Triage of the 125 deleted tests (see the per-class docstrings for detail):not serve). Nothing else. Those are superseded -- strictly, not nominally --by two structural censuses this branch added:``tests/security/test_unauthenticated_reachability_census.py``- (``test_no_route_lost_authentication_relative_to_main`` enumerates every- ``@login_required`` route on ``origin/main`` and requires its port to depend- on ``require_auth``) and ``tests/web/test_route_table_parity.py``+ (``test_unauthenticated_routes_are_exactly_the_declared_public_set`` rejects+ any mounted route that loses ``require_auth``) and+ ``tests/web/test_route_table_parity.py``(``test_method_sets_match_per_path`` / ``test_no_route_lost_its_auth_gate``/ ``test_status_codes_match_the_reviewed_table``). Deleting the``Depends(require_auth)`` on any rag route turns those red.diff --git a/tests/security/test_unauthenticated_reachability_census.py b/tests/security/test_unauthenticated_reachability_census.pyindex 7d3e91aa40..6b6ea80ca6 100644--- a/tests/security/test_unauthenticated_reachability_census.py+++ b/tests/security/test_unauthenticated_reachability_census.py@@ -12,12 +12,13 @@ route reachable by anyone.So this module answers two questions statically, over the WHOLE route table:-1. **Auth presence vs. main.** Every ``@login_required`` route on- ``origin/main`` is enumerated, mapped onto its port counterpart, and- required to depend on ``require_auth`` (directly or transitively).- :func:`test_no_route_lost_authentication_relative_to_main` is the headline;- :func:`test_main_login_required_baseline_matches_origin_main` re-derives the- frozen baseline from ``git show origin/main`` so it cannot silently rot.+1. **Authentication presence.** Every mounted FastAPI route must depend on+ ``require_auth`` (directly or transitively) or be exactly one of the+ reviewed entries in :data:`DECLARED_PUBLIC`. Set equality makes both a new+ anonymous route and a stale public exception fail closed. Historical+ Flask-to-FastAPI route and authentication parity belongs to+ ``tests/web/test_route_table_parity.py`` and its single reviewed snapshot;+ this census deliberately does not duplicate that legacy table.2. **The exemption intersection.** Three surfaces let a request skip acontrol: the CSRF middleware's ``_SKIP_EXACT_PATHS`` /@@ -40,32 +41,30 @@ file does not redo that argument. It differs in two ways that matter:``web/routers/*.py``, so it also covers the three routes registered directlyon the app object (``/``, ``/favicon.ico``, ``/static/{path:path}``) — whichis where two of the three ``@limiter.exempt`` unauthenticated routes live;-* its subject is auth PRESENCE measured against main, and the exemption+* its subject is auth PRESENCE over the mounted app, and the exemptionintersection, not identity threading.Static, not executed---------------------Everything here is AST analysis of the installed package source plus a-``git archive`` of ``origin/main``. No app boot, no TestClient, no database:-a census must be exhaustive, and a request-driven one can only ever cover the-routes somebody remembered to request. The package is located through-``importlib.util.find_spec``, so pointing ``PYTHONPATH`` at a mutated copy of-``local_deep_research`` re-runs the whole census against that copy — which is-how the negative control for this file was exercised by hand (strip-``Depends(require_auth)`` from one handler; the census names it).+Everything here is AST analysis of the installed package source. No app boot,+no TestClient, no database: a census must be exhaustive, and a request-driven+one can only ever cover the routes somebody remembered to request. The+package is located through ``importlib.util.find_spec``, so pointing+``PYTHONPATH`` at a mutated copy of ``local_deep_research`` re-runs the whole+census against that copy — which is how the negative control for this file+was exercised by hand (strip ``Depends(require_auth)`` from one handler; the+census names it).Anti-vacuity------------Every headline assertion here is "this list is empty", which is exactly the-shape that passes when the analyzer silently resolves nothing. Four guards:+shape that passes when the analyzer silently resolves nothing. Three guards:* :func:`test_route_table_is_mount_driven_and_complete` pins the mountedmodule set, a floor on route count, and specific routes that must resolve.* :func:`test_auth_closure_resolves_the_real_dependency_graph` pins thetransitive ``require_auth`` closure both ways — names that must be in it andnames that must not.-* :func:`test_main_login_required_baseline_matches_origin_main` proves the- frozen main baseline is the real one.* :func:`test_census_flags_synthetic_vulnerable_handlers` is the positivecontrol: four hand-written handlers, each vulnerable in a different way, gothrough the SAME functions the census uses and must each be flagged.@@ -83,14 +82,9 @@ from __future__ import annotationsimport astimport functoolsimport importlib.util-import re-import subprocess-import tarfilefrom dataclasses import dataclass, fieldfrom pathlib import Path-import pytest-# ---------------------------------------------------------------------------# Locating the package under census# ---------------------------------------------------------------------------@@ -517,521 +511,13 @@ DECLARED_PUBLIC = frozenset(# app_factory.index, which also carried no @login_required).("GET", "/"),# Static assets. Public by definition on a self-hosted web app;- # both were unauthenticated AND @limiter.exempt on main too.+ # both were unauthenticated AND @limiter.exempt on the Flask baseline.("GET", "/favicon.ico"),("GET", "/static/{path:path}"),})-# ----------------------------------------------------------------------------# The main baseline: every @login_required route on origin/main-# -----------------------------------------------------------------------------#: Blueprint variables whose live mount prefix is NOT the one written at-#: ``Blueprint(...)`` construction time, from-#: ``web/app_factory.py::register_blueprints`` on main. Keyed by-#: ``(repo-relative file, blueprint variable)``.-#:-#: ``news/flask_api.py``'s ``news_api_bp`` is the subtle one: it is never-#: registered on the app directly. ``news/web.py`` nests it-#: (``bp.register_blueprint(news_api_bp)``) and that outer blueprint is-#: registered with ``url_prefix="/news"``, so its own ``url_prefix="/api"``-#: composes to ``/news/api/...`` — which is exactly where the port serves it.-MAIN_BLUEPRINT_MOUNTS = {- ("web/routes/api_routes.py", "api_bp"): "/research/api",- ("web/routes/context_overflow_api.py", "context_overflow_bp"): "/metrics",- ("news/web.py", "bp"): "/news",- ("news/flask_api.py", "news_api_bp"): "/news",-}--#: main paths that the port deliberately moved. Each was checked against the-#: frontend callers, which were updated in the same change.-MAIN_TO_PORT_PATH = {- # The context-overflow blueprint lost its "/metrics" mount prefix; the- # port's router declares no prefix and the three JS callers- # (progress.js, details.js, results.js) fetch the new path.- "/metrics/api/context-overflow": "/api/context-overflow",- "/metrics/api/research/{}/context-overflow": (- "/api/research/{}/context-overflow"- ),-}--#: Authenticated main routes with no port counterpart, and why that is not an-#: auth regression. Every entry here is a DUPLICATE surface that main served-#: twice: ``web/routes/news_routes.py`` (mounted at /api/news) re-implemented-#: endpoints that ``news/flask_api.py`` already served at /news/api. The port-#: kept one copy — the /news/api one — and every surviving route is-#: authenticated (proved by the main census below, which covers both).-MAIN_ROUTES_DROPPED_BY_THE_PORT = frozenset(- {- ("DELETE", "/api/news/subscriptions/{}"),- ("GET", "/api/news/categories"),- ("GET", "/api/news/feed"),- ("GET", "/api/news/subscriptions"),- ("GET", "/api/news/subscriptions/{}"),- ("GET", "/api/news/subscriptions/{}/history"),- ("PATCH", "/api/news/subscriptions/{}"),- ("POST", "/api/news/feedback"),- ("POST", "/api/news/preferences"),- ("POST", "/api/news/research"),- ("POST", "/api/news/subscriptions"),- ("PUT", "/api/news/subscriptions/{}"),- }-)--#: Every ``(method, path)`` that carried ``@login_required`` on origin/main,-#: with path parameters erased to ``{}`` so Flask's ``<string:id>`` and-#: FastAPI's ``{id}`` compare. Frozen here so the census runs without network-#: or git; :func:`test_main_login_required_baseline_matches_origin_main`-#: re-derives it from ``git show origin/main`` and fails on any drift.-MAIN_LOGIN_REQUIRED = frozenset(- {- ("DELETE", "/api/chat/sessions/{}"),- ("DELETE", "/api/chat/sessions/{}/attempts/{}"),- ("DELETE", "/api/delete/{}"),- ("DELETE", "/api/news/subscriptions/{}"),- ("DELETE", "/benchmark/api/delete/{}"),- ("DELETE", "/library/api/collection/{}/document/{}"),- ("DELETE", "/library/api/collection/{}/documents/bulk"),- ("DELETE", "/library/api/collections/{}"),- ("DELETE", "/library/api/collections/{}/index"),- ("DELETE", "/library/api/document/{}"),- ("DELETE", "/library/api/document/{}/blob"),- ("DELETE", "/library/api/documents/blobs"),- ("DELETE", "/library/api/documents/bulk"),- ("DELETE", "/news/api/search-history"),- ("DELETE", "/news/api/subscription/folders/{}"),- ("DELETE", "/news/api/subscriptions/{}"),- ("DELETE", "/notes/api/documents/{}/annotations/{}"),- ("DELETE", "/notes/api/notes/{}"),- ("DELETE", "/notes/api/notes/{}/collections/{}"),- ("DELETE", "/notes/api/research/{}/annotations/{}"),- ("DELETE", "/research/api/resources/{}/delete/{}"),- ("DELETE", "/settings/api/{}"),- ("GET", "/api/chat/sessions"),- ("GET", "/api/chat/sessions/{}"),- ("GET", "/api/chat/sessions/{}/messages"),- ("GET", "/api/config/limits"),- ("GET", "/api/history"),- ("GET", "/api/news/categories"),- ("GET", "/api/news/feed"),- ("GET", "/api/news/subscriptions"),- ("GET", "/api/news/subscriptions/{}"),- ("GET", "/api/news/subscriptions/{}/history"),- ("GET", "/api/queue/status"),- ("GET", "/api/queue/{}/position"),- ("GET", "/api/report/{}"),- ("GET", "/api/research/{}"),- ("GET", "/api/research/{}/logs"),- ("GET", "/api/research/{}/logs/export"),- ("GET", "/api/research/{}/status"),- ("GET", "/api/scheduler/status"),- ("GET", "/benchmark"),- ("GET", "/benchmark/api/configs"),- ("GET", "/benchmark/api/history"),- ("GET", "/benchmark/api/results/{}"),- ("GET", "/benchmark/api/results/{}/export"),- ("GET", "/benchmark/api/running"),- ("GET", "/benchmark/api/search-quality"),- ("GET", "/benchmark/api/status/{}"),- ("GET", "/benchmark/results"),- ("GET", "/chat"),- ("GET", "/chat/{}"),- ("GET", "/details/{}"),- ("GET", "/history"),- ("GET", "/history/api"),- ("GET", "/history/details/{}"),- ("GET", "/history/log_count/{}"),- ("GET", "/history/logs/{}"),- ("GET", "/history/markdown/{}"),- ("GET", "/history/report/{}"),- ("GET", "/history/status/{}"),- ("GET", "/library"),- ("GET", "/library/api/collections"),- ("GET", "/library/api/collections/list"),- ("GET", "/library/api/collections/{}/documents"),- ("GET", "/library/api/collections/{}/index"),- ("GET", "/library/api/collections/{}/index/status"),- ("GET", "/library/api/collections/{}/preview"),- ("GET", "/library/api/config/supported-formats"),- ("GET", "/library/api/document/{}/pdf"),- ("GET", "/library/api/document/{}/pdf-url"),- ("GET", "/library/api/document/{}/preview"),- ("GET", "/library/api/document/{}/text"),- ("GET", "/library/api/documents"),- ("GET", "/library/api/get-research-sources/{}"),- ("GET", "/library/api/rag/documents"),- ("GET", "/library/api/rag/index-all"),- ("GET", "/library/api/rag/info"),- ("GET", "/library/api/rag/models"),- ("GET", "/library/api/rag/settings"),- ("GET", "/library/api/rag/stats"),- ("GET", "/library/api/research-history/collection"),- ("GET", "/library/api/research-list"),- ("GET", "/library/api/stats"),- ("GET", "/library/api/zotero/collections"),- ("GET", "/library/api/zotero/config"),- ("GET", "/library/api/zotero/groups"),- ("GET", "/library/api/zotero/status"),- ("GET", "/library/collections"),- ("GET", "/library/collections/create"),- ("GET", "/library/collections/{}"),- ("GET", "/library/collections/{}/upload"),- ("GET", "/library/document/{}"),- ("GET", "/library/document/{}/chunks"),- ("GET", "/library/document/{}/pdf"),- ("GET", "/library/document/{}/txt"),- ("GET", "/library/download-manager"),- ("GET", "/library/embedding-settings"),- ("GET", "/library/search"),- ("GET", "/library/search/api/keyword"),- ("GET", "/library/search/api/semantic"),- ("GET", "/library/zotero"),- ("GET", "/metrics"),- ("GET", "/metrics/api/context-overflow"),- ("GET", "/metrics/api/cost-analytics"),- ("GET", "/metrics/api/domain-classifications"),- ("GET", "/metrics/api/domain-classifications/progress"),- ("GET", "/metrics/api/domain-classifications/summary"),- ("GET", "/metrics/api/journal-data/status"),- ("GET", "/metrics/api/journals"),- ("GET", "/metrics/api/journals/research/{}"),- ("GET", "/metrics/api/journals/user-research"),- ("GET", "/metrics/api/link-analytics"),- ("GET", "/metrics/api/metrics"),- ("GET", "/metrics/api/metrics/enhanced"),- ("GET", "/metrics/api/metrics/research/{}"),- ("GET", "/metrics/api/metrics/research/{}/links"),- ("GET", "/metrics/api/metrics/research/{}/search"),- ("GET", "/metrics/api/metrics/research/{}/timeline"),- ("GET", "/metrics/api/pricing"),- ("GET", "/metrics/api/pricing/{}"),- ("GET", "/metrics/api/rate-limiting"),- ("GET", "/metrics/api/rate-limiting/current"),- ("GET", "/metrics/api/ratings/{}"),- ("GET", "/metrics/api/research-costs/{}"),- ("GET", "/metrics/api/research/{}/context-overflow"),- ("GET", "/metrics/api/star-reviews"),- ("GET", "/metrics/context-overflow"),- ("GET", "/metrics/costs"),- ("GET", "/metrics/journals"),- ("GET", "/metrics/links"),- ("GET", "/metrics/star-reviews"),- ("GET", "/news"),- ("GET", "/news/api/categories"),- ("GET", "/news/api/feed"),- ("GET", "/news/api/scheduler/stats"),- ("GET", "/news/api/scheduler/status"),- ("GET", "/news/api/scheduler/users"),- ("GET", "/news/api/search-history"),- ("GET", "/news/api/subscription/folders"),- ("GET", "/news/api/subscription/stats"),- ("GET", "/news/api/subscription/subscriptions/organized"),- ("GET", "/news/api/subscriptions/current"),- ("GET", "/news/api/subscriptions/{}"),- ("GET", "/news/api/subscriptions/{}/history"),- ("GET", "/news/subscriptions"),- ("GET", "/news/subscriptions/new"),- ("GET", "/news/subscriptions/{}/edit"),- ("GET", "/notes"),- ("GET", "/notes/api/documents/{}/annotations"),- ("GET", "/notes/api/documents/{}/notes"),- ("GET", "/notes/api/notes"),- ("GET", "/notes/api/notes/ask-context"),- ("GET", "/notes/api/notes/search-for-linking"),- ("GET", "/notes/api/notes/semantic-search"),- ("GET", "/notes/api/notes/{}"),- ("GET", "/notes/api/notes/{}/backlinks"),- ("GET", "/notes/api/notes/{}/collections"),- ("GET", "/notes/api/notes/{}/outgoing-links"),- ("GET", "/notes/api/notes/{}/research"),- ("GET", "/notes/api/notes/{}/similar"),- ("GET", "/notes/api/notes/{}/suggested-links"),- ("GET", "/notes/api/notes/{}/unlinked-mentions"),- ("GET", "/notes/api/notes/{}/versions"),- ("GET", "/notes/api/notes/{}/versions/semantic-diff"),- ("GET", "/notes/api/notes/{}/versions/{}"),- ("GET", "/notes/api/research/{}/annotations"),- ("GET", "/notes/api/research/{}/notes"),- ("GET", "/notes/{}"),- ("GET", "/progress/{}"),- ("GET", "/research/api/check/ollama_model"),- ("GET", "/research/api/check/ollama_status"),- ("GET", "/research/api/resources/{}"),- ("GET", "/research/api/settings/current-config"),- ("GET", "/research/api/status/{}"),- ("GET", "/results/{}"),- ("GET", "/settings"),- ("GET", "/settings/api"),- ("GET", "/settings/api/available-models"),- ("GET", "/settings/api/available-search-engines"),- ("GET", "/settings/api/backup-status"),- ("GET", "/settings/api/bulk"),- ("GET", "/settings/api/categories"),- ("GET", "/settings/api/data-location"),- ("GET", "/settings/api/ollama-status"),- ("GET", "/settings/api/rate-limiting/status"),- ("GET", "/settings/api/search-favorites"),- ("GET", "/settings/api/types"),- ("GET", "/settings/api/ui_elements"),- ("GET", "/settings/api/warnings"),- ("GET", "/settings/api/{}"),- ("GET", "/settings/api_keys"),- ("GET", "/settings/collections"),- ("GET", "/settings/llm"),- ("GET", "/settings/main"),- ("GET", "/settings/search_engines"),- ("PATCH", "/api/chat/sessions/{}"),- ("PATCH", "/api/news/subscriptions/{}"),- ("PATCH", "/notes/api/notes/{}/research/{}"),- ("POST", "/api/chat/sessions"),- ("POST", "/api/chat/sessions/{}/attempts/{}/retry"),- ("POST", "/api/chat/sessions/{}/generate-title"),- ("POST", "/api/chat/sessions/{}/messages"),- ("POST", "/api/clear_history"),- ("POST", "/api/followup/prepare"),- ("POST", "/api/followup/start"),- ("POST", "/api/news/feedback"),- ("POST", "/api/news/preferences"),- ("POST", "/api/news/research"),- ("POST", "/api/news/subscriptions"),- ("POST", "/api/save_raw_config"),- ("POST", "/api/scheduler/run-now"),- ("POST", "/api/start_research"),- ("POST", "/api/terminate/{}"),- ("POST", "/api/upload/pdf"),- ("POST", "/api/v1/research/{}/export/{}"),- ("POST", "/benchmark/api/cancel/{}"),- ("POST", "/benchmark/api/start"),- ("POST", "/benchmark/api/start-simple"),- ("POST", "/benchmark/api/validate-config"),- ("POST", "/library/api/check-downloads"),- ("POST", "/library/api/collections"),- ("POST", "/library/api/collections/{}/index/cancel"),- ("POST", "/library/api/collections/{}/index/start"),- ("POST", "/library/api/collections/{}/search"),- ("POST", "/library/api/collections/{}/upload"),- ("POST", "/library/api/document/{}/favorite"),- ("POST", "/library/api/documents/preview"),- ("POST", "/library/api/download-all-text"),- ("POST", "/library/api/download-bulk"),- ("POST", "/library/api/download-research/{}"),- ("POST", "/library/api/download-source"),- ("POST", "/library/api/download-text/{}"),- ("POST", "/library/api/download/{}"),- ("POST", "/library/api/mark-redownload"),- ("POST", "/library/api/open-folder"),- ("POST", "/library/api/queue-all-undownloaded"),- ("POST", "/library/api/rag/configure"),- ("POST", "/library/api/rag/index-document"),- ("POST", "/library/api/rag/remove-document"),- ("POST", "/library/api/rag/test-embedding"),- ("POST", "/library/api/research-history/convert-all"),- ("POST", "/library/api/research/{}/add-to-collection"),- ("POST", "/library/api/sync-library"),- ("POST", "/library/api/zotero/sync"),- ("POST", "/library/api/zotero/test"),- ("POST", "/metrics/api/cost-calculation"),- ("POST", "/metrics/api/domain-classifications/classify"),- ("POST", "/metrics/api/journal-data/download"),- ("POST", "/metrics/api/ratings/{}"),- ("POST", "/news/api/check-overdue"),- ("POST", "/news/api/feedback/batch"),- ("POST", "/news/api/feedback/{}"),- ("POST", "/news/api/preferences"),- ("POST", "/news/api/research/{}"),- ("POST", "/news/api/scheduler/check-now"),- ("POST", "/news/api/scheduler/cleanup-now"),- ("POST", "/news/api/scheduler/start"),- ("POST", "/news/api/scheduler/stop"),- ("POST", "/news/api/search-history"),- ("POST", "/news/api/subscribe"),- ("POST", "/news/api/subscription/folders"),- ("POST", "/news/api/subscriptions/{}/run"),- ("POST", "/news/api/vote"),- ("POST", "/notes/api/documents/{}/annotations"),- ("POST", "/notes/api/documents/{}/notes"),- ("POST", "/notes/api/notes"),- ("POST", "/notes/api/notes/resolve-link"),- ("POST", "/notes/api/notes/suggest-tags"),- ("POST", "/notes/api/notes/synthesize"),- ("POST", "/notes/api/notes/synthesize/preview"),- ("POST", "/notes/api/notes/{}/accept-link"),- ("POST", "/notes/api/notes/{}/collections"),- ("POST", "/notes/api/notes/{}/fact-check"),- ("POST", "/notes/api/notes/{}/fact-check/{}/grade"),- ("POST", "/notes/api/notes/{}/index"),- ("POST", "/notes/api/notes/{}/key-concepts"),- ("POST", "/notes/api/notes/{}/research"),- ("POST", "/notes/api/notes/{}/research-questions"),- ("POST", "/notes/api/notes/{}/research/reorder"),- ("POST", "/notes/api/notes/{}/similar-passages"),- ("POST", "/notes/api/notes/{}/summarize"),- ("POST", "/notes/api/notes/{}/versions/{}/restore"),- ("POST", "/notes/api/research/{}/annotations"),- ("POST", "/notes/api/research/{}/notes"),- ("POST", "/notes/api/research/{}/save-as-note"),- ("POST", "/open_file_location"),- ("POST", "/research/api/resources/{}"),- ("POST", "/research/api/start"),- ("POST", "/research/api/terminate/{}"),- ("POST", "/settings/api/import"),- ("POST", "/settings/api/notifications/test-url"),- ("POST", "/settings/api/rate-limiting/cleanup"),- ("POST", "/settings/api/rate-limiting/engines/{}/reset"),- ("POST", "/settings/api/search-favorites/toggle"),- ("POST", "/settings/fix_corrupted_settings"),- ("POST", "/settings/open_file_location"),- ("POST", "/settings/reset_to_defaults"),- ("POST", "/settings/save_all_settings"),- ("POST", "/settings/save_settings"),- ("PUT", "/api/news/subscriptions/{}"),- ("PUT", "/library/api/collections/{}"),- ("PUT", "/news/api/subscription/folders/{}"),- ("PUT", "/news/api/subscription/subscriptions/{}"),- ("PUT", "/news/api/subscriptions/{}"),- ("PUT", "/notes/api/notes/{}"),- ("PUT", "/settings/api/search-favorites"),- ("PUT", "/settings/api/{}"),- }-)---_FLASK_CONVERTER = re.compile(- r"<(?:[a-zA-Z_][a-zA-Z0-9_]*:)?([a-zA-Z_][a-zA-Z0-9_]*)>"-)-_PARAM = re.compile(r"\{[^}]*\}")---def anon_path(path: str) -> str:- """Erase parameter names so Flask and FastAPI paths compare.-- ``/progress/<string:research_id>`` and ``/progress/{research_id}`` both- become ``/progress/{}``. The trailing slash is dropped because the port- normalises ``/news/`` to ``/news``.- """- path = _FLASK_CONVERTER.sub("{}", path)- path = _PARAM.sub("{}", path)- return path.rstrip("/") or "/"---def flask_login_required_routes(root: Path) -> set:- """``{(method, anon path)}`` for every ``@login_required`` Flask route.-- ``root`` is a ``local_deep_research`` package directory (here: one- extracted from ``origin/main``). Blueprint prefixes come from the- ``Blueprint(...)`` call, composed with :data:`MAIN_BLUEPRINT_MOUNTS` for- the four blueprints whose live mount prefix differs.- """- found: set = set()- for path in sorted(root.rglob("*.py")):- text = path.read_text(encoding="utf-8")- if ".route(" not in text or "login_required" not in text:- continue- try:- tree = ast.parse(text, filename=str(path))- except SyntaxError: # pragma: no cover- continue- rel = path.relative_to(root).as_posix()- declared = {}- for node in ast.walk(tree):- if not (- isinstance(node, ast.Assign)- and isinstance(node.value, ast.Call)- ):- continue- func = node.value.func- name = func.id if isinstance(func, ast.Name) else None- if name != "Blueprint":- continue- prefix = ""- for kw in node.value.keywords:- if kw.arg == "url_prefix" and isinstance(- kw.value, ast.Constant- ):- prefix = kw.value.value or ""- for target in node.targets:- if isinstance(target, ast.Name):- declared[target.id] = prefix- for node in ast.walk(tree):- if not isinstance(- node, (ast.FunctionDef, ast.AsyncFunctionDef)- ) or "login_required" not in _decorator_names(node):- continue- for dec in node.decorator_list:- if not (- isinstance(dec, ast.Call)- and isinstance(dec.func, ast.Attribute)- and dec.func.attr == "route"- and isinstance(dec.func.value, ast.Name)- ):- continue- var = dec.func.value.id- prefix = MAIN_BLUEPRINT_MOUNTS.get(- (rel, var), declared.get(var, "")- )- if (rel, var) in MAIN_BLUEPRINT_MOUNTS:- prefix += declared.get(var, "")- raw = (- dec.args[0].value- if dec.args and isinstance(dec.args[0], ast.Constant)- else "<dynamic>"- )- methods = ["GET"]- for kw in dec.keywords:- if kw.arg == "methods" and isinstance(- kw.value, (ast.List, ast.Tuple)- ):- methods = [- e.value- for e in kw.value.elts- if isinstance(e, ast.Constant)- ]- for method in methods:- found.add((method.upper(), anon_path(prefix + raw)))- return found---def _repo_root() -> Path:- return Path(__file__).resolve().parents[2]---def _extract_origin_main(destination: Path) -> Path | None:- """``git archive`` origin/main's package into ``destination``.-- Returns the extracted package directory, or None when the ref is not- available (shallow clone, no ``origin`` remote) so the caller can skip.- """- archive = destination / "main.tar"- try:- with archive.open("wb") as handle:- subprocess.run(- [- "git",- "archive",- "origin/main",- "src/local_deep_research",- ],- cwd=_repo_root(),- stdout=handle,- stderr=subprocess.DEVNULL,- check=True,- timeout=120,- )- except (- subprocess.CalledProcessError,- subprocess.TimeoutExpired,- FileNotFoundError,- OSError,- ):- return None- with tarfile.open(archive) as tar:- tar.extractall(destination, filter="data") # noqa: S202- package = destination / "src" / "local_deep_research"- return package if package.is_dir() else None--# ---------------------------------------------------------------------------# Anti-vacuity guard 1: the route table itself# ---------------------------------------------------------------------------@@ -1175,77 +661,10 @@ def test_auth_closure_resolves_the_real_dependency_graph():# ----------------------------------------------------------------------------# Headline 1: auth presence, measured against main+# Current unauthenticated surface and CSRF intersection# ----------------------------------------------------------------------------def test_no_route_lost_authentication_relative_to_main():- """No route that required login on main is unauthenticated in the port.-- This is the migration's central risk: ``@login_required`` was a decorator- on the view, ``Depends(require_auth)`` is a parameter default in the- signature, and the translation was done by hand 300+ times. A dropped one- is invisible to every test that only exercises the logged-in path.-- Each of main's authenticated ``(method, path)`` pairs must land on a port- route that transitively depends on ``require_auth``, be a deliberate- path move (:data:`MAIN_TO_PORT_PATH`), or be a deliberately removed- duplicate (:data:`MAIN_ROUTES_DROPPED_BY_THE_PORT`).- """- port_auth: dict = {}- for route in route_table():- key = (route.method, anon_path(route.path))- port_auth[key] = port_auth.get(key, False) or route.requires_auth-- regressions = []- unmapped = []- for method, path in sorted(MAIN_LOGIN_REQUIRED):- if (method, path) in MAIN_ROUTES_DROPPED_BY_THE_PORT:- continue- target = (method, MAIN_TO_PORT_PATH.get(path, path))- if target not in port_auth:- unmapped.append((method, path))- elif not port_auth[target]:- regressions.append((method, path))-- assert not regressions, (- "AUTH REGRESSION — these routes required login on main and are "- "reachable unauthenticated in the port:\n "- + "\n ".join(f"{m} {p}" for m, p in regressions)- )- assert not unmapped, (- "these authenticated main routes have no port counterpart and are "- "not on the reviewed removed/moved lists; each one is either a lost "- "endpoint or a lost auth check that changed path:\n "- + "\n ".join(f"{m} {p}" for m, p in unmapped)- )---def test_main_login_required_baseline_matches_origin_main(tmp_path):- """The frozen main baseline is the real one, re-derived from git.-- :data:`MAIN_LOGIN_REQUIRED` is data, not an assumption: without this test- it could drift (or have been mis-extracted once) and the regression test- above would compare the port against a fiction. Extracts origin/main's- package with ``git archive`` and re-runs the Flask extractor over it.- """- package = _extract_origin_main(tmp_path)- if package is None:- pytest.skip("origin/main is not available in this checkout")-- derived = flask_login_required_routes(package)- assert len(derived) >= 300, (- f"only {len(derived)} @login_required routes found on origin/main; "- "the extractor is broken, not the port"- )- assert derived == MAIN_LOGIN_REQUIRED, (- "the frozen main baseline no longer matches origin/main.\n"- f" only on origin/main: {sorted(derived - MAIN_LOGIN_REQUIRED)}\n"- f" only in the frozen set: "- f"{sorted(MAIN_LOGIN_REQUIRED - derived)}"- )--def test_no_unauthenticated_route_is_csrf_exempt():"""The dangerous combination: no auth AND no CSRF token required.@@ -1319,12 +738,12 @@ def test_unauthenticated_routes_are_exactly_the_declared_public_set():# ----------------------------------------------------------------------------# Headline 2: the exemption x unauthenticated intersection+# Rate-limit and API-v1 exemption intersections# ---------------------------------------------------------------------------#: ``@limiter.exempt`` routes that are ALSO unauthenticated — the full#: intersection, asserted by equality. Both are static asset handlers that-#: were exempt and unauthenticated on main too (``app_factory.favicon`` /+#: were exempt and unauthenticated on the Flask baseline too (``app_factory.favicon`` /#: ``app_serve_static``). They read no database and return no user data;#: ``/static`` resolves through ``PathValidator.validate_safe_path``.UNAUTHENTICATED_AND_RATE_LIMIT_EXEMPT = frozenset(