Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
80 lines
2.1 KiB
Go
80 lines
2.1 KiB
Go
package support
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func TestScoreCorpusItem_keywordAndCategory(t *testing.T) {
|
|
t.Parallel()
|
|
hay := "i cannot reset my password on the account page"
|
|
score := ScoreCorpusItemForTest(hay, "account",
|
|
[]string{"password", "reset"},
|
|
[]string{"password_reset"},
|
|
[]string{"account"},
|
|
0,
|
|
)
|
|
if score < 0.78 {
|
|
t.Fatalf("expected strong match score >= 0.78, got %v", score)
|
|
}
|
|
weak := ScoreCorpusItemForTest("hello world", "other",
|
|
[]string{"password", "reset", "billing", "invoice"},
|
|
nil,
|
|
[]string{"billing"},
|
|
0,
|
|
)
|
|
if weak >= 0.5 {
|
|
t.Fatalf("expected weak score < 0.5, got %v", weak)
|
|
}
|
|
}
|
|
|
|
func TestRedactSecretsForMatch(t *testing.T) {
|
|
t.Parallel()
|
|
in := "key sk-abcdefghijklmnopqrstuvwxyz12 and Bearer tokensecret1234567890 end"
|
|
out := RedactSecretsForMatch(in)
|
|
if strings.Contains(out, "sk-abcdefghijklmnopqrstuvwxyz12") || strings.Contains(out, "tokensecret1234567890") {
|
|
t.Fatalf("secrets not redacted: %q", out)
|
|
}
|
|
if !strings.Contains(out, "REDACTED") {
|
|
t.Fatalf("expected REDACTED marker, got %q", out)
|
|
}
|
|
}
|
|
|
|
func TestApplyTemplatePlaceholders_allowlist(t *testing.T) {
|
|
t.Parallel()
|
|
ticket := Ticket{Subject: "Need help", Category: "billing"}
|
|
body := applyTemplatePlaceholders("Re: {{subject}} ({{category}}) {{evil}}", ticket)
|
|
if !strings.Contains(body, "Need help") || !strings.Contains(body, "billing") {
|
|
t.Fatalf("placeholders not applied: %q", body)
|
|
}
|
|
if !strings.Contains(body, "{{evil}}") {
|
|
t.Fatalf("disallowed placeholder should remain literal: %q", body)
|
|
}
|
|
}
|
|
|
|
func TestLabelAutoBody_idempotent(t *testing.T) {
|
|
t.Parallel()
|
|
once := labelAutoBody("Hello")
|
|
twice := labelAutoBody(once)
|
|
if strings.Count(twice, "Automated answer from help center") != 1 {
|
|
t.Fatalf("footer duplicated: %q", twice)
|
|
}
|
|
}
|
|
|
|
func TestMatchAutoReplyResult_shape(t *testing.T) {
|
|
t.Parallel()
|
|
id := uuid.New()
|
|
r := MatchAutoReplyResult{
|
|
Matched: true,
|
|
Confidence: 0.9,
|
|
ReplyBody: "answer",
|
|
ArticleID: &id,
|
|
Kind: MatchKindKBArticle,
|
|
}
|
|
if !r.Matched || r.ArticleID == nil || r.Kind != MatchKindKBArticle {
|
|
t.Fatalf("unexpected result: %+v", r)
|
|
}
|
|
}
|