package skills import ( "fmt" "strings" "testing" "unicode/utf8" ) // 技能描述在本仓库里几乎都是中文(SKILL.md 的 frontmatter),而 PromptSection 的 // 预算 maxPromptChars 是字节数:按字节切会在尾部留下半个中文字,这段是要进 system // prompt 发给模型的。 func TestPromptSectionTruncationKeepsUTF8(t *testing.T) { var sk []Skill for i := 0; i < 200; i++ { sk = append(sk, Skill{ Name: fmt.Sprintf("技能%03d", i), Description: strings.Repeat("用于演示中文描述的截断位置", 20), }) } out := PromptSection(sk) if len(out) <= maxPromptChars { t.Skip("没造出溢出场景,用例无效") } if !utf8.ValidString(out) { t.Errorf("技能列表截断后含非法 UTF-8,切点附近:%q", out[maxPromptChars-20:min(len(out), maxPromptChars+30)]) } if !strings.Contains(out, "skill list truncated") { t.Error("截断标记丢了——用户与模型都不知道这份列表不是全量") } }