| 1 | package main |
| 2 | |
| 3 | // The Notion import's files and gates. |
| 4 | const ( |
| 5 | importStore = "internal/mapa/import_store.go" |
| 6 | importWrite = "internal/mapa/import_write.go" |
| 7 | importTitles = "internal/mapa/import_titles.go" |
| 8 | importSet = "internal/mapa/import_set.go" |
| 9 | importReport = "internal/mapa/import_report.go" |
| 10 | importLedger = "internal/mapa/import_ledger.go" |
| 11 | importSurvey = "internal/mapa/import_survey.go" |
| 12 | importBook = "internal/mapa/import_book.go" |
| 13 | importView = "internal/mapa/import_view.go" |
| 14 | importGuard = "internal/mapa/import_handlers.go" |
| 15 | importJob = "internal/mapa/import_job.go" |
| 16 | importImages = "internal/mapa/import_images.go" |
| 17 | importPlace = "internal/mapa/import_images_place.go" |
| 18 | importCredential = "internal/mapa/import_credential.go" |
| 19 | importRetention = "internal/mapa/import_retention.go" |
| 20 | pagesFile = "internal/mapa/pages.go" |
| 21 | handlersPages = "internal/mapa/handlers_pages.go" |
| 22 | notionmdTree = "internal/mapa/notionmd/render.go" |
| 23 | mapaPackage = "./internal/mapa/" |
| 24 | ) |
| 25 | |
| 26 | // inMapa is a mutation whose gate is in package mapa. |
| 27 | func inMapa(gate, name, test string, edits ...edit) mutation { |
| 28 | return mutation{gate: gate, name: name, test: test, edits: edits, |
| 29 | pkg: mapaPackage} |
| 30 | } |
| 31 | |
| 32 | // importMutations break the Notion import's gates (Notion import spec |
| 33 | // §18: I2 to I19), one at a time. I1's are the mapper's |
| 34 | // (mutations_mapper.go). I14 waits for images. I16 has none: it can go |
| 35 | // red only if the module gains a write, which M4 forbids. |
| 36 | var importMutations = []mutation{ |
| 37 | inMapa("I2", "an unchanged page committed again", "TestI2ARerun", |
| 38 | edit{importWrite, "\tif entry.current.Title == entry.title &&", |
| 39 | "\tif false && entry.current.Title == entry.title &&"}, |
| 40 | edit{importStore, "\tif record.Body == body {", "\tif false {"}), |
| 41 | // I3 removes both checks; each is also held alone, the store's by |
| 42 | // M3's gates, the run's by M2's (round 2: the note that once said |
| 43 | // the run's could not be held alone was wrong; a kept page's title |
| 44 | // and a kept page's images both depend on it). |
| 45 | inMapa("I3", "any live page read as untouched, run and store", "TestI3", |
| 46 | edit{importTitles, |
| 47 | "return entry.live && entry.revision == entry.place.Revision", |
| 48 | "return entry.live"}, |
| 49 | edit{importStore, "\t\tpage.Revision != write.expect {", |
| 50 | "\t\tfalse {"}), |
| 51 | inMapa("I4", "absence counted before the survey is complete", "TestI4", |
| 52 | edit{importReport, |
| 53 | "if !entry.place.mapped(entry.row) || !tally.view.SurveyDone {", |
| 54 | "if !entry.place.mapped(entry.row) {"}), |
| 55 | inMapa("I5", "a link to a page's Notion title, not its planned one", |
| 56 | "TestI5", edit{importSet, "return entry.title, notionmd.Live", |
| 57 | "return plainRuns(entry.staged.Title), notionmd.Live"}), |
| 58 | inMapa("I6", "a candidate leaves no room for its suffix", "TestI6", |
| 59 | edit{importTitles, |
| 60 | "room := maxTitle - utf8.RuneCountInString(suffix)", |
| 61 | "room := maxTitle + 0*utf8.RuneCountInString(suffix)"}), |
| 62 | inMapa("H1", "the candidates bounded at 64", "TestI6Seventy", |
| 63 | edit{importTitles, "\tfor index := skip; ; index++ {", |
| 64 | "\tfor index := skip; index < 64; index++ {"}, |
| 65 | edit{importTitles, "\t\t\treturn candidate, err\n\t\t}\n\t}\n}", |
| 66 | "\t\t\treturn candidate, err\n\t\t}\n\t}\n" + |
| 67 | "\treturn \"\", errors.New(\"bounded\")\n}"}), |
| 68 | inMapa("L4", "a page deleted in Mapa holds its title", "TestI6ADeleted", |
| 69 | edit{importTitles, |
| 70 | "\t\tif entry.place.mapped(entry.row) && !entry.live {", |
| 71 | "\t\tif false {"}), |
| 72 | inMapa("I7", "ImportUpdate names the page's owner", "TestI7", |
| 73 | edit{importStore, |
| 74 | "if page, record, err = tx.importable(write); err != nil {\n" + |
| 75 | "\t\t\treturn err\n\t\t}", |
| 76 | "if page, record, err = tx.importable(write); err != nil {\n" + |
| 77 | "\t\t\treturn err\n\t\t}\n\t\tactor = page.OwnerID"}), |
| 78 | inMapa("I7", "ImportCreate names the connection's creator", "TestI7", |
| 79 | edit{importStore, "\t\torigin := write.origin\n\t\tpage, err =", |
| 80 | "\t\tif held, ok, _ := connection(tx.db); ok {\n" + |
| 81 | "\t\t\tactor = held.CreatedBy\n\t\t}\n" + |
| 82 | "\t\torigin := write.origin\n\t\tpage, err ="}), |
| 83 | {gate: "I8", name: "an http.Get in a handler", copy: true, |
| 84 | test: "TestI8", edits: []edit{{handlersPages, |
| 85 | "// seeOther ends a POST that worked.", |
| 86 | "var _ = http.Get\n\n// seeOther ends a POST that worked."}}}, |
| 87 | {gate: "I8", name: "the module imported from notionmd", copy: true, |
| 88 | test: "TestI8", edits: []edit{{notionmdTree, |
| 89 | "import (\n\t\"context\"", |
| 90 | "import (\n\t_ \"amadan.net/oficina/notion.git/notion\"\n" + |
| 91 | "\t\"context\""}}}, |
| 92 | {gate: "I9", name: "the staged tree written unsealed", test: "TestI9", |
| 93 | edits: []edit{{importLedger, |
| 94 | "return store.sealer.Seal(seal.PurposeNotionStaged, plain)", |
| 95 | "return plain, nil"}}}, |
| 96 | inMapa("I10", "a staged page's title logged", "TestI10", |
| 97 | edit{importSurvey, |
| 98 | "staged := stagedPage(page, blocks, ref.Parent, seq)", |
| 99 | "staged := stagedPage(page, blocks, ref.Parent, seq)\n" + |
| 100 | "\tjob.logger.Info(\"staged\", \"title\", " + |
| 101 | "plainRuns(staged.Title))"}), |
| 102 | {gate: "I11", name: "the token's tail shown beside the workspace", |
| 103 | test: "TestI11", edits: []edit{{importView, |
| 104 | "data.Workspace = app.workspaceName(row)", |
| 105 | "token, _ := app.store.token(request.Context())\n" + |
| 106 | "\t\tdata.Workspace = app.workspaceName(row) + " + |
| 107 | "token[len(token)-8:]"}}}, |
| 108 | inMapa("I12", "a resumed survey reads every page again", |
| 109 | "TestI12ResumeContinuesTheSurvey", edit{importSurvey, |
| 110 | "if row.SurveyedRun == job.lease.run {", "if false {"}), |
| 111 | inMapa("I12", "a write by a run whose lease moved", |
| 112 | "TestI12StopRefusesTheOldGoroutine", edit{importBook, |
| 113 | "if held.RowsAffected != 1 {", "if false {"}), |
| 114 | {gate: "I13", name: "every member let through", test: "TestI13", |
| 115 | edits: []edit{{importGuard, "if !app.config.Importer(address) {", |
| 116 | "if !app.config.Importer(address) && false {"}}}, |
| 117 | inMapa("I17", "ImportCreate leaves its map row to a later write", |
| 118 | "TestI17ACrash", edit{importStore, |
| 119 | "return tx.placeRow(write, page, mapCreated)", "return nil"}), |
| 120 | {gate: "I17", name: "a handler calls ImportCreate", copy: true, |
| 121 | pkg: mapaPackage, test: "TestI17OnlyTheRunWritesImports", |
| 122 | edits: []edit{{handlersPages, |
| 123 | "// seeOther ends a POST that worked.", |
| 124 | "var _ = (*Store).ImportCreate\n\n" + |
| 125 | "// seeOther ends a POST that worked."}}}, |
| 126 | inMapa("I18", "tx.commit keeps imported for every caller", "TestI18", |
| 127 | edit{pagesFile, |
| 128 | "record.Imported = record.Imported && tx.importing", |
| 129 | "_ = tx.importing"}), |
| 130 | inMapa("I19", "the bookkeeping fence checks no table", |
| 131 | "TestI19BookkeepingIsFenced", edit{importBook, |
| 132 | "if !strings.HasPrefix(table, \"notion_\") {", "if false {"}), |
| 133 | inMapa("M3", "ImportUpdate's revision check alone removed", |
| 134 | "TestM3ASaveMidRunIsKept", edit{importStore, |
| 135 | "\t\tpage.Revision != write.expect {", "\t\tfalse {"}), |
| 136 | inMapa("M3", "ImportUpdate's gone check alone removed", |
| 137 | "TestM3ADeleteMidRunIsNotWritten", edit{importStore, |
| 138 | "if err != nil || page.Gone || page.Kind", |
| 139 | "if err != nil || page.Kind"}), |
| 140 | // The deleted page is decided in early() now, before anything is |
| 141 | // rendered (L15), so sending it to create means both: early lets it |
| 142 | // through, and commit takes "not live" for "not mapped". |
| 143 | inMapa("M3", "a page deleted in Mapa sent to create", |
| 144 | "TestM3ADeletedPageIsNotRecreated", |
| 145 | edit{importWrite, "\tcase !entry.live:\n\t\treturn mapGone\n", ""}, |
| 146 | edit{importWrite, "\tif !entry.place.mapped(entry.row) {\n" + |
| 147 | "\t\treturn job.create(", |
| 148 | "\tif !entry.live {\n\t\treturn job.create("}), |
| 149 | inMapa("M4", "ImportUpdate without the lease", |
| 150 | "TestM4EveryRunWriteHoldsTheLease", edit{importStore, |
| 151 | "\t\tif err := holdLease(tx.db, write.lease); err != nil {\n" + |
| 152 | "\t\t\treturn err\n\t\t}\n" + |
| 153 | "\t\tactor, err := tx.member(write.who)\n" + |
| 154 | "\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n" + |
| 155 | "\t\tvar record Record", |
| 156 | "\t\tactor, err := tx.member(write.who)\n" + |
| 157 | "\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n" + |
| 158 | "\t\tvar record Record"}), |
| 159 | inMapa("M4", "staging without the lease", |
| 160 | "TestM4EveryRunWriteHoldsTheLease", edit{importSurvey, |
| 161 | "bookkeep(ctx, job.lease, func(db *gorm.DB) error {\n" + |
| 162 | "\t\trow.State, row.ErrorCode, row.SurveyedRun = mapStaged", |
| 163 | "bookkeep(ctx, runLease{}, func(db *gorm.DB) error {\n" + |
| 164 | "\t\trow.State, row.ErrorCode, row.SurveyedRun = mapStaged"}), |
| 165 | inMapa("M4", "an outcome without the lease", |
| 166 | "TestM4EveryRunWriteHoldsTheLease", edit{importWrite, |
| 167 | "bookkeep(ctx, job.lease, func(db *gorm.DB) error {\n" + |
| 168 | "\t\tif err := job.recordOutcome", |
| 169 | "bookkeep(ctx, runLease{}, func(db *gorm.DB) error {\n" + |
| 170 | "\t\tif err := job.recordOutcome"}), |
| 171 | inMapa("M4", "the run's end without the lease", |
| 172 | "TestM4EveryRunWriteHoldsTheLease", edit{importJob, |
| 173 | "bookkeep(ctx, job.lease, func(db *gorm.DB) error {\n" + |
| 174 | "\t\terr := db.Model(&NotionPage{})", |
| 175 | "bookkeep(ctx, runLease{}, func(db *gorm.DB) error {\n" + |
| 176 | "\t\terr := db.Model(&NotionPage{})"}), |
| 177 | inMapa("M4", "a new token leaves resumable runs", |
| 178 | "TestM4ANewTokenEndsAResumableRun", edit{importCredential, |
| 179 | "\t\t\tif err := tx.endResumable(runDisconnected); " + |
| 180 | "err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n" + |
| 181 | "\t\treturn tx.saveConnection", |
| 182 | "\t\t}\n\t\treturn tx.saveConnection"}), |
| 183 | inMapa("M4", "the heartbeat carries on without its lease", |
| 184 | "TestM4TheHeartbeatStops", edit{importJob, |
| 185 | "\t\t\t\tstop()\n\t\t\t\treturn\n", |
| 186 | "\t\t\t\tcontinue\n"}), |
| 187 | inMapa("M5", "no connection ever idle", "TestM5AnIdleToken", |
| 188 | edit{importRetention, |
| 189 | "return now.Sub(last) >= IdleTokenWindow", |
| 190 | "return false && now.Sub(last) >= IdleTokenWindow"}), |
| 191 | inMapa("M6", "Forget leaves the connection", "TestM6ForgetDeletes", |
| 192 | edit{importCredential, |
| 193 | "err = tx.db.Where(\"1 = 1\").Delete(&NotionConnection{}).Error", |
| 194 | "err = nil"}), |
| 195 | inMapa("L5", "a page with no planned title answered live", "TestL5", |
| 196 | edit{importSet, |
| 197 | "\t\tif entry.row.State == mapFailed || entry.title == \"\" ||\n" + |
| 198 | "\t\t\t(entry.place.mapped(entry.row) && !entry.live) {\n" + |
| 199 | "\t\t\treturn \"\", notionmd.Dead\n\t\t}\n" + |
| 200 | "\t\treturn entry.title, notionmd.Live", |
| 201 | "\t\tif entry.row.State == mapFailed {\n" + |
| 202 | "\t\t\treturn \"\", notionmd.Dead\n\t\t}\n" + |
| 203 | "\t\treturn firstOf(entry.title, " + |
| 204 | "plainRuns(entry.staged.Title)), notionmd.Live"}), |
| 205 | // The check's marker clause: Low3 in mutations_mapper.go. |
| 206 | inMapa("L6", "the fix-up writes a created page as updated", "TestL6", |
| 207 | edit{importJob, "\twrite.state = entry.row.State\n", "\n"}), |
| 208 | inMapa("L7", "a rename collision fails the page", "TestL7", |
| 209 | edit{importWrite, "if code != \"title_taken\" || attempt > 8 {", |
| 210 | "if true {"}), |
| 211 | inMapa("L8", "a failed launch leaves the run", "TestL8", |
| 212 | edit{importJob, |
| 213 | "\t\t_ = app.store.endRun(context.Background(), lease, " + |
| 214 | "runFailed,\n\t\t\trunInternal)", |
| 215 | "\t\t_ = lease"}), |
| 216 | inMapa("L9", "a finished row decided unstaged keeps its page", "TestL9", |
| 217 | edit{importSurvey, "\tif row.State == mapFinished {\n" + |
| 218 | "\t\t// A finished import's page that this import cannot read", |
| 219 | "\tif false {\n\t\t// A finished import's page " + |
| 220 | "that this import cannot read"}), |
| 221 | {gate: "L12", name: "an aliased net/http Get in a handler", copy: true, |
| 222 | test: "TestI8MapaHasNoEgressOfItsOwn", edits: []edit{ |
| 223 | {handlersPages, "\t\"net/http\"\n\t\"strconv\"", |
| 224 | "\t\"net/http\"\n\tweb \"net/http\"\n\t\"strconv\""}, |
| 225 | {handlersPages, "// seeOther ends a POST that worked.", |
| 226 | "var _ = web.Get\n\n// seeOther ends a POST that worked."}}}, |
| 227 | {gate: "L12", name: "os/exec in a handler", copy: true, |
| 228 | test: "TestI8MapaHasNoEgressOfItsOwn", edits: []edit{ |
| 229 | {handlersPages, "\t\"net/http\"\n\t\"strconv\"", |
| 230 | "\t\"net/http\"\n\t\"os/exec\"\n\t\"strconv\""}, |
| 231 | {handlersPages, "// seeOther ends a POST that worked.", |
| 232 | "var _ = exec.Command\n\n" + |
| 233 | "// seeOther ends a POST that worked."}}}, |
| 234 | {gate: "L12", name: "a DNS lookup in config", copy: true, |
| 235 | test: "TestI8MapaHasNoEgressOfItsOwn", edits: []edit{ |
| 236 | {"internal/mapa/config.go", "func isLocal(origin string) bool {", |
| 237 | "var _ = net.LookupHost\n\n" + |
| 238 | "func isLocal(origin string) bool {"}}}, |
| 239 | inMapa("L11", "History ignores imported", "TestL11", |
| 240 | edit{"internal/mapa/import_history.go", |
| 241 | "if err != nil || !record.Imported {", |
| 242 | "if err != nil || true {"}), |
| 243 | inMapa("M2", "untouched alone reads any live page as untouched", |
| 244 | "TestM2AKeptPageKeepsItsTitleForLinks", edit{importTitles, |
| 245 | "return entry.live && entry.revision == entry.place.Revision", |
| 246 | "return entry.live"}), |
| 247 | inMapa("M2", "a kept page not decided before its images", "TestL15", |
| 248 | edit{importWrite, "\tcase !untouched(entry):\n" + |
| 249 | "\t\tentry.place.Kept = job.keptReason(ctx, entry.place.PageID)\n" + |
| 250 | "\t\treturn mapKept\n", ""}), |
| 251 | inMapa("M1", "a page's render runs without its budget", |
| 252 | "TestM1ASlowPageFailsAlone", edit{importWrite, |
| 253 | "renderCtx, cancel := context.WithTimeout(ctx,\n" + |
| 254 | "\t\trenderBudgetFor(entry.staged))", |
| 255 | "renderCtx, cancel := context.WithCancel(ctx)"}), |
| 256 | inMapa("Low4", "a page found gone stays live", |
| 257 | "TestLowADeleteMidRunIsGoneForLaterPages", edit{importWrite, |
| 258 | "\t\t\tentry.live = false\n", "\n"}), |
| 259 | inMapa("Low6", "a page refused for being gone reported kept", |
| 260 | "TestLowADeleteMidRunIsGoneForLaterPages", edit{importWrite, |
| 261 | "\t\t\tentry.live = false\n\t\t\treturn mapGone, \"\", nil", |
| 262 | "\t\t\tentry.live = false\n\t\t\treturn mapKept, \"\", nil"}), |
| 263 | inMapa("Low6", "Forget leaves resumable runs", |
| 264 | "TestLowForgetEndsAResumableRun", edit{importCredential, |
| 265 | "\t\tif err := tx.endResumable(runForgotten); err != nil {", |
| 266 | "\t\tif err := error(nil); err != nil {"}), |
| 267 | inMapa("Low6", "idle ignores runs", "TestLowARecentRunKeepsTheToken", |
| 268 | edit{importRetention, |
| 269 | "if run, found, err := latestRun(database); err == nil && found {", |
| 270 | "if run, found, err := latestRun(database); err == nil && " + |
| 271 | "found && false {"}), |
| 272 | inMapa("I14", "ImportCreate commits with attachNothing", |
| 273 | "TestI14AnImageIsAddedAndAttached", edit{importStore, |
| 274 | "actor, VerbCreated, attachOwn(0))", |
| 275 | "actor, VerbCreated, attachNothing)"}), |
| 276 | inMapa("I14", "ImportUpdate's edited revision attaches nothing", |
| 277 | "TestI14AnImageGoneOrChangedIsFetchedAgain", edit{importStore, |
| 278 | "VerbEdited, attachOwn(0))", "VerbEdited, attachNothing)"}), |
| 279 | inMapa("I14", "reuse skips the Held check", |
| 280 | "TestI14AnImageGoneOrChangedIsFetchedAgain", edit{importImages, |
| 281 | "job.images.Held(ctx, prior.PublicID, entry.place.PageID) {", |
| 282 | "true {"}), |
| 283 | inMapa("I14", "reuse ignores the file's key", |
| 284 | "TestI14AnImageGoneOrChangedIsFetchedAgain", edit{importImages, |
| 285 | "if found && sameFile(prior.Key, placed.key) {", "if found {"}), |
| 286 | // What comparing the minute-rounded edit time did, for a file |
| 287 | // replaced in that minute (§25 note 17). |
| 288 | inMapa("I14", "reuse ignores the file's key, the same minute", |
| 289 | "TestI14AnImageReplacedInTheSameMinuteIsFetched", edit{importImages, |
| 290 | "if found && sameFile(prior.Key, placed.key) {", "if found {"}), |
| 291 | inMapa("I14", "a permanent refusal outlives its file", |
| 292 | "TestI14ARefusalIsALineAndRemembered", edit{importImages, |
| 293 | "if found && sameFile(prior.Key, placed.key) {", "if found {"}), |
| 294 | inMapa("I14", "the key kept is the staged file's", |
| 295 | "TestI14AFileReplacedMidRunIsKeyedAsDownloaded", edit{importImages, |
| 296 | "\t\tplaced.key = fetched\n", "\t\t_ = fetched\n"}), |
| 297 | // Fable M1: the fake signs every read afresh, as Notion does, so a |
| 298 | // key that keeps the signature fetches every image on every run. |
| 299 | inMapa("I14", "the file key is the signed URL", |
| 300 | "TestI14AnImageIsAddedAndAttached", edit{importImages, |
| 301 | "key: notion.FileKey(block.File.URL),", |
| 302 | "key: block.File.URL,"}, |
| 303 | edit{importImages, "\tkey := notion.FileKey(fresh.File.URL)\n", |
| 304 | "\tkey := fresh.File.URL\n"}), |
| 305 | inMapa("I14", "an empty file key matches", |
| 306 | "TestAnEmptyFileKeyMatchesNothing", edit{importImages, |
| 307 | "return kept != \"\" && kept == now", "return kept == now"}), |
| 308 | inMapa("I2", "an unchanged Notion edit time read as an unchanged page", |
| 309 | "TestI2AnEditInTheSameMinuteIsPickedUp", edit{importWrite, |
| 310 | "\tif entry.current.Title == entry.title &&\n", |
| 311 | "\tif entry.current.Origin != nil &&\n" + |
| 312 | "\t\tentry.current.Origin.Edited == entry.staged.Edited ||\n" + |
| 313 | "\t\tentry.current.Title == entry.title &&\n"}), |
| 314 | inMapa("I14", "no copy is tried", "TestI14ABlockOnASecondPageIsCopied", |
| 315 | edit{importImages, |
| 316 | "if added, ok := job.copyImage(ctx, entry, block); ok {", |
| 317 | "if added, ok := job.copyImage(ctx, entry, block); ok && false {"}), |
| 318 | inMapa("I14", "a permanent refusal not remembered", |
| 319 | "TestI14ARefusalIsALineAndRemembered", edit{ |
| 320 | "internal/mapa/import_images_place.go", |
| 321 | "\tcase placed.permanent:", "\tcase false:"}), |
| 322 | inMapa("I14", "a quota refusal does not stop downloads", |
| 323 | "TestI14TheFirstQuotaRefusalStopsDownloads", edit{importImages, |
| 324 | "\t\tjob.imagesStopped = quotaReason(err)\n" + |
| 325 | "\t\treturn refusal{text: job.imagesStopped}", |
| 326 | "\t\treturn refusal{text: quotaReason(err)}"}), |
| 327 | inMapa("I14", "a kept page's images left pending", |
| 328 | "TestI14ANotWrittenPagesImagesGoAtOnce", edit{importWrite, |
| 329 | "if state == mapKept || state == mapFailed || state == mapGone {", |
| 330 | "if state == mapFailed || state == mapGone {"}), |
| 331 | inMapa("Low5", "a deleted page's images left pending", |
| 332 | "TestI14ANotWrittenPagesImagesGoAtOnce", edit{importWrite, |
| 333 | "if state == mapKept || state == mapFailed || state == mapGone {", |
| 334 | "if state == mapKept || state == mapFailed {"}), |
| 335 | inMapa("Low5", "the fix-up renders with no image lines", |
| 336 | "TestLow5TheFixUpKeepsImagesAfterAResume", edit{importJob, |
| 337 | "\t\timages = storedImages(entry)", "\t\timages = &pageImages{}"}), |
| 338 | inMapa("R3M2", "a copy ignores the file's key", |
| 339 | "TestI14AChangedSharedImageIsFetchedOnce", edit{importPlace, |
| 340 | "other.Page == 0 || !sameFile(other.Key, key) ||", |
| 341 | "other.Page == 0 || !sameFile(key, key) ||"}), |
| 342 | inMapa("R3M3", "Forget leaves notion_images", "TestM6ForgetDeletes", |
| 343 | edit{importCredential, |
| 344 | "err = tx.db.Where(\"1 = 1\").Delete(&NotionImage{}).Error", |
| 345 | "err = nil"}), |
| 346 | inMapa("R3L1", "placeRow keeps no image places", |
| 347 | "TestL1ACrashAfterTheWriteKeepsImagePlaces", edit{importStore, |
| 348 | "return keepPlaces(tx.db, tx.store, page.ID, write.images)", |
| 349 | "return nil"}), |
| 350 | inMapa("R3L2", "a block twice on a page is two images", |
| 351 | "TestL2ABlockTwiceOnAPageIsOneImage", edit{importImages, |
| 352 | "if _, done := prepared.lines[block.ID]; done {", |
| 353 | "if _, done := prepared.lines[block.ID]; done && false {"}), |
| 354 | inMapa("R3L3", "a kept page carries its old image counts", |
| 355 | "TestL3TheStopIsThisRuns", edit{importWrite, |
| 356 | "\t\tentry.place.Images = nil\n", "\n"}), |
| 357 | inMapa("R3L5", "a refused host remembered as permanent", |
| 358 | "TestL5ARefusedHostIsTriedAgain", edit{importImages, |
| 359 | "permanent: notion.CodeOf(err) == notion.CodeTooLarge}", |
| 360 | "permanent: true}"}), |
| 361 | {gate: "R3L6", name: "net.Dial in the images bucket", copy: true, |
| 362 | test: "TestI8MapaHasNoEgressOfItsOwn", edits: []edit{ |
| 363 | {"internal/mapa/images_bucket.go", "\t\"net/http\"\n", |
| 364 | "\t\"net\"\n\t\"net/http\"\n"}, |
| 365 | {"internal/mapa/images_bucket.go", |
| 366 | "// bucket is CARLOS's bucket as Mapa writes to it", |
| 367 | "var _ = net.Dial\n\n" + |
| 368 | "// bucket is CARLOS's bucket as Mapa writes to it"}}}, |
| 369 | inMapa("R3L7", "a copy from a page that no longer holds it", |
| 370 | "TestL7ACopyNeedsAHeldSource", edit{importPlace, |
| 371 | "!job.images.Held(ctx, other.PublicID, other.Page) {", |
| 372 | "false {"}), |
| 373 | inMapa("R3L7", "no lease check before a copy", |
| 374 | "TestL7BothImageWritesHoldTheLease", edit{importImages, |
| 375 | "\tif err := job.store.bookkeep(ctx, job.lease, noChange); " + |
| 376 | "err != nil {\n\t\treturn nil, \"\", refusal{}, err\n\t}\n" + |
| 377 | "\tif added, ok := job.copyImage", |
| 378 | "\tif added, ok := job.copyImage"}), |
| 379 | inMapa("R3L7", "no lease check before an add", |
| 380 | "TestL7BothImageWritesHoldTheLease", edit{importImages, |
| 381 | "\tif err := job.store.bookkeep(ctx, job.lease, noChange); " + |
| 382 | "err != nil {\n\t\treturn nil, \"\", refusal{}, err\n\t}\n" + |
| 383 | "\tadded, err := job.images.Add", |
| 384 | "\tadded, err := job.images.Add"}), |
| 385 | inMapa("R3L7", "quotaReason always names the person's", |
| 386 | "TestL7TheTeamAllowanceIsNamed", edit{ |
| 387 | "internal/mapa/import_images_store.go", |
| 388 | "if errors.As(err, &refusal) && refusal.team {", |
| 389 | "if errors.As(err, &refusal) && refusal.team && false {"}), |
| 390 | inMapa("R4L3", "Finish deletes where the images went", |
| 391 | "TestFinishKeepsTheMap", edit{importCredential, |
| 392 | "\t\tif err := tx.endResumable(runFinished); err != nil {", |
| 393 | "\t\ttx.db.Where(\"1 = 1\").Delete(&NotionImage{})\n" + |
| 394 | "\t\tif err := tx.endResumable(runFinished); err != nil {"}), |
| 395 | } |
| 396 | |