diff --git a/CHANGELOG.md b/CHANGELOG.md index 18580a4cb..fd145ae1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ This file is about `ergo.rego` only. The Rust engine's changes are in [engines/r ### Fixed +- A root read through the item's `named by` key is read once, before any item, whatever key comes before or after the item's key, as [tally.walk](spec/semantics.md#counts-and-sums-in-sentences) and [for.roots](spec/semantics.md#for) say. With no `m` in the params, the params' `k` holding `"a"` and `tests` holding `[]`, `count of tests whose v equals $params.m named by key named by $params.k is 0` and `count of tests whose v equals $params.m named by $params.k named by key is 0` used to pass, and now fail as `absent` with `$params.m is missing`. The same goes for a `sum of`, and for a key from the subject beside the key from `$params`, like `$params.m named by pr.key named by $params.k named by key`. Changes the report of such a check. Under `for: every xs, if any, as x`, a key that reads the line's alias in front of the item's key, like `$params.m named by x named by key`, reads the root with each item of `xs`: with `xs` holding `["a"]` it used to pass and now fails as `absent` with `item 1 of xs: $params.m is missing`, and with `xs` holding `[]` it still passes. - A `count of` or `sum of` under a `for` line no longer fails an empty list with `, if any,` on an item its `that` or `whose` leaves out, or on an item when the `that` or `whose` reads the line's alias, like `count of zw.k that exists is at most x.n` or `count of tests.v that equals x.m named by key is 0` ([for.roots](spec/semantics.md#for), [for.if_any](spec/semantics.md#for)). With `zw` holding `[{"k": 1}, {"v": 2}]`, `count of zw.k that exists is at most x.n` also passes when `xs` holds `[{"v": 1, "n": 3}]`, where it failed as `absent` with `item 2 of zw: k is missing`. The items a `that` reading the line's alias can't decide are said under each item of the line, like `item 1 of xs: item 2 of zw: k is missing`, and no longer up front as `item 2 of zw: k is missing`. A sentence that reads no alias of the line, like `count of zw.k that is 1 is at most 5`, says such an item once, where it said `item 2 of zw: k is missing; item 2 of zw: k is missing`. Changes the report of such checks. - A key that starts with a `$`, read on each item of a walk, is the item's key and not a name, as [name.keys](spec/syntax.md#naming-a-path) says. `every tests."$x" is 1` with every test holding `"$x": 1` used to fail as `absent` with `$x is missing`, and now passes, and the message of an item that fails quotes the key, like `item 2 of tests: "$x" is 2`. - Under a second `for` line, an earlier line's alias of the wrong type in the `whose` of a `count of` or the `that` of a `sum of` fails the check for each item of the first list, even when the second list is empty, as [for.roots](spec/semantics.md#for) says. With `ys` holding `[{"rv": "s"}]`, `xs` holding `[]` and `zw` holding `[{"k": 1}, {"k": 2}]`, `for: every ys as y, every xs, if any, as x` with `count of zw whose k is at most y.rv is at most x.n` fails as `unusable` with `item 1 of ys: y.rv is "s", which isn't a number`, where it passed. With items in `xs`, the message no longer puts `item 1 of xs` in front of it. Changes the report of such a check. diff --git a/engines/rego/src/lines/roots.rego b/engines/rego/src/lines/roots.rego index 564091668..7a22f648f 100644 --- a/engines/rego/src/lines/roots.rego +++ b/engines/rego/src/lines/roots.rego @@ -871,6 +871,17 @@ _keyed_read_before(step) if { is_string(object.get(_fb({}, step), _fk(step), null)) } +_keyed_read_before(step) if { + _is_ref(step) + _ref_state(step.ref) == "value" + is_string(_ref_read(step.ref)) +} + +_keyed_read_before(step) if { + _name_step(step) + is_string(object.get(object.get(input, "ergo/names", {}), step.named_by, null)) +} + _keyed_plain_end(p) := min({i | some i, step in p; i > 0; not is_string(step)}) _keyed_off_start(p) if _part_start(p) diff --git a/engines/rego/src/messages/walks.rego b/engines/rego/src/messages/walks.rego index 44c801548..ebbfcb5e1 100644 --- a/engines/rego/src/messages/walks.rego +++ b/engines/rego/src/messages/walks.rego @@ -640,11 +640,6 @@ _m_keyed_fault_paths(subj, whose) := {p | _whose_reads_keyed_root(whose) if { some c in whose some p in _keyed_cond_paths(c) - is_array(p) - count(p) > 2 - last := p[count(p) - 1] - is_object(last) - "named_by_field" in object.keys(last) _keyed_root_path(p) } diff --git a/engines/rego/tests/lines/roots_test.rego b/engines/rego/tests/lines/roots_test.rego index c643abc00..33e0e46b8 100644 --- a/engines/rego/tests/lines/roots_test.rego +++ b/engines/rego/tests/lines/roots_test.rego @@ -793,6 +793,43 @@ test_keyed_root_fault_names_a_missing_root_from_input_or_params_by_its_whole_pat ergo._keyed_root_fault({}, ["$$input", "d", "m", {"named_by_field": "key"}]) == {"cause": "null", "text": "$input.d is null"} with data.ergo_document as {"d": null} } +test_a_key_from_params_in_front_of_the_items_key_keeps_the_root_read_before_any_item if { + pr := {"key": "a", "tests": []} + every p in [ + ["$$params", "m", {"ref": ["$$params", "k"]}, {"named_by_field": "key"}], + ["$$params", "m", {"ref": ["$$params", "k"]}, {"named_by_field": "\u0003pr\u0003key"}, {"named_by_field": "key"}], + ["$$params", "m", {"named_by_field": "\u0003pr\u0003key"}, {"ref": ["$$params", "k"]}, {"named_by_field": "key"}], + ] { + ergo._keyed_root_path(p) with input as {"ergo/names": {"ergo/subject": pr}} with data.ergo_params as {"k": "a"} + ergo._keyed_root_fault(pr, p) == {"cause": "absent", "text": "$params.m is missing"} with input as {"ergo/names": {"ergo/subject": pr}} with data.ergo_params as {"k": "a"} + } +} + +test_a_bound_line_alias_in_front_of_the_items_key_reads_the_root_before_any_item_of_the_walked_list if { + pr := {"key": "a", "tests": []} + every p in [ + ["$$params", "m", {"named_by": "x"}, {"named_by_field": "key"}], + ["$$params", "m", {"named_by": "x"}, {"ref": ["$$params", "k"]}, {"named_by_field": "key"}], + ["$$params", "m", {"ref": ["$$params", "k"]}, {"named_by": "x"}, {"named_by_field": "key"}], + ] { + ergo._keyed_root_path(p) with input as {"ergo/names": {"ergo/subject": pr, "x": "a"}} with data.ergo_params as {"k": "a"} + ergo._keyed_root_fault(pr, p) == {"cause": "absent", "text": "$params.m is missing"} with input as {"ergo/names": {"ergo/subject": pr, "x": "a"}} with data.ergo_params as {"k": "a"} + not ergo._keyed_root_path(p) with input as {"ergo/names": {"ergo/subject": pr}} with data.ergo_params as {"k": "a"} + } +} + +test_a_root_read_through_a_key_from_params_and_the_items_key_takes_the_roots_cause_and_leaves_a_key_that_cant_be_read_to_the_key if { + pr := {"key": "a", "tests": []} + p := ["$$params", "m", {"ref": ["$$params", "k"]}, {"named_by_field": "key"}] + names := {"ergo/names": {"ergo/subject": pr}} + ergo._keyed_root_fault(pr, p) == {"cause": "null", "text": "$params.m is null"} with input as names with data.ergo_params as {"k": "a", "m": null} + ergo._keyed_root_fault(pr, p) == {"cause": "unusable", "text": "$params.m is 3, which isn't an object"} with input as names with data.ergo_params as {"k": "a", "m": 3} + ergo._keyed_root_fault(pr, p) == {"cause": "absent", "text": "$params.m is missing"} with input as names with data.ergo_params as {"k": ""} + every params in [{}, {"k": null}, {"k": 3}] { + not ergo._keyed_root_path(p) with input as names with data.ergo_params as params + } +} + test_a_root_read_through_two_subject_keys_that_both_fail_takes_the_worst_cause if { p := ["$$params", "m", {"named_by_field": "\u0003pr\u0003key"}, {"named_by_field": "\u0003pr\u0003j"}] every row in [ diff --git a/engines/rego/tests/messages/walks_test.rego b/engines/rego/tests/messages/walks_test.rego index ef4d20ab8..8b3813e10 100644 --- a/engines/rego/tests/messages/walks_test.rego +++ b/engines/rego/tests/messages/walks_test.rego @@ -113,6 +113,14 @@ test_a_root_read_through_the_items_key_in_a_whose_is_read_before_any_item_whatev } } +test_a_root_read_through_the_items_key_and_then_a_key_from_params_is_read_before_any_item if { + c := {"op": "compare", "cmp": "eq", "left": ["v"], "right": ["$$params", "m", {"named_by_field": "key"}, {"ref": ["$$params", "k"]}]} + every pair in [[{"k": "a"}, {"cause": "absent", "text": "$params.m is missing"}], [{"k": "a", "m": null}, {"cause": "null", "text": "$params.m is null"}], [{"k": "a", "m": 3}, {"cause": "unusable", "text": "$params.m is 3, which isn't an object"}]] { + ergo._m_tally_keyed_base({"tests": []}, {"count_of": ["tests"], "whose": [c]}).faults == [pair[1]] with data.ergo_params as pair[0] + } + not ergo._m_tally_keyed_base({"tests": []}, {"count_of": ["tests"], "whose": [c]}) with data.ergo_params as {"k": "a", "m": {}} +} + test_a_count_shows_every_item_it_cant_read_whatever_its_cause_but_not_a_root_or_a_params_item_of_another_cause if { item := {"item": {"i": ["xs", 0]}} ergo._m_record_shown(["absent", "item 1 of xs: v is missing", item], "unusable") diff --git a/engines/rego/tests/spec_test.rego b/engines/rego/tests/spec_test.rego index 32a920d72..29fe277a3 100644 --- a/engines/rego/tests/spec_test.rego +++ b/engines/rego/tests/spec_test.rego @@ -45,7 +45,6 @@ known_differences := { "sentences / a root from $input or the subject itself read through a named by key from the subject, in a count of or a sum of over items, is said once on the assertion, and each item the clause can't read is said after it / puts the root on the assertion and gives an item entry only to the item the clause can't read", "sentences / a root from $params read through a named by key from $params and then the item's key is read once, before any item, so a root it doesn't have fails the check on an empty list too / fails as absent naming the root when the params have no m and tests is empty", "sentences / a root from $params read through a named by key from the subject and then the item's key is read once, before any item, so a root that has no key for the subject's key fails the check on an empty list too / fails as absent naming the root through the subject's key when the params' m has no such key and tests is empty", - "sentences / a root from $params read through the item's key and then a named by key from $params is read once, before any item, so a root it doesn't have fails the check on an empty list too / fails as absent naming the root when the params have no m and tests is empty", "sentences / a root from $params read through the item's own key, in a one-line every with if any, is not an object, so it fails as unusable on an empty list / fails as unusable naming $params.m when tests is empty", "sentences / a root from $params read through the item's own key, in a one-line every with if any, is null, so it fails as null on an empty list / fails as null naming $params.m when tests is empty", "sentences / a root read through the item's own key, in a one-line every with if any, is read once, before any item, so it fails on an empty list when it is missing, null or not an object / fails as absent naming $params.m and $input.m when neither is there and tests is empty", diff --git a/engines/rust/CHANGELOG.md b/engines/rust/CHANGELOG.md index 80d966c2c..549c10bff 100644 --- a/engines/rust/CHANGELOG.md +++ b/engines/rust/CHANGELOG.md @@ -35,6 +35,7 @@ Each release names the version of the spec it follows. The spec's own changes ar ### Fixed +- A root read through a `named by` key from `$params` and then the item's `named by` key is read once, before any item, as [tally.walk](../../spec/semantics.md#counts-and-sums-in-sentences) and [for.roots](../../spec/semantics.md#for) say. With no `m` in the params, the params' `k` holding `"a"` and `tests` holding `[]`, `count of tests whose v equals $params.m named by $params.k named by key is 0` used to pass, and now fails as `absent` with `$params.m is missing`. The same goes for a key from the subject beside it, like `$params.m named by pr.key named by $params.k named by key`. Changes the report of such a check. Under `for: every xs, if any, as x`, a root read through the item's key and then the line's alias, like `$params.m named by key named by x`, is no longer read when `xs` holds `[]`, so the check passes there, as [for.roots](../../spec/semantics.md#for) says, where it used to fail as `absent` with `$params.m is missing`. - A sentence under a `for` line that reads the line's alias only as the `named by` key of `$params` or `$input` on the right of `is in`, like `count of zw whose k is in $params.m named by x is at most 5`, is left out on an empty list with `, if any,`, as it is in `ergo.rego`, so the check passes. It used to run before any item and fail on an item it couldn't decide. A count that never ran is no longer among the row's `inputs`. The part before such a key, like `$params.m` in `$params.m named by x`, is read with each item too, and not before any item, so it no longer fails the check on an empty list when it is missing or `null`. - A `named by` key from the subject in a `whose … exists`, like `pr.key` in `count of tests whose $params.m named by pr.key exists is 0`, is read once, before any item, as with the other phrases ([tally.whose](../../spec/semantics.md#counts-and-sums-in-sentences), [for.roots](../../spec/semantics.md#for)). A key that is missing, `null` or isn't text fails the check, like `pr.key is {}, which isn't text`, even when the list is empty, with or without `, if any,`. It passed before. This changes the report of a policy that has one. diff --git a/engines/rust/engine/src/ops/key_base.rs b/engines/rust/engine/src/ops/key_base.rs index ea4ff6370..dd3b9d5cd 100644 --- a/engines/rust/engine/src/ops/key_base.rs +++ b/engines/rust/engine/src/ops/key_base.rs @@ -221,12 +221,18 @@ pub fn base_of(path: &Path, item_keys: bool, ctx: &Ctx) -> Option<(String, Strin if !super::walk::reads_outside(path) && path.start != path::Start::Params { return None; } + if path.steps[at..].iter().any(|step| { + matches!(step, Step::Ref(key) | Step::Field(key) if super::for_line::path_reads_unbound_alias(key, ctx)) + }) { + return None; + } match &path.steps[at] { Step::Ref(key) => { - if super::for_line::path_reads_unbound_alias(key, ctx) { + if key_flaw(key, ctx).is_none() + && !(item_keys && subject_keys_then_an_items_key(&path.steps[at..], ctx)) + { return None; } - key_flaw(key, ctx)?; } Step::Field(key) if !item_keys @@ -262,6 +268,9 @@ fn subject_keys_then_an_items_key(steps: &[Step], ctx: &Ctx) -> bool { path::names_the_subject(&key.start) && matches!(path::resolve(step, ctx), Ok(path::Resolved::Key(_))) } + Step::Ref(key) => { + !super::for_line::path_reads_unbound_alias(key, ctx) && key_flaw(key, ctx).is_none() + } _ => false, }) } diff --git a/engines/rust/engine/src/ops/key_base/tests.rs b/engines/rust/engine/src/ops/key_base/tests.rs index 067dba5f3..2ce35053e 100644 --- a/engines/rust/engine/src/ops/key_base/tests.rs +++ b/engines/rust/engine/src/ops/key_base/tests.rs @@ -688,3 +688,112 @@ fn a_counted_item_clause_is_kept_even_when_its_text_is_a_base_problem() { "w is 2; o is 5, which isn't an object; o is 5, which isn't an object; $params.k is missing" ); } + +#[test] +fn a_root_read_through_a_key_from_params_and_then_the_items_key_has_its_base_read_before_any_item() +{ + let subject = json!({"tests": []}); + let mut path = keyed(Start::Params, &["m"], "k"); + path.steps.push(Step::Field(Box::new(Path { + start: Start::Own, + steps: vec![Step::Key("key".to_string())], + }))); + let params = json!({"k": "a"}); + let (name, text, cause) = base_of(&path, true, &ctx(&subject, ¶ms, &[])).unwrap(); + assert_eq!( + (name.as_str(), text.as_str(), cause), + ("$params.m", "$params.m is missing", Cause::Absent) + ); + let params = json!({"k": "a", "m": {}}); + assert!(base_of(&path, true, &ctx(&subject, ¶ms, &[])).is_none()); +} + +fn chain(steps: Vec) -> Path { + let mut all = vec![Step::Key("m".to_string())]; + all.extend(steps); + Path { + start: Start::Params, + steps: all, + } +} + +fn items_key() -> Step { + Step::Field(Box::new(Path { + start: Start::Own, + steps: vec![Step::Key("key".to_string())], + })) +} + +fn alias_key() -> Step { + Step::Ref(Box::new(Path { + start: Start::Alias("x".to_string()), + steps: vec![], + })) +} + +fn params_key() -> Step { + Step::Ref(Box::new(Path { + start: Start::Params, + steps: vec![Step::Key("k".to_string())], + })) +} + +#[test] +fn a_root_read_through_the_items_key_and_then_an_unbound_line_alias_is_not_read_before_any_item() { + let subject = json!({"key": "a", "tests": []}); + let params = json!({"k": "a"}); + for steps in [ + vec![items_key(), alias_key()], + vec![items_key(), params_key(), alias_key()], + vec![params_key(), items_key(), alias_key()], + ] { + assert!(base_of(&chain(steps), true, &ctx(&subject, ¶ms, &[])).is_none()); + } +} + +#[test] +fn a_root_read_through_a_key_from_params_and_the_items_key_takes_the_roots_cause_whatever_the_key() +{ + let subject = json!({"key": "a", "tests": []}); + let path = chain(vec![params_key(), items_key()]); + for (params, text, cause) in [ + ( + json!({"k": "a", "m": null}), + "$params.m is null", + Cause::Null, + ), + ( + json!({"k": "a", "m": 3}), + "$params.m is 3, which isn't an object", + Cause::Unusable, + ), + (json!({"k": ""}), "$params.m is missing", Cause::Absent), + (json!({}), "$params.m is missing", Cause::Absent), + (json!({"k": null}), "$params.m is missing", Cause::Absent), + (json!({"k": 3}), "$params.m is missing", Cause::Absent), + ] { + let (_, found, found_cause) = base_of(&path, true, &ctx(&subject, ¶ms, &[])).unwrap(); + assert_eq!((found.as_str(), found_cause), (text, cause)); + } +} + +#[test] +fn a_bound_line_alias_in_front_of_the_items_key_reads_the_root_before_any_item() { + let subject = json!({"key": "a", "tests": []}); + let params = json!({"k": "a"}); + let x = json!("a"); + for steps in [ + vec![alias_key(), items_key()], + vec![alias_key(), params_key(), items_key()], + vec![params_key(), alias_key(), items_key()], + vec![items_key(), alias_key()], + ] { + let path = chain(steps.clone()); + let (_, text, cause) = base_of(&path, true, &ctx(&subject, ¶ms, &[("x", &x)])).unwrap(); + assert_eq!( + (text.as_str(), cause), + ("$params.m is missing", Cause::Absent) + ); + assert!(base_of(&chain(steps), true, &ctx(&subject, ¶ms, &[])).is_none()); + } +} diff --git a/engines/rust/sentences/tests/oracle/checks.rs b/engines/rust/sentences/tests/oracle/checks.rs index 5d2efeca3..e17cae2e1 100644 --- a/engines/rust/sentences/tests/oracle/checks.rs +++ b/engines/rust/sentences/tests/oracle/checks.rs @@ -133,6 +133,18 @@ pub const CHECK_OK: &[(&str, &str, &[&str], &[&str])] = &[ &[], &[], ), + ( + "count of tests whose v equals $params.m named by key named by x is 0", + "count of tests whose v equals $params.m named by key named by x is 0", + &[], + &[], + ), + ( + "count of tests whose v equals $params.m named by x named by key is 0", + "count of tests whose v equals $params.m named by x named by key is 0", + &[], + &[], + ), ( "every tests whose $input.m named by key is 1, if any, exists", "every tests whose $input.m named by key is 1, if any, exists", diff --git a/spec/OPEN.md b/spec/OPEN.md index c2a62df61..26de006cc 100644 --- a/spec/OPEN.md +++ b/spec/OPEN.md @@ -92,20 +92,19 @@ OPA 1.20.2 crashes when it compares a number whose exponent is beyond ±1e6 with - **Some chains of keys from the subject name one failing key in `ergo.rego` where the Rust engine names each (type 3, [problems.all_said](semantics.md#which-problems-a-message-says), [problems.where_said](semantics.md#which-problems-a-message-says)).** With three keys, the first `"a"`, then `null` and `3`, `count of` with an item says `pr.k is 3, which isn't text` in `ergo.rego` and adds `; pr.j is null` in the Rust engine, and the same with `{"key": null, "j": 3}` and `tests` `[{"v": 1}]`. Under a `for` line, or in a `for` line's own `whose`, when the root is `null` and has a path or several keys, `ergo.rego` says a key twice: with `for: every tests whose v equals $params.m.d named by pr.key named by pr.j, if any, as t`, `t exists`, `m` `null`, `key` "a", `j` `{}` and `tests` `[]`, it says `pr.j is {}, which isn't text; pr.j is {}, which isn't text; $params.m is null`, where the Rust engine says `pr.j is {}, which isn't text` once, as problems.where_said asks. No step is scheduled yet. - **The wording of a chain of keys that can't be read, in a few shapes (type 3).** `$params.m named by key named by j does not exist` says its problems in a different order in the two engines. Under a `for` line, `first of` has `; tests is []` added in the Rust engine. With `count of tests whose $params.m named by key exists is 0`, the Rust engine says `item 1 of tests: key is missing` and `ergo.rego` says `""`. With `count of tests whose v exists and whose $params.m named by pr.key exists is 0`, `ergo.rego` says `count of … is 0 is false`. No step is scheduled yet. - **The `failures` of a `count of` over a list with items, whose `whose` reads a root through two `named by` keys from the subject (type 3, [row.parts](semantics.md#what-a-row-shows)).** With the params `{"m": {"a": {"y": {"j": 1}}}}`, the subject's `key` holding `"a"` and `j` holding `"q"`, and `tests` holding `[{"v": 1, "pr": "y"}]`, `count of tests whose v equals $params.m named by pr.key named by pr.j is 1` fails as `absent` with `$params.m named by pr.key named by pr.j is missing` in both engines. The Rust engine puts the problem on the assertion, with no item entry, and `ergo.rego` puts it on an `item 1 of tests` entry and gives the assertion the message `""`. It is the shape of the entry below with one key, so its step fixes it too. Case: `sentences` "two named by keys from the subject, one after the other, are both read from the subject and never from the item", in `known_differences`. -- **A root read through the item's own key that can't be read is said again for each item in `ergo.rego` (type 3, [problems.where_said](semantics.md#which-problems-a-message-says)).** With no params and `tests` holding `[{"key": "a", "v": 1}]`, `count of tests whose $params.m named by key is 1 is 0` and `for: every tests whose $params.m named by key is 1, if any, as t` with `t exists` fail as `absent` in both engines, with `$params.m is missing` in the Rust engine and `$params.m is missing; item 1 of tests: $params.m named by key is missing` in `ergo.rego`. The same goes for `$input.m`, for `exists`, `is one of`, `is true`, `matches` and `is in` after the root, and for `m` `null` or `3`. With `m` `null` and `tests` holding `[{"v": 1}]`, the `for` line says `$params.m is null; item 1 of tests: key is missing; $params.m is null` in `ergo.rego`, and the Rust engine says the root once, first. problems.where_said says a problem in something read from outside the item is said once, with no item in front, so the Rust engine is right. On `main` `ergo.rego` passed these on an empty list and named only the items here. A chain of the item's own key and a key from the subject, in either order, does the same: with the subject's `key` holding `"a"` and `tests` holding `[{"v": 1, "key": "b"}]`, `count of tests whose $params.m named by pr.key named by key is 1 is 0` says `$params.m is missing; item 1 of tests: $params.m named by pr.key named by key is missing` in `ergo.rego` and `$params.m is missing` in the Rust engine, and with `m` `null` or `3` the item says `$params.m is null` or `$params.m is 3, which isn't an object` again. A one-line `every` over that list names only the item in `ergo.rego`, on `main` too. With items, a chain ending in a key from `$params` still names every item: `count of tests whose v equals $params.m named by key named by $params.k is 0` says `$params.m is missing; item 1 of tests: $params.m named by key named by $params.k is missing` in `ergo.rego` where the chain ending in `pr.key` says only `$params.m is missing`, and `for: every tests whose v equals $params.m named by key named by pr.key, if any, as t` says `$params.m is missing` and then `item N of tests: $params.m named by key named by pr.key is missing` for each item, where the Rust engine says only the root. The step that fixes it: `ergo.rego` leaves a root it has said out of each item's problems, as it does after `equals` and `is at least`. +- **A root read through the item's own key that can't be read is said again for each item in `ergo.rego` (type 3, [problems.where_said](semantics.md#which-problems-a-message-says)).** With no params and `tests` holding `[{"key": "a", "v": 1}]`, `count of tests whose $params.m named by key is 1 is 0` and `for: every tests whose $params.m named by key is 1, if any, as t` with `t exists` fail as `absent` in both engines, with `$params.m is missing` in the Rust engine and `$params.m is missing; item 1 of tests: $params.m named by key is missing` in `ergo.rego`. The same goes for `$input.m`, for `exists`, `is one of`, `is true`, `matches` and `is in` after the root, and for `m` `null` or `3`. With `m` `null` and `tests` holding `[{"v": 1}]`, the `for` line says `$params.m is null; item 1 of tests: key is missing; $params.m is null` in `ergo.rego`, and the Rust engine says the root once, first. problems.where_said says a problem in something read from outside the item is said once, with no item in front, so the Rust engine is right. On `main` `ergo.rego` passed these on an empty list and named only the items here. A chain of the item's own key and a key from the subject, in either order, does the same: with the subject's `key` holding `"a"` and `tests` holding `[{"v": 1, "key": "b"}]`, `count of tests whose $params.m named by pr.key named by key is 1 is 0` says `$params.m is missing; item 1 of tests: $params.m named by pr.key named by key is missing` in `ergo.rego` and `$params.m is missing` in the Rust engine, and with `m` `null` or `3` the item says `$params.m is null` or `$params.m is 3, which isn't an object` again. A one-line `every` over that list names only the item in `ergo.rego`, on `main` too. With items, `for: every tests whose v equals $params.m named by key named by pr.key, if any, as t` says `$params.m is missing` and then `item N of tests: $params.m named by key named by pr.key is missing` for each item, where the Rust engine says only the root. The step that fixes it: `ergo.rego` leaves a root it has said out of each item's problems, as it does after `equals` and `is at least`. - **The `failures` of a `count of` over a list with items, whose `whose` reads a root through a `named by` key from the subject that the root doesn't have (type 3, [row.parts](semantics.md#what-a-row-shows)).** With no params, `count of xs whose v equals $params.m named by pr.k is 1`, the key `"a"` and `xs` holding `[{"v": 1}]` fails as `absent` with `$params.m named by pr.k is missing` in both engines. `ergo.rego` puts the problem on an `item 1 of xs` entry, as the `sentences` case "a key from the subject that can't be read, in a relative clause" pins, and the Rust engine puts it on the assertion, with no item entry. row.parts says "something read outside the item sits on the assertion, once, and items hold only their own problems", so the Rust engine follows the rule and the case doesn't. The same goes for `pr named by pr.k`, and for the key `null`. It is the same with items the clause can't read: with the params `{"m": {"a": 1}}`, the key `"b"` and `tests` holding `[{"v": 1}, {}]`, `count of tests whose v equals $input.m named by pr.key is 0` says `$input.m named by pr.key is missing; item 2 of tests: v is missing` in both engines, and `ergo.rego` adds an `item 1 of tests` entry that holds the root's problem, for `pr named by pr.key`, `count of tests.v that …` and `sum of tests.v whose $params.m named by pr.key is 1` too. The `sentences` case "a root from $input or the subject itself read through a named by key from the subject, in a count of or a sum of over items, ..." follows the rule, so it is in `known_differences`. The step that fixes it: a decision on the case's rows, then `ergo.rego` reads the root before any item there too. - **A key from the subject that can't be read, beside a root that is missing or `null`, in a one-line `every` or `some`, an `every … that` or a `for` line (type 3).** With no params and the key `[]`, `every tests whose v equals $params.d.m named by pr.key exists` fails as `unusable` in both engines. `ergo.rego` says `pr.key is [], which isn't text; $params.d.m named by pr.key is missing` and the Rust engine says only `pr.key is [], which isn't text`, as both engines do for `count of`. A key that is missing, `null` or `3` beside a root that is `null` is the same, in `every`, `some` and `every … that`, with the root `$params.m`, `$input.m`, `pr.m` or the parent's `art.m`: with no key, the params `{"m": null}` and `tests` `[{}]`, `every tests whose v equals $params.m named by pr.key exists` fails as `absent` in both engines, with `pr.key is missing; item 1 of tests: v is missing` in the Rust engine, and `ergo.rego` adds `$params.m is null` after the key. A `for` line's second `whose` is the same: with subjects `art` from `arts` and `pr` from `every art.prs`, the key `3`, `xs` `[{}]` and `tests` `[{"v": 1}]`, `for: every xs as x, every tests whose v equals x.m named by pr.key, if any, as t` with `t exists` fails as `unusable` in both engines, with `pr.key is 3, which isn't text` in the Rust engine and `pr.key is 3, which isn't text; item 1 of xs: x.m named by pr.key is missing` in `ergo.rego`, and `first of tests whose v equals x.m named by pr.key as t` too. [problems.all_said](semantics.md#which-problems-a-message-says) says "A message SHOULD say every problem Ergo finds", and the root can't be read whatever the key holds, so `ergo.rego` follows it here. On `main` `ergo.rego` failed the first one as `absent`. No step is scheduled yet. - **A one-line walk under a `for` line whose root is the line's alias read through a key from the subject says the key twice (type 3, [problems.where_said](semantics.md#which-problems-a-message-says)).** With no key, `xs` `[{"m": null}]` and `tests` `[{}]`, `every tests whose v equals x.m named by pr.key exists` under `for: every xs as x` fails as `absent` in both engines, with `pr.key is missing; item 1 of xs: item 1 of tests: v is missing` in the Rust engine and `pr.key is missing; item 1 of xs: pr.key is missing; x.m is null; item 1 of xs: item 1 of tests: v is missing` in `ergo.rego`. problems.where_said says a key read from outside the item is said once, with no item in front, so the Rust engine follows it, though `ergo.rego` also names `x.m is null`, which [problems.all_said](semantics.md#which-problems-a-message-says) asks for. With `tests` `[{}, {"v": 1}]`, `sum of tests.v that equals x.m named by pr.key is 1` says `pr.key is missing; item 1 of xs: item 1 of tests: v is missing` in the Rust engine and `pr.key is missing; item 1 of tests: v is missing` in `ergo.rego`, which drops `item 1 of xs:` in front. No step is scheduled yet. - **A chain of a key from the subject and then the item's own key, over an empty list, when the first step of the root is missing from an object that exists (type 1, [tally.walk](semantics.md#counts-and-sums-in-sentences), [for.roots](semantics.md#for)).** tally.walk says "one that's missing or `null` fails it as `absent` or `null`, even when the list is empty", and for.roots says "Each root is read once, before any item". With the params `{"m": {}}`, `key` "a" for the subject and `tests` `[]`, `count of tests whose v equals $params.m named by pr.key named by key is 0` passes in both engines, and should fail as `absent` with `$params.m named by pr.key is missing`, as it does when `named by pr.key` is the last key. Case: `sentences` "a root from $params read through a named by key from the subject and then the item's key is read once, before any item, so a root that has no key for the subject's key fails the check on an empty list too", in `known_differences` and in `engines/rust/known-failures.txt`. The case pins the `count` form and not the other forms. The step: the next burn-down pull request, so that both engines read the root up to the subject's key before any item. -- **A chain of the item's own key and then a key from `$params`, over an empty list, when the root can't be read (type 1, [tally.walk](semantics.md#counts-and-sums-in-sentences), [for.roots](semantics.md#for)).** tally.walk says "one that's missing or `null` fails it as `absent` or `null`, even when the list is empty", and for.roots says "Each root is read once, before any item". With no `m` in the params, the params' `k` holding `"a"` and `tests` `[]`, `count of tests whose v equals $params.m named by key named by $params.k is 0` passes in `ergo.rego` and fails as `absent` with `$params.m is missing` in the Rust engine, which is right. The same goes for `sum of v of tests whose v equals $params.m named by key named by $params.k is 0`. On `main` too. Case: `sentences` "a root from $params read through the item's key and then a named by key from $params is read once, before any item, so a root it doesn't have fails the check on an empty list too", in `known_differences`. The case pins the `count` form. The step: the next burn-down pull request (B8), so that `ergo.rego` reads the root before any item when the chain ends in a key from `$params`. -- **A chain with a key from `$params` in front of the item's own key, over an empty list, when the root can't be read (type 1, both engines, [tally.walk](semantics.md#counts-and-sums-in-sentences), [for.roots](semantics.md#for)).** tally.walk says "one that's missing or `null` fails it as `absent` or `null`, even when the list is empty", and for.roots says "Each root is read once, before any item". With no `m` in the params, the params' `k` holding `"a"` and `tests` `[]`, `count of tests whose v equals $params.m named by $params.k named by key is 0` passes in both engines, and should fail as `absent` with `$params.m is missing`. `$params.m named by $params.k named by pr.key named by key` and `$params.m named by pr.key named by $params.k named by key` pass in both too, and `$params.m named by $params.k` and `$params.m named by pr.key named by key` alone fail. The Rust engine reads only the keys of the subject that come before the item's key, so a `$params` key in front still skips reading the root. On `main` too. Case: `sentences` "a root from $params read through a named by key from $params and then the item's key is read once, before any item, so a root it doesn't have fails the check on an empty list too", in `known_differences` and in `engines/rust/known-failures.txt`. The case pins the `count` form. The step: the next burn-down pull request (B8), so that both engines read the root before any item whatever the keys in front of the item's key. +- **Which `inputs` a root read through a key that can be read and then the item's own key puts on the row, over an empty list (type 2, both engines, [tally.inputs](semantics.md#counts-and-sums-in-sentences), [tally.whose](semantics.md#counts-and-sums-in-sentences)).** With no `m` in the params, the params' `k` holding `"a"` and `tests` `[]`, `count of tests whose v equals $params.m named by $params.k named by key is 0` fails in both engines as `absent` with `$params.m is missing`, as it should. No rule decides the row's `inputs` here: tally.inputs names only the count and the walked list, and tally.whose puts a key on the assertion's inputs only when it is missing or `null`. The two cases disagree: the case below expects `$params.m named by $params.k named by key` (`absent`) and `$params.k` (`usable`) in the inputs, and the `sentences` case for `$params.m named by key named by $params.k` ("a root from $params read through the item's key and then a named by key from $params …"), which both engines pass, expects no input for the root or the key. Both engines list neither, and put them only in the check's `$refs`. Case: `sentences` "a root from $params read through a named by key from $params and then the item's key is read once, before any item, so a root it doesn't have fails the check on an empty list too", in `known_differences` and in `engines/rust/known-failures.txt`. The step: a decision on which inputs such a row lists, and then both cases follow it. - **A `null` key from the subject on an empty list, in a one-line `every` or `some` (type 2).** With no params, the key `null` and `tests` `[]`, `every tests whose v equals $params.m named by pr.key exists` and `some tests whose v equals $params.m named by pr.key exists` fail as `null` in `ergo.rego` with `pr.key is null; tests is []`, and as `absent` in the Rust engine with `$params.m named by pr.key is missing; pr.key is null; tests is []`. [tally.whose](semantics.md#counts-and-sums-in-sentences) says "each item takes the cause of its own paths, and the row takes the worst of all", and `$params.m` is missing whatever the key holds, so the Rust engine is right. `count of tests whose v equals $params.zz named by pr.key is 0` with `key` `null` is the same: `ergo.rego` says `null` with `pr.key is null`, and the Rust engine says `absent` with `$params.zz named by pr.key is missing; pr.key is null`. With no `m` and the params' `k` `null`, `count of tests whose v equals $params.m named by $params.k named by key is 0` on `[]` is the same, with `$params.k is null` in `ergo.rego` and `$params.m is missing; $params.k is null` in the Rust engine, in the other orders of the keys too. With no `m` and `tests` `[]`, `some tests whose v equals $params.m named by key named by pr.key exists` says `value` with `tests is []` in `ergo.rego` and `absent` with `$params.m is missing; tests is []` in the Rust engine. With no `m` and `tests` `[{"v": 1, "key": "b", "j": "c"}, {"v": 1, "key": "b", "j": 3}]`, `count of tests whose v equals $params.m named by key named by j is 0` says `absent` with `$params.m is missing` in `ergo.rego` and `unusable` with `$params.m is missing; item 2 of tests: j is 3, which isn't text` in the Rust engine, which follows problems.all_said. On `main` too. No step is scheduled yet. - **A root that can't be read, beside a chain of keys that can't be read or a sum, in `ergo.rego` (type 3, [problems.all_said](semantics.md#which-problems-a-message-says), [problems.where_said](semantics.md#which-problems-a-message-says)).** With no `m` in the params and `tests` `[{"v": 1, "key": "b", "j": "c"}, {"v": 1, "key": "b"}]`, `count of tests whose v equals $params.m named by key named by j is 0` says `$params.m is missing` in `ergo.rego` and `$params.m is missing; item 2 of tests: j is missing` in the Rust engine, and with `j` `3` in the second item `ergo.rego` drops `item 2 of tests: j is 3, which isn't text` in the same way, so it no longer says the second key's problem, as it did on `main`. With `tests` `[]`, `sum of v of tests whose v equals $params.m named by key named by pr.key is 0` fails as `absent` in both engines, with `$params.m is missing` in the Rust engine and `sum of v of tests whose v equals $params.m named by key named by pr.key is 0 is false` in `ergo.rego`, which never names `$params.m`. With `named by art.key` or `named by art` where `art` holds an object, both engines fail as `unusable` with `art is an object with 2 keys, which isn't text`, and the Rust engine adds `; $params.m is missing`. No step is scheduled yet. - **A `count of`, `every` or `some` whose `whose` reads a parent's or the subject's field through a `null` key from the subject (type 2).** With subjects `art` from `arts` and `pr` from `every art.prs`, the parent's `m` holding `{"a": 1}`, the key `null` and `tests` holding `[{"v": 1}]`, `count of tests whose art.m named by pr.key is 1 is 0` fails in `ergo.rego` as `absent` with `item 1 of tests: .art.m named by pr.key is missing`, and in the Rust engine as `null` with `pr.key is null`. [tally.whose](semantics.md#counts-and-sums-in-sentences) says the key "is always said, once and before any item", so the Rust engine is right. A one-line `every` or `some` is the same, and so is a root from the subject: with the key `null` and `tests` `[{"v": 1}, {}]`, `every tests whose pr named by pr.key is 1, if any, exists` fails in `ergo.rego` as `absent` with `item 1 of tests: .pr named by pr.key is missing; item 2 of tests: .pr named by pr.key is missing`, and in the Rust engine as `null` with `pr.key is null`, and `art.m`, `pr.m` and `some` give the same. The other way round, with `key` `null` and `tests` `[{"v": 1}]`, `count of tests whose t2 named by pr.key exists is 0` and, under `for: every xs, if any, as x`, `count of tests whose x.m named by pr.key exists is 0` fail as `null` with `pr.key is null` in the Rust engine and as `absent` in `ergo.rego`. On `main` too. No case pins it. The step is in `ergo.rego`'s read of a path on the left of a `whose` that starts at a parent or the subject and ends with a key from the subject. - **The message of an `item` entry of a `for` line whose list is read through an alias's field that is missing (type 3).** With `for: every ab.items as c`, `assert: c.ok is true` and `ab` holding `[{"ok": true}, {"ok": false}]`, both engines fail as `absent` and say `item 1 of ab: items is missing; item 2 of ab: items is missing`. The message of each item entry is `item 1 of ab: items is missing` in the Rust engine and `items is missing` in `ergo.rego`. With a quoted key like `"a; b"` in place of `items`, it is the same, and the quoted `; ` reads fine in both engines. - **A `named by` key from the subject holding `3`, in `first of` under a `for` line, fails as `absent` in `ergo.rego` and `unusable` in Rust (type 2).** With `for: every xs as x, first of tests whose m named by pr.key is 1 as t`, `assert: t exists`, `key` `3`, `tests` `[]` and `xs` `[{"a": 1}]`, `ergo.rego` says `absent` with `tests is []` and the Rust engine says `unusable` with `pr.key is 3, which isn't text; tests is []`, which follows [path.field_step](semantics.md#reading-a-path). - **The assertion entry of `every tests whose $params.m named by $params.k is 1 exists` lacks the `$params.k` input in `ergo.rego` (type 3).** With the params `{"m": {"a": 1}, "k": "a"}` and `tests` `[]`, the Rust engine lists `$params.k` in the assertion entry's `inputs` and `ergo.rego` lists none. -- **The rows of the `sentences` cases of a root read through a `named by` key from the subject copy the Rust engine for fields no rule decides (type 3).** The groups "a root from $params read through a named by key from the subject ..." (the three of them, with the key on the left of a `whose` and under `for: every xs, if any, as x`) and "a root from $input or the subject itself read through a named by key from the subject ..." (the three of them) pin the verdict, the cause and the message, which [tally.whose](semantics.md#counts-and-sums-in-sentences) and [for.roots](semantics.md#for) decide. A row has to be written whole, so the rows also hold what no rule says (and the rows of the one-line `every` and the line alias cases written for the entries above hold them too, copied from the `count of` rows): whether `$params.m named by pr.key` is an entry of `inputs` at all ([walk.inputs](semantics.md#every-and-some) says both that it lists the path and its key, and that a `$params` path isn't an entry of `inputs`), the `locations` of the count entry (`[]`), whether `tests[]` is in the row's `inputs`, the `locations` of `xs[]` and the `inputs` of an item's entry. The group "a named by key from the subject that isn't text, on the left of a whose with exists, ..." also pins the subject's `key` holding `{}` as an input with the outcome `usable`, and `$params.m named by pr.key` with the outcome `unusable` and the value `null`, which no rule says either, as it is with `is 1`. The two groups for a root read through the item's own key and a key from the subject, in either order, over an empty list with no `m` in the params, copy the Rust engine in the same way (the `key` input with the outcome `usable`, and `$params:` as the location of the missing root, as the nearest rows have it). The cases for a chain with a key from `$params` and the item's key, in either order, copy the same nearest rows and the Rust engine's rows (the `$params.k` input with the outcome `usable`, and `$params:` and `$params:/k` as locations), and the case for a chain of the subject's key and then the item's key, with the params `{"m": {}}`, copies the rows of the nearest case in the same way, with `$params:/m` as the location of the root and `$params.m named by pr.key is missing` as the message, which no rule words for a missing step after a subject key. The group "a count of or sum of whose whose or that reads the line's alias, with or without a named by key, ..." copies the rows of the nearest `for` case on an empty list with `, if any,`, with `tests[].v` holding `[null]` at the item's location and, on the row without `, if any,`, the outcome `usable`. They are what the Rust engine gives, and `ergo.rego` gives the same. Settle them with one rule and then check the rows. +- **The rows of the `sentences` cases of a root read through a `named by` key from the subject copy the Rust engine for fields no rule decides (type 3).** The groups "a root from $params read through a named by key from the subject ..." (the three of them, with the key on the left of a `whose` and under `for: every xs, if any, as x`) and "a root from $input or the subject itself read through a named by key from the subject ..." (the three of them) pin the verdict, the cause and the message, which [tally.whose](semantics.md#counts-and-sums-in-sentences) and [for.roots](semantics.md#for) decide. A row has to be written whole, so the rows also hold what no rule says (and the rows of the one-line `every` and the line alias cases written for the entries above hold them too, copied from the `count of` rows): whether `$params.m named by pr.key` is an entry of `inputs` at all ([walk.inputs](semantics.md#every-and-some) says both that it lists the path and its key, and that a `$params` path isn't an entry of `inputs`), the `locations` of the count entry (`[]`), whether `tests[]` is in the row's `inputs`, the `locations` of `xs[]` and the `inputs` of an item's entry. The group "a named by key from the subject that isn't text, on the left of a whose with exists, ..." also pins the subject's `key` holding `{}` as an input with the outcome `usable`, and `$params.m named by pr.key` with the outcome `unusable` and the value `null`, which no rule says either, as it is with `is 1`. The two groups for a root read through the item's own key and a key from the subject, in either order, over an empty list with no `m` in the params, copy the Rust engine in the same way (the `key` input with the outcome `usable`, and `$params:` as the location of the missing root, as the nearest rows have it). The cases for a chain with a key from `$params` and the item's key, in either order, copy the same nearest rows and the Rust engine's rows (the `$params.k` input with the outcome `usable`, and `$params:` and `$params:/k` as locations), and the case for a chain of the subject's key and then the item's key, with the params `{"m": {}}`, copies the rows of the nearest case in the same way, with `$params:/m` as the location of the root and `$params.m named by pr.key is missing` as the message, which no rule words for a missing step after a subject key. The group "a count of or sum of whose whose or that reads the line's alias, with or without a named by key, ..." copies the rows of the nearest `for` case on an empty list with `, if any,`, with `tests[].v` holding `[null]` at the item's location and, on the row without `, if any,`, the outcome `usable`. They are what the Rust engine gives, and `ergo.rego` gives the same. The two groups for a root read through the line alias and the item's key, in either order, under `for: every xs, if any, as x`, copy the Rust engine's rows in the same way, for `inputs` and `failures`, and pin only the verdict, the cause and the message by rule. Settle them with one rule and then check the rows. - **A chain of two keys from the subject after `exists`, over a list with items, when both keys fail or the value between them can't take a key (type 2, both engines).** The verdicts agree, and with `tests` `[]` so do the cause and the message. With `tests` `[{"v": 1}]`, `pr.key` missing and `pr.j` `3`, `every tests whose $params.m named by pr.key named by pr.j exists exists` fails as `unusable` with `pr.j is 3, which isn't text; pr.key is missing` in the Rust engine, and as `absent` with `pr.key is missing` in `ergo.rego`. [problems.all_said](semantics.md#which-problems-a-message-says) says a message says every problem and the row's cause is the worst of them, so `ergo.rego` is wrong there. The same `count of … is 0` fails as `unusable` in both, but `ergo.rego` says only `pr.key is missing`, and with both keys `null` it says `pr.key is null, and pr.j is null` where the Rust engine says `pr.j is null; pr.key is null`. With `pr.key` `"a"`, `pr.j` `"b"` and the params `{"m": {"a": 1}}`, `count of tests whose $params.m named by pr.key named by pr.j exists is 0` says `item 1 of tests: $params.m named by pr.key is 1, which isn't an object` in the Rust engine, where `ergo.rego` says it once, before any item, with no item in front, as [problems.where_said](semantics.md#which-problems-a-message-says) says for a problem in something read from outside the item. The step that fixes it: `ergo.rego` reads every key of the chain before the items when the list has items too, and the Rust engine says the value between the keys before any item after `exists`. The spec doesn't settle these yet, because the two engines give different reports. Unless a line says otherwise, both fail and pass the same checks. @@ -233,12 +232,12 @@ The spec doesn't settle these yet, because the two engines give different report ## Where both engines differ from a rule -- **A one-line `every` with `, if any,` whose `whose` reads a root through the item's own key passes in both engines on an empty list when the root can't be read (type 1, both engines, [tally.walk](semantics.md#counts-and-sums-in-sentences), [for.roots](semantics.md#for), [problems.same_path](semantics.md#which-problems-a-message-says)).** tally.walk says "The same goes for every root [for.roots](#for) names, … `$params` and `$input`, wherever the check reads it: an `every` or `some` phrase, a `whose`, …", and for.roots says "Each root is read once, before any item". With no params and `tests` `[]`, `every tests whose $params.m named by key is 1, if any, exists` passes in both engines, and the same with `$input.m`, `$params.m.d` and the parent's `art.m` holding `3`. Both engines fail `count of tests whose $params.m named by key is 1 is 0` and the `for` line `every tests whose $params.m named by key is 1, if any, as t` as `absent` with `$params.m is missing`, and the Rust engine fails the one-line `every` too under `for: every xs, if any, as x` with `xs` `[]`. So the one-line form should fail as `absent` with `$params.m is missing`. On `main` too. Cases: `sentences` "a root read through the item's own key, in a one-line every with if any, is read once, before any item, so it fails on an empty list when it is missing, null or not an object" and the two groups for a `$params.m` that is null and not an object, known failures of both engines. The step that fixes it: both engines read the root before any item in a one-line `every … , if any,`. +- **A one-line `every` with `, if any,` whose `whose` reads a root through the item's own key passes in both engines on an empty list when the root can't be read (type 1, both engines, [tally.walk](semantics.md#counts-and-sums-in-sentences), [for.roots](semantics.md#for), [problems.same_path](semantics.md#which-problems-a-message-says)).** tally.walk says "The same goes for every root [for.roots](#for) names, … `$params` and `$input`, wherever the check reads it: an `every` or `some` phrase, a `whose`, …", and for.roots says "Each root is read once, before any item". With no params and `tests` `[]`, `every tests whose $params.m named by key is 1, if any, exists` passes in both engines, and the same with `$input.m`, `$params.m.d` and the parent's `art.m` holding `3`. A chain passes too: with the params' `k` holding `"a"` and the subject's `key` holding `"a"`, `every tests whose v equals $params.m named by $params.k named by key, if any, exists`, `… named by key named by $params.k, if any, exists` and `… named by pr.key named by key, if any, exists`. Both engines fail `count of tests whose $params.m named by key is 1 is 0` and the `for` line `every tests whose $params.m named by key is 1, if any, as t` as `absent` with `$params.m is missing`, and the Rust engine fails the one-line `every` too under `for: every xs, if any, as x` with `xs` `[]`. So the one-line form should fail as `absent` with `$params.m is missing`. On `main` too. Cases: `sentences` "a root read through the item's own key, in a one-line every with if any, is read once, before any item, so it fails on an empty list when it is missing, null or not an object" and the two groups for a `$params.m` that is null and not an object, known failures of both engines. The step that fixes it: both engines read the root before any item in a one-line `every … , if any,`. - **A `named by` key from the subject after the line's alias, under a `for` line with items, is said with the line's item in front by a case (type 3, both engines, a case differs from a rule, [tally.whose](semantics.md#counts-and-sums-in-sentences), [problems.where_said](semantics.md#which-problems-a-message-says)).** With `for: every ms as mm`, `count of xs whose v equals mm named by pr.k is 1`, no `k` on the subject and `ms` and `xs` holding one item each, both engines fail as `absent` with `pr.k is missing`, said once on the assertion. The `sentences` case "a named by key from the subject after a parent or an alias, inside a relative clause" says `item 1 of ms: pr.k is missing`, with the problem on an `item 1 of ms` entry. tally.whose says a key that is missing "is always said, once and before any item", and problems.where_said says a problem in something read from the subject "SHOULD be said once, before any item, with no item in front", so the case differs from both. It is a known failure of both engines. The step that fixes it: a decision on the case's row. - **A `named by` key from the subject that isn't text is listed as `usable`, and two cases say so (type 2, both engines, a case differs from a rule, [path.field_step](semantics.md#reading-a-path)).** With `tests` holding `[]` and the subject's `key` holding `3`, `count of tests whose m named by pr.key is 1 is 0` fails as `unusable` with `pr.key is 3, which isn't text` in both engines, and both list the input `key` with the outcome `usable`. path.field_step says a field that isn't a string ends the path `unusable`, and [What a row shows](semantics.md#what-a-row-shows) says an input's outcome is `unusable` "when the value was read fine but the check can't use it", as the Rust engine lists `$input.k` holding `3`. The `sentences` cases "a named by key from the subject after any path, inside a relative clause" and "a key from the subject that can't be read, in a relative clause" pin a key holding `3` as `usable`, so those cases differ from path.field_step and the outcome rule, which say `unusable`; nothing here proposes a fix, and a decision has to say which of the two is right before any engine or case changes. - **A field in front of a list with a `whose`, named like a `for` alias, reads the item's field (type 1, [sentence.for.alias](syntax.md#the-for-line)).** The rule says an alias shadows a field with the same name everywhere but on the left side of a `whose`, so under `for: every envs as e`, the `e` of `every e of tests whose kind is "unit" is "passed"` is the alias. Both engines read each test's own `e`: with `envs` holding `["passed"]` and one unit test whose `e` is `"failed"`, they fail as `value` with `item 1 of tests: e is "failed"`, where the rule reads the alias and passes. The Rust engine also leaves out the entry of the kept fields. So do both engines with a list along the field: under `for: every envs as commits`, `every commits.sha of prs whose state is "merged" is "ok"` walks each kept pull request's own commits, where the rule reads the alias's `sha`. Cases: `field_of` "a field in front of a list with whose, named like a for alias, is the alias, which shadows a field with the same name" and "a field in front of a list with whose and a list along the field, named like a for alias, is the alias, which shadows the field of the same name", known failures of both engines. The step that fixes it: both engines read a bare alias in front of `of` as the alias. -- **A tally of a field in front of a list with a `whose`, named like a `for` alias, is written wrong by the Rust engine (type 1, [sentence.for.alias](syntax.md#the-for-line)).** Under `for: every envs as d`, with `envs` holding `["passed"]` and `tests` holding `[{"kind": "unit"}, {"kind": "unit"}]`, the `d` of `count of d of tests whose kind is "unit" is 2` is the alias, read on each of the two unit tests, so the check passes, as it does in `ergo.rego`. The Rust engine fails `$well_formed` with `d of tests whose kind is "unit" isn't supported by this engine yet`. A dot in front, `count of .d of tests whose kind is "unit" is 2`, reads each test's own `d` in both engines. Same debt as the `every` entry above. No case pins it yet, because a case compares whole rows. The step that fixes it: the Rust engine reads a bare alias in front of `of` as the alias in a tally, then a case. +- **A tally of a field in front of a list with a `whose`, named like a `for` alias, reads the item's field in the Rego engine and is written wrong by the Rust engine (type 1, [sentence.for.alias](syntax.md#the-for-line)).** Under `for: every envs as d`, with `envs` holding `["passed"]` and `tests` holding `[{"kind": "unit"}, {"kind": "unit"}]`, the `d` of `count of d of tests whose kind is "unit" is 2` is the alias, read on each of the two unit tests, so the check passes. `ergo.rego` reads each test's own `d` and fails as `absent` with `item 1 of tests: d is missing; item 2 of tests: d is missing`. The Rust engine fails `$well_formed` with `d of tests whose kind is "unit" isn't supported by this engine yet`. A dot in front, `count of .d of tests whose kind is "unit" is 2`, reads each test's own `d` in both engines. Same debt as the `every` entry above. Case: `field_of` "a tally of a field in front of a list with a whose, named like a for alias, is the alias, which shadows a field with the same name", a known failure of both engines. The step that fixes it: both engines read a bare alias in front of `of` as the alias in a tally. - **The cause of a tally of a field with a `named by` key from the subject in front of a list with a `whose`, when the list or its items and the key both fail (type 2, both engines).** [tally.walk](semantics.md#counts-and-sums-in-sentences) says the side takes the worst cause of the key and the list. For `count of m named by key of tests whose kind is "unit" is 1`, and the same with `sum of` and `count of distinct`: with `tests` `null` and no `key`, both engines fail as `null` where the rule gives `absent`; with `tests` missing or `null` and `key` `3` or a list, both fail as `absent` or `null` where the rule gives `unusable`. With one test that has no `kind` and `key` `null`, `ergo.rego` fails as `null` where the rule, and the Rust engine, give `absent`. The messages differ too (type 3): with no `tests` and no `key`, `ergo.rego` says `key is missing` and the Rust engine `key is missing; tests is missing`, as the rule says, and with `tests` `null` the Rust engine says `tests is null` twice, like `tests is null; key is missing; tests is null`. The step that fixes it: both engines take the worst cause of the key and the list, say the list after the key, then a case for each state of the list and the key. With the key from `$params.k`, 21 of the cells of that grid also differ between the two engines, in the cause only: with `tests` missing and `$params.k` `3`, a list or an object, the Rust engine says `absent` and `ergo.rego` `unusable`; with `tests` `null` and no `k`, `null` and `absent`; with `tests` `null` and `k` `3`, a list or an object, `null` and `unusable`. The rule gives `unusable` for an unusable key and `absent` for a missing one beside a `null` list, as above, so the same step fixes them. - **No spec case for the crash of a tally of a field with a `named by` key that can't be read, beside a list that can't be read (type 3).** `ergo.rego` stopped with a conflict error on `count of m named by key of tests whose kind is "unit" is 1` with `tests` missing and `key` missing, and now gives a row. Only a unit test (`engines/rego/tests/messages/walks_test.rego`) pins it, because no rule says where an unreadable key's entry sits among the row's `inputs`, and a case holds the whole row. The step that fixes it: a rule sentence for the order of the entries of a key and a list, then a case. - **A child subject's `from` line, or a `from` line with a `whose`, that reads params that aren't an object (type 3).** [path.start](semantics.md#reading-a-path) says their `$min_subjects` row says what the params are, as the `from` line of any other subject does. With the params `3`, the child subject `from: t.m named by $params.env` and `from: things whose id is $params.x` fail `$min_subjects` as `unusable` in both engines, and say the count instead, like `in-scope k count is 0`. Case: `subjects` "a child subject's from line and a whose in a from line that read params that aren't an object". The step that fixes it: name the params in those rows in both engines. diff --git a/spec/cases/sentences/cases.json b/spec/cases/sentences/cases.json index e5d990002..124526b5b 100644 --- a/spec/cases/sentences/cases.json +++ b/spec/cases/sentences/cases.json @@ -107336,5 +107336,315 @@ }, {"cases": [{"description": "passes on an empty xs with if any and a good root, because z.k is left out with the line", "input": {"ts": [{"id": "t", "xs": [], "zw": [{"k": 1}]}]}, "results": [{"cause": "satisfied", "check": "c", "inputs": [{"locations": [], "name": "xs[]", "value": []}, {"locations": ["/ts/0/zw/0"], "name": "zw[]", "value": [{"k": 1}]}], "passed": true, "requirement": "r", "subject": {"id": "t", "type": "t"}}], "rules": ["for.roots", "for.if_any"]}], "description": "a first of line after a line over an empty list with if any, whose whose reads a root through the line alias's key, passes when the root is there and the sentence reads the second alias, which is left out", "params": {"m": {"a": [1]}}, "policy": {"ergo_spec": "{{spec}}", "requirements": {"r": {"checks": {"c": {"assert": "z.k is 1", "for": "every xs, if any, as x, first of zw whose k is in $params.m named by x as z"}}, "min_subjects": 0, "subject": "t"}}, "subjects": {"t": {"from": "ts", "identified_by": "id"}}}}, {"cases": [{"description": "fails as unusable on an empty xs with if any when y is 3", "input": {"ts": [{"id": "t", "xs": [], "ys": [3], "zw": [{"k": 1}]}]}, "results": [{"cause": "unusable", "check": "c", "failures": [{"cause": "unusable", "failures": [], "inputs": [], "kind": "assertion", "locations": ["$policy:/requirements/r/checks/c/assert"], "message": "the check is false", "name": "count of zw.k that is in $params.m named by y named by x is at most 5"}], "inputs": [{"locations": ["/ts/0/zw/0/k"], "name": "count of zw.k that is in $params.m named by y named by x", "value": null}, {"locations": [], "name": "xs[]", "outcome": "usable", "value": []}, {"locations": ["/ts/0/ys/0"], "name": "ys[]", "outcome": "usable", "value": [3]}, {"locations": ["/ts/0/zw/0/k"], "name": "zw[].k", "outcome": "usable", "value": [1]}], "message": "the check is false; item 1 of ys: y is 3, which isn't text", "passed": false, "requirement": "r", "subject": {"id": "t", "type": "t"}}], "rules": ["for.roots"]}], "description": "a root read through the key of an earlier line's alias that is not text fails the check, once, before any item, even when the later line has no item", "params": {"m": {"a": {"a": [1]}}}, "policy": {"ergo_spec": "{{spec}}", "requirements": {"r": {"checks": {"c": {"assert": "count of zw.k that is in $params.m named by y named by x is at most 5", "for": "every ys as y, every xs, if any, as x"}}, "min_subjects": 0, "subject": "t"}}, "subjects": {"t": {"from": "ts", "identified_by": "id"}}}}, - {"cases": [{"description": "fails on an empty xs with if any when item 2 of zw is not an object", "input": {"ts": [{"id": "t", "xs": [], "ys": ["a"], "zw": [{"k": 1}, 5]}]}, "results": [{"cause": "not_an_object", "check": "c", "failures": [{"cause": "not_an_object", "failures": [], "inputs": [], "kind": "assertion", "locations": ["$policy:/requirements/r/checks/c/assert"], "message": "item 1 of ys: item 2 of zw is 5, which isn't an object; item 1 of ys: the check is false", "name": "count of zw.k that is in $params.m named by y is at most x.n"}], "inputs": [{"locations": [], "name": "xs[]", "outcome": "usable", "value": []}, {"locations": ["/ts/0/ys/0"], "name": "ys[]", "outcome": "usable", "value": ["a"]}, {"locations": ["/ts/0/zw/0/k", "/ts/0/zw/1"], "name": "zw[].k", "outcome": "usable", "value": [1, null]}], "message": "item 1 of ys: item 2 of zw is 5, which isn't an object; item 1 of ys: the check is false", "passed": false, "requirement": "r", "subject": {"id": "t", "type": "t"}}], "rules": ["for.roots", "tally.walk"]}], "description": "a that of a count of that reads an earlier line's alias as the key, and the later line's alias only on the right of the comparison, can't decide an item, so it fails even when the later line has no item", "params": {"m": {"a": [1]}}, "policy": {"ergo_spec": "{{spec}}", "requirements": {"r": {"checks": {"c": {"assert": "count of zw.k that is in $params.m named by y is at most x.n", "for": "every ys as y, every xs, if any, as x"}}, "min_subjects": 0, "subject": "t"}}, "subjects": {"t": {"from": "ts", "identified_by": "id"}}}} + {"cases": [{"description": "fails on an empty xs with if any when item 2 of zw is not an object", "input": {"ts": [{"id": "t", "xs": [], "ys": ["a"], "zw": [{"k": 1}, 5]}]}, "results": [{"cause": "not_an_object", "check": "c", "failures": [{"cause": "not_an_object", "failures": [], "inputs": [], "kind": "assertion", "locations": ["$policy:/requirements/r/checks/c/assert"], "message": "item 1 of ys: item 2 of zw is 5, which isn't an object; item 1 of ys: the check is false", "name": "count of zw.k that is in $params.m named by y is at most x.n"}], "inputs": [{"locations": [], "name": "xs[]", "outcome": "usable", "value": []}, {"locations": ["/ts/0/ys/0"], "name": "ys[]", "outcome": "usable", "value": ["a"]}, {"locations": ["/ts/0/zw/0/k", "/ts/0/zw/1"], "name": "zw[].k", "outcome": "usable", "value": [1, null]}], "message": "item 1 of ys: item 2 of zw is 5, which isn't an object; item 1 of ys: the check is false", "passed": false, "requirement": "r", "subject": {"id": "t", "type": "t"}}], "rules": ["for.roots", "tally.walk"]}], "description": "a that of a count of that reads an earlier line's alias as the key, and the later line's alias only on the right of the comparison, can't decide an item, so it fails even when the later line has no item", "params": {"m": {"a": [1]}}, "policy": {"ergo_spec": "{{spec}}", "requirements": {"r": {"checks": {"c": {"assert": "count of zw.k that is in $params.m named by y is at most x.n", "for": "every ys as y, every xs, if any, as x"}}, "min_subjects": 0, "subject": "t"}}, "subjects": {"t": {"from": "ts", "identified_by": "id"}}}}, + { + "cases": [ + { + "description": "fails as absent with the item in front when xs has one item and the params have no m", + "input": { + "prs": [ + { + "id": "p", + "tests": [ + { + "key": "a", + "v": 1 + } + ], + "xs": [ + "a" + ] + } + ] + }, + "results": [ + { + "cause": "absent", + "check": "alias_first", + "failures": [ + { + "cause": "absent", + "failures": [ + { + "cause": "absent", + "failures": [], + "inputs": [ + { + "locations": [ + "/prs/0/tests/0" + ], + "name": "count of tests whose v equals $params.m named by x named by key", + "value": null + } + ], + "kind": "item", + "locations": [ + "/prs/0/xs/0" + ], + "message": "$params.m is missing", + "name": "item 1 of xs", + "value": "a" + } + ], + "inputs": [], + "kind": "assertion", + "locations": [ + "$policy:/requirements/r/checks/alias_first/assert" + ], + "message": "", + "name": "count of tests whose v equals $params.m named by x named by key is 0" + } + ], + "inputs": [ + { + "locations": [ + "/prs/0/tests/0" + ], + "name": "tests[]", + "outcome": "usable", + "value": [ + { + "key": "a", + "v": 1 + } + ] + }, + { + "locations": [ + "/prs/0/xs/0" + ], + "name": "xs[]", + "outcome": "usable", + "value": [ + "a" + ] + } + ], + "message": "item 1 of xs: $params.m is missing", + "passed": false, + "requirement": "r", + "subject": { + "id": "p", + "type": "pr" + } + }, + { + "cause": "absent", + "check": "key_first", + "failures": [ + { + "cause": "absent", + "failures": [ + { + "cause": "absent", + "failures": [], + "inputs": [ + { + "locations": [ + "/prs/0/tests/0" + ], + "name": "count of tests whose v equals $params.m named by key named by x", + "value": null + } + ], + "kind": "item", + "locations": [ + "/prs/0/xs/0" + ], + "message": "$params.m is missing", + "name": "item 1 of xs", + "value": "a" + } + ], + "inputs": [], + "kind": "assertion", + "locations": [ + "$policy:/requirements/r/checks/key_first/assert" + ], + "message": "", + "name": "count of tests whose v equals $params.m named by key named by x is 0" + } + ], + "inputs": [ + { + "locations": [ + "/prs/0/tests/0" + ], + "name": "tests[]", + "outcome": "usable", + "value": [ + { + "key": "a", + "v": 1 + } + ] + }, + { + "locations": [ + "/prs/0/xs/0" + ], + "name": "xs[]", + "outcome": "usable", + "value": [ + "a" + ] + } + ], + "message": "item 1 of xs: $params.m is missing", + "passed": false, + "requirement": "r", + "subject": { + "id": "p", + "type": "pr" + } + } + ], + "rules": [ + "for.roots", + "for.if_any", + "tally.walk" + ] + } + ], + "description": "a root from $params read through the line alias and the item's key, in either order, is read with each item, so a root it doesn't have fails the check when xs has an item, naming the item", + "params": {}, + "policy": { + "ergo_spec": "{{spec}}", + "requirements": { + "r": { + "checks": { + "alias_first": { + "assert": "count of tests whose v equals $params.m named by x named by key is 0", + "for": "every xs, if any, as x" + }, + "key_first": { + "assert": "count of tests whose v equals $params.m named by key named by x is 0", + "for": "every xs, if any, as x" + } + }, + "min_subjects": 0, + "subject": "pr" + } + }, + "subjects": { + "pr": { + "from": "prs", + "identified_by": "id" + } + } + } + }, + { + "cases": [ + { + "description": "passes when xs is empty and the params have no m", + "input": { + "prs": [ + { + "id": "p", + "tests": [ + { + "key": "a", + "v": 1 + } + ], + "xs": [] + } + ] + }, + "results": [ + { + "cause": "satisfied", + "check": "alias_first", + "inputs": [ + { + "locations": [ + "/prs/0/tests/0" + ], + "name": "tests[]", + "value": [ + { + "key": "a", + "v": 1 + } + ] + }, + { + "locations": [], + "name": "xs[]", + "value": [] + } + ], + "passed": true, + "requirement": "r", + "subject": { + "id": "p", + "type": "pr" + } + }, + { + "cause": "satisfied", + "check": "key_first", + "inputs": [ + { + "locations": [ + "/prs/0/tests/0" + ], + "name": "tests[]", + "value": [ + { + "key": "a", + "v": 1 + } + ] + }, + { + "locations": [], + "name": "xs[]", + "value": [] + } + ], + "passed": true, + "requirement": "r", + "subject": { + "id": "p", + "type": "pr" + } + } + ], + "rules": [ + "for.roots", + "for.if_any", + "tally.walk" + ] + } + ], + "description": "a root from $params read through the line alias and the item's key, in either order, is not read at all when xs is empty with if any, so the check passes whether or not the root can be read", + "params": {}, + "policy": { + "ergo_spec": "{{spec}}", + "requirements": { + "r": { + "checks": { + "alias_first": { + "assert": "count of tests whose v equals $params.m named by x named by key is 0", + "for": "every xs, if any, as x" + }, + "key_first": { + "assert": "count of tests whose v equals $params.m named by key named by x is 0", + "for": "every xs, if any, as x" + } + }, + "min_subjects": 0, + "subject": "pr" + } + }, + "subjects": { + "pr": { + "from": "prs", + "identified_by": "id" + } + } + } + } ]