Files
odysseus/tests/test_document_deeplink.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

34 lines
1.3 KiB
Python

"""Regression guards for in-chat document deep-links (#document-<id>).
The frontend module is browser-coupled (window/fetch/document) so there's
no JS unit harness for it — these pin the source-level invariants that the
404-silent-failure fix depends on. See issue #560.
"""
from pathlib import Path
_REPO = Path(__file__).resolve().parents[1]
def test_chat_document_links_use_the_document_id():
"""The list/open tool must anchor to the real document id, not a slug —
a slug 404s against the UUID-keyed /api/document/<id> route."""
src = (_REPO / "src" / "agent_tools" /"document_tools.py").read_text(encoding="utf-8")
assert "(#document-{d.id})" in src
assert "(#document-{doc.id})" in src
def test_document_deeplink_handled_on_hashchange_and_load():
"""#document-<id> in the URL must open the doc on refresh / URL-bar nav,
not just on click."""
js = (_REPO / "static" / "js" / "document.js").read_text(encoding="utf-8")
assert "addEventListener('hashchange', _maybeOpenDocFromHash)" in js
assert "#document-" in js
def test_failed_document_load_surfaces_user_error():
"""A missing/failed document must tell the user, not fail silently."""
js = (_REPO / "static" / "js" / "document.js").read_text(encoding="utf-8")
assert "uiModule.showError" in js
assert "Document not found" in js