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
+30
View File
@@ -90,6 +90,36 @@ func TestSummariseTrimsToOneLine(t *testing.T) {
}
}
func TestSummariseNormalisesAwkwardReplies(t *testing.T) {
cases := []struct {
name string
reply string
want string
}{
{"newlines and tabs", "First\tline\r\nsecond line", "First line"},
{"non-breaking spaces", "Fixed\u00a0the\u202fflaky\u2007test.", "Fixed the flaky test"},
{"zero-width characters", "Fixed \u200bthe \u200dflaky\ufeff test.", "Fixed the flaky test"},
{"surrounding quotes and trailing punctuation", "\u201cFixed the flaky test!\u201d", "Fixed the flaky test"},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
s := Summariser{
Selection: selection(),
Generator: generatorFunc(func(context.Context, stage.ModelConfig, string) (string, error) {
return tc.reply, nil
}),
}
got := s.Summarise(context.Background(), "source text")
if got != tc.want {
t.Fatalf("got %q, want %q", got, tc.want)
}
if strings.ContainsAny(got, "\r\n\t") || strings.Contains(got, "\u00a0\u200b\u200d\ufeff") {
t.Fatalf("result %q still carries whitespace or zero-width runes", got)
}
})
}
}
func TestSummariseCapsLongReply(t *testing.T) {
reply := strings.Repeat("x", OutputCap+50)
s := Summariser{