mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-29 09:46:34 +01:00
M13: a gate naming a rule the file skips fails unless it allows the skip
This commit is contained in:
1 parent
1205a4cc30
commit
04ff77c5b6
3 files changed
+66
-1
No files matched your search
@@ -373,6 +373,16 @@ pub(crate) fn run(
|
||||
}
|
||||
}
|
||||
}
|
||||
// A gate that names a rule the file turned off, or that its preset leaves out, asks for a
|
||||
// check the run does not do: named here, so the gate can refuse instead of passing on
|
||||
// evidence it never gathered. Only explicitly named rules count — a run without a filter is
|
||||
// the review under the file's own settings, the file's choice.
|
||||
for id in filter.into_iter().flatten() {
|
||||
if !settings.enabled(id) {
|
||||
let reason = if settings.disabled.contains(id.as_str()) { "disabled" } else { "preset" };
|
||||
unchecked.push(json!({"rule": id, "reason": reason}));
|
||||
}
|
||||
}
|
||||
let mut out = settings.json();
|
||||
if let Some(o) = out.as_object_mut() {
|
||||
o.insert("scope".into(), json!(scope));
|
||||
|
||||
@@ -44,7 +44,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
spec!(
|
||||
"design.assert",
|
||||
"Assert design",
|
||||
"{scope?: selection|page|document (default: selection when something is selected, else page), ids?: [layer ids] (instead of scope), rules?: [rule ids], preset?: recommended|strict|accessibility (default: the file's), modes?: {collection: mode} (resolve bound colours in these variable modes), failOn?: low|medium|high (default high), minScore?: 0-100 (default 0), limit?: 1000-1000000 (nodes before the audit says truncated; default 50000)} → {ok: true, score, counts} fails with an error when a finding at or above failOn exists, the score is below minScore, or the audit could not check a rule it asked for (truncated at the node limit it ran with, or past a measure cap: what it did not reach is unchecked, so narrow the scope, filter the rules or raise `limit`); read-only, for CI",
|
||||
"{scope?: selection|page|document (default: selection when something is selected, else page), ids?: [layer ids] (instead of scope), rules?: [rule ids], preset?: recommended|strict|accessibility (default: the file's), modes?: {collection: mode} (resolve bound colours in these variable modes), failOn?: low|medium|high (default high), minScore?: 0-100 (default 0), limit?: 1000-1000000 (nodes before the audit says truncated; default 50000), allowSkipped?: bool (default false; passes a gate naming a rule the file disables or its preset excludes — never a truncated audit or a measure cap)} → {ok: true, score, counts} fails with an error when a finding at or above failOn exists, the score is below minScore, or the audit could not check a rule it asked for (truncated at the node limit it ran with, past a measure cap, or skipped by the file's settings: what it did not reach is unchecked, so narrow the scope, filter the rules or raise `limit`); read-only, for CI",
|
||||
false,
|
||||
assert_cmd
|
||||
),
|
||||
@@ -138,6 +138,26 @@ fn assert_cmd(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
"design review failed: the audit stopped at the {limit}-node limit after {nodes} nodes, so what it did not reach is unchecked; audit a smaller scope (selection, page or ids) or raise `limit`, then assert again"
|
||||
)));
|
||||
}
|
||||
// A gate naming a rule the file disabled or its preset leaves out is asking for a check the
|
||||
// run does not do: refused, unless the caller passes `allowSkipped` to accept exactly that —
|
||||
// it does not waive a truncated audit or a measure cap, which stay unchecked evidence.
|
||||
let allow_skipped = params::boolean(p, "allowSkipped").unwrap_or(false);
|
||||
let skipped: Vec<&str> = report["unchecked"]
|
||||
.as_array()
|
||||
.map(|v| {
|
||||
v.iter()
|
||||
.filter(|e| matches!(e["reason"].as_str(), Some("disabled") | Some("preset")))
|
||||
.filter_map(|e| e["rule"].as_str())
|
||||
.filter(|rule| filter.as_ref().is_none_or(|set| set.contains(*rule)))
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
if !skipped.is_empty() && !allow_skipped {
|
||||
return Err(EngineError::Other(format!(
|
||||
"design review failed: the file's settings skip {} (disabled by the file, or not in the preset it checks with), so a gate naming it checked nothing for it; check the file's design.configure, gate with a preset that includes it, or pass allowSkipped to accept the skip",
|
||||
skipped.join(", ")
|
||||
)));
|
||||
}
|
||||
// What the audit reported as unchecked, restricted to the rules this gate asked for. The
|
||||
// audit names each rule it could not check (`limit` truncation is handled above with its own
|
||||
// advice), so a cap added there fails this gate without a list here to keep in step.
|
||||
|
||||
@@ -899,6 +899,41 @@ fn assert_refuses_a_scope_whose_measured_checks_were_capped() {
|
||||
assert!(s.execute("design.assert", &json!({"scope": "page"})).is_ok(), "a disabled rule leaves nothing unchecked");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_gate_naming_a_rule_the_file_skips_fails_unless_allowed() {
|
||||
let mut s = Session::new();
|
||||
ex(&mut s, "shape.rectangle", json!({"x": 0.0, "y": 0.0, "width": 10.0, "height": 10.0}));
|
||||
// The file turns the clipping rule off; naming it asks for a check the run does not do.
|
||||
ex(&mut s, "design.configure", json!({"disabled": ["layout.clipped"]}));
|
||||
let named = json!(["layout.clipped"]);
|
||||
let audit = ex(&mut s, "design.audit", json!({"scope": "page", "rules": &named}));
|
||||
assert_eq!(audit["unchecked"][0], json!({"rule": "layout.clipped", "reason": "disabled"}), "{audit}");
|
||||
let err = s.execute("design.assert", &json!({"scope": "page", "rules": &named})).unwrap_err().to_string();
|
||||
assert!(err.contains("the file's settings skip layout.clipped"), "{err}");
|
||||
// Deliberately allowing the skip passes, and the file's own whole review still passes
|
||||
// without naming the rule — that is the file's choice, not the gate's.
|
||||
assert!(s.execute("design.assert", &json!({"scope": "page", "rules": &named, "allowSkipped": true})).is_ok());
|
||||
assert!(s.execute("design.assert", &json!({"scope": "page"})).is_ok());
|
||||
// The same through the preset: `layout.no-auto-layout` is Strict-only.
|
||||
let strict_only = json!(["layout.no-auto-layout"]);
|
||||
let err = s.execute("design.assert", &json!({"scope": "page", "rules": &strict_only})).unwrap_err().to_string();
|
||||
assert!(err.contains("the file's settings skip layout.no-auto-layout"), "{err}");
|
||||
assert!(s.execute("design.assert", &json!({"scope": "page", "rules": &strict_only, "preset": "strict"})).is_ok());
|
||||
// The allowance never waives unchecked evidence: on a scope whose measured checks were
|
||||
// capped, `allowSkipped` still fails on the cap.
|
||||
for i in 0..2_001 {
|
||||
ex(
|
||||
&mut s,
|
||||
"text.create",
|
||||
json!({"text": "Overflowing line of interface copy", "name": &format!("Box {i}"), "x": 0.0, "y": 0.0,
|
||||
"width": 60, "props": {"textAutoResize": "none"}}),
|
||||
);
|
||||
}
|
||||
let both = json!(["layout.clipped", "layout.text-overflow"]);
|
||||
let err = s.execute("design.assert", &json!({"scope": "page", "rules": &both, "allowSkipped": true})).unwrap_err().to_string();
|
||||
assert!(err.contains("did not measure all of layout.text-overflow"), "{err}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn assert_refuses_an_explicit_empty_selection() {
|
||||
let mut s = Session::new();
|
||||
|
||||
Reference in new issue
Block a user