Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ac7495d
overriding env with test env
nishika26 Jul 17, 2025
bdb0459
env file example
nishika26 Jul 17, 2025
ec994bc
Merge branch 'main' into enhancement/env_test
nishika26 Jul 22, 2025
4703a57
stricter overriding for test db
nishika26 Jul 22, 2025
e290dd7
ci
nishika26 Jul 22, 2025
bbdf4de
ci clarification
nishika26 Jul 22, 2025
b7f26cd
Merge branch 'main' into enhancement/env_test
nishika26 Jul 24, 2025
0bc016d
updating env variables before importing
nishika26 Jul 24, 2025
08ed5c6
Merge branch 'main' into enhancement/env_test
nishika26 Jul 24, 2025
c0e37f0
adding test db to ci
nishika26 Jul 24, 2025
cc29969
adding test db to ci
nishika26 Jul 24, 2025
be834e7
adding test db to ci
nishika26 Jul 24, 2025
07cfecd
adding test db to ci
nishika26 Jul 24, 2025
1516fb1
adding test db to ci
nishika26 Jul 24, 2025
3a2bf4c
adding test db to ci
nishika26 Jul 24, 2025
bb9ecd9
Merge branch 'main' into enhancement/env_test
AkhileshNegi Jul 31, 2025
0c680fa
coderabbit suggestions
Aug 1, 2025
945bf3d
coderabbit suggestions
Aug 1, 2025
292a548
coderabbit suggestions
Aug 1, 2025
bc4d30e
cleanups
Aug 1, 2025
1157fe2
fixing few testcases
Aug 1, 2025
7528612
few more cleanups
Aug 1, 2025
0fcd10c
creating both env files
Aug 1, 2025
4f2375c
cleanup CI
Aug 1, 2025
f8615e7
using testdb
Aug 1, 2025
3c42875
updating DB
Aug 1, 2025
d663406
using env.test as .env
Aug 1, 2025
0ec01d7
cleaning up env variable
Aug 1, 2025
ae259aa
updating env.example
Aug 1, 2025
de5a19c
increasing pool size
Aug 1, 2025
21497d1
cleanup file
Aug 4, 2025
aa14f7e
cleanup file
Aug 4, 2025
f69f428
cleanup env
Aug 4, 2025
9ecc5cb
cleaning up imports
Aug 4, 2025
5398d21
revert changes for storage.py
Aug 5, 2025
724a229
removing redundant code
Aug 5, 2025
074e753
fixing engine
Aug 5, 2025
72847f8
cleanups for PEP8
Aug 5, 2025
bf6c039
cleanups
Aug 5, 2025
ca60538
removing duplicate setting engine
Aug 5, 2025
1239e2a
removing duplicate setting engine
Aug 5, 2025
874f177
added few comments
Aug 6, 2025
4733796
Merge branch 'main' into enhancement/env_test
AkhileshNegi Aug 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,3 @@ AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=ap-south-1
AWS_S3_BUCKET_PREFIX="bucket-prefix-name"

# OpenAI

OPENAI_API_KEY="this_is_not_a_secret"
LANGFUSE_PUBLIC_KEY="this_is_not_a_secret"
LANGFUSE_SECRET_KEY="this_is_not_a_secret"
LANGFUSE_HOST="this_is_not_a_secret"

# Misc

CI=""
25 changes: 25 additions & 0 deletions .env.test.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ENVIRONMENT=local

PROJECT_NAME="AI Platform"
STACK_NAME=ai-platform

#Backend
SECRET_KEY=changethis
FIRST_SUPERUSER=superuser@example.com
FIRST_SUPERUSER_PASSWORD=changethis
EMAIL_TEST_USER="test@example.com"

# Postgres

POSTGRES_SERVER=localhost
POSTGRES_PORT=5432
POSTGRES_DB=ai_platform_test
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres

# AWS

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=ap-south-1
AWS_S3_BUCKET_PREFIX="bucket-prefix-name"
4 changes: 0 additions & 4 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ jobs:
count: [100]

env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
LANGFUSE_PUBLIC_KEY: ${{ secrets.LANGFUSE_PUBLIC_KEY }}
LANGFUSE_SECRET_KEY: ${{ secrets.LANGFUSE_SECRET_KEY }}
LANGFUSE_HOST: ${{ secrets.LANGFUSE_HOST }}
LOCAL_CREDENTIALS_ORG_OPENAI_API_KEY: ${{ secrets.LOCAL_CREDENTIALS_ORG_OPENAI_API_KEY }}
LOCAL_CREDENTIALS_API_KEY: ${{ secrets.LOCAL_CREDENTIALS_API_KEY }}

Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: ai_platform
POSTGRES_DB: ai_platform_test
ports:
- 5432:5432
options: --health-cmd "pg_isready -U postgres" --health-interval 10s --health-timeout 5s --health-retries 5
Expand All @@ -34,7 +34,9 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Making env file
run: cp .env.example .env
run: |
cp .env.test.example .env
cp .env.test.example .env.test

- name: Install uv
uses: astral-sh/setup-uv@v6
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ node_modules/
/playwright/.cache/

# Environments
.env
.env*
.venv
env/
venv/
Expand Down
4 changes: 0 additions & 4 deletions backend/app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ class Settings(BaseSettings):
env_ignore_empty=True,
extra="ignore",
)
LANGFUSE_PUBLIC_KEY: str
LANGFUSE_SECRET_KEY: str
LANGFUSE_HOST: str # 🇪🇺 EU region
OPENAI_API_KEY: str
API_V1_STR: str = "/api/v1"
SECRET_KEY: str = secrets.token_urlsafe(32)
# 60 minutes * 24 hours * 1 days = 1 days
Expand Down
13 changes: 13 additions & 0 deletions backend/app/core/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@

engine = create_engine(str(settings.SQLALCHEMY_DATABASE_URI))

# Configure connection pool settings
# For testing, we need more connections since tests run in parallel
pool_size = 20 if settings.ENVIRONMENT == "local" else 5
max_overflow = 30 if settings.ENVIRONMENT == "local" else 10

engine = create_engine(
str(settings.SQLALCHEMY_DATABASE_URI),
pool_size=pool_size,
max_overflow=max_overflow,
pool_pre_ping=True,
pool_recycle=300, # Recycle connections after 5 minutes
)


# make sure all SQLModel models are imported (app.models) before initializing DB
# otherwise, SQLModel might fail to initialize relationships properly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
from app.core.cloud import AmazonCloudStorageClient
from app.core.config import settings
from app.models import Document
from app.tests.utils.document import (
Route,
WebCrawler,
httpx_to_standard,
)
from app.tests.utils.document import Route, WebCrawler, httpx_to_standard


class WebUploader(WebCrawler):
Expand Down
6 changes: 1 addition & 5 deletions backend/app/tests/api/routes/test_onboarding.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import pytest
from fastapi.testclient import TestClient
from app.main import app # Assuming your FastAPI app is in app/main.py
from app.models import Organization, Project, User, APIKey
from app.crud import create_organization, create_project, create_user, create_api_key
from app.api.deps import SessionDep
from sqlalchemy import create_engine
from sqlmodel import Session, SQLModel
from sqlmodel import Session
from app.core.config import settings
from app.tests.utils.utils import random_email, random_lower_string
from app.core.security import decrypt_api_key
Expand Down
58 changes: 42 additions & 16 deletions backend/app/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,60 @@
import logging
from collections.abc import Generator

import pytest
from dotenv import find_dotenv
from fastapi.testclient import TestClient
from sqlmodel import Session
from sqlalchemy import event
from collections.abc import Generator
from sqlmodel import Session

from app.core.config import settings
from app.core.db import engine
from app.api.deps import get_db
from app.core.config import settings
from app.main import app
from app.models import APIKeyPublic
from app.tests.utils.user import authentication_token_from_email
from app.tests.utils.utils import get_superuser_token_headers, get_api_key_by_email
from app.seed_data.seed_data import seed_database
from app.tests.utils.user import authentication_token_from_email
from app.tests.utils.utils import (
get_superuser_token_headers,
get_api_key_by_email,
load_environment,
)

logger = logging.getLogger(__name__)


@pytest.fixture(scope="session", autouse=True)
def seed_baseline():
# Load test environment to ensure correct bucket name
path = find_dotenv(".env.test")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will use .env file, if there is no .env.test available.

load_environment(path)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AkhileshNegi I have modified seed_baseline function with

Screenshot 2025-08-06 at 5 24 52 PM

And this is my output

app/tests/api/routes/test_api_key.py Loading environment variables for testing...
postgresql+psycopg://postgres:postgres@localhost:5432/aipostgres
postgresql+psycopg://postgres:postgres@localhost:5432/aipostgres

After loading also settings is having old reference of env variables. db should be aipostgres_test.


# Import engine after environment is loaded
from app.core.db import engine

with Session(engine) as session:
logger.info("Seeding baseline data...")
seed_database(session) # deterministic baseline
yield


@pytest.fixture(scope="function", autouse=True)
def cleanup_sessions():
"""Clean up any lingering sessions after each test."""
yield
# Force cleanup of any remaining connections in the pool
from app.core.db import engine

engine.dispose()


@pytest.fixture(scope="function")
def db() -> Generator[Session, None, None]:
from app.core.db import engine

connection = engine.connect()
transaction = connection.begin()
session = Session(bind=connection)

nested = session.begin_nested()

@event.listens_for(session, "after_transaction_end")
def restart_savepoint(sess, trans):
if trans.nested and not trans._parent.nested:
Expand All @@ -32,14 +65,7 @@ def restart_savepoint(sess, trans):
finally:
session.close()
transaction.rollback()
connection.close()


@pytest.fixture(scope="session", autouse=True)
def seed_baseline():
with Session(engine) as session:
seed_database(session) # deterministic baseline
yield
connection.close() # Explicitly close the connection


@pytest.fixture(scope="function")
Expand Down
5 changes: 2 additions & 3 deletions backend/app/tests/crud/test_thread_result.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
from sqlmodel import SQLModel, Session, create_engine
from sqlmodel import Session

from app.models import OpenAI_Thread, OpenAIThreadCreate
from app.models import OpenAIThreadCreate
from app.crud import upsert_thread_result, get_thread_result


Expand Down
Loading