From 10c2686131b57a97eae6756ad6dd9d2279c531f3 Mon Sep 17 00:00:00 2001 From: bchanot Date: Sun, 18 Oct 2026 04:55:12 +0200 Subject: [PATCH] chore(memory): Safari download fix recorded, awaiting owner iPhone validation --- .claude/memory/journal.md | 4 ++++ .claude/tasks/TODO.md | 4 +++- .../2026-10-18-pdf-download-webkit-0930.md | 11 +++++++++++ .../plans/2026-10-18-pdf-download-webkit-0930.md | 13 +++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 .claude/tasks/contracts/2026-10-18-pdf-download-webkit-0930.md create mode 100644 .claude/tasks/plans/2026-10-18-pdf-download-webkit-0930.md diff --git a/.claude/memory/journal.md b/.claude/memory/journal.md index ab7252e2..1bb1d37c 100644 --- a/.claude/memory/journal.md +++ b/.claude/memory/journal.md @@ -277,3 +277,7 @@ Owner brief: 5 checks before R3 close. Copy round trip proven, no in-app restore ## 2026-10-17 (R4.0 plan) Owner go R4.0 (A1-A13: one branch + J1, old PDFs preserved, years 0-99 kept, Producer/Creator Faunosteo, goldens/r4, 0 px diff, import message kept + kinds split, copy via worker, Firefox/WebKit, report:compare name, TTF/scope_disclaimer/caps out, WASM stop, real PDFs). chore/rust-r4-plan: plan rev 1 → 3 challengers (19 major, 0 fatal) → rev 2. Facts: Rust lossy UTF-8 = TextDecoder (200,015 cases, 0 diff); serde_json refuses 1e400 (JS → null) → rewrite; TS embedPng holds RGB planes until save (≈ 3.8 MB/view) → session ≈ 0.37 MB/view; import already needs DecompressionStream (Firefox 113, Safari 16.4); glue module record retains instances (no throwaway instance). Firefox 157 Playwright OK, WebKit needs 2 apt libs. No code. Stop: owner validation, OD-1..OD-7. + +## 2026-10-18 (R4 prerequisites) + +Owner validated R4.0 plan with conditions (BDR-057, plan §A.6, LRN-059/060). R3 state checked: merged 8df964b, branch gone. chore/rust-r4-plan finished → develop ae17097. Hotfix bugfix/pdf-download-webkit 2b8000e: downloadBlob (anchor attached, URL revoked after 30 s) shared by rescue copy + PDF export; 3 challengers SOLID, app 405, security PASS, RUST.md 8.7 synced. Playwright WebKit 27.2 now starts (owner installed libs); desktop WebKit/Firefox/Chromium save the PDF even with immediate revoke → fix unproven until owner iPhone run. Stop: owner iPhone validation + CHANGELOG wording, then merge, then feature branch. diff --git a/.claude/tasks/TODO.md b/.claude/tasks/TODO.md index 6269cea8..ae353448 100644 --- a/.claude/tasks/TODO.md +++ b/.claude/tasks/TODO.md @@ -205,7 +205,9 @@ feat/findings-tree-v2 merged (FindingsTreePicker tracked in HEAD); all work belo - [ ] R3 follow-ups kept by the owner (2026-10-15): worker TLS exercised against a real HTTPS endpoint before the deployment that needs it; roxmltree limits + SVG prescan (pin the iterative release when published); Firefox/WebKit check; SVG references across drawings scoped per view before community uploads (Step 13); WASM size margin (396 of 600 KB) before R4; TypeScript PDF sanitiser still present until R4 - [ ] R4 pdf core: reader (Web Worker, BLK-009 browser measurements) + writer (`pdf-writer`, Std14 AFM, draw log; lines/rects/colours golden frozen with the TS engine first, D-R2) + `report-compare` tool; `packages/pdf` deleted; N-1 scanner reads R4 PDFs - [x] R4.0 plan (owner go 2026-10-17, arbitrations A1-A13): `.claude/tasks/plans/2026-10-17-rust-r4-pdf-core.md` rev 2 after 3 challengers (correctness 6 major, robustness 10 major, simplicity 3 major; none fatal) on chore/rust-r4-plan; Playwright Firefox 157 installed + proven, WebKit 27.2 downloaded (owner: `sudo apt-get install libevent-2.1-7t64 libmanette-0.2-0`); validated by the owner 2026-10-18 with conditions (plan §A.6, BDR-057) - - [ ] after validation: finish chore/rust-r4-plan into develop (owner signal), Safari PDF download fix (separate bugfix, owner go), then cut feature/rust-r4-pdf-core + - [x] R3 closed checked 2026-10-18 (8df964b on develop, branch gone); chore/rust-r4-plan finished into develop ae17097 (owner signal 2026-10-18) + - [ ] Safari PDF download fix on bugfix/pdf-download-webkit (2b8000e + docs): downloadBlob, URL kept 30 s; 3 challengers SOLID, app 405 tests, typecheck, lint, security PASS; Playwright WebKit/Firefox/Chromium do not reproduce the cancel (desktop) → owner iPhone validation, then merge; CHANGELOG entry awaiting owner wording + - [ ] then cut feature/rust-r4-pdf-core from updated develop; WebKit libs installed by owner 2026-10-18, Playwright WebKit 27.2 runs workers + wasm - [ ] R4.1 freeze (O1-O13, ledger, browser harness, TS baselines) - [ ] R4.2 reader (cargo + wasm, differential, OD-3 thresholds confirmed with owner before R4.3) - [ ] R4.3 import worker + rescue copy (B.1.5, OD-1 applied, browser proof per slice from here) diff --git a/.claude/tasks/contracts/2026-10-18-pdf-download-webkit-0930.md b/.claude/tasks/contracts/2026-10-18-pdf-download-webkit-0930.md new file mode 100644 index 00000000..1150a5bd --- /dev/null +++ b/.claude/tasks/contracts/2026-10-18-pdf-download-webkit-0930.md @@ -0,0 +1,11 @@ +# CONTRACT: PDF export download survives WebKit (hotfix) + +- REQUEST (verbatim, owner brief 2026-10-18 + synthesis 2026-10-17): « Le téléchargement PDF Safari mérite un correctif indépendant avant la recette iPhone. » The URL is revoked at once (`EditorRoute.tsx:245`), which WebKit may cancel. +- ACCEPTANCE CRITERIA: + 1. The PDF export download keeps its object URL alive `REVOKE_DELAY_MS` (30 s) and revokes it afterwards; it is never revoked synchronously. + 2. The anchor is attached to the document while clicked, then removed. + 3. File name unchanged: `bilan-${report.animal.name}-${report.date}.pdf`; Blob type `application/pdf`. + 4. `downloadJson` behaviour unchanged (name `-.json`, type `application/json`, 30 s revoke). + 5. `pnpm --filter @faunosteo/app test:run`, `pnpm typecheck`, `pnpm lint` green. +- FILE SCOPE: `apps/app/src/lib/download.ts`, `apps/app/src/app/routes/EditorRoute.tsx`, `apps/app/tests/unit/routes.EditorRoute.export.test.tsx` (the existing case asserts the old immediate revoke and must change). +- OUT OF SCOPE: any UI change, the export engine, other object URLs (rasteriser, avatar). diff --git a/.claude/tasks/plans/2026-10-18-pdf-download-webkit-0930.md b/.claude/tasks/plans/2026-10-18-pdf-download-webkit-0930.md new file mode 100644 index 00000000..10896d9d --- /dev/null +++ b/.claude/tasks/plans/2026-10-18-pdf-download-webkit-0930.md @@ -0,0 +1,13 @@ +# FIX PLAN: PDF export download revoked at once (WebKit may cancel it) + +Root cause: `apps/app/src/app/routes/EditorRoute.tsx` onExport (lines 239-245) builds a detached ``, clicks it and calls `URL.revokeObjectURL(url)` on the next line. WebKit (Safari, iOS) can cancel a download whose blob URL is revoked before the download starts reading it; Firefox historically ignored clicks on detached anchors. `apps/app/src/lib/download.ts` `downloadJson` (R3, BDR-055) already attaches the anchor while clicking and revokes after `REVOKE_DELAY_MS = 30_000`. + +Edit: +1. `lib/download.ts`: new exported `downloadBlob(blob: Blob, fileName: string): void` = create URL, anchor with `href` and `download`, `document.body.appendChild(a)`, `a.click()`, `a.remove()`, `setTimeout(() => URL.revokeObjectURL(url), REVOKE_DELAY_MS)`. `downloadJson(raw, stem)` becomes `downloadBlob(new Blob([raw], { type: 'application/json' }), `${stem}-${todayIso()}.json`)`; its doc comment keeps the lone-surrogate note, the WebKit note moves to `downloadBlob`. +2. `EditorRoute.tsx`: the seven lines become `downloadBlob(new Blob([pdf as BlobPart], { type: 'application/pdf' }), `bilan-${report.animal.name}-${report.date}.pdf`)`, import from `@/lib/download`. Warnings alert and error handling unchanged (the alert still follows the click synchronously, as today). +3. Test `routes.EditorRoute.export.test.tsx` case "downloads bilan--.pdf through a blob URL it then revokes": fake timers with `shouldAdvanceTime: true` for that case; the click spy also records `this.isConnected`; assert connected at click, not revoked right after the download, revoked with `blob:faunosteo-test` after advancing 30,000 ms. + +## Challenge summary (correctness SOLID, robustness SOLID, simplicity SOLID; minors folded) +- Test step 3, closed: keep the `downloads` array as is; add a separate `clicked: HTMLAnchorElement[]` filled by the click spy (cleared in beforeEach). In the revoke case: `vi.useFakeTimers({ shouldAdvanceTime: true })` BEFORE `mountAndExport`; after the download, assert `clicked[0].isConnected` was true at click (record it in the spy as `connectedAtClick`), `document.querySelector('a[download]')` is null, `URL.revokeObjectURL` not called; then `vi.advanceTimersByTime(30_000)` and assert it was called with `blob:faunosteo-test`. Add `vi.useRealTimers()` to the file's afterEach. +- `downloadJson` criterion 4 (name `-.json`, type, 30 s revoke) is checked by reading the code and by the existing coreStopped / heldSession suites; no scope widening. +- WebKit: unit tests prove the code shape only. The premise is checked with a Playwright WebKit reproduction (immediate vs delayed revoke) and the fix is validated only by the owner's iPhone run (BDR-057 OD-6): several views, the warnings-alert path, the download prompt left open over 30 s. If that run still fails, the next suspect is the lost user activation between the click and `a.click()` after `await exportReportToPdf`.