Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 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
21fcc38
rego: add a failing test that a keyed root is read through the subjec…
jbpros Dec 5, 2026
6bdc270
rego: read a keyed root through the subject's key before any item, so…
jbpros Dec 5, 2026
3df6056
rust: add a failing test that a keyed root is read through the subjec…
jbpros Dec 5, 2026
63b2f05
rust: read a keyed root up to the item's key before any item, so a ro…
jbpros Dec 5, 2026
36c1c08
docs: say in the changelogs that a keyed root is read through the sub…
jbpros Dec 5, 2026
2c4556e
rego: add a failing test that a prefix read through the subject's key…
jbpros Dec 5, 2026
5fe4c50
rego: name a prefix read through the subject's key that isn't an obje…
jbpros Dec 5, 2026
1f98417
rego: drop the unreachable end of a keyed read, since every caller re…
jbpros Dec 5, 2026
40280f9
rust: add a failing test that a step before the item's key that isn't…
jbpros Dec 5, 2026
a6069d9
rust: read each step before the item's key, so one that isn't an obje…
jbpros Dec 5, 2026
47434d2
docs: name every form a keyed root read before any item changes, and …
jbpros Dec 5, 2026
6e502d7
spec: add cases for a root read through the subject's key that isn't …
jbpros Dec 5, 2026
572c62d
rego: list the call of a keyed prefix fault to the message that names…
jbpros Dec 5, 2026
518035d
rust: drop a needless borrow in key_base
jbpros Dec 5, 2026
4e2e256
docs: say what main does for the sum with a wrong-typed prefix
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ This file is about `ergo.rego` only. The Rust engine's changes are in [engines/r

### Fixed

- 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.
Expand Down
1 change: 1 addition & 0 deletions engines/rego/layers-known.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
18 changes: 15 additions & 3 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 All @@ -881,15 +892,15 @@ _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
}

_keyed_prefix_fault(subj, p, j, k) := {"cause": st, "text": _name_key_said([_input_name(_keyed_named(p, j, k, st)), _keyed_state_value[st]])[1]} if {
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)
Expand All @@ -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
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]}}}
}
}
}
58 changes: 58 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,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 [
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
Loading
Loading