Files
Maven/internal/phraser/llmphraser_chatmsg_test.go
claude e94c868160 a chat prompt says which turn to answer (V-554)
Prior turns were joined with newlines and nothing else, so the model got
four unlabelled lines and no way to tell which one was the question. It
answered an earlier one: asked "как дела" after a question about the
telephone, she carried on about the telephone. Four turns live for
fifteen minutes, so the line she answered was often minutes old.

One user message still, because the template constraint that forced the
flattening is real. The turns are labelled as his own earlier words and
the current utterance is named as the one to answer. With no history
the message is the utterance alone, unchanged.
2026-08-05 22:40:28 +04:00

43 lines
1.6 KiB
Go

package phraser
import (
"strings"
"testing"
"github.com/kami/maven/internal/dialogue"
)
// TestChatUserMessageMarksWhichTurnToAnswer — Vikunja #554. Four prior turns
// were joined with newlines and nothing else, so nothing in the message said
// which line was the question.
func TestChatUserMessageMarksWhichTurnToAnswer(t *testing.T) {
got := chatUserMessage("как дела", []dialogue.Turn{
{Text: "кто изобрёл телефон"},
{Text: "а когда это было"},
})
if !strings.Contains(got, "кто изобрёл телефон") {
t.Error("the prior turns must survive — they are what anaphora reads")
}
now := strings.LastIndex(got, "как дела")
if now < strings.Index(got, "кто изобрёл телефон") {
t.Error("the current utterance must come last, after the turns it follows")
}
if !strings.Contains(got, "Раньше ты говорил") {
t.Errorf("the prior turns must be labelled as prior: %q", got)
}
if strings.Contains(got, " вы ") || strings.Contains(got, "Вы ") {
t.Errorf("the persona addresses him informally: %q", got)
}
}
// TestChatUserMessageWithNoHistoryIsJustTheUtterance — the common case must not
// grow a preamble that the model then has to see past.
func TestChatUserMessageWithNoHistoryIsJustTheUtterance(t *testing.T) {
if got := chatUserMessage(" привет ", nil); got != "привет" {
t.Errorf("chatUserMessage = %q, want %q", got, "привет")
}
if got := chatUserMessage("привет", []dialogue.Turn{{Text: " "}}); got != "привет" {
t.Errorf("a blank prior turn must not label anything: %q", got)
}
}