Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
11a4c77
rego: test that a root read through the item's key and then a key fro…
jbpros Dec 5, 2026
ee90813
rego: read a root through the item's key before any item whatever key…
jbpros Dec 5, 2026
133137c
rego: test that a key from $params in front of the item's key keeps t…
jbpros Dec 5, 2026
1c0ac52
rego: read a root before any item when a key from $params sits in fro…
jbpros Dec 5, 2026
6213dda
rust: test that a root read through a key from $params and then the i…
jbpros Dec 5, 2026
b264611
rust: read a root before any item when a key from $params sits in fro…
jbpros Dec 5, 2026
9861717
docs: list the fixes and keep the inputs the two engines leave out in…
jbpros Dec 5, 2026
9e032c1
rego: test that a bound line alias in front of the item's key reads t…
jbpros Dec 5, 2026
e776f69
rego: read a root before any item through a bound line alias in front…
jbpros Dec 5, 2026
dd9ccd9
rust: test that a root read through the item's key and then an unboun…
jbpros Dec 5, 2026
99810a3
rust: read no root before any item when a later key reads an unbound …
jbpros Dec 5, 2026
99e0c1b
test the causes of a root read through a key from $params and the ite…
jbpros Dec 5, 2026
7ce5848
docs: record the line alias forms in the changelogs and reword the in…
jbpros Dec 5, 2026
3fbe8cc
spec: add cases for a root read through the line alias and the item's…
jbpros Dec 5, 2026
a1ca8b9
docs: say the cases for the line alias and the item's key copy the Ru…
jbpros Dec 5, 2026
5c616b4
rego: test that an earlier line's alias read as a named by key is sai…
jbpros Dec 5, 2026
746112e
rego: say an earlier line's alias read as a named by key when the who…
jbpros Dec 5, 2026
fbcbd4f
rust: test that a that whose key reads an earlier alias fails the che…
jbpros Dec 5, 2026
f8eff71
rust: fail a that whose key reads an earlier alias that holds no obje…
jbpros Dec 5, 2026
ad930d2
docs: say the Rust engine fails a that keyed by an earlier alias on a…
jbpros Dec 5, 2026
5136946
rego: guard that a that keyed by an earlier alias is left to the item…
jbpros Dec 5, 2026
bf37c69
spec: add a case for a that keyed by two aliases on an empty later li…
jbpros Dec 5, 2026
50aa158
docs: say in the changelogs every report change the review found for …
jbpros Dec 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ This file is about `ergo.rego` only. The Rust engine's changes are in [engines/r

### Fixed

- 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.
Expand Down
10 changes: 9 additions & 1 deletion engines/rego/src/lines/for_lines.rego
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions engines/rego/src/lines/roots.rego
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions engines/rego/src/messages/walks.rego
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
24 changes: 24 additions & 0 deletions engines/rego/tests/lines/for_lines_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -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]}}}
}
}
}
37 changes: 37 additions & 0 deletions engines/rego/tests/lines/roots_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,43 @@ test_keyed_root_fault_names_a_missing_root_from_input_or_params_by_its_whole_pat
ergo._keyed_root_fault({}, ["$$input", "d", "m", {"named_by_field": "key"}]) == {"cause": "null", "text": "$input.d is null"} with data.ergo_document as {"d": null}
}

test_a_key_from_params_in_front_of_the_items_key_keeps_the_root_read_before_any_item if {
pr := {"key": "a", "tests": []}
every p in [
["$$params", "m", {"ref": ["$$params", "k"]}, {"named_by_field": "key"}],
["$$params", "m", {"ref": ["$$params", "k"]}, {"named_by_field": "\u0003pr\u0003key"}, {"named_by_field": "key"}],
["$$params", "m", {"named_by_field": "\u0003pr\u0003key"}, {"ref": ["$$params", "k"]}, {"named_by_field": "key"}],
] {
ergo._keyed_root_path(p) with input as {"ergo/names": {"ergo/subject": pr}} with data.ergo_params as {"k": "a"}
ergo._keyed_root_fault(pr, p) == {"cause": "absent", "text": "$params.m is missing"} with input as {"ergo/names": {"ergo/subject": pr}} with data.ergo_params as {"k": "a"}
}
}

test_a_bound_line_alias_in_front_of_the_items_key_reads_the_root_before_any_item_of_the_walked_list if {
pr := {"key": "a", "tests": []}
every p in [
["$$params", "m", {"named_by": "x"}, {"named_by_field": "key"}],
["$$params", "m", {"named_by": "x"}, {"ref": ["$$params", "k"]}, {"named_by_field": "key"}],
["$$params", "m", {"ref": ["$$params", "k"]}, {"named_by": "x"}, {"named_by_field": "key"}],
] {
ergo._keyed_root_path(p) with input as {"ergo/names": {"ergo/subject": pr, "x": "a"}} with data.ergo_params as {"k": "a"}
ergo._keyed_root_fault(pr, p) == {"cause": "absent", "text": "$params.m is missing"} with input as {"ergo/names": {"ergo/subject": pr, "x": "a"}} with data.ergo_params as {"k": "a"}
not ergo._keyed_root_path(p) with input as {"ergo/names": {"ergo/subject": pr}} with data.ergo_params as {"k": "a"}
}
}

test_a_root_read_through_a_key_from_params_and_the_items_key_takes_the_roots_cause_and_leaves_a_key_that_cant_be_read_to_the_key if {
pr := {"key": "a", "tests": []}
p := ["$$params", "m", {"ref": ["$$params", "k"]}, {"named_by_field": "key"}]
names := {"ergo/names": {"ergo/subject": pr}}
ergo._keyed_root_fault(pr, p) == {"cause": "null", "text": "$params.m is null"} with input as names with data.ergo_params as {"k": "a", "m": null}
ergo._keyed_root_fault(pr, p) == {"cause": "unusable", "text": "$params.m is 3, which isn't an object"} with input as names with data.ergo_params as {"k": "a", "m": 3}
ergo._keyed_root_fault(pr, p) == {"cause": "absent", "text": "$params.m is missing"} with input as names with data.ergo_params as {"k": ""}
every params in [{}, {"k": null}, {"k": 3}] {
not ergo._keyed_root_path(p) with input as names with data.ergo_params as params
}
}

test_a_root_read_through_two_subject_keys_that_both_fail_takes_the_worst_cause if {
p := ["$$params", "m", {"named_by_field": "\u0003pr\u0003key"}, {"named_by_field": "\u0003pr\u0003j"}]
every row in [
Expand Down
8 changes: 8 additions & 0 deletions engines/rego/tests/messages/walks_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 2 additions & 4 deletions engines/rego/tests/spec_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,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",
Expand All @@ -45,14 +42,15 @@ known_differences := {
"sentences / a root from $input or the subject itself read through a named by key from the subject, in a count of or a sum of over items, is said once on the assertion, and each item the clause can't read is said after it / puts the root on the assertion and gives an item entry only to the item the clause can't read",
"sentences / a root from $params read through a named by key from $params and then the item's key is read once, before any item, so a root it doesn't have fails the check on an empty list too / fails as absent naming the root when the params have no m and tests is empty",
"sentences / a root from $params read through a named by key from the subject and then the item's key is read once, before any item, so a root that has no key for the subject's key fails the check on an empty list too / fails as absent naming the root through the subject's key when the params' m has no such key and tests is empty",
"sentences / a root from $params read through the item's key and then a named by key from $params is read once, before any item, so a root it doesn't have fails the check on an empty list too / fails as absent naming the root when the params have no m and tests is empty",
"sentences / a root from $params read through the item's own key, in a one-line every with if any, is not an object, so it fails as unusable on an empty list / fails as unusable naming $params.m when tests is empty",
"sentences / a root from $params read through the item's own key, in a one-line every with if any, is null, so it fails as null on an empty list / fails as null naming $params.m when tests is empty",
"sentences / a root read through the item's own key, in a one-line every with if any, is read once, before any item, so it fails on an empty list when it is missing, null or not an object / fails as absent naming $params.m and $input.m when neither is there and tests is empty",
"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",
}

Expand Down
2 changes: 2 additions & 0 deletions engines/rust/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Each release names the version of the spec it follows. The spec's own changes ar

### Fixed

- 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.
Expand Down
Loading
Loading