d00929ac0b
replySystem had two arms that PR 30 made reachable, and both answered confidently wrong: the date arm keyword-matched "числ" and always answered today, so "какое число завтра" answered today; the clock arm ignored a named city and answered local time. The date arm now reads the day word through router.ParseCalendarDate (which grew послезавтра/вчера and now cuts the day boundary in the local zone instead of UTC). The clock arm answers the named zone when it resolves offline from the tz database embedded in the binary, and otherwise says plainly that she only knows local time. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CGeSZxh1DCtRxmFVSYVGvJ
59 lines
2.4 KiB
Go
59 lines
2.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/kami/maven/internal/router"
|
|
)
|
|
|
|
// systemHandler — a handler with nothing but a fixed clock, which is all
|
|
// replySystem needs.
|
|
func systemHandler(now time.Time) *reactiveHandler {
|
|
return &reactiveHandler{now: func() time.Time { return now }}
|
|
}
|
|
|
|
// TestReplySystemDateOffset — "какое число завтра" must answer tomorrow's
|
|
// date, not today's (Vikunja #388).
|
|
func TestReplySystemDateOffset(t *testing.T) {
|
|
// Thursday, 30 July 2026.
|
|
now := time.Date(2026, 7, 30, 14, 5, 0, 0, time.UTC)
|
|
h := systemHandler(now)
|
|
cases := []struct{ utterance, want string }{
|
|
{"какое сегодня число", "сегодня четверг, 30 июля 2026 года"},
|
|
{"какое число", "сегодня четверг, 30 июля 2026 года"},
|
|
{"какое число завтра", "завтра пятница, 31 июля 2026 года"},
|
|
{"какое число послезавтра", "послезавтра суббота, 1 августа 2026 года"},
|
|
{"какое было число вчера", "вчера среда, 29 июля 2026 года"},
|
|
}
|
|
for _, c := range cases {
|
|
got := h.replySystem(context.Background(), router.Decision{Utterance: c.utterance})
|
|
if got != c.want {
|
|
t.Errorf("replySystem(%q) = %q, want %q", c.utterance, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestReplySystemClockCity — the clock arm must not answer local time for a
|
|
// question about another city (Vikunja #388). Known cities get their own zone;
|
|
// unknown places get an honest "local time only".
|
|
func TestReplySystemClockCity(t *testing.T) {
|
|
// 12:00 UTC — Kyiv is +03 in July, Moscow +03, London +01.
|
|
now := time.Date(2026, 7, 30, 12, 0, 0, 0, time.UTC)
|
|
h := systemHandler(now)
|
|
cases := []struct{ utterance, want string }{
|
|
{"который час", "сейчас 12 часов ровно"},
|
|
{"который час в киеве", "в Киеве сейчас 15 часов ровно"},
|
|
{"сколько времени в москве", "в Москве сейчас 15 часов ровно"},
|
|
{"который час в лондоне", "в Лондоне сейчас 13 часов ровно"},
|
|
{"который час в бишкеке", onlyLocalTimeReply},
|
|
}
|
|
for _, c := range cases {
|
|
got := h.replySystem(context.Background(), router.Decision{Utterance: c.utterance})
|
|
if got != c.want {
|
|
t.Errorf("replySystem(%q) = %q, want %q", c.utterance, got, c.want)
|
|
}
|
|
}
|
|
}
|