Skip to content

Conversation

@akshaydeo
Copy link
Contributor

@akshaydeo akshaydeo commented Jan 5, 2026

Summary

Add virtual key (VK) testing support to integration tests, enabling tests to run with and without the x-bf-vk header to validate governance functionality.

Changes

  • Enabled config store and governance in integration test configuration
  • Added virtual key configuration in config.yml for cross-provider testing
  • Modified test parameterization to include vk_enabled flag for all cross-provider tests
  • Updated OpenAI client creation to conditionally include the x-bf-vk header
  • Fixed virtual key context handling in HTTP transport

Type of change

  • Feature
  • Bug fix

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations

How to test

Run the integration tests with the updated configuration:

cd tests/integrations
python -m pytest tests/test_openai.py -v

The tests will now run twice for each provider/model combination when virtual key testing is enabled - once with the standard API key and once with the virtual key header.

Breaking changes

  • No

Security considerations

This PR improves testing of the governance and virtual key functionality, which is a security-related feature. The virtual key implementation in the HTTP transport was fixed to use the correct context key.

Checklist

  • I added/updated tests where appropriate
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 5, 2026

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Virtual key support added, enabling configuration and use of virtual keys for cross-provider authentication
    • Virtual key configuration now available with enable/disable and value settings
  • Tests

    • Cross-provider tests expanded to include virtual key enabled and disabled scenarios
    • Enhanced test coverage validates behavior with and without virtual key headers
  • Chores

    • Updated plugin creation default configuration

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

The changes introduce virtual key (VK) support across the testing infrastructure and HTTP transport layer. Configuration files enable governance with VK entries, test utilities add VK parametrization for cross-provider scenarios, test methods are refactored to conditionally inject x-bf-vk headers, and HTTP context storage normalizes virtual key value handling.

Changes

Cohort / File(s) Summary
Virtual Key Configuration Setup
tests/integrations/config.json, tests/integrations/config.yml
Config store enabled with SQLite backend; governance section added with virtual_keys array (id: vk-test, value: sk-bf-test-key); client governance enforcement enabled; virtual_key blocks added to YAML with enabled flag and test key value.
Virtual Key Testing Utilities
tests/integrations/tests/utils/config_loader.py, tests/integrations/tests/utils/parametrize.py
New instance methods added to ConfigLoader: get_virtual_key() and is_virtual_key_configured(). New public functions in parametrize: get_cross_provider_params_with_vk_for_scenario() returns (provider, model, vk_enabled) tuples; format_vk_test_id() formats test IDs with VK state suffix.
Virtual Key Test Implementation
tests/integrations/tests/test_openai.py
Test parametrization source changed from get_cross_provider_params_for_scenario to get_cross_provider_params_with_vk_for_scenario; new factory function get_provider_openai_client(provider, vk_enabled=False) injects x-bf-vk header conditionally; all test methods refactored to accept vk_enabled parameter and use provider-specific client instead of shared fixture; vk_enabled threaded through test logic and API calls.
Virtual Key HTTP Handler Integration
transports/bifrost-http/lib/ctx.go
Virtual key header value now stored under fixed public key schemas.BifrostContextKeyVirtualKey instead of using header name as context key; consolidates storage for x-bf-vk, x-api-key, and x-goog-api-key paths.
Plugin Handler Default
transports/bifrost-http/handlers/plugins.go
Default IsCustom field for auto-created plugins changed from true to false in updatePlugin logic.
Formatting
transports/bifrost-http/server/server.go
Empty line removed inside RemovePlugin CAS loop; no behavioral changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A virtual key now hops through the tests,
With headers that dance and config that rests,
Provider clients spring forth with conditional cheer,
Parametrized pathways make testing more clear! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 68.52% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'adds vk based integration tests' directly relates to the main change—adding virtual key testing support to integration tests.
Description check ✅ Passed The pull request description covers all required template sections including summary, changes, type of change, affected areas, how to test, breaking changes, security considerations, and a completed checklist.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 01-06-adds_vk_based_integration_tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2026

🧪 Test Suite Available

This PR can be tested by a repository admin.

Run tests for PR #1252

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@akshaydeo akshaydeo marked this pull request as ready for review January 5, 2026 20:47
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/integrations/tests/utils/parametrize.py (1)

8-8: Remove unused import.

The Union import is not used in this file. The code uses the modern | union operator (Python 3.10+) instead of Union[...] syntax.

🔎 Proposed fix
-from typing import List, Tuple, Union
+from typing import List, Tuple
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3f0e4ca and 7124300.

📒 Files selected for processing (8)
  • tests/integrations/config.json
  • tests/integrations/config.yml
  • tests/integrations/tests/test_openai.py
  • tests/integrations/tests/utils/config_loader.py
  • tests/integrations/tests/utils/parametrize.py
  • transports/bifrost-http/handlers/plugins.go
  • transports/bifrost-http/lib/ctx.go
  • transports/bifrost-http/server/server.go
💤 Files with no reviewable changes (1)
  • transports/bifrost-http/server/server.go
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

always check the stack if there is one for the current PR. do not give localized reviews for the PR, always see all changes in the light of the whole stack of PRs (if there is a stack, if there is no stack you can continue to make localized suggestions/reviews)

Files:

  • tests/integrations/config.yml
  • tests/integrations/config.json
  • transports/bifrost-http/lib/ctx.go
  • tests/integrations/tests/utils/config_loader.py
  • transports/bifrost-http/handlers/plugins.go
  • tests/integrations/tests/utils/parametrize.py
  • tests/integrations/tests/test_openai.py
🧠 Learnings (5)
📚 Learning: 2025-12-09T17:07:42.007Z
Learnt from: qwerty-dvorak
Repo: maximhq/bifrost PR: 1006
File: core/schemas/account.go:9-18
Timestamp: 2025-12-09T17:07:42.007Z
Learning: In core/schemas/account.go, the HuggingFaceKeyConfig field within the Key struct is currently unused and reserved for future Hugging Face inference endpoint deployments. Do not flag this field as missing from OpenAPI documentation or require its presence in the API spec until the feature is actively implemented and used. When the feature is added, update the OpenAPI docs accordingly; otherwise, treat this field as non-breaking and not part of the current API surface.

Applied to files:

  • transports/bifrost-http/lib/ctx.go
  • transports/bifrost-http/handlers/plugins.go
📚 Learning: 2025-12-29T11:54:55.836Z
Learnt from: akshaydeo
Repo: maximhq/bifrost PR: 1153
File: framework/configstore/rdb.go:2221-2246
Timestamp: 2025-12-29T11:54:55.836Z
Learning: In Go reviews, do not flag range-over-int patterns like for i := range n as compile-time errors, assuming Go 1.22+ semantics. Only flag actual range-capable values (slices, arrays, maps, channels, strings) and other compile-time issues. This applies to all Go files across the repository.

Applied to files:

  • transports/bifrost-http/lib/ctx.go
  • transports/bifrost-http/handlers/plugins.go
📚 Learning: 2025-12-12T08:25:02.629Z
Learnt from: Pratham-Mishra04
Repo: maximhq/bifrost PR: 1000
File: transports/bifrost-http/integrations/router.go:709-712
Timestamp: 2025-12-12T08:25:02.629Z
Learning: In transports/bifrost-http/**/*.go, update streaming response handling to align with OpenAI Responses API: use typed SSE events such as response.created, response.output_text.delta, response.done, etc., and do not rely on the legacy data: [DONE] termination marker. Note that data: [DONE] is only used by the older Chat Completions and Text Completions streaming APIs. Ensure parsers, writers, and tests distinguish SSE events from the [DONE] sentinel and handle each event type accordingly for correct stream termination and progress updates.

Applied to files:

  • transports/bifrost-http/lib/ctx.go
  • transports/bifrost-http/handlers/plugins.go
📚 Learning: 2025-12-29T09:14:16.633Z
Learnt from: akshaydeo
Repo: maximhq/bifrost PR: 888
File: transports/bifrost-http/handlers/middlewares.go:246-256
Timestamp: 2025-12-29T09:14:16.633Z
Learning: In the bifrost HTTP transport, fasthttp.RequestCtx is the primary context carrier and should be passed directly to functions that expect a context.Context. Do not convert to context.Context unless explicitly required. Ensure tracer implementations and related components are designed to accept fasthttp.RequestCtx directly, and document this architectural decision for maintainers.

Applied to files:

  • transports/bifrost-http/lib/ctx.go
  • transports/bifrost-http/handlers/plugins.go
📚 Learning: 2025-12-24T07:38:16.990Z
Learnt from: qwerty-dvorak
Repo: maximhq/bifrost PR: 1095
File: tests/integrations/tests/test_google.py:2030-2030
Timestamp: 2025-12-24T07:38:16.990Z
Learning: In Python tests under tests/integrations/tests, allow a fixture parameter named test_config in test functions even if unused; do not flag it as unused. This is an internal convention to ensure consistency for integration tests.

Applied to files:

  • tests/integrations/tests/test_openai.py
🧬 Code graph analysis (3)
transports/bifrost-http/lib/ctx.go (1)
core/schemas/bifrost.go (1)
  • BifrostContextKeyVirtualKey (123-123)
tests/integrations/tests/utils/parametrize.py (1)
tests/integrations/tests/utils/config_loader.py (3)
  • get_config (455-460)
  • is_virtual_key_configured (441-448)
  • is_virtual_key_configured (512-514)
tests/integrations/tests/test_openai.py (3)
tests/integrations/tests/utils/parametrize.py (2)
  • get_cross_provider_params_with_vk_for_scenario (50-101)
  • format_provider_model (126-141)
tests/integrations/tests/utils/config_loader.py (6)
  • get_config (455-460)
  • get_integration_url (112-131)
  • get_integration_url (463-464)
  • get_api_config (197-199)
  • get_virtual_key (426-439)
  • get_virtual_key (507-509)
core/schemas/bifrost.go (1)
  • OpenAI (35-35)
🪛 Ruff (0.14.10)
tests/integrations/tests/test_openai.py

268-268: Unused method argument: test_config

(ARG002)


286-286: Unused method argument: test_config

(ARG002)


303-303: Unused method argument: test_config

(ARG002)


323-323: Unused method argument: test_config

(ARG002)


347-347: Unused method argument: test_config

(ARG002)


392-392: Unused method argument: test_config

(ARG002)


411-411: Unused method argument: test_config

(ARG002)


427-427: Unused method argument: test_config

(ARG002)


443-443: Unused method argument: test_config

(ARG002)


574-574: Unused method argument: test_config

(ARG002)


875-875: Unused method argument: test_config

(ARG002)


893-893: Unused method argument: test_config

(ARG002)


911-911: Unused method argument: test_config

(ARG002)


942-942: Unused method argument: test_config

(ARG002)


1008-1008: Unused method argument: test_config

(ARG002)


1168-1168: Unused method argument: test_config

(ARG002)


1212-1212: Unused method argument: test_config

(ARG002)


1248-1248: Unused method argument: test_config

(ARG002)


1283-1283: Unused method argument: test_config

(ARG002)


1330-1330: Unused method argument: test_config

(ARG002)


1379-1379: Unused method argument: test_config

(ARG002)


1432-1432: Unused method argument: test_config

(ARG002)


1489-1489: Unused method argument: test_config

(ARG002)


1529-1529: Unused method argument: test_config

(ARG002)


1751-1751: Unused method argument: test_config

(ARG002)


1826-1826: Unused method argument: test_config

(ARG002)


1897-1897: Unused method argument: test_config

(ARG002)


1956-1956: Unused method argument: test_config

(ARG002)


2002-2002: Unused method argument: test_config

(ARG002)


2083-2083: Unused method argument: test_config

(ARG002)


2214-2214: Unused method argument: test_config

(ARG002)


2237-2237: Unused method argument: test_config

(ARG002)


2363-2363: Unused method argument: test_config

(ARG002)


2484-2484: Unused method argument: test_config

(ARG002)

🔇 Additional comments (12)
transports/bifrost-http/lib/ctx.go (1)

209-212: Good fix: Standardizes virtual key context storage.

This change ensures the virtual key is stored under schemas.BifrostContextKeyVirtualKey constant instead of using the header name string as the context key. This aligns with how VKs from other headers (authorization, x-api-key, x-goog-api-key) are already stored at lines 219, 225, and 229, enabling consistent retrieval by governance and other components.

tests/integrations/config.json (2)

154-175: LGTM: VK testing infrastructure enabled correctly.

The configuration changes enable config_store, add governance with a test virtual key, and configure the client to enforce governance. The virtual key value "sk-bf-test-key" aligns with config.yml, enabling consistent VK-based integration testing.


183-184: LGTM: Governance enabled for VK testing.

Correctly enables governance and enforces the governance header requirement, allowing integration tests to validate VK functionality.

tests/integrations/config.yml (1)

698-702: LGTM: Virtual key configuration added.

The virtual key configuration enables VK-based testing with the value matching config.json. This allows integration tests to run scenarios both with and without the VK header.

tests/integrations/tests/utils/config_loader.py (2)

426-448: LGTM: Virtual key accessors implemented correctly.

The get_virtual_key() and is_virtual_key_configured() methods safely handle missing configuration and disabled states. The implementation correctly checks the enabled flag and returns empty string as a fallback, making it easy for tests to conditionally enable VK scenarios.


507-514: LGTM: Convenience functions added.

The module-level convenience functions properly delegate to the ConfigLoader instance, maintaining consistency with the existing pattern in the file.

transports/bifrost-http/handlers/plugins.go (1)

316-316: The IsCustom field difference between line 245 (true) and line 316 (false) is intentional and correctly reflects the semantic difference. The configstore layer automatically recalculates IsCustom based on the plugin's Path field: plugins without a custom path are marked as non-custom (false), while plugins with a path are marked as custom (true). The handler's explicit values are overridden by this automatic calculation, making the explicit assignments at both lines semantically correct for their respective contexts.

Likely an incorrect or invalid review comment.

tests/integrations/tests/utils/parametrize.py (2)

50-101: LGTM!

The VK parametrization logic correctly doubles test coverage when virtual keys are configured, ensuring both standard and VK-enabled scenarios are tested. The dummy tuple handling prevents pytest errors when no providers are available.


104-123: LGTM!

Clear and well-documented test ID formatting utility. The examples in the docstring are helpful.

tests/integrations/tests/test_openai.py (3)

198-224: LGTM!

The VK-enabled client factory correctly conditionally injects the x-bf-vk header only when both vk_enabled=True and a valid virtual key is configured. The logic properly handles the case where VK is empty or unconfigured.


265-282: LGTM!

The test correctly adopts the VK testing pattern: parametrizing with vk_enabled, creating a provider-specific client with the VK flag, and using it for API calls. This ensures governance and virtual key functionality are validated.


283-301: LGTM!

The VK testing pattern is applied consistently across all cross-provider parameterized tests. Each test correctly:

  1. Uses get_cross_provider_params_with_vk_for_scenario for parametrization
  2. Accepts the vk_enabled parameter
  3. Creates a provider-specific client with get_provider_openai_client(provider, vk_enabled=vk_enabled)

This ensures comprehensive testing of both standard API key and virtual key authentication paths.

Also applies to: 302-319, 573-617, 874-891, 1168-1206, 2683-2701

Copy link
Contributor Author

akshaydeo commented Jan 5, 2026

Merge activity

  • Jan 5, 9:06 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jan 5, 9:07 PM UTC: @akshaydeo merged this pull request with Graphite.

@akshaydeo akshaydeo merged commit 9863ecf into main Jan 5, 2026
11 checks passed
@akshaydeo akshaydeo deleted the 01-06-adds_vk_based_integration_tests branch January 5, 2026 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants