fix(anatomy): V1-2.2 owner arbitrations on SVG references and bytes

Refuse local references to ids a drawing does not define, scope canvas
ids per view, upload every drawing in one stored form checked by the
verdict and the preview, keep strict numeric rgb() colours, and commit
real Inkscape 1.4.3 exports with their generator.
This commit is contained in:
bchanot committed 2026-10-29 16:24:07 +01:00
1 parent 17d919971e
commit e823655f09
31 files changed
+1362 -110

No files matched your search

+26 -2
View File
@@ -3,7 +3,10 @@
* index, the fingerprint and the canvases of the bundled sheet; hash and fingerprint
* mismatches refuse the build with their closed kind; a draft's document is replaced and
* redrawn; the edit commands run through `call`; every hostile SVG and flood gets a closed
* cleaning answer with no trap. The Rust suites hold the rules; this proves the facade.
* cleaning answer with no trap. The owner's decisions of 2026-10-29 too: canvases scope their
* ids per view, dangling references and removals that leave a dependent are refused, the
* stored form is what a file uploads, cairo's `rgb()` colours are kept. The Rust suites hold
* the rules; this proves the facade.
*/
import { readFileSync, readdirSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
@@ -16,6 +19,8 @@ const SEED = `${ROOT}supabase/seed/anatomical-sheets/equine/draft/`
const HOSTILE = `${ROOT}crates/core/tests/fixtures/svg/hostile/`
const HORSE_ID = '7f767f74-3b36-51a7-8465-52dd7e2ead4a'
const HORSE_SHA = '0ea5202fa3b95bac167b87c12ee969ab0272e085b60c2d34dbca6202c5f08541'
const EXPORTS = `${ROOT}crates/core/tests/fixtures/svg/exports/`
const PROLOG = '<?xml version="1.0" encoding="UTF-8"?>\n'
const FINGERPRINT = '12d788727c1e532641bd5b3a7ecf39dbdd25e70350f8a76be5ca917b262874e2'
const path = (p: string) => fileURLToPath(new URL(p, import.meta.url))
const text = (p: string) => readFileSync(path(p), 'utf8')
@@ -78,6 +83,12 @@ describe('PreviewSheet through the shipped module', () => {
for (const viewId of ['main', 'head']) {
const input = JSON.stringify({ viewId })
expect(preview.call('view.canvas', input)).toBe(handle.call('view.canvas', input))
const svg: string = value(preview.call('view.canvas', input)).svg
const ids = [...svg.matchAll(/ id="([^"]*)"/g)].map((m) => m[1])
expect(ids.length).toBeGreaterThan(100)
expect(ids.every((id) => id.startsWith(`fv.${viewId}.`))).toBe(true)
const refs = [...svg.matchAll(/(?:href="#|url\(#)([^")]*)/g)].map((m) => m[1])
expect(refs.every((ref) => ids.includes(ref))).toBe(true)
}
handle.free()
preview.free()
@@ -121,6 +132,10 @@ describe('PreviewSheet through the shipped module', () => {
glue.call('sheet.dependents', JSON.stringify({ document, key: { kind: 'view', id: 'head' } })),
)
expect(head.dependents.length).toBeGreaterThan(0)
const named = JSON.parse(
glue.call('sheet.edit', JSON.stringify({ document, command: { op: 'remove', key: { kind: 'view', id: 'head' } } })),
)
expect(named.kind).toBe('has_dependents')
})
})
@@ -147,7 +162,16 @@ describe('clean_svg through the shipped module', () => {
expect(value(glue.clean_svg(new Uint8Array(readFileSync(path(`${HOSTILE}script.svg`))))).reason).toBe(
'svg_active_content',
)
expect(value(glue.clean_svg(horse)).outcome).toBe('clean')
const cleanHorse = value(glue.clean_svg(horse))
expect([cleanHorse.outcome, cleanHorse.sha256]).toEqual(['clean', HORSE_SHA])
expect(cleanHorse.stored).toBe(new TextDecoder().decode(horse))
const dangling = new TextEncoder().encode('<svg xmlns="http://www.w3.org/2000/svg"><use href="#nope"/></svg>')
expect(value(glue.clean_svg(dangling)).reason).toBe('dangling_reference')
const cairo = value(
glue.clean_svg(new Uint8Array(readFileSync(path(`${EXPORTS}cairo-1.18.4-pycairo-1.27.0-shapes.svg`)))),
)
expect([cairo.outcome, cairo.removed]).toEqual(['clean', []])
expect(cairo.stored.startsWith(PROLOG) && cairo.stored.includes('fill="rgb(20%, 40%, 70%)"')).toBe(true)
console.info(`[core-wasm] clean_svg: ${inputs.length} inputs, slowest ${slowest.toFixed(1)} ms`)
expect(glue.core_version()).toMatch(/^\d+\.\d+\.\d+$/)
})
+1 -1
View File
@@ -1,3 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
export type DrawingResult = "ok" | "missing" | "size_mismatch" | "hash_mismatch" | "svg_rejected" | "svg_removal";
export type DrawingResult = "ok" | "missing" | "size_mismatch" | "hash_mismatch" | "svg_rejected" | "svg_removal" | "svg_not_canonical";
+3 -3
View File
@@ -23,10 +23,10 @@ style_removed: boolean,
*/
preview: string | null,
/**
* Cleanable only: the text to upload.
* Clean or cleanable: the text to upload, the drawing's stored form.
*/
cleaned: string | null,
stored: string | null,
/**
* SHA-256 and size of the bytes to upload: the original (clean) or the cleaned text.
* SHA-256 and size of `stored`, the bytes to upload.
*/
sha256: string | null, byte_size: number | null, };