Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 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
9b96f77
docs: say the Rego engine also reads the item's field in a tally of a…
jbpros Dec 5, 2026
a9b5342
rego: test that each kept item reads the field in front of the list f…
jbpros Dec 5, 2026
75f62ab
rego: read the field in front of a list through one rule that says wh…
jbpros Dec 5, 2026
14e99f9
rego: test that a field in front of a list named like a for alias rea…
jbpros Dec 5, 2026
518570c
rego: mark a field in front of a list named like a for alias as the a…
jbpros Dec 5, 2026
95bd91b
rego: test that each kept item reads the field in front of the list f…
jbpros Dec 5, 2026
6a1313b
rego: read each kept item's field from the for alias when the field i…
jbpros Dec 5, 2026
d5878b0
docs: say ergo.rego reads a field in front of a list named like a 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
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 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's entry of the kept fields holds no value yet, as `spec/OPEN.md` 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.
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
33 changes: 25 additions & 8 deletions engines/rego/src/lines/walk.rego
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)))

Expand Down Expand Up @@ -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
}

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
10 changes: 9 additions & 1 deletion engines/rego/src/sentences/problems.rego
Original file line number Diff line number Diff line change
Expand Up @@ -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))
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