Files
odysseus/tests/test_active_document_clear.py
Yeoh Ing Ji 3e49658204 refactor(tools): extract document tools to handle registry (#3666)
* feat(tools): add document management tool handlers to the agent_tools module

* feat(tools): extraced document tools for create, update, edit, suggest, and manage from tool_implementations.py

* feat(tests): refactor document tool tests to use TOOL_HANDLERS and document_tools

* refactor(tools): add document tool dispatcher and updated tool calling path

* refactor(tools): remove duplicated document management functions

* refactor(tools): removing unused functions and adding new import paths

* refactor(tools): update document tool execute methods to use context dictionary

* refactor(tests): update import paths for document tools in test files

* refactor(tests): update owner parameter format in document management tests

* refactor(tests): update import path for _owned_document_query

* feat(tools): add document management tool handlers to the agent_tools module

* feat(tools): extraced document tools for create, update, edit, suggest, and manage from tool_implementations.py

* feat(tests): refactor document tool tests to use TOOL_HANDLERS and document_tools

* refactor(tools): add document tool dispatcher and updated tool calling path

* refactor(tools): remove duplicated document management functions

* refactor(tools): removing unused functions and adding new import paths

* refactor(tools): update document tool execute methods to use context dictionary

* refactor(tests): update import paths for document tools in test files

* refactor(tests): update owner parameter format in document management tests

* refactor(tests): update import path for _owned_document_query

* refactor: update import paths for document tools

* fix(tests): correct source path for document ID test
2026-06-10 10:41:52 +02:00

39 lines
1.3 KiB
Python

"""Issue #1160 — a closed document must not stay 'active' and leak into new chats.
Closing a document tab detaches it (session_id -> NULL) or deletes it, but the
in-memory active-document pointer was never cleared, so the last-resort doc
injection re-surfaced the closed doc in later, unrelated chats. The document
routes now call clear_active_document() on detach/delete; this pins that helper.
"""
from src.agent_tools.document_tools import (
set_active_document,
get_active_document,
clear_active_document
)
def test_clear_matching_id_resets_pointer():
set_active_document("doc-123")
assert get_active_document() == "doc-123"
assert clear_active_document("doc-123") is True
assert get_active_document() is None
def test_clear_non_matching_id_leaves_other_active_doc():
set_active_document("doc-abc")
# Closing a DIFFERENT document must not clobber the currently active one.
assert clear_active_document("doc-xyz") is False
assert get_active_document() == "doc-abc"
def test_clear_without_id_clears_unconditionally():
set_active_document("doc-abc")
assert clear_active_document() is True
assert get_active_document() is None
def test_clear_when_already_none_is_safe():
set_active_document(None)
assert clear_active_document("doc-123") is False
assert get_active_document() is None