secert updated
This commit is contained in:
@@ -3,9 +3,9 @@ package controllers
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"hash/crc32"
|
||||
"io"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -179,9 +179,24 @@ func buildApp(t *testing.T, chat utils.Chat) (*fiber.App, *fakeShop) {
|
||||
return app, shop
|
||||
}
|
||||
|
||||
// webSession mints a session for THIS test's own user.
|
||||
//
|
||||
// One user id across the file put every test in one rate-limit bucket — six
|
||||
// questions and then 429 for ten seconds — so the suite passed test by test and
|
||||
// failed when run together, which is the worst way round: green locally, red in
|
||||
// CI, and the failure blamed on the model.
|
||||
//
|
||||
// A per-test user is also the truthful shape. The limiter is per person, and
|
||||
// two tests are two people.
|
||||
func webSession(t *testing.T) string {
|
||||
t.Helper()
|
||||
token, _, err := utils.MintWebToken(testCaller, time.Now())
|
||||
|
||||
claims := testCaller
|
||||
// Stable across runs and distinct per test, so a failure names the same
|
||||
// user every time. The fakes key on tenant, never on this.
|
||||
claims.Userid = testCaller.Userid + int(crc32.ChecksumIEEE([]byte(t.Name()))%10_000)
|
||||
|
||||
token, _, err := utils.MintWebToken(claims, time.Now())
|
||||
if err != nil {
|
||||
t.Fatalf("minting a session: %v", err)
|
||||
}
|
||||
@@ -306,20 +321,9 @@ func TestStatusNamesTheMissingVariable(t *testing.T) {
|
||||
func liveHTTPChat(t *testing.T) utils.Chat {
|
||||
t.Helper()
|
||||
|
||||
// Defaults exactly as production does, so this proves three variables are
|
||||
// enough rather than working around the question.
|
||||
provider := strings.ToLower(strings.TrimSpace(os.Getenv("ASSISTANT_PROVIDER")))
|
||||
model := strings.TrimSpace(os.Getenv("ASSISTANT_MODEL"))
|
||||
if provider == "" && model != "" {
|
||||
provider = "openai"
|
||||
}
|
||||
|
||||
cfg := config.AssistantConfig{
|
||||
Provider: provider,
|
||||
BaseURL: os.Getenv("ASSISTANT_BASE_URL"),
|
||||
APIKey: os.Getenv("ASSISTANT_API_KEY"),
|
||||
Balanced: model,
|
||||
}
|
||||
// Read exactly as production reads it, so this proves the shipped defaults
|
||||
// work rather than quietly testing a configuration of its own.
|
||||
cfg := config.AssistantFromEnv()
|
||||
if !cfg.Enabled() {
|
||||
t.Skipf("no model configured: %s", cfg.Why())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user