package router import ( "strings" "testing" ) // routeGrammar carried the same unbounded `ws ::= [ \t\n]*` the phrasing // grammar did (Vikunja #531). It never ran away in practice because this path // sends routeRepeatPenalty and the phrasing path sent nothing — an accident, // not a defence. The bound is the defence. // // Unlike responseGrammar this grammar does have one legitimate unbounded // repetition: `("," ws action)*` in root, because a compound utterance is any // number of actions and capping it would silently drop the last ask. That one // is bounded in practice by MaxTokens and by each action being fixed-shape. // Whitespace has no such excuse. func TestRouteGrammarWhitespaceIsBounded(t *testing.T) { if !strings.Contains(routeGrammar, `ws ::= [ \t\n]{0,4}`) { t.Errorf("the ws rule is not bounded — an unbounded one lets the model emit whitespace to the token cap:\n%s", routeGrammar) } if strings.Contains(routeGrammar, `[ \t\n]*`) { t.Error("routeGrammar still contains an unbounded whitespace repetition") } } // The penalty stays. It curbs the in-field repetition loop the bound cannot // reach — a model repeating whole words inside a string rule is still inside // the grammar — and removing it because the grammar is now bounded would be // reading this fix as broader than it is. func TestRouterStillSendsARepeatPenalty(t *testing.T) { if routeRepeatPenalty <= 1.0 { t.Errorf("routeRepeatPenalty is %v, which is no penalty at all", routeRepeatPenalty) } }