mirror of
https://github.com/escalante29/WealthySmart.git
synced 2026-07-17 14:28:47 +02:00
Root cause of the "chunks" clear bug: conversation history is server-owned, but MAF seeds a thread from whatever the client sends when no snapshot exists. Any stale tab (open across a clear or from an older session) still holds the old conversation in memory, and its next question re-persisted the whole thing — clears appeared to peel off one layer at a time. The agent middleware now drops client-sent history for threads with no stored snapshot, keeping only the last user turn (fresh conversations and empty-messages hydration requests pass through untouched). Verified live: simulated a cleared-thread stale tab, asked from it, and only the new turn was persisted. Also: clearThread surfaces DELETE failures as a toast instead of silently reloading, and conftest sets a dummy OPENAI_API_KEY so tests can import app.main. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
"""Shared fixtures. Env vars are set before any app import so config.Settings()
|
|
fail-fast validation passes with deterministic test values regardless of the
|
|
developer's .env."""
|
|
|
|
import os
|
|
|
|
os.environ.setdefault(
|
|
"SECRET_KEY", "test-secret-key-0123456789abcdef0123456789abcdef"
|
|
)
|
|
os.environ.setdefault("ADMIN_USERNAME", "testadmin")
|
|
os.environ.setdefault("ADMIN_PASSWORD", "test-password")
|
|
os.environ.setdefault("DATABASE_URL", "sqlite://")
|
|
# app.main builds the MAF agent at import; the OpenAI client only needs a
|
|
# syntactically-present key.
|
|
os.environ.setdefault("OPENAI_API_KEY", "test-dummy-key")
|
|
|
|
import pytest
|
|
from sqlalchemy.pool import StaticPool
|
|
from sqlmodel import Session, SQLModel, create_engine
|
|
|
|
import app.models.models # noqa: F401 — register all tables on the metadata
|
|
|
|
|
|
@pytest.fixture()
|
|
def engine():
|
|
eng = create_engine(
|
|
"sqlite://",
|
|
connect_args={"check_same_thread": False},
|
|
poolclass=StaticPool,
|
|
)
|
|
SQLModel.metadata.create_all(eng)
|
|
yield eng
|
|
eng.dispose()
|
|
|
|
|
|
@pytest.fixture()
|
|
def session(engine):
|
|
with Session(engine) as s:
|
|
yield s
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def fixed_exchange_rates(monkeypatch):
|
|
"""Never hit the network: CRC passthrough, USD pinned at 500."""
|
|
from app.services import exchange_rate
|
|
|
|
monkeypatch.setattr(
|
|
exchange_rate,
|
|
"get_crc_multipliers",
|
|
lambda session: {"CRC": 1.0, "USD": 500.0},
|
|
)
|