ci / go (push) Waiting to run
ci / go-db (agent) (push) Waiting to run
ci / go-db (config) (push) Waiting to run
ci / go-db (db) (push) Waiting to run
ci / go-db (evidence) (push) Waiting to run
ci / go-db (llmrec) (push) Waiting to run
ci / go-db (server) (push) Waiting to run
detections / detections (push) Waiting to run
web / web (push) Waiting to run
docs / links (push) Canceled after 0s
32 lines
1006 B
Go
32 lines
1006 B
Go
package agent
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"unicode/utf8"
|
|
|
|
"github.com/Autumn-27/artex/db"
|
|
)
|
|
|
|
func TestOverviewTextBudgetIsFairAndUTF8Safe(t *testing.T) {
|
|
if got := relatedOverviewBudgetForSources(1); got != relatedOverviewMaxTextPerSource {
|
|
t.Fatalf("single source budget=%d want=%d", got, relatedOverviewMaxTextPerSource)
|
|
}
|
|
perSource := relatedOverviewBudgetForSources(db.MaxTaskSourceCount)
|
|
if perSource*db.MaxTaskSourceCount > relatedOverviewTotalTextRunes {
|
|
t.Fatalf("aggregate budget exceeded: per_source=%d", perSource)
|
|
}
|
|
|
|
budget := overviewTextBudget{remaining: 5}
|
|
got := budget.take(strings.Repeat("中", 10), 20)
|
|
if !utf8.ValidString(got) {
|
|
t.Fatalf("budget truncation produced invalid UTF-8: %q", got)
|
|
}
|
|
if utf8.RuneCountInString(got) != 5 || !budget.truncated || budget.remaining != 0 {
|
|
t.Fatalf("unexpected truncation: got=%q budget=%+v", got, budget)
|
|
}
|
|
if tail := budget.take("more", 20); tail != "" {
|
|
t.Fatalf("exhausted budget returned more text: %q", tail)
|
|
}
|
|
}
|