package protocol import ( "encoding/json" "strings" "testing" ) func TestOutputPreviewUsesRetainedValuesWithoutAssumingSchema(t *testing.T) { for _, test := range []struct { output map[string]any want string }{ {map[string]any{"summary": "Fixed layout\nand added regression checks", "evidence": "details"}, "Fixed layout and added regression checks"}, {map[string]any{"artifacts": []string{"report.md"}}, `artifacts: ["report.md"]`}, {map[string]any{"z": true, "a": json.Number("9007199254740993")}, "a: 9007199254740993"}, {map[string]any{"input": map[string]any{"prompt": "private task"}}, ""}, {nil, ""}, } { if got := OutputPreview(test.output); got != test.want { t.Fatal(got, test.want) } } preview := OutputPreview(map[string]any{"summary": strings.Repeat("宽", 500)}) if len([]rune(preview)) != 280 || !strings.HasSuffix(preview, "…") { t.Fatal("preview is not bounded by characters") } } func TestNormalizeTextCollapsesToSingleCleanLine(t *testing.T) { for _, test := range []struct { name string in string want string }{ {"whitespace and control characters", " a\t\t b\n\nc\r\nd ", "a b c d"}, {"non-breaking spaces", "a\u00a0\u202fb\u2007c", "a b c"}, {"zero-width joiners", "a\u200b\u200c\u200db", "ab"}, {"word joiner and byte-order mark", "\ufeffa\u2060b", "ab"}, {"soft hyphen and mongolian vowel separator", "so\u00adft\u180e-hyphen", "soft-hyphen"}, {"only invisible runes", "\u00a0\t\u200b\r\n", ""}, {"already clean", "one clean line", "one clean line"}, } { t.Run(test.name, func(t *testing.T) { got := NormalizeText(test.in) if got != test.want { t.Fatalf("NormalizeText(%q) = %q, want %q", test.in, got, test.want) } if strings.ContainsAny(got, "\r\n\t") || strings.Contains(got, " ") { t.Fatalf("NormalizeText(%q) is not single-spaced: %q", test.in, got) } }) } }