mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 02:35:37 +01:00
Tests: merge two duplicate engine tests, keeping every assertion
Two engine tests ran the same inputs as another test and checked them
again with a tighter bound or a second check.
- commands_that_do_not_wait_for_a_tool_edit_change_no_document ran every
junk case of every non-waiting command on the Single and Multi
fixtures, which every_command_with_junk_params also runs. The junk
sweep now compares tool_edit_state before and after each of those
calls as well as its own panic, interaction and invariant checks. The
tool-edit test keeps only the cases that turn each option on and off
(option_cases), which the junk sweep does not send.
- turned_colored_inflate_facets_and_seams_cover_their_edges_once drew
the same turned Inflate in the same solid fill as one case of
colored_light_surfaces_match_supersampling_at_internal_facet_edges.
That case now carries its bound (at most one RGB channel more than 3
levels off, by no more than 4) and the separate test is removed.
Each merged test fails on a fault that only the removed check caught
before: document.info bumping the revision on a non-object params value
fails every_command_with_junk_params ("document.info "str" [Multi]"),
and solid_surface drawing every facet as a fill and a seam stroke fails
the supersampling test (2 channels off, at most 5).
docs/target-app-parity.md and waits_for_tool_edit's doc comment name
the tests that now hold these checks.
This commit is contained in:
1 parent
68dbab8b90
commit
13b9e22c4c
4 files changed
+52
-49
No files matched your search
@@ -118,8 +118,8 @@ const WAIT_FOR_TOOL_EDIT: &[&str] = &[
|
||||
/// Does command `id`, run on its own, first apply the edit the active tool is computing on
|
||||
/// another thread and the input held for it ([`Session::finish_tool_edit`])? Every command that
|
||||
/// can edit, select, save or give a document a new revision does; queries that only read do not
|
||||
/// (`commands_that_do_not_wait_for_a_tool_edit_change_no_document` in the command sweep checks
|
||||
/// them). A frontend that adds params from
|
||||
/// (`every_command_with_junk_params` and `commands_that_do_not_wait_for_a_tool_edit_change_no_document`
|
||||
/// in the command sweep check them). A frontend that adds params from
|
||||
/// its own state (the active artboard) applies them first itself.
|
||||
pub fn waits_for_tool_edit(id: &str) -> bool {
|
||||
find_command(id).is_some_and(|spec| spec.journal || WAIT_FOR_TOOL_EDIT.contains(&id))
|
||||
|
||||
@@ -30,17 +30,27 @@ fn no_panic(r: Result<Value, vectorcraft_engine::EngineError>) -> Result<Value,
|
||||
|
||||
/// Run one call; returns a failure description or None.
|
||||
fn probe(fx: Fixture, id: &str, params: &Value) -> Option<String> {
|
||||
probe_and_compare(fx, id, params, false).0
|
||||
}
|
||||
|
||||
/// Run one call as [`probe`] does, returning its failure description, and with `compare`, also
|
||||
/// `id params [fixture]` when the call changed the session's [`tool_edit_state`], panic or not.
|
||||
fn probe_and_compare(fx: Fixture, id: &str, params: &Value, compare: bool) -> (Option<String>, Option<String>) {
|
||||
let mut s = fx.session();
|
||||
let before = compare.then(|| tool_edit_state(&s));
|
||||
let r = catch_quiet(|| no_panic(s.execute(id, params)));
|
||||
match r {
|
||||
let changed = before.filter(|b| tool_edit_state(&s) != *b).map(|_| format!("{id} {params} [{fx:?}]"));
|
||||
let failure = match r {
|
||||
Err(msg) => Some(format!("PANIC {id} {params} [{fx:?}]: {msg}")),
|
||||
Ok(_) => {
|
||||
if s.in_interaction() {
|
||||
return Some(format!("{id} {params} [{fx:?}]: left an interaction open"));
|
||||
Some(format!("{id} {params} [{fx:?}]: left an interaction open"))
|
||||
} else {
|
||||
check_session(&s).err().map(|e| format!("{id} {params} [{fx:?}]: {e}"))
|
||||
}
|
||||
check_session(&s).err().map(|e| format!("{id} {params} [{fx:?}]: {e}"))
|
||||
}
|
||||
}
|
||||
};
|
||||
(failure, changed)
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -223,31 +233,43 @@ fn junk_cases(c: &vectorcraft_engine::CommandSpec, path: &str) -> Vec<Value> {
|
||||
cases
|
||||
}
|
||||
|
||||
/// Every command with every junk case in every fixture: no panic, no interaction left open and no
|
||||
/// broken invariant ([`probe`]). In `Single` and `Multi`, every command that runs at once while the
|
||||
/// active tool computes an edit on another thread (it does not `waits_for_tool_edit`) also leaves
|
||||
/// the documents' revisions and selections, the active document and the current paint as they were
|
||||
/// ([`tool_edit_state`]), as `commands_that_do_not_wait_for_a_tool_edit_change_no_document` checks
|
||||
/// for the cases that turn each option on and off.
|
||||
#[test]
|
||||
fn every_command_with_junk_params() {
|
||||
let dir = vectorcraft_testkit::TempDir::new("sweep");
|
||||
let path = safe_path(&dir);
|
||||
let mut failures = vec![];
|
||||
let mut changed = vec![];
|
||||
let mut calls = 0usize;
|
||||
for fx in Fixture::ALL {
|
||||
for c in command_specs() {
|
||||
let compare = matches!(fx, Fixture::Single | Fixture::Multi) && !vectorcraft_engine::waits_for_tool_edit(c.id);
|
||||
let cases = junk_cases(c, &path);
|
||||
for p in &cases {
|
||||
calls += 1;
|
||||
if let Some(f) = probe(fx, c.id, p) {
|
||||
failures.push(f);
|
||||
}
|
||||
let (failure, change) = probe_and_compare(fx, c.id, p, compare);
|
||||
failures.extend(failure);
|
||||
changed.extend(change);
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(calls > 5_000, "only {calls} calls");
|
||||
failures.sort();
|
||||
failures.dedup();
|
||||
changed.sort();
|
||||
changed.dedup_by(|a, b| a.split(' ').next() == b.split(' ').next());
|
||||
assert!(
|
||||
failures.is_empty(),
|
||||
"{} failures (of {calls} calls):\n{}",
|
||||
failures.is_empty() && changed.is_empty(),
|
||||
"{} failures (of {calls} calls):\n{}\n{} commands change a document without waiting for a tool edit:\n{}",
|
||||
failures.len(),
|
||||
failures.iter().take(60).cloned().collect::<Vec<_>>().join("\n")
|
||||
failures.iter().take(60).cloned().collect::<Vec<_>>().join("\n"),
|
||||
changed.len(),
|
||||
changed.join("\n")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -262,10 +284,11 @@ fn tool_edit_state(s: &Session) -> ToolEditState {
|
||||
(docs, s.active_index(), s.paint.clone())
|
||||
}
|
||||
|
||||
/// The params the tool-edit sweep sends `c`: junk params, then each documented key turned on and
|
||||
/// off, with a string under a file or folder key replaced by a location inside `path`'s folder.
|
||||
fn tool_edit_cases(c: &vectorcraft_engine::CommandSpec, path: &str) -> Vec<Value> {
|
||||
let mut cases = junk_cases(c, path);
|
||||
/// The params the tool-edit sweep sends `c` beyond its junk cases, which the junk sweep checks:
|
||||
/// each documented key turned on and off, with a string under a file or folder key replaced by a
|
||||
/// location inside `path`'s folder.
|
||||
fn option_cases(c: &vectorcraft_engine::CommandSpec, path: &str) -> Vec<Value> {
|
||||
let mut cases = vec![];
|
||||
for k in command_param_keys(c) {
|
||||
for v in [json!(true), json!(false), json!(1), json!("on")] {
|
||||
cases.push(json!({ k.as_str(): safe_value_for_command(c, &k, &v, path) }));
|
||||
@@ -333,7 +356,7 @@ fn sweep_cases_name_files_only_inside_the_temp_folder() {
|
||||
}
|
||||
}
|
||||
let mut cases = junk_params_for_command(c, &path);
|
||||
cases.extend(tool_edit_cases(c, &path));
|
||||
cases.extend(option_cases(c, &path));
|
||||
cases.extend(serializable_cases(c, &path));
|
||||
for p in &cases {
|
||||
let Some(o) = p.as_object() else { continue };
|
||||
@@ -485,8 +508,9 @@ fn sweep_cases_send_the_file_keys_of_the_command_catalog() {
|
||||
/// Every command that runs at once while the active tool computes an edit on another thread (a
|
||||
/// Shape Builder merge), rather than applying the edit first (`waits_for_tool_edit`), leaves the
|
||||
/// documents' revisions and selections, the active document and the current paint as they were,
|
||||
/// with `{}`, junk params and params that turn its options on and off: the edit, computed for the
|
||||
/// document as it was, still applies after it.
|
||||
/// with params that turn its options on and off ([`option_cases`]; `every_command_with_junk_params`
|
||||
/// checks the same with the junk cases): the edit, computed for the document as it was, still
|
||||
/// applies after it.
|
||||
#[test]
|
||||
fn commands_that_do_not_wait_for_a_tool_edit_change_no_document() {
|
||||
let dir = vectorcraft_testkit::TempDir::new("sweep");
|
||||
@@ -494,7 +518,7 @@ fn commands_that_do_not_wait_for_a_tool_edit_change_no_document() {
|
||||
let mut failures = vec![];
|
||||
for fx in [Fixture::Single, Fixture::Multi] {
|
||||
for c in command_specs().iter().filter(|c| !vectorcraft_engine::waits_for_tool_edit(c.id)) {
|
||||
let cases = tool_edit_cases(c, &path);
|
||||
let cases = option_cases(c, &path);
|
||||
for p in &cases {
|
||||
let mut s = fx.session();
|
||||
let before = tool_edit_state(&s);
|
||||
|
||||
@@ -533,7 +533,8 @@ fn seams_against_supersampled(d: &Document, image: &vectorcraft_render::Rendered
|
||||
/// opacity once over the surface. Inflate seen straight on, one layer of facets, has no alpha off, and
|
||||
/// in opaque fills no RGB channel more than 3 levels off. Inflate turned so facets narrow to slivers
|
||||
/// at the edges, and Revolve with a cap over its body, draw facets over other facets, and have no
|
||||
/// alpha off.
|
||||
/// alpha off. In the turned Inflate's opaque solid fill, each facet and its seam cover an edge pixel
|
||||
/// once together, so at most one RGB channel is more than 3 levels off, by no more than 4.
|
||||
#[test]
|
||||
fn colored_light_surfaces_match_supersampling_at_internal_facet_edges() {
|
||||
let lights = json!([
|
||||
@@ -556,20 +557,21 @@ fn colored_light_surfaces_match_supersampling_at_internal_facet_edges() {
|
||||
let (mut s, _) = setup("threeD.inflate");
|
||||
let change = json!({"index":0,"item":null,"params":{"ambient":10,"lights":lights,"rotationX":rotation.0,"rotationY":rotation.1}});
|
||||
s.execute("effect.setParams", &change).unwrap();
|
||||
cases.push((format!("inflate {rotation:?}"), s, fills([100, 150], [200, 150]), rotation == (0, 0)));
|
||||
cases.push((format!("inflate {rotation:?}"), s, fills([100, 150], [200, 150]), rotation == (0, 0), rotation == (50, 35)));
|
||||
}
|
||||
let (mut s, _) = capped_profile();
|
||||
s.execute("effect.setParams", &json!({"index":0,"item":null,"params":{"ambient":10,"lights":lights}})).unwrap();
|
||||
cases.push(("revolve".into(), s, fills([80, 200], [240, 200]), false));
|
||||
cases.push(("revolve".into(), s, fills([80, 200], [240, 200]), false, false));
|
||||
let mut failures = vec![];
|
||||
for (name, mut s, fills, one_layer) in cases {
|
||||
for (name, mut s, fills, one_layer, turned) in cases {
|
||||
for fill in fills {
|
||||
s.execute("paint.setFill", &fill).unwrap();
|
||||
let image = render(doc(&s));
|
||||
let (measured, color, max, holes, worst) = seams_against_supersampled(doc(&s), &image);
|
||||
assert!(measured > 2_000, "{name} {fill}: {measured} pixels inside");
|
||||
let opaque = !fill.to_string().contains("opacity");
|
||||
if holes > 0 || (one_layer && opaque && color > 0) {
|
||||
let edges_once = turned && fill.get("color").is_some();
|
||||
if holes > 0 || (one_layer && opaque && color > 0) || (edges_once && (color > 1 || max > 4)) {
|
||||
failures.push(format!(
|
||||
"{name} {fill}: of {measured} pixels, {color} channels off by more than 3 (at most {max}), {holes} alphas off: {worst:?}"
|
||||
));
|
||||
@@ -579,29 +581,6 @@ fn colored_light_surfaces_match_supersampling_at_internal_facet_edges() {
|
||||
assert!(failures.is_empty(), "{failures:#?}");
|
||||
}
|
||||
|
||||
/// Inflate turned so its facets narrow to slivers at the edges, in an opaque solid fill under two
|
||||
/// colored lights, against 3x averaged down ([`seams_against_supersampled`]): each facet and its
|
||||
/// seam cover an edge pixel once together, so at most one RGB channel is more than 3 levels off, by
|
||||
/// no more than 4, and no alpha is off.
|
||||
#[test]
|
||||
fn turned_colored_inflate_facets_and_seams_cover_their_edges_once() {
|
||||
let lights = json!([
|
||||
{"color":"#ff0000","rotation":135,"height":35,"intensity":70},
|
||||
{"color":"#0000ff","rotation":-35,"height":25,"intensity":65}
|
||||
]);
|
||||
let (mut s, _) = setup("threeD.inflate");
|
||||
let change = json!({"index":0,"item":null,"params":{"ambient":10,"lights":lights,"rotationX":50,"rotationY":35}});
|
||||
s.execute("effect.setParams", &change).unwrap();
|
||||
s.execute("paint.setFill", &json!({"color":"#ffcc66"})).unwrap();
|
||||
let image = render(doc(&s));
|
||||
let (measured, color, max, holes, worst) = seams_against_supersampled(doc(&s), &image);
|
||||
assert!(measured > 2_000, "{measured} pixels inside");
|
||||
assert!(
|
||||
holes == 0 && color <= 1 && max <= 4,
|
||||
"of {measured} pixels, {color} channels off by more than 3 (at most {max}), {holes} alphas off: {worst:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// The closed facet edges of colored-light surfaces survive SVG and PDF, read back and drawn at
|
||||
/// 1:1, and Expand Appearance: inside the art, every pixel stays opaque and within 6 levels of the
|
||||
/// live art.
|
||||
|
||||
@@ -2896,7 +2896,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
|
||||
Evidence for the shared light Color: geometry tests in `tests_lighting`, effect paint tests, command/save/undo/expand and SVG/PDF checks in `three_d_light_color`, and headless picker/reset/preview tests in `tests_revolve`. Revolve keeps smooth colored vector ramps and continuous flat-lit caps. Inflate geometry tests check spherical lighting, shared vertex/edge continuity, concave cell coverage, puffed backs at perspective and legacy single-light/list equivalence; rendered command/export regressions cover smooth shading and editable expansion. Four legacy white-light PNGs matched main byte for byte when this was measured (2026-10-17); since every 3D seam took round joins (2026-11-12), white-light output is expected to differ from them at facet corners ([Seams](three-d.md#seams)); the four scenes were not exported again to measure it; [release measurements](3d-lighting-performance.md) record the colored solid-fill batch and the remaining source-gradient cost. Colored Inflate's facets lie over an underlay of themselves under one clip, so their shared edges show neither the black channel backdrop nor the background ([Seams](three-d.md#seams)); `three_d_light_color::colored_light_surfaces_match_supersampling_at_internal_facet_edges` compares 1:1 with 3x averaged down, and `colored_light_seams_stay_closed_in_svg_pdf_and_expansion` checks SVG, PDF and Expand Appearance. Colored Revolve's faces lie over an underlay of themselves the same way, run by run in a group and with mapped graphics kept after their faces; `colored_revolve_faces_leave_no_alpha_holes_at_one_to_one` checks that no pixel inside the art lets the background through at 1:1 where 3x averaged down is opaque, live, read back from SVG and PDF, and expanded.
|
||||
|
||||
Colored Inflate's composited facets that are simple polygons are each one filled path of the facet and its round seam, so a facet edge pixel is covered once instead of by a fill and then a same-color stroke ([Seams](three-d.md#seams)); `three_d_light_color::turned_colored_inflate_facets_and_seams_cover_their_edges_once` bounds the turned (X 50°, Y 35°) solid fill against 3x averaged down, and `lighting::tests::seamed_fill_covers_a_polygon_and_its_seam_once` checks the path's coverage and the facets that keep a fill and a stroke.
|
||||
Colored Inflate's composited facets that are simple polygons are each one filled path of the facet and its round seam, so a facet edge pixel is covered once instead of by a fill and then a same-color stroke ([Seams](three-d.md#seams)); `three_d_light_color::colored_light_surfaces_match_supersampling_at_internal_facet_edges` bounds the turned (X 50°, Y 35°) solid fill against 3x averaged down, and `lighting::tests::seamed_fill_covers_a_polygon_and_its_seam_once` checks the path's coverage and the facets that keep a fill and a stroke.
|
||||
|
||||
## Eyedropper character dimensions (2026-11-11)
|
||||
|
||||
|
||||
Reference in new issue
Block a user