secert updated

This commit is contained in:
2026-09-24 17:20:04 +05:30
parent 299871b820
commit 00317a00d8
11 changed files with 517 additions and 81 deletions

View File

@@ -112,6 +112,13 @@ func (ctl *AssistantController) Ask(c *fiber.Ctx) error {
if errors.As(err, &tooFast) {
return assistantRefuse(c, http.StatusTooManyRequests, err.Error())
}
// The provider's quota, as opposed to our own limiter above. Same status
// for the same reason — it is not a bad question, it is a busy minute —
// and the message is ours rather than Groq's, which names our billing
// account and the tokens-per-minute arithmetic behind it.
if errors.Is(err, utils.ErrBusy) {
return assistantRefuse(c, http.StatusTooManyRequests, utils.ErrBusy.Error())
}
return assistantRefuse(c, http.StatusBadRequest, err.Error())
}

View File

@@ -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())
}