onboarding before tests
This commit is contained in:
parent
304e0c15d2
commit
3c14905440
2 changed files with 68 additions and 0 deletions
|
|
@ -22,6 +22,42 @@ pytestmark = pytest.mark.skipif(
|
||||||
# Module-level cache for API key (created once, reused)
|
# Module-level cache for API key (created once, reused)
|
||||||
_cached_api_key: str | None = None
|
_cached_api_key: str | None = None
|
||||||
_base_url = os.environ.get("OPENRAG_URL", "http://localhost:3000")
|
_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:
|
def get_api_key() -> str:
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,35 @@ let OpenRAGClient: typeof import("../src").OpenRAGClient;
|
||||||
const BASE_URL = process.env.OPENRAG_URL || "http://localhost:3000";
|
const BASE_URL = process.env.OPENRAG_URL || "http://localhost:3000";
|
||||||
const SKIP_TESTS = process.env.SKIP_SDK_INTEGRATION_TESTS === "true";
|
const SKIP_TESTS = process.env.SKIP_SDK_INTEGRATION_TESTS === "true";
|
||||||
|
|
||||||
|
// Ensure the OpenRAG instance is onboarded before running tests
|
||||||
|
async function ensureOnboarding(): Promise<void> {
|
||||||
|
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
|
// Create API key for tests
|
||||||
async function createApiKey(): Promise<string> {
|
async function createApiKey(): Promise<string> {
|
||||||
// Use /api/keys to go through frontend proxy (frontend at :3000 proxies /api/* to backend)
|
// 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;
|
let testFilePath: string;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
// Ensure onboarding is done first (marks config as edited)
|
||||||
|
await ensureOnboarding();
|
||||||
|
|
||||||
// Import SDK
|
// Import SDK
|
||||||
const sdk = await import("../src");
|
const sdk = await import("../src");
|
||||||
OpenRAGClient = sdk.OpenRAGClient;
|
OpenRAGClient = sdk.OpenRAGClient;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue