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:
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user