The importer's looks: Fable on phase 4
M2: an imported styled revision reads the look's words with (from Notion), not a stale edited-there date. Lows: covers fetched only from the gallery's pair (Files.Gallery); the fresh page object read once and its types checked; look places in a print domain of their own; width ratios compared with each other; a passing failure keeps the look; three more mutations and a Resume test. The module is pinned to its leaf-pair fix (M1).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
18 files changed,
+360
−66
AGENTS.md+1 −1docs/superpowers/specs/2026-11-17-notion-import.md+1 −1docs/superpowers/specs/2026-11-22-mapa-columns-icons.md+4 −3go.mod+1 −1go.sum+2 −0internal/mapa/import_history.go+4 −2internal/mapa/import_images_place.go+38 −1internal/mapa/import_looks.go+92 −44internal/mapa/import_looks_test.go+98 −2internal/mapa/markup/testdata/corpus/import.json+1 −0internal/mapa/markup/testdata/editor.json+2 −1internal/mapa/markup/testdata/golden.json+1 −0internal/mapa/notionmd/blocks.go+13 −5internal/mapa/notionmd/fixtures_blocks_test.go+8 −0internal/mapa/notionmd/testdata/fixtures/columns-equal-ones.json+54 −0internal/mapa/notionmd/testdata/golden/columns-equal-ones.json+5 −0internal/mapa/notionmd/testdata/golden/columns-equal-ones.md+13 −0scripts/mutate/import_looks.go+22 −5
CI failed — run details
CI log
=== editor ===
cd editor && npm ci --no-audit --no-fund --loglevel=error
added 16 packages in 311ms
cd editor && node build-bundles.mjs
wrote internal/mapa/static/editor.bad1b29c273b6a86.js (364471 bytes, 114.4KB gzipped; L12 budget 120KB)
cd editor && node --test
✔ a badge is named for what it does, starting with its visible word (0.786809ms)
✔ first words stop at five words or forty characters (0.149045ms)
✔ the field keeps one trimmed line, without brackets (0.229823ms)
✔ the field holds at most MaxAlt bytes, cut at a character (0.335438ms)
✔ a block becomes column 1 of two, and undo gives it back (11.679912ms)
✔ a selection over blocks moves them all into column 1 (1.777124ms)
✔ no layout is made inside a layout (0.555904ms)
✔ Add a column, Remove this column and Undo columns (4.218212ms)
✔ Undo columns puts the blocks in reading order (0.726168ms)
✔ Backspace in an empty column takes the column away (0.979435ms)
✔ ⌥⌘→ and ⌥⌘← move between columns (0.482269ms)
✔ typing a fence line in a column never closes it (D16) (7.129636ms)
✔ a selection holding a layout makes no nested layout (H1) (3.472698ms)
✔ a fence typed after a break in a column stays in the column (H2) (4.15153ms)
✔ code holding a fence line and ::: stays code in its column (H2) (3.633735ms)
✔ Backspace after a layout and Delete before one join nothing (M4) (1.493722ms)
✔ deleting across columns keeps every column (M3) (2.011726ms)
✔ a layout pasted into a column arrives as its blocks (M1) (2.529682ms)
✔ copying inside one column puts no fence on the clipboard (M2) (0.299873ms)
✔ typing goes on in the column after a structural reparse (round 2) (8.511994ms)
✔ a structural reparse in a column leaves code as it was (round 2) (2.836536ms)
✔ days and weeks move across months and years (0.850147ms)
✔ a month keeps the day, or takes the month's last (0.207512ms)
✔ the grid is six weeks from Monday, as the month calendar draws it (0.530798ms)
✔ the grid starts the week where the locale does (0.428159ms)
✔ the keys move a day, a week, a month and a year (0.208254ms)
✔ the picked day is the chip [[ makes for a date (18.411803ms)
✔ Insert → Today's date still puts today in at once (1.740988ms)
✔ / offers Date, the picker, and Today's date beside it (0.266811ms)
✔ after a ! the chip goes in after a space, never as an embed (3.219974ms)
✔ where the Markdown would read the chip differently, it is refused (2.435718ms)
✔ over a selection the chip goes after it and the words stay (1.927551ms)
✔ today is the day in the viewer's zone (15.985004ms)
✔ every offered locale has cases (0.936685ms)
✔ dates.mjs writes every date Go writes, byte for byte (3.089933ms)
✔ a chip, the month and the week, in three locales (0.380221ms)
✔ dates.json is what ICU gives, byte for byte (463.965334ms)
✔ L1: mounting then serialising gives cleanBody(body), byte for byte (105.52851ms)
ℹ 904 bodies
✔ L1: mounting a stored body adds nothing, and saving it writes nothing new (85.574914ms)
✔ L2: one edited block changes only that block's bytes; undo gives the body back (146.01008ms)
ℹ 891 single-block edits
✔ L2: inserting or deleting a block changes bytes only at the new seams, by Join (157.818479ms)
ℹ 899 inserts, 837 deletes
✔ L3: seeded edits keep the document and its Markdown saying the same thing (5067.480668ms)
ℹ 21696 edits over 904 bodies
✔ L3: Link to a page makes exactly one chip, and changes nothing else (1295.09003ms)
ℹ 4724 links over 904 bodies; refused: {"A page link can’t hold another link or a line break. Select plain words.":945,"A page link can’t show [ or ]]. Select words without them.":404,"Select some words to link them to a page.":174,"Linked here, the Markdown around these words would read differently: a ! before them makes an embed, and a stray ` or * pairs up. Select other words.":18}
✔ L3: a picked date is one more date chip, or refused where a letter would be too (1364.643634ms)
ℹ over 904 bodies: {"inserted":5356,"spaced":23,"refused":45,"unstable":9}
✔ linear: trailing spaces (32.865114ms)
✔ linear: trailing whitespace (31.572293ms)
✔ linear: unclosed web links (16.495504ms)
✔ linear: web links with no address (20.459758ms)
✔ linear: unclosed wiki links (25.902766ms)
✔ linear: unclosed embeds (19.756071ms)
✔ linear: closes only (5.181577ms)
✔ the selected words become the chip's shown text (13.748972ms)
✔ words that are the title make a plain [[Title]] (4.817567ms)
✔ spaces at the selection's edges stay outside the chip (1.985859ms)
✔ a date makes a date link, in a heading, an item and a quote (7.813045ms)
✔ bold words lose their bold: a chip carries no marks in Mapa's Markdown (1.740067ms)
✔ only the linked block's bytes change, and undo gives the body back (4.11965ms)
✔ a selection across blocks, over a chip or a break, or of brackets is refused (2.090822ms)
✔ a target the words cannot be linked to as typed is refused (0.347891ms)
✔ ⌘L: over a selection it opens Page link; with none it types [[; in code it does nothing (2.670531ms)
✔ web-linked words are refused: the address would be lost (review M4) (2.002861ms)
✔ words whose Markdown would read otherwise are refused (review M3) (2.257269ms)
✔ ⌘A then ⌘L says why, instead of doing nothing (review low 1) (0.452734ms)
✔ linkCheck says why it refuses (review low 2) (1.773438ms)
✔ golden file has bodies (0.771362ms)
✔ markup.mjs parses every body into Go's blocks, byte offsets and all (38.845865ms)
✔ markup.mjs strips and spans every block as Go does (46.851324ms)
✔ the schema's toDOM draws every body as Go renders it (64.592684ms)
✔ emphasis draws the four pinned outputs (18.330034ms)
✔ a body ends in the editor's empty paragraph (0.235183ms)
✔ the editor labels date chips as Go does, in every locale L4 holds (13.04792ms)
✔ a POST that never answers is aborted after the timeout (21.409858ms)
✔ a keepalive POST carries no signal, and an answer clears the timer (1.187909ms)
✔ autosave sends only what differs, and the tab owns the draft it wrote (12.090196ms)
✔ an offered draft never commits by itself; Save commits it (1.375915ms)
✔ reload, then close: sessionStorage says the draft is this tab's own (0.590107ms)
✔ closing carries text not yet sent, and the cap leaves it out (31.134096ms)
✔ clean rebase: applied, the caret survives, the base moves by the rebase POST (4.145369ms)
✔ the block under the caret is the teammate's too, and undo brings back yours (3.069666ms)
✔ typing mid-flight: the merge is not applied and the base does not move (2.158196ms)
✔ a merge the editor cannot represent stops after three tries (4.198257ms)
✔ a conflict is shown, locks the editor's own commits, and Resolve settles it (1.588206ms)
✔ leaving: a conflict stays with the choice; a failed flush offers Leave anyway; a stored draft leaves (1.808372ms)
✔ a stale tab shows the newer draft, offered, and never overwrites it (1.440624ms)
✔ the first scratch commit: empty creates nothing, then one page, then drafts on it (0.909506ms)
✔ noBase and gone lead to the existing choices (0.792349ms)
✔ a commit that merged is applied when nothing was typed since (1.115506ms)
✔ back from the cache: nothing unsaved reloads, unsaved text autosaves at once (8.239341ms)
✔ an own draft committed meanwhile goes on as a new draft (1.523477ms)
✔ a reload keeps a stored draft; unsent text still commits (0.573957ms)
✔ a page deleted mid-edit: what is typed is still stored as the draft, and nothing commits (H1) (1.2053ms)
✔ an offered draft committed in another tab: typing goes on as a new draft (H1) (2.358897ms)
✔ a commit reply without a revision is not a commit; an emptied day starts afresh (H2) (0.978453ms)
✔ Resolve stores what was typed first, and takes no typing until its answer is applied (M1) (2.579702ms)
✔ closing with a choice open, or commits held, still writes the text, never commits (M2) (1.023506ms)
✔ closing inside the settling window sends the loaded version with settling=1 (M3) (0.307987ms)
✔ a clean merge not applied because of typing still ends the choice on show (M4) (0.806095ms)
✔ settling finds the draft committed with a teammate's text: a close still writes (M-A) (0.44473ms)
✔ settling finds another tab's newer draft: the tab shows it before any typing (0.562436ms)
✔ a page deleted before the first autosave: the text is offered as a scratch page, and a close makes one (M-B) (0.516502ms)
✔ an autosave that never answered but landed: its 409 keeps the typing since (L3) (0.496124ms)
✔ marks: em outside strong, bold reopened around italics, edges outside (4.703457ms)
✔ marks close before code, links and atoms, and reopen after (0.372667ms)
✔ untouched blocks and atoms re-emit their source; edited atoms are written from attributes (5.448068ms)
✔ empty blocks are written as nothing (2.096815ms)
✔ an unclosed fence that is no longer last gets its closing fence (2.153548ms)
✔ the structure check puts Join's seam where a kept one would merge two blocks (1.995957ms)
✔ prepareSave adopts the parse when no seam or rewrite can save the document (2.25261ms)
✔ reparse: typed emphasis becomes a mark, "- " after a break becomes an item (2.362603ms)
✔ a trailing hard break stays on screen and is written as nothing (0.811445ms)
✔ the reparse waits while an IME is composing (0.867038ms)
✔ copied blocks paste with their bytes and seams; a cut and paste gives the body back (5.005684ms)
✔ a forged x-mapa slice is refused, and text from outside is read as Markdown (0.673391ms)
✔ rebuild changes origins only, outside undo history (2.893122ms)
✔ applyBody takes a teammate's block, keeps the caret, and ends untouched (1.742401ms)
✔ a block whose context changed is written again: a task toggled, a bullet, a quote (2.151194ms)
✔ a duplicate ^id typed above its holder never takes the id from it (1.468576ms)
✔ a copy-dragged block is reparsed, and says what its Markdown says (1.54138ms)
✔ a history command that throws is refused, never thrown (8.031388ms)
✔ an image re-emits its source, and an edited alt changes only its span (1.299774ms)
✔ a paste whose image copy is refused says why and pastes nothing (16.674845ms)
✔ a line of image openers reads in linear time (116.321376ms)
✔ a line of shared link address reads in linear time (8.339456ms)
✔ a line of shared web address reads in linear time (40.291248ms)
✔ one rename at a time, from either field (2.008982ms)
✔ an empty or unchanged title sends nothing (0.190892ms)
✔ a refusal keeps what was typed, and the title (0.348452ms)
✔ the pending state holds for the busy rule (9.364002ms)
✔ a failed POST says so and keeps the title (1.592705ms)
✔ Update links posts the confirm page's POST (0.354373ms)
✔ clean is CleanTitle's whitespace rule (0.685112ms)
✔ the saver's base follows a rename made over it, and only that (0.354243ms)
✔ closing sends the rename as one keepalive POST (3.31095ms)
✔ the port answers every shared case as typeddate.go does (8.000551ms)
✔ numbers follow the locale: 12/11 is November in en-IE, December in en-US (0.294422ms)
✔ M6: several files land in the order they were chosen (39.787549ms)
✔ M5: one Backspace before the box keeps the image where the box is (11.173458ms)
✔ M5: undoing text typed just before the box keeps the upload (12.667069ms)
✔ L12: a failed upload an undo takes away does not stall the next (13.640484ms)
✔ M4: Replace… keeps the old image until the new one is in, and its alt (14.054715ms)
✔ M3 and N1: text wins, except over a picture copied from a page (1.476881ms)
✔ N2: a JPEG over 10 MB is scaled before its size is checked (5.169786ms)
✔ a drag whose anchor the document no longer reaches selects to its end (7.937425ms)
ℹ tests 143
ℹ suites 0
ℹ pass 143
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 8346.082978
=== vet ===
go vet ./...
go vet -tags browser ./internal/mapatest/
=== fmt ===
=== code ===
go tool rastrillo budget code
The base has no .rastrillo/code.txt: skipping the check that records only go down.
budget code: within the limits.
=== test ===
CGO_ENABLED=0 go test ./...
? amadan.net/oficina/mapa/cmd/mapa [no test files]
ok amadan.net/oficina/mapa/internal/mapa 4.134s
ok amadan.net/oficina/mapa/internal/mapa/emoji (cached)
? amadan.net/oficina/mapa/internal/mapa/icons [no test files]
ok amadan.net/oficina/mapa/internal/mapa/imagefile (cached)
ok amadan.net/oficina/mapa/internal/mapa/locale (cached)
ok amadan.net/oficina/mapa/internal/mapa/markup 0.154s
ok amadan.net/oficina/mapa/internal/mapa/notionmd 0.319s
ok amadan.net/oficina/mapa/internal/mapa/seal (cached)
ok amadan.net/oficina/mapa/internal/mapatest 13.989s
? amadan.net/oficina/mapa/scripts/mutate [no test files]
? amadan.net/oficina/mapa/scripts/preview [no test files]
=== migration-check ===
go tool rastrillo migration check
rastrillo migration check: models and migrations agree
=== credits-check ===
python3 scripts/credits.py --check
the Colophon's JavaScript inventory is stale; run make credits
make: *** [Makefile:171: credits-check] Error 1
amadan: step credits-check failed: exit status 2
amadan: job failed at step credits-check — its output is above, not at the tail of this log
diff --git a/AGENTS.md b/AGENTS.md| index bff8e81..5d0e154 100644 |
| --- a/AGENTS.md |
| +++ b/AGENTS.md |
| @@ -218,7 +218,7 @@ Makefile, estilo's files served straight from the module). |
| (L9, level-up build note 79), that Recently edited filters team |
| pages inside its query (build note 80), the images' named risks |
| (`scripts/mutate/images.go`), and that the Notion import's gates I1 |
| - to I19 can (`MUTATE_GATES=I3,I13` runs a few). |
| + to I25 can (`MUTATE_GATES=I3,I13` runs a few). |
| ## Serving |
diff --git a/docs/superpowers/specs/2026-11-17-notion-import.md b/docs/superpowers/specs/2026-11-17-notion-import.md| index 3b46d14..5c6d856 100644 |
| --- a/docs/superpowers/specs/2026-11-17-notion-import.md |
| +++ b/docs/superpowers/specs/2026-11-17-notion-import.md |
| @@ -538,7 +538,7 @@ The import writes pages only through two methods in package `mapa`, each **one ` |
| | `notion_connections` (one row) | `id`, `created_by` (member id), `created_at`, `verified_at` | token, workspace name | that a Notion connection exists, who made it, when it was last checked | |
| | `notion_runs` | `id`, `actor`, `state`, `lease` (random, redrawn on start, resume and Stop), `started_at`, `heartbeat_at`, `progress_at`, `finished_at`, the counters, `error_code` | — | when imports ran, who ran them, how many pages each created, kept, failed. The lease is random and says nothing | |
| | `notion_pages` (the map) | `id`, `notion_print` (unique), `state`, `error_code`, `surveyed_run`, `seen_run` | the coordinate record (Notion id, last Notion title, Mapa page id, last written revision, unresolved mention ids, placeholder ids); the staged tree | how many Notion pages exist and their states | |
| -| `notion_images` | `id`, `place_print` (unique: an HMAC of the Notion block id and the **Notion** page id together, which the map pins to one Mapa page; §25.7; and one row each for a page's icon and cover, whose place print is of the pseudo-block `icon:` or `cover:` and the Notion page id: columns and icons spec §6.1), `block_print` (an HMAC of the block id alone, not unique, to find a block that moved or is shown on several pages), `state` (`imported`, `refused`; a transient failure keeps no row, so the next run tries again) | the image record (block id, the file's key (§25 note 17), Mapa page id, public id, refusal reason) | how many images were imported, refused and failed, and, through equal `block_print`s, how many Notion images appear on more than one page. The images spec's own `images` table holds the rest (§12) | |
| +| `notion_images` | `id`, `place_print` (unique: an HMAC of the Notion block id and the **Notion** page id together, which the map pins to one Mapa page; §25.7; and one row each for a page's icon and cover, whose place print is an HMAC in a domain of its own (`look`, the Notion page id and the pseudo-block `icon:` or `cover:`), and whose `block_print` is the same value, so a look row shares no print with any other row: columns and icons spec §6.1; the table's row count, plaintext, includes them), `block_print` (an HMAC of the block id alone, not unique, to find a block that moved or is shown on several pages), `state` (`imported`, `refused`; a transient failure keeps no row, so the next run tries again) | the image record (block id, the file's key (§25 note 17), Mapa page id, public id, refusal reason) | how many images were imported, refused and failed, and, through equal `block_print`s, how many Notion images appear on more than one page. The images spec's own `images` table holds the rest (§12) | |
| - **What the file still shows, said plainly.** The coordinate is sealed, so no column joins a ledger row to a Mapa page. **But the plaintext event log does.** A run's `created` events, by the run's actor, inside the run's window in `notion_runs`, mark which team pages it made, and sequential `pages.id` and `notion_pages.id` in survey order line them up row for row. So the file shows **which team pages came from a Notion import, and roughly their order in Notion**. It does not show their titles, bodies or Notion ids. This goes in the leak list. `notion_pages` carries no `updated_at`, which would be a second join. |
| - **Prints are HMACs under the instance key**, equality only, as every print in Mapa (base §4). |
diff --git a/docs/superpowers/specs/2026-11-22-mapa-columns-icons.md b/docs/superpowers/specs/2026-11-22-mapa-columns-icons.md| index 9a392ca..d8f4eec 100644 |
| --- a/docs/superpowers/specs/2026-11-22-mapa-columns-icons.md |
| +++ b/docs/superpowers/specs/2026-11-22-mapa-columns-icons.md |
| @@ -794,10 +794,11 @@ Fable found every round-1 finding answered in substance, and five mediums and si |
| ### Phase 4: the importer's icons, covers and widths (`feat/import-looks`, and the notion module's `feat/looks`) |
| -- **F1, the module.** `Icon.URL` (file, external, custom_emoji), `Page.Cover {Type, URL}` in place of `HasCover`, and `Block.WidthRatio`, each read from Notion's documented shapes (`notiontest.AddLooks`, `TestPageLooksDecode`); no real recording was made, as §6.5's two unverified points (a custom emoji's host, `width_ratio` on a column read) await §19's first real run. Q5: the file transport pins `www.notion.so` to `/images/page-cover/` only; M5 refuses every other path on that host, and two mutations (the pair removed, the host pinned alone) are caught. |
| +- **F1, the module.** `Icon.URL` (file, external, custom_emoji), `Page.Cover {Type, URL}` in place of `HasCover`, and `Block.WidthRatio`, each read from Notion's documented shapes (`notiontest.AddLooks`, `TestPageLooksDecode`); no real recording was made, as §6.5's unverified points (a custom emoji's host, `width_ratio` on a column read, and whether the gallery answers without a redirect, which the fetcher refuses) await §19's first real run, listed in the module's AGENTS.md. Q5: the file transport pins `www.notion.so` to `/images/page-cover/` and one plain name after it (a leaf pair: no `%`, no further `/`), and `Files.Gallery` answers for that pair alone; M5 refuses every other path on that host, encoded slashes and backslashes included, and three mutations (the pair removed, the host pinned alone, the leaf rule removed) are caught. |
| - **F2, the staged tree.** `notionmd.Page` holds the look under new keys (`pageIcon`, `pageCover`), so a tree staged before this decodes with none, and that page's look comes on its next run. The mapper writes nothing of the look and no longer counts it; it counts `column_widths` when a layout's columns' ratios differ (a column with none is an even share). |
| -- **F3, the look before the write.** `import_looks.go` prepares the icon and the cover after the page's images and before its transaction, under §12's rules: the page object read again for a fresh URL, the lease checked before each add, a refusal the page's count and never its failure. An emoji goes through `EmojiIcon`'s check. An icon is fetched with a 128 KiB cap, and one over 512 pixels a side is discarded at once and remembered as refused. A cover is fetched when it is Notion-hosted or the pin allows its address. The look's added images and places join the page's images, so a kept or failed page discards them and a written page keeps their `notion_images` rows in its own transaction. |
| +- **F3, the look before the write.** `import_looks.go` prepares the icon and the cover after the page's images and before its transaction, under §12's rules: the page object read again for a fresh URL, the lease checked before each add, a refusal the page's count and never its failure. An emoji goes through `EmojiIcon`'s check. An icon is fetched with a 128 KiB cap, and one over 512 pixels a side is discarded at once and remembered as refused. A cover is fetched when it is Notion-hosted or on the gallery's pair. The page object is read again once a page, and what it holds now is checked as Survey's was. A passing failure (not a permanent refusal) keeps the icon or banner the page has, so it costs no revision now and none to undo next run. The look's places are printed in a domain of their own (`look`, the page, the pseudo-block), so a look row shares no print with a block's. The look's added images and places join the page's images, so a kept or failed page discards them and a written page keeps their `notion_images` rows in its own transaction. |
| - **F4, the writes.** `ImportCreate` writes the record with its icon and banner (centred, `Y: 50`), and its commit attaches them. `ImportUpdate` writes renamed, styled, edited, each only when needed, in one transaction (`update:styled` is a new crash point); the styled revision carries drafts as a rename's does. "Unchanged" compares the look too. A page this run prepared no look for (a fix-up after a Resume) keeps its own. |
| - **F5, the report.** "Icons imported", "Icons not imported" by reason, "Banners imported" and "Banners not imported" (Luna: Mapa's word for what Notion calls a cover), and "Column widths" among the losses; the old "Page icons" and "Page covers" losses are gone (an old run's report shows them by key). Luna's wording applied (`copy-review/import-looks`). |
| -- **F6, gates.** I20 and I25 (`TestI20IconsAreImported`: emoji, custom emoji and uploaded icons imported; Notion's set, an emoji Mapa lacks, an icon too wide, a download that fails and a custom emoji on an unpinned host counted, the page written each time); I21 (`TestI21CoversAreImportedFromThePinOnly`); I22 is COL11 plus the width goldens; I24 (`TestI24ALookChangedInNotionIsStyled`, `TestI24RenamedStyledEditedInOrder`, and I17's re-run crash case now renaming, restyling and editing at every crash point). Four mutations, all caught. The import spec's §9.1, §10, §11.4 and §15 say what this spec changed. |
| +- **F6, gates.** I20 and I25 (`TestI20IconsAreImported`: emoji, custom emoji and uploaded icons imported; Notion's set, an emoji Mapa lacks, an icon too wide, a download that fails and a custom emoji on an unpinned host counted, the page written each time); I21 (`TestI21CoversAreImportedFromThePinOnly`); I22 is COL11 plus the width goldens; I24 (`TestI24ALookChangedInNotionIsStyled`, `TestI24RenamedStyledEditedInOrder`, and I17's re-run crash case now renaming, restyling and editing at every crash point). Seven mutations, all caught. The import spec's §9.1, §10, §11.4 and §15 say what this spec changed. |
| +- **F7, Fable on the build (`bd3ee46`, module `d36f6e0`): APPROVE, no High, two Mediums, answered.** M1: the gallery pin let an encoded `/` or `\` follow its prefix; it is now a leaf pair. M2: an imported styled revision read "Updated from Notion · edited there <date>", a stale date; it now reads the look's own words with "(from Notion)". Lows: the redirect check added to the first-run list (L1); `Files.Gallery` for covers (L2); the fresh object's types checked (L3); look prints in their own domain (L4); width ratios compared with each other (L5); mutations for the 512-pixel discard, the 128 KiB cap and a fix-up keeping its look, with a Resume test (L6); a passing failure keeps the look (L7); the page object read once (L8); the module landed first and Mapa pinned to its main (L9). I24 gains the fix-up and passing-failure tests; I20 a 128 KiB icon. |
diff --git a/go.mod b/go.mod| index 2d0fa33..7556485 100644 |
| --- a/go.mod |
| +++ b/go.mod |
| @@ -6,7 +6,7 @@ toolchain go1.26.11 |
| require ( |
| amadan.net/oficina/estilo.git v0.0.0-20261118055615-d004805f40f2 |
| - amadan.net/oficina/notion.git v0.0.0-20261122193726-d36f6e0f6101 |
| + amadan.net/oficina/notion.git v0.0.0-20261122203529-9de09416b0e5 |
| amadan.net/rastrillo/rastrillo v0.35.1-0.20261116213651-96812beacacc |
| github.com/chromedp/cdproto v0.158.6 |
| github.com/chromedp/chromedp v0.21.0 |
diff --git a/go.sum b/go.sum| index a6f1ef7..a8f96c8 100644 |
| --- a/go.sum |
| +++ b/go.sum |
| @@ -4,6 +4,8 @@ amadan.net/oficina/notion.git v0.0.0-20261122111155-169302d88bbe h1:rTQZz9FJ7tQ7 |
| amadan.net/oficina/notion.git v0.0.0-20261122111155-169302d88bbe/go.mod h1:2WuyjBTLHwurTGri00zfPxSKc9b3pomdT6wSs/UIvA4= |
| amadan.net/oficina/notion.git v0.0.0-20261122193726-d36f6e0f6101 h1:EdCkiWKC2PrZuiFEIeSrT4YH3E2Js4d1PKI37kG1qZ8= |
| amadan.net/oficina/notion.git v0.0.0-20261122193726-d36f6e0f6101/go.mod h1:2WuyjBTLHwurTGri00zfPxSKc9b3pomdT6wSs/UIvA4= |
| +amadan.net/oficina/notion.git v0.0.0-20261122203529-9de09416b0e5 h1:vtl6aPel2HbTNoUnigTlUjymI5T6HTfzPBHN/mqXKQc= |
| +amadan.net/oficina/notion.git v0.0.0-20261122203529-9de09416b0e5/go.mod h1:2WuyjBTLHwurTGri00zfPxSKc9b3pomdT6wSs/UIvA4= |
| amadan.net/rastrillo/fiesta v1.3.0 h1:7SsHw4aeWPLStR3RHFEEtX4CwqKu+Ig3PgNX8FvD8WM= |
| amadan.net/rastrillo/fiesta v1.3.0/go.mod h1:LpO391W1dIRUxOIKklHm+bGyWXtlFyBRRPQCysb9LjY= |
| amadan.net/rastrillo/rastrillo v0.35.1-0.20261116213651-96812beacacc h1:QakboVkj9nqA6ZaKXeDVXWLPobQSVvd80ic521aA8/U= |
diff --git a/internal/mapa/import_history.go b/internal/mapa/import_history.go| index 9ef25f5..daa2690 100644 |
| --- a/internal/mapa/import_history.go |
| +++ b/internal/mapa/import_history.go |
| @@ -14,7 +14,7 @@ import ( |
| // importedSummary is a version's summary when the import wrote it: |
| // "Imported this from Notion · edited there 12 October 2026" for its |
| // first revision, "Updated from Notion · …" for a later one, and a |
| -// rename's own words with "(from Notion)" after them. |
| +// rename's or a new look's own words with "(from Notion)" after them. |
| func (history *pageHistory) importedSummary(index int, |
| plain string) (string, error) { |
| record, err := history.record(index) |
| @@ -25,7 +25,9 @@ func (history *pageHistory) importedSummary(index int, |
| case VerbCreated: |
| return "Imported this from Notion" + |
| editedThere(history.viewer.Locale, record), nil |
| - case VerbRenamed: |
| + case VerbRenamed, VerbStyled: |
| + // The look changed with no edit there: no "edited there" date, |
| + // which would be the body's (Fable on phase 4, M2). |
| return plain + " (from Notion)", nil |
| } |
| return "Updated from Notion" + |
diff --git a/internal/mapa/import_images_place.go b/internal/mapa/import_images_place.go| index 4f5ee8a..3f6e9fa 100644 |
| --- a/internal/mapa/import_images_place.go |
| +++ b/internal/mapa/import_images_place.go |
| @@ -22,6 +22,9 @@ type placedImage struct { |
| page, block, key string |
| publicID, reason string |
| permanent bool |
| + // look marks an icon's or a cover's place (columns and icons spec |
| + // §6.1), printed in its own domain (lookPrints). |
| + look bool |
| } |
| // imagePlace is a notion_images row's sealed record. Key is the file's |
| @@ -56,6 +59,24 @@ func (store *Store) imagePrints(page, block string) (string, string, |
| return place, alone, err |
| } |
| +// lookPrints are an icon's or a cover's handles: one print, in a domain |
| +// of its own, for both, so a look row never shares a block's place and |
| +// its block print finds no other row (Fable on phase 4, L4). |
| +func (store *Store) lookPrints(page, pseudo string) (string, string, |
| + error) { |
| + place, err := store.sealer.Print(seal.PrintNotionImage, |
| + []byte("look\x00"+notionKey(page)+"\x00"+pseudo)) |
| + return place, place, err |
| +} |
| + |
| +// printsOf is a placed image's handles. |
| +func (store *Store) printsOf(placed placedImage) (string, string, error) { |
| + if placed.look { |
| + return store.lookPrints(placed.page, placed.block) |
| + } |
| + return store.imagePrints(placed.page, placed.block) |
| +} |
| + |
| func (store *Store) openPlace(row NotionImage) (imagePlace, error) { |
| var place imagePlace |
| plain, err := store.sealer.Open(seal.PurposeNotionImage, |
| @@ -66,6 +87,16 @@ func (store *Store) openPlace(row NotionImage) (imagePlace, error) { |
| return place, json.Unmarshal(plain, &place) |
| } |
| +// priorLook is where a page's icon or cover went last time. |
| +func (job *importJob) priorLook(ctx context.Context, page, |
| + pseudo string) (imagePlace, bool, error) { |
| + place, _, err := job.store.lookPrints(page, pseudo) |
| + if err != nil { |
| + return imagePlace{}, false, err |
| + } |
| + return job.placeAt(ctx, place) |
| +} |
| + |
| // priorPlace is where the block went on this page last time. |
| func (job *importJob) priorPlace(ctx context.Context, page, |
| block string) (imagePlace, bool, error) { |
| @@ -73,6 +104,12 @@ func (job *importJob) priorPlace(ctx context.Context, page, |
| if err != nil { |
| return imagePlace{}, false, err |
| } |
| + return job.placeAt(ctx, place) |
| +} |
| + |
| +// placeAt is the notion_images row at a place print, opened. |
| +func (job *importJob) placeAt(ctx context.Context, |
| + place string) (imagePlace, bool, error) { |
| row, found := notionImageOf(job.store.database.WithContext(ctx), place) |
| if !found { |
| return imagePlace{}, false, nil |
| @@ -140,7 +177,7 @@ func keepPlaces(db *gorm.DB, store *Store, pageID int64, |
| func keepPlace(db *gorm.DB, store *Store, pageID int64, |
| placed placedImage) error { |
| - place, alone, err := store.imagePrints(placed.page, placed.block) |
| + place, alone, err := store.printsOf(placed) |
| if err != nil { |
| return err |
| } |
diff --git a/internal/mapa/import_looks.go b/internal/mapa/import_looks.go| index a54d47c..64cef4b 100644 |
| --- a/internal/mapa/import_looks.go |
| +++ b/internal/mapa/import_looks.go |
| @@ -11,9 +11,9 @@ import ( |
| // cover, prepared with its images, before the page's transaction, under |
| // the same rules (import spec §12): a fresh URL from the page object, |
| // the lease checked just before each add, a failure the page's own |
| -// count and never its failure. notion_images keeps where each went, |
| -// under the pseudo-blocks icon: and cover: on the page, so the file's |
| -// key decides whether it changed, as for an image block. |
| +// count and never its failure. notion_images keeps where each went, in |
| +// a print domain of its own (lookPrints), so the file's key decides |
| +// whether it changed, as for an image block. |
| // The look's pseudo-blocks in notion_images. |
| const ( |
| @@ -33,12 +33,20 @@ const ( |
| ) |
| // pageLook is a page's prepared icon and banner, the images it added, |
| -// and where each went. |
| +// where each went, and the page object read again for fresh URLs, once. |
| type pageLook struct { |
| icon *Icon |
| banner *Banner |
| added []AddedImage |
| placed []placedImage |
| + fresh *notion.Page |
| +} |
| + |
| +// lookOutcome is one icon's or cover's: the image's public id, or why |
| +// not, and whether that is for good. |
| +type lookOutcome struct { |
| + public, reason string |
| + permanent bool |
| } |
| // prepareLook prepares a page's icon and cover, counting each. |
| @@ -65,42 +73,65 @@ func (job *importJob) prepareIcon(ctx context.Context, entry *importEntry, |
| } |
| look.icon, counts.Icon = made, lookImported |
| return nil |
| - case icon.Type != notion.IconCustomEmoji && icon.Type != notion.FileHosted: |
| + case !iconFetched(icon.Type): |
| // Notion's own icon set is SVG, which Mapa refuses, and any |
| // other address is never fetched (import D13). |
| counts.Icon = lookIconSet |
| return nil |
| } |
| - public, reason, err := job.lookImage(ctx, entry, iconPlace, icon, look) |
| - if err != nil || reason != "" { |
| - counts.Icon = reason |
| + got, err := job.lookImage(ctx, entry, iconPlace, icon, look) |
| + if err != nil { |
| return err |
| } |
| - look.icon, counts.Icon = &Icon{Image: public}, lookImported |
| + switch { |
| + case got.reason == "": |
| + look.icon, counts.Icon = &Icon{Image: got.public}, lookImported |
| + case !got.permanent: |
| + // Tried again next run: the page keeps the icon it has, so a |
| + // passing failure is not two revisions (Fable on phase 4, L7). |
| + look.icon, counts.Icon = entry.current.Icon, got.reason |
| + default: |
| + counts.Icon = got.reason |
| + } |
| return nil |
| } |
| +// iconFetched is an icon type whose picture is downloaded. |
| +func iconFetched(kind string) bool { |
| + return kind == notion.IconCustomEmoji || kind == notion.FileHosted |
| +} |
| + |
| +// coverFetched is a cover downloaded: Notion-hosted, or from Notion's |
| +// own gallery, the one external address the module pins for it (Q5). |
| +func (job *importJob) coverFetched(cover *notionmd.Look) bool { |
| + return cover.Type == notion.FileHosted || |
| + (cover.Type == notion.FileExternal && job.files.Gallery(cover.URL)) |
| +} |
| + |
| func (job *importJob) prepareCover(ctx context.Context, entry *importEntry, |
| look *pageLook, counts *imageCounts) error { |
| cover := entry.staged.Cover |
| if cover == nil { |
| return nil |
| } |
| - // An external cover is fetched only from Notion's own gallery, the |
| - // one address the file transport pins for it (Q5). |
| - if cover.Type != notion.FileHosted && !job.files.Allowed(cover.URL) { |
| + if !job.coverFetched(cover) { |
| counts.Cover = lookElsewhere |
| return nil |
| } |
| - public, reason, err := job.lookImage(ctx, entry, coverPlace, cover, |
| - look) |
| - if err != nil || reason != "" { |
| - counts.Cover = reason |
| + got, err := job.lookImage(ctx, entry, coverPlace, cover, look) |
| + if err != nil { |
| return err |
| } |
| - // The API gives no position: centred. |
| - look.banner, counts.Cover = &Banner{Image: public, Y: 50}, |
| - lookImported |
| + switch { |
| + case got.reason == "": |
| + // The API gives no position: centred. |
| + look.banner = &Banner{Image: got.public, Y: 50} |
| + counts.Cover = lookImported |
| + case !got.permanent: |
| + look.banner, counts.Cover = entry.current.Banner, got.reason |
| + default: |
| + counts.Cover = got.reason |
| + } |
| return nil |
| } |
| @@ -108,30 +139,30 @@ func (job *importJob) prepareCover(ctx context.Context, entry *importEntry, |
| // Notion still shows the same file and the page still holds the image, |
| // a permanent refusal remembered, or a fresh download. |
| func (job *importJob) lookImage(ctx context.Context, entry *importEntry, |
| - pseudo string, given *notionmd.Look, look *pageLook) (string, string, |
| + pseudo string, given *notionmd.Look, look *pageLook) (lookOutcome, |
| error) { |
| - placed := placedImage{page: entry.staged.ID, block: pseudo, |
| + placed := placedImage{page: entry.staged.ID, block: pseudo, look: true, |
| key: notion.FileKey(given.URL)} |
| - prior, found, err := job.priorPlace(ctx, entry.staged.ID, pseudo) |
| + prior, found, err := job.priorLook(ctx, entry.staged.ID, pseudo) |
| if err != nil { |
| - return "", "", err |
| + return lookOutcome{}, err |
| } |
| if found && sameFile(prior.Key, placed.key) { |
| if prior.Reason != "" { |
| placed.reason, placed.permanent = prior.Reason, true |
| look.placed = append(look.placed, placed) |
| - return "", prior.Reason, nil |
| + return lookOutcome{reason: prior.Reason, permanent: true}, nil |
| } |
| if entry.place.PageID != 0 && |
| job.images.Held(ctx, prior.PublicID, entry.place.PageID) { |
| placed.publicID = prior.PublicID |
| look.placed = append(look.placed, placed) |
| - return prior.PublicID, "", nil |
| + return lookOutcome{public: prior.PublicID}, nil |
| } |
| } |
| - added, key, why, err := job.addLook(ctx, entry, pseudo) |
| + added, key, why, err := job.addLook(ctx, entry, pseudo, look) |
| if err != nil { |
| - return "", "", err |
| + return lookOutcome{}, err |
| } |
| if key != "" { |
| placed.key = key |
| @@ -139,12 +170,12 @@ func (job *importJob) lookImage(ctx context.Context, entry *importEntry, |
| if why.text != "" { |
| placed.reason, placed.permanent = why.text, why.permanent |
| look.placed = append(look.placed, placed) |
| - return "", why.text, nil |
| + return lookOutcome{reason: why.text, permanent: why.permanent}, nil |
| } |
| placed.publicID = added.PublicID() |
| look.added = append(look.added, added) |
| look.placed = append(look.placed, placed) |
| - return placed.publicID, "", nil |
| + return lookOutcome{public: placed.publicID}, nil |
| } |
| // addLook downloads an icon or a cover and adds it, and answers the key |
| @@ -152,7 +183,7 @@ func (job *importJob) lookImage(ctx context.Context, entry *importEntry, |
| // away again at once: Mapa never decodes pixels, so it cannot scale one |
| // down (§6.1). |
| func (job *importJob) addLook(ctx context.Context, entry *importEntry, |
| - pseudo string) (AddedImage, string, refusal, error) { |
| + pseudo string, look *pageLook) (AddedImage, string, refusal, error) { |
| if job.imagesStopped == "" { |
| if err := job.images.Ready(ctx); err != nil { |
| job.imagesStopped = errNoImageStore.Error() |
| @@ -164,7 +195,8 @@ func (job *importJob) addLook(ctx context.Context, entry *importEntry, |
| if err := job.store.bookkeep(ctx, job.lease, noChange); err != nil { |
| return nil, "", refusal{}, err |
| } |
| - data, key, why, err := job.downloadLook(ctx, entry.staged.ID, pseudo) |
| + data, key, why, err := job.downloadLook(ctx, entry.staged.ID, pseudo, |
| + look) |
| if err != nil || why.text != "" { |
| return nil, key, why, err |
| } |
| @@ -185,21 +217,21 @@ func (job *importJob) addLook(ctx context.Context, entry *importEntry, |
| return added, key, refusal{}, nil |
| } |
| -// downloadLook reads the page object again for a fresh URL and fetches |
| -// the icon's or the cover's file through the pinned transport. |
| +// downloadLook fetches the icon's or the cover's file, from the page |
| +// object read again for a fresh URL (once a page), through the pinned |
| +// transport. What the fresh object holds is checked as Survey's was: an |
| +// icon or cover changed since to one Mapa does not fetch gives no file |
| +// (Fable on phase 4, L3). |
| func (job *importJob) downloadLook(ctx context.Context, pageID, |
| - pseudo string) ([]byte, string, refusal, error) { |
| - page, err := job.client.Page(ctx, pageID) |
| - if err != nil { |
| - return nil, "", refusal{text: fetchReason(err)}, finalOnly(err) |
| - } |
| - address, limit := "", int64(imageCap) |
| - switch { |
| - case pseudo == iconPlace && page.Icon != nil: |
| - address, limit = page.Icon.URL, MaxIconBytes |
| - case pseudo == coverPlace && page.Cover != nil: |
| - address = page.Cover.URL |
| + pseudo string, look *pageLook) ([]byte, string, refusal, error) { |
| + if look.fresh == nil { |
| + page, err := job.client.Page(ctx, pageID) |
| + if err != nil { |
| + return nil, "", refusal{text: fetchReason(err)}, finalOnly(err) |
| + } |
| + look.fresh = &page |
| } |
| + address, limit := job.freshAddress(*look.fresh, pseudo) |
| if address == "" { |
| return nil, "", refusal{text: fetchReason(nil)}, nil |
| } |
| @@ -215,3 +247,19 @@ func (job *importJob) downloadLook(ctx context.Context, pageID, |
| } |
| return data, key, refusal{}, nil |
| } |
| + |
| +// freshAddress is the address to fetch from a fresh page object, and |
| +// its cap, or "" when it holds no picture Mapa fetches. |
| +func (job *importJob) freshAddress(page notion.Page, pseudo string) (string, |
| + int64) { |
| + switch { |
| + case pseudo == iconPlace && page.Icon != nil && |
| + iconFetched(page.Icon.Type): |
| + return page.Icon.URL, MaxIconBytes |
| + case pseudo == coverPlace && page.Cover != nil && |
| + job.coverFetched(¬ionmd.Look{Type: page.Cover.Type, |
| + URL: page.Cover.URL}): |
| + return page.Cover.URL, imageCap |
| + } |
| + return "", 0 |
| +} |
diff --git a/internal/mapa/import_looks_test.go b/internal/mapa/import_looks_test.go| index d5bb86c..3a5f5e1 100644 |
| --- a/internal/mapa/import_looks_test.go |
| +++ b/internal/mapa/import_looks_test.go |
| @@ -5,6 +5,7 @@ import ( |
| "image" |
| "image/color" |
| "image/png" |
| + "math/rand/v2" |
| "strings" |
| "testing" |
| @@ -31,6 +32,25 @@ func widePicture(t *testing.T, width, height int) []byte { |
| return out.Bytes() |
| } |
| +// noisyPicture is a PNG of noise, w×h, too large in bytes for an icon |
| +// at 300×300. |
| +func noisyPicture(t *testing.T, width, height int) []byte { |
| + t.Helper() |
| + random := rand.New(rand.NewPCG(1, 2)) |
| + canvas := image.NewRGBA(image.Rect(0, 0, width, height)) |
| + for column := range width { |
| + for line := range height { |
| + canvas.Set(column, line, color.RGBA{uint8(random.IntN(256)), |
| + uint8(random.IntN(256)), uint8(random.IntN(256)), 255}) |
| + } |
| + } |
| + var out bytes.Buffer |
| + if err := png.Encode(&out, canvas); err != nil { |
| + t.Fatal(err) |
| + } |
| + return out.Bytes() |
| +} |
| + |
| // unhost takes a hosted file away, so its download fails. |
| func unhost(ws *notiontest.Workspace, url string) { |
| path := strings.TrimPrefix(url, strings.TrimSuffix( |
| @@ -49,6 +69,9 @@ func looksWorld(t *testing.T) (*importWorld, notiontest.Looks) { |
| wide := ws.Page("", notiontest.Text("Wide icon")) |
| ws.SetIcon(wide, notiontest.FileIcon(ws.Host("wide.png", |
| widePicture(t, 600, 10)))) |
| + heavy := ws.Page("", notiontest.Text("Heavy icon")) |
| + ws.SetIcon(heavy, notiontest.FileIcon(ws.Host("heavy.png", |
| + noisyPicture(t, 300, 300)))) |
| gone := ws.Page("", notiontest.Text("Lost icon")) |
| lost := ws.Host("lost.png", picture(t, 3)) |
| ws.SetIcon(gone, notiontest.FileIcon(lost)) |
| @@ -98,7 +121,7 @@ func TestI20IconsAreImported(t *testing.T) { |
| } |
| } |
| for _, title := range []string{"Notion icon", "Odd emoji", "Wide icon", |
| - "Lost icon", "Foreign emoji"} { |
| + "Heavy icon", "Lost icon", "Foreign emoji"} { |
| if _, record := world.lookOf(title); record.Icon != nil { |
| t.Errorf("%s was given an icon: %+v", title, record.Icon) |
| } |
| @@ -107,7 +130,7 @@ func TestI20IconsAreImported(t *testing.T) { |
| t.Errorf("%d images left pending: the wide icon holds none", pending) |
| } |
| report, _ := world.store.report(ctx(), run) |
| - want := map[string]int{lookIconSet: 1, lookEmoji: 1, lookIconLarge: 1, |
| + want := map[string]int{lookIconSet: 1, lookEmoji: 1, lookIconLarge: 2, |
| "couldn't be downloaded": 1, "not from Notion's file store": 1} |
| if report.Icons != 3 || !sameCounts(report.IconFailures, want) { |
| t.Errorf("the report's icons: %d, %+v", report.Icons, |
| @@ -201,6 +224,13 @@ func TestI24ALookChangedInNotionIsStyled(t *testing.T) { |
| t.Fatalf("the icon: %+v", record.Icon) |
| } |
| world.expectVerbs(page.ID, VerbCreated, VerbStyled) |
| + viewer, _ := world.store.Viewer(ctx(), ana, nil) |
| + list, err := world.store.History(ctx(), viewer, page.ID, 0) |
| + if err != nil || len(list.Versions) != 2 || !strings.HasSuffix( |
| + list.Versions[0].Summary, " (from Notion)") || |
| + strings.Contains(list.Versions[0].Summary, "edited there") { |
| + t.Errorf("the styled revision reads %+v, %v", list, err) |
| + } |
| if _, record := world.lookOf("Custom emoji icon"); record.Icon == nil || |
| record.Icon.Emoji != "📌" { |
| t.Errorf("a page styled in Mapa lost its icon: %+v", record.Icon) |
| @@ -240,3 +270,69 @@ func TestI24RenamedStyledEditedInOrder(t *testing.T) { |
| world.expectVerbs(page.ID, VerbCreated, VerbRenamed, VerbStyled, |
| VerbEdited) |
| } |
| + |
| +// A fix-up after a Resume rewrites a page that has an icon: the page |
| +// keeps it, with no styled revision (Fable on phase 4, L6). |
| +// |
| +// Mutation (make mutate): lookRecord gives no look when the run |
| +// prepared none. |
| +func TestI24AFixUpAfterAResumeKeepsTheIcon(t *testing.T) { |
| + ws := notiontest.NewWorkspace("fixup") |
| + alpha := ws.Page("", notiontest.Text("Alpha")) |
| + ws.SetIcon(alpha, notiontest.EmojiIcon("🚀")) |
| + beta := ws.Page("", notiontest.Text("Beta")) |
| + ws.Add(alpha, notiontest.Para(notiontest.PageMention(beta, "Beta"))) |
| + world := newImportWorld(t, ws) |
| + world.connect(ana) |
| + lease, err := world.store.StartRun(ctx(), ana, false) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + seen := 0 |
| + importCrash = func(point string) error { |
| + if point == "write:rendered" { |
| + if seen++; seen == 2 { |
| + world.store.CreateTeamPage(ctx(), bo, "Beta", "Bo's.") |
| + return errCrashed |
| + } |
| + } |
| + return nil |
| + } |
| + t.Cleanup(func() { importCrash = nil }) |
| + world.finish(lease, ana) |
| + importCrash = nil |
| + world.store.InterruptRuns(ctx()) |
| + world.resumeIfNeeded(lease) |
| + page, record := world.lookOf("Alpha") |
| + if record.Icon == nil || record.Icon.Emoji != "🚀" || |
| + !strings.Contains(record.Body, "Beta (Notion)") { |
| + t.Fatalf("Alpha after its fix-up: %+v", record) |
| + } |
| + world.expectVerbs(page.ID, VerbCreated, VerbEdited) |
| +} |
| + |
| +// A changed icon whose download fails for now leaves the page with the |
| +// icon it has: no revision now, and none to undo next run (Fable on |
| +// phase 4, L7). |
| +func TestI24APassingFailureKeepsTheIcon(t *testing.T) { |
| + ws := notiontest.NewWorkspace("passing") |
| + page := ws.Page("", notiontest.Text("Iconic")) |
| + ws.SetIcon(page, notiontest.FileIcon(ws.Host("one.png", picture(t, 1)))) |
| + world := newImportWorld(t, ws) |
| + world.useImages() |
| + world.connect(ana) |
| + world.importAs(ana) |
| + mine, before := world.lookOf("Iconic") |
| + next := ws.Host("two.png", picture(t, 2)) |
| + ws.SetIcon(page, notiontest.FileIcon(next)) |
| + unhost(ws, next) |
| + world.server.Reset() |
| + if run := world.importAs(ana); run.Updated != 0 || run.Unchanged != 1 { |
| + t.Fatalf("the re-run: %+v", run) |
| + } |
| + if _, after := world.lookOf("Iconic"); after.Icon == nil || |
| + *after.Icon != *before.Icon { |
| + t.Errorf("the icon went from %+v to %+v", before.Icon, after.Icon) |
| + } |
| + world.expectVerbs(mine.ID, VerbCreated) |
| +} |
diff --git a/internal/mapa/markup/testdata/corpus/import.json b/internal/mapa/markup/testdata/corpus/import.json| index 9725913..11524ef 100644 |
| --- a/internal/mapa/markup/testdata/corpus/import.json |
| +++ b/internal/mapa/markup/testdata/corpus/import.json |
| @@ -25,6 +25,7 @@ |
| {"name":"import/columns-empty","body":":::: columns\n\n::: column\n:::\n\n::: column\nB.\n\n:::\n\n::::"}, |
| {"name":"import/columns-widths","body":":::: columns\n\n::: column\nNarrow.\n\n:::\n\n::: column\nWide.\n\n:::\n\n::::"}, |
| {"name":"import/columns-even","body":":::: columns\n\n::: column\nHalf.\n\n:::\n\n::: column\nHalf too.\n\n:::\n\n::::"}, |
| +{"name":"import/columns-equal-ones","body":":::: columns\n\n::: column\nOne.\n\n:::\n\n::: column\nTwo.\n\n:::\n\n::::"}, |
| {"name":"import/tabs","body":"**First tab**\n\nIn it."}, |
| {"name":"import/synced","body":"Synced text.\n\nMirrored."}, |
| {"name":"import/synced-unshared","body":"> From Notion: a synced block whose original wasn't shared with the import."}, |
diff --git a/internal/mapa/markup/testdata/editor.json b/internal/mapa/markup/testdata/editor.json| index f047906..20d6a1a 100644 |
| --- a/internal/mapa/markup/testdata/editor.json |
| +++ b/internal/mapa/markup/testdata/editor.json |
| @@ -1,4 +1,4 @@ |
| -{"clean":"71b3d9b6135aaa191ce7b72a00d6f227a65b0254b00888707ab426a2b34e7fc5","bodies":[ |
| +{"clean":"f7c2a5944006373dafcf324c3bed5033ddc528fcdcde2cea77552bcf8f09b56d","bodies":[ |
| {"name":"edge/crlf","body":"# [[Acme]]Titl\n\n- # b\n\n![[fichas:c1]][[Acme#^b1|that]]","blocks":["heading:1","item:bullet_list:0:true","paragraph"]}, |
| {"name":"edge/lone-cr","body":"a\n\n*a\nb*\n\n- cword [[Acme]]\n- ---d~1. ~~|c\n\na","blocks":["paragraph","paragraph","item:bullet_list:0:true","item:bullet_list:0:false","paragraph"]}, |
| {"name":"edge/mixed-line-endings","body":" ^ab\n\n*word","blocks":["paragraph","paragraph"]}, |
| @@ -166,6 +166,7 @@ |
| {"name":"import/columns-empty","body":":::: columns\n\n::: column\n[ od a\n\n:::\n\n::: column\n![[fichas:c1]]\n\n:::\n\n::::","blocks":["columns","column","paragraph","column_end","column","paragraph","column_end","columns_end"]}, |
| {"name":"import/columns-widths","body":":::: columns\n\n::: column\nNarrow.\n\n:::\n\n::: column\nWid[ ] \ne[ ] .\n\n[[2026-11-12]]\n\n:::\n\n::::\n\n--","blocks":["columns","column","paragraph","column_end","column","paragraph","paragraph","column_end","columns_end","paragraph"]}, |
| {"name":"import/columns-even","body":":::: columns\n\n::: column\nHa# lf```.[ ] \n\n:::\n\n::: column\nHalf [[Acme#^b1|that]]too.\n\nHalf [[Acme#^b1|that]]too.\n\n:::\n\n::: column\n]a \n\nHalf [[Acme#^b1|that]]too.\n\nHalf [[Acme#^b1|that]] ^abtoo.\n\n:::\n\n::::","blocks":["columns","column","paragraph","column_end","column","paragraph","paragraph","column_end","column","paragraph","paragraph","paragraph","column_end","columns_end"]}, |
| +{"name":"import/columns-equal-ones","body":":::: columns\n\n::: column\nOn`e.---\n\n:::\n\n::: column\nTwo`.`\n\n:::\n\n::::","blocks":["columns","column","paragraph","column_end","column","paragraph","column_end","columns_end"]}, |
| {"name":"import/tabs","body":".**Firs**\n**t ta```b**\n\n.**Firs**\n**t tab**.**Firs**\n**t tab**\n\n![[fichas:c1]]```![[fichas:c1]]","blocks":["paragraph","paragraph","paragraph"]}, |
| {"name":"import/synced","body":"ced word word text.\n\nrrrroor*ed~~~*.","blocks":["paragraph","paragraph"]}, |
| {"name":"import/synced-unshared","body":"From Notion: a synced block whose or~~~iginal wasn't shared with **th**e import.From Notion: a synced block whose original wasn","blocks":["paragraph"]}, |
diff --git a/internal/mapa/markup/testdata/golden.json b/internal/mapa/markup/testdata/golden.json| index e31cd7b..3b415e7 100644 |
| --- a/internal/mapa/markup/testdata/golden.json |
| +++ b/internal/mapa/markup/testdata/golden.json |
| @@ -166,6 +166,7 @@ |
| {"name":"import/columns-empty","body":":::: columns\n\n::: column\n:::\n\n::: column\nB.\n\n:::\n\n::::","blocks":[{"kind":"columns","level":2,"ordered":false,"marker":"","start":0,"end":12,"source":":::: columns","plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":14,"end":24,"source":"::: column","column":1,"plain":"","spans":[]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":25,"end":28,"source":":::","column":1,"plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":30,"end":40,"source":"::: column","column":2,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":41,"end":43,"source":"B.","column":2,"plain":"B.","spans":[{"kind":"text","text":"B.","target":"","anchor":"","url":"","source":"B."}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":45,"end":48,"source":":::","column":2,"plain":"","spans":[]},{"kind":"columns_end","level":0,"ordered":false,"marker":"","start":50,"end":54,"source":"::::","plain":"","spans":[]}],"links":[],"images":[],"html":"<div mapa-columns=\"2\"><div mapa-column><p><br class=\"ProseMirror-trailingBreak\"></p></div><div mapa-column><p>B.</p></div></div><p><br class=\"ProseMirror-trailingBreak\"></p>"}, |
| {"name":"import/columns-widths","body":":::: columns\n\n::: column\nNarrow.\n\n:::\n\n::: column\nWide.\n\n:::\n\n::::","blocks":[{"kind":"columns","level":2,"ordered":false,"marker":"","start":0,"end":12,"source":":::: columns","plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":14,"end":24,"source":"::: column","column":1,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":25,"end":32,"source":"Narrow.","column":1,"plain":"Narrow.","spans":[{"kind":"text","text":"Narrow.","target":"","anchor":"","url":"","source":"Narrow."}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":34,"end":37,"source":":::","column":1,"plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":39,"end":49,"source":"::: column","column":2,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":50,"end":55,"source":"Wide.","column":2,"plain":"Wide.","spans":[{"kind":"text","text":"Wide.","target":"","anchor":"","url":"","source":"Wide."}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":57,"end":60,"source":":::","column":2,"plain":"","spans":[]},{"kind":"columns_end","level":0,"ordered":false,"marker":"","start":62,"end":66,"source":"::::","plain":"","spans":[]}],"links":[],"images":[],"html":"<div mapa-columns=\"2\"><div mapa-column><p>Narrow.</p></div><div mapa-column><p>Wide.</p></div></div><p><br class=\"ProseMirror-trailingBreak\"></p>"}, |
| {"name":"import/columns-even","body":":::: columns\n\n::: column\nHalf.\n\n:::\n\n::: column\nHalf too.\n\n:::\n\n::::","blocks":[{"kind":"columns","level":2,"ordered":false,"marker":"","start":0,"end":12,"source":":::: columns","plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":14,"end":24,"source":"::: column","column":1,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":25,"end":30,"source":"Half.","column":1,"plain":"Half.","spans":[{"kind":"text","text":"Half.","target":"","anchor":"","url":"","source":"Half."}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":32,"end":35,"source":":::","column":1,"plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":37,"end":47,"source":"::: column","column":2,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":48,"end":57,"source":"Half too.","column":2,"plain":"Half too.","spans":[{"kind":"text","text":"Half too.","target":"","anchor":"","url":"","source":"Half too."}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":59,"end":62,"source":":::","column":2,"plain":"","spans":[]},{"kind":"columns_end","level":0,"ordered":false,"marker":"","start":64,"end":68,"source":"::::","plain":"","spans":[]}],"links":[],"images":[],"html":"<div mapa-columns=\"2\"><div mapa-column><p>Half.</p></div><div mapa-column><p>Half too.</p></div></div><p><br class=\"ProseMirror-trailingBreak\"></p>"}, |
| +{"name":"import/columns-equal-ones","body":":::: columns\n\n::: column\nOne.\n\n:::\n\n::: column\nTwo.\n\n:::\n\n::::","blocks":[{"kind":"columns","level":2,"ordered":false,"marker":"","start":0,"end":12,"source":":::: columns","plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":14,"end":24,"source":"::: column","column":1,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":25,"end":29,"source":"One.","column":1,"plain":"One.","spans":[{"kind":"text","text":"One.","target":"","anchor":"","url":"","source":"One."}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":31,"end":34,"source":":::","column":1,"plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":36,"end":46,"source":"::: column","column":2,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":47,"end":51,"source":"Two.","column":2,"plain":"Two.","spans":[{"kind":"text","text":"Two.","target":"","anchor":"","url":"","source":"Two."}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":53,"end":56,"source":":::","column":2,"plain":"","spans":[]},{"kind":"columns_end","level":0,"ordered":false,"marker":"","start":58,"end":62,"source":"::::","plain":"","spans":[]}],"links":[],"images":[],"html":"<div mapa-columns=\"2\"><div mapa-column><p>One.</p></div><div mapa-column><p>Two.</p></div></div><p><br class=\"ProseMirror-trailingBreak\"></p>"}, |
| {"name":"import/tabs","body":"**First tab**\n\nIn it.","blocks":[{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":0,"end":13,"source":"**First tab**","plain":"**First tab**","spans":[{"kind":"text","text":"**First tab**","target":"","anchor":"","url":"","source":"**First tab**"}]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":15,"end":21,"source":"In it.","plain":"In it.","spans":[{"kind":"text","text":"In it.","target":"","anchor":"","url":"","source":"In it."}]}],"links":[],"images":[],"html":"<p><strong>First tab</strong></p><p>In it.</p>"}, |
| {"name":"import/synced","body":"Synced text.\n\nMirrored.","blocks":[{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":0,"end":12,"source":"Synced text.","plain":"Synced text.","spans":[{"kind":"text","text":"Synced text.","target":"","anchor":"","url":"","source":"Synced text."}]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":14,"end":23,"source":"Mirrored.","plain":"Mirrored.","spans":[{"kind":"text","text":"Mirrored.","target":"","anchor":"","url":"","source":"Mirrored."}]}],"links":[],"images":[],"html":"<p>Synced text.</p><p>Mirrored.</p>"}, |
| {"name":"import/synced-unshared","body":"> From Notion: a synced block whose original wasn't shared with the import.","blocks":[{"kind":"quote","level":0,"ordered":false,"marker":"","start":0,"end":75,"source":"> From Notion: a synced block whose original wasn't shared with the import.","plain":"From Notion: a synced block whose original wasn't shared with the import.","spans":[{"kind":"text","text":"From Notion: a synced block whose original wasn't shared with the import.","target":"","anchor":"","url":"","source":"From Notion: a synced block whose original wasn't shared with the import."}]}],"links":[],"images":[],"html":"<blockquote><p>From Notion: a synced block whose original wasn't shared with the import.</p></blockquote><p><br class=\"ProseMirror-trailingBreak\"></p>"}, |
diff --git a/internal/mapa/notionmd/blocks.go b/internal/mapa/notionmd/blocks.go| index 29e02a7..6dcb970 100644 |
| --- a/internal/mapa/notionmd/blocks.go |
| +++ b/internal/mapa/notionmd/blocks.go |
| @@ -163,16 +163,24 @@ func (mapper *mapper) columns(block Block, _ int) { |
| } |
| // unevenWidths is columns whose width ratios differ: Mapa's layouts are |
| -// even, so the widths are counted (columns and icons spec §6.2). A |
| -// column with no ratio is an even share. |
| +// even, so the widths are counted (columns and icons spec §6.2). When |
| +// every column has a ratio they are compared with each other, whatever |
| +// they sum to (Fable on phase 4, L5); a column with none is an even |
| +// share, 1/n, against which the others are compared. |
| func unevenWidths(columns []Block) bool { |
| - even := 1 / float64(len(columns)) |
| + share := columns[0].WidthRatio |
| + for _, column := range columns { |
| + if column.WidthRatio == 0 { |
| + share = 1 / float64(len(columns)) |
| + break |
| + } |
| + } |
| for _, column := range columns { |
| ratio := column.WidthRatio |
| if ratio == 0 { |
| - ratio = even |
| + ratio = 1 / float64(len(columns)) |
| } |
| - if ratio-even > 0.001 || even-ratio > 0.001 { |
| + if ratio-share > 0.001*share || share-ratio > 0.001*share { |
| return true |
| } |
| } |
diff --git a/internal/mapa/notionmd/fixtures_blocks_test.go b/internal/mapa/notionmd/fixtures_blocks_test.go| index aee4552..12d545b 100644 |
| --- a/internal/mapa/notionmd/fixtures_blocks_test.go |
| +++ b/internal/mapa/notionmd/fixtures_blocks_test.go |
| @@ -92,6 +92,14 @@ func containerFixtures() []fixture { |
| with(Block{Type: "column", Known: true, WidthRatio: 0.5}, |
| para(txt("Half."))), |
| with(Block{Type: "column", Known: true}, para(txt("Half too."))))), |
| + // Equal ratios that do not sum to 1 are even (Fable on phase 4, |
| + // L5). |
| + page("columns-equal-ones", with(Block{Type: "column_list", |
| + Known: true}, |
| + with(Block{Type: "column", Known: true, WidthRatio: 1}, |
| + para(txt("One."))), |
| + with(Block{Type: "column", Known: true, WidthRatio: 1}, |
| + para(txt("Two."))))), |
| page("tabs", with(blk("tab", txt("First tab")), para(txt("In it.")))), |
| page("synced", with(Block{Type: "synced_block", Known: true}, |
| para(txt("Synced text."))), with(Block{Type: "synced_block", |
diff --git a/internal/mapa/notionmd/testdata/fixtures/columns-equal-ones.json b/internal/mapa/notionmd/testdata/fixtures/columns-equal-ones.json| new file mode 100644 |
| index 0000000..a256dd7 |
| --- /dev/null |
| +++ b/internal/mapa/notionmd/testdata/fixtures/columns-equal-ones.json |
| @@ -0,0 +1,54 @@ |
| +{ |
| + "name": "columns-equal-ones", |
| + "page": { |
| + "id": "page-columns-equal-ones", |
| + "seq": 0, |
| + "blocks": [ |
| + { |
| + "id": "", |
| + "type": "column_list", |
| + "known": true, |
| + "children": [ |
| + { |
| + "id": "", |
| + "type": "column", |
| + "known": true, |
| + "width": 1, |
| + "children": [ |
| + { |
| + "id": "", |
| + "type": "paragraph", |
| + "known": true, |
| + "text": [ |
| + { |
| + "type": "text", |
| + "text": "One." |
| + } |
| + ] |
| + } |
| + ] |
| + }, |
| + { |
| + "id": "", |
| + "type": "column", |
| + "known": true, |
| + "width": 1, |
| + "children": [ |
| + { |
| + "id": "", |
| + "type": "paragraph", |
| + "known": true, |
| + "text": [ |
| + { |
| + "type": "text", |
| + "text": "Two." |
| + } |
| + ] |
| + } |
| + ] |
| + } |
| + ] |
| + } |
| + ] |
| + } |
| +} |
diff --git a/internal/mapa/notionmd/testdata/golden/columns-equal-ones.json b/internal/mapa/notionmd/testdata/golden/columns-equal-ones.json| new file mode 100644 |
| index 0000000..6337d24 |
| --- /dev/null |
| +++ b/internal/mapa/notionmd/testdata/golden/columns-equal-ones.json |
| @@ -0,0 +1,5 @@ |
| +{ |
| + "result": { |
| + "Body": "" |
| + } |
| +} |
diff --git a/internal/mapa/notionmd/testdata/golden/columns-equal-ones.md b/internal/mapa/notionmd/testdata/golden/columns-equal-ones.md| new file mode 100644 |
| index 0000000..0990daa |
| --- /dev/null |
| +++ b/internal/mapa/notionmd/testdata/golden/columns-equal-ones.md |
| @@ -0,0 +1,13 @@ |
| +:::: columns |
| + |
| +::: column |
| +One. |
| + |
| +::: |
| + |
| +::: column |
| +Two. |
| + |
| +::: |
| + |
| +:::: |
diff --git a/scripts/mutate/import_looks.go b/scripts/mutate/import_looks.go| index afa5ff1..4e03a2c 100644 |
| --- a/scripts/mutate/import_looks.go |
| +++ b/scripts/mutate/import_looks.go |
| @@ -2,8 +2,9 @@ package main |
| // The columns and icons spec's mutations for the importer's looks |
| // (§6.1, §6.4, §9): an emoji icon written unchecked, an external cover |
| -// fetched without asking the pin, a look left out of "unchanged", and |
| -// the styled revision skipped. |
| +// fetched without asking the pin, a look left out of "unchanged", the |
| +// styled revision skipped, an icon's two limits, and a fix-up dropping |
| +// the look it did not prepare. |
| const ( |
| importLooksGo = "internal/mapa/import_looks.go" |
| @@ -20,9 +21,9 @@ var importLookMutations = []mutation{ |
| {gate: "I21", test: "TestI21CoversAreImportedFromThePinOnly", pkg: inside, |
| name: "an external cover fetched without asking the pin", |
| edits: []edit{{file: importLooksGo, |
| - from: "\tif cover.Type != notion.FileHosted && " + |
| - "!job.files.Allowed(cover.URL) {", |
| - to: "\tif false {"}}}, |
| + from: "(cover.Type == notion.FileExternal && " + |
| + "job.files.Gallery(cover.URL))", |
| + to: "cover.Type == notion.FileExternal"}}}, |
| {gate: "I24", test: "TestI24ALookChangedInNotionIsStyled", pkg: inside, |
| name: "unchanged decided without the look", |
| edits: []edit{{file: importWriteGo, |
| @@ -35,4 +36,20 @@ var importLookMutations = []mutation{ |
| from: "\t\tif err := tx.importStyle(&page, &record, actor, " + |
| "write); err != nil {", |
| to: "\t\tif err := error(nil); err != nil {"}}}, |
| + {gate: "I20", test: "TestI20IconsAreImported", pkg: inside, |
| + name: "an icon over 512 pixels a side kept", |
| + edits: []edit{{file: importLooksGo, |
| + from: "if pseudo == iconPlace && added.Side() > MaxIconSide {", |
| + to: "if pseudo == iconPlace && added.Side() > 1<<20 {"}}}, |
| + {gate: "I20", test: "TestI20IconsAreImported", pkg: inside, |
| + name: "an icon fetched with the 10 MB cap", |
| + edits: []edit{{file: importLooksGo, |
| + from: "\t\treturn page.Icon.URL, MaxIconBytes", |
| + to: "\t\treturn page.Icon.URL, imageCap"}}}, |
| + {gate: "I24", test: "TestI24AFixUpAfterAResumeKeepsTheIcon", pkg: inside, |
| + name: "a fix-up with no prepared look writes none", |
| + edits: []edit{{file: importWriteGo, |
| + from: "\t\treturn Record{Icon: entry.current.Icon, " + |
| + "Banner: entry.current.Banner}", |
| + to: "\t\treturn Record{}"}}}, |
| } |