| 1 | package memoriatest |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "testing" |
| 6 | |
| 7 | "amadan.net/oficina/memoria/internal/memoria/notion" |
| 8 | ) |
| 9 | |
| 10 | // TestContainersAreNotCountedAsPages. |
| 11 | // |
| 12 | // A data source is a container, not a document. Ledgering one gave it a |
| 13 | // row that stayed "pending" forever, counted it in the run's total, and |
| 14 | // counted it as "already up to date" on every later run — so the status |
| 15 | // page said "1 of 2 known pages imported" permanently, about a workspace |
| 16 | // that was completely imported. A number that can never reach its own |
| 17 | // denominator is the same lie as a confident zero, told the other way up. |
| 18 | // |
| 19 | // Found by a code review. |
| 20 | // |
| 21 | // MUTATION-TESTED 2026-09-05: removing the container guard around |
| 22 | // SeeSourcePage in Syncer.walk makes this fail with 1 of 2. Reverted. |
| 23 | func TestContainersAreNotCountedAsPages(t *testing.T) { |
| 24 | src := newSource() |
| 25 | src.roots = append(src.roots, notion.Ref{ |
| 26 | ID: "db1", Title: "Projects", EditedTime: "t1", |
| 27 | Kind: notion.KindDataSource, DataSourceID: "db1", |
| 28 | }) |
| 29 | src.children["db1"] = []notion.Ref{{ |
| 30 | ID: "row1", Title: "Project Bluebird", Path: []string{"Projects"}, |
| 31 | EditedTime: "t1", Kind: notion.KindPage, |
| 32 | }} |
| 33 | src.bodies["row1"] = "Status: Shipped. The deal closed in March." |
| 34 | |
| 35 | h, app, cid, _ := connectorApp(t, src) |
| 36 | sync(t, h, app, cid) |
| 37 | sync(t, h, app, cid) |
| 38 | |
| 39 | total, imported, err := app.Store().CountPages(context.Background(), cid) |
| 40 | if err != nil { |
| 41 | t.Fatal(err) |
| 42 | } |
| 43 | if total != imported { |
| 44 | t.Errorf("%d of %d imported: a container is sitting in the ledger as a page that "+ |
| 45 | "can never import, so this number can never reach its own denominator", |
| 46 | imported, total) |
| 47 | } |
| 48 | if total != 1 { |
| 49 | t.Errorf("ledger holds %d rows, want 1 — the row, not the database", total) |
| 50 | } |
| 51 | } |
| 52 | |