From 6e3bb3be976d5ad8bf9009614e6c0fad5c1ed642 Mon Sep 17 00:00:00 2001 From: claude Date: Wed, 5 Aug 2026 21:40:49 +0400 Subject: [PATCH] each agenda grammar is tested against its own example (V-552) Replaces a test whose name promised more than its body checked: it looped the grammars asserting Pattern != nil, which regexp.MustCompile already guarantees at init. Asserting the grammars pass IsAgendaQuestion would be true by construction, since the first arm is that same loop. A hand-written example per grammar name catches what neither does: a grammar edited until it no longer matches the case its comment gives, and a new grammar nobody wrote an example for. --- internal/router/agendaq_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/internal/router/agendaq_test.go b/internal/router/agendaq_test.go index 2421ee0..4781d59 100644 --- a/internal/router/agendaq_test.go +++ b/internal/router/agendaq_test.go @@ -39,3 +39,28 @@ func TestIsAgendaQuestionSeparatesHisDayFromTheWorld(t *testing.T) { } } } + +// One hand-written utterance per agenda grammar, keyed by name. Asserting that +// the grammars pass IsAgendaQuestion would be true by construction, since the +// first arm is the loop over them. This asserts something else: that each +// grammar still matches the case its own comment gives, and that the set of +// grammars has not grown a member nobody wrote an example for. +func TestEachAgendaGrammarStillMatchesItsOwnExample(t *testing.T) { + examples := map[string]string{ + "calendar-query": "что в календаре на завтра", + "agenda-query": "что у меня сегодня", + "plan-day-query": "какие планы на завтра", + "rest-of-day-query": "что дальше?", + "event-time-query": "когда планёрка", + } + for _, g := range AgendaQueryGrammars() { + u, ok := examples[g.Name] + if !ok { + t.Errorf("agenda grammar %q has no example here — add one", g.Name) + continue + } + if !g.Pattern.MatchString(u) { + t.Errorf("grammar %q no longer matches %q", g.Name, u) + } + } +}