Files
Maven/internal/router/worldquery_test.go
T
claude b5500a5be8 Say where the answer lives, not just that it is a question (V-655)
A question was sorted twice. The cascade picked one of seven intents with
stage 0 rules, the resident model and the classifier behind it, a 91-case
fixture measuring it and the decision trace recording it. Then IntentQuery
handed the turn to a second dispatch in the daemon, twenty-two branches
deciding by seed similarity in a fixed order, with none of that. The careful
sorter did the easy half.

Decision grows a Source: twelve destinations, not twenty-two, because the
recall passes are one destination from the outside and so are the three world
sources. Empty is a real value and it is the floor — nothing names one, the
daemon walks its whole chain, and that is exactly what shipped before.

Stage 0 fills it where a deterministic rule already knows. Two new world rules
for the shapes measured failing on the box on 2026-08-07: "что такое TCP?" and
"кто такой Линус Торвальдс?" were answered by weather and by the personal
boundary, and "сколько будет 17 на 23?" was answered "для какого города?".
The calendar noun rule and the closed event-noun rule name the calendar. The
possessive agenda rules deliberately do not: "что у меня в списке покупок"
matches agenda-query, and naming the calendar there would take the list off
the turn.

Fixture unchanged at 69/91, which is the point — it scores intent, and none of
these cases changes intent.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-07 13:01:59 +04:00

89 lines
3.2 KiB
Go

package router
import "testing"
// The three utterances from the 2026-08-07 week on the box that no local source
// could answer and three different local sources claimed anyway. Stage 0 has to
// say which side of the boundary they are on, because by the time the chain is
// walking, the only thing separating them from a weather forecast is a cosine.
func TestAWorldQuestionNamesTheWorld(t *testing.T) {
cases := []struct {
utterance string
rule string
}{
{"что такое TCP?", "definition-query"},
{"кто такой Линус Торвальдс?", "definition-query"},
{"что такая мембрана", "definition-query"},
{"кто такая Ада Лавлейс?", "definition-query"},
{"what is TCP?", "definition-query"},
{"сколько будет 17 на 23?", "arithmetic-query"},
{"посчитай 2+2", "arithmetic-query"},
{"сколько будет 5 умножить на 6", "arithmetic-query"},
}
for _, c := range cases {
dec, rule, ok := matchWorldQuery(c.utterance)
if !ok {
t.Errorf("%q: no world rule claimed it", c.utterance)
continue
}
if rule != c.rule {
t.Errorf("%q: claimed by %q, want %q", c.utterance, rule, c.rule)
}
if dec.Intent != IntentQuery {
t.Errorf("%q: intent %q, want query", c.utterance, dec.Intent)
}
if dec.Source != SourceWorld {
t.Errorf("%q: source %q, want %q", c.utterance, dec.Source, SourceWorld)
}
}
}
// The frame has to be the whole opening or the rule is reading somebody else's
// sentence. Every case here contains a world-question shape and is not one.
func TestAWorldRuleDeclinesWhatIsNotItsShape(t *testing.T) {
cases := []struct {
utterance string
why string
}{
{"напомни узнать что такое TCP", "a reminder that happens to quote the frame"},
{"запиши что такое TCP", "a capture that happens to quote the frame"},
{"сколько будет гостей", "an ask with no number is not arithmetic"},
{"что у меня сегодня?", "his agenda, and the agenda rules own it"},
{"кто там?", "not the frame"},
{"посчитай расходы", "no number, so the money source keeps it"},
}
for _, c := range cases {
if _, rule, ok := matchWorldQuery(c.utterance); ok {
t.Errorf("%q: claimed by %q, want no claim — %s", c.utterance, rule, c.why)
}
}
}
// The destination is advice about who may guess, never a filled slot. A rule
// that quietly captured the topic would change what every source below reads.
func TestNamingTheWorldFillsNoSlot(t *testing.T) {
dec, _, ok := matchWorldQuery("что такое TCP?")
if !ok {
t.Fatal("definition-query did not claim it")
}
if dec.Slots.Text != "" || dec.Slots.HasTime || dec.Slots.HasFn || dec.Slots.HasKey {
t.Errorf("slots = %+v, want none filled", dec.Slots)
}
if dec.Confidence != 1.0 {
t.Errorf("confidence = %v, want 1.0 for a stage-0 match", dec.Confidence)
}
}
func matchWorldQuery(utterance string) (Decision, string, bool) {
for _, g := range WorldQueryGrammars() {
m := g.Pattern.FindStringSubmatch(utterance)
if m == nil {
continue
}
if dec, ok := g.Build(m); ok {
return dec, g.Name, true
}
}
return Decision{}, "", false
}