Skip to content

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

Closed

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

Activity

  1. changed the title [-]integration: yapper backend tries to connect to external service in test mode[/-] [+]fix(integration): yapper backend tries to connect to external service in test mode[/+] on Oct 3, 2026
  2. nycomp commented on Oct 3, 2026

    @nycomp
    ContributorAuthor

    Triage note (bug sweep 2026-10-04): no reproduction found — the STORAGE_MODE=1 local path in campus/yapper/__init__.py exists and all suites are green. The issue describes speculative edge cases (unset env before init). Leaving open pending a concrete repro; if one turns up, the fix is likely a test-fixture ordering guarantee rather than yapper code.

  3. nycomp commented on Oct 28, 2026

    @nycomp
    ContributorAuthor

    Fixed by the phase-2 yapper rework (#981, merged as c6f034b): yapper.create() resolves its DB via the documented priority chain (explicit db_uri → provider → YAPPERDB_URI env → remote vault) and raises in test mode instead of reaching the network when no URI resolves — campus/yapper/init.py:88-89 ("STORAGE_MODE=1 (test mode) must not contact external services"). Guarded by tests/unit/yapper/test_factory.py subprocess tests asserting the resolution order and the no-campus.auth` property. Dev-verified with the campus.api deploy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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