mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-13 11:40:53 +08:00
Comments, doc comments, UI labels, log and error messages, LLM prompt strings, markdown docs, test data and assertions. Identifiers, enum keys, routes, placeholders and code structure are unchanged. Notes: - docs/漏洞流量证据.md renamed to docs/vulnerability-traffic-evidence.md - tests that exercised CJK specific handling (GBK zip names, Chinese full text search) now use ASCII equivalents; go build passes and the test suite matches the pre translation baseline (remaining failures need a PostgreSQL DSN and fail identically on the original) - frontend mention syntax now uses English kinds (finding, asset, ...) matching the backend, chat mentions tests pass
32 lines
1005 B
Go
32 lines
1005 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)
|
||
}
|
||
}
|