diff --git a/tests/integration/test_api_endpoints.py b/tests/integration/test_api_endpoints.py index bd5bbc91..d49cf224 100644 --- a/tests/integration/test_api_endpoints.py +++ b/tests/integration/test_api_endpoints.py @@ -41,8 +41,11 @@ def dump_docker_logs(container_name_pattern: str = "langflow", tail: int = 100): async def perform_onboarding(client: httpx.AsyncClient, embedding_model: str = "text-embedding-3-small", llm_model: str = "gpt-4o-mini"): """Perform onboarding configuration to properly initialize the system. - This should be called after wait_for_service_ready() and before uploading documents. + This should be called once at the beginning of test session, or per-test if config is reset. It configures the embedding model, LLM model, and initializes the OpenSearch index. + + If onboarding has already been performed (config.edited=True), this will use the /settings + endpoint instead to update the configuration. """ onboarding_payload = { "model_provider": "openai", @@ -52,11 +55,26 @@ async def perform_onboarding(client: httpx.AsyncClient, embedding_model: str = " "sample_data": False, } onboarding_resp = await client.post("/onboarding", json=onboarding_payload) - if onboarding_resp.status_code not in (200, 204): + + # If onboarding fails because config is already edited, use /settings endpoint instead + if onboarding_resp.status_code == 403: + print(f"[DEBUG] Config already onboarded, using /settings endpoint instead") + settings_payload = { + "embedding_model": embedding_model, + "llm_model": llm_model, + } + settings_resp = await client.post("/settings", json=settings_payload) + if settings_resp.status_code not in (200, 204): + raise AssertionError( + f"Settings update failed: {settings_resp.status_code} {settings_resp.text}" + ) + print(f"[DEBUG] Settings updated: embedding_model={embedding_model}, llm_model={llm_model}") + elif onboarding_resp.status_code not in (200, 204): raise AssertionError( f"Onboarding failed: {onboarding_resp.status_code} {onboarding_resp.text}" ) - print(f"[DEBUG] Onboarding completed: embedding_model={embedding_model}, llm_model={llm_model}") + else: + print(f"[DEBUG] Onboarding completed: embedding_model={embedding_model}, llm_model={llm_model}") async def wait_for_service_ready(client: httpx.AsyncClient, timeout_s: float = 30.0): @@ -414,7 +432,6 @@ async def test_langflow_chat_and_nudges_endpoints(): try: async with httpx.AsyncClient(transport=transport, base_url="http://testserver") as client: await wait_for_service_ready(client) - await perform_onboarding(client) warmup_file = Path("./nudges_seed.md") warmup_file.write_text( @@ -509,7 +526,6 @@ async def test_search_multi_embedding_models( try: async with httpx.AsyncClient(transport=transport, base_url="http://testserver") as client: await wait_for_service_ready(client) - await perform_onboarding(client) async def _upload_doc(name: str, text: str) -> None: file_path = tmp_path / name