chore(memory): V1-2.2 three MEDIUM evidence, lot B patch, contract, TODO, journal
This commit is contained in:
1 parent
9e49ed1b4d
commit
f1bb19b30b
9 files changed
+1652
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,56 @@
|
||||
# V1-2.2 three MEDIUM (owner brief « arbitrages propriétaire sur les trois MEDIUM », 2026-10-30),
|
||||
# mutation run: F = frame (defect 3), I = isolation and hitbox (defects 1, 2), K/V = the reserved-id
|
||||
# and root-visibility protections re-checked on the new composer. Each mutant is applied to its
|
||||
# source file, its cargo suite runs, the file is restored. Run from the repo root.
|
||||
import subprocess
|
||||
PDF='--features pdf-read,pdf-write'
|
||||
muts=[
|
||||
('F1 every bound in frame','crates/core/src/anatomy/frame.rs',' bounds.min_x >= self.min_x - slack\n',' true || bounds.min_x >= self.min_x - slack\n','sheet_frame',''),
|
||||
('F2 right edge unchecked','crates/core/src/anatomy/frame.rs',' && bounds.max_x <= self.min_x + self.width + slack\n','','sheet_frame',''),
|
||||
('F3 bottom edge unchecked','crates/core/src/anatomy/frame.rs',' && bounds.max_y <= self.min_y + self.height + slack\n','','sheet_frame',''),
|
||||
('F4 view_box ignored, drawing frame always','crates/core/src/anatomy/frame.rs',' match view.view_box() {',' match None::<&crate::domain::sheet::ViewBox> {','sheet_frame',''),
|
||||
('F5 zero width accepted','crates/core/src/anatomy/frame.rs',' && width > 0.0\n','','sheet_frame',''),
|
||||
('F6 trailing numbers accepted','crates/core/src/anatomy/frame.rs',' [min_x, min_y, width, height] =>',' [min_x, min_y, width, height, ..] =>','sheet_frame',''),
|
||||
('F7 circle radius ignored','crates/core/src/anatomy/frame.rs',' min_x: c.cx - c.r,',' min_x: c.cx,','sheet_frame',''),
|
||||
('F8 unreadable path accepted','crates/core/src/anatomy/frame.rs',' None => Placement::Unreadable,',' None => Placement::InFrame,','sheet_frame',''),
|
||||
('F9 cubic extremes skipped','crates/core/src/anatomy/path.rs',' let a = -p0 + 3.0 * p1 - 3.0 * p2 + p3;\n',' return [None, None];\n let a = -p0 + 3.0 * p1 - 3.0 * p2 + p3;\n','sheet_frame',''),
|
||||
('F9b quadratic extreme skipped','crates/core/src/anatomy/path.rs',' let denominator = p0 - 2.0 * p1 + p2;\n',' return None;\n let denominator = p0 - 2.0 * p1 + p2;\n','sheet_frame',''),
|
||||
('F10 arc extremes skipped','crates/core/src/anatomy/path.rs',' if ellipse.sweeps(angle) {',' if false && ellipse.sweeps(angle) {','sheet_frame',''),
|
||||
('F11 trailing garbage accepted','crates/core/src/anatomy/path.rs',' if !cursor.done() {\n return None;\n }\n pen.bounds',' pen.bounds','sheet_frame',''),
|
||||
('F12 missing drawing frame not reported','crates/core/src/anatomy/frame.rs',' faults.push(FrameFault::NoFrame { view_index });\n','','sheet_frame',''),
|
||||
('F13 verdict ignores frame issues','crates/core/src/domain/sheet/verdict.rs',' .chain(frame_failures(&report))\n','','sheet_frame',''),
|
||||
('F14 verdict measures nothing','crates/core/src/domain/sheet/verdict.rs',' report\n .issues\n .extend(frame_issues(&document.typed, |id| roots.get(id).copied()));\n','','sheet_frame',''),
|
||||
('F15 preview measures nothing','crates/core/src/domain/sheet/preview.rs',' report.issues.extend(frame_issues(&self.document, |id| {\n self.drawing(id).and_then(|d| d.as_ref().ok())\n }));\n','','sheet_frame',''),
|
||||
('F16 frame faults as rules failure','crates/core/src/domain/sheet/verdict.rs',' let rule =\n |code: &str| ![super::report::GEOMETRY_MISSING, OUT_OF_FRAME, NO_FRAME].contains(&code);',' let rule = |code: &str| code != super::report::GEOMETRY_MISSING;','sheet_frame',''),
|
||||
('F17 slack follows the offset','crates/core/src/anatomy/frame.rs',' let slack = EDGE_TOLERANCE * self.width.max(self.height);',' let slack = EDGE_TOLERANCE * (self.width.max(self.height) + self.min_x.abs());','sheet_frame',''),
|
||||
('I1 drawing attributes back on the root','crates/core/src/anatomy/compose.rs',' .partition(|a| a.qname == "xmlns" || a.qname == "xmlns:xlink");',' .partition(|_| true);','svg_marker_isolation',''),
|
||||
('I2 layer inside the drawing group (canvas)','crates/core/src/anatomy/compose.rs',' let layer = render_composed_layer(document, view_id, &HashSet::new())?;\n root.children.push(Node::Element(checked(layer)?));\n Ok(root)\n}\n\n/// Root attributes',' let layer = render_composed_layer(document, view_id, &HashSet::new())?;\n if let Some(Node::Element(group)) = root.children.first_mut() {\n group.children.push(Node::Element(checked(layer)?));\n }\n Ok(root)\n}\n\n/// Root attributes','svg_marker_isolation',''),
|
||||
('I3 halo in the drawing group','crates/core/src/anatomy/compose.rs',' root.children.push(Node::Element(defs));',' if let Some(Node::Element(group)) = root.children.first_mut() {\n group.children.insert(0, Node::Element(defs));\n }','svg_marker_isolation',''),
|
||||
('I4 hitbox stroke not declared','crates/core/src/anatomy/layer.rs',' hitbox.push(("stroke", "none".to_owned()));\n','','svg_marker_isolation',''),
|
||||
('I5 hitbox captures on all','crates/core/src/anatomy/layer.rs',' hitbox.push(("pointer-events", "visibleFill".to_owned()));',' hitbox.push(("pointer-events", "all".to_owned()));','svg_marker_isolation',''),
|
||||
('I6 composers draw the R3 layer','crates/core/src/anatomy/layer.rs',' layer(document, view_id, states, true)',' layer(document, view_id, states, false)','svg_marker_isolation',''),
|
||||
('I7 R3 layer gets the declared hitbox (seed review drawings would change)','crates/core/src/anatomy/layer.rs',' layer(document, view_id, states, false)',' layer(document, view_id, states, true)','anatomy_layer',''),
|
||||
('K1 reader skips the reserved check','crates/core/src/anatomy/svg/mod.rs',' refs::check_reserved_ids(&sanitized.root)?;\n','','svg_reserved_ids',''),
|
||||
('K7 highlight composes a reserved id','crates/core/src/anatomy/compose.rs',' if holds_reserved_id(&asset) {\n return Err(ComposeError::ReservedId);\n }\n','','svg_reserved_ids',''),
|
||||
('K8 canvas composes a reserved id','crates/core/src/anatomy/compose.rs',' if holds_reserved_id(asset) {\n return Err(ComposeError::ReservedId);\n }\n','','svg_reserved_ids',''),
|
||||
('K10 halo not written','crates/core/src/anatomy/compose.rs',' root.children.push(Node::Element(defs));','','pdf_session',PDF),
|
||||
('V1 reader skips the root visibility check','crates/core/src/anatomy/svg/mod.rs',' sanitize::check_root_visibility(&sanitized.root)?;\n','','svg_root_visibility',''),
|
||||
('V6 canvas composes a hidden root','crates/core/src/anatomy/compose.rs',' if check_root_visibility(asset).is_err() {\n return Err(ComposeError::RootVisibility);\n }\n','','svg_root_visibility',''),
|
||||
('V7 highlight composes a hidden root','crates/core/src/anatomy/compose.rs',' if check_root_visibility(&asset).is_err() {\n return Err(ComposeError::RootVisibility);\n }\n','','svg_root_visibility',''),
|
||||
]
|
||||
for name,path,old,new,suite,features,*more in muts:
|
||||
src=open(path).read()
|
||||
mutant=src
|
||||
for o,n in [(old,new)]+list(more):
|
||||
if mutant.count(o)!=1:
|
||||
print(name,'ANCHOR NOT FOUND x',mutant.count(o)); mutant=None; break
|
||||
mutant=mutant.replace(o,n)
|
||||
if mutant is None:
|
||||
continue
|
||||
open(path,'w').write(mutant)
|
||||
try:
|
||||
r=subprocess.run(['bash','-c',f'. scripts/rust-env.sh && cargo test -q -p faunosteo-core {features} --test {suite} 2>&1 | tail -3'],capture_output=True,text=True)
|
||||
out=r.stdout
|
||||
print(f"{name} ({suite}): {'KILLED' if 'FAILED' in out else ('COMPILE-ERR' if 'could not compile' in out else 'SURVIVED')}", flush=True)
|
||||
finally:
|
||||
open(path,'w').write(src)
|
||||
@@ -0,0 +1,82 @@
|
||||
# V1-2.2 three MEDIUM: evidence (2026-10-30)
|
||||
|
||||
Owner brief « V1-2.2 : arbitrages propriétaire sur les trois MEDIUM » on `958228a`. Contract
|
||||
`.claude/tasks/contracts/2026-10-30-v1-2-2-three-medium.md`. Lot A (defect 3, frame) committed `0c87c7f`, `faa53c7`,
|
||||
`587cbb2`. Lot B (defects 1 and 2, isolation and hitbox) NOT committed: it changes what frozen R3 references compare;
|
||||
patch `2026-10-30-v1-2-2-lot-b-isolation.patch` (against `587cbb2`), docs RUST.md §12.11 (lot A) and §12.12 (lot B, in
|
||||
the patch).
|
||||
|
||||
## 1. Audit
|
||||
|
||||
- Reaching the layer before: the root's presentation attributes the reader keeps. Inherited: `stroke*`, `fill*`,
|
||||
`visibility`, `color`, `clip-rule`, `color-interpolation-filters` (the halo filter sat in the drawing's first
|
||||
`<defs>`), font properties. Whole subtree, no child can undo: `opacity`, `display`, `systemLanguage`. Already removed
|
||||
on the root by the reader: `class`, `style`, `transform`, `filter`, `mask`, `clip-path`; no `pointer-events`,
|
||||
`cursor` or `<style>` survives anywhere; root `visibility` refused (`root_visibility`).
|
||||
- Markers: point hitbox `fill` transparent, `pointer-events` all, no stroke (inherits it, and under `all` the stroke
|
||||
area is hit even unpainted); visible twin `pointer-events` none; zones and trigger declare `stroke-width` 2, not
|
||||
`stroke-opacity`, `stroke-dasharray` (zones), `stroke-linejoin`, `fill-rule`.
|
||||
- Frame: canvas = view box, else drawing `viewBox` verbatim, else `0 0 100 100`; PDF = view box, else the drawing's;
|
||||
root `preserveAspectRatio` kept (a `slice` crops where the PDF raster aspect is clamped to [0.2, 2] or the canvas box
|
||||
differs).
|
||||
- Equine: all 28 annotations in frame, minimum margin 34 units; each point centre hit by its own marker in Chromium.
|
||||
|
||||
## 2. Lot A, frame (committed)
|
||||
|
||||
- `sheet_frame` 12 tests: on `958228a` 9 fail, 3 accept-only pass; green after. Reported drawing (horse `viewBox` +10 000,
|
||||
content translated back, read clean) refused with its 19 main-view annotations, failures exactly
|
||||
`["verification.validation.out_of_frame"]`, document text unchanged.
|
||||
- `path.rs` unit tests: 500 random cubics, 500 random arcs against 20 001 samples; grammars.
|
||||
- Mutations F1-F16 (+F9b): 17/17 killed after pinning the failure list (F16 survived the first run).
|
||||
- Oracles: none changed. `check:all` green on the lot A tree (cargo 2 145 passed summed over the feature passes, ts-rs
|
||||
types unchanged, core-wasm 65, supabase 128, app 566, lint, build, e2e:ui 26, app image, worker tests and image;
|
||||
e2e:shell not run).
|
||||
- Module: 560 377 → 572 993 B gzip -9; Node's gzip level 9 582 919 B (budget 600 000, margin 17 081 B).
|
||||
|
||||
## 3. Lot B, isolation and hitbox (proposal)
|
||||
|
||||
- `svg_marker_isolation` 5 tests, all red on `958228a`, green with lot B.
|
||||
- Pixels (Playwright Chromium 156, Firefox 157, WebKit 27.2; PDF = sized SVG → Image → white canvas as
|
||||
`browserRasterizer`, canvas = inline SVG 1000 × 786; equine main view, `hock`, `hip`, `lumbar`, `head-trigger`
|
||||
selected, halo on). Plain equine: 0 px difference in both forms, three engines. Markers alone (drawing removed) vs the
|
||||
plain markers, old / new, Chromium PDF: `stroke-width` 132 851 / 0; `stroke-opacity` 41 393 / 0; `dasharray`
|
||||
22 528 / 0; `color-interpolation-filters` (halo) 66 271 / 0; `linejoin` 19 / 0; `opacity` markers absent / 0;
|
||||
`display`, `fill`, `fill-opacity`, `fill-rule` 0 / 0. Same pattern in Firefox and WebKit, canvas and PDF; new = 0
|
||||
in every case. Side effect: root `opacity="0"` / `display="none"` now hide the drawing alone, the same in every engine.
|
||||
- Real PDF exports (demo.fr.logos, v2full.fr.logos, v2unresolved.fr.nologos; every view rasterised by Chromium):
|
||||
byte-identical to `958228a`; 15 pages identical at 100 dpi.
|
||||
- Clicks (`apps/app/e2e/ui/canvas-clicks.spec.ts`, harness `e2e/harness/canvas.{html,tsx}`; projects chromium-desktop,
|
||||
chromium-375 touch, firefox-desktop, webkit-desktop, webkit-375 touch): lot B 67 passed, 5 fixme; `958228a` 45 failed
|
||||
(Chromium and WebKit every stroke case; Firefox 3). Full `e2e:ui` on lot B: 93 passed, 5 skipped.
|
||||
- Mutations I1-I7 killed; K1, K7, K8, K10, V1, V6, V7 rerun killed.
|
||||
- References compared differently (not edited): R3 `highlight.json` (36 cases) and R3 canvas goldens
|
||||
(`canvas.{main,head}.json`, `.layers.json`): equal under the declared transforms `with_isolated_layer`,
|
||||
`withIsolatedLayer`, `withDeclaredHitboxes` (included in the patch, uncommitted). R4.1 `pdf/r3/real/manifest.json`
|
||||
call 1 `svgSha256` (`a9a3155c…` → `45fd4aaf…`): a byte digest, the core-wasm test fails until the owner decides.
|
||||
Unchanged: R3 `layer.json`, `sanitiser.json`, R4 PDF digests, step6 goldens, N-1 copies, seed review drawings
|
||||
(R3 layer kept for them), equine drawing (sha256 `0ea5202f…`) and fingerprint.
|
||||
- Module with lot B: 573 088 B gzip -9.
|
||||
|
||||
## 4. Pre-existing finding: junction points
|
||||
|
||||
Zones are painted and hit after the points. Share of each visible disc recorded by its own marker (plain equine,
|
||||
identical in the three engines): `c7-t1` 51 %, `l6-s1` 56 %, `t18-l1` 72 %, fore fetlock 92 %. In Firefox and WebKit
|
||||
the centre of `c7-t1` records « thoracic ». Prototype orders (DOM reordering, not built): points above zones → discs
|
||||
100 % (fore fetlock 92 %), zones lose 2 to 10 % to the point hitboxes; hitboxes, then zones, then capturing twins
|
||||
(« visible wins ») → discs 99-100 %, zones lose only what the discs cover (3 %). Owner decision.
|
||||
|
||||
## 5. Independent reviews (fresh, Opus: the pinned Fable model was out of credits)
|
||||
|
||||
- Security: PASS, semgrep 163 rules 0 findings. MEDIUM scale bypass, reproduced: `viewBox` × 1 000 with the content
|
||||
scaled back keeps the horse identical, every marker sub-pixel, verdict green (defect 3 by another route; owner
|
||||
decision, not built). MEDIUM offset and precision: slack grew with the offset (fixed `9e49ed1`, test + mutant F17);
|
||||
absolute 1e-12 epsilons in the curve extremes and f64 reading where browsers use f32 (needs coordinate range bounds,
|
||||
owner decision). LOW NaN dropped by `min`/`max` (fixed `9e49ed1`: non-finite bounds unreadable). LOW test lint allows
|
||||
(project convention).
|
||||
- Verifier: ECARTS(2). C8 unverifiable inside its brief (docker, mutations); FLOOR `test.skip` on the tap test, not
|
||||
authorised (removed: the desktop projects already leave `@phone` out). C1-C7, C9 met; declared transforms judged
|
||||
faithful (they only rewrite the frozen side, strict comparison kept). F16 anchor broken by rustfmt (fixed). Proof
|
||||
scripts were not in the repo: now `2026-10-30-v1-2-2-three-medium-tools/` (pixel probe, real PDF export, junction
|
||||
probe). Residual: a root `systemLanguage` now sits on the drawing's group (drawing only, markers unaffected).
|
||||
- After the fixes: mutations 32/32 killed; module 573 134 B gzip -9, Node 583 018 B; `e2e:ui` 93 passed, 5 fixme;
|
||||
app 566. `check:all` last ran in full on `faa53c7` (lot A before `9e49ed1`), not rerun after `9e49ed1`.
|
||||
@@ -0,0 +1,47 @@
|
||||
// THROWAWAY: pixel proof of composed views, old (958228a) vs new, three engines; metrics in page.
|
||||
import { createRequire } from 'node:module'
|
||||
import { readFileSync, readdirSync } from 'node:fs'
|
||||
const require = createRequire(process.argv[2] + '/apps/app/package.json')
|
||||
const pw = require('@playwright/test')
|
||||
const DIR = process.argv[3]
|
||||
const engines = process.argv[4].split(',')
|
||||
const variants = [...new Set(readdirSync(DIR + '/new').map((f) => f.split('.')[0]))].sort()
|
||||
const read = (side, v, form, part) => readFileSync(`${DIR}/${side}/${v}.${form}.${part}.svg`, 'utf8')
|
||||
|
||||
const LIB = `
|
||||
window.store = {}
|
||||
window.keep = async (key, img) => { const c = document.createElement('canvas'); c.width = img.width; c.height = img.height; const x = c.getContext('2d'); x.fillStyle='#fff'; x.fillRect(0,0,c.width,c.height); x.drawImage(img, 0, 0, c.width, c.height); window.store[key] = x.getImageData(0, 0, c.width, c.height).data }
|
||||
window.pdf = async (key, svg) => { const root = new DOMParser().parseFromString(svg, 'image/svg+xml').documentElement; const vb = root.getAttribute('viewBox').split(/[\\s,]+/).map(Number); const w = 1200, h = Math.round(1200 * vb[3] / vb[2]); root.setAttribute('width', String(w)); root.setAttribute('height', String(h)); const url = URL.createObjectURL(new Blob([new XMLSerializer().serializeToString(root)], { type: 'image/svg+xml;charset=utf-8' })); const img = new Image(); img.width = w; img.height = h; img.src = url; await img.decode(); await window.keep(key, img) }
|
||||
window.png = async (key, b64) => { const img = new Image(); img.src = 'data:image/png;base64,' + b64; await img.decode(); await window.keep(key, img) }
|
||||
window.diff = (a, b) => { a = window.store[a]; b = window.store[b]; let n = 0; for (let i = 0; i < a.length; i += 4) if (a[i] !== b[i] || a[i+1] !== b[i+1] || a[i+2] !== b[i+2]) n++; return n }
|
||||
window.ink = (a) => { a = window.store[a]; let n = 0; for (let i = 0; i < a.length; i += 4) if (a[i] < 250 || a[i+1] < 250 || a[i+2] < 250) n++; return n }
|
||||
window.hl = (a) => { a = window.store[a]; let n = 0; for (let i = 0; i < a.length; i += 4) if (Math.abs(a[i]-0xb8) <= 24 && Math.abs(a[i+1]-0x5a) <= 24 && Math.abs(a[i+2]-0x3f) <= 24) n++; return n }
|
||||
`
|
||||
for (const name of engines) {
|
||||
const browser = await pw[name].launch()
|
||||
const work = await browser.newPage()
|
||||
const shot = await browser.newPage({ viewport: { width: 1100, height: 900 } })
|
||||
await work.setContent('<html><body></body></html>'); await work.addScriptTag({ content: LIB })
|
||||
console.log(`== ${name} ${browser.version()}`)
|
||||
const load = async (key, form, svg) => {
|
||||
if (form === 'pdf') return work.evaluate(([k, s]) => window.pdf(k, s), [key, svg])
|
||||
await shot.setContent(`<html><body style="margin:0;background:#fff"><div id="h" style="width:1000px;height:786px">${svg.replace(/^<svg /, '<svg width="1000" height="786" ')}</div></body></html>`)
|
||||
const b64 = (await shot.locator('#h').screenshot()).toString('base64')
|
||||
return work.evaluate(([k, b]) => window.png(k, b), [key, b64])
|
||||
}
|
||||
for (const form of ['pdf', 'canvas']) {
|
||||
await load('base', form, read('new', 'plain', form, 'layer'))
|
||||
for (const v of variants) {
|
||||
for (const side of ['old', 'new']) for (const part of ['full', 'layer']) await load(`${side}.${part}`, form, read(side, v, form, part))
|
||||
const row = await work.evaluate(() => ({
|
||||
full_old_vs_new: window.diff('old.full', 'new.full'),
|
||||
markers_old_vs_plain: window.diff('old.layer', 'base'),
|
||||
markers_new_vs_plain: window.diff('new.layer', 'base'),
|
||||
marker_ink_old: window.ink('old.layer'), marker_ink_new: window.ink('new.layer'),
|
||||
highlight_old: window.hl('old.full'), highlight_new: window.hl('new.full'),
|
||||
}))
|
||||
console.log(form.padEnd(6), v.padEnd(15), JSON.stringify(row))
|
||||
}
|
||||
}
|
||||
await browser.close()
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// THROWAWAY (never committed): capture of each visible shape under three layer orders.
|
||||
import { test } from '../support/browser'
|
||||
test('junction options @phone', async ({ page }, info) => {
|
||||
await page.goto('/e2e/harness/canvas.html?drawing=plain')
|
||||
await page.locator('[data-anno-id="hock"]').first().waitFor({ state: 'attached' })
|
||||
for (const option of ['current', 'points-above-zones', 'visible-wins']) {
|
||||
const out = await page.evaluate((option) => {
|
||||
const svg = document.querySelector('[data-testid="anatomy-canvas"] svg') as SVGSVGElement
|
||||
const layer = svg.lastElementChild as SVGGElement
|
||||
const kids = Array.from(layer.children) as SVGGeometryElement[]
|
||||
const hit = kids.filter((k) => k.getAttribute('fill') === 'transparent')
|
||||
const twins = kids.filter((k) => k.getAttribute('pointer-events') === 'none')
|
||||
const shapes = kids.filter((k) => !hit.includes(k) && !twins.includes(k))
|
||||
if (option === 'points-above-zones') {
|
||||
const points = kids.filter((k) => hit.includes(k) || twins.includes(k))
|
||||
layer.replaceChildren(...shapes, ...points)
|
||||
}
|
||||
if (option === 'visible-wins') {
|
||||
twins.forEach((t) => t.setAttribute('pointer-events', 'visibleFill'))
|
||||
layer.replaceChildren(...hit, ...shapes, ...twins)
|
||||
}
|
||||
const ctm = svg.getScreenCTM()!
|
||||
const who = (x: number, y: number) => { const p = new DOMPoint(x, y).matrixTransform(ctm); return document.elementFromPoint(p.x, p.y)?.closest('[data-anno-id]')?.getAttribute('data-anno-id') ?? '-' }
|
||||
const rows: Record<string, string> = {}
|
||||
for (const t of twins) {
|
||||
const id = t.getAttribute('data-anno-id')!
|
||||
const cx = +t.getAttribute('cx')!, cy = +t.getAttribute('cy')!, r = +t.getAttribute('r')!
|
||||
let n = 0, own = 0
|
||||
for (let dx = -r; dx <= r; dx += 2) for (let dy = -r; dy <= r; dy += 2) { if (Math.hypot(dx, dy) > r) continue; n++; if (who(cx + dx, cy + dy) === id) own++ }
|
||||
if (own < n) rows[id] = `disc ${own}/${n}`
|
||||
}
|
||||
for (const z of shapes) {
|
||||
const id = z.getAttribute('data-anno-id')!
|
||||
const b = z.getBBox()
|
||||
let n = 0, own = 0
|
||||
for (let x = b.x; x <= b.x + b.width; x += 6) for (let y = b.y; y <= b.y + b.height; y += 6) { if (!z.isPointInFill(new DOMPoint(x, y))) continue; n++; if (who(x, y) === id) own++ }
|
||||
if (own < n) rows[id] = `area ${own}/${n}`
|
||||
}
|
||||
return rows
|
||||
}, option)
|
||||
console.log(`JUNCTION ${info.project.name} ${option} ${JSON.stringify(out)}`)
|
||||
await page.reload(); await page.locator('[data-anno-id="hock"]').first().waitFor({ state: 'attached' })
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,59 @@
|
||||
// THROWAWAY (never committed): a real PDF export, every view rasterised by Chromium as
|
||||
// apps/app/src/pdf/browserRasterizer.ts does, written to REAL_PDF_OUT.
|
||||
import { createRequire } from 'node:module'
|
||||
import { readFileSync, writeFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { openExportSession } from '../src/index'
|
||||
import { nodeCoreRuntime } from '../src/node'
|
||||
import { readAttachedDocument } from './n-1/scanner/attachment/read'
|
||||
|
||||
const ROOT = fileURLToPath(new URL('../../../', import.meta.url))
|
||||
const FIXTURES = join(ROOT, 'apps/app/tests/fixtures')
|
||||
const OUT = process.env.REAL_PDF_OUT
|
||||
|
||||
function unwrap<T>(o: { ok: true; value: T } | { ok: false; kind: string; detail?: string }, what: string): T {
|
||||
if (!o.ok) throw new Error(`${what}: ${o.kind} ${o.detail ?? ''}`)
|
||||
return o.value
|
||||
}
|
||||
|
||||
it.runIf(OUT)('real pdf', async () => {
|
||||
const require = createRequire(join(ROOT, 'apps/app/package.json'))
|
||||
const { chromium } = require('@playwright/test')
|
||||
const browser = await chromium.launch()
|
||||
const page = await browser.newPage()
|
||||
await page.setContent('<html><body></body></html>')
|
||||
const runtime = await nodeCoreRuntime('pkg')
|
||||
for (const name of ['demo.fr.logos', 'v2full.fr.logos', 'v2unresolved.fr.nologos']) {
|
||||
const env = (await readAttachedDocument(new Uint8Array(readFileSync(join(FIXTURES, `pdf/r3/${name}.pdf`))))) as Record<string, unknown>
|
||||
const input = JSON.stringify({ report: env.report, sheetSnapshot: env.sheetSnapshot, branding: env.branding, labels: env.labels, locale: env.locale, exportedAt: env.exportedAt })
|
||||
const session = unwrap(openExportSession(runtime, input), name)
|
||||
const svgs: string[] = []
|
||||
try {
|
||||
for (;;) {
|
||||
const step = unwrap(session.next(), 'next')
|
||||
if (step.step === 'done') break
|
||||
for (const r of step.requests) {
|
||||
svgs.push(r.svg)
|
||||
const b64: string = await page.evaluate(async ([svg, w, h]: [string, number, number]) => {
|
||||
const root = new DOMParser().parseFromString(svg, 'image/svg+xml').documentElement
|
||||
if (root.namespaceURI !== 'http://www.w3.org/2000/svg') root.setAttribute('xmlns', 'http://www.w3.org/2000/svg')
|
||||
root.setAttribute('width', String(w)); root.setAttribute('height', String(h))
|
||||
const url = URL.createObjectURL(new Blob([new XMLSerializer().serializeToString(root)], { type: 'image/svg+xml;charset=utf-8' }))
|
||||
const img = new Image(); img.decoding = 'sync'; img.src = url; await img.decode()
|
||||
const c = document.createElement('canvas'); c.width = w; c.height = h
|
||||
const ctx = c.getContext('2d')!; ctx.fillStyle = '#ffffff'; ctx.fillRect(0, 0, w, h); ctx.drawImage(img, 0, 0, w, h)
|
||||
return c.toDataURL('image/png').split(',')[1]
|
||||
}, [r.svg, r.widthPx, r.heightPx])
|
||||
unwrap(session.addRaster(r.key, new Uint8Array(Buffer.from(b64, 'base64'))), r.key)
|
||||
}
|
||||
}
|
||||
const parts = unwrap(session.finish(), 'finish')
|
||||
writeFileSync(join(OUT!, `${name}.pdf`), Buffer.concat(parts))
|
||||
writeFileSync(join(OUT!, `${name}.views.json`), JSON.stringify(svgs.length))
|
||||
} finally {
|
||||
session.free()
|
||||
}
|
||||
}
|
||||
await browser.close()
|
||||
}, 600_000)
|
||||
Reference in new issue
Block a user