diff --git a/.claude/memory/journal.md b/.claude/memory/journal.md index bfc34ac4..05cec1bf 100644 --- a/.claude/memory/journal.md +++ b/.claude/memory/journal.md @@ -289,3 +289,4 @@ Owner validated R4.0 plan with conditions (BDR-057, plan §A.6, LRN-059/060). R3 - 2026-10-18 R4.3 done on feature/rust-r4-pdf-core (52471db..b08373a): FileBytes sink + import_pdf_bytes/restore_copy_bytes; worker protocol v1 (task/chunk/ack/end → ready/result/failed), page reads file in 1 MiB BYOB chunks (amendment B.1.5: WebKit worker file read ≈180 MiB), client timers + settle-once + terminate, controller, HomeRoute switched, B.1.8 messages pinned on O8/O7/O2/O3 via in-process worker, 6 suites migrated (458 app tests). Security gates: reader PASS after fix, worker PASS 7 LOW → hardenings 8ddf185. Browser proofs on dist: 666/678, W5 0 long tasks, CSP with/without OK; 50 MiB WebKit 145 vs TS 76 (was 324); leak series Chromium OK, Firefox sawtooth reclaimed, WebKit grows with same-tab navigation (control too). DEPLOY note, R4_J1.md + kit script. Open for owner: WebKit large-file gate, WebKit leak criterion. Next: owner decision, J1 on devices. - 2026-10-18 owner: J1 authorised with both WebKit reserves (BDR-059), cap 50 MiB kept, no streaming scanner, criterion 10 MiB / 5 imports kept with same-page vs navigation split + control. Kit generated (../faunosteo-j1-kit, 13 MB, L report as rescue copy for the 42 MB export), R4_J1_RESULTS.md template. STOP: waiting for device results; no merge, no R4.4. - 2026-10-18 J1 partial: owner ran the functional checks on a computer, no failure (browser/version, timings pending); iPhone not available, deferred → stays NON TESTÉ, blocks final R4.3 acceptance (OD-6). Proposed: continue R4.4 on the branch with the iPhone J1 as a blocking item before any merge; waiting for the owner's decision. No merge, no R4.4 started. +- 2026-10-18 R4.4 done (70007e0, 1550d21): pdf::write text/afm_data/dates (O4 55,992 widths bit-exact, 1,168 wraps, safeText every code point, upper 1,580 = Rust to_uppercase, O5 tables, O6 6,468 cells), input checks, layouts → DrawLog; O1 12 runs 2,124 calls equal, step6 text/images 24 derived. Layout L 3 ms, CAP 24 ms release. Nothing wired, module size unchanged. STOP before R4.5. diff --git a/.claude/tasks/TODO.md b/.claude/tasks/TODO.md index 4f1dbf81..a2eea609 100644 --- a/.claude/tasks/TODO.md +++ b/.claude/tasks/TODO.md @@ -231,9 +231,9 @@ feat/findings-tree-v2 merged (FindingsTreePicker tracked in HEAD); all work belo - [x] R4.3e (done 2026-10-18; two WebKit points for the owner: 50 MiB file 145 MiB vs TS 76, leak series not demonstrable headless) record RUST.md §10.5, DEPLOY note (worker CSP, Firefox 114 line per OD-1), PDF_IMPORT_HARDENING §5 results, J1 procedure; announce "TEST FONCTIONNEL DISPONIBLE" with the 7-point checkpoint (BDR-058) - [ ] J1 owner checkpoint (plan A.4) - [ ] R4.4 layout → draw log (owner go 2026-10-18, BDR-060; stop before R4.5) - - [ ] R4.4a `pdf/write/{text,afm_data,dates}.rs`: safe_text (O4 ranges), js_upper (O4 runs/special), js_trim/whitespace, measure = units × (size/1000) with WX||250 + KPX over WinAnsi bytes (O5 tables generated by scripts/r4-afm-data.mjs), wrap_lines (JS \s+), format_date fr/en (O6 grid, years 0-99 → 19xx per A3); cargo tests on O4 measure groups, wrapLines, safeText, upper, O5 widths, O6 - - [ ] R4.4b `pdf/write/{mod,input,draw_log,layout/{header,footer,observation,conclusion}}.rs`: ExportInput (ts-rs) checks (branding/labels, assert_snapshot + read_svg per asset, sheet mismatch, caps), rasters by key + PNG dims (IHDR only; gate at R4.5), DrawLog ops at full precision in TS call order (footers after all pages), links, embeds, warnings; cargo O1 12 logs exact, step6 text/images goldens (24) derived - - [ ] R4.4c record RUST.md §10.6 (modules, parity, declared differences, performance), ledger targets, suites green, STOP before R4.5 + - [x] R4.4a `pdf/write/{text,afm_data,dates}.rs`: safe_text (O4 ranges), js_upper (O4 runs/special), js_trim/whitespace, measure = units × (size/1000) with WX||250 + KPX over WinAnsi bytes (O5 tables generated by scripts/r4-afm-data.mjs), wrap_lines (JS \s+), format_date fr/en (O6 grid, years 0-99 → 19xx per A3); cargo tests on O4 measure groups, wrapLines, safeText, upper, O5 widths, O6 + - [x] R4.4b `pdf/write/{mod,input,draw_log,layout/{header,footer,observation,conclusion}}.rs`: ExportInput (ts-rs) checks (branding/labels, assert_snapshot + read_svg per asset, sheet mismatch, caps), rasters by key + PNG dims (IHDR only; gate at R4.5), DrawLog ops at full precision in TS call order (footers after all pages), links, embeds, warnings; cargo O1 12 logs exact, step6 text/images goldens (24) derived + - [x] R4.4c (done 2026-10-18, STOP before R4.5) record RUST.md §10.6 (modules, parity, declared differences, performance), ledger targets, suites green, STOP before R4.5 - [ ] R4.5 serialiser (pdf-writer, self-check, from_envelope) - [ ] R4.6 app export (session in main instance, owner phone check of L) - [ ] R4.7 report-compare in Rust diff --git a/docs/development/RUST.md b/docs/development/RUST.md index 71b89f29..84b91470 100644 --- a/docs/development/RUST.md +++ b/docs/development/RUST.md @@ -1432,3 +1432,72 @@ Residual risks and open points (R4.3, for the J1 checkpoint): worker, which would keep hostile memory alive between imports. - The TypeScript reader stays in `packages/pdf` until R4.8 (parity and the full switch); `apps/app/src/pdf/import.ts` is now used by tests only. + +### 10.6 R4.4: the layout in Rust (2026-10-18, nothing wired yet) + +What runs in Rust (`crates/core/src/pdf/write`, feature `pdf-write`, enabled +by the wasm facade and linked into the module only once R4.5 and R4.6 call +it; the shipped size is unchanged until then): the text rules of +`packages/pdf/src/text.ts` and `render/text.ts` (`text.rs`: `safe_text` +with the Cc, Cf, Zl and Zp classes frozen from V8 in O4, not Rust's tables; +`js_upper` from the O4 runs and specials; `js_trim` and the JS `\s` set; +`measure` = Σ (WX or 250) + KPX over WinAnsi bytes, then × size / 1000 in +that order; `wrap_lines` with JS `split(/\s+/)` semantics, empty words +included), the AFM metrics and Unicode tables generated from O5 and O4 by +`scripts/r4-afm-data.mjs` (`afm_data.rs`, 82 KB, deterministic), the dates +of `render/dates.ts` (`dates.rs`: `Date.UTC` with years 0 to 99 mapped to +1900 to 1999 as A3 keeps them, proleptic Gregorian, fr-FR and en-US long +forms), the input checks of `export.ts` (`input.rs`: branding and labels +through their schemas, the snapshot gate with every asset through the R3 +SVG reader, sheet mismatch, 500 observations and 8 views per observation) +and the four layouts (`layout/{header,footer,observation,conclusion}.rs`) +into a `DrawLog` (`draw_log.rs`: every text, image, line, rectangle call +with its arguments at full precision, per page with the footer last, the +links by page, the images in embed order with their pixel size read from +the PNG header; the PNG gate and decode are R4.5). + +Parity (cargo, `pdf_text` and `pdf_layout`): + +| Oracle | Check | Result | +|---|---|---| +| O4 `measure` | 2,333 rows × 3 fonts × 8 sizes | 55,992 widths equal; 4,800 recorded widths bit for bit | +| O4 `wrapLines` | 73 cases × 2 sizes × 8 widths | 1,168 wraps equal | +| O4 `safeText` | every code point 0..0x10FFFF (the 2,048 surrogates excepted: not a Rust `char`; their row is `question`) | 79 ranges equal | +| O4 `upper` | every scalar value | 1,580 changed code points equal; Rust's `to_uppercase` (Unicode 17) agrees with V8 on all of them | +| O5 | every WX by byte and every kerning pair | equal; WinAnsi pairs: Helvetica 1,295, Helvetica-Bold 1,181, Times-Roman 986 | +| O6 | 6,468 grid cells × 2 locales, 22 others | equal (1,355 refused cells) | +| O1 | 12 runs (3 reports × 2 locales × 2 logo modes), inputs = the envelope of each run's own R3 PDF, rasters = the goldens' stubs | 2,124 calls equal at full precision, embeds and links equal | +| Step 6 `text.*` and `images.*` | 24 goldens derived from the log in the engine's global call order (page contents, then footers), two decimals | equal | + +Subtleties the port had to carry: U+00AD is WinAnsi (`hyphen`) but Cf, so +dropped, while U+00A0 is kept; kerning goes by glyph name, so bytes 32/160, +45/173 and 255/159 share their pairs; a leading or trailing whitespace run +gives an empty word to the wrap, which joins as a trailing space when it +fits; words are split on raw JS whitespace before `safeText` runs (U+200B is +dropped but not `\s`); `Date.UTC` applies the leap rule to the mapped year +(0000-02-29 is refused, 1900 is not leap); the first-page link order of the +saved file is per page (header, then footer), whatever the call order; the +Step 6 text golden is in global call order, footers after every page. + +Declared differences: none in the oracles. The snapshot assets go through +the R3 SVG reader where the TypeScript ran its sanitiser (declared at R3, +RUST.md §9.4, plan §A.3): a foreign archive the sanitiser cleaned and the +reader refuses is `snapshot_invalid` with the reader's reason in the detail +(the detail reaches the DEV console only). + +Cost (release build, i7-11700B): L (60 observations) 61 pages, 2,377 calls, +124 embeds, checks 1 ms, layout 3 ms; CAP (500 observations) 501 pages, +19,625 calls, 1,004 embeds, checks 1 ms, layout 24 ms (debug: 29 and 222 ms). + +Residual risks and open points (R4.4): + +- The PNG header alone sizes an image (`embedPng`'s `width` and `height`); + the UPNG acceptance rules and the branding PNG gate (`pngIssue`) are R4.5, + with the O6 PNG cases (108). A PNG the header reads and UPNG refuses is + not detected before R4.5. +- `rasterSizeOf` (the raster request size from a viewBox, JS `Number` + semantics) and `numberToString` are pinned in O4 but ported at R4.5 / R4.6 + with the content emitter and the session. +- The module size impact of the writer is measured when R4.5 links it + (W1, the `afm_data` tables are 82 KB of source, the compiled tables about + 12 KB).