7f42cc73be
Seven fixes, each answering a line comment on the stack.
**Weather no longer invents Moscow** (PR 50). extractWeatherLocation returned
the string "Moscow" when he named no city and voice.weather.default_location
was unset — a made-up answer presented as fact, which is the one thing maven
must never do. It returns "" now and the query path says it does not know.
**Digest statuses are a defined type** (PR 50). DigestStatus string plus the
three constants, so a rule name cannot reach the status column.
**Quiet-mode negation is not adjacency** (PR 53). The OFF list carried
{"не","тих"}, an adjacency pattern, so "не надо тихий режим" missed OFF, hit
the ON pattern {"тих","режим"}, and asking for quiet mode to stop turned it
on. Negators are scanned over the whole utterance now, with the two ON phrases
that are themselves built on "не" excluded. "тихий режим выключи" works too,
which it did not before.
**Pattern stability uses a median band** (PR 54). max/min over the extremes
asked whether every gap resembles every other gap, so 7,7,7,7,20 — four clean
weeks and one holiday — was thrown away at a ratio of 2.9. Each interval is
now tested against the median and 70% must be in band, and the reported
interval is the median of the in-band ones, so a holiday no longer drags a
weekly habit to "every 9.6 days". The reviewer's 5,8,10,3 is still rejected.
**The weekday profile stops reciting everyday habits** (PR 59). "What do I do
on Saturdays?" answered "you drink water" — true, and useless, because it is
equally true of every other day. Activities that are habits on six or more
weekdays move to Profile.Everyday and are read back as daily habits instead of
as an answer about that day.
**Russian phrase tables move out of Go** (PR 59, PR 61). The behaviour glosses
and weekday names, and the task capture/urgency/list vocabulary, are now
behavior_ru.json and task_phrases.json, embedded with go:embed. Single-binary
deploy is unchanged; wording edits are no longer source diffs.
**nginx template stops taking nginx down** (PR 52). Two host-side failure
modes, both plausible causes of today's crash. The $connection_upgrade map is
fatal when duplicated, so it moved to its own nginx-upgrade-map.conf with a
grep-first note. And `listen 10.42.0.1:80` fails with EADDRNOTAVAIL when wg0
is not up yet, so nginx exits on a reboot that beats WireGuard — the header
now documents net.ipv4.ip_nonlocal_bind.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TrVSBKe3RFDF4fGYKWYQnX
150 lines
4.7 KiB
Go
150 lines
4.7 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/kami/maven/internal/ipc"
|
|
)
|
|
|
|
// quietFakeAPI records the WriteFact the toggle performs.
|
|
type quietFakeAPI struct {
|
|
ipc.UnimplementedCoreAPI
|
|
got ipc.WriteFactReq
|
|
call int
|
|
}
|
|
|
|
func (a *quietFakeAPI) WriteFact(_ context.Context, req ipc.WriteFactReq) (int64, error) {
|
|
a.got, a.call = req, a.call+1
|
|
return 1, nil
|
|
}
|
|
|
|
// quietVerdict — what a phrase should do to the setting.
|
|
type quietVerdict int
|
|
|
|
const (
|
|
quietNone quietVerdict = iota
|
|
quietOn
|
|
quietOff
|
|
)
|
|
|
|
func TestResolveQuietToggle(t *testing.T) {
|
|
cases := []struct {
|
|
text string
|
|
want quietVerdict
|
|
}{
|
|
// ON vocabulary.
|
|
{"quiet on", quietOn},
|
|
{"quiet mode", quietOn},
|
|
{"тихий режим", quietOn},
|
|
{"тихий", quietOn},
|
|
{"не шуми", quietOn},
|
|
{"не беспокоить", quietOn},
|
|
{"тихо", quietOn},
|
|
// ON, inflected / embedded in a sentence.
|
|
{"включи тихий режим", quietOn},
|
|
{"побудь в тихом режиме", quietOn},
|
|
{"Тихий Режим!", quietOn},
|
|
{"тихая", quietOn},
|
|
|
|
// OFF vocabulary — all seven, incl. the three that used to say ON.
|
|
{"quiet off", quietOff},
|
|
{"quiet end", quietOff},
|
|
{"громкий режим", quietOff},
|
|
{"шумный режим", quietOff},
|
|
{"отмени тихий", quietOff},
|
|
{"выключи тихий", quietOff},
|
|
{"не тихо", quietOff},
|
|
// OFF wins over the ON words it contains.
|
|
{"выключи тихий режим", quietOff},
|
|
{"отмени тихий режим пожалуйста", quietOff},
|
|
{"верни громкий режим", quietOff},
|
|
|
|
// False positives: "тихо"/"тихий" as ordinary Russian.
|
|
{"очень тихий сегодня день", quietNone},
|
|
{"в комнате тихо", quietNone},
|
|
{"тихонько напомни", quietNone},
|
|
{"потихоньку", quietNone},
|
|
{"тихонько", quietNone},
|
|
{"он говорил тихим голосом весь вечер", quietNone},
|
|
|
|
// Unrelated.
|
|
{"напомни завтра позвонить маме", quietNone},
|
|
{"какая погода", quietNone},
|
|
{"", quietNone},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.text, func(t *testing.T) {
|
|
api := &quietFakeAPI{}
|
|
h := &reactiveHandler{api: api, now: func() time.Time { return time.Unix(0, 0).UTC() }}
|
|
reply, handled := h.resolveQuietToggle(context.Background(), tc.text)
|
|
|
|
if tc.want == quietNone {
|
|
if handled || reply != "" {
|
|
t.Fatalf("%q: got (%q, %v), want no match", tc.text, reply, handled)
|
|
}
|
|
if api.call != 0 {
|
|
t.Fatalf("%q: wrote a fact on a non-match", tc.text)
|
|
}
|
|
return
|
|
}
|
|
if !handled {
|
|
t.Fatalf("%q: not handled, want %v", tc.text, tc.want)
|
|
}
|
|
wantReply, wantVal := "тихий режим выключен.", "false"
|
|
if tc.want == quietOn {
|
|
wantReply, wantVal = "тихий режим включён. буду реже напоминать.", "true"
|
|
}
|
|
if reply != wantReply {
|
|
t.Errorf("%q: reply = %q, want %q", tc.text, reply, wantReply)
|
|
}
|
|
if api.call != 1 {
|
|
t.Fatalf("%q: WriteFact called %d times, want 1", tc.text, api.call)
|
|
}
|
|
if api.got.Kind != "config" || api.got.Key != "quiet_hours" || api.got.Source != "tap:voice" || api.got.Confidence != 1.0 {
|
|
t.Errorf("%q: request shape = %+v", tc.text, api.got)
|
|
}
|
|
if api.got.Value != wantVal {
|
|
t.Errorf("%q: value = %q, want %q", tc.text, api.got.Value, wantVal)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestQuietToggleNegationIsNotAdjacency — negation used to be an adjacency
|
|
// pattern ({"не","тих"} in the OFF list), so any word between the negator and
|
|
// the quiet word made the ON pattern win and asking for quiet mode to STOP
|
|
// turned it on. Negation is scanned over the whole utterance now.
|
|
func TestQuietToggleNegationIsNotAdjacency(t *testing.T) {
|
|
off := []string{
|
|
"не надо тихий режим",
|
|
"не хочу тихий режим",
|
|
"тихий режим выключи",
|
|
"убери тихий режим",
|
|
"хватит тихого режима",
|
|
"прекрати тихий режим",
|
|
"тихий режим отмени пожалуйста",
|
|
}
|
|
for _, text := range off {
|
|
t.Run(text, func(t *testing.T) {
|
|
on, isOff := classifyQuietToggle(text)
|
|
if on || !isOff {
|
|
t.Fatalf("%q: want OFF, got on=%v off=%v", text, on, isOff)
|
|
}
|
|
})
|
|
}
|
|
|
|
// The two ON phrases that are themselves built on "не" must stay ON: they
|
|
// are requests FOR quiet, not negations of one.
|
|
for _, text := range []string{"не шуми", "не беспокоить"} {
|
|
t.Run(text, func(t *testing.T) {
|
|
on, isOff := classifyQuietToggle(text)
|
|
if !on || isOff {
|
|
t.Fatalf("%q: want ON, got on=%v off=%v", text, on, isOff)
|
|
}
|
|
})
|
|
}
|
|
}
|