Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
79 lines
2.1 KiB
Go
79 lines
2.1 KiB
Go
package service
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestSanitizeGeneratedTitle(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
raw string
|
|
want string
|
|
wantTruncated bool
|
|
}{
|
|
{
|
|
name: "plain title is kept as is",
|
|
raw: "保单理赔流程咨询",
|
|
want: "保单理赔流程咨询",
|
|
},
|
|
{
|
|
name: "thinking prefix and surrounding whitespace are dropped",
|
|
raw: "<think>\n\n</think> Claim filing steps \n",
|
|
want: "Claim filing steps",
|
|
},
|
|
{
|
|
name: "over-long ascii title is truncated",
|
|
raw: strings.Repeat("a", 300),
|
|
want: strings.Repeat("a", maxSessionTitleRunes),
|
|
wantTruncated: true,
|
|
},
|
|
{
|
|
name: "over-long cjk title is truncated by rune, not byte",
|
|
raw: strings.Repeat("保", 300),
|
|
want: strings.Repeat("保", maxSessionTitleRunes),
|
|
wantTruncated: true,
|
|
},
|
|
{
|
|
name: "title exactly at the limit is not truncated",
|
|
raw: strings.Repeat("保", maxSessionTitleRunes),
|
|
want: strings.Repeat("保", maxSessionTitleRunes),
|
|
},
|
|
{
|
|
name: "empty completion stays empty",
|
|
raw: " ",
|
|
want: "",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
got, truncated := sanitizeGeneratedTitle(tt.raw)
|
|
if got != tt.want {
|
|
t.Fatalf("title = %q, want %q", got, tt.want)
|
|
}
|
|
if truncated != tt.wantTruncated {
|
|
t.Fatalf("truncated = %v, want %v", truncated, tt.wantTruncated)
|
|
}
|
|
if len([]rune(got)) > maxSessionTitleRunes {
|
|
t.Fatalf("title still exceeds %d runes: %d", maxSessionTitleRunes, len([]rune(got)))
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// The database column is VARCHAR(255) in every shipped migration; guard the
|
|
// constant so nobody raises it past what the column can hold.
|
|
func TestMaxSessionTitleRunesFitsColumn(t *testing.T) {
|
|
t.Parallel()
|
|
// Worst case for UTF-8 is 4 bytes per rune, but the column counts characters
|
|
// in PostgreSQL and bytes in some engines, so keep a conservative bound.
|
|
if maxSessionTitleRunes > 255 {
|
|
t.Fatalf("maxSessionTitleRunes=%d exceeds the sessions.title column limit", maxSessionTitleRunes)
|
|
}
|
|
}
|