diff --git a/CHANGELOG.md b/CHANGELOG.md index 18580a4cb..c10cf8ada 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ This file is about `ergo.rego` only. The Rust engine's changes are in [engines/r ### Fixed +- A field in front of a list with a `whose`, named like a `for` alias and with no dot in front, is the alias, as [sentence.for.alias](spec/syntax.md#the-for-line) says. Under `for: every envs as e`, `every e of tests whose kind is "unit" is "passed"` reads the alias for each kept test, and under `for: every envs as commits`, `every commits.sha of prs whose state is "merged" is "ok"` reads the alias's `sha`. Before, both read each kept item's own field. A dot in front, `.e`, still reads the item's field. The row lists no entry for that field, as [for.inputs](spec/semantics.md#for) says. This changes the report of a policy that has one. +- A root read through a `named by` key from the subject, or from `$params`, and then the item's own key is read up to the item's key once, before any item, as [tally.walk](spec/semantics.md#counts-and-sums-in-sentences) and [for.roots](spec/semantics.md#for) say. 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` passed, and now fails as `absent` with `$params.m named by pr.key is missing`. The same goes for `sum of … whose` and `count of … that`, for a root from `$input` or from the subject, like `pr.m named by pr.key named by key`, for a key from `$input` and for a chain of two keys from the subject. A `null` prefix now fails as `null`, a key text from the subject that names nothing, like `""` or `"zz"`, fails as `absent`, and a prefix that isn't an object, like `{"m": {"a": 3}}`, a list or a text, fails as `unusable` with `$params.m named by pr.key is 3, which isn't an object`, also in the middle of a chain like `$params.m named by pr.k1 named by pr.k2 named by key`, where it passed. Under `for: every xs, if any, as x` with `xs` `[]`, `… named by pr.key named by key` passed and now fails as `absent`. Under `for: every xs as x` with `xs` `[]`, the cause goes from `value` to `absent` or `null`. With `xs` `["a"]`, `$params.m named by x named by key` and `$params.m named by pr.key named by x named by key` passed and now fail. This changes the report of a policy that has one. +- Under a second `for` line with `, if any,` whose `whose` leaves no item, an earlier line's alias read as a `named by` key that isn't text fails the check, as with an empty list ([for.pass](spec/semantics.md#for), [for.if_any](spec/semantics.md#for)). `for: every ys as y, every xs whose v is 1, if any, as x` with `count of zw.k that is in $params.m named by y named by x is at most 5` and `ys` `[3]` used to pass, and now fails as `unusable` with `item 1 of ys: y is 3, which isn't text`. Without `, if any,`, `every ys as y, every xs whose v is 1 as x` with `ys` `[3]` and `xs` `[{"v": 2}]` used to fail as `value` with `item 1 of ys is 3` and now fails as `unusable` with `item 1 of ys: y is 3, which isn't text; item 1 of ys is 3`. A `named by y` key that is `null` now adds `item 1 of ys: y is null` to the message. This changes the report of a policy that has one. +- 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/layers-known.txt b/engines/rego/layers-known.txt index ce9920c18..9cff45b6d 100644 --- a/engines/rego/layers-known.txt +++ b/engines/rego/layers-known.txt @@ -94,6 +94,7 @@ _input_ref_inputs -> _right_ref_ops _is_key -> _out_of_range _joined -> _escaped _key_isnt_text -> _m_isnt +_keyed_prefix_fault -> _m_isnt _keys_of -> _named _leaf_cause -> _leaf_passed _leaf_cause -> _leaf_paths diff --git a/engines/rego/src/lines/for_lines.rego b/engines/rego/src/lines/for_lines.rego index 32167b2d5..3ea30a0b7 100644 --- a/engines/rego/src/lines/for_lines.rego +++ b/engines/rego/src/lines/for_lines.rego @@ -326,7 +326,15 @@ _for_second_keyed(j, nw, ns) := j < nw if j < ns else := true -_for_second_has_items(check, subj) if _for_walk(object.remove(check.items[1], ["whose", "pick"]), subj, _for_names).items != [] +_for_second_has_items(check, subj) if { + item := object.remove(check.items[1], ["pick"]) + some e in _for_walk(object.remove(item, ["whose"]), subj, _for_names).items + _for_second_whose_keeps(_for_whose(object.union({"whose": []}, item), e, _for_names)) +} + +_for_second_whose_keeps(wh) if wh.kept + +_for_second_whose_keeps(wh) if wh.undecided != [] _second_root(subj, c) := root if { root := _root_read_flaw(subj, c) diff --git a/engines/rego/src/lines/roots.rego b/engines/rego/src/lines/roots.rego index 564091668..15cc006b0 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) @@ -881,7 +892,7 @@ _keyed_off_start(p) if _builtin(p) _keyed_root_fault(subj, p) := fs[0] if { k := _keyed_plain_end(p) - fs := [f | some j in numbers.range(2, k); f := _keyed_prefix_fault(subj, p, j, k)] + fs := [f | some j in numbers.range(2, _keyed_item_at(p)); f := _keyed_prefix_fault(subj, p, j, k)] count(fs) > 0 } @@ -889,7 +900,7 @@ _keyed_prefix_fault(subj, p, j, k) := {"cause": st, "text": _name_key_said([_inp shown := _as_subject_part(array.slice(p, 0, j)) st := _any_read_state(subj, shown) st in {"absent", "null"} -} else := {"cause": "unusable", "text": _tally_step(subj, shown, false, true).msg} if { +} else := {"cause": "unusable", "text": _m_isnt(_input_name(shown), v, "an object")} if { shown := _as_subject_part(array.slice(p, 0, j)) _any_read_state(subj, shown) == "value" v := _value_at(subj, shown) @@ -901,10 +912,11 @@ _keyed_state_value := {"absent": _absent, "null": null} _keyed_named(p, j, k, st) := _as_subject_part(array.slice(p, 0, k)) if { st == "absent" + j <= k _builtin(p) } else := _as_subject_part(array.slice(p, 0, j)) -_keyed_prefix_stops(j, k, _) if j == k +_keyed_prefix_stops(j, k, _) if j >= k _keyed_prefix_stops(j, k, v) if { j < k diff --git a/engines/rego/src/lines/walk.rego b/engines/rego/src/lines/walk.rego index 94f9d489e..9e64a0551 100644 --- a/engines/rego/src/lines/walk.rego +++ b/engines/rego/src/lines/walk.rego @@ -62,9 +62,16 @@ _walk_read_row(check, subj) := _key_listed({"cause": state, "inputs": _merged_in not _walk_keys({"path": p}, subj) } -_walk_read_path(check) := array.concat(check.path, _s_steps_after(check.field.path)) if check.field +_walk_field_source(check) := {"from": "alias", "path": [check.field.path[0]], "steps": array.slice(check.field.path, 1, count(check.field.path))} if { + _named(check.field.path) + not _builtin(check.field.path) + not _part_start(check.field.path) +} else := {"from": "item", "path": check.path, "steps": check.field.path} if check.field -else := check.path +_walk_read_path(check) := array.concat(src.path, _s_steps_after(src.steps)) if { + src := _walk_field_source(check) + src.from == "item" +} else := check.path _walk_read_row(check, subj) := {"cause": cause, "inputs": inputs, "failed": failed, "fails": fails, "empty": _walk_none(listed, cause)} if { keys := _walk_keys(check, subj) @@ -93,12 +100,20 @@ _walk_along(check, subj, listed) := {"w": w, "judged": _walk_judged(check, w)} i j := _walk_judged(object.remove(check, ["distinct"]), listed) ks := {e.i | some k, e in listed.items; j[k].kept; j[k].decided} found := _walk_kept(_walk_start(check, subj), _walk_keys({"path": _walk_read_path(check)}, subj), check.if_any == true, n, ks) - w := object.union(found, {"items": [x | some e in listed.items; some x in _walk_along_items(e, ks, found)]}) + src := _walk_field_source(check) + w := object.union(found, {"items": [x | some e in listed.items; some x in _walk_along_items(e, ks, found, _walk_along_from(src, subj))]}) } else := {"w": listed, "judged": _walk_judged(check, listed)} -_walk_along_items(e, ks, _) := [e] if not e.i in ks +_walk_along_items(e, ks, _, _) := [e] if not e.i in ks -_walk_along_items(e, ks, found) := [object.union(x, {"along": true}) | some x in found.items; array.slice(x.i, 0, count(e.i)) == e.i] if e.i in ks +_walk_along_items(e, ks, found, from) := [object.union(x, from) | some x in found.items; array.slice(x.i, 0, count(e.i)) == e.i] if e.i in ks + +_walk_along_from(src, _) := {"along": true} if src.from == "item" + +_walk_along_from(src, subj) := {"along": true, "r": p, "v": object.get({"v": _start_of(subj, p)}, array.concat(["v"], src.steps), _absent), "alias_at": _joined(_start_at(p), src.steps)} if { + src.from == "alias" + p := array.concat(src.path, src.steps) +} default _walk_none(_, _) := false @@ -292,7 +307,9 @@ _walk_base(path) := base if base := _start_at(path) else := "" -_walk_at(w, e) := _joined(w.trail[0].a, array.slice(e.c, count(w.trail[0].c), count(e.c))) if not _walk_marked(e.v) +_walk_at(w, e) := e.alias_at if "alias_at" in object.keys(e) + +else := _joined(w.trail[0].a, array.slice(e.c, count(w.trail[0].c), count(e.c))) if not _walk_marked(e.v) else := _pointer(w.trail[0].a, w.trail[0].v, array.slice(e.c, count(w.trail[0].c), count(e.c))) @@ -492,8 +509,8 @@ _walk_judgement(check, w, e) := {"kept": kept, "passed": passed, "failure": fail failure := _walk_failure(check.path, w, e, undecided, kept, leaf, passed) } -_walk_judgement(check, w, e) := _walk_split_judgement(check, w, e, array.slice(check.whose, count(check.whose) - check.field.that, count(check.whose)), array.concat(check.path, check.field.path)) if { - check.field +_walk_judgement(check, w, e) := _walk_split_judgement(check, w, e, array.slice(check.whose, count(check.whose) - check.field.that, count(check.whose)), array.concat(src.path, src.steps)) if { + src := _walk_field_source(check) e.along } @@ -512,8 +529,9 @@ _walk_split_judgement(check, w, e, conds, path) := {"kept": kept, "passed": pass } _walk_field_inputs(check, w, judged) := [{"name": check.field.name, "value": [_walk_value(f.v, f, w) | some f in kept], "locations": [_walk_at(w, f) | some f in kept]}] if { + _walk_field_source(check).from == "item" kept := [e | some i, e in w.items; judged[i].kept; judged[i].decided] -} +} else := [] _focus_entry(e) := object.union(object.remove(e, ["i", "iv", "r"]), {"i": e.c, "iv": e.v, "r": []}) if { e.r != [] 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/src/sentences/problems.rego b/engines/rego/src/sentences/problems.rego index a591f54ab..91cc688a8 100644 --- a/engines/rego/src/sentences/problems.rego +++ b/engines/rego/src/sentences/problems.rego @@ -415,10 +415,18 @@ _s_aliased(a, names) := object.union(object.union(a, {k: _s_marked(a[k], names, {"phrase": _s_marked_phrase(a.phrase, names)}, object.union( {"terms": [_s_marked_kept_term(t, names) | some t in a.terms] | is_array(object.get(a, "terms", null))}, - {"where": [_s_marked_cond(c, names) | some c in a.where] | is_array(object.get(a, "where", null))}, + object.union( + {"where": [_s_marked_cond(c, names) | some c in a.where] | is_array(object.get(a, "where", null))}, + {"field_of": _s_aliased_field_of(a.field_of, names) | is_object(object.get(a, "field_of", null))}, + ), ), )) +_s_aliased_field_of(p, names) := object.union(p, {"alias": true}) if { + _s_markable(p, names.for) + object.get(p, "dot", false) != true +} else := p + _s_marked_kept_term(t, names) := object.union(_s_marked_term(t, names), {"field_of_where": [_s_marked_cond(c, names) | some c in t.field_of_where]}) if { is_object(t) is_array(object.get(t, "field_of_where", null)) diff --git a/engines/rego/tests/lines/for_lines_test.rego b/engines/rego/tests/lines/for_lines_test.rego index 4cb21bf25..fce98e1f7 100644 --- a/engines/rego/tests/lines/for_lines_test.rego +++ b/engines/rego/tests/lines/for_lines_test.rego @@ -519,3 +519,27 @@ test_a_count_whose_key_from_the_first_lines_alias_is_said_for_each_item_of_the_f } } } + +test_a_count_whose_key_from_the_first_lines_alias_is_left_to_the_items_when_the_whose_of_the_second_list_fails_one_condition_and_leaves_another_undecided if { + check := ergo._s_written_check({"for": "every ys as y, every xs whose v is 1 and whose w is 1, if any, as x", "assert": "count of zw.k that is in $params.m named by y named by x is at most 5"}) + subj := {"ys": [3], "xs": [{"v": 2}], "zw": [{"k": 1}]} + names := {"ergo/subject": subj, "$at": {"names": {}}} + ergo._for_second_has_items(check, subj) with input as {"ergo/names": names} + [x | some x in ergo._for_second_roots(check, subj)] == [] with input as {"ergo/names": names} with data.ergo_params as {"m": {"a": {"a": [1]}}} +} + +test_a_count_whose_key_from_the_first_lines_alias_is_said_for_each_item_of_the_first_list_when_the_whose_of_the_second_list_leaves_no_item if { + every line in ["every ys as y, every xs whose v is 1, if any, as x", "some ys as y, every xs whose v is 1, if any, as x"] { + check := ergo._s_written_check({"for": line, "assert": "count of zw.k that is in $params.m named by y named by x is at most 5"}) + every c in [ + [3, [["unusable", ["item 1 of ys: y is 3, which isn't text"]]]], + [null, [["null", ["item 1 of ys: y is null"]]]], + [{"o": 1}, [["unusable", [`item 1 of ys: y is {"o": 1}, which isn't text`]]]], + ["a", []], + ] { + subj := {"ys": [c[0]], "xs": [{"v": 2}], "zw": [{"k": 1}]} + names := {"ergo/subject": subj, "$at": {"names": {}}} + [[x.fl, x.ms] | some x in ergo._for_second_roots(check, subj)] == c[1] with input as {"ergo/names": names} with data.ergo_params as {"m": {"a": {"a": [1]}}} + } + } +} diff --git a/engines/rego/tests/lines/roots_test.rego b/engines/rego/tests/lines/roots_test.rego index c643abc00..bdd1d3548 100644 --- a/engines/rego/tests/lines/roots_test.rego +++ b/engines/rego/tests/lines/roots_test.rego @@ -793,6 +793,64 @@ 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_keyed_root_fault_reads_the_root_through_the_subjects_key_before_the_items_key if { + pr := {"key": "a", "tests": []} + p := ["$$params", "m", {"named_by_field": "\u0003pr\u0003key"}, {"named_by_field": "key"}] + ergo._keyed_root_fault(pr, p) == {"cause": "absent", "text": "$params.m named by pr.key is missing"} with input as {"ergo/names": {"ergo/subject": pr}} with data.ergo_params as {"m": {}} + ergo._keyed_root_fault(pr, p) == {"cause": "null", "text": "$params.m named by pr.key is null"} with input as {"ergo/names": {"ergo/subject": pr}} with data.ergo_params as {"m": {"a": null}} + 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 {} + not ergo._keyed_root_fault(pr, p) with input as {"ergo/names": {"ergo/subject": pr}} with data.ergo_params as {"m": {"a": {}}} +} + +test_keyed_root_fault_fails_a_prefix_read_through_the_subjects_key_that_isnt_an_object_as_unusable if { + pr := {"key": "a", "k1": "a", "k2": "c", "tests": []} + names := {"ergo/names": {"ergo/subject": pr}} + p := ["$$params", "m", {"named_by_field": "\u0003pr\u0003key"}, {"named_by_field": "key"}] + ergo._keyed_root_fault(pr, p) == {"cause": "unusable", "text": "$params.m named by pr.key is 3, which isn't an object"} with input as names with data.ergo_params as {"m": {"a": 3}} + ergo._keyed_root_fault(pr, p) == {"cause": "unusable", "text": "$params.m named by pr.key is [], which isn't an object"} with input as names with data.ergo_params as {"m": {"a": []}} + ergo._keyed_root_fault(pr, p) == {"cause": "unusable", "text": "$params.m named by pr.key is \"s\", which isn't an object"} with input as names with data.ergo_params as {"m": {"a": "s"}} + ergo._keyed_root_fault(pr, p) == {"cause": "absent", "text": "$params.m named by pr.key is missing"} with input as names with data.ergo_params as {"m": {}} + chain := ["$$params", "m", {"named_by_field": "\u0003pr\u0003k1"}, {"named_by_field": "\u0003pr\u0003k2"}, {"named_by_field": "key"}] + ergo._keyed_root_fault(pr, chain) == {"cause": "unusable", "text": "$params.m named by pr.k1 is 3, which isn't an object"} with input as names with data.ergo_params as {"m": {"a": 3}} +} + +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/lines/walk_test.rego b/engines/rego/tests/lines/walk_test.rego index 6a27813ab..be3172a6d 100644 --- a/engines/rego/tests/lines/walk_test.rego +++ b/engines/rego/tests/lines/walk_test.rego @@ -390,3 +390,37 @@ test_a_quoted_field_that_starts_with_a_dollar_fails_on_a_key_that_cant_be_read_a quoted.cause == bare.cause } } + +test_each_item_the_whose_keeps_reads_the_field_in_front_of_the_list_from_itself_along_the_steps_of_the_field if { + every pair in [ + [`every status of tests whose kind is "unit" is "passed"`, ["status"]], + [`every v.n of tests whose kind is "unit" exists`, ["v", "n"]], + [`every "$c".sha of tests whose kind is "unit" is "ok"`, [{"literal": "$c"}, "sha"]], + ] { + check := ergo._rooted(ergo._s_written_check(pair[0])) + ergo._walk_field_source(check) == {"from": "item", "path": check.path, "steps": pair[1]} + } +} + +_aliased_kept_row(line, text, subj, names) := r if { + check := ergo._rooted(ergo._s_written_check({"for": line, "assert": text}).checks[0]) + r := ergo._walk_row(check, subj) with data.ergo_document as {} with data.ergo_params as {} with input as {"ergo/names": names} +} + +test_each_item_the_whose_keeps_reads_the_field_in_front_of_the_list_from_the_for_alias_of_the_same_name if { + subj := {"envs": [{"sha": "ok"}], "prs": [{"state": "merged", "commits": {"sha": "bad"}}, {"state": "open"}], "tests": [{"kind": "unit", "e": "failed"}, {"kind": "e2e"}]} + at := {"names": {"e": "~~/envs/0", "commits": "~~/envs/0"}} + bare := _aliased_kept_row("every envs as e", `every e of tests whose kind is "unit" is "passed"`, subj, {"ergo/subject": subj, "e": "passed", "$at": at}) + bare.cause == "satisfied" + dotted := _aliased_kept_row("every envs as commits", `every commits.sha of prs whose state is "merged" is "ok"`, subj, {"ergo/subject": subj, "commits": {"sha": "ok"}, "$at": at}) + dotted.cause == "satisfied" +} + +test_a_field_in_front_of_the_list_read_from_the_for_alias_lists_no_entry_because_an_alias_value_is_never_listed if { + subj := {"envs": [{"sha": "ok"}], "prs": [{"state": "merged", "commits": {"sha": "bad"}}], "tests": [{"kind": "unit", "e": "failed"}]} + at := {"names": {"e": "~~/envs/0", "commits": "~~/envs/0"}} + bare := _aliased_kept_row("every envs as e", `every e of tests whose kind is "unit" is "passed"`, subj, {"ergo/subject": subj, "e": "passed", "$at": at}) + [i | some i in bare.inputs; i.name == `e of tests whose kind is "unit"`] == [] + dotted := _aliased_kept_row("every envs as commits", `every commits.sha of prs whose state is "merged" is "ok"`, subj, {"ergo/subject": subj, "commits": {"sha": "ok"}, "$at": at}) + [i | some i in dotted.inputs; i.name == `commits.sha of prs whose state is "merged"`] == [] +} 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/sentences/field_of_test.rego b/engines/rego/tests/sentences/field_of_test.rego index 211d91041..f2be8fb74 100644 --- a/engines/rego/tests/sentences/field_of_test.rego +++ b/engines/rego/tests/sentences/field_of_test.rego @@ -387,3 +387,14 @@ test_a_pick_in_front_of_a_field_beside_another_assertion_still_doesnt_parse if { test_a_pick_in_front_of_a_field_says_an_unknown_name_too if { ergo._sentence(`first of status of tests whose kind is $nope is "passed"`) == {"problems": [_pick_place, "unknown name $nope"]} } + +test_a_field_in_front_of_a_list_named_like_a_for_alias_reads_the_alias_and_a_dot_in_front_reads_the_field if { + every pair in [ + ["every envs as e", `every e of tests whose kind is "unit" is "passed"`, ["$e"]], + ["every envs as commits", `every commits.sha of prs whose state is "merged" is "ok"`, ["$commits", "sha"]], + ["every envs as commits", `every .commits.sha of prs whose state is "merged" is "ok"`, ["commits", "sha"]], + ["every envs as e", `every status of tests whose kind is "unit" is "passed"`, ["status"]], + ] { + ergo._s_written_check({"for": pair[0], "assert": pair[1]}).checks[0].field.path == pair[2] + } +} diff --git a/engines/rego/tests/spec_test.rego b/engines/rego/tests/spec_test.rego index 32a920d72..afbb8d641 100644 --- a/engines/rego/tests/spec_test.rego +++ b/engines/rego/tests/spec_test.rego @@ -14,8 +14,6 @@ known_differences := { "derived / an every or some whose whose reads a root from $input through a key the item holds fails on the root, said once, when each item reads fine / the root is missing", "derived / an every or some whose whose reads a root from $input through a key the item holds fails on the root, said once, when each item reads fine / the root is null", "derived / an every or some whose whose reads a root from $params through a key the item holds fails on the root, said once, when each item reads fine / the root is null", - "field_of / 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 / the alias holds the sha the phrase wants, and the commit of the kept pull request does not", - "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 / the alias is the text the phrase wants, and the unit test's own field isn't", "field_of / a field with a dot in front of a list with whose and a list along the field, named like a for alias, reads the field and not the alias / the commit of the kept pull request is ok, and the alias holds a sha that is not", "field_of / a tally of a field in front of a list with a whose reads a for line's alias in the whose once for each of the line's items, as the tally of the items does / the alias is the kind of one test, so each tally passes, and the row shows the line's list and the list the whose walks", "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 / the alias is read on each of the two unit tests, so the count is two and the check passes", @@ -30,9 +28,6 @@ known_differences := { "for / a part that holds a list is walked by a whose in `count of m.ys whose v is in pl.z is 0` / the part holds an empty list and the list has an item", "for / a part that holds a list is walked in the whose of a for line and in a whose under it / an empty part fails as value", "for / a walk through a for line's alias leaves a root after the phrase to the assertion, and each item keeps its own cause and the items of its list / an item whose list holds five items without v", - "for / an earlier line's alias read as a named by key that isn't text, under a second for line with if any whose whose leaves no item, fails the check, as with no item in the list / fails as null with the item of ys in front when y is null, though the whose of xs leaves no item", - "for / an earlier line's alias read as a named by key that isn't text, under a second for line with if any whose whose leaves no item, fails the check, as with no item in the list / fails as unusable with the item of ys in front when y is 3, though the whose of xs leaves no item", - "for / an earlier line's alias read as a named by key that isn't text, under a second for line with if any whose whose leaves no item, fails the check, as with no item in the list / fails as unusable with the item of ys in front when y is an object, though the whose of xs leaves no item", "for / the roots of the line's own whose come before the roots of its sentences, whatever their causes / $params.min is missing and says first, though $params.a has the worse cause", "members / count of member of a root that isn't an object, or that a key from outside the item names, on a for line over an empty list / fails on the root before any item, with or without if any, and says the empty list after it only without if any", "members / every member of on a for line whose whose reads a named by key from $params that isn't text, beside a member that fails on its own field / says the key once, before any member, and then the member that has its own problem", @@ -44,15 +39,16 @@ known_differences := { "sentences / a named by key from the subject after a parent or an alias, inside a relative clause / fails as absent once when the subject has no k", "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 from $params read through two named by keys from the subject and then the item's key fails the check on an empty list too, when the first one finds a value that isn't an object / fails as unusable naming the value the first key finds when it is 3 and 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", "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 null naming $input.m when it is null and 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 unusable naming $input.m when it is 3 and tests is empty", "sentences / 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 / fails as unusable on an empty xs with if any when y is 3", "sentences / 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 / fails on an empty xs with if any when item 2 of zw is not an object", + "sentences / a that of a count of that reads the line's alias as a named by key, after an earlier line's alias, has nothing to check on an empty later list with if any, so it passes whatever the items of the counted list are / passes on an empty xs with if any when item 2 of zw is not an object", + "sentences / a that of a count of that reads the line's alias as a named by key, after an earlier line's alias, has nothing to check on an empty later list with if any, so it passes whatever the items of the counted list are / passes on an empty xs with if any when item 2 of zw has no k", "sentences / two named by keys from the subject, one after the other, are both read from the subject and never from the item / fails as absent when the param has no field named by the subject's j, even when the item's own pr names one", } diff --git a/engines/rust/CHANGELOG.md b/engines/rust/CHANGELOG.md index 80d966c2c..4182ad684 100644 --- a/engines/rust/CHANGELOG.md +++ b/engines/rust/CHANGELOG.md @@ -35,6 +35,10 @@ Each release names the version of the spec it follows. The spec's own changes ar ### Fixed +- A field in front of a list with a `whose`, named like a `for` alias and with no dot in front, is the alias, as [sentence.for.alias](../../spec/syntax.md#the-for-line) says. Under `for: every envs as e`, `every e of tests whose kind is "unit" is "passed"` reads the alias for each kept test, where it read each test's own `e`, and the row lists no entry for that field, as [for.inputs](../../spec/semantics.md#for) says. This changes the report of a policy that has one. +- A root read through a `named by` key from the subject, or from `$params`, and then the item's own key is read up to the item's key once, before any item, as [tally.walk](../../spec/semantics.md#counts-and-sums-in-sentences) and [for.roots](../../spec/semantics.md#for) say. 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` passed, and now fails as `absent` with `$params.m named by pr.key is missing`. The same goes for `sum of … whose` and `count of … that`, for a root from `$input` or from the subject, like `pr.m named by pr.key named by key`, for a key from `$input` and for a chain of two keys from the subject. A `null` prefix now fails as `null`, a key text from the subject that names nothing, like `""` or `"zz"`, fails as `absent`, and a prefix that isn't an object, like `{"m": {"a": 3}}`, a list or a text, fails as `unusable` with `$params.m named by pr.key is 3, which isn't an object`, also in the middle of a chain like `$params.m named by pr.k1 named by pr.k2 named by key`, where it passed. Under `for: every xs, if any, as x` with `xs` `[]`, `… named by pr.key named by key` passed and now fails as `absent`. Under `for: every xs as x` with `xs` `[]`, the cause goes from `value` to `absent` or `null`. With `xs` `["a"]`, `$params.m named by x named by key` and `$params.m named by pr.key named by x named by key` passed and now fail. In the Rust engine alone, a one-line `some` or `every` without `, if any,` on an empty list now takes the root's cause, like `absent` with `$params.m named by pr.key is missing; tests is []` where it said `value` with `tests is []`, and `count of tests.v that equals $params.m named by pr.key named by key is 0` with an item that isn't an object fails as `not_an_object`, naming the root and the item, where it said `absent`. This changes the report of a policy that has one. +- A `count of` whose `that` reads an earlier line's alias as a `named by` key, like `count of zw.k that is in $params.m named by y is at most x.n` under `for: every ys as y, every xs, if any, as x`, fails when an item of the list can't be decided, even when the later list is empty and the earlier item isn't an object, as [for.roots](../../spec/semantics.md#for) says. It used to pass. With `ys` `[3]` and `xs` `[]`, `named by y` and `named by y.k` used to fail as `unusable` with only `y is 3, which isn't text`, and now fail as `not_an_object` and add `, and item 2 of zw is 5, which isn't an object`. Without `, if any,`, `every ys as y, every xs as x` with `xs` `[]` used to fail as `value` with `xs is []` and now fails as `not_an_object` with `xs is []; item 1 of ys: item 2 of zw is 5, which isn't an object`. This changes the report of a policy that has one. +- 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/lower.rs b/engines/rust/engine/src/lower.rs index ed9813908..af405bc78 100644 --- a/engines/rust/engine/src/lower.rs +++ b/engines/rust/engine/src/lower.rs @@ -1030,6 +1030,10 @@ pub(crate) fn walk_too_long_before( .then(|| "every and some over more than ten steps aren't supported yet".to_string()) } +fn names_a_for_alias(field: &s::FieldOf, scope: &Scope) -> bool { + matches!(&field.path.start, s::Start::Field { key, dot: false } if scope.aliases().contains(key)) +} + pub(crate) fn field_path(field: &s::FieldOf) -> s::Path { let start = match &field.path.start { s::Start::Field { key, .. } | s::Start::Quoted(key) | s::Start::Unknown(key) => { @@ -1099,7 +1103,11 @@ pub fn lower_quantified( steps: Vec::new(), }; let field = match field { - Some(written) => match item.left_path(&field_path(written)) { + Some(written) => match if names_a_for_alias(written, scope) { + scope.left_path(&written.path) + } else { + item.left_path(&field_path(written)) + } { Ok(read) => { if let Err(found) = scope.left_path(&field_path(written)) { problems.extend(found); diff --git a/engines/rust/engine/src/lower/tests.rs b/engines/rust/engine/src/lower/tests.rs index 6c2413c2c..f08d66993 100644 --- a/engines/rust/engine/src/lower/tests.rs +++ b/engines/rust/engine/src/lower/tests.rs @@ -106,6 +106,24 @@ fn a_parent_name_starts_at_the_parent_and_a_part_of_it_at_the_part() { ); } +#[test] +fn a_bare_field_in_front_of_a_list_named_like_a_for_alias_reads_the_alias_and_a_dotted_one_the_item() + { + let scope = Scope::new().with_for_alias("e"); + let lower = |text: &str| lower_assertion(&s::parse_check(text).unwrap().assertions[0], &scope); + let field_of = |text: &str| match lower(text) { + Ok(Check::Walk(walk)) => walk.field.map(|field| field.path), + _ => panic!("{text:?} doesn't lower to a walk"), + }; + let bare = field_of(r#"every e.sha of tests whose kind is "unit" is "ok""#).unwrap(); + assert_eq!(bare.start, Start::Alias("e".to_string())); + assert_eq!(bare.steps, [key("sha")]); + assert_eq!( + field_of(r#"every .e.sha of tests whose kind is "unit" is "ok""#), + Some(scope.in_item().left_path(&path("e.sha")).unwrap()) + ); +} + #[test] fn a_for_alias_starts_at_the_alias() { let p = lowered(&scope(), "pr.author"); diff --git a/engines/rust/engine/src/ops/for_line.rs b/engines/rust/engine/src/ops/for_line.rs index 0bec776c3..6dd1a56e9 100644 --- a/engines/rust/engine/src/ops/for_line.rs +++ b/engines/rust/engine/src/ops/for_line.rs @@ -206,6 +206,25 @@ fn reads_alias_whole(check: &Check, alias: &str) -> bool { }) } +fn reads_into_alias(check: &Check, alias: &str) -> bool { + let into = |path: &Path| { + matches!(&path.start, Start::Alias(name) if name == alias) && !path.steps.is_empty() + }; + nested_checks(check).into_iter().any(|inner| { + all_paths(inner) + .into_iter() + .chain(inner.paths()) + .chain(super::lists::right_paths(inner)) + .any(|path| { + into(path) + || path.steps.iter().any(|step| match step { + Step::Ref(reference) | Step::Field(reference) => into(reference), + _ => false, + }) + }) + }) +} + fn sorts_by_alias(item: &Item, alias: &str) -> bool { matches!(&item.how, How::Pick { sorted: Some(sorted), .. } if reads_path(&sorted.path, alias)) } @@ -3243,31 +3262,39 @@ impl For { } fn item_roots(&self, depth: usize, ctx: &Ctx) -> Vec { - let roots = |ctx: &Ctx| -> Vec { + let alias = &self.items[depth].alias; + let roots = |ctx: &Ctx| -> Vec<(Clause, bool)> { let outer = outer_ctx(ctx); let whose: Vec<&Check> = self.items[depth + 1..] .iter() .flat_map(|item| item.whose.iter()) .collect(); + let into = whose.iter().any(|check| reads_into_alias(check, alias)); let mut said = super::message::root_clauses(&whose, &outer); said.extend(super::message::walked_root_clauses(&whose, &outer)); + let mut said: Vec<(Clause, bool)> = said.into_iter().map(|root| (root, into)).collect(); for sentence in &self.sentences { - said.extend(sentence_roots_said(&sentence.check, &outer)); + let into = reads_into_alias(&sentence.check, alias); + said.extend( + sentence_roots_said(&sentence.check, &outer) + .into_iter() + .map(|root| (root, into)), + ); } said }; let whole = ctx .aliases - .get(&self.items[depth].alias) + .get(alias) .is_some_and(|at| !at.value.is_object()); let mut up = ctx.clone(); - up.aliases.remove(&self.items[depth].alias); + up.aliases.remove(alias); let said = |root: &Clause| super::clause::text(std::slice::from_ref(root)); - let before: Vec = roots(&up).iter().map(said).collect(); + let before: Vec = roots(&up).iter().map(|(root, _)| said(root)).collect(); let mut out: Vec = Vec::new(); - for root in roots(ctx) { + for (root, into) in roots(ctx) { let text = said(&root); - if !before.contains(&text) && !(whole && root.cause == Cause::NotAnObject) { + if !before.contains(&text) && !(whole && into && root.cause == Cause::NotAnObject) { push_new(&mut out, Clause::said(root.cause, text)); } } diff --git a/engines/rust/engine/src/ops/for_line/tests.rs b/engines/rust/engine/src/ops/for_line/tests.rs index cf9dd7891..2c01ca0bf 100644 --- a/engines/rust/engine/src/ops/for_line/tests.rs +++ b/engines/rust/engine/src/ops/for_line/tests.rs @@ -238,6 +238,18 @@ fn a_sentence_that_reads_the_alias_of_an_empty_list_a_for_line_tolerates_has_not ); } +#[test] +fn a_that_keyed_by_an_earlier_alias_fails_on_an_empty_later_list() { + let subject = json!({"xs": [], "ys": ["a"], "zw": [{"k": 1}, 5]}); + let row = row_with( + "every ys as y, every xs, if any, as x", + json!("count of zw.k that is in $params.m named by y is at most x.n"), + subject, + json!({"m": {"a": [1]}}), + ); + assert_eq!(row["cause"], "not_an_object"); +} + #[test] fn an_empty_first_list_a_for_line_tolerates_still_runs_the_sentences_that_dont_read_it() { let approvers = json!([{"u": "ada"}, {"u": "g", "state": "REJECTED"}]); diff --git a/engines/rust/engine/src/ops/key_base.rs b/engines/rust/engine/src/ops/key_base.rs index ea4ff6370..3167288ba 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 @@ -247,23 +253,67 @@ pub fn base_of(path: &Path, item_keys: bool, ctx: &Ctx) -> Option<(String, Strin if keys.is_empty() || keys.len() != at { return None; } - base_flaw(&path.start, &keys, false, ctx).map(|(text, cause, input)| (input.name, text, cause)) + if let Some((text, cause, input)) = base_flaw(&path.start, &keys, false, ctx) { + return Some((input.name, text, cause)); + } + let end = at + items_key_at(&path.steps[at..], ctx).filter(|_| item_keys)?; + for stop in at + 1..end { + let before = Path { + start: path.start.clone(), + steps: path.steps[..stop].to_vec(), + }; + if let Some(value) = path::read(&before, ctx).value.filter(|v| !v.is_object()) { + let named = name::name(&before); + let text = message::isnt(&named, value, "an object"); + return Some((named, text, Cause::Unusable)); + } + } + let prefix = Path { + start: path.start.clone(), + steps: path.steps[..end].to_vec(), + }; + let named = name::name(&prefix); + match path::read(&prefix, ctx) { + path::Read { + outcome: Outcome::Absent, + .. + } => Some((named.clone(), format!("{named} is missing"), Cause::Absent)), + path::Read { + outcome: Outcome::Null, + .. + } => Some((named.clone(), format!("{named} is null"), Cause::Null)), + path::Read { + value: Some(value), .. + } if !value.is_object() => { + let text = message::isnt(&named, value, "an object"); + Some((named, text, Cause::Unusable)) + } + _ => None, + } } fn subject_keys_then_an_items_key(steps: &[Step], ctx: &Ctx) -> bool { - let Some(at) = steps.iter().position(|step| { + items_key_at(steps, ctx).is_some() +} + +fn items_key_at(steps: &[Step], ctx: &Ctx) -> Option { + let at = steps.iter().position(|step| { matches!(step, Step::Field(key) if matches!(key.start, path::Start::Subject | path::Start::Own)) - }) else { - return false; - }; - steps[..at].iter().all(|step| match step { - Step::Key(_) => true, - Step::Field(key) => { - path::names_the_subject(&key.start) - && matches!(path::resolve(step, ctx), Ok(path::Resolved::Key(_))) - } - _ => false, - }) + })?; + steps[..at] + .iter() + .all(|step| match step { + Step::Key(_) => true, + Step::Field(key) => { + 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, + }) + .then_some(at) } /// The key and base problems of every path `check` reads. diff --git a/engines/rust/engine/src/ops/key_base/tests.rs b/engines/rust/engine/src/ops/key_base/tests.rs index 067dba5f3..de3897f70 100644 --- a/engines/rust/engine/src/ops/key_base/tests.rs +++ b/engines/rust/engine/src/ops/key_base/tests.rs @@ -688,3 +688,198 @@ 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": {}}); + let (_, text, cause) = base_of(&path, true, &ctx(&subject, ¶ms, &[])).unwrap(); + assert_eq!( + (text.as_str(), cause), + ("$params.m named by $params.k is missing", Cause::Absent) + ); + let params = json!({"k": "a", "m": {"a": {}}}); + assert!(base_of(&path, true, &ctx(&subject, ¶ms, &[])).is_none()); +} + +fn subject_key() -> Step { + Step::Field(Box::new(Path { + start: Start::Part(Box::new(crate::path::PartStart { + name: "pr".to_string(), + base: Start::Alias(crate::path::OUTER.to_string()), + steps: vec![], + id: None, + })), + steps: vec![Step::Key("key".to_string())], + })) +} + +#[test] +fn a_root_read_through_the_subjects_key_and_then_the_items_key_is_read_up_to_the_items_key_before_any_item() + { + let subject = json!({"key": "a", "tests": []}); + let path = chain(vec![subject_key(), items_key()]); + for (params, text, cause) in [ + ( + json!({"m": {}}), + "$params.m named by pr.key is missing", + Cause::Absent, + ), + ( + json!({"m": {"a": null}}), + "$params.m named by pr.key is null", + Cause::Null, + ), + (json!({}), "$params.m is missing", Cause::Absent), + ] { + let found = base_of( + &path, + true, + &ctx(&subject, ¶ms, &[(crate::path::OUTER, &subject)]), + ) + .map(|(_, t, c)| (t, c)); + assert_eq!(found, Some((text.to_string(), cause))); + } + let params = json!({"m": {"a": {}}}); + assert!( + base_of( + &path, + true, + &ctx(&subject, ¶ms, &[(crate::path::OUTER, &subject)]) + ) + .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()); + } +} + +#[test] +fn a_root_read_through_the_subjects_key_fails_as_unusable_where_a_step_before_the_items_key_isnt_an_object() + { + let subject = json!({"key": "a", "tests": []}); + let x = json!("c"); + for (steps, params, text) in [ + ( + vec![subject_key(), params_key(), items_key()], + json!({"m": {"a": "s"}, "k": "c"}), + "$params.m named by pr.key is \"s\", which isn't an object", + ), + ( + vec![subject_key(), alias_key(), items_key()], + json!({"m": {"a": 3}}), + "$params.m named by pr.key is 3, which isn't an object", + ), + ] { + let found = base_of( + &chain(steps), + true, + &ctx( + &subject, + ¶ms, + &[(crate::path::OUTER, &subject), ("x", &x)], + ), + ) + .map(|(_, t, c)| (t, c)); + assert_eq!(found, Some((text.to_string(), Cause::Unusable))); + } +} diff --git a/engines/rust/engine/src/ops/walk.rs b/engines/rust/engine/src/ops/walk.rs index 03ed9aa1e..93f35e5f9 100644 --- a/engines/rust/engine/src/ops/walk.rs +++ b/engines/rust/engine/src/ops/walk.rs @@ -1721,7 +1721,7 @@ fn field_end(walk: &Walk, walked: &Walked, item: &WalkItem, at: &Ctx) -> (String } fn kept_field_input(walk: &Walk, walked: &Walked, judged: &[Judged], ctx: &Ctx) -> Option { - let field = walk.field.as_ref()?; + let field = walk.field.as_ref().filter(|field| !from_alias(field))?; let mut at = ctx.clone(); at.label = None; let mut value = Vec::new(); @@ -1860,11 +1860,18 @@ fn field_item<'a>(walk: &Walk, item: &WalkItem<'a>, at: &Ctx<'a>) -> Option Path { let mut path = item.rest_path(); if let Some(field) = walk.field.as_ref().filter(|_| !item.along) { + if from_alias(field) { + return field.path.clone(); + } path.steps.extend(field.path.steps.iter().cloned()); } path } +fn from_alias(field: &Field) -> bool { + matches!(field.path.start, Start::Alias(_)) +} + fn walked_root_said(check: &Check, ctx: &Ctx, cause: Cause) -> Option { message::walked_root_clauses(&[check], ctx) .into_iter() diff --git a/engines/rust/engine/src/ops/walk/tests.rs b/engines/rust/engine/src/ops/walk/tests.rs index 82a2078bd..bba5a5dee 100644 --- a/engines/rust/engine/src/ops/walk/tests.rs +++ b/engines/rust/engine/src/ops/walk/tests.rs @@ -3008,3 +3008,31 @@ fn every_distinct_over_a_field_of_the_kept_items_checks_each_value_of_the_field_ assert_eq!(kept_row.rich, dotted_row.rich, "{kept}"); } } + +#[test] +fn a_field_that_starts_at_a_for_alias_reads_the_alias_and_lists_no_entry_for_the_field() { + let mut walk = every(&["tests"], Vec::new(), equals(json!("ok")), false); + walk.field = Some(Field { + name: "e.sha of tests".to_string(), + path: at(Start::Alias("e".to_string()), &["sha"]), + that: 0, + }); + let subject = json!({"tests": [{"sha": "bad"}, {"sha": "bad"}]}); + let input = json!({}); + let params = json!({}); + let env = json!({"sha": "ok"}); + let mut context = ctx(&subject, &input, Some(¶ms)); + context.aliases.insert( + "e".to_string(), + Located { + value: &env, + location: Location::input_root().key("envs").index(0), + }, + ); + let out = run(&walk, &context); + let names: Vec<&str> = out.verdict.inputs.iter().map(|i| i.name.as_str()).collect(); + assert_eq!( + (out.verdict.cause, names), + (Cause::Satisfied, vec!["tests[]"]) + ); +} diff --git a/engines/rust/known-failures.txt b/engines/rust/known-failures.txt index a08572995..eea410326 100644 --- a/engines/rust/known-failures.txt +++ b/engines/rust/known-failures.txt @@ -56,10 +56,8 @@ distinct / every distinct with conditions / copies a condition can't decide fail distinct / locations read through the subject and read from the input / a read through the subject lists every copy, and a path from the input lists only the location it names field_of / a field in front of a list with no whose and a list along the field is the dot path and is reported as it: every commits.sha of prs exists / a commit has no sha, and a pull request that is not merged is read too field_of / a field in front of a list with no whose, with if any, and a list along the field is the dot path: every commits.sha of prs, if any, exists / a commit has no sha, and a pull request that is not merged is read too -field_of / 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 / the alias holds the sha the phrase wants, and the commit of the kept pull request does not field_of / a field in front of a list with whose is read on each item the whose keeps: every with no item kept fails, as every does on a whose that keeps nothing / no test is a smoke test field_of / a field in front of a list with whose is read on each item the whose keeps: some with no item kept fails / no test is a smoke test -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 / the alias is the text the phrase wants, and the unit test's own field isn't field_of / a field with a dot in front of a list with whose and a list along the field, named like a for alias, reads the field and not the alias / the commit of the kept pull request is ok, and the alias holds a sha that is not field_of / a list along the field of the items a whose keeps, three of them kept among others it leaves out: exists / one of three kept pull requests has a commit with no sha field_of / a list along the field of the items a whose keeps: exists, which fails as value on a commit with no sha or a null sha / a commit has no sha @@ -416,7 +414,6 @@ sentences / a named by key from the subject after any path, inside a relative cl sentences / a named by key on the right of every, after a part, a parent, an alias, $params or $input / fails as unusable once when the subject's key isn't text sentences / a named by on the right of every that can't be read / names the key that is null, as the plain check does, when m is null too 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 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 name on the right of some in a from line's condition, read up front / fails the candidate once, with no item named, even when its list is empty diff --git a/engines/rust/sentences/tests/oracle/checks.rs b/engines/rust/sentences/tests/oracle/checks.rs index 5d2efeca3..47f94bad3 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", @@ -261,6 +273,12 @@ pub const CHECK_OK: &[(&str, &str, &[&str], &[&str])] = &[ &[], &[], ), + ( + "count of tests whose v equals $params.m named by pr.k1 named by pr.k2 named by key is 0", + "count of tests whose v equals $params.m named by pr.k1 named by pr.k2 named by key is 0", + &[], + &[], + ), ( "count of tests whose v equals x.m named by pr.key is 0", "count of tests whose v equals x.m named by pr.key is 0", diff --git a/spec/OPEN.md b/spec/OPEN.md index c2a62df61..60e652860 100644 --- a/spec/OPEN.md +++ b/spec/OPEN.md @@ -92,20 +92,21 @@ 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. -- **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. +- **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. With a key from the subject in front of the item's key, the Rust engine also takes the root's cause where `ergo.rego` doesn't: with the params `{"m": {}}`, `key` "a" and `tests` `[]`, `some tests whose v equals $params.m named by pr.key named by key exists` says `value` with `tests is []` in `ergo.rego` and `absent` with `$params.m named by pr.key is missing; tests is []` in the Rust engine, and the same with `m.a` `null`, `3` or `[]`, and with `every`. Since #960, where the Rust engine reads the root before any item. No step is scheduled yet. +- **A root read through the subject's key beside an item that isn't an object (type 2).** With the params `{"m": {}}`, `key` "a" and `tests` `[{"v": 1, "key": "b"}]`, `count of tests.v that equals $params.m named by pr.key named by key is 0` fails as `absent` with `item 1 of tests: v: $params.m named by pr.key named by key is missing` in `ergo.rego`, and as `not_an_object` with `$params.m named by pr.key is missing; item 1 of tests: v is 1, which isn't an object` in the Rust engine. [problems.all_said](semantics.md#which-problems-a-message-says) says every problem and the worst cause, so the Rust engine is right. Since #960. The step that fixes it reads the root before any item in `ergo.rego`'s `that` too. - **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 sum of a root read through the subject's key that finds a value that isn't an object says another message in `ergo.rego` (type 3, [problems.all_said](semantics.md#which-problems-a-message-says)).** With the params `{"m": {"a": 3}}`, `key` "a" and `tests` `[]`, `sum of v of tests whose v equals $params.m named by pr.key named by key is 0` fails as `unusable` in both engines, with `$params.m named by pr.key is 3, which isn't an object` in the Rust engine and `sum of v of tests whose v equals $params.m named by pr.key named by key needs more than 15 digits` in `ergo.rego`, which doesn't name the root. On `main` both engines pass this check, because neither reads the root before an item and the list is empty. Since #960. +- **The root entry of a chain of two keys from the subject, when the first finds a value that isn't an object, has the outcome `absent` in `ergo.rego` and `unusable` in the Rust engine (type 2, [tally.inputs](semantics.md#counts-and-sums-in-sentences)).** With the params `{"m": {"a": 3}}`, `k1` "a", `k2` "b" and `tests` `[]`, `count of tests whose v equals $params.m named by pr.k1 named by pr.k2 named by key is 0` fails as `unusable` with `$params.m named by pr.k1 is 3, which isn't an object` in both engines, and the entry `$params.m named by pr.k1 named by pr.k2 named by key` of `inputs` has the outcome `unusable` in the Rust engine and `absent` in `ergo.rego`. With one key from the subject, both say `unusable`. The case "fails as unusable naming the value the first key finds when it is 3 and tests is empty" is listed in `known_differences`. - **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. The four groups for a root read through the subject's key and then the item's key, with the params' `m` `null`, `{"a": 3}` or `{"a": []}`, and for two keys from the subject with `{"a": 3}`, over an empty list, copy the Rust engine's rows for `inputs` and `failures` in the same way, after the verdict, the cause and the message, which tally.walk and for.roots decide, were the same in both engines. 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. @@ -204,11 +205,13 @@ The spec doesn't settle these yet, because the two engines give different report - **The order of the problems of a count under two `for` lines, when a root fails an item of each list, in `ergo.rego` ([problems.item_order](semantics.md#which-problems-a-message-says)) (type 3).** With `ys` holding `[{"rv": "s"}, {"rv": 1}]`, `xs` holding `[{"n": 3}]` and `zw` holding `[{"k": 1}, {"v": 2}]`, `for: every ys as y, every xs as x` with `count of zw whose k is in y.rv is at most 5` says `item 1 of ys: y.rv is "s", which isn't a list; item 1 of ys: item 2 of zw: k is missing; item 2 of ys: y.rv is 1, which isn't a list; item 2 of ys: item 2 of zw: k is missing` in the Rust engine, and on `main` too. `ergo.rego` says both `y.rv` problems first, then `item 1 of ys: item 2 of zw: k is missing; and 1 more`. The verdict is the same. No case pins it. No step is scheduled yet. - **The `item` prefix and the `message` of an assertion over an empty second list, in `ergo.rego` (type 3, [message.items](semantics.md#messages)).** With `ys` holding `[{}]`, `xs` holding `[]` and `zw` holding `[]`, `for: every ys as y, every xs, if any, as x` with `some zw whose k is at most y.rv exists` fails as `absent` and says `item 1 of ys: y.rv is missing, and zw is []` in the Rust engine, and `item 1 of ys: y.rv is missing; item 1 of ys: zw is []` in `ergo.rego`. With `every zw whose k is at most y.rv, if any, exists` the `assertion` entry's `message` is `item 1 of ys: y.rv is missing` in `ergo.rego` and an empty text in the Rust engine, and the row's message is the same in both. The verdict is the same. No case pins it. No step is scheduled yet. - **The message of a check whose sentence reads a root through the key of an earlier line's alias that isn't text and then the line's alias, over an empty later list (type 3, [for.if_any](semantics.md#for)).** With `ys` `[3]`, `xs` `[]`, `zw` `[{"k": 1}]` and the params `{"m": {"a": {"a": [1]}}}`, `for: every ys as y, every xs, if any, as x` with `count of zw.k that is in $params.m named by y named by x is at most 5` fails as `unusable` in both engines with `item 1 of ys: y is 3, which isn't text`. With `ys` `[null]` both fail as `null` with `item 1 of ys: y is null`, and with `ys` `[{"o": 1}]` as `unusable` with `item 1 of ys: y is {"o": 1}, which isn't text`. The case `sentences` "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" expects the message `the check is false; item 1 of ys: y is 3, which isn't text` and an `assertion` entry that says `the check is false`, which the Rust engine once gave when it took a `named by` key on the right of `is in` as no read of the alias. Both engines now leave that sentence out, as for.if_any says. The case is in `engines/rust/known-failures.txt` and in `known_differences` in `engines/rego/tests/spec_test.rego` until a decision says which message the case pins. No step is scheduled yet. +- **A `that` of a `count of` that reads the line's alias as a `named by` key, after an earlier line's alias, fails in `ergo.rego` over an empty later list with `, if any,` (type 1, [for.roots](semantics.md#for), [for.if_any](semantics.md#for)).** With `ys` `["a"]`, `xs` `[]`, `zw` `[{"k": 1}, 5]` and the params `{"m": {"a": {"a": [1]}}}`, `for: every ys as y, every xs, if any, as x` with `count of zw.k that is in $params.m named by y named by x is at most 5` fails as `not_an_object` with `item 2 of zw is 5, which isn't an object` in `ergo.rego` and passes in the Rust engine, which is right. for.roots says a sentence reads the alias when a path in it starts at the alias "or has a step named by it", so the `that` reads `x` and item 2 of `zw` isn't a root, and for.if_any says a check that reads the alias has nothing to check and is left out on an empty list. With `zw` `[{"k": 1}, {"v": 2}]` `ergo.rego` fails as `absent` with `item 2 of zw: k is missing`, and the same happens with `xs` `[{"v": 2}]` and `every xs whose v is 1, if any, as x`. The `sentences` case "a that of a count of that reads the line's alias as a named by key, after an earlier line's alias, has nothing to check on an empty later list with if any, ..." pins it and is a known failure in `ergo.rego`. No rule decides the `inputs` of its row, so they are copied from the Rust engine, which is right here. The fix in `ergo.rego` is where the roots of the later line are judged, `_for_second_roots`: leave out a root of a `that` that reads the line's alias. +- **A `count of` under a later `for` line whose `whose` can't decide an item says the earlier alias's `named by` key in the Rust engine and not in `ergo.rego` (type 2, [problems.all_said](semantics.md#which-problems-a-message-says)).** With `ys` `[3]`, `xs` `[{"w": 1}]`, `zw` `[{"k": 1}]` and the params `{"m": {"a": {"a": [1]}}}`, `for: every ys as y, every xs whose v is 1, if any, as x` with `count of zw.k that is in $params.m named by y named by x is at most 5` fails as `absent` with `item 1 of xs: v is missing` in `ergo.rego`, and as `unusable` with `item 1 of xs: v is missing; item 1 of ys: y is 3, which isn't text` in the Rust engine, which is right. The same goes for `{"v": null}` and for `whose v is in $params.q` with no `q`. +- **The key of an earlier line's alias is said again for each item and path in `ergo.rego` (type 3, [problems.where_said](semantics.md#which-problems-a-message-says)).** With `ys` `[3]`, a later list with items and a counted list with several paths, `ergo.rego` says `item 1 of ys: item 1 of xs: item 1 of zw: k: y is 3, which isn't text` for each item and path, and the Rust engine says it once. +- **An earlier line's alias read as a `named by` key that is `null` gives a different cause in `ergo.rego` (type 2, [problems.all_said](semantics.md#which-problems-a-message-says)).** With `ys` `[null]` and a `count of` that reads `named by y` under a later `for` line, `ergo.rego` fails as `unusable` with a message that starts `the check is false; ` and the Rust engine fails as `null` with `item 1 of ys: y is null`, which is right. - **The line's alias read as a `named by` key that is `null`, in the `whose` of a `count of` under a `for` line (type 2, [for.roots](semantics.md#for), [problems.same_path](semantics.md#which-problems-a-message-says)).** With `xs` `[null]`, `zw` `[{"k": 1}, {"k": 2}]` and the params `{"m": {"a": [1]}}`, `for: every xs as x` with `count of zw whose k is in $params.m named by x is at most 5` fails as `null` with `item 1 of xs: x is null` in the Rust engine, which is right, and as `unusable` with `item 1 of xs: item 1 of zw: $params.m named by x is null; item 1 of xs: item 2 of zw: $params.m named by x is null` in `ergo.rego`, which names the path and not the key, once per item. The step is in the `whose` of a `count of` in `ergo.rego`, which reads the key inside each item. - **The line's alias read as a `named by` key that is missing from `$params`, beside an item of the counted list that isn't an object (type 2, [problems.all_said](semantics.md#which-problems-a-message-says)).** With `xs` `["c"]`, `zw` `[{"k": 1}, 5]` and the params `{"m": {"a": [1]}}`, `for: every xs as x` with `count of zw whose k is in $params.m named by x is at most 5` fails as `absent` with `item 1 of xs: $params.m named by x is missing` in `ergo.rego`, which leaves out item 2 of `zw`. The Rust engine fails as `not_an_object` with `item 1 of xs is "c", which isn't an object`, which leaves out the missing key and names item 2 of `zw` as item 1 of `xs`. With `xs` `["a"]`, where the key is fine, both engines say `item 1 of xs is "a", which isn't an object`, which names `x` and not item 2 of `zw`. The step is in the `whose` of a `count of` under a `for` line, in both engines. -- **A `that` of a `count of` that reads an earlier line's alias as the key and the line's alias only on the right of the comparison passes in the Rust engine over an empty list (type 1, [for.roots](semantics.md#for), [tally.walk](semantics.md#counts-and-sums-in-sentences)).** With `ys` `["a"]`, `xs` `[]`, `zw` `[{"k": 1}, 5]` and the params `{"m": {"a": [1]}}`, `for: every ys as y, every xs, if any, as x` with `count of zw.k that is in $params.m named by y is at most x.n` fails as `not_an_object` in `ergo.rego`, because item 2 of `zw` isn't an object, and passes in the Rust engine. The `that` reads `y`, an alias of an earlier line, so it reads no alias of the line `x`, and for.roots says the item it can't decide fails the check. Rust is the engine that is wrong. Case: `sentences` "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", in `engines/rust/known-failures.txt`. The step is in the Rust engine, which takes a key from an earlier line's alias as a read of an alias that depends on the item. -- **A `whose` of a later `for` line that leaves no item doesn't make `ergo.rego` read an earlier line's alias as a `named by` key (type 1, [for.pass](semantics.md#for), [for.if_any](semantics.md#for), [for.roots](semantics.md#for)).** for.pass says an item whose key fails the check "even when nothing is checked for it because the second list is empty with `, if any,` or its `whose` leaves nothing", and for.if_any treats a `whose` that leaves no item like an empty list. With `ys` `[3]`, `xs` `[{"v": 2}]`, `zw` `[{"k": 1}]` and the params `{"m": {"a": {"a": [1]}}}`, `for: every ys as y, every xs whose v is 1, if any, as x` with `count of zw.k that is in $params.m named by y named by x is at most 5` passes in `ergo.rego` and fails as `unusable` with `item 1 of ys: y is 3, which isn't text` in the Rust engine, which is right. With `ys` `[null]` the Rust engine fails as `null` with `item 1 of ys: y is null`, and with `[{"o": 1}]` as `unusable`; `ergo.rego` passes them. The same goes for the `count of zw whose …` form and for `some ys as y` as the first line. On `main` too. Cases: `for` "an earlier line's alias read as a named by key that isn't text, under a second for line with if any whose whose leaves no item, fails the check, as with no item in the list" (three cases), in `known_differences` in `engines/rego/tests/spec_test.rego`. The step is in `ergo.rego`, in `_for_second_keyed` and `_for_second_roots` (`engines/rego/src/lines/for_lines.rego`), where the later line's keys are said when its `whose` leaves no item. A later fix. -- **The message of a `count of` whose `that` reads an earlier line's alias as the key, over an empty later list, in `ergo.rego` (type 3, [problems.all_said](semantics.md#which-problems-a-message-says)).** With `ys` `["a"]`, `xs` `[]`, `zw` `[{"k": 1}, 5]` and the params `{"m": {"a": [1]}}`, `for: every ys as y, every xs, if any, as x` with `count of zw.k that is in $params.m named by y is at most x.n` fails as `not_an_object` with `item 1 of ys: item 2 of zw is 5, which isn't an object` in `ergo.rego`. The case `sentences` "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" also expects `item 1 of ys: the check is false`, which `ergo.rego` said when it couldn't read `$params.m named by y` through the alias. The root reads `[1]`, so no rule gives that part. The verdict and cause are the same. The case is in `known_differences` in `engines/rego/tests/spec_test.rego` until a decision says which message the case pins. +- **The message of a `count of` whose `that` reads an earlier line's alias as the key, over an empty later list (type 3, [problems.all_said](semantics.md#which-problems-a-message-says)).** With `ys` `["a"]`, `xs` `[]`, `zw` `[{"k": 1}, 5]` and the params `{"m": {"a": [1]}}`, `for: every ys as y, every xs, if any, as x` with `count of zw.k that is in $params.m named by y is at most x.n` fails as `not_an_object` with `item 1 of ys: item 2 of zw is 5, which isn't an object` in both engines. The case `sentences` "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" also expects `item 1 of ys: the check is false`, which `ergo.rego` said when it couldn't read `$params.m named by y` through the alias. The root reads `[1]`, so no rule gives that part. The verdict and cause are the same. The case is in `known_differences` in `engines/rego/tests/spec_test.rego` and in `engines/rust/known-failures.txt` until a decision says which message the case pins. - **The cause of a `for` row whose `sum of … that` compares with a root that is missing or `null`, beside an item it can't add (type 2).** With the params `{"zw": [{"k": 1}, {"k": "z"}]}`, no `rv` in the input and `xs` holding one item, `for: every xs as x` with `sum of $params.zw.k that is $input.rv is at most x.n` fails as `unusable` with `item 2 of $params.zw: k is "z", which isn't a number; $input.rv is missing` in `ergo.rego`, and as `absent` with `$input.rv is missing` in the Rust engine. With `rv` `null` the Rust engine fails as `null`. The sentence alone says only the root, with that cause, in both engines, and [problems.same_path](semantics.md#which-problems-a-message-says) says a path gives the same outcome in every sentence. No case pins it. On `main` too. The step is in `ergo.rego`'s roots of a `for` sentence (`lines/roots.rego`), which should say what the sentence says alone. - **The cause of a count whose `whose` reads a list root of the wrong type with `is in` or `is not in`, beside an item that isn't an object, in `ergo.rego` (type 2, [problems.all_said](semantics.md#which-problems-a-message-says)).** With the params `{"l": "s"}` and `zw` holding `[{"k": 1}, 3]`, `count of zw whose k is in $params.l is at most 5` fails as `unusable` in `ergo.rego` though it says `$params.l is "s", which isn't a list; item 2 of zw is 3, which isn't an object`, and with `is not in` it fails as `unusable` and leaves the item out. The Rust engine says both and fails as `not_an_object` both times, as `is at least $params.l` does in both engines. The rule says "The row's cause MUST be the worst cause of all of them", so the Rust engine is right. The same shows under a `for` line, like `count of member of y.zm whose k is not in pa.m named by $params.key is at most x.n` under `for: every ys as y, every xs, if any, as x`. On `main` too. No case pins it. The step is in `ergo.rego`'s cause of a `whose` with a broken list on the right (`_tally_cond_cause` in `checks/derived.rego`), which takes that flaw for every item and never reads the item. - **The root before a `named by` key the counted item holds, beside the items a count's `whose` can't decide, under a `for` line (type 3, [for.roots](semantics.md#for)).** With the params `{"m": null}`, `zw` holding `[{"k": 1}, 3]` and `xs` `[]`, `for: every xs, if any, as x` with `count of zw whose k is in $params.m named by key is at most x.n` fails as `not_an_object` in both engines, and says `$params.m is null; item 1 of zw: key is missing; item 2 of zw is 3, which isn't an object` in `ergo.rego`, as the count says it alone, and puts `$params.m is null` last in the Rust engine, which puts the root after the items whenever its cause is milder than theirs, like `$params.m is missing` beside an item that isn't an object. With two items of `xs`, `ergo.rego` then says `item 1 of xs: $params.m is null; item 2 of xs: $params.m is null; and 1 more` again after them, and with `$params.m` `"s"` and one item of `xs` it says `item 1 of xs: $params.m is "s", which isn't an object` after them. Under `for: every ws as w, every xs, if any, as x`, `count of w.zw whose k is in $params.m named by key is at most x.n` says `item 1 of ws: $params.m is "s", which isn't an object` in `ergo.rego` and no item in front in the Rust engine. For an item without the key on an empty list, like `zw` `[{"k": 1}]`, neither engine puts an `item` entry under the assertion, which [row.parts](semantics.md#what-a-row-shows) asks for, and the Rust engine lists `zw` on it. for.roots says the count says it "as it does alone, once, with no item of the line in front". No case pins these. The steps: the Rust engine says the root and the items as one count, in `undecided_count_clauses` in `ops/for_line.rs`, and `ergo.rego` leaves the root out of each item of the line once it said it (`lines/roots.rego`). @@ -233,12 +236,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. +- **The `inputs` of the `field_of` tally cases of #909 list fewer entries than the rules say (type 2, [tally.inputs](semantics.md#counts-and-sums-in-sentences), [for.inputs](semantics.md#for)).** The rows of "a tally of a field with a dot in front of a list with a whose, named like a for alias, reads the field of each kept item and not the alias" and "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" leave out entries that tally.inputs names, so they stay in `known_differences` and in `engines/rust/known-failures.txt` even where the verdict, the cause and the message are right. The step: write the rows whole from tally.inputs and for.inputs, and then each engine follows them. +- **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/field_of/cases.json b/spec/cases/field_of/cases.json index 2f1fc8894..c306f3d80 100644 --- a/spec/cases/field_of/cases.json +++ b/spec/cases/field_of/cases.json @@ -5401,15 +5401,6 @@ "cause": "satisfied", "check": "c", "inputs": [ - { - "locations": [ - "/builds/0/envs/0" - ], - "name": "e of tests whose kind is \"unit\"", - "value": [ - "passed" - ] - }, { "locations": [ "/builds/0/envs/0" @@ -18777,15 +18768,6 @@ "cause": "satisfied", "check": "c", "inputs": [ - { - "locations": [ - "/builds/0/envs/0/sha" - ], - "name": "commits.sha of prs whose state is \"merged\"", - "value": [ - "ok" - ] - }, { "locations": [ "/builds/0/envs/0" diff --git a/spec/cases/sentences/cases.json b/spec/cases/sentences/cases.json index e5d990002..e0d977b85 100644 --- a/spec/cases/sentences/cases.json +++ b/spec/cases/sentences/cases.json @@ -107336,5 +107336,835 @@ }, {"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": "passes 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": "satisfied", "check": "c", "inputs": [{"locations": [], "name": "xs[]", "value": []}, {"locations": ["/ts/0/ys/0"], "name": "ys[]", "value": ["a"]}, {"locations": ["/ts/0/zw/0/k", "/ts/0/zw/1"], "name": "zw[].k", "value": [1, null]}], "passed": true, "requirement": "r", "subject": {"id": "t", "type": "t"}}], "rules": ["for.roots", "for.if_any"]}, {"description": "passes on an empty xs with if any when item 2 of zw has no k", "input": {"ts": [{"id": "t", "xs": [], "ys": ["a"], "zw": [{"k": 1}, {"v": 2}]}]}, "results": [{"cause": "satisfied", "check": "c", "inputs": [{"locations": [], "name": "xs[]", "value": []}, {"locations": ["/ts/0/ys/0"], "name": "ys[]", "value": ["a"]}, {"locations": ["/ts/0/zw/0/k", "/ts/0/zw/1"], "name": "zw[].k", "value": [1, null]}], "passed": true, "requirement": "r", "subject": {"id": "t", "type": "t"}}], "rules": ["for.roots", "for.if_any"]}], "description": "a that of a count of that reads the line's alias as a named by key, after an earlier line's alias, has nothing to check on an empty later list with if any, so it passes whatever the items of the counted list are", "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 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" + } + } + } + }, + { + "cases": [ + { + "description": "fails as null naming the root when the params' m is null and tests is empty", + "input": { + "prs": [ + { + "id": "p", + "key": "a", + "tests": [] + } + ] + }, + "results": [ + { + "cause": "null", + "check": "count", + "failures": [ + { + "cause": "null", + "failures": [], + "inputs": [ + { + "locations": [], + "name": "count of tests whose v equals $params.m named by pr.key named by key", + "value": null + }, + { + "locations": [ + "$params:/m" + ], + "name": "$params.m named by pr.key named by key", + "outcome": "null", + "value": null + }, + { + "locations": [ + "/prs/0/key" + ], + "name": "key", + "outcome": "usable", + "value": "a" + } + ], + "kind": "assertion", + "locations": [ + "$policy:/requirements/r/checks/count" + ], + "message": "$params.m is null", + "name": "count of tests whose v equals $params.m named by pr.key named by key is 0" + } + ], + "inputs": [ + { + "locations": [], + "name": "count of tests whose v equals $params.m named by pr.key named by key", + "value": null + }, + { + "locations": [], + "name": "tests[]", + "outcome": "usable", + "value": [] + }, + { + "locations": [ + "$params:/m" + ], + "name": "$params.m named by pr.key named by key", + "outcome": "null", + "value": null + }, + { + "locations": [ + "/prs/0/key" + ], + "name": "key", + "outcome": "usable", + "value": "a" + } + ], + "message": "$params.m is null", + "passed": false, + "requirement": "r", + "subject": { + "id": "p", + "type": "pr" + } + } + ], + "rules": [ + "tally.walk", + "sentence.path.subject.step", + "path.field_step" + ] + } + ], + "description": "a root from $params that is null, read through a named by key from the subject and then the item's key, fails the check on an empty list too", + "params": { + "m": null + }, + "policy": { + "ergo_spec": "{{spec}}", + "requirements": { + "r": { + "checks": { + "count": "count of tests whose v equals $params.m named by pr.key named by key is 0" + }, + "min_subjects": 0, + "subject": "pr" + } + }, + "subjects": { + "pr": { + "from": "prs", + "identified_by": "id" + } + } + } + }, + { + "cases": [ + { + "description": "fails as unusable naming the value the subject's key finds when it is 3 and tests is empty", + "input": { + "prs": [ + { + "id": "p", + "key": "a", + "tests": [] + } + ] + }, + "results": [ + { + "cause": "unusable", + "check": "count", + "failures": [ + { + "cause": "unusable", + "failures": [], + "inputs": [ + { + "locations": [], + "name": "count of tests whose v equals $params.m named by pr.key named by key", + "value": null + }, + { + "locations": [ + "$params:/m/a" + ], + "name": "$params.m named by pr.key named by key", + "outcome": "unusable", + "value": null + }, + { + "locations": [ + "/prs/0/key" + ], + "name": "key", + "outcome": "usable", + "value": "a" + } + ], + "kind": "assertion", + "locations": [ + "$policy:/requirements/r/checks/count" + ], + "message": "$params.m named by pr.key is 3, which isn't an object", + "name": "count of tests whose v equals $params.m named by pr.key named by key is 0" + } + ], + "inputs": [ + { + "locations": [], + "name": "count of tests whose v equals $params.m named by pr.key named by key", + "value": null + }, + { + "locations": [], + "name": "tests[]", + "outcome": "usable", + "value": [] + }, + { + "locations": [ + "$params:/m/a" + ], + "name": "$params.m named by pr.key named by key", + "outcome": "unusable", + "value": null + }, + { + "locations": [ + "/prs/0/key" + ], + "name": "key", + "outcome": "usable", + "value": "a" + } + ], + "message": "$params.m named by pr.key is 3, which isn't an object", + "passed": false, + "requirement": "r", + "subject": { + "id": "p", + "type": "pr" + } + } + ], + "rules": [ + "tally.walk", + "sentence.path.subject.step", + "path.field_step" + ] + } + ], + "description": "a root from $params read through a named by key from the subject that finds a value that isn't an object, and then the item's key, fails the check on an empty list too", + "params": { + "m": { + "a": 3 + } + }, + "policy": { + "ergo_spec": "{{spec}}", + "requirements": { + "r": { + "checks": { + "count": "count of tests whose v equals $params.m named by pr.key named by key is 0" + }, + "min_subjects": 0, + "subject": "pr" + } + }, + "subjects": { + "pr": { + "from": "prs", + "identified_by": "id" + } + } + } + }, + { + "cases": [ + { + "description": "fails as unusable naming the value the subject's key finds when it is an empty list and tests is empty", + "input": { + "prs": [ + { + "id": "p", + "key": "a", + "tests": [] + } + ] + }, + "results": [ + { + "cause": "unusable", + "check": "count", + "failures": [ + { + "cause": "unusable", + "failures": [], + "inputs": [ + { + "locations": [], + "name": "count of tests whose v equals $params.m named by pr.key named by key", + "value": null + }, + { + "locations": [ + "$params:/m/a" + ], + "name": "$params.m named by pr.key named by key", + "outcome": "unusable", + "value": null + }, + { + "locations": [ + "/prs/0/key" + ], + "name": "key", + "outcome": "usable", + "value": "a" + } + ], + "kind": "assertion", + "locations": [ + "$policy:/requirements/r/checks/count" + ], + "message": "$params.m named by pr.key is [], which isn't an object", + "name": "count of tests whose v equals $params.m named by pr.key named by key is 0" + } + ], + "inputs": [ + { + "locations": [], + "name": "count of tests whose v equals $params.m named by pr.key named by key", + "value": null + }, + { + "locations": [], + "name": "tests[]", + "outcome": "usable", + "value": [] + }, + { + "locations": [ + "$params:/m/a" + ], + "name": "$params.m named by pr.key named by key", + "outcome": "unusable", + "value": null + }, + { + "locations": [ + "/prs/0/key" + ], + "name": "key", + "outcome": "usable", + "value": "a" + } + ], + "message": "$params.m named by pr.key is [], which isn't an object", + "passed": false, + "requirement": "r", + "subject": { + "id": "p", + "type": "pr" + } + } + ], + "rules": [ + "tally.walk", + "sentence.path.subject.step", + "path.field_step" + ] + } + ], + "description": "a root from $params read through a named by key from the subject that finds a list, and then the item's key, fails the check on an empty list too", + "params": { + "m": { + "a": [] + } + }, + "policy": { + "ergo_spec": "{{spec}}", + "requirements": { + "r": { + "checks": { + "count": "count of tests whose v equals $params.m named by pr.key named by key is 0" + }, + "min_subjects": 0, + "subject": "pr" + } + }, + "subjects": { + "pr": { + "from": "prs", + "identified_by": "id" + } + } + } + }, + { + "cases": [ + { + "description": "fails as unusable naming the value the first key finds when it is 3 and tests is empty", + "input": { + "prs": [ + { + "id": "p", + "k1": "a", + "k2": "b", + "tests": [] + } + ] + }, + "results": [ + { + "cause": "unusable", + "check": "count", + "failures": [ + { + "cause": "unusable", + "failures": [], + "inputs": [ + { + "locations": [], + "name": "count of tests whose v equals $params.m named by pr.k1 named by pr.k2 named by key", + "value": null + }, + { + "locations": [ + "$params:/m/a" + ], + "name": "$params.m named by pr.k1 named by pr.k2 named by key", + "outcome": "unusable", + "value": null + }, + { + "locations": [ + "/prs/0/k1" + ], + "name": "k1", + "outcome": "usable", + "value": "a" + }, + { + "locations": [ + "/prs/0/k2" + ], + "name": "k2", + "outcome": "usable", + "value": "b" + }, + { + "locations": [ + "/prs/0" + ], + "name": "key", + "outcome": "absent", + "value": null + } + ], + "kind": "assertion", + "locations": [ + "$policy:/requirements/r/checks/count" + ], + "message": "$params.m named by pr.k1 is 3, which isn't an object", + "name": "count of tests whose v equals $params.m named by pr.k1 named by pr.k2 named by key is 0" + } + ], + "inputs": [ + { + "locations": [], + "name": "count of tests whose v equals $params.m named by pr.k1 named by pr.k2 named by key", + "value": null + }, + { + "locations": [], + "name": "tests[]", + "outcome": "usable", + "value": [] + }, + { + "locations": [ + "$params:/m/a" + ], + "name": "$params.m named by pr.k1 named by pr.k2 named by key", + "outcome": "unusable", + "value": null + }, + { + "locations": [ + "/prs/0/k1" + ], + "name": "k1", + "outcome": "usable", + "value": "a" + }, + { + "locations": [ + "/prs/0/k2" + ], + "name": "k2", + "outcome": "usable", + "value": "b" + }, + { + "locations": [ + "/prs/0" + ], + "name": "key", + "outcome": "absent", + "value": null + } + ], + "message": "$params.m named by pr.k1 is 3, which isn't an object", + "passed": false, + "requirement": "r", + "subject": { + "id": "p", + "type": "pr" + } + } + ], + "rules": [ + "tally.walk", + "sentence.path.subject.step", + "path.field_step" + ] + } + ], + "description": "a root from $params read through two named by keys from the subject and then the item's key fails the check on an empty list too, when the first one finds a value that isn't an object", + "params": { + "m": { + "a": 3 + } + }, + "policy": { + "ergo_spec": "{{spec}}", + "requirements": { + "r": { + "checks": { + "count": "count of tests whose v equals $params.m named by pr.k1 named by pr.k2 named by key is 0" + }, + "min_subjects": 0, + "subject": "pr" + } + }, + "subjects": { + "pr": { + "from": "prs", + "identified_by": "id" + } + } + } + } ]