From 97f855b40de1b9305d48fe727246a092177333f4 Mon Sep 17 00:00:00 2001 From: Paulo Victor Cordeiro <146781332+pvcordeiro@users.noreply.github.com> Date: Tue, 2 Jun 2026 18:32:38 +0100 Subject: [PATCH] fix: pass owner to start_research in chat stream path (#1265) * fix: pass owner to start_research in chat stream path Research launched from the chat stream omits the owner parameter, causing those research sessions to never appear in the user's research library (which filters by owner). All other start_research call sites in this file already pass owner=_user. * test: assert all start_research calls in chat_routes pass owner Uses AST inspection to verify every start_research() call site includes the owner= keyword argument, preventing regressions where new call sites forget to scope research by user. --- routes/chat_routes.py | 1 + tests/test_research_chat_stream_owner.py | 35 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/test_research_chat_stream_owner.py diff --git a/routes/chat_routes.py b/routes/chat_routes.py index 3f7738a..3a94c8c 100644 --- a/routes/chat_routes.py +++ b/routes/chat_routes.py @@ -711,6 +711,7 @@ def setup_chat_routes( prior_findings=_prior_findings, prior_urls=_prior_urls, on_complete=_on_research_done, + owner=_user, ) _heartbeat_counter = 0 diff --git a/tests/test_research_chat_stream_owner.py b/tests/test_research_chat_stream_owner.py new file mode 100644 index 0000000..37076b2 --- /dev/null +++ b/tests/test_research_chat_stream_owner.py @@ -0,0 +1,35 @@ +"""Verify that research launched from the chat stream passes owner to start_research.""" + +import ast +import textwrap +from pathlib import Path + +_CHAT_ROUTES = Path(__file__).resolve().parent.parent / "routes" / "chat_routes.py" + + +def test_chat_stream_start_research_passes_owner(): + """The start_research call in the chat-stream path must include owner=.""" + source = _CHAT_ROUTES.read_text(encoding="utf-8") + tree = ast.parse(source) + + # Find all calls to *.start_research or start_research + calls = [] + for node in ast.walk(tree): + if not isinstance(node, ast.Call): + continue + func = node.func + name = "" + if isinstance(func, ast.Attribute): + name = func.attr + elif isinstance(func, ast.Name): + name = func.id + if name == "start_research": + calls.append(node) + + assert calls, "No start_research calls found in chat_routes.py" + + for call in calls: + kwarg_names = [kw.arg for kw in call.keywords] + assert "owner" in kwarg_names, ( + f"start_research call at line {call.lineno} is missing owner= keyword argument" + )