gateway: a request to an unmasked route isn't masked first (#3973)
wangbinyq (#3973): with masking on, a request to a provider set to go unmasked was still masked whole before routing, then sent as the agent wrote it, so the masking was thrown away. In their log that was 97.9% of magpie's own time: median 560ms, p99 16s, max 219s. serve now masks after Resolve/FindGroup. When unredactedRoute holds and no body goes anywhere else (bodiesKeptAway: no observer wanting bodies, no request archive), masking is skipped. The redact writer goes under capture, an order that commutes with the old one. A turned-away request is logged masked (maskedCopy). count_tokens masks only when its route isn't unmasked. The context card's text stays masked: the kept body is masked when PromptText first reads it (keptBody.plain), not on the request's way. The log and recent calls keep the body as it went. Run on mote at this tree (base58fb3a778, rebased ontod74ef5e04with no internal/gateway change in between): - gofmt -l internal/gateway: none. GOOS=linux/windows/darwin go vet -tags nogui ./internal/gateway: ok. - go test -tags nogui -count=1 -timeout 45m ./internal/gateway: one red, TestPluginStreamsPastTheBudgetWait (connection reset by peer, load ~80). That is #3946, already open. Alone with TestPromptTextIsWhatWasSent, -count=5: ok. - The first full run caught TestPromptTextIsWhatWasSent red: the card's text held the key on an unmasked route. Fixed by the lazy masking above; it is green now. - Broken by hand: on origin/main's gateway.go and redact.go, the new TestUnmaskedRouteIsNotMasked is red ("masked 1 times, want masking false", "count masked 1 times"). - Real run: old and new magpie serve in a sandbox HOME, redact on, a local Anthropic provider on a fake upstream, 15 requests of 1.2MB with emails, phone numbers and keys. Unmasked provider: median 176ms on old, 13ms on new. Masked provider: 171ms vs 172ms. Not tried: a real vendor account. The change sits before the upstream call, and the fake upstream stands in for it.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -978,7 +978,7 @@ func (s *Server) codexUpstreamOn(w http.ResponseWriter, r *http.Request, rest st
|
||||
if m := noteMasked(r, "chat", maskedHits, string(body), tr.ID, "openai", model); m != nil {
|
||||
s.trace.update(tr, func(t *Route) { t.Masked = m })
|
||||
}
|
||||
promptRead := s.inspectPrompt(tr, provider.Responses, body, body)
|
||||
promptRead := s.inspectPrompt(tr, provider.Responses, body, body, false)
|
||||
end = func(status int, msg string, tokens, out int) {
|
||||
ms := time.Since(start).Milliseconds()
|
||||
ttft, text := first.ms()
|
||||
|
||||
+58
-31
@@ -1363,14 +1363,6 @@ func (s *Server) countTokens(w http.ResponseWriter, r *http.Request) {
|
||||
writeError(w, provider.Anthropic, 400, err.Error())
|
||||
return
|
||||
}
|
||||
// Count the same masked prompt that generation sends to the vendor.
|
||||
plain := body
|
||||
w, body, unmask, err := redacted(r.Context(), w, body)
|
||||
defer unmask()
|
||||
if err != nil {
|
||||
writeError(w, provider.Anthropic, maskStatus(err), err.Error())
|
||||
return
|
||||
}
|
||||
named := unprefixed(model)
|
||||
if m := claudeTierStandIn(r, agentOf(r), model); m != "" {
|
||||
model = m // counted on the model the request will go to
|
||||
@@ -1394,9 +1386,17 @@ func (s *Server) countTokens(w http.ResponseWriter, r *http.Request) {
|
||||
if countOff(w, provider.Anthropic, id) {
|
||||
return
|
||||
}
|
||||
// and counts the unmasked one where generation sends that
|
||||
if _, ms, isGroup := provider.FindGroup(id); ok && unredactedRoute(p, isGroup, ms) {
|
||||
body = plain
|
||||
// Count the same masked prompt that generation sends to the vendor,
|
||||
// and the one as written where generation sends that, masked only
|
||||
// then (#3973)
|
||||
if _, ms, isGroup := provider.FindGroup(id); !ok || !unredactedRoute(p, isGroup, ms) {
|
||||
var unmask func()
|
||||
w, body, unmask, err = redacted(r.Context(), w, body)
|
||||
defer unmask()
|
||||
if err != nil {
|
||||
writeError(w, provider.Anthropic, maskStatus(err), err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
if level := desktopSubagentEffort(r, agentOf(r), body, pick); level != "" && ok && !provider.Reasonless(p.ID, model) {
|
||||
body = withFixedEffort(provider.Anthropic, body, fitLevel(level, p.Efforts(model)))
|
||||
@@ -1702,27 +1702,22 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro
|
||||
// what the vendor saw and said. plain is the body as the agent wrote
|
||||
// it, for a request that goes only where the user said it may go
|
||||
// unmasked (unredactedRoute)
|
||||
// unmasked (unredactedRoute). The body is masked once the route is
|
||||
// known (below): one that goes as written isn't masked at all, where
|
||||
// masking it took up to minutes for nothing (#3973)
|
||||
plain := body
|
||||
var masked []byte // the masked body, when plain goes instead
|
||||
w, body, unmask, maskedHits, err := redactedHits(r.Context(), w, body)
|
||||
defer unmask()
|
||||
if err != nil { // fails closed: never sent unmasked
|
||||
log.Printf("gateway: %v", err)
|
||||
writeError(w, from, maskStatus(err), err.Error())
|
||||
return
|
||||
}
|
||||
var maskedHits maskHits
|
||||
maskDone, sentWhole := false, false
|
||||
unmask := func() {}
|
||||
defer func() { unmask() }()
|
||||
// the reply's model the member that answered, when asked for (#822)
|
||||
w, r, named := withMemberNames(w, r)
|
||||
defer named()
|
||||
requestBody, requestTruncated := captureRequestBody(body)
|
||||
// an observer may want the bodies uncut (the OTLP export, #538): the
|
||||
// request is already whole in memory, so keep it as it came, and the
|
||||
// reply goes to a spool as it streams
|
||||
wholeBodies := usage.ObservedBodies() == usage.WholeBodies
|
||||
var wholeIn []byte
|
||||
if wholeBodies {
|
||||
wholeIn = body
|
||||
}
|
||||
// a model asked for at an effort of its own (a Claude Code tier, #536)
|
||||
// is the model, every try of it asked for that effort
|
||||
askedFor := modelOf(body) // as it reaches serve, which an error in its stream names (keptAlive)
|
||||
@@ -1750,7 +1745,18 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro
|
||||
metadata := requestSessionMetadata(r.Header, body)
|
||||
var clientResponseID string // only a reply released to the client owns this ID
|
||||
call := Call{Time: start, From: from, Model: unprefixed(modelOf(body)), Agent: who.agent, Via: who.via, Kind: requestCallKind(r.Header, metadata),
|
||||
RequestBody: requestBody, RequestTruncated: requestTruncated, wholeIn: wholeIn, wire: archiving(r, capture, start, body)}
|
||||
wire: archiving(r, capture, start, nil)}
|
||||
// the log has the body as it went: masked, or as written where it
|
||||
// went so
|
||||
logBody := func(b []byte) {
|
||||
call.RequestBody, call.RequestTruncated = captureRequestBody(b)
|
||||
if wholeBodies {
|
||||
call.wholeIn = b
|
||||
}
|
||||
if call.wire != nil {
|
||||
call.wire.body = b
|
||||
}
|
||||
}
|
||||
defer discardArchive(capture)
|
||||
r, watched := observeRequest(r, call.Kind, body)
|
||||
defer func() { watched.end(call, time.Since(start).Milliseconds()) }()
|
||||
@@ -1786,6 +1792,10 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro
|
||||
// a request turned away before any provider was asked is in the log
|
||||
// as the failure it was, with the reason
|
||||
turnedAway := func() {
|
||||
if !maskDone {
|
||||
// sent nowhere: the log has it masked, or not at all
|
||||
logBody(maskedCopy(r.Context(), body))
|
||||
}
|
||||
finishCapture()
|
||||
call.Millis = time.Since(start).Milliseconds()
|
||||
s.record(call)
|
||||
@@ -1921,10 +1931,27 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro
|
||||
g, ms, isGroup := provider.FindGroup(asked)
|
||||
g = g.Live() // a manual group's rules wait
|
||||
// a model on this machine or the local network that the user set to
|
||||
// go unmasked gets the request as written (lc on Discord); the log
|
||||
// keeps the masked one
|
||||
if unredactedRoute(p, isGroup, ms) {
|
||||
masked, body = body, plain
|
||||
// go unmasked gets the request as written (lc on Discord), and it is
|
||||
// masked only for an observer or the archive, which may keep it
|
||||
// elsewhere
|
||||
if sentWhole = unredactedRoute(p, isGroup, ms) && !bodiesKeptAway(); !sentWhole {
|
||||
rw, b, done, hits, err := redactedHits(r.Context(), capture.ResponseWriter, body)
|
||||
if err != nil { // fails closed: never sent unmasked
|
||||
log.Printf("gateway: %v", err)
|
||||
call.Status, call.Error = maskStatus(err), err.Error()
|
||||
writeError(w, from, call.Status, err.Error())
|
||||
return
|
||||
}
|
||||
capture.ResponseWriter, body, unmask, maskedHits = rw, b, done, hits
|
||||
if unredactedRoute(p, isGroup, ms) {
|
||||
masked, body = body, plain
|
||||
}
|
||||
}
|
||||
maskDone = true
|
||||
if masked != nil {
|
||||
logBody(masked)
|
||||
} else {
|
||||
logBody(body)
|
||||
}
|
||||
// a gateway key held to some models (#882) is refused another, or a
|
||||
// group it doesn't name with one it may not use in it
|
||||
@@ -2426,7 +2453,7 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro
|
||||
// request went as written. The record names the provider and model
|
||||
// the last try went to, not the group's first member, which a
|
||||
// failover may never have reached
|
||||
if masked == nil {
|
||||
if masked == nil && !sentWhole {
|
||||
m, done := noteMaskedUntil(r, "chat", maskedHits, string(body), tr.ID, p.ID, call.Model)
|
||||
if m != nil {
|
||||
s.trace.update(tr, func(t *Route) { t.Masked = m })
|
||||
@@ -2434,12 +2461,12 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro
|
||||
defer func() { done(call.Provider, model) }()
|
||||
}
|
||||
// the card's text is the masked body, even where the request went
|
||||
// unmasked
|
||||
// unmasked: masked by PromptText when it went whole (#3973)
|
||||
textBody := body
|
||||
if masked != nil {
|
||||
textBody = masked
|
||||
}
|
||||
promptRead := s.inspectPrompt(tr, from, body, textBody)
|
||||
promptRead := s.inspectPrompt(tr, from, body, textBody, sentWhole)
|
||||
var lastTried provider.Provider // the last try's, for its model's context window and the usage's endpoint
|
||||
var skipped []string
|
||||
sent := "" // the reasoning the last try's model was asked for
|
||||
|
||||
@@ -1226,13 +1226,14 @@ func windowFor(id, model string) int {
|
||||
// inspectPrompt reads the request's prompt beside it, putting the estimate
|
||||
// in the trace as soon as it is read; wait returns it, for the route's
|
||||
// end to scale to what was counted. masked is the body as the vendor would
|
||||
// get it with masking on, kept a while for the card's text (PromptText).
|
||||
func (s *Server) inspectPrompt(tr *Route, from provider.Protocol, body, masked []byte) (wait func() *Prompt) {
|
||||
// get it with masking on, kept a while for the card's text (PromptText);
|
||||
// plain when it went unmasked, so is masked only when the card asks.
|
||||
func (s *Server) inspectPrompt(tr *Route, from provider.Protocol, body, masked []byte, plain bool) (wait func() *Prompt) {
|
||||
ch := make(chan *Prompt, 1)
|
||||
go func() {
|
||||
p := promptOf(from, body)
|
||||
if p != nil {
|
||||
s.trace.keepBody(tr.ID, from, masked)
|
||||
s.trace.keepBody(tr.ID, from, masked, plain)
|
||||
s.trace.update(tr, func(t *Route) {
|
||||
if t.Prompt == nil {
|
||||
t.Prompt = p
|
||||
|
||||
@@ -13,6 +13,7 @@ package gateway
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"slices"
|
||||
"strconv"
|
||||
@@ -37,17 +38,19 @@ type keptBody struct {
|
||||
id int64
|
||||
from provider.Protocol
|
||||
body []byte
|
||||
// plain: body went unmasked, and is masked when its text is read
|
||||
plain bool
|
||||
}
|
||||
|
||||
// keepBody keeps a request's masked body for its prompt's text, dropping
|
||||
// the oldest past promptBodies or promptBodiesMax.
|
||||
func (t *trace) keepBody(id int64, from provider.Protocol, body []byte) {
|
||||
func (t *trace) keepBody(id int64, from provider.Protocol, body []byte, plain bool) {
|
||||
if len(body) == 0 || len(body) > promptBodyMax {
|
||||
return
|
||||
}
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
t.bodies = append(t.bodies, keptBody{id: id, from: from, body: body})
|
||||
t.bodies = append(t.bodies, keptBody{id: id, from: from, body: body, plain: plain})
|
||||
total := 0
|
||||
for _, b := range t.bodies {
|
||||
total += len(b.body)
|
||||
@@ -59,6 +62,17 @@ func (t *trace) keepBody(id int64, from provider.Protocol, body []byte) {
|
||||
}
|
||||
}
|
||||
|
||||
// maskedBody puts body, masked, in place of route id's plain kept body.
|
||||
func (t *trace) maskedBody(id int64, body []byte) {
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
for i := range t.bodies {
|
||||
if t.bodies[i].id == id && t.bodies[i].plain {
|
||||
t.bodies[i].body, t.bodies[i].plain = body, false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// keptBodyOf is a route's kept body; false when it isn't kept.
|
||||
func (t *trace) keptBodyOf(id int64) (keptBody, bool) {
|
||||
t.mu.Lock()
|
||||
@@ -104,6 +118,14 @@ func (s *Server) PromptText(id int64, kind string, withText bool) (PromptText, b
|
||||
if !ok || !slices.Contains(partOrder, kind) {
|
||||
return PromptText{}, false
|
||||
}
|
||||
if kb.plain {
|
||||
// masked here, not on the request's way (#3973); kept masked for
|
||||
// the next read
|
||||
if kb.body = maskedCopy(context.Background(), kb.body); kb.body == nil {
|
||||
return PromptText{}, false
|
||||
}
|
||||
s.trace.maskedBody(id, kb.body)
|
||||
}
|
||||
b, ok := promptPieces(kb.from, kb.body)
|
||||
if !ok {
|
||||
return PromptText{}, false
|
||||
|
||||
@@ -101,20 +101,20 @@ func TestPromptTextKeepsOnlyTheLastBodies(t *testing.T) {
|
||||
var tr trace
|
||||
body := []byte(`{"system":"s","messages":[{"role":"user","content":"hi"}]}`)
|
||||
for id := int64(1); id <= promptBodies+2; id++ {
|
||||
tr.keepBody(id, provider.Anthropic, body)
|
||||
tr.keepBody(id, provider.Anthropic, body, false)
|
||||
}
|
||||
for id := int64(1); id <= promptBodies+2; id++ {
|
||||
if _, ok := tr.keptBodyOf(id); ok != (id > 2) {
|
||||
t.Fatalf("body %d kept %v", id, ok)
|
||||
}
|
||||
}
|
||||
tr.keepBody(100, provider.Anthropic, make([]byte, promptBodyMax+1))
|
||||
tr.keepBody(100, provider.Anthropic, make([]byte, promptBodyMax+1), false)
|
||||
if _, ok := tr.keptBodyOf(100); ok {
|
||||
t.Fatal("kept a body over promptBodyMax")
|
||||
}
|
||||
big := make([]byte, promptBodiesMax/3)
|
||||
for id := int64(200); id < 204; id++ {
|
||||
tr.keepBody(id, provider.Anthropic, big)
|
||||
tr.keepBody(id, provider.Anthropic, big, false)
|
||||
}
|
||||
total := 0
|
||||
for _, b := range tr.bodies {
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/maskrec"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
"github.com/yetone/magpie/internal/usage"
|
||||
)
|
||||
|
||||
// redacted masks a request's secrets, as the settings say, before it goes
|
||||
@@ -240,6 +241,42 @@ func maskedQuery(ctx context.Context, query string, p *provider.Provider) (strin
|
||||
return masked, err
|
||||
}
|
||||
|
||||
// maskedCopy is body masked for a record of a request sent nowhere, nil
|
||||
// when masking fails: nothing unmasked is kept in its place.
|
||||
func maskedCopy(ctx context.Context, body []byte) []byte {
|
||||
m, err := gwmw.Masking(redactionWanted())
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if m == nil {
|
||||
return body
|
||||
}
|
||||
b, err := gwmw.Safely(func() []byte {
|
||||
if t, ok := m.(gwmw.ContextTeller); ok {
|
||||
b, _ := t.JSONHitsContext(ctx, body)
|
||||
return b
|
||||
}
|
||||
b, _ := m.JSON(body)
|
||||
return b
|
||||
})
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// bodiesKeptAway says a request's body may be kept off this computer: an
|
||||
// observer wants it (the OTLP export, a JS plugin's observer) or the
|
||||
// request archive is on. A request sent unmasked is masked for them all
|
||||
// the same.
|
||||
func bodiesKeptAway() bool {
|
||||
if usage.ObservedBodies() != usage.NoBodies {
|
||||
return true
|
||||
}
|
||||
_, on := archiveDest()
|
||||
return on
|
||||
}
|
||||
|
||||
// unredactedRoute says a request resolved to p, or to the group whose
|
||||
// models are ms, goes only where the user set requests to go unmasked
|
||||
// (provider.SkipsRedaction): p and each of its fallbacks, or every model of
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/gwmw"
|
||||
"github.com/yetone/magpie/internal/masking"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
"github.com/yetone/magpie/internal/usage"
|
||||
)
|
||||
|
||||
// countedMasker is the built-in masker, counting the bodies it is asked
|
||||
// to mask.
|
||||
type countedMasker struct {
|
||||
m masking.Masker
|
||||
n *atomic.Int64
|
||||
}
|
||||
|
||||
func (c countedMasker) JSON(b []byte) ([]byte, int) { c.n.Add(1); return c.m.JSON(b) }
|
||||
func (c countedMasker) Text(s string) (string, int) { c.n.Add(1); return c.m.Text(s) }
|
||||
func (c countedMasker) Restore(s string, escaped bool) string {
|
||||
return c.m.Restore(s, escaped)
|
||||
}
|
||||
func (c countedMasker) Writer(w http.ResponseWriter) (http.ResponseWriter, func()) {
|
||||
return c.m.Writer(w)
|
||||
}
|
||||
|
||||
// wangbinyq (#3973): a request that goes only to a local model set to go
|
||||
// unmasked was masked all the same before it was routed, and the masked
|
||||
// body thrown away, up to minutes of magpie's own time for each. Now it
|
||||
// isn't masked at all, a chat or a token count, and the log has it as it
|
||||
// went; one that goes to a vendor, an unknown model's, or one an observer
|
||||
// keeps the bodies of is masked as before.
|
||||
func TestUnmaskedRouteIsNotMasked(t *testing.T) {
|
||||
const key = "sk-proj-abcdEFGH1234ijklMNOP5678qrst"
|
||||
chat := `{"model":"fake/m1","max_tokens":10,"messages":[{"role":"user","content":"my key is ` + key + `"}]}`
|
||||
count := `{"model":"fake/m1","messages":[{"role":"user","content":"my key is ` + key + `"}]}`
|
||||
cases := []struct {
|
||||
name string
|
||||
set bool
|
||||
observed bool
|
||||
masks bool // the masker is asked
|
||||
whole bool // the provider is sent the key
|
||||
}{
|
||||
{name: "set to go unmasked", set: true, whole: true},
|
||||
{name: "unset", masks: true},
|
||||
{name: "an observer keeps the bodies", set: true, observed: true, masks: true, whole: true},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
f := &fake{ctype: "application/json", reply: `{"id":"msg_1","type":"message","role":"assistant","model":"m1","content":[{"type":"text","text":"ok"}],"stop_reason":"end_turn","usage":{"input_tokens":3,"output_tokens":1}}`}
|
||||
setup(t, provider.Anthropic, f)
|
||||
p, err := provider.Find("fake")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p.Unredacted = tc.set
|
||||
if err := provider.Save(*p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := settings.Save(settings.Settings{Redact: true}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if tc.observed {
|
||||
t.Cleanup(usage.Observe(&fakeObserver{bodies: usage.CapturedBodies}))
|
||||
}
|
||||
withoutMasker(t)
|
||||
n := new(atomic.Int64)
|
||||
t.Cleanup(gwmw.Mask(countedMasker{n: n}))
|
||||
s := New()
|
||||
rec := httptest.NewRecorder()
|
||||
s.Handler().ServeHTTP(rec, httptest.NewRequest("POST", "/v1/messages", strings.NewReader(chat)))
|
||||
if rec.Code != 200 {
|
||||
t.Fatalf("%d %s", rec.Code, rec.Body)
|
||||
}
|
||||
if whole := strings.Contains(string(f.got), key); whole != tc.whole {
|
||||
t.Fatalf("sent whole %v, want %v: %s", whole, tc.whole, f.got)
|
||||
}
|
||||
if masks := n.Load() > 0; masks != tc.masks {
|
||||
t.Fatalf("masked %d times, want masking %v", n.Load(), tc.masks)
|
||||
}
|
||||
c := s.Recent()[0]
|
||||
if logged := strings.Contains(c.RequestBody, key); logged != !tc.masks {
|
||||
t.Fatalf("the log has the key %v, want %v: %s", logged, !tc.masks, c.RequestBody)
|
||||
}
|
||||
if c.RequestBody == "" {
|
||||
t.Fatal("the log has no body")
|
||||
}
|
||||
n.Store(0)
|
||||
f.reply = `{"input_tokens":17}`
|
||||
if code, reply := post(t, "/v1/messages/count_tokens", count); code != 200 {
|
||||
t.Fatalf("count: %d %s", code, reply)
|
||||
}
|
||||
if whole := strings.Contains(string(f.got), key); whole != tc.whole {
|
||||
t.Fatalf("counted whole %v, want %v: %s", whole, tc.whole, f.got)
|
||||
}
|
||||
if masks := n.Load() > 0; masks != (tc.masks && !tc.set) {
|
||||
t.Fatalf("count masked %d times, want masking %v", n.Load(), tc.masks && !tc.set)
|
||||
}
|
||||
})
|
||||
}
|
||||
t.Run("an unknown model's log", func(t *testing.T) {
|
||||
f := &fake{ctype: "application/json"}
|
||||
setup(t, provider.Anthropic, f)
|
||||
if err := settings.Save(settings.Settings{Redact: true}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s := New()
|
||||
rec := httptest.NewRecorder()
|
||||
s.Handler().ServeHTTP(rec, httptest.NewRequest("POST", "/v1/messages", strings.NewReader(strings.Replace(chat, "fake/m1", "nobody/m1", 1))))
|
||||
if rec.Code != 404 {
|
||||
t.Fatalf("%d %s", rec.Code, rec.Body)
|
||||
}
|
||||
if c := s.Recent()[0]; c.RequestBody == "" || strings.Contains(c.RequestBody, key) {
|
||||
t.Fatalf("the log has %q", c.RequestBody)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user