Skip to content

Commit 414f985

Browse files
chore: tests fixes
1 parent fbdd429 commit 414f985

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+995
-195
lines changed

.github/workflows/scripts/release-core.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ fi
3232
# Building core
3333
go mod download
3434
go build ./...
35-
go test ./...
3635
cd ..
3736
echo "✅ Core build validation successful"
3837

38+
# Run core provider tests
39+
echo "🔧 Running core provider tests..."
40+
cd tests/core-providers
41+
go test -v ./...
42+
cd ../..
3943

4044
# Capturing changelog
4145
CHANGELOG_BODY=$(cat core/changelog.md)

core/bifrost.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,11 @@ func (bifrost *Bifrost) handleRequest(ctx context.Context, req *schemas.BifrostR
12291229
primaryResult, primaryErr := bifrost.tryRequest(ctx, req)
12301230

12311231
if primaryErr != nil {
1232-
bifrost.logger.Debug(fmt.Sprintf("Primary provider %s with model %s returned error: %v", provider, model, primaryErr))
1232+
if primaryErr.Error != nil {
1233+
bifrost.logger.Debug(fmt.Sprintf("Primary provider %s with model %s returned error: %s", provider, model, primaryErr.Error.Message))
1234+
} else {
1235+
bifrost.logger.Debug(fmt.Sprintf("Primary provider %s with model %s returned error: %v", provider, model, primaryErr))
1236+
}
12331237
if len(fallbacks) > 0 {
12341238
bifrost.logger.Debug(fmt.Sprintf("Check if we should try %d fallbacks", len(fallbacks)))
12351239
}

core/changelog.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- The pattern we follow here is to keep the changelog for the latest version -->
22
<!-- Old changelogs are automatically attached to the GitHub releases -->
33

4-
- fix: openai specific parameters filtered for openai compatibile providers
5-
- fix: error response unmarshalling for gemini provider
6-
- BREAKING FIX: json_schema field correctly renamed to schema; ResponsesTextConfigFormatJSONSchema restructured
4+
- bug: fixed embedding request not being handled in `GetExtraFields()` method of `BifrostResponse`
5+
- fix: added latency calculation for vertex native requests
6+
- feat: added cached tokens and reasoning tokens to the usage metadata for chat completions

core/schemas/bifrost.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ func (r *BifrostResponse) GetExtraFields() *BifrostResponseExtraFields {
232232
return &r.ResponsesResponse.ExtraFields
233233
case r.ResponsesStreamResponse != nil:
234234
return &r.ResponsesStreamResponse.ExtraFields
235+
case r.EmbeddingResponse != nil:
236+
return &r.EmbeddingResponse.ExtraFields
235237
case r.SpeechResponse != nil:
236238
return &r.SpeechResponse.ExtraFields
237239
case r.SpeechStreamResponse != nil:

core/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.12
1+
1.2.13

docs/architecture/core/concurrency.mdx

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -268,29 +268,31 @@ The backpressure system protects Bifrost from being overwhelmed while maintainin
268268
### **Thread-Safe Object Pools**
269269

270270
```mermaid
271-
graph TB
272-
subgraph "sync.Pool Architecture"
273-
GetObject[Get Object<br/>sync.Pool.Get()]
271+
graph TD
272+
subgraph "sync.Pool Lifecycle"
273+
direction LR
274+
GetObject[Get Object<br/>sync.Pool.Get]
275+
PoolCheck{Is Pool Empty?}
274276
NewObject[New Object<br/>Factory Function]
275277
UseObject[Use Object<br/>Application Logic]
276278
ResetObject[Reset Object<br/>Clear State]
277-
ReturnObject[Return Object<br/>sync.Pool.Put()]
279+
ReturnObject[Return Object<br/>sync.Pool.Put]
280+
281+
GetObject --> PoolCheck
282+
PoolCheck -- Yes --> NewObject
283+
PoolCheck -- No --> UseObject
284+
NewObject --> UseObject
285+
UseObject --> ResetObject
286+
ResetObject --> ReturnObject
278287
end
279288
280-
subgraph "GC Integration"
289+
subgraph "GC Interaction"
290+
direction TB
281291
GCRun[GC Runs]
282-
PoolCleanup[Pool Cleanup<br/>Automatic]
283-
Reallocation[Object Reallocation<br/>as Needed]
292+
PoolCleanup[Pool Cleanup<br>Removes idle objects]
293+
294+
GCRun --> PoolCleanup
284295
end
285-
286-
GetObject --> NewObject
287-
NewObject --> UseObject
288-
UseObject --> ResetObject
289-
ResetObject --> ReturnObject
290-
ReturnObject --> GetObject
291-
292-
GCRun --> PoolCleanup
293-
PoolCleanup --> Reallocation
294296
```
295297

296298
**Thread-Safe Pool Architecture:**

docs/features/plugins/mocker.mdx

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ func main() {
3939
}
4040
defer client.Shutdown()
4141

42-
// All requests will now return: "This is a mock response from the Mocker plugin"
43-
response, _ := client.ChatCompletionRequest(context.Background(), &schemas.BifrostChatRequest{
42+
// All chat and responses requests will now return: "This is a mock response from the Mocker plugin"
43+
44+
// Chat completion request
45+
chatResponse, _ := client.ChatCompletionRequest(context.Background(), &schemas.BifrostChatRequest{
4446
Provider: schemas.OpenAI,
4547
Model: "gpt-4",
4648
Input: []schemas.ChatMessage{
@@ -52,6 +54,20 @@ func main() {
5254
},
5355
},
5456
})
57+
58+
// Responses request
59+
responsesResponse, _ := client.ResponsesRequest(context.Background(), &schemas.BifrostResponsesRequest{
60+
Provider: schemas.OpenAI,
61+
Model: "gpt-4o",
62+
Input: []schemas.ResponsesMessage{
63+
{
64+
Role: bifrost.Ptr(schemas.ResponsesInputMessageRoleUser),
65+
Content: &schemas.ResponsesMessageContent{
66+
ContentStr: bifrost.Ptr("Hello!"),
67+
},
68+
},
69+
},
70+
})
5571
}
5672
```
5773

@@ -86,6 +102,30 @@ plugin, err := mocker.NewMockerPlugin(mocker.MockerConfig{
86102
})
87103
```
88104

105+
### Responses Request Example
106+
107+
The mocker plugin automatically handles both chat completion and responses requests with the same configuration:
108+
109+
```go
110+
// This rule will work for both ChatCompletionRequest and ResponsesRequest
111+
{
112+
Name: "universal-mock",
113+
Enabled: true,
114+
Probability: 1.0,
115+
Conditions: mocker.Conditions{
116+
MessageRegex: stringPtr("(?i).*hello.*"),
117+
},
118+
Responses: []mocker.Response{
119+
{
120+
Type: mocker.ResponseTypeSuccess,
121+
Content: &mocker.SuccessResponse{
122+
Message: "Hello! I'm a mock response that works for both request types.",
123+
},
124+
},
125+
},
126+
}
127+
```
128+
89129
## Installation
90130

91131
Add the plugin to your project:
@@ -137,6 +177,29 @@ config := mocker.MockerConfig{
137177
}
138178
```
139179

180+
## Supported Request Types
181+
182+
The Mocker plugin supports the following Bifrost request types:
183+
184+
- **Chat Completion Requests** (`ChatCompletionRequest`) - Standard chat-based interactions
185+
- **Responses Requests** (`ResponsesRequest`) - OpenAI-compatible responses API format
186+
- **Skip Context Key** - Use `"skip-mocker"` context key to bypass mocking per request
187+
188+
### Skip Mocker for Specific Requests
189+
190+
You can skip the mocker plugin for specific requests by adding a context key:
191+
192+
```go
193+
import "github.com/maximhq/bifrost/core/schemas"
194+
195+
// Create context that skips mocker
196+
ctx := context.WithValue(context.Background(),
197+
schemas.BifrostContextKey("skip-mocker"), true)
198+
199+
// This request will bypass the mocker and go to the real provider
200+
response, err := client.ChatCompletionRequest(ctx, request)
201+
```
202+
140203
## Key Features
141204

142205
### Template Variables
@@ -469,6 +532,27 @@ Response{
469532
}
470533
```
471534

535+
### Skip Mocker Not Working
536+
537+
Ensure you're using the correct context key format:
538+
539+
```go
540+
// ✅ Correct
541+
ctx := context.WithValue(context.Background(),
542+
schemas.BifrostContextKey("skip-mocker"), true)
543+
544+
// ❌ Wrong
545+
ctx := context.WithValue(context.Background(), "skip-mocker", true)
546+
```
547+
548+
### Responses Request Issues
549+
550+
If responses requests aren't being mocked:
551+
552+
1. Verify the plugin supports `ResponsesRequest` (version 1.2.13+)
553+
2. Check that your regex patterns match the message content
554+
3. Ensure the request type is `schemas.ResponsesRequest`
555+
472556
### Debug Mode
473557

474558
Enable debug logging to troubleshoot:

framework/changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- The pattern we follow here is to keep the changelog for the latest version -->
22
<!-- Old changelogs are automatically attached to the GitHub releases -->
33

4-
- chore: version update core to 1.2.12
4+
- chore: version update core to 1.2.13
55
- feat: added support for vertex provider/model format in pricing lookup

framework/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.14
1+
1.1.15

plugins/governance/changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<!-- The pattern we follow here is to keep the changelog for the latest version -->
22
<!-- Old changelogs are automatically attached to the GitHub releases -->
33

4-
- chore: version update core to 1.2.12 and framework to 1.1.14
4+
- chore: version update core to 1.2.13 and framework to 1.1.15

0 commit comments

Comments
 (0)