fix(anatomy): V1-2.2 refuse markers too small on the phone preview
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.
This commit is contained in:
1 parent
9c606aa567
commit
96b99784b5
17 files changed
+944
-37
No files matched your search
@@ -409,16 +409,25 @@ fn both_composers_frame_the_view_on_the_measured_frame() {
|
||||
}
|
||||
|
||||
/// 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).
|
||||
/// 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 = |cx: f64| {
|
||||
let far = |min_x: f64, cx: f64| {
|
||||
with_view_box(
|
||||
&with_geometry("main", circle(cx, 5.0, 1.0)),
|
||||
0,
|
||||
json!({ "min_x": 1e15, "min_y": 0, "width": 1000, "height": 10 }),
|
||||
json!({ "min_x": min_x, "min_y": 0, "width": 10, "height": 10 }),
|
||||
)
|
||||
};
|
||||
assert!(accepted(&far(1e15 + 500.0)));
|
||||
assert!(!accepted(&far(1e15 + 5000.0)));
|
||||
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"
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,362 @@
|
||||
//! V1-2.2 owner brief « décisions et poursuite des corrections » (2026-11-01), the scale
|
||||
//! bypass: the horse with its `viewBox` blown up and its content scaled back is the same horse,
|
||||
//! every marker in frame and shrunk to a speck, accepted. Two rules of `anatomy::frame` close
|
||||
//! it, one definition for the verdict and the preview: every annotation shows at least 4 CSS px
|
||||
//! on the smallest preview (the editor at 320 × 568: the main view's 286 × 310 box, a detail
|
||||
//! view's 254 × 191; the visible disc for a point, the smaller side for a shape), and a frame is
|
||||
//! usable only within the `f32` range rules (magnitude, span, aspect, offset against the span).
|
||||
//! The document is never rewritten.
|
||||
#![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)]
|
||||
|
||||
mod common;
|
||||
|
||||
use common::sheet_readers::{DETAIL_ASSET, MAIN_ASSET, OPEN, document, drawing};
|
||||
use faunosteo_core::anatomy::frame::{
|
||||
MAX_FRAME_ASPECT, MAX_FRAME_MAGNITUDE, MAX_FRAME_OFFSET_RATIO, MIN_FRAME_SPAN, MIN_VISIBLE_PX,
|
||||
};
|
||||
use faunosteo_core::anatomy::svg::clean::clean_svg;
|
||||
use faunosteo_core::domain::sheet::preview::{PreviewInput, PreviewSheet, PreviewStatus};
|
||||
use faunosteo_core::domain::sheet::verdict::{
|
||||
VerdictBinding, VerdictDrawing, VerdictInput, 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 TOO_SMALL: &str = "annotation.geometry.too_small";
|
||||
const NO_FRAME: &str = "view.frame.unknown";
|
||||
const OUT_OF_FRAME: &str = "annotation.geometry.out_of_frame";
|
||||
/// The verdict's closed codes, as the SQL stores them.
|
||||
const SMALL_FAILURE: &str = "verification.validation.marker_too_small";
|
||||
const FRAME_FAILURE: &str = "verification.validation.out_of_frame";
|
||||
|
||||
/// The frame and size issues `(code, path)`, the verdict and the preview agreeing, and the
|
||||
/// verdict's failures.
|
||||
fn judged(
|
||||
document: &str,
|
||||
drawings: &[(&'static str, &str)],
|
||||
) -> (Vec<(String, String)>, Vec<String>) {
|
||||
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();
|
||||
let verdict = compute_verdict(&VerdictInput {
|
||||
binding: VerdictBinding {
|
||||
sheet_id: "s".to_owned(),
|
||||
version_id: "v".to_owned(),
|
||||
revision: 1,
|
||||
review_id: "r".to_owned(),
|
||||
},
|
||||
document,
|
||||
base_document: None,
|
||||
drawings: rows,
|
||||
});
|
||||
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();
|
||||
let issues = |all: &[faunosteo_core::domain::sheet::SheetIssue]| -> Vec<(String, String)> {
|
||||
all.iter()
|
||||
.filter(|i| [TOO_SMALL, NO_FRAME, OUT_OF_FRAME].contains(&i.code.as_str()))
|
||||
.map(|i| (i.code.clone(), i.path.clone()))
|
||||
.collect()
|
||||
};
|
||||
let found = issues(&verdict.issues);
|
||||
assert_eq!(
|
||||
found,
|
||||
issues(&state.report.issues),
|
||||
"verdict and preview agree"
|
||||
);
|
||||
(found, verdict.failures)
|
||||
}
|
||||
|
||||
/// The shared sheet with the given geometry on its first annotation, and drawings with the
|
||||
/// given `viewBox` values.
|
||||
fn shared(
|
||||
view: &str,
|
||||
geometry: Value,
|
||||
main_box: &str,
|
||||
detail_box: &str,
|
||||
) -> (Vec<(String, String)>, Vec<String>) {
|
||||
let mut doc: Value = serde_json::from_str(&document()).unwrap();
|
||||
doc["annotations"][0]["geometry"] = geometry;
|
||||
doc["annotations"][0]["view_id"] = json!(view);
|
||||
let main = OPEN.replace("0 0 10 10", main_box) + "<path d=\"M0 0h1\"/></svg>";
|
||||
let detail = OPEN.replace("0 0 10 10", detail_box) + "<path d=\"M0 0h1\"/></svg>";
|
||||
judged(
|
||||
&doc.to_string(),
|
||||
&[(MAIN_ASSET, &main), (DETAIL_ASSET, &detail)],
|
||||
)
|
||||
}
|
||||
|
||||
fn on_main(geometry: Value, view_box: &str) -> (Vec<(String, String)>, Vec<String>) {
|
||||
shared("main", geometry, view_box, "0 0 10 10")
|
||||
}
|
||||
|
||||
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 codes(found: &(Vec<(String, String)>, Vec<String>)) -> Vec<String> {
|
||||
found.0.iter().map(|(code, _)| code.clone()).collect()
|
||||
}
|
||||
|
||||
/// The horse with its `viewBox` multiplied by `factor` and its content scaled back.
|
||||
fn scaled_horse(factor: f64) -> 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,
|
||||
&format!(
|
||||
"viewBox=\"0 0 {} {}\"><g transform=\"scale({factor})\">",
|
||||
2073.4 * factor,
|
||||
1629.4 * factor
|
||||
),
|
||||
1,
|
||||
)
|
||||
.replacen("</svg>", "</g></svg>", 1);
|
||||
clean_svg(text.as_bytes()).stored.unwrap()
|
||||
}
|
||||
|
||||
fn equine() -> String {
|
||||
common::repo_file(&format!("{SEED}/document.json"))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_equine_draft_shows_every_marker_on_the_phone_preview() {
|
||||
let horse = common::repo_file(&format!("{SEED}/assets/horse.svg"));
|
||||
let (issues, failures) = judged(&equine(), &[(HORSE_ID, &horse)]);
|
||||
assert!(issues.is_empty(), "{issues:?}");
|
||||
assert!(failures.is_empty(), "{failures:?}");
|
||||
// The smallest: the junctions (r 30, disc r 18) at 286 / 2073.4 px per unit.
|
||||
let junction = 36.0 * 286.0 / 2073.4;
|
||||
assert!((4.96..4.97).contains(&junction) && junction >= MIN_VISIBLE_PX);
|
||||
}
|
||||
|
||||
/// The bypass: scaled ×100, every one of the 19 main-view markers is refused as too small (the
|
||||
/// head view has its own `view_box`); scaled ×1 000 the frame passes `2²⁰` and is not usable.
|
||||
/// The document text never changes.
|
||||
#[test]
|
||||
fn the_blown_up_horse_is_refused() {
|
||||
let text = equine();
|
||||
let (issues, failures) = judged(&text, &[(HORSE_ID, &scaled_horse(100.0))]);
|
||||
assert_eq!(issues.len(), 19, "{issues:?}");
|
||||
assert!(
|
||||
issues.iter().all(|(code, _)| code == TOO_SMALL),
|
||||
"{issues:?}"
|
||||
);
|
||||
assert_eq!(failures, [SMALL_FAILURE]);
|
||||
let doc: Value = serde_json::from_str(&text).unwrap();
|
||||
for (_, path) in &issues {
|
||||
let index: usize = path
|
||||
.strip_prefix("annotations[")
|
||||
.and_then(|p| p.strip_suffix("].geometry"))
|
||||
.unwrap()
|
||||
.parse()
|
||||
.unwrap();
|
||||
assert_eq!(doc["annotations"][index]["view_id"], "main");
|
||||
}
|
||||
let (issues, failures) = judged(&text, &[(HORSE_ID, &scaled_horse(1000.0))]);
|
||||
assert_eq!(issues, [(NO_FRAME.to_owned(), "views[0]".to_owned())]);
|
||||
assert_eq!(failures, [FRAME_FAILURE]);
|
||||
assert_eq!(text, equine(), "the document is never rewritten");
|
||||
}
|
||||
|
||||
/// The threshold on the real sheet: the junctions fall below 4 px once the horse is scaled by
|
||||
/// more than 4.966 / 4 ≈ 1.2414; the other points (disc r 22) hold until ≈ 1.517.
|
||||
#[test]
|
||||
fn the_equine_threshold_falls_on_the_junctions_first() {
|
||||
let text = equine();
|
||||
let small = |factor: f64| -> Vec<String> {
|
||||
let (issues, _) = judged(&text, &[(HORSE_ID, &scaled_horse(factor))]);
|
||||
let doc: Value = serde_json::from_str(&text).unwrap();
|
||||
issues
|
||||
.iter()
|
||||
.map(|(_, path)| {
|
||||
let index: usize = path[12..path.len() - 10].parse().unwrap();
|
||||
doc["annotations"][index]["id"].as_str().unwrap().to_owned()
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
assert!(small(1.24).is_empty());
|
||||
let mut junctions = small(1.25);
|
||||
junctions.sort();
|
||||
assert_eq!(junctions, ["c7-t1", "l6-s1", "t18-l1"]);
|
||||
assert_eq!(small(1.51).len(), 3);
|
||||
assert_eq!(small(1.52).len(), 13, "every point, the zones still shown");
|
||||
}
|
||||
|
||||
/// A point shows its visible disc, `2 × max(2, r − 12)`, never its transparent hitbox; at
|
||||
/// 28.6 px per unit (a 10-unit frame on the main box) the disc floor of 4 units shows 114 px.
|
||||
#[test]
|
||||
fn a_point_is_measured_on_its_visible_disc() {
|
||||
// A 1 000-unit frame: 0.286 px per unit. Hitbox r 20 (11.4 px across), disc r 8: 4.58 px.
|
||||
assert!(codes(&on_main(circle(500.0, 500.0, 20.0), "0 0 1000 1000")).is_empty());
|
||||
// Disc r 6 (r 18): 3.43 px, while the hitbox would show 10.3 px.
|
||||
assert_eq!(
|
||||
codes(&on_main(circle(500.0, 500.0, 18.0), "0 0 1000 1000")),
|
||||
[TOO_SMALL]
|
||||
);
|
||||
// Under r 14 the disc stays r 2: a frame of 10 units shows it 114 px.
|
||||
assert!(codes(&on_main(circle(5.0, 5.0, 1.0), "0 0 10 10")).is_empty());
|
||||
}
|
||||
|
||||
/// A detail view is measured on the dialog's box (254 × 191), the main view on its own
|
||||
/// (286 × 310): the same disc on the same 200-unit frame shows 3.82 px in a detail view,
|
||||
/// 5.72 px on the main view.
|
||||
#[test]
|
||||
fn a_detail_view_is_measured_on_the_dialog_box() {
|
||||
let disc = circle(100.0, 100.0, 1.0);
|
||||
assert!(codes(&shared("main", disc.clone(), "0 0 200 200", "0 0 200 200")).is_empty());
|
||||
assert_eq!(
|
||||
codes(&shared("detail", disc, "0 0 200 200", "0 0 200 200")),
|
||||
[TOO_SMALL]
|
||||
);
|
||||
}
|
||||
|
||||
/// Shapes show their smaller side, measured on the curve (never the control points) and the
|
||||
/// arc: on a 10-unit frame (28.6 px per unit), 4 px is 0.14 unit.
|
||||
#[test]
|
||||
fn shapes_are_measured_on_their_curves_and_arcs() {
|
||||
let main = |d: &str| codes(&on_main(path(d), "0 0 10 10"));
|
||||
// A cubic whose control points rise 0.18 (5.1 px) while the curve rises 0.135 (3.9 px).
|
||||
assert_eq!(main("M1 1 C1 1.18 3 1.18 3 1 Z"), [TOO_SMALL]);
|
||||
assert!(
|
||||
main("M1 1 C1 1.2 3 1.2 3 1 Z").is_empty(),
|
||||
"rises 0.15: 4.3 px"
|
||||
);
|
||||
// A half ellipse of radius 0.06 (1.7 px), then 0.2 (5.7 px).
|
||||
assert_eq!(main("M1 1 A1 0.06 0 0 1 3 1 Z"), [TOO_SMALL]);
|
||||
assert!(main("M1 1 A1 0.2 0 0 1 3 1 Z").is_empty());
|
||||
// A flat polygon has no smaller side. Declared limit: a thin shape drawn on a diagonal is
|
||||
// measured on its bounds (the rule is a scale floor, never a shape review).
|
||||
let line = json!({ "type": "polygon", "points": [[1, 1], [5, 1], [9, 1]] });
|
||||
assert_eq!(codes(&on_main(line, "0 0 10 10")), [TOO_SMALL]);
|
||||
}
|
||||
|
||||
/// The frame range rules, each at its limit and one step past it; past it the frame is not
|
||||
/// usable (`view.frame.unknown`, the frame failure).
|
||||
#[test]
|
||||
fn the_frame_range_rules_hold_at_their_limits() {
|
||||
let at =
|
||||
|view_box: &str, cx: f64, cy: f64, r: f64| codes(&on_main(circle(cx, cy, r), view_box));
|
||||
// Magnitude: the far edge at 2²⁰ (span 2¹³: the offset ratio, 128, holds on both sides).
|
||||
let span = 8192.0;
|
||||
let near = MAX_FRAME_MAGNITUDE - span;
|
||||
let edge = format!("{near} 0 {span} {span}");
|
||||
assert!(at(&edge, near + 4096.0, 4096.0, 200.0).is_empty(), "{edge}");
|
||||
let past = format!("{} 0 {span} {span}", near + 1.0);
|
||||
assert_eq!(at(&past, near + 4096.0, 4096.0, 200.0), [NO_FRAME]);
|
||||
// Span: one unit is usable, just below it is not (browsers stop painting a frame of
|
||||
// `2⁻⁷`, see `MIN_FRAME_SPAN`).
|
||||
assert!(
|
||||
at(
|
||||
&format!("0 0 {MIN_FRAME_SPAN} {MIN_FRAME_SPAN}"),
|
||||
0.5,
|
||||
0.5,
|
||||
0.25
|
||||
)
|
||||
.is_empty()
|
||||
);
|
||||
assert_eq!(at("0 0 0.999 0.999", 0.5, 0.5, 0.25), [NO_FRAME]);
|
||||
assert_eq!(
|
||||
at("0 0 0.0078125 0.0078125", 0.004, 0.004, 0.002),
|
||||
[NO_FRAME]
|
||||
);
|
||||
// Aspect, on the main view while the annotation sits on the detail view (a frame of aspect
|
||||
// 100 is at most 2.86 px tall on the phone, so nothing in it shows 4 px): 100, then 101.
|
||||
let band = |w: f64| {
|
||||
codes(&shared(
|
||||
"detail",
|
||||
circle(5.0, 5.0, 1.0),
|
||||
&format!("0 0 {w} 10"),
|
||||
"0 0 10 10",
|
||||
))
|
||||
};
|
||||
assert!(band(10.0 * MAX_FRAME_ASPECT).is_empty());
|
||||
assert_eq!(band(10.0 * MAX_FRAME_ASPECT + 10.0), [NO_FRAME]);
|
||||
// Offset: the far edge at 256 spans, then past it.
|
||||
let ratio = MAX_FRAME_OFFSET_RATIO;
|
||||
assert!(
|
||||
at(
|
||||
&format!("{} 0 10 10", ratio * 10.0 - 10.0),
|
||||
ratio * 10.0 - 5.0,
|
||||
5.0,
|
||||
1.0
|
||||
)
|
||||
.is_empty()
|
||||
);
|
||||
assert_eq!(
|
||||
at(
|
||||
&format!("{} 0 10 10", ratio * 10.0 - 9.0),
|
||||
ratio * 10.0 - 4.0,
|
||||
5.0,
|
||||
1.0
|
||||
),
|
||||
[NO_FRAME]
|
||||
);
|
||||
// Negative offsets count the same.
|
||||
assert_eq!(
|
||||
at(
|
||||
&format!("{} 0 10 10", -ratio * 10.0 - 1.0),
|
||||
-ratio * 10.0 + 4.0,
|
||||
5.0,
|
||||
1.0
|
||||
),
|
||||
[NO_FRAME]
|
||||
);
|
||||
}
|
||||
|
||||
/// A view's own `view_box` follows the same rules as a drawing's `viewBox`.
|
||||
#[test]
|
||||
fn a_view_box_follows_the_same_rules() {
|
||||
let mut doc: Value = serde_json::from_str(&document()).unwrap();
|
||||
doc["views"][0]["view_box"] = json!({ "min_x": 1e7, "min_y": 0, "width": 10, "height": 10 });
|
||||
doc["annotations"][0]["geometry"] = circle(1e7 + 5.0, 5.0, 1.0);
|
||||
let main = OPEN.to_owned() + "<path d=\"M0 0h1\"/></svg>";
|
||||
let (issues, failures) = judged(
|
||||
&doc.to_string(),
|
||||
&[(MAIN_ASSET, &main), (DETAIL_ASSET, &main)],
|
||||
);
|
||||
assert_eq!(issues, [(NO_FRAME.to_owned(), "views[0]".to_owned())]);
|
||||
// The shared sheet fails `verification.validation.rules` on its own; the frame code joins it.
|
||||
assert!(failures.iter().any(|f| f == FRAME_FAILURE), "{failures:?}");
|
||||
}
|
||||
|
||||
/// The drawing's own transforms move the drawing only (the markers are drawn by the engine, in
|
||||
/// the frame's user space): a drawing scaled down to nothing keeps its markers' size, and the
|
||||
/// rule measures them alone.
|
||||
#[test]
|
||||
fn transforms_inside_the_drawing_never_change_the_measure() {
|
||||
let mut doc: Value = serde_json::from_str(&document()).unwrap();
|
||||
doc["annotations"][0]["geometry"] = circle(5.0, 5.0, 1.0);
|
||||
let tiny =
|
||||
OPEN.to_owned() + "<g transform=\"scale(0.000001)\"><path d=\"M0 0h10v10z\"/></g></svg>";
|
||||
let main = OPEN.to_owned() + "<path d=\"M0 0h1\"/></svg>";
|
||||
let (issues, failures) = judged(
|
||||
&doc.to_string(),
|
||||
&[(MAIN_ASSET, &tiny), (DETAIL_ASSET, &main)],
|
||||
);
|
||||
let measured = |f: &String| f == FRAME_FAILURE || f == SMALL_FAILURE;
|
||||
assert!(
|
||||
issues.is_empty() && !failures.iter().any(measured),
|
||||
"{issues:?} {failures:?}"
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user