Files
claude da9114b623 Preserve context across conversation intents (V-542)
Owner explicitly requested direct commits to master; bypass the branch-only hook.
2026-08-13 02:14:46 +04:00

99 lines
3.7 KiB
Go

package router
import (
"testing"
"time"
)
// Russian capture must produce the same keys the loop's care rules read, or a
// ru voice test silently writes nothing and the nudges look broken.
func TestDefaultFactParserRU(t *testing.T) {
p := DefaultFactParser{}
cases := []struct {
utterance string
key string
ok bool
}{
{"выпил воды", "water", true},
{"попил воду", "water", true},
{"я поел", "meal", true},
{"пообедал", "meal", true},
{"принял душ", "shower", true},
{"сделал перерыв", "break", true},
{"немного отдохнул", "break", true},
{"поспал шесть часов", "sleep", true},
{"перезапусти nginx", "", false}, // an act, not a fact
// Inflections the substring stems caught and a lemma test must keep.
{"только что выпил кружку воды", "water", true},
{"воды попил наконец", "water", true},
{"пью воду", "water", true},
{"поужинал", "meal", true},
{"отметь что я позавтракал овсянкой", "meal", true},
{"сходил в душ", "shower", true},
{"отдыхал час", "break", true},
{"выспался", "sleep", true},
// Misfires the substring stems accepted. Rejecting them is the point of
// V-586: none of these is a fact about his day.
{"я пилот", "", false},
{"водитель приехал", "", false},
{"надо заводить машину", "", false},
{"у меня душа болит", "", false},
{"в комнате душно", "", false},
{"это была беда", "", false},
{"победа наша", "", false},
}
for _, c := range cases {
k, _, ok := p.Parse(c.utterance)
if ok != c.ok || k != c.key {
t.Errorf("Parse(%q) = (%q, %v), want (%q, %v)", c.utterance, k, ok, c.key, c.ok)
}
}
}
func TestAnaphoraResolverUsesTokenBoundariesAcrossPunctuation(t *testing.T) {
r := AnaphoraResolver{}
for _, text := range []string{
"что это?",
"вернуть его, наверное",
"а он — большой?",
"расскажи о ней.",
} {
if _, ok := r.Resolve(text); !ok {
t.Errorf("Resolve(%q) missed a punctuated pronoun", text)
}
}
for _, text := range []string{"этология", "нейросеть", "онлайн"} {
if ref, ok := r.Resolve(text); ok {
t.Errorf("Resolve(%q) = %q; substring is not a pronoun token", text, ref)
}
}
}
func TestParseCalendarDate(t *testing.T) {
now := time.Date(2026, 7, 6, 14, 30, 0, 0, time.UTC)
cases := []struct {
text string
want time.Time
ok bool
}{
{"что у меня сегодня по плану", time.Date(2026, 7, 6, 0, 0, 0, 0, time.UTC), true},
{"что завтра", time.Date(2026, 7, 7, 0, 0, 0, 0, time.UTC), true},
{"планы на сегодня", time.Date(2026, 7, 6, 0, 0, 0, 0, time.UTC), true},
{"расписание на завтра", time.Date(2026, 7, 7, 0, 0, 0, 0, time.UTC), true},
{"what's today", time.Date(2026, 7, 6, 0, 0, 0, 0, time.UTC), true},
{"tomorrow plans", time.Date(2026, 7, 7, 0, 0, 0, 0, time.UTC), true},
{"какое число послезавтра", time.Date(2026, 7, 8, 0, 0, 0, 0, time.UTC), true},
{"что было вчера", time.Date(2026, 7, 5, 0, 0, 0, 0, time.UTC), true},
{"yesterday plans", time.Date(2026, 7, 5, 0, 0, 0, 0, time.UTC), true},
{"какая погода", time.Time{}, false},
{"сколько времени", time.Time{}, false},
{"", time.Time{}, false},
}
for _, c := range cases {
got, ok := ParseCalendarDate(c.text, now)
if ok != c.ok || !got.Equal(c.want) {
t.Errorf("ParseCalendarDate(%q) = %v, %v; want %v, %v", c.text, got, ok, c.want, c.ok)
}
}
}