From 3c149054402cdac890da9e8bd7622ca025b8bb08 Mon Sep 17 00:00:00 2001 From: phact Date: Fri, 19 Dec 2025 03:59:37 -0500 Subject: [PATCH] onboarding before tests --- sdks/python/tests/test_integration.py | 36 +++++++++++++++++++++++ sdks/typescript/tests/integration.test.ts | 32 ++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/sdks/python/tests/test_integration.py b/sdks/python/tests/test_integration.py index 86edb7d3..1b1c2e44 100644 --- a/sdks/python/tests/test_integration.py +++ b/sdks/python/tests/test_integration.py @@ -22,6 +22,42 @@ pytestmark = pytest.mark.skipif( # Module-level cache for API key (created once, reused) _cached_api_key: str | None = None _base_url = os.environ.get("OPENRAG_URL", "http://localhost:3000") +_onboarding_done = False + + +@pytest.fixture(scope="session", autouse=True) +def ensure_onboarding(): + """Ensure the OpenRAG instance is onboarded before running tests. + + This marks the config as 'edited' so that settings updates are allowed. + """ + global _onboarding_done + if _onboarding_done: + return + + onboarding_payload = { + "llm_provider": "openai", + "embedding_provider": "openai", + "embedding_model": "text-embedding-3-small", + "llm_model": "gpt-4o-mini", + "sample_data": False, + } + + try: + response = httpx.post( + f"{_base_url}/api/onboarding", + json=onboarding_payload, + timeout=30.0, + ) + if response.status_code in (200, 204): + print(f"[SDK Tests] Onboarding completed successfully") + else: + # May already be onboarded, which is fine + print(f"[SDK Tests] Onboarding returned {response.status_code}: {response.text[:200]}") + except Exception as e: + print(f"[SDK Tests] Onboarding request failed: {e}") + + _onboarding_done = True def get_api_key() -> str: diff --git a/sdks/typescript/tests/integration.test.ts b/sdks/typescript/tests/integration.test.ts index 745da192..34dee2a7 100644 --- a/sdks/typescript/tests/integration.test.ts +++ b/sdks/typescript/tests/integration.test.ts @@ -18,6 +18,35 @@ let OpenRAGClient: typeof import("../src").OpenRAGClient; const BASE_URL = process.env.OPENRAG_URL || "http://localhost:3000"; const SKIP_TESTS = process.env.SKIP_SDK_INTEGRATION_TESTS === "true"; +// Ensure the OpenRAG instance is onboarded before running tests +async function ensureOnboarding(): Promise { + const onboardingPayload = { + llm_provider: "openai", + embedding_provider: "openai", + embedding_model: "text-embedding-3-small", + llm_model: "gpt-4o-mini", + sample_data: false, + }; + + try { + const response = await fetch(`${BASE_URL}/api/onboarding`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(onboardingPayload), + }); + + if (response.status === 200 || response.status === 204) { + console.log("[SDK Tests] Onboarding completed successfully"); + } else { + // May already be onboarded, which is fine + const text = await response.text(); + console.log(`[SDK Tests] Onboarding returned ${response.status}: ${text.slice(0, 200)}`); + } + } catch (e) { + console.log(`[SDK Tests] Onboarding request failed: ${e}`); + } +} + // Create API key for tests async function createApiKey(): Promise { // Use /api/keys to go through frontend proxy (frontend at :3000 proxies /api/* to backend) @@ -57,6 +86,9 @@ describe.skipIf(SKIP_TESTS)("OpenRAG TypeScript SDK Integration", () => { let testFilePath: string; beforeAll(async () => { + // Ensure onboarding is done first (marks config as edited) + await ensureOnboarding(); + // Import SDK const sdk = await import("../src"); OpenRAGClient = sdk.OpenRAGClient;