oficina / mapa Public

Import: answer Fable's review of the real-workspace fixes

M1: re-pinned to the module whose fake signs every file URL afresh, as
Notion does; the mutation "the file key is the signed URL" turns I14
red. L1: a downloaded image is kept under the key of the file fetched,
not the staged one. L5: a permanent refusal is retried once its file is
replaced, gated. Spec §12's permanent refusals corrected, §19 step 5
checks the key's premises, §25 note 17 records the review.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 74e14410564bd2e02c6033e5a10268e067db261e parent 8ba8887
6 files changed, +92 −24
  • docs/superpowers/specs/2026-11-17-notion-import.md +13 −2
  • go.mod +1 −1
  • go.sum +2 −2
  • internal/mapa/import_images.go +25 −18
  • internal/mapa/import_images_test.go +37 −1
  • scripts/mutate/mutations_import.go +14 −0

CI failed — run details

CI log
=== editor ===
cd editor && npm ci --no-audit --no-fund --loglevel=error

added 16 packages in 316ms
cd editor && node build-bundles.mjs
wrote internal/mapa/static/editor.115ddee5d3f54787.js (354112 bytes, 111.2KB gzipped; L12 budget 120KB)
cd editor && node --test
✔ a badge is named for what it does, starting with its visible word (0.771522ms)
✔ first words stop at five words or forty characters (0.126164ms)
✔ the field keeps one trimmed line, without brackets (0.200532ms)
✔ the field holds at most MaxAlt bytes, cut at a character (0.299827ms)
✔ days and weeks move across months and years (0.855989ms)
✔ a month keeps the day, or takes the month's last (0.240857ms)
✔ the grid is six weeks from Monday, as the month calendar draws it (0.556363ms)
✔ the grid starts the week where the locale does (0.547927ms)
✔ the keys move a day, a week, a month and a year (0.222113ms)
✔ the picked day is the chip [[ makes for a date (13.050875ms)
✔ Insert → Today's date still puts today in at once (5.000924ms)
✔ / offers Date, the picker, and Today's date beside it (0.278817ms)
✔ after a ! the chip goes in after a space, never as an embed (2.217556ms)
✔ where the Markdown would read the chip differently, it is refused (2.252301ms)
✔ over a selection the chip goes after it and the words stay (2.192059ms)
✔ today is the day in the viewer's zone (18.77502ms)
✔ every offered locale has cases (1.00216ms)
✔ dates.mjs writes every date Go writes, byte for byte (3.542506ms)
✔ a chip, the month and the week, in three locales (0.591719ms)
✔ dates.json is what ICU gives, byte for byte (482.109138ms)
✔ L1: mounting then serialising gives cleanBody(body), byte for byte (78.754157ms)
ℹ 871 bodies
✔ L1: mounting a stored body adds nothing, and saving it writes nothing new (78.60418ms)
✔ L2: one edited block changes only that block's bytes; undo gives the body back (124.214273ms)
ℹ 858 single-block edits
✔ L2: inserting or deleting a block changes bytes only at the new seams, by Join (133.314556ms)
ℹ 866 inserts, 817 deletes
✔ L3: seeded edits keep the document and its Markdown saying the same thing (4898.095086ms)
ℹ 20904 edits over 871 bodies
✔ L3: Link to a page makes exactly one chip, and changes nothing else (1126.710668ms)
ℹ 4532 links over 871 bodies; refused: {"A page link can’t hold another link or a line break. Select plain words.":918,"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 (1106.979862ms)
ℹ over 871 bodies: {"inserted":5158,"spaced":23,"refused":45,"unstable":9}
✔ linear: trailing spaces (32.493276ms)
✔ linear: trailing whitespace (17.005046ms)
✔ linear: unclosed web links (27.387498ms)
✔ linear: web links with no address (35.587359ms)
✔ linear: unclosed wiki links (39.058492ms)
✔ linear: unclosed embeds (19.782291ms)
✔ linear: closes only (5.275512ms)
✔ the selected words become the chip's shown text (11.687876ms)
✔ words that are the title make a plain [[Title]] (3.915668ms)
✔ spaces at the selection's edges stay outside the chip (1.214194ms)
✔ a date makes a date link, in a heading, an item and a quote (5.379447ms)
✔ bold words lose their bold: a chip carries no marks in Mapa's Markdown (1.023229ms)
✔ only the linked block's bytes change, and undo gives the body back (2.681958ms)
✔ a selection across blocks, over a chip or a break, or of brackets is refused (1.085204ms)
✔ a target the words cannot be linked to as typed is refused (0.208958ms)
✔ ⌘L: over a selection it opens Page link; with none it types [[; in code it does nothing (2.022374ms)
✔ web-linked words are refused: the address would be lost (review M4) (1.502027ms)
✔ words whose Markdown would read otherwise are refused (review M3) (1.423642ms)
✔ ⌘A then ⌘L says why, instead of doing nothing (review low 1) (0.698446ms)
✔ linkCheck says why it refuses (review low 2) (1.310502ms)
✔ golden file has bodies (0.787391ms)
✔ markup.mjs parses every body into Go's blocks, byte offsets and all (34.334434ms)
✔ markup.mjs strips and spans every block as Go does (54.871436ms)
✔ the schema's toDOM draws every body as Go renders it (68.847468ms)
✔ emphasis draws the four pinned outputs (19.075409ms)
✔ a body ends in the editor's empty paragraph (0.245215ms)
✔ the editor labels date chips as Go does, in every locale L4 holds (13.340252ms)
✔ a POST that never answers is aborted after the timeout (21.133179ms)
✔ a keepalive POST carries no signal, and an answer clears the timer (1.198915ms)
✔ autosave sends only what differs, and the tab owns the draft it wrote (10.072659ms)
✔ an offered draft never commits by itself; Save commits it (1.320651ms)
✔ reload, then close: sessionStorage says the draft is this tab's own (0.552946ms)
✔ closing carries text not yet sent, and the cap leaves it out (43.275109ms)
✔ clean rebase: applied, the caret survives, the base moves by the rebase POST (4.538044ms)
✔ the block under the caret is the teammate's too, and undo brings back yours (4.234231ms)
✔ typing mid-flight: the merge is not applied and the base does not move (1.866845ms)
✔ a merge the editor cannot represent stops after three tries (4.533745ms)
✔ a conflict is shown, locks the editor's own commits, and Resolve settles it (1.464148ms)
✔ leaving: a conflict stays with the choice; a failed flush offers Leave anyway; a stored draft leaves (1.739049ms)
✔ a stale tab shows the newer draft, offered, and never overwrites it (1.065337ms)
✔ the first scratch commit: empty creates nothing, then one page, then drafts on it (0.871528ms)
✔ noBase and gone lead to the existing choices (0.828548ms)
✔ a commit that merged is applied when nothing was typed since (1.073513ms)
✔ back from the cache: nothing unsaved reloads, unsaved text autosaves at once (8.245285ms)
✔ an own draft committed meanwhile goes on as a new draft (1.462525ms)
✔ a reload keeps a stored draft; unsent text still commits (0.572583ms)
✔ a page deleted mid-edit: what is typed is still stored as the draft, and nothing commits (H1) (1.29256ms)
✔ an offered draft committed in another tab: typing goes on as a new draft (H1) (2.918718ms)
✔ a commit reply without a revision is not a commit; an emptied day starts afresh (H2) (1.449721ms)
✔ Resolve stores what was typed first, and takes no typing until its answer is applied (M1) (8.364295ms)
✔ closing with a choice open, or commits held, still writes the text, never commits (M2) (1.142201ms)
✔ closing inside the settling window sends the loaded version with settling=1 (M3) (0.333138ms)
✔ a clean merge not applied because of typing still ends the choice on show (M4) (1.015956ms)
✔ settling finds the draft committed with a teammate's text: a close still writes (M-A) (0.485431ms)
✔ settling finds another tab's newer draft: the tab shows it before any typing (0.767315ms)
✔ a page deleted before the first autosave: the text is offered as a scratch page, and a close makes one (M-B) (0.532338ms)
✔ an autosave that never answered but landed: its 409 keeps the typing since (L3) (0.6409ms)
✔ marks: em outside strong, bold reopened around italics, edges outside (5.313955ms)
✔ marks close before code, links and atoms, and reopen after (0.485982ms)
✔ untouched blocks and atoms re-emit their source; edited atoms are written from attributes (7.292157ms)
✔ empty blocks are written as nothing (2.938955ms)
✔ an unclosed fence that is no longer last gets its closing fence (1.521864ms)
✔ the structure check puts Join's seam where a kept one would merge two blocks (1.875531ms)
✔ prepareSave adopts the parse when no seam or rewrite can save the document (4.918671ms)
✔ reparse: typed emphasis becomes a mark, "- " after a break becomes an item (2.526721ms)
✔ a trailing hard break stays on screen and is written as nothing (1.015124ms)
✔ the reparse waits while an IME is composing (0.691263ms)
✔ copied blocks paste with their bytes and seams; a cut and paste gives the body back (4.689945ms)
✔ a forged x-mapa slice is refused, and text from outside is read as Markdown (0.674091ms)
✔ rebuild changes origins only, outside undo history (1.592476ms)
✔ applyBody takes a teammate's block, keeps the caret, and ends untouched (1.488443ms)
✔ a block whose context changed is written again: a task toggled, a bullet, a quote (4.452055ms)
✔ a duplicate ^id typed above its holder never takes the id from it (1.560507ms)
✔ a copy-dragged block is reparsed, and says what its Markdown says (1.177576ms)
✔ a history command that throws is refused, never thrown (4.970315ms)
✔ an image re-emits its source, and an edited alt changes only its span (1.265068ms)
✔ a paste whose image copy is refused says why and pastes nothing (16.907396ms)
✔ a line of image openers reads in linear time (102.659091ms)
✔ a line of shared link address reads in linear time (12.835055ms)
✔ a line of shared web address reads in linear time (55.167465ms)
✔ one rename at a time, from either field (2.134862ms)
✔ an empty or unchanged title sends nothing (0.211753ms)
✔ a refusal keeps what was typed, and the title (0.257157ms)
✔ the pending state holds for the busy rule (8.465414ms)
✔ a failed POST says so and keeps the title (0.447731ms)
✔ Update links posts the confirm page's POST (0.255294ms)
✔ clean is CleanTitle's whitespace rule (0.131695ms)
✔ the saver's base follows a rename made over it, and only that (0.31749ms)
✔ closing sends the rename as one keepalive POST (1.78337ms)
✔ the port answers every shared case as typeddate.go does (7.549534ms)
✔ numbers follow the locale: 12/11 is November in en-IE, December in en-US (0.299055ms)
✔ M6: several files land in the order they were chosen (45.109674ms)
✔ M5: one Backspace before the box keeps the image where the box is (11.710998ms)
✔ M5: undoing text typed just before the box keeps the upload (12.867696ms)
✔ L12: a failed upload an undo takes away does not stall the next (14.607626ms)
✔ M4: Replace… keeps the old image until the new one is in, and its alt (13.565751ms)
✔ M3 and N1: text wins, except over a picture copied from a page (1.638772ms)
✔ N2: a JPEG over 10 MB is scaled before its size is checked (4.657326ms)
✔ a drag whose anchor the document no longer reaches selects to its end (5.239777ms)
ℹ tests 126
ℹ suites 0
ℹ pass 126
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 7689.911413
=== 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.
scripts/mutate/mutations_import.go line 301: 90 columns wide, over the 80 allowed. Wrap the line, or add a record with a reason to .rastrillo/code.txt.
rastrillo: budget code: 1 problem
make: *** [Makefile:69: code] Error 1

amadan: step code failed: exit status 2

amadan: job failed at step code — its output is above, not at the tail of this log
diff --git a/docs/superpowers/specs/2026-11-17-notion-import.md b/docs/superpowers/specs/2026-11-17-notion-import.md
index aa4a147..95097d6 100644
--- a/docs/superpowers/specs/2026-11-17-notion-import.md
+++ b/docs/superpowers/specs/2026-11-17-notion-import.md
@@ -447,7 +447,7 @@ Mapa has **no escapes** (level-up D11). The editor accepts that because a person
- **Commit as it goes** (images §7). Images are downloaded and added only for the page about to be written, and that page is committed before the next page's images are added. So pending images never pile up against the runner's own allowance. **If the page's write returns *kept* or fails, the run deletes that page's pending images at once**, through the images spec's removal (one transaction, `removed`, the runner as actor, §3.2 item 3's shape), so nothing holds quota for seven days.
- **The lease is checked just before each `AddImage` and `CopyImage`.** Those are their own writes, outside the page transaction. The one gap left: a lease that moves between the check and the call lets one pending image be added by a run that no longer holds it. It is never attached, and the sweep removes it after seven days. That is the named exception to §8.3's "changes nothing".
- **Reuse.** `notion_images` maps (Notion block, Mapa page) to the Mapa image's public id, sealed. An unchanged block on the same page reuses it, after the run checks, in its own read, that the image row still exists and is attached to that page; one the sweep or a member's "Remove from Mapa" took away is fetched again. **A block that moves to another page**, or a synced block that shows one Notion file on several pages, is found by its block alone (`block_print`, §15), and gets `CopyImage` from the existing Mapa image where the runner may read it, and a fresh download otherwise.
-- **A failure is not the page's failure.** A refused or failed image becomes the images spec's text line, `(Image not imported: <file name>, <reason>)`, the file name taken from the last segment of Notion's file URL path, decoded (or the caption when the path has none),, in its place, and the page is written. The report counts images by reason. **A permanent refusal** (type, size, dimensions, host not allowed) is recorded on its `notion_images` row with the file's key and is not downloaded again until the block shows another file (§25 note 17). **A transient one** (network, 429, 5xx, an expired URL) is tried again on the next run.
+- **A failure is not the page's failure.** A refused or failed image becomes the images spec's text line, `(Image not imported: <file name>, <reason>)`, the file name taken from the last segment of Notion's file URL path, decoded (or the caption when the path has none),, in its place, and the page is written. The report counts images by reason. **A permanent refusal** (type, size, dimensions; a host the pin refuses is transient, since §19 step 4 may yet add it: build round 3, L5) is recorded on its `notion_images` row with the file's key and is not downloaded again until the block shows another file (§25 note 17). **A transient one** (network, 429, 5xx, an expired URL, a host not allowed) is tried again on the next run.
- **Quota.** Notion's block objects carry no file size, so the run cannot total the images before it starts. Instead, the Start page shows **both** allowances the images spec checks: the team's (`MAPA_IMAGE_QUOTA_TEAM`) and the runner's own (`MAPA_IMAGE_QUOTA_PERSON`, which counts their pending and private images). `ErrImageQuota` can come from either. On the first one, the run reads both figures to say which, and stops downloading for the rest of that run: every later image becomes the text line, and the report says at the top which allowance is full. Raising that allowance, or freeing the runner's own, and running again fills them in, because those pages render differently and are still untouched (§13.2). `ErrNoImageStore` does the same from the first image: "images aren't set up on this Mapa yet".
- **External images** stay links (D13). The images spec leaves fetching them to this spec (its §7), and this spec does not propose it. **Q2** asks Paul.
- **Literal image syntax.** Notion text that happens to read `![…](/i/…)` would become an image reference once the images spec is built. §11.4 neutralises it.
@@ -655,7 +655,7 @@ Against Paul's workspace. **Read-only on Notion's side**, owned by Paul, and a s
2. He shares a small set of top-level pages with it, a few hundred pages at most for the first run, not the workspace root.
3. `cmd/notion-record` records that set, from Paul's machine, into a directory outside every repository. Scrub it, commit the scrubbed fixtures to the module, delete the raw recording. Compare its block types with §10.1: any type not in the table is added to the table before the run.
4. Check the image file URLs in the recording against the file transport's (host, path prefix) pairs. Fix the allowlist from what Notion actually sends, not from the documentation's one example. **Expect a virtual-hosted bucket**, for example `prod-files-secure.s3.us-west-2.amazonaws.com` with the workspace id as the first path segment: it is its own pair, host and prefix both, never the host alone. **Done, by the first read-only run** (831 objects, 158 pages): all 144 hosted files were at `https://prod-files-secure.s3.us-west-2.amazonaws.com/<workspace id>/<file id>/<name>`, which the documented pair refused. That host is now its own pair, prefix `/` (§25 note 17).
-5. Check whether Notion rounds `last_edited_time` to the minute: image reuse and copies compare a block's edit time (§12), so two edits within a minute would look like one. **Done, by the first read-only run: it does**, all 3,815 edit times ended in `:00`. Image reuse and copies now compare the file's key; pages were already decided on the rendered body (§13.2), now gated for an edit in the same minute (§25 note 17). User mentions came back `@Anonymous`: the integration lacked step 1's user information, which Paul turns on; with it the import writes the name (§11.2; I1's `@Ana`, notionmd's `mentions-other`). Check that user mentions carry names (§11.2), what a synced block's copy returns for its children (§10.1), and whether `GET /v1/users/me` carries a workspace id (§8.3). **If it carries none, the map's workspace is matched by name** (§25.8): two workspaces with one name pass as one, and a workspace renamed in Notion is refused as another until the import is forgotten. Record which it is in the build notes before the run on `paulca`.
+5. Check whether Notion rounds `last_edited_time` to the minute. **Done, by the first read-only run: it does**, all 3,815 edit times ended in `:00`. Image reuse and copies, which compared a block's edit time, now compare the file's key; pages were already decided on the rendered body (§13.2), now gated for an edit in the same minute (§25 note 17). **Still to check, before the run on `paulca`:** the file key's two premises. Record the same set twice and diff the keys (an unchanged file's path must be the same on every read, or every run fetches every image again); then replace one image in Notion, record again, and see its key move (a replaced file must get a new file id, or the import keeps the old picture). User mentions came back `@Anonymous`: the integration lacked step 1's user information, which Paul turns on; with it the import writes the name (§11.2; I1's `@Ana`, notionmd's `mentions-other`). Check that user mentions carry names (§11.2), what a synced block's copy returns for its children (§10.1), and whether `GET /v1/users/me` carries a workspace id (§8.3). **If it carries none, the map's workspace is matched by name** (§25.8): two workspaces with one name pass as one, and a workspace renamed in Notion is refused as another until the import is forgotten. Record which it is in the build notes before the run on `paulca`.
**The run, on the `test` team first** (`test.mapa.oficina.works`, disposable)
6. Connect, run, and watch the status page through to the end.
@@ -929,6 +929,17 @@ Where the build chose, or departed:
`TestI14AnImageReplacedInTheSameMinuteIsFetched`, and the copy's
`TestI14AChangedSharedImageIsFetchedOnce`, now replace the file
without moving the edit time; each has a mutation.
+ - **Fable's review of this change: CHANGES REQUIRED, answered.** M1:
+ the fake signed every file URL alike, so no gate could tell a key
+ that kept the signature; the fake now signs every read afresh, as
+ Notion does (module test and mutation), and Mapa's mutation "the
+ file key is the signed URL" turns I14 red. L1: a file replaced
+ between Survey and Write is kept under the key of what was
+ downloaded, not the staged one
+ (`TestI14AFileReplacedMidRunIsKeyedAsDownloaded`). L3: the key drops
+ the port. L5: a permanent refusal is retried once the file is
+ replaced, gated. L2: §19 step 5 now checks the key's premises. L6:
+ §12's permanent refusals corrected (a refused host is transient).
### Fable's review of the build (2026-11-17): CHANGES REQUIRED, answered
diff --git a/go.mod b/go.mod
index d2a7373..853880a 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-20261122103431-770a9bb3668f
+ amadan.net/oficina/notion.git v0.0.0-20261122104455-e5964756a145
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 14e1ead..d436b0d 100644
--- a/go.sum
+++ b/go.sum
@@ -1,7 +1,7 @@
amadan.net/oficina/estilo.git v0.0.0-20261118055615-d004805f40f2 h1:E2+IhBdGcjhX3IX8UgQj5t6Bu+4zkGG0J+W1CIeoTAo=
amadan.net/oficina/estilo.git v0.0.0-20261118055615-d004805f40f2/go.mod h1:2UFIFrbTrhew8EFM0C94WmTo2OASM2pHEgT4jzeE/s8=
-amadan.net/oficina/notion.git v0.0.0-20261122103431-770a9bb3668f h1:i1B5WWVVLUmMvOSJ+T31PTvCuoDKMtVgBmHnFeRb1Zo=
-amadan.net/oficina/notion.git v0.0.0-20261122103431-770a9bb3668f/go.mod h1:2WuyjBTLHwurTGri00zfPxSKc9b3pomdT6wSs/UIvA4=
+amadan.net/oficina/notion.git v0.0.0-20261122104455-e5964756a145 h1:lQfT6o8lVXTXImeIlm52bEys0vlFdP4VD6yPn8TPf7g=
+amadan.net/oficina/notion.git v0.0.0-20261122104455-e5964756a145/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_images.go b/internal/mapa/import_images.go
index 315a010..9ca36fe 100644
--- a/internal/mapa/import_images.go
+++ b/internal/mapa/import_images.go
@@ -188,10 +188,15 @@ func sameFile(kept, now string) bool {
func (job *importJob) freshImage(ctx context.Context, entry *importEntry,
block notionmd.Block, alt string, placed placedImage) (gotImage,
error) {
- added, reason, err := job.addImage(ctx, entry, block)
+ added, fetched, reason, err := job.addImage(ctx, entry, block)
if err != nil {
return gotImage{}, err
}
+ if fetched != "" {
+ // The file downloaded is the one kept: a file replaced since
+ // Survey read the block is keyed as the bytes are (Fable L1).
+ placed.key = fetched
+ }
if reason.text != "" {
placed.reason, placed.permanent = reason.text, reason.permanent
return gotImage{reason: reason.text, placed: placed}, nil
@@ -207,12 +212,12 @@ type refusal struct {
permanent bool
}
-// addImage copies or downloads one image and adds it. A refusal is a
-// reason, not an error: the image becomes its line and the page is
-// written. Only what stops the run (a lost lease, the token refused) is
-// an error.
+// addImage copies or downloads one image and adds it, and answers the
+// key of the file it downloaded, if it did. A refusal is a reason, not
+// an error: the image becomes its line and the page is written. Only
+// what stops the run (a lost lease, the token refused) is an error.
func (job *importJob) addImage(ctx context.Context, entry *importEntry,
- block notionmd.Block) (AddedImage, refusal, error) {
+ block notionmd.Block) (AddedImage, string, refusal, error) {
id := block.ID
if job.imagesStopped == "" {
if err := job.images.Ready(ctx); err != nil {
@@ -220,42 +225,44 @@ func (job *importJob) addImage(ctx context.Context, entry *importEntry,
}
}
if job.imagesStopped != "" {
- return nil, refusal{text: job.imagesStopped}, nil
+ return nil, "", refusal{text: job.imagesStopped}, nil
}
// The lease is checked just before each of the store's own writes
// (§12): a copy, or an add after the download.
if err := job.store.bookkeep(ctx, job.lease, noChange); err != nil {
- return nil, refusal{}, err
+ return nil, "", refusal{}, err
}
if added, ok := job.copyImage(ctx, entry, block); ok {
- return added, refusal{}, nil
+ return added, "", refusal{}, nil
}
- data, why, err := job.download(ctx, id)
+ data, key, why, err := job.download(ctx, id)
if err != nil || why.text != "" {
- return nil, why, err
+ return nil, key, why, err
}
if err := job.store.bookkeep(ctx, job.lease, noChange); err != nil {
- return nil, refusal{}, err
+ return nil, "", refusal{}, err
}
added, err := job.images.Add(ctx, job.who, data)
- return added, job.storeRefusal(err), nil
+ return added, key, job.storeRefusal(err), nil
}
-// download reads the block again for a fresh signed URL and fetches it.
+// download reads the block again for a fresh signed URL and fetches it,
+// and answers that file's key.
func (job *importJob) download(ctx context.Context, id string) ([]byte,
- refusal, error) {
+ string, refusal, error) {
fresh, err := job.client.Block(ctx, id)
if err != nil || fresh.File == nil {
- return nil, refusal{text: fetchReason(err)}, finalOnly(err)
+ return nil, "", refusal{text: fetchReason(err)}, finalOnly(err)
}
+ key := notion.FileKey(fresh.File.URL)
data, err := job.files.Fetch(ctx, fresh.File.URL, imageCap)
if err != nil {
// Only size is permanent: a host the pin refuses may be one
// §19 step 4 has yet to add, so it is tried again (round 3, L5).
- return nil, refusal{text: fetchReason(err),
+ return nil, key, refusal{text: fetchReason(err),
permanent: notion.CodeOf(err) == notion.CodeTooLarge}, nil
}
- return data, refusal{}, nil
+ return data, key, refusal{}, nil
}
// storeRefusal is what Mapa images' answer means for the run: the first
diff --git a/internal/mapa/import_images_test.go b/internal/mapa/import_images_test.go
index 4e97d80..e9c55be 100644
--- a/internal/mapa/import_images_test.go
+++ b/internal/mapa/import_images_test.go
@@ -138,7 +138,7 @@ func TestI14ABlockOnASecondPageIsCopied(t *testing.T) {
// not remembered.
func TestI14ARefusalIsALineAndRemembered(t *testing.T) {
ws := newSmall()
- ws.Add(ws.handbook, notiontest.Image(ws.Host("notes.png",
+ ids := ws.Add(ws.handbook, notiontest.Image(ws.Host("notes.png",
[]byte("not a picture at all"))))
world := newImportWorld(t, ws.Workspace)
world.useImages()
@@ -154,6 +154,42 @@ func TestI14ARefusalIsALineAndRemembered(t *testing.T) {
if world.fileRequests() != 0 {
t.Errorf("a permanent refusal was fetched again")
}
+ // The file replaced with a picture in the same minute: the refusal
+ // was the old file's, so the new one is fetched (Fable L5).
+ changeImage(t, ws, ids[0], 10)
+ world.server.Reset()
+ world.importAs(ana)
+ _, record, _ = world.pageTitled("Handbook")
+ if world.fileRequests() != 1 || !strings.Contains(record.Body, "](/i/") {
+ t.Errorf("a refused file replaced: %d fetched, body %q",
+ world.fileRequests(), record.Body)
+ }
+}
+
+// Fable L1: a file replaced between Survey and Write is downloaded as
+// it is now, and kept under the key of what was downloaded, so the next
+// run fetches nothing.
+//
+// Mutation (make mutate, first red 2026-11-22): the key kept is the
+// staged file's.
+func TestI14AFileReplacedMidRunIsKeyedAsDownloaded(t *testing.T) {
+ ws, block := imagePage(t)
+ world := newImportWorld(t, ws.Workspace)
+ world.useImages()
+ world.connect(ana)
+ atPoint(t, "survey:walked", 1, func() {
+ world.server.Lock()
+ defer world.server.Unlock()
+ changeImage(t, ws, block, 11)
+ })
+ world.importAs(ana)
+ importCrash = nil
+ world.server.Reset()
+ // (The page itself updates: changeImage drops the caption.)
+ world.importAs(ana)
+ if world.fileRequests() != 0 {
+ t.Errorf("the run after fetched %d", world.fileRequests())
+ }
}
// I14: the first quota refusal stops downloads for the run and names
diff --git a/scripts/mutate/mutations_import.go b/scripts/mutate/mutations_import.go
index 6e83143..6763de1 100644
--- a/scripts/mutate/mutations_import.go
+++ b/scripts/mutate/mutations_import.go
@@ -288,6 +288,20 @@ var importMutations = []mutation{
inMapa("I14", "reuse ignores the file's key, the same minute",
"TestI14AnImageReplacedInTheSameMinuteIsFetched", edit{importImages,
"if found && sameFile(prior.Key, placed.key) {", "if found {"}),
+ inMapa("I14", "a permanent refusal outlives its file",
+ "TestI14ARefusalIsALineAndRemembered", edit{importImages,
+ "if found && sameFile(prior.Key, placed.key) {", "if found {"}),
+ inMapa("I14", "the key kept is the staged file's",
+ "TestI14AFileReplacedMidRunIsKeyedAsDownloaded", edit{importImages,
+ "\t\tplaced.key = fetched\n", "\t\t_ = fetched\n"}),
+ // Fable M1: the fake signs every read afresh, as Notion does, so a
+ // key that keeps the signature fetches every image on every run.
+ inMapa("I2", "the file key is the signed URL",
+ "TestI14AnImageIsAddedAndAttached", edit{importImages,
+ "placed := placedImage{block: block.ID, key: notion.FileKey(block.File.URL),",
+ "placed := placedImage{block: block.ID, key: block.File.URL,"},
+ edit{importImages, "\tkey := notion.FileKey(fresh.File.URL)\n",
+ "\tkey := fresh.File.URL\n"}),
inMapa("I14", "an empty file key matches",
"TestAnEmptyFileKeyMatchesNothing", edit{importImages,
"return kept != \"\" && kept == now", "return kept == now"}),