From a8b30f541415b77d7746e86fcdf8d64e117df381 Mon Sep 17 00:00:00 2001 From: Jordan White Date: Wed, 25 Nov 2026 10:42:07 -0800 Subject: [PATCH] fix: build OKP offline citation URLs from portal path, not source_path Offline OKP citation URLs were built from the chunk `source_path` field, which is the docs.redhat.com path (/en/documentation/...). That path is not served by the offline RHOKP portal (/documentation/en-us/.../), so citations returned 404 for the documentation whose docs.redhat.com URL uses the flat/topic (modular docs) shape, which the portal's Apache compatibility rewrites do not cover. Build offline URLs from the portal path (parent_id/document_id) instead, and graft the section anchor (#heading_id) from source_path so deep-linking is preserved. This matches the documented `okp.offline` contract ("use parent_id"). Fixed across all OKP offline URL builders: - utils/responses.py: _build_okp_doc_url (also used by utils/agents/tool_processor) - utils/rag/vector_search.py: _extract_solr_document_metadata (now surfaces parent_id), _build_document_url, _convert_solr_chunks_to_rag_format - utils/referenced_documents.py: new graft_url_fragment helper Co-Authored-By: Claude Opus 4.8 --- src/utils/rag/vector_search.py | 76 ++++++++++----- src/utils/referenced_documents.py | 33 +++++++ src/utils/responses.py | 20 +++- .../unit/utils/agents/test_tool_processor.py | 17 ++-- tests/unit/utils/rag/test_vector_search.py | 50 ++++++---- tests/unit/utils/test_referenced_documents.py | 43 +++++++++ tests/unit/utils/test_responses.py | 96 +++++++++++++++---- 7 files changed, 270 insertions(+), 65 deletions(-) create mode 100644 tests/unit/utils/test_referenced_documents.py diff --git a/src/utils/rag/vector_search.py b/src/utils/rag/vector_search.py index f9eb20fb50..7b2f1c633a 100644 --- a/src/utils/rag/vector_search.py +++ b/src/utils/rag/vector_search.py @@ -29,6 +29,7 @@ set_span_attributes, ) from utils.rag.reranker import apply_byok_rerank_boost, rerank_chunks_with_cross_encoder +from utils.referenced_documents import graft_url_fragment from utils.responses import resolve_vector_store_ids if TYPE_CHECKING: @@ -310,14 +311,20 @@ async def _query_store_for_byok_rag( # pylint: disable=too-many-arguments,too-m def _extract_solr_document_metadata( chunk: Any, -) -> tuple[Optional[str], Optional[str], Optional[str], Optional[str]]: - """Extract document ID, title, reference URL, and source path from chunk metadata.""" +) -> tuple[Optional[str], Optional[str], Optional[str], Optional[str], Optional[str]]: + """Extract document ID, title, reference URL, source path and portal path. + + ``parent_id`` is the portal's own ``/documentation/en-us/...`` path and is what + offline document URLs must be built from; ``source_path`` is the docs.redhat.com + path and is only used to recover the section anchor (and for online fallbacks). + """ # 1) dict metadata metadata = getattr(chunk, "metadata", None) or {} doc_id = metadata.get("doc_id") or metadata.get("document_id") title = metadata.get("title") reference_url = metadata.get("reference_url") source_path = metadata.get("source_path") + parent_id = metadata.get("parent_id") or metadata.get("document_id") # 2) typed chunk_metadata if not doc_id: @@ -328,6 +335,11 @@ def _extract_solr_document_metadata( title = title or chunk_meta.get("title") reference_url = reference_url or chunk_meta.get("reference_url") source_path = source_path or chunk_meta.get("source_path") + parent_id = ( + parent_id + or chunk_meta.get("parent_id") + or chunk_meta.get("document_id") + ) else: doc_id = getattr(chunk_meta, "doc_id", None) or getattr( chunk_meta, "document_id", None @@ -337,8 +349,13 @@ def _extract_solr_document_metadata( chunk_meta, "reference_url", None ) source_path = source_path or getattr(chunk_meta, "source_path", None) + parent_id = ( + parent_id + or getattr(chunk_meta, "parent_id", None) + or getattr(chunk_meta, "document_id", None) + ) - return doc_id, title, reference_url, source_path + return doc_id, title, reference_url, source_path, parent_id def _process_byok_rag_chunks_for_documents( @@ -432,16 +449,16 @@ def _process_solr_chunks_for_documents( "Extracting doc ids from chunk id: %s", getattr(chunk, "chunk_id", None) ) - doc_id, title, reference_url, source_path = _extract_solr_document_metadata( - chunk + doc_id, title, reference_url, source_path, parent_id = ( + _extract_solr_document_metadata(chunk) ) - if not doc_id and not reference_url and not source_path: + if not doc_id and not reference_url and not source_path and not parent_id: continue # Build URL based on offline flag doc_url, reference_doc = _build_document_url( - offline, doc_id, reference_url, source_path + offline, doc_id, reference_url, source_path, parent_id ) if reference_doc and reference_doc not in metadata_doc_ids: @@ -773,14 +790,22 @@ def _build_document_url( doc_id: Optional[str], reference_url: Optional[str], source_path: Optional[str] = None, + parent_id: Optional[str] = None, ) -> tuple[str, Optional[str]]: """Build document URL based on offline flag and available metadata. + In offline mode the URL is built from the portal path (``parent_id`` / + ``doc_id``), i.e. the portal's ``/documentation/en-us/...`` layout, with the + section anchor grafted from ``source_path`` to preserve deep-linking. The raw + ``source_path`` is the docs.redhat.com path and is not served offline, so it is + used only for its ``#fragment``. + Args: - offline: Whether to use offline mode (source_path) or online mode (reference_url) + offline: Whether to use offline mode (portal path) or online mode (reference_url) doc_id: Document ID from chunk metadata reference_url: Reference URL from chunk metadata (online deep-link) - source_path: Relative path from chunk metadata (offline deep-link) + source_path: docs.redhat.com path from chunk metadata (anchor source offline) + parent_id: Portal path from chunk metadata (offline deep-link) Returns: Tuple of (doc_url, reference_doc) where: @@ -790,7 +815,7 @@ def _build_document_url( """ base_url = _get_okp_base_url() if offline: - reference_doc = source_path or doc_id + reference_doc = graft_url_fragment(parent_id or doc_id, source_path) else: reference_doc = reference_url or doc_id doc_url = _join_okp_doc_url(base_url, reference_doc) @@ -820,18 +845,22 @@ def _convert_solr_chunks_to_rag_format( # Build attributes with document metadata attributes = {} - # Legacy logic: extract doc_url from chunk metadata based on offline flag - if chunk.metadata: - if offline: - source_path = chunk.metadata.get("source_path") - if source_path: - attributes["doc_url"] = _join_okp_doc_url( - _get_okp_base_url(), source_path - ) - else: - reference_url = chunk.metadata.get("reference_url") - if reference_url: - attributes["doc_url"] = reference_url + # Legacy logic: extract doc_url from chunk metadata based on offline flag. + # Offline URLs use the portal path (parent_id/document_id); source_path is + # the docs.redhat.com path and only contributes the section anchor. + metadata = chunk.metadata or {} + source_path = metadata.get("source_path") + if offline: + portal_path = metadata.get("parent_id") or metadata.get("document_id") + if portal_path: + attributes["doc_url"] = _join_okp_doc_url( + _get_okp_base_url(), + graft_url_fragment(portal_path, source_path), + ) + else: + reference_url = metadata.get("reference_url") + if reference_url: + attributes["doc_url"] = reference_url # For Solr chunks, also extract from chunk_metadata if hasattr(chunk, "chunk_metadata") and chunk.chunk_metadata: @@ -841,7 +870,8 @@ def _convert_solr_chunks_to_rag_format( # Build URL if not already set if "doc_url" not in attributes and offline and doc_id: attributes["doc_url"] = _join_okp_doc_url( - _get_okp_base_url(), doc_id + _get_okp_base_url(), + graft_url_fragment(doc_id, source_path), ) # Get score from retrieved_scores list if available diff --git a/src/utils/referenced_documents.py b/src/utils/referenced_documents.py index ae5cf59850..6f7ec55a32 100644 --- a/src/utils/referenced_documents.py +++ b/src/utils/referenced_documents.py @@ -5,6 +5,39 @@ from models.common.turn_summary import ReferencedDocument +def graft_url_fragment( + reference: Optional[str], source_path: Optional[str] +) -> Optional[str]: + """Append the ``#fragment`` from ``source_path`` onto ``reference``. + + OKP offline document URLs are built from the portal path (``parent_id`` / + ``document_id``), which points at the page but carries no section anchor. The + chunk's ``source_path`` does carry the matched section's ``#heading_id``. + Grafting that fragment onto the portal path preserves deep-linking to the + matched section. + + This is a no-op when ``reference`` is empty, when ``source_path`` is empty or + has no ``#`` fragment, when the fragment is empty, or when ``reference`` + already has a fragment of its own. + + Args: + reference: The portal-relative document path to augment. + source_path: The chunk source path that may carry a ``#fragment``. + + Returns: + ``reference`` with the fragment appended, or the original ``reference``. + + """ + if not reference or not source_path or "#" not in source_path: + return reference + if "#" in str(reference): + return reference + fragment = source_path.split("#", 1)[1] + if not fragment: + return reference + return f"{reference}#{fragment}" + + def deduplicate_referenced_documents( docs: list[ReferencedDocument], ) -> list[ReferencedDocument]: diff --git a/src/utils/responses.py b/src/utils/responses.py index 6e6ed8cd16..0781a069bf 100644 --- a/src/utils/responses.py +++ b/src/utils/responses.py @@ -135,6 +135,7 @@ normalize_vertex_ai_model_id, prepare_input, ) +from utils.referenced_documents import graft_url_fragment from utils.suid import is_moderation_id, to_ogx_conversation_id from utils.token_counter import TokenCounter @@ -917,8 +918,16 @@ def apply_mcp_headers_to_explicit_tools( def _build_okp_doc_url(attributes: dict[str, Any]) -> Optional[str]: """Build a full OKP document URL from file_search result attributes. - Uses the ``offline`` flag from OKP configuration to choose between - ``source_path`` (disconnected clusters) and ``reference_url`` (online). + Uses the ``offline`` flag from OKP configuration to choose the relative path: + + * offline (disconnected / RHOKP portal): the ``parent_id`` / ``document_id`` + path, i.e. the portal's own ``/documentation/en-us/...`` layout. The chunk's + section anchor is preserved by grafting the ``#fragment`` from + ``source_path`` so deep links keep working. ``source_path`` itself is the + docs.redhat.com path (``/en/documentation/...``) and is **not** served by the + offline portal, so it must not be used as the path. + * online: ``reference_url`` (the docs.redhat.com URL). + The chosen relative path is joined with the OKP base URL. Parameters: @@ -930,7 +939,12 @@ def _build_okp_doc_url(attributes: dict[str, Any]) -> Optional[str]: """ offline = configuration.okp.offline if offline: - reference = attributes.get("source_path") or attributes.get("doc_id") + reference = ( + attributes.get("parent_id") + or attributes.get("document_id") + or attributes.get("doc_id") + ) + reference = graft_url_fragment(reference, attributes.get("source_path")) else: reference = attributes.get("reference_url") or attributes.get("doc_id") diff --git a/tests/unit/utils/agents/test_tool_processor.py b/tests/unit/utils/agents/test_tool_processor.py index c03afc58f5..3d3f2c8555 100644 --- a/tests/unit/utils/agents/test_tool_processor.py +++ b/tests/unit/utils/agents/test_tool_processor.py @@ -404,18 +404,20 @@ def test_okp_online_builds_full_url(self, mocker: MockerFixture) -> None: assert str(doc.doc_url) == "https://docs.example.com/en/docs/guide/index" assert doc.source == "okp" - def test_okp_offline_builds_url_from_source_path( + def test_okp_offline_builds_url_from_portal_path( self, mocker: MockerFixture ) -> None: - """Test OKP offline mode uses source_path with OKP base URL.""" + """Test OKP offline mode uses the portal path and grafts the source anchor.""" mock_config = mocker.patch("utils.responses.configuration") mock_config.okp.offline = True - mock_config.okp.rhokp_url = AnyUrl("http://localhost:8081/") + mock_config.okp.rhokp_url = AnyUrl("http://localhost:8080/") result = _file_search_result( attributes={ - "reference_url": "https://docs.redhat.com/en/docs/guide/index", - "source_path": "/en/docs/guide/index", + "reference_url": "https://docs.redhat.com/en/docs/guide/index#frag", + "source_path": "/en/docs/guide/index#frag", + "parent_id": "/documentation/en-us/p/1/guide", + "document_id": "/documentation/en-us/p/1/guide", "title": "OKP Guide", "source": "okp", } @@ -424,7 +426,10 @@ def test_okp_offline_builds_url_from_source_path( doc = build_referenced_document(result, ["portal-rag"], {"portal-rag": "okp"}) assert doc is not None - assert str(doc.doc_url) == "http://localhost:8081/en/docs/guide/index" + assert ( + str(doc.doc_url) + == "http://localhost:8080/documentation/en-us/p/1/guide#frag" + ) assert doc.source == "okp" def test_non_okp_source_uses_reference_url_directly(self) -> None: diff --git a/tests/unit/utils/rag/test_vector_search.py b/tests/unit/utils/rag/test_vector_search.py index 59ced4b5f8..06a167f839 100644 --- a/tests/unit/utils/rag/test_vector_search.py +++ b/tests/unit/utils/rag/test_vector_search.py @@ -408,16 +408,18 @@ def test_extract_from_dict_metadata(self, mocker: MockerFixture) -> None: "title": "Test Document", "reference_url": "https://example.com/doc", "source_path": "/docs/page.html#section", + "parent_id": "/documentation/en-us/p/1/topic", } - doc_id, title, reference_url, source_path = _extract_solr_document_metadata( - chunk + doc_id, title, reference_url, source_path, parent_id = ( + _extract_solr_document_metadata(chunk) ) assert doc_id == "doc_123" assert title == "Test Document" assert reference_url == "https://example.com/doc" assert source_path == "/docs/page.html#section" + assert parent_id == "/documentation/en-us/p/1/topic" def test_extract_from_chunk_metadata_object(self, mocker: MockerFixture) -> None: """Test extraction from typed chunk_metadata object.""" @@ -426,33 +428,37 @@ def test_extract_from_chunk_metadata_object(self, mocker: MockerFixture) -> None chunk_meta.title = "Another Document" chunk_meta.reference_url = "https://example.com/another" chunk_meta.source_path = "/docs/another.html" + chunk_meta.parent_id = "/documentation/en-us/p/1/another" + chunk_meta.document_id = "/documentation/en-us/p/1/another" chunk = mocker.Mock() chunk.metadata = {} chunk.chunk_metadata = chunk_meta - doc_id, title, reference_url, source_path = _extract_solr_document_metadata( - chunk + doc_id, title, reference_url, source_path, parent_id = ( + _extract_solr_document_metadata(chunk) ) assert doc_id == "doc_456" assert title == "Another Document" assert reference_url == "https://example.com/another" assert source_path == "/docs/another.html" + assert parent_id == "/documentation/en-us/p/1/another" def test_extract_with_missing_fields(self, mocker: MockerFixture) -> None: """Test extraction when some fields are missing.""" chunk = mocker.Mock() chunk.metadata = {"doc_id": "doc_789"} - doc_id, title, reference_url, source_path = _extract_solr_document_metadata( - chunk + doc_id, title, reference_url, source_path, parent_id = ( + _extract_solr_document_metadata(chunk) ) assert doc_id == "doc_789" assert title is None assert reference_url is None assert source_path is None + assert parent_id is None class TestGetOkpBaseUrl: @@ -480,22 +486,25 @@ def test_returns_default_when_rhokp_url_unset(self, mocker: MockerFixture) -> No class TestBuildDocumentUrl: """Tests for _build_document_url function.""" - def test_offline_mode_with_source_path(self, mocker: MockerFixture) -> None: - """Test URL building in offline mode with source_path.""" + def test_offline_mode_uses_parent_id_with_anchor( + self, mocker: MockerFixture + ) -> None: + """Test offline mode builds from parent_id and grafts the source_path anchor.""" config_mock = mocker.Mock() config_mock.okp.rhokp_url = "https://mimir.test" mocker.patch("utils.rag.vector_search.configuration", config_mock) doc_url, reference_doc = _build_document_url( offline=True, - doc_id="doc_123", + doc_id="/documentation/en-us/p/1/install_chunk_2", reference_url=None, - source_path="/docs/install.html#step-3", + source_path="/en/documentation/p/1/install#step-3", + parent_id="/documentation/en-us/p/1/install", ) - assert doc_url == "https://mimir.test/docs/install.html#step-3" - assert reference_doc == "/docs/install.html#step-3" + assert doc_url == "https://mimir.test/documentation/en-us/p/1/install#step-3" + assert reference_doc == "/documentation/en-us/p/1/install#step-3" def test_offline_mode_falls_back_to_doc_id(self, mocker: MockerFixture) -> None: - """Test offline mode falls back to doc_id when source_path is None.""" + """Test offline mode falls back to doc_id when parent_id/source_path absent.""" config_mock = mocker.Mock() config_mock.okp.rhokp_url = "https://mimir.test" mocker.patch("utils.rag.vector_search.configuration", config_mock) @@ -541,10 +550,16 @@ class TestConvertSolrChunksToRagFormat: """Tests for _convert_solr_chunks_to_rag_format function.""" def test_convert_with_metadata_offline(self, mocker: MockerFixture) -> None: - """Test conversion with metadata in offline mode uses source_path.""" + """Test offline conversion builds doc_url from parent_id with grafted anchor.""" + config_mock = mocker.Mock() + config_mock.okp.rhokp_url = "https://mimir.test" + mocker.patch("utils.rag.vector_search.configuration", config_mock) chunk = mocker.Mock() chunk.content = "Test content" - chunk.metadata = {"source_path": "/docs/install.html#step-3"} + chunk.metadata = { + "parent_id": "/documentation/en-us/p/1/install", + "source_path": "/en/documentation/p/1/install#step-3", + } chunk.chunk_metadata = None result = _convert_solr_chunks_to_rag_format([chunk], [0.85], offline=True) @@ -555,7 +570,10 @@ def test_convert_with_metadata_offline(self, mocker: MockerFixture) -> None: assert result[0].score == 0.85 assert result[0].attributes is not None assert "doc_url" in result[0].attributes - assert "/docs/install.html#step-3" in result[0].attributes["doc_url"] + assert ( + result[0].attributes["doc_url"] + == "https://mimir.test/documentation/en-us/p/1/install#step-3" + ) def test_convert_with_metadata_online(self, mocker: MockerFixture) -> None: """Test conversion with metadata in online mode.""" diff --git a/tests/unit/utils/test_referenced_documents.py b/tests/unit/utils/test_referenced_documents.py new file mode 100644 index 0000000000..f910493cc7 --- /dev/null +++ b/tests/unit/utils/test_referenced_documents.py @@ -0,0 +1,43 @@ +"""Unit tests for utils.referenced_documents.""" + +from utils.referenced_documents import graft_url_fragment + + +class TestGraftUrlFragment: + """Tests for graft_url_fragment.""" + + def test_grafts_fragment_onto_portal_path(self) -> None: + """The #fragment from source_path is appended to the portal path.""" + assert ( + graft_url_fragment( + "/documentation/en-us/p/1/topic", + "/en/documentation/p/1/topic#GUID-abc", + ) + == "/documentation/en-us/p/1/topic#GUID-abc" + ) + + def test_noop_when_source_path_has_no_fragment(self) -> None: + """No change when source_path carries no anchor.""" + assert ( + graft_url_fragment("/documentation/en-us/p/1/topic", "/en/documentation/x") + == "/documentation/en-us/p/1/topic" + ) + + def test_noop_when_reference_already_has_fragment(self) -> None: + """An existing fragment on the reference is preserved (not doubled).""" + assert ( + graft_url_fragment("/p/1/topic#existing", "/s#other") + == "/p/1/topic#existing" + ) + + def test_noop_when_reference_is_none(self) -> None: + """None reference stays None.""" + assert graft_url_fragment(None, "/s#frag") is None + + def test_noop_when_source_path_is_none(self) -> None: + """None source_path leaves the reference unchanged.""" + assert graft_url_fragment("/p/1/topic", None) == "/p/1/topic" + + def test_noop_when_fragment_is_empty(self) -> None: + """A trailing '#' with no fragment is ignored.""" + assert graft_url_fragment("/p/1/topic", "/s#") == "/p/1/topic" diff --git a/tests/unit/utils/test_responses.py b/tests/unit/utils/test_responses.py index cbfff359b5..de3ce3971c 100644 --- a/tests/unit/utils/test_responses.py +++ b/tests/unit/utils/test_responses.py @@ -3678,22 +3678,69 @@ def test_online_mode_uses_reference_url(self, mocker: MockerFixture) -> None: ) assert url == "https://docs.openshift.com/docs/pipelines/config.html" - def test_offline_mode_uses_source_path(self, mocker: MockerFixture) -> None: - """Test that offline mode (offline=True) uses source_path.""" + def test_offline_mode_uses_portal_path_with_anchor( + self, mocker: MockerFixture + ) -> None: + """Test offline mode uses the portal path and grafts the source_path anchor. + + ``source_path`` is the docs.redhat.com path and must not be used as the + offline path; only its ``#fragment`` is carried over for deep-linking. + """ mock_okp = mocker.Mock() mock_okp.offline = True - mock_okp.rhokp_url = "https://docs.openshift.com" + mock_okp.rhokp_url = "https://okp.example.com" mock_config = mocker.Mock() mock_config.okp = mock_okp mocker.patch("utils.responses.configuration", mock_config) url = _build_okp_doc_url( { - "reference_url": "/docs/pipelines/config.html", - "source_path": "pipelines/config.html", + "reference_url": "https://docs.redhat.com/en/documentation/p/1/topic", + "source_path": "/en/documentation/p/1/topic#GUID-abc", + "parent_id": "/documentation/en-us/p/1/topic", + "document_id": "/documentation/en-us/p/1/topic", } ) - assert url == "https://docs.openshift.com/pipelines/config.html" + assert url == "https://okp.example.com/documentation/en-us/p/1/topic#GUID-abc" + + def test_offline_prefers_parent_id_over_document_id( + self, mocker: MockerFixture + ) -> None: + """Test offline mode prefers parent_id, then document_id, then doc_id.""" + mock_okp = mocker.Mock() + mock_okp.offline = True + mock_okp.rhokp_url = "https://okp.example.com" + mock_config = mocker.Mock() + mock_config.okp = mock_okp + mocker.patch("utils.responses.configuration", mock_config) + + url = _build_okp_doc_url( + { + "parent_id": "/documentation/en-us/p/1/topic", + "document_id": "/other/path", + "doc_id": "/documentation/en-us/p/1/topic_chunk_3", + } + ) + assert url == "https://okp.example.com/documentation/en-us/p/1/topic" + + def test_offline_portal_path_without_source_anchor( + self, mocker: MockerFixture + ) -> None: + """Test offline mode leaves the portal path unchanged when no anchor exists.""" + mock_okp = mocker.Mock() + mock_okp.offline = True + mock_okp.rhokp_url = "https://okp.example.com" + mock_config = mocker.Mock() + mock_config.okp = mock_okp + mocker.patch("utils.responses.configuration", mock_config) + + url = _build_okp_doc_url( + { + "source_path": "/en/documentation/p/1/topic", + "document_id": "/documentation/en-us/p/1/topic", + } + ) + assert url == "https://okp.example.com/documentation/en-us/p/1/topic" def test_online_falls_back_to_doc_id(self, mocker: MockerFixture) -> None: """Test online mode falls back to doc_id when reference_url is absent.""" @@ -3708,7 +3755,7 @@ def test_online_falls_back_to_doc_id(self, mocker: MockerFixture) -> None: assert url == "https://docs.openshift.com/some-doc-id" def test_offline_falls_back_to_doc_id(self, mocker: MockerFixture) -> None: - """Test offline mode falls back to doc_id when source_path is absent.""" + """Test offline mode falls back to doc_id when parent_id/document_id absent.""" mock_okp = mocker.Mock() mock_okp.offline = True mock_okp.rhokp_url = "https://docs.openshift.com" @@ -3788,23 +3835,40 @@ def test_okp_online_builds_full_url(self, mocker: MockerFixture) -> None: assert docs[0].doc_title == "Pipeline Config" assert docs[0].source == "okp" - def test_okp_offline_builds_url_from_source_path( + def test_okp_offline_builds_url_from_portal_path( self, mocker: MockerFixture ) -> None: - """Test OKP result builds URL from source_path in offline mode.""" + """Test OKP result builds the offline URL from the portal path with anchor. + + Regression test for the reported 404: the offline doc_url must use the + portal ``/documentation/en-us/...`` path (from parent_id/document_id), not + the docs.redhat.com ``/en/documentation/...`` source_path, while keeping the + section anchor. + """ mock_okp = mocker.Mock() mock_okp.offline = True - mock_okp.rhokp_url = "https://docs.openshift.com" + mock_okp.rhokp_url = "http://localhost:8080" mock_config = mocker.Mock() mock_config.okp = mock_okp mocker.patch("utils.responses.configuration", mock_config) + parent = ( + "/documentation/en-us/red_hat_developer_hub/2.1/whats_new-removed_features" + ) mock_result = mocker.Mock() mock_result.attributes = { - "reference_url": "/docs/pipelines/config.html", - "source_path": "pipelines/config.html", - "title": "Pipeline Config", - "doc_id": "doc-001", + "reference_url": ( + "https://docs.redhat.com/en/documentation/red_hat_developer_hub/2.1/" + "whats_new-removed_features#GUID-58b48cbd" + ), + "source_path": ( + "/en/documentation/red_hat_developer_hub/2.1/" + "whats_new-removed_features#GUID-58b48cbd" + ), + "parent_id": parent, + "document_id": parent, + "title": "Removed features - Red Hat Developer Hub 2.1", + "doc_id": f"{parent}_chunk_1", "source": "okp", } @@ -3822,9 +3886,7 @@ def test_okp_offline_builds_url_from_source_path( ) assert len(docs) == 1 - assert ( - str(docs[0].doc_url) == "https://docs.openshift.com/pipelines/config.html" - ) + assert str(docs[0].doc_url) == f"http://localhost:8080{parent}#GUID-58b48cbd" assert docs[0].source == "okp" def test_okp_multistore_detected_via_source_attribute(