Owner decision 2026-11-01: the scale bypass (viewBox blown up, drawing scaled back) is closed by the visible size, 4 CSS px on the editor at 320 x 568 (equine junctions 4.97 px), verdict marker_too_small. A frame is usable only where browsers draw it faithfully: edges within 2^20, span from 1 unit, aspect 100, offset 256 spans; measured in 3 engines.
434 lines
15 KiB
Rust
434 lines
15 KiB
Rust
//! V1-2.2 owner brief « arbitrages propriétaire sur les trois MEDIUM » (2026-10-30), defect 3:
|
|
//! an annotation outside the visible frame of its view is refused, by the server verdict and by
|
|
//! the preview, from one frame definition (`anatomy::frame`): the view's `view_box`, else the
|
|
//! `viewBox` of the drawing the view draws, read as a browser reads it. Both composers frame the
|
|
//! view on it and drop the drawing's `preserveAspectRatio` (so `xMidYMid meet`): the whole frame
|
|
//! is what the canvas and the PDF show. The document is never rewritten.
|
|
//!
|
|
//! The reported drawing: the equine horse with its root `viewBox` moved by 10 000 and its
|
|
//! content moved back by a `translate`, pixel-identical, read clean; its 19 main-view markers
|
|
//! were drawn outside the frame.
|
|
#![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)]
|
|
|
|
mod common;
|
|
|
|
use common::sheet_readers::{DETAIL_ASSET, MAIN_ASSET, OPEN, document, drawing, svg};
|
|
use std::collections::HashSet;
|
|
|
|
use faunosteo_core::anatomy::compose::{compose_canvas, compose_highlight};
|
|
use faunosteo_core::anatomy::svg::clean::clean_svg;
|
|
use faunosteo_core::anatomy::svg::read_svg;
|
|
use faunosteo_core::domain::sheet::preview::{PreviewInput, PreviewSheet, PreviewStatus};
|
|
use faunosteo_core::domain::sheet::verdict::{
|
|
DrawingResult, Verdict, VerdictBinding, VerdictDrawing, VerdictInput, codes, compute_verdict,
|
|
sha256_hex,
|
|
};
|
|
use serde_json::{Value, json};
|
|
|
|
const SEED: &str = "supabase/seed/anatomical-sheets/equine/draft";
|
|
const HORSE_ID: &str = "7f767f74-3b36-51a7-8465-52dd7e2ead4a";
|
|
const OUT_OF_FRAME: &str = "annotation.geometry.out_of_frame";
|
|
const NO_FRAME: &str = "view.frame.unknown";
|
|
/// The verdict's closed code (`verdict::codes::OUT_OF_FRAME`), as the SQL stores it.
|
|
const FRAME_FAILURE: &str = "verification.validation.out_of_frame";
|
|
|
|
fn binding() -> VerdictBinding {
|
|
VerdictBinding {
|
|
sheet_id: "s".to_owned(),
|
|
version_id: "v".to_owned(),
|
|
revision: 1,
|
|
review_id: "r".to_owned(),
|
|
}
|
|
}
|
|
|
|
fn verdict(document: &str, drawings: &[(&'static str, &str)]) -> Verdict {
|
|
let rows = drawings
|
|
.iter()
|
|
.map(|(asset_id, text)| VerdictDrawing {
|
|
asset_id,
|
|
sha256: Box::leak(sha256_hex(text.as_bytes()).into_boxed_str()),
|
|
byte_size: text.len() as u64,
|
|
bytes: Some(Box::leak(text.as_bytes().to_vec().into_boxed_slice())),
|
|
})
|
|
.collect();
|
|
compute_verdict(&VerdictInput {
|
|
binding: binding(),
|
|
document,
|
|
base_document: None,
|
|
drawings: rows,
|
|
})
|
|
}
|
|
|
|
/// The frame issues of a draft preview: `(code, path)`.
|
|
fn preview_frame_issues(document: &str, drawings: &[(&str, &str)]) -> Vec<(String, String)> {
|
|
let input = PreviewInput {
|
|
status: PreviewStatus::Draft,
|
|
document: document.to_owned(),
|
|
fingerprint: None,
|
|
};
|
|
let given = drawings
|
|
.iter()
|
|
.map(|(id, text)| drawing(id, text))
|
|
.collect();
|
|
let state = PreviewSheet::load(input, given).unwrap().state().unwrap();
|
|
frame_issues(&state.report.issues)
|
|
}
|
|
|
|
fn frame_issues(issues: &[faunosteo_core::domain::sheet::SheetIssue]) -> Vec<(String, String)> {
|
|
issues
|
|
.iter()
|
|
.filter(|i| i.code == OUT_OF_FRAME || i.code == NO_FRAME)
|
|
.map(|i| (i.code.clone(), i.path.clone()))
|
|
.collect()
|
|
}
|
|
|
|
/// The verdict and the preview agree; answers the frame issues and whether the verdict failed
|
|
/// with the frame code.
|
|
fn judged(document: &str, drawings: &[(&'static str, &str)]) -> (Vec<(String, String)>, bool) {
|
|
let verdict = verdict(document, drawings);
|
|
let from_verdict = frame_issues(&verdict.issues);
|
|
assert_eq!(from_verdict, preview_frame_issues(document, drawings));
|
|
let failed = verdict.failures.iter().any(|f| f == FRAME_FAILURE);
|
|
assert_eq!(failed, !from_verdict.is_empty(), "{:?}", verdict.failures);
|
|
(from_verdict, failed)
|
|
}
|
|
|
|
/// The shared two-view sheet with the main view's one annotation replaced.
|
|
fn with_geometry(view: &str, geometry: Value) -> String {
|
|
let mut doc: Value = serde_json::from_str(&document()).unwrap();
|
|
doc["annotations"][0]["geometry"] = geometry;
|
|
doc["annotations"][0]["view_id"] = json!(view);
|
|
doc.to_string()
|
|
}
|
|
|
|
fn with_view_box(doc: &str, view: usize, view_box: Value) -> String {
|
|
let mut doc: Value = serde_json::from_str(doc).unwrap();
|
|
doc["views"][view]["view_box"] = view_box;
|
|
doc.to_string()
|
|
}
|
|
|
|
fn main_drawing() -> String {
|
|
svg("<path d=\"M0 0h10v10z\"/>")
|
|
}
|
|
|
|
fn accepted(doc: &str) -> bool {
|
|
let main = main_drawing();
|
|
let detail = svg("<path d=\"M0 0h1\"/>");
|
|
judged(doc, &[(MAIN_ASSET, &main), (DETAIL_ASSET, &detail)])
|
|
.0
|
|
.is_empty()
|
|
}
|
|
|
|
fn circle(cx: f64, cy: f64, r: f64) -> Value {
|
|
json!({ "type": "circle", "cx": cx, "cy": cy, "r": r })
|
|
}
|
|
|
|
fn path(d: &str) -> Value {
|
|
json!({ "type": "path", "d": d })
|
|
}
|
|
|
|
fn polygon(points: Value) -> Value {
|
|
json!({ "type": "polygon", "points": points })
|
|
}
|
|
|
|
/// The horse with its frame moved and its content moved back: what a browser draws is the
|
|
/// same horse, the annotations (in the root's coordinates) are not on it any more.
|
|
fn shifted_horse() -> String {
|
|
let horse = common::repo_file(&format!("{SEED}/assets/horse.svg"));
|
|
let frame = "viewBox=\"0 0 2073.4 1629.4\">";
|
|
assert_eq!(horse.matches(frame).count(), 1);
|
|
let text = horse
|
|
.replacen(
|
|
frame,
|
|
"viewBox=\"10000 10000 2073.4 1629.4\"><g transform=\"translate(10000 10000)\">",
|
|
1,
|
|
)
|
|
.replacen("</svg>", "</g></svg>", 1);
|
|
clean_svg(text.as_bytes()).stored.unwrap()
|
|
}
|
|
|
|
#[test]
|
|
fn the_equine_draft_has_every_annotation_in_frame() {
|
|
let text = common::repo_file(&format!("{SEED}/document.json"));
|
|
let horse = common::repo_file(&format!("{SEED}/assets/horse.svg"));
|
|
let (issues, failed) = judged(&text, &[(HORSE_ID, &horse)]);
|
|
assert!(issues.is_empty() && !failed, "{issues:?}");
|
|
}
|
|
|
|
/// The reported defect: refused, the 19 main-view annotations named, the head view (its own
|
|
/// `view_box`) untouched, the document text unchanged.
|
|
#[test]
|
|
fn the_shifted_horse_is_refused_with_its_nineteen_markers() {
|
|
let text = common::repo_file(&format!("{SEED}/document.json"));
|
|
let before = text.clone();
|
|
let shifted = shifted_horse();
|
|
let (issues, failed) = judged(&text, &[(HORSE_ID, &shifted)]);
|
|
assert!(failed);
|
|
assert_eq!(issues.len(), 19, "{issues:?}");
|
|
let doc: Value = serde_json::from_str(&text).unwrap();
|
|
for (code, path) in &issues {
|
|
assert_eq!(code, OUT_OF_FRAME);
|
|
let index: usize = path
|
|
.strip_prefix("annotations[")
|
|
.and_then(|p| p.strip_suffix("].geometry"))
|
|
.unwrap()
|
|
.parse()
|
|
.unwrap();
|
|
assert_eq!(
|
|
doc["annotations"][index]["view_id"],
|
|
json!("main"),
|
|
"{path}"
|
|
);
|
|
}
|
|
assert_eq!(text, before, "the document is never rewritten");
|
|
let verdict = verdict(&text, &[(HORSE_ID, &shifted)]);
|
|
assert_eq!(
|
|
verdict.drawings[0].result,
|
|
DrawingResult::Ok,
|
|
"the drawing reads clean"
|
|
);
|
|
assert_eq!(
|
|
verdict.failures,
|
|
[FRAME_FAILURE],
|
|
"its own code, never a rules failure"
|
|
);
|
|
assert_eq!(verdict.failure_code.as_deref(), Some(FRAME_FAILURE));
|
|
}
|
|
|
|
#[test]
|
|
fn an_annotation_on_the_frame_edges_is_in_frame() {
|
|
assert!(accepted(&with_geometry("main", circle(5.0, 5.0, 5.0))));
|
|
assert!(accepted(&with_geometry("main", circle(1.0, 9.0, 1.0))));
|
|
assert!(accepted(&with_geometry(
|
|
"main",
|
|
polygon(json!([[0, 0], [10, 0], [10, 10], [0, 10]]))
|
|
)));
|
|
assert!(accepted(&with_geometry("main", path("M0 0L10 10H0Z"))));
|
|
}
|
|
|
|
#[test]
|
|
fn an_annotation_past_an_edge_is_refused() {
|
|
for geometry in [
|
|
circle(5.0, 5.0, 5.001),
|
|
circle(0.999, 5.0, 1.0),
|
|
circle(5.0, 9.5, 0.6),
|
|
circle(-3.0, -3.0, 1.0),
|
|
circle(50.0, 50.0, 1.0),
|
|
polygon(json!([[0, 0], [10.001, 0], [5, 5]])),
|
|
polygon(json!([[-1, 5], [5, 5], [5, 6]])),
|
|
path("M1 1L5 5L5 10.5"),
|
|
path("M5 5h-6"),
|
|
] {
|
|
assert!(
|
|
!accepted(&with_geometry("main", geometry.clone())),
|
|
"{geometry}"
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Curves are measured where they go, not by their control points.
|
|
#[test]
|
|
fn curves_and_arcs_are_measured_on_their_shape() {
|
|
for inside in [
|
|
"M1 5C1 -0.5 9 -0.5 9 5",
|
|
"M1 5Q5 -4 9 5",
|
|
"M2 5A3 3 0 0 1 8 5",
|
|
"M2 5A3 3 0 0 0 8 5",
|
|
"M1 5a4 4 0 1 1 8 0a4 4 0 1 1 -8 0",
|
|
"M1 5S5 0 9 5T5 9",
|
|
] {
|
|
assert!(accepted(&with_geometry("main", path(inside))), "{inside}");
|
|
}
|
|
for outside in [
|
|
"M1 1C1 -5 9 -5 9 1",
|
|
"M1 1Q5 -9 9 1",
|
|
"M1 5A6 6 0 1 1 9 5",
|
|
"M1 5A6 6 0 1 0 9 5",
|
|
"M5 1A4 6 90 0 1 5 9",
|
|
] {
|
|
assert!(
|
|
!accepted(&with_geometry("main", path(outside))),
|
|
"{outside}"
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Coordinates a browser would not read as the whole path are refused, never guessed.
|
|
#[test]
|
|
fn unreadable_path_data_is_refused() {
|
|
for d in [
|
|
"M1 1L",
|
|
"M1 1 L 2",
|
|
"L1 1",
|
|
"M1 1 X 2 2",
|
|
"M1e 1",
|
|
"M1 1A1 1 0 2 0 3 3",
|
|
] {
|
|
assert!(!accepted(&with_geometry("main", path(d))), "{d}");
|
|
}
|
|
}
|
|
|
|
/// A secondary view is checked against its own frame: its `view_box`, else its drawing's.
|
|
#[test]
|
|
fn a_secondary_view_is_checked_against_its_own_frame() {
|
|
let cropped = |geometry| {
|
|
with_view_box(
|
|
&with_geometry("detail", geometry),
|
|
1,
|
|
json!({ "min_x": 2, "min_y": 2, "width": 4, "height": 4 }),
|
|
)
|
|
};
|
|
assert!(accepted(&cropped(circle(4.0, 4.0, 2.0))));
|
|
assert!(!accepted(&cropped(circle(7.0, 4.0, 0.5))));
|
|
// No view_box: the detail drawing's own viewBox (0 0 10 10).
|
|
assert!(accepted(&with_geometry("detail", circle(9.0, 9.0, 1.0))));
|
|
assert!(!accepted(&with_geometry("detail", circle(9.5, 9.0, 1.0))));
|
|
}
|
|
|
|
/// The main view's `view_box` wins over the drawing's.
|
|
#[test]
|
|
fn a_view_box_of_the_document_is_the_frame() {
|
|
let framed = |geometry| {
|
|
with_view_box(
|
|
&with_geometry("main", geometry),
|
|
0,
|
|
json!({ "min_x": 100, "min_y": 100, "width": 10, "height": 10 }),
|
|
)
|
|
};
|
|
assert!(accepted(&framed(circle(105.0, 105.0, 1.0))));
|
|
assert!(!accepted(&framed(circle(5.0, 5.0, 1.0))));
|
|
}
|
|
|
|
/// A frame the drawing gives in another spelling is the same frame; a drawing without a
|
|
/// usable `viewBox` under a view without `view_box` has no frame: refused, not guessed.
|
|
#[test]
|
|
fn the_drawing_view_box_is_read_as_a_browser_reads_it() {
|
|
let doc = with_geometry("main", circle(5.0, 5.0, 1.0));
|
|
let detail = svg("<path d=\"M0 0h1\"/>");
|
|
let main_with = |view_box: Option<&str>| {
|
|
let open = match view_box {
|
|
Some(v) => OPEN.replace("viewBox=\"0 0 10 10\"", &format!("viewBox=\"{v}\"")),
|
|
None => OPEN.replace(" viewBox=\"0 0 10 10\"", ""),
|
|
};
|
|
clean_svg(format!("{open}<path d=\"M0 0h10\"/></svg>").as_bytes())
|
|
.stored
|
|
.unwrap()
|
|
};
|
|
for usable in [
|
|
"0,0,10,10",
|
|
" 0 0 10 10 ",
|
|
"0 0 1e1 1e1",
|
|
"-0 -0 +10 10.0",
|
|
"0, 0 10 ,10",
|
|
] {
|
|
let main = main_with(Some(usable));
|
|
let (issues, _) = judged(&doc, &[(MAIN_ASSET, &main), (DETAIL_ASSET, &detail)]);
|
|
assert!(issues.is_empty(), "{usable}: {issues:?}");
|
|
}
|
|
for unusable in [
|
|
None,
|
|
Some("0 0 0 10"),
|
|
Some("0 0 10 -10"),
|
|
Some("0 0 10"),
|
|
Some("0 0 10 10 10"),
|
|
Some("0x0 0 10 10"),
|
|
Some("0 0 10 10px"),
|
|
Some("0 0 1e999 10"),
|
|
Some(""),
|
|
] {
|
|
let main = main_with(unusable);
|
|
let (issues, failed) = judged(&doc, &[(MAIN_ASSET, &main), (DETAIL_ASSET, &detail)]);
|
|
assert!(failed, "{unusable:?}");
|
|
assert_eq!(
|
|
issues,
|
|
[(NO_FRAME.to_owned(), "views[0]".to_owned())],
|
|
"{unusable:?}"
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Transforms inside the drawing move the drawing, never the annotations: a drawing scaled or
|
|
/// moved inside an unchanged frame keeps its annotations in frame; a frame moved with its
|
|
/// annotations is in frame too.
|
|
#[test]
|
|
fn legitimate_transforms_are_accepted() {
|
|
let detail = svg("<path d=\"M0 0h1\"/>");
|
|
let doc = with_geometry("main", circle(5.0, 5.0, 1.0));
|
|
let scaled = clean_svg(
|
|
svg("<g transform=\"scale(0.5) translate(3 3)\"><path d=\"M0 0h10v10z\"/></g>").as_bytes(),
|
|
)
|
|
.stored
|
|
.unwrap();
|
|
assert!(
|
|
judged(&doc, &[(MAIN_ASSET, &scaled), (DETAIL_ASSET, &detail)])
|
|
.0
|
|
.is_empty()
|
|
);
|
|
|
|
let open = OPEN.replace("viewBox=\"0 0 10 10\"", "viewBox=\"100 100 10 10\"");
|
|
let moved = clean_svg(format!("{open}<path d=\"M100 100h10\"/></svg>").as_bytes())
|
|
.stored
|
|
.unwrap();
|
|
let moved_doc = with_geometry("main", circle(105.0, 105.0, 1.0));
|
|
assert!(
|
|
judged(&moved_doc, &[(MAIN_ASSET, &moved), (DETAIL_ASSET, &detail)])
|
|
.0
|
|
.is_empty()
|
|
);
|
|
let (issues, failed) = judged(&doc, &[(MAIN_ASSET, &moved), (DETAIL_ASSET, &detail)]);
|
|
assert!(failed && issues.len() == 1);
|
|
}
|
|
|
|
/// A drawing missing or refused fails on its own code; its views are not measured.
|
|
#[test]
|
|
fn a_view_whose_drawing_is_missing_is_not_measured() {
|
|
let doc = with_geometry("main", circle(50.0, 50.0, 1.0));
|
|
let detail = svg("<path d=\"M0 0h1\"/>");
|
|
let verdict = verdict(&doc, &[(DETAIL_ASSET, &detail)]);
|
|
assert!(verdict.failures.iter().any(|f| f == codes::DRAWING_MISSING));
|
|
assert!(frame_issues(&verdict.issues).is_empty());
|
|
}
|
|
|
|
/// The composers frame each view on the same frame and own its fitting: the drawing's
|
|
/// `preserveAspectRatio` (here `slice`, which crops) never reaches the composed root.
|
|
#[test]
|
|
fn both_composers_frame_the_view_on_the_measured_frame() {
|
|
let sheet = common::sheet_readers::sheet();
|
|
let ids: HashSet<&str> = ["hock"].into_iter().collect();
|
|
let text = OPEN.replace(
|
|
"viewBox=\"0 0 10 10\"",
|
|
"preserveAspectRatio=\"xMidYMid slice\" viewBox=\"0,0,10,10\"",
|
|
) + "<path d=\"M0 0h10\"/></svg>";
|
|
let root = read_svg(&text).unwrap().root;
|
|
let canvas = compose_canvas(&sheet, "main", &root).unwrap();
|
|
let pdf = compose_highlight(&sheet, "main", root, &ids, false).unwrap();
|
|
for composed in [&canvas, &pdf] {
|
|
assert_eq!(composed.attr("viewBox"), Some("0 0 10 10"));
|
|
assert_eq!(composed.attr("preserveAspectRatio"), None);
|
|
}
|
|
}
|
|
|
|
/// The edge slack follows the frame's span, never its offset: a frame far from the origin
|
|
/// keeps the same strictness (security review of the three-MEDIUM brief). Since the owner
|
|
/// brief of 2026-11-01 a frame that far (`1e15`) is unusable (`f32` range rules); at the
|
|
/// largest offset still accepted (256 spans) the edge is as strict.
|
|
#[test]
|
|
fn a_frame_far_from_the_origin_is_as_strict() {
|
|
let far = |min_x: f64, cx: f64| {
|
|
with_view_box(
|
|
&with_geometry("main", circle(cx, 5.0, 1.0)),
|
|
0,
|
|
json!({ "min_x": min_x, "min_y": 0, "width": 10, "height": 10 }),
|
|
)
|
|
};
|
|
assert!(accepted(&far(2550.0, 2559.0)), "edge reached");
|
|
assert!(
|
|
!accepted(&far(2550.0, 2559.0 + 1e-6)),
|
|
"a millionth past the edge"
|
|
);
|
|
assert!(
|
|
!accepted(&far(1e15, 1e15 + 5.0)),
|
|
"a frame at 1e15 is not usable"
|
|
);
|
|
}
|