mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-08-10 07:28:41 -04:00
Merge verified Odysseus fixes
This commit is contained in:
@@ -354,6 +354,7 @@ async def test_build_chat_context_incognito_does_not_duplicate_current_user_mess
|
||||
monkeypatch.setitem(sys.modules, mod_name, MagicMock())
|
||||
|
||||
chat_helpers = importlib.import_module("routes.chat_helpers")
|
||||
chat_helpers._INCOGNITO_CONTEXTS.clear()
|
||||
|
||||
async def fake_preprocess(chat_handler, message, att_ids, sess, **kwargs):
|
||||
# **kwargs absorbs auto_opened_docs (added when PDF imports auto-create
|
||||
@@ -417,6 +418,68 @@ async def test_build_chat_context_incognito_does_not_duplicate_current_user_mess
|
||||
assert len(user_messages) == 1
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_build_chat_context_incognito_ignores_saved_session_history(monkeypatch):
|
||||
for mod_name in [
|
||||
"starlette.middleware",
|
||||
"starlette.middleware.base",
|
||||
"core.models",
|
||||
"core.database",
|
||||
"routes.prefs_routes",
|
||||
"routes.research_routes",
|
||||
"src.llm_core",
|
||||
"src.context_compactor",
|
||||
"src.model_context",
|
||||
"src.auth_helpers",
|
||||
]:
|
||||
if mod_name not in sys.modules:
|
||||
monkeypatch.setitem(sys.modules, mod_name, MagicMock())
|
||||
|
||||
chat_helpers = importlib.import_module("routes.chat_helpers")
|
||||
chat_helpers._INCOGNITO_CONTEXTS.clear()
|
||||
|
||||
async def fake_preprocess(chat_handler, message, att_ids, sess, **kwargs):
|
||||
return chat_helpers.PreprocessedMessage(
|
||||
enhanced_message=message,
|
||||
user_content=message,
|
||||
text_for_context=message,
|
||||
youtube_transcripts=[],
|
||||
attachment_meta=[],
|
||||
)
|
||||
|
||||
async def fake_maybe_compact(sess, endpoint_url, model, messages, headers, owner=None):
|
||||
return messages, 123, False
|
||||
|
||||
monkeypatch.setattr(chat_helpers, "preprocess", fake_preprocess)
|
||||
monkeypatch.setattr(chat_helpers, "extract_preset", lambda *_args, **_kwargs: chat_helpers.PresetInfo(0.7, 1024, None, None))
|
||||
monkeypatch.setattr(chat_helpers, "load_prefs_for_user", lambda user: {})
|
||||
monkeypatch.setattr(chat_helpers, "effective_user", lambda request: "tester")
|
||||
monkeypatch.setattr(chat_helpers, "normalize_model_id", lambda endpoint_url, model, **kwargs: None)
|
||||
monkeypatch.setattr(chat_helpers, "maybe_compact", fake_maybe_compact)
|
||||
monkeypatch.setattr(chat_helpers, "trim_for_context", lambda messages, context_length: messages)
|
||||
|
||||
sess = SimpleNamespace(
|
||||
endpoint_url="http://localhost:8000/v1",
|
||||
model="test-model",
|
||||
headers={},
|
||||
get_context_messages=lambda: [{"role": "user", "content": "older non-incognito secret"}],
|
||||
)
|
||||
chat_processor = SimpleNamespace(build_context_preface=lambda **kwargs: ([], [], []))
|
||||
|
||||
ctx = await chat_helpers.build_chat_context(
|
||||
sess=sess,
|
||||
request=SimpleNamespace(),
|
||||
chat_handler=SimpleNamespace(),
|
||||
chat_processor=chat_processor,
|
||||
message="fresh incognito turn",
|
||||
session_id="s-incog",
|
||||
incognito=True,
|
||||
)
|
||||
|
||||
assert {"role": "user", "content": "fresh incognito turn"} in ctx.messages
|
||||
assert all(m.get("content") != "older non-incognito secret" for m in ctx.messages)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_admin_agent_tools_require_admin(monkeypatch):
|
||||
auth_mod = _install_core_auth_stub(monkeypatch)
|
||||
@@ -648,6 +711,7 @@ async def test_public_agent_policy_blocks_sensitive_tools(monkeypatch):
|
||||
# here instead of silently shrinking the blocklist.
|
||||
bare_email_tools = (
|
||||
"list_email_accounts", "list_emails", "read_email", "search_emails",
|
||||
"scan_email_unsubscribes", "unsubscribe_email",
|
||||
"send_email", "reply_to_email", "draft_email", "draft_email_reply",
|
||||
"ai_draft_email_reply", "archive_email", "delete_email",
|
||||
"mark_email_read", "bulk_email", "download_attachment",
|
||||
@@ -758,6 +822,7 @@ async def test_disable_tool_email_covers_full_builtin_set(monkeypatch):
|
||||
# from the constant fails here instead of silently shrinking the toggle.
|
||||
bare_email_tools = (
|
||||
"list_email_accounts", "list_emails", "read_email", "search_emails",
|
||||
"scan_email_unsubscribes", "unsubscribe_email",
|
||||
"send_email", "reply_to_email", "draft_email", "draft_email_reply",
|
||||
"ai_draft_email_reply", "archive_email", "delete_email",
|
||||
"mark_email_read", "bulk_email", "download_attachment",
|
||||
@@ -930,7 +995,7 @@ async def test_plan_mode_blocks_mutating_email_aliases_without_mcp_inventory(mon
|
||||
denied = plan_mode_disabled_tools()
|
||||
|
||||
for tool_name in ("draft_email", "draft_email_reply", "ai_draft_email_reply",
|
||||
"download_attachment", "send_email", "delete_email"):
|
||||
"download_attachment", "send_email", "delete_email", "unsubscribe_email"):
|
||||
desc, result = await execute_tool_block(
|
||||
SimpleNamespace(tool_type=tool_name, content="{}"),
|
||||
owner="admin-user",
|
||||
@@ -949,6 +1014,17 @@ async def test_plan_mode_blocks_mutating_email_aliases_without_mcp_inventory(mon
|
||||
("mcp__email__search_emails", {"query": "x", "_odysseus_owner": "admin-user"}),
|
||||
]
|
||||
|
||||
mcp.calls.clear()
|
||||
desc, result = await execute_tool_block(
|
||||
SimpleNamespace(tool_type="scan_email_unsubscribes", content='{"limit": 1}'),
|
||||
owner="admin-user",
|
||||
disabled_tools=denied,
|
||||
)
|
||||
assert result["exit_code"] == 0
|
||||
assert mcp.calls == [
|
||||
("mcp__email__scan_email_unsubscribes", {"limit": 1, "_odysseus_owner": "admin-user"}),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_bare_email_dispatch_empty_content_calls_with_empty_args(monkeypatch):
|
||||
|
||||
Reference in New Issue
Block a user