Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 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
8a66412
rego: add a failing test that a one-line walk reads a root through th…
jbpros Dec 5, 2026
697e07e
rego: test the some form without if any, since if any belongs to every
jbpros Dec 5, 2026
ff09e9c
rust: add a failing test that a one-line walk reads a root through th…
jbpros Dec 5, 2026
7b238af
rego: read a root through the item's key before any item in a one-lin…
jbpros Dec 5, 2026
6ab770b
rust: read a root through the item's key before any item in a one-lin…
jbpros Dec 5, 2026
d20d13a
docs: say a one-line every reads a root through the item's key before…
jbpros Dec 5, 2026
6a165b4
spec: drop the two rows that pass from the known differences, and say…
jbpros Dec 5, 2026
1c0b9c1
spec: drop the three more rows that ergo.rego now passes from the kno…
jbpros Dec 5, 2026
4cde282
rego: test that a one-line walk leaves a root a contains reads throug…
jbpros Dec 5, 2026
7d62dda
rego: leave a root a contains reads through the item's key to each it…
jbpros Dec 5, 2026
836df31
rego: test that a root read through the item's key names a list befor…
jbpros Dec 5, 2026
8329928
rego: fail a root read through the item's key when a list sits before…
jbpros Dec 5, 2026
05e0968
rego: test that a one-line walk leaves a root on the value side of an…
jbpros Dec 5, 2026
ed87ca1
rego: read only the left side of a one-line walk's whose through the …
jbpros Dec 5, 2026
010b74e
rust: test that a one-line walk leaves a root on the value side of it…
jbpros Dec 5, 2026
62fe2d0
rust: read only the left side of a one-line walk's whose through the …
jbpros Dec 5, 2026
4b32a0d
spec: record the shared type 1s of a value-side or subject root in a …
jbpros Dec 5, 2026
362da8a
docs: say the one-line walk reads only the left side's root through t…
jbpros Dec 5, 2026
e5e1619
spec: put back the three known differences that the narrowing makes f…
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ This file is about `ergo.rego` only. The Rust engine's changes are in [engines/r

### Fixed

- A one-line `every` or `some` whose `whose` reads a root from `$params` or `$input` through the item's own `named by` key, on the left side of the comparison, reads that root 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 params and `tests` `[]`, `every tests whose $params.m named by key is 1, if any, exists` passed, and now fails as `absent` with `$params.m is missing`, and as `null` or `unusable` when `m` is `null` or `3`. A list before a field, like `m` holding `[]` in `$params.m.d named by key`, fails as `unusable` with `$params.m is [], which isn't an object`. A root on the value side, like `$params.m` in `v is in $params.m named by key`, is read with each item as before.
- 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
30 changes: 19 additions & 11 deletions engines/rego/src/lines/roots.rego
Original file line number Diff line number Diff line change
Expand Up @@ -834,10 +834,14 @@ _walk_root_clauses(check, subj) := _m_said_clauses(_m_said_sorted(_walk_root_sai

_for_root_keys_said(check) := _once([_name_key_said(x) | some c in array.concat(_for_nested_conds(check), _for_line_whose_conds(check)); some x in _root_keys_unread(c)])

_for_keyed_roots_said(check, subj) := [[f.cause, f.text] | some f in _keyed_root_faults(subj, _for_line_whose_conds(check))] if not _unreadable_input
_for_keyed_roots_said(check, subj) := [[f.cause, f.text] | some f in _keyed_root_faults(subj, _keyed_whose_conds(check))] if not _unreadable_input

else := []

_keyed_whose_conds(check) := array.concat(_for_line_whose_conds(check), [_keyed_walk_cond(c) | check.op in _walk_ops; some c in object.get(check, "whose", [])])

_keyed_walk_cond(c) := object.remove(c, ["right"])

_keyed_root_faults(subj, whose) := _once([x[2] | some x in sort([[i, f.text, f] |
some c in whose
some p in _keyed_cond_paths(c)
Expand Down Expand Up @@ -871,6 +875,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,36 +896,29 @@ _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)
not is_object(v)
_keyed_prefix_stops(j, k, v)
}

_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, v) if {
j < k
not is_array(v)
}

_walk_root_said(check, subj) := _once(array.concat(
array.concat(array.concat(_for_root_keys_said(check), _for_keyed_roots_said(check, subj)), [[y[1], y[0]] | some y in sort([[x[1], x[0]] | some c in _walk_count_conds(check); some x in array.concat(_m_root_said_all(subj, c), _m_cond_walked_said(c)); x[0] in _no_value_states; startswith(x[1], "$")])]),
array.concat(
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]}}}
}
}
}
Loading
Loading