From 39d3b30380dfcd4558891dc5f98236339b5485a1 Mon Sep 17 00:00:00 2001 From: Sergey Yedrikov Date: Sat, 4 Oct 2025 00:52:15 -0400 Subject: [PATCH] OLS-1980: Add autodiscovery for indexID value --- ols/app/models/config.py | 17 +++++------------ tests/unit/app/models/test_config.py | 20 +++++++++++++++----- tests/unit/utils/test_config.py | 28 ---------------------------- 3 files changed, 20 insertions(+), 45 deletions(-) diff --git a/ols/app/models/config.py b/ols/app/models/config.py index ffeaad95e..f5ac3f8bb 100644 --- a/ols/app/models/config.py +++ b/ols/app/models/config.py @@ -874,7 +874,6 @@ def validate_yaml(self) -> None: """Validate reference content index config.""" if self.product_docs_index_path is not None: try: - fallback_to_default = False checks.dir_check( self.product_docs_index_path, "Reference content index path" ) @@ -887,22 +886,16 @@ def validate_yaml(self) -> None: try: checks.dir_check(default_path, "Reference content index path") self.product_docs_index_path = FilePath(default_path) - # load all index in the default path + # we don't know the index_id for "latest" so ignore what + # the config says and load whatever index is there self.product_docs_index_id = None - fallback_to_default = True except checks.InvalidConfigurationError: raise e_original - if self.product_docs_index_id is None and not fallback_to_default: + else: + if self.product_docs_index_id is not None: raise checks.InvalidConfigurationError( - "product_docs_index_path is specified but product_docs_index_id is missing" + "product_docs_index_id is specified but product_docs_index_path is missing" ) - if ( - self.product_docs_index_id is not None - and self.product_docs_index_path is None - ): - raise checks.InvalidConfigurationError( - "product_docs_index_id is specified but product_docs_index_path is missing" - ) class ReferenceContent(BaseModel): diff --git a/tests/unit/app/models/test_config.py b/tests/unit/app/models/test_config.py index f6996fb6d..de84dca5c 100644 --- a/tests/unit/app/models/test_config.py +++ b/tests/unit/app/models/test_config.py @@ -1,8 +1,10 @@ """Unit tests for data models.""" import copy +import errno import logging import os +from unittest import mock import pytest from pydantic import ValidationError @@ -2928,14 +2930,19 @@ def test_reference_content_index_yaml_validation(): # should not raise an exception reference_content_index.validate_yaml() - # existing docs index path with set up product ID + # existing docs index path with set up index ID reference_content_index.product_docs_index_path = "." reference_content_index.product_docs_index_id = "foo" reference_content_index.validate_yaml() - # existing docs index path, but no product ID + # existing docs index path, but no index ID reference_content_index.product_docs_index_path = "." reference_content_index.product_docs_index_id = None + reference_content_index.validate_yaml() + + # no docs index path, but with index id + reference_content_index.product_docs_index_path = None + reference_content_index.product_docs_index_id = "foo" with pytest.raises(InvalidConfigurationError): reference_content_index.validate_yaml() @@ -2952,9 +2959,12 @@ def test_reference_content_index_yaml_validation(): # docs index point to a proper directory, that is not # readable by the service - reference_content_index.product_docs_index_path = "/root" - with pytest.raises(InvalidConfigurationError): - reference_content_index.validate_yaml() + with mock.patch( + "os.stat", side_effect=PermissionError(errno.EACCES, "Permission denied") + ): + reference_content_index.product_docs_index_path = "/root" + with pytest.raises(InvalidConfigurationError): + reference_content_index.validate_yaml() def test_reference_content_constructor(): diff --git a/tests/unit/utils/test_config.py b/tests/unit/utils/test_config.py index 88b302640..e6ea99371 100644 --- a/tests/unit/utils/test_config.py +++ b/tests/unit/utils/test_config.py @@ -544,34 +544,6 @@ def test_invalid_config_improper_reference_content(): check_expected_exception( """ --- -llm_providers: - - name: p1 - type: bam - credentials_path: tests/config/secret/apitoken - models: - - name: m1 - credentials_path: tests/config/secret/apitoken -ols_config: - reference_content: - indexes: - - product_docs_index_path: "/tmp" - conversation_cache: - type: memory - memory: - max_entries: 1000 -dev_config: - temperature_override: 0.1 - enable_dev_ui: true - disable_auth: false - -""", - InvalidConfigurationError, - "product_docs_index_path is specified but product_docs_index_id is missing", - ) - - check_expected_exception( - """ ---- llm_providers: - name: p1 type: bam