79 lines
3.6 KiB
Go
79 lines
3.6 KiB
Go
package domain
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.cin.su/m/Assistant/contracts/interaction"
|
|
)
|
|
|
|
func TestCompilePersonalMemoryKeepsLatestLocationAndPreferences(t *testing.T) {
|
|
memory := CompilePersonalMemory([]interaction.HumanUtterance{
|
|
{ID: "location-old", Content: "я сейчас в Санкт-Петербурге", ReceivedAtUnixMillis: 100},
|
|
{ID: "color", Content: "мне нравится красный цвет", ReceivedAtUnixMillis: 200},
|
|
{ID: "location-new", Content: "я сейчас в Москве", ReceivedAtUnixMillis: 300},
|
|
})
|
|
if got := memory.CurrentLocation(); got != "Москве" {
|
|
t.Fatalf("current location = %q", got)
|
|
}
|
|
context := memory.ContextText()
|
|
if !strings.Contains(context, "Москве") || !strings.Contains(context, "красный цвет") || strings.Contains(context, "Санкт-Петербурге") {
|
|
t.Fatalf("unexpected compact memory context: %q", context)
|
|
}
|
|
}
|
|
|
|
func TestCompilePersonalMemoryDoesNotTreatThirdPartyStatementAsPersonalFact(t *testing.T) {
|
|
memory := CompilePersonalMemory([]interaction.HumanUtterance{{Content: "Погода сейчас в Москве", ReceivedAtUnixMillis: 100}})
|
|
if memory.CurrentLocation() != "" || memory.ContextText() != "" {
|
|
t.Fatalf("ordinary factual question became personal memory: %+v", memory)
|
|
}
|
|
}
|
|
|
|
func TestCompilePersonalMemoryBoundsLongRememberedValues(t *testing.T) {
|
|
longValue := strings.Repeat("x", 513)
|
|
memory := CompilePersonalMemory([]interaction.HumanUtterance{{
|
|
Content: "запомни: мой тестовый цвет — " + longValue,
|
|
ReceivedAtUnixMillis: 100,
|
|
}})
|
|
if memory.ContextText() != "" {
|
|
t.Fatalf("long remembered value leaked into cognitive context: %q", memory.ContextText())
|
|
}
|
|
}
|
|
|
|
func TestRecallPersonalPreferenceUsesProjectedAssertion(t *testing.T) {
|
|
answer := RecallPersonalPreference([]interaction.HumanUtterance{{
|
|
Content: "запомни: мой тестовый цвет — acceptance-m5-синий-914",
|
|
}}, "Какой тестовый цвет я назвал?")
|
|
if answer != "Вы называли тестовый цвет: acceptance-m5-синий-914." {
|
|
t.Fatalf("answer=%q", answer)
|
|
}
|
|
}
|
|
|
|
func TestCompilePersonalMemoryRanksCurrentSubjectWithoutDroppingHistory(t *testing.T) {
|
|
memory := CompilePersonalMemory([]interaction.HumanUtterance{
|
|
{ID: "old", Content: "запомни: мой тестовый цвет — фиолетовый", ReceivedAtUnixMillis: 100},
|
|
{ID: "new", Content: "запомни: мой тестовый цвет — acceptance-m5-синий-914", ReceivedAtUnixMillis: 200},
|
|
})
|
|
current, ok := memory.LatestPreference("тестовый цвет")
|
|
if !ok || current.Value != "тестовый цвет — acceptance-m5-синий-914" {
|
|
t.Fatalf("current=%+v ok=%t", current, ok)
|
|
}
|
|
if len(memory.Facts) != 2 {
|
|
t.Fatalf("historical evidence was dropped: %+v", memory.Facts)
|
|
}
|
|
}
|
|
|
|
func TestCompilePersonalMemoryNormalizesOperationalSubjectMarker(t *testing.T) {
|
|
memory := CompilePersonalMemory([]interaction.HumanUtterance{
|
|
{ID: "old", Content: "запомни: мой тестовый цвет — фиолетовый", ReceivedAtUnixMillis: 100},
|
|
{ID: "new", Content: "запомни: мой тестовый цвет M5 — лазурный", ReceivedAtUnixMillis: 200},
|
|
})
|
|
current, ok := memory.LatestPreference("тестовый цвет")
|
|
if !ok || current.SourceUtteranceID != "new" || !strings.Contains(current.Value, "лазурный") {
|
|
t.Fatalf("expected newest marked preference, got %+v, ok=%t", current, ok)
|
|
}
|
|
if len(memory.Facts) != 2 {
|
|
t.Fatalf("expected historical fact retention, got %d facts", len(memory.Facts))
|
|
}
|
|
}
|