oficina / mapa Public

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

Plain git — no account needed to clone.

Download

Download this file

1package mapa
2
3import (
4 "testing"
5)
6
7// I18, provenance (Notion import spec §14.2). Every verb on an imported
8// page (commit, rename, revert, restore, relink, mark) clears imported
9// and keeps origin.
10//
11// Mutation (make mutate, first red 2026-11-17): tx.commit keeps
12// imported for every caller.
13func TestI18VerbsClearImportedAndKeepOrigin(t *testing.T) {
14 verbs := map[string]func(*importWorld, Page) error{
15 "commit": func(world *importWorld, page Page) error {
16 _, err := world.store.Commit(ctx(), bo, page.ID, page.Revision,
17 "Bo's words.")
18 return err
19 },
20 "rename": func(world *importWorld, page Page) error {
21 return world.store.Rename(ctx(), bo, page.ID, "Renamed")
22 },
23 "mark": func(world *importWorld, page Page) error {
24 _, err := world.store.MarkBlock(ctx(), bo, page.ID, 0)
25 return err
26 },
27 "revert": func(world *importWorld, page Page) error {
28 if _, err := world.store.Commit(ctx(), bo, page.ID,
29 page.Revision, "Bo's words."); err != nil {
30 return err
31 }
32 return world.store.Revert(ctx(), bo, page.ID, page.Revision)
33 },
34 "relink": func(world *importWorld, page Page) error {
35 if err := world.store.Rename(ctx(), bo, page.ID,
36 "HB"); err != nil {
37 return err
38 }
39 equipment, _, _ := world.pageTitled("Equipment")
40 _, err := world.store.UpdateLinks(ctx(), bo, page.ID,
41 []int64{equipment.ID})
42 return err
43 },
44 "restore": func(world *importWorld, page Page) error {
45 if err := world.store.Delete(ctx(), bo, page.ID); err != nil {
46 return err
47 }
48 _, err := world.store.Restore(ctx(), bo, page.ID, "Restored")
49 return err
50 },
51 }
52 for name, verb := range verbs {
53 t.Run(name, func(t *testing.T) {
54 world := newImportWorld(t, newSmall().Workspace)
55 world.connect(ana)
56 world.importAs(ana)
57 page, record, _ := world.pageTitled("Handbook")
58 if !record.Imported || record.Origin == nil {
59 t.Fatalf("an imported page's record: %+v", record)
60 }
61 if err := verb(world, page); err != nil {
62 t.Fatalf("%s: %v", name, err)
63 }
64 world.checkProvenance(name)
65 })
66 }
67}
68
69// checkProvenance is every live page's newest record: not imported if
70// a verb wrote it, and still from Notion.
71func (world *importWorld) checkProvenance(name string) {
72 world.t.Helper()
73 var event Event
74 world.store.database.Where("object_kind = ?", ObjectPage).
75 Order("id DESC").First(&event)
76 var page Page
77 world.store.database.Where("id = ?", event.ObjectID).First(&page)
78 record, err := world.store.OpenPage(page)
79 if err != nil {
80 world.t.Fatal(err)
81 }
82 if record.Imported || record.Origin == nil ||
83 record.Origin.Source != "notion" {
84 world.t.Errorf("after %s: imported %v, origin %+v", name,
85 record.Imported, record.Origin)
86 }
87}
88