Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions coderd/x/chatd/chatprovider/chatprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package chatprovider_test

import (
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -925,6 +926,88 @@ func TestModelFromConfig_Bedrock(t *testing.T) {
require.Equal(t, chatprovider.UserAgent(), got.UserAgent)
})

t.Run("CapturesSystemFieldShape", func(t *testing.T) {
t.Parallel()
ctx := testutil.Context(t, testutil.WaitShort)

type requestCapture struct {
Body string
BodyReadError error
}

requests := make(chan requestCapture, 1)
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()

body, err := io.ReadAll(r.Body)
requests <- requestCapture{
Body: string(body),
BodyReadError: err,
}
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}

w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(bedrockNonStreamingResponse())
}))
defer server.Close()

model, err := chatprovider.ModelFromConfig(
fantasybedrock.Name,
modelID,
chatprovider.ProviderAPIKeys{
ByProvider: map[string]string{
fantasybedrock.Name: "test-key",
},
BaseURLByProvider: map[string]string{
fantasybedrock.Name: server.URL,
},
},
chatprovider.UserAgent(),
nil,
nil,
)
require.NoError(t, err)
require.NotNil(t, model)

_, err = model.Generate(ctx, fantasy.Call{
Prompt: []fantasy.Message{
{
Role: fantasy.MessageRoleSystem,
Content: []fantasy.MessagePart{
fantasy.TextPart{Text: "you are helpful"},
},
},
{
Role: fantasy.MessageRoleUser,
Content: []fantasy.MessagePart{
fantasy.TextPart{Text: "hello"},
},
},
},
})
require.NoError(t, err)

got := testutil.TryReceive(ctx, t, requests)
require.NoError(t, got.BodyReadError)

var payload map[string]json.RawMessage
require.NoError(t, json.Unmarshal([]byte(got.Body), &payload))

systemField, ok := payload["system"]
require.True(t, ok, "expected top-level system field in request body: %s", got.Body)
t.Logf("Bedrock system field JSON: %s", systemField)

var systemValue any
require.NoError(t, json.Unmarshal(systemField, &systemValue))

systemText, ok := systemValue.(string)
require.True(t, ok, "expected system field to be a JSON string, got %T in request body: %s", systemValue, got.Body)
require.Equal(t, "you are helpful", systemText)
})

t.Run("NonBedrockStillRequiresAPIKey", func(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ replace github.com/spf13/afero => github.com/aslilac/afero v0.0.0-20250403163713
// 4) (anthropic-sdk-go) dannykopping's appendCompact performance fixes
// 5) (anthropic-sdk-go) DirectEncoder to eliminate nested MarshalJSON allocation chain
// 6) Anthropic EffortXHigh constant for Claude Opus 4.7
// See: https://github.com/coder/fantasy/commits/959aa39579d2
replace charm.land/fantasy => github.com/coder/fantasy v0.0.0-20260416152503-959aa39579d2
// See: https://github.com/coder/fantasy/commits/12c408489e35
replace charm.land/fantasy => github.com/coder/fantasy v0.0.0-20260423190606-12c408489e35

// coder/coder uses a fork of charmbracelet's fork of the Anthropic Go SDK with some
// additional performance improvements.
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ github.com/coder/bubbletea v1.2.2-0.20241212190825-007a1cdb2c41 h1:SBN/DA63+ZHwu
github.com/coder/bubbletea v1.2.2-0.20241212190825-007a1cdb2c41/go.mod h1:I9ULxr64UaOSUv7hcb3nX4kowodJCVS7vt7VVJk/kW4=
github.com/coder/clistat v1.2.1 h1:P9/10njXMyj5cWzIU5wkRsSy5LVQH49+tcGMsAgWX0w=
github.com/coder/clistat v1.2.1/go.mod h1:m7SC0uj88eEERgvF8Kn6+w6XF21BeSr+15f7GoLAw0A=
github.com/coder/fantasy v0.0.0-20260416152503-959aa39579d2 h1:bZoww6da3tFbiYHLgIZuRNTMgsiQDSgblDMSOSmmlzE=
github.com/coder/fantasy v0.0.0-20260416152503-959aa39579d2/go.mod h1:wZ0e3lEPqrM0XiIdAUQLvMKCLYhc3gi96MRX2wjbX44=
github.com/coder/fantasy v0.0.0-20260423190606-12c408489e35 h1:ccyKCj5TEvDAIWa2v42PSp0SVvxiegocxDy57UdbPRs=
github.com/coder/fantasy v0.0.0-20260423190606-12c408489e35/go.mod h1:wZ0e3lEPqrM0XiIdAUQLvMKCLYhc3gi96MRX2wjbX44=
github.com/coder/flog v1.1.0 h1:kbAes1ai8fIS5OeV+QAnKBQE22ty1jRF/mcAwHpLBa4=
github.com/coder/flog v1.1.0/go.mod h1:UQlQvrkJBvnRGo69Le8E24Tcl5SJleAAR7gYEHzAmdQ=
github.com/coder/go-httpstat v0.0.0-20230801153223-321c88088322 h1:m0lPZjlQ7vdVpRBPKfYIFlmgevoTkBxB10wv6l2gOaU=
Expand Down
Loading