package memoriatest import ( "html" "strings" "testing" ) // The typeahead (§8.14), through the real route: the box's one checked // answer and the documents, never a best guess and never §8.9's model // step. Until Fable's review (2026-11-02) its only coverage was a browser // test and the team lapse test, so `make ci` could not see either rule. // // MUTATION-TESTED 2026-11-02, each seen red and reverted: the `Guess == // nil` condition dropped → "a best guess"; /suggest calling Search for // SearchWhileTyping → "the model was called". func TestTheTypeaheadNeverGuessesOrCallsTheModel(t *testing.T) { m := &countingModel{} h, _ := appWithModel(t, m) store(t, h, "Reception", "## Front desk\n\nOffice phone: +353 (0)1 547 9999") store(t, h, "Contacts", "## Phones\n\nReception: +353 (0)1 547 0001\n\nSales: +353 (0)1 547 0002\n\nFax: +353 (0)1 547 0003\n\nSupport: +353 (0)1 547 0004") // The presence half: a checked answer is the answer row. one := get(t, h, "/suggest?q=office+phone") if b := html.UnescapeString(one.Body.String()); one.Code != 200 || !strings.Contains(b, "rst-suggest-fact") || !strings.Contains(b, "547 9999") { t.Fatalf("a checked answer is not the typeahead's answer row (%d):\n%s", one.Code, b) } // Four phones and nothing to choose between them: the results page's // best guess, never the typeahead's answer. rec := get(t, h, "/suggest?q=phone+number") b := html.UnescapeString(rec.Body.String()) if strings.Contains(b, "rst-suggest-fact") { t.Errorf("the typeahead shows a best guess as its answer:\n%s", b) } if !strings.Contains(get(t, h, "/?q=phone+number").Body.String(), "rst-fact-guess") { t.Fatal("the results page makes no guess here, so the absence above proves nothing") } before := m.calls get(t, h, "/suggest?q=office+address") if m.calls != before { t.Errorf("the model was called %d times by a keystroke; the typeahead never runs §8.9", m.calls-before) } }