Fix build: define protocol.NormalizeText used by the summariser

internal/summarise called protocol.NormalizeText, which was never defined, so the tree did not compile. Add the shared normalisation helper: drop zero-width formatting runes, turn control characters into spaces and collapse whitespace runs (including the non-breaking space variants) into single spaces. Reuse it in OutputPreview instead of duplicating the mapping logic.

Cover the awkward inputs (newlines, tabs, non-breaking spaces, zero-width runes, surrounding quotes, trailing punctuation) in the protocol and summarise tests. Unrelated working-tree changes are left uncommitted.
This commit is contained in:
2026-10-16 12:28:27 +01:00
parent 8e49a0c6f9
commit bfef465977
3 changed files with 90 additions and 7 deletions
+26
View File
@@ -26,3 +26,29 @@ func TestOutputPreviewUsesRetainedValuesWithoutAssumingSchema(t *testing.T) {
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)
}
})
}
}