diff --git a/test/braintrust/trace/span_filter_test.rb b/test/braintrust/trace/span_filter_test.rb index e4e135c..051a10e 100644 --- a/test/braintrust/trace/span_filter_test.rb +++ b/test/braintrust/trace/span_filter_test.rb @@ -11,9 +11,8 @@ def test_init_with_filter_ai_spans_keeps_ai_spans tracer_provider = OpenTelemetry::SDK::Trace::TracerProvider.new Braintrust.init( - api_key: "test-key", + api_key: "test-api-key", set_global: false, - blocking_login: false, enable_tracing: true, tracer_provider: tracer_provider, exporter: exporter, @@ -214,9 +213,8 @@ def setup_with_filter(filter_ai_spans: false, span_filter_funcs: []) tracer_provider = OpenTelemetry::SDK::Trace::TracerProvider.new Braintrust.init( - api_key: "test-key", + api_key: "test-api-key", set_global: false, - blocking_login: false, enable_tracing: true, tracer_provider: tracer_provider, exporter: exporter, diff --git a/test/braintrust/without_openai_test.rb b/test/braintrust/without_openai_test.rb index 3e0c14a..4f87cdf 100644 --- a/test/braintrust/without_openai_test.rb +++ b/test/braintrust/without_openai_test.rb @@ -16,15 +16,15 @@ def test_core_functionality_without_openai skip "Test only runs in without-openai appraisal" if openai_available? # Test that we can initialize Braintrust without tracing (no OpenAI needed) + # Note: "test-api-key" triggers fake auth to avoid HTTP requests state = Braintrust.init( - api_key: "test-key", + api_key: "test-api-key", set_global: false, - blocking_login: false, enable_tracing: false ) assert_instance_of Braintrust::State, state - assert_equal "test-key", state.api_key + assert_equal "test-api-key", state.api_key end def test_openai_require_fails_without_gem diff --git a/test/test_helper.rb b/test/test_helper.rb index 61d66cf..b1a0f8f 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -64,6 +64,29 @@ # Test helpers for OpenTelemetry tracing module TracingTestHelper + # ============================================================================= + # IMPORTANT: Magic Test API Key + # ============================================================================= + # + # When calling Braintrust.init in tests, use api_key: "test-api-key" to trigger + # fake authentication that avoids HTTP requests. This magic key is handled in + # lib/braintrust/api/internal/auth.rb and returns fake org info immediately. + # + # Without this magic key, Braintrust.init spawns a background login thread that + # can cause WebMock errors after tests complete (orphan thread race condition). + # + # Example: + # Braintrust.init(api_key: "test-api-key", set_global: false, enable_tracing: true) + # + # TODO: Future work - move this magic key handling out of production code and into + # test helpers instead. Options include: + # 1. A test-only initializer that provides org_id directly (skips login entirely) + # 2. Dependency injection for the Auth module in tests + # 3. Environment-based test mode detection + # + # See: lib/braintrust/api/internal/auth.rb for the magic key implementation + # ============================================================================= + # Wrapper for OpenTelemetry test setup class OtelTestRig attr_reader :tracer_provider, :exporter, :state