From 0dcc1a1a29322a83c481dd225e0ea31198edaa9d Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 02:46:11 +0100 Subject: [PATCH 1/8] rego: test that an earlier line's alias read as a named by key is said when the whose of the later line leaves no item Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/tests/lines/for_lines_test.rego | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/engines/rego/tests/lines/for_lines_test.rego b/engines/rego/tests/lines/for_lines_test.rego index 4cb21bf25..a49079d11 100644 --- a/engines/rego/tests/lines/for_lines_test.rego +++ b/engines/rego/tests/lines/for_lines_test.rego @@ -519,3 +519,19 @@ 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_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]}}} + } + } +} From 6125d4ac17d0ea13c5b947d4f1fba72dc4b1bb68 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 02:52:24 +0100 Subject: [PATCH 2/8] rego: say an earlier line's alias read as a named by key when the whose of the later line leaves no item Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- CHANGELOG.md | 1 + engines/rego/src/lines/for_lines.rego | 10 +++++++++- engines/rego/tests/spec_test.rego | 3 --- spec/OPEN.md | 1 - 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd145ae1c..2747b09c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ 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`. 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`. 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/tests/spec_test.rego b/engines/rego/tests/spec_test.rego index 29fe277a3..719e701ee 100644 --- a/engines/rego/tests/spec_test.rego +++ b/engines/rego/tests/spec_test.rego @@ -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", diff --git a/spec/OPEN.md b/spec/OPEN.md index 7471a0bba..c2c515474 100644 --- a/spec/OPEN.md +++ b/spec/OPEN.md @@ -206,7 +206,6 @@ The spec doesn't settle these yet, because the two engines give different report - **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 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. From 3494063c217818b8fd7ec70107f33a70e65e3295 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 02:54:16 +0100 Subject: [PATCH 3/8] rust: test that a that whose key reads an earlier alias fails the check on an empty later list Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rust/engine/src/ops/for_line/tests.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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"}]); From 562d038d15dfaa009d6abc05d04c804ebc5cfea7 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 02:59:03 +0100 Subject: [PATCH 4/8] rust: fail a that whose key reads an earlier alias that holds no object on an empty later list An item of a count of that the that can't decide was dropped as said by the earlier item, because that item isn't an object, even when the sentence reads the alias only whole, as a key. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rust/engine/src/ops/for_line.rs | 41 ++++++++++++++++++++----- 1 file changed, 34 insertions(+), 7 deletions(-) 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)); } } From 80f19fa97ff65c697b103254207cf865dfd65f2f Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 02:59:35 +0100 Subject: [PATCH 5/8] docs: say the Rust engine fails a that keyed by an earlier alias on an empty later list Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rust/CHANGELOG.md | 1 + spec/OPEN.md | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/engines/rust/CHANGELOG.md b/engines/rust/CHANGELOG.md index 549c10bff..8ac10080f 100644 --- a/engines/rust/CHANGELOG.md +++ b/engines/rust/CHANGELOG.md @@ -35,6 +35,7 @@ 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. 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`. diff --git a/spec/OPEN.md b/spec/OPEN.md index c2c515474..30c48ce57 100644 --- a/spec/OPEN.md +++ b/spec/OPEN.md @@ -205,8 +205,7 @@ The spec doesn't settle these yet, because the two engines give different report - **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. - **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. -- **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`). From e159a21ed9ec3bb75290eb0546a3c410de3f7cfd Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 03:22:13 +0100 Subject: [PATCH 6/8] rego: guard that a that keyed by an earlier alias is left to the items when a later whose fails one condition and leaves another undecided Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/tests/lines/for_lines_test.rego | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/engines/rego/tests/lines/for_lines_test.rego b/engines/rego/tests/lines/for_lines_test.rego index a49079d11..fce98e1f7 100644 --- a/engines/rego/tests/lines/for_lines_test.rego +++ b/engines/rego/tests/lines/for_lines_test.rego @@ -520,6 +520,14 @@ 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"}) From 381e5d6d9ac1ab6cee9dec915ade58e247bc076c Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 03:26:16 +0100 Subject: [PATCH 7/8] spec: add a case for a that keyed by two aliases on an empty later list, which ergo.rego fails and Rust passes Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/tests/spec_test.rego | 2 ++ spec/OPEN.md | 4 ++++ spec/cases/sentences/cases.json | 1 + 3 files changed, 7 insertions(+) diff --git a/engines/rego/tests/spec_test.rego b/engines/rego/tests/spec_test.rego index 719e701ee..9f9fc9d9e 100644 --- a/engines/rego/tests/spec_test.rego +++ b/engines/rego/tests/spec_test.rego @@ -49,6 +49,8 @@ known_differences := { "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/spec/OPEN.md b/spec/OPEN.md index 30c48ce57..569dc43ff 100644 --- a/spec/OPEN.md +++ b/spec/OPEN.md @@ -203,6 +203,10 @@ 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. - **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. diff --git a/spec/cases/sentences/cases.json b/spec/cases/sentences/cases.json index 124526b5b..9b31f8b39 100644 --- a/spec/cases/sentences/cases.json +++ b/spec/cases/sentences/cases.json @@ -107337,6 +107337,7 @@ {"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": "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": [ { From b589336dfa93507e138f78fa5e9b53714b8dca8a Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 03:26:24 +0100 Subject: [PATCH 8/8] docs: say in the changelogs every report change the review found for a that keyed by an earlier alias Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- CHANGELOG.md | 2 +- engines/rust/CHANGELOG.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2747b09c8..086799094 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ 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`. 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`. diff --git a/engines/rust/CHANGELOG.md b/engines/rust/CHANGELOG.md index 8ac10080f..fa0a07570 100644 --- a/engines/rust/CHANGELOG.md +++ b/engines/rust/CHANGELOG.md @@ -35,7 +35,7 @@ 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. 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`.