oficina / memoria Public

Clone
git clone https://amadan.net/oficina/memoria

Plain git — no account needed to clone.

Download

Download this file

1package memoria
2
3import (
4 "context"
5 "reflect"
6 "testing"
7 "time"
8
9 "amadan.net/oficina/memoria/internal/memoria/fact"
10)
11
12// The front page's "Try" line: searches built from the documents' own
13// labels and the people they mention, from memoria's own documents only.
14//
15// MUTATION-TESTED 2026-10-30, each reverted: sibling documents not
16// skipped → "a sibling's words"; the kind word not added → "office";
17// labels not merged → "merged"; a person counted from their own document
18// → "only mentioned by itself"; the TTL check removed → "cached"; one
19// suggestion per document rather than per name → "who is Bill Horsman"
20// twice (Paul's screenshot, 2026-10-31).
21func TestTryIsBuiltFromTheDocuments(t *testing.T) {
22 ctx := context.Background()
23 s := storeForTest(t)
24 for _, d := range []IngestSpec{
25 {Source: "upload", Key: "o", Title: "Office", Body: "## Contact\n\nOffice: +353 (0)1 547 7854"},
26 {Source: "upload", Key: "r", Title: "Reception notes", Body: "## Phones\n\nOffice phone number: +353 (0)1 547 7854"},
27 {Source: "upload", Key: "b", Title: "Bill Horsman", Body: "Membership Type: Member"},
28 {Source: "upload", Key: "m", Title: "Board notes", Body: "Bill Horsman to circulate the minutes."},
29 {Source: "upload", Key: "x", Title: "Ann Lone", Body: "Nobody else mentions Ann."},
30 // A second document with the same name: still one suggestion.
31 {Source: "upload", Key: "b2", Title: "Bill Horsman", Body: "Profile: on the board since 2019."},
32 } {
33 if _, err := s.Ingest(ctx, d); err != nil {
34 t.Fatal(err)
35 }
36 }
37 // A sibling app's document: its words must not become a suggestion.
38 if _, err := s.Ingest(ctx, IngestSpec{Source: "Docs", Key: "s", Title: "Secret plan", Body: "Secret line: +353 (0)1 547 0000",
39 ItemID: "s", SiblingRevision: 1}); err != nil {
40 t.Fatal(err)
41 }
42 clock := time.Unix(1_800_000_000, 0)
43 s.try.now = func() time.Time { return clock }
44 got := s.Try(ctx)
45 want := []string{"office phone", "who is Bill Horsman"}
46 if !reflect.DeepEqual(got, want) {
47 t.Fatalf("Try = %q, want %q (merged; office; only mentioned by itself; a sibling's words)", got, want)
48 }
49
50 // Reused within the TTL, worked out again after it.
51 if _, err := s.Ingest(ctx, IngestSpec{Source: "upload", Key: "v", Title: "Invoices", Body: "VAT number: IE3384527RH"}); err != nil {
52 t.Fatal(err)
53 }
54 if got := s.Try(ctx); !reflect.DeepEqual(got, want) {
55 t.Errorf("cached: within the TTL Try changed to %q", got)
56 }
57 clock = clock.Add(TryTTL)
58 if got := s.Try(ctx); len(got) != 3 {
59 t.Errorf("after the TTL Try = %q, want the VAT number added", got)
60 }
61}
62
63func TestSearchFor(t *testing.T) {
64 for _, c := range []struct {
65 label string
66 k fact.Kind
67 want string
68 }{
69 {"Office", fact.Phone, "office phone"},
70 {"The office phone number is", fact.Phone, "office phone number"},
71 {"Eircode", fact.Eircode, "eircode"},
72 {"Reception", fact.Email, "reception email"},
73 {"VAT", fact.VAT, "vat"},
74 {"Our long label that is a whole sentence here", fact.Phone, ""},
75 } {
76 if got := searchFor(c.label, c.k); got != c.want {
77 t.Errorf("searchFor(%q, %s) = %q, want %q", c.label, c.k, got, c.want)
78 }
79 }
80}
81