generated from nyjc-computing/replit-flask-app
-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Problem
During integration testing, when running tests in certain configurations, the yapper backend attempts to connect to external services instead of using the local test backend. This causes test failures with NetworkError exceptions.
Root Cause
The yapper initialization logic in campus/yapper/__init__.py has a specific code path for STORAGE_MODE="1" (test mode), but there may be edge cases where:
STORAGE_MODEenvironment variable is not set beforeyapper.init()is called- The
campus.storage.testing.is_test_mode()check returns False when it shouldn't - The fallback logic attempts to use
campus_python.Campusto connect to remote vault
Expected Behavior
When ENV="testing", yapper should:
- Use
SQLiteYapperbackend with a local temp file - Never attempt to connect to external services (campus_python.Campus)
- Retrieve YAPPERDB_URI from local auth_resources.vault
Actual Behavior
In some test configurations, yapper:
- Attempts to create
campus_python.Campusclient - Tries to connect to remote vault service
- Fails with NetworkError/connection timeout
Code Context
campus/yapper/__init__.py around lines 67-75:
# In test mode (STORAGE_MODE=1), use local auth resources directly
# to avoid connecting to external services
if storage_mode == "1":
from campus.auth import resources as auth_resources
yapper_vault = auth_resources.vault["yapper"]
yapperdb_uri = yapper_vault["YAPPERDB_URI"]
yapper = SQLiteYapper(db=yapperdb_uri, client_id=client_id, **kwargs)
yapper._init_db()
return yapperPotential Solutions
- Add explicit test mode check: Check
ENV=="testing"in addition toSTORAGE_MODE - Ensure STORAGE_MODE is always set in test fixtures: Verify
campus.storage.testing.configure_test_storage()is called before any yapper initialization - Add early validation in yapper.init(): Raise a clear error if running in test mode but STORAGE_MODE is not set
- Add logging: Log which backend path is being taken for easier debugging
Test Case
def test_yapper_uses_local_backend_in_test_mode():
"""Verify yapper uses SQLite backend in test mode."""
from campus.common import env
# Ensure test mode is configured
import campus.storage.testing
campus.storage.testing.configure_test_storage()
assert env.get("STORAGE_MODE") == "1"
# This should not attempt any network connections
yapper = create_yapper()
assert isinstance(yapper, SQLiteYapper)Priority
Medium - Tests can be run with proper setup, but the failure mode is confusing and fragile.
Labels
bug, integration-tests, yapper, test-infrastructure
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working