Skip to content

integration: yapper backend tries to connect to external service in test mode #319

@nycomp

Description

@nycomp

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:

  1. STORAGE_MODE environment variable is not set before yapper.init() is called
  2. The campus.storage.testing.is_test_mode() check returns False when it shouldn't
  3. The fallback logic attempts to use campus_python.Campus to connect to remote vault

Expected Behavior

When ENV="testing", yapper should:

  • Use SQLiteYapper backend 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.Campus client
  • 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 yapper

Potential Solutions

  1. Add explicit test mode check: Check ENV=="testing" in addition to STORAGE_MODE
  2. Ensure STORAGE_MODE is always set in test fixtures: Verify campus.storage.testing.configure_test_storage() is called before any yapper initialization
  3. Add early validation in yapper.init(): Raise a clear error if running in test mode but STORAGE_MODE is not set
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions