From 11a4c77ec07093ddebadeae33a88a9b509c84aed Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 01:05:05 +0100 Subject: [PATCH 01/57] rego: test that a root read through the item's key and then a key from $params is read before any item Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/tests/messages/walks_test.rego | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/engines/rego/tests/messages/walks_test.rego b/engines/rego/tests/messages/walks_test.rego index ef4d20ab8..8b3813e10 100644 --- a/engines/rego/tests/messages/walks_test.rego +++ b/engines/rego/tests/messages/walks_test.rego @@ -113,6 +113,14 @@ test_a_root_read_through_the_items_key_in_a_whose_is_read_before_any_item_whatev } } +test_a_root_read_through_the_items_key_and_then_a_key_from_params_is_read_before_any_item if { + c := {"op": "compare", "cmp": "eq", "left": ["v"], "right": ["$$params", "m", {"named_by_field": "key"}, {"ref": ["$$params", "k"]}]} + every pair in [[{"k": "a"}, {"cause": "absent", "text": "$params.m is missing"}], [{"k": "a", "m": null}, {"cause": "null", "text": "$params.m is null"}], [{"k": "a", "m": 3}, {"cause": "unusable", "text": "$params.m is 3, which isn't an object"}]] { + ergo._m_tally_keyed_base({"tests": []}, {"count_of": ["tests"], "whose": [c]}).faults == [pair[1]] with data.ergo_params as pair[0] + } + not ergo._m_tally_keyed_base({"tests": []}, {"count_of": ["tests"], "whose": [c]}) with data.ergo_params as {"k": "a", "m": {}} +} + test_a_count_shows_every_item_it_cant_read_whatever_its_cause_but_not_a_root_or_a_params_item_of_another_cause if { item := {"item": {"i": ["xs", 0]}} ergo._m_record_shown(["absent", "item 1 of xs: v is missing", item], "unusable") From ee908130a21cc6efc4e656c4ac4f6c81b5cc4c8a Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 01:06:45 +0100 Subject: [PATCH 02/57] rego: read a root through the item's key before any item whatever key comes after it Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/src/messages/walks.rego | 5 ----- engines/rego/tests/spec_test.rego | 1 - 2 files changed, 6 deletions(-) diff --git a/engines/rego/src/messages/walks.rego b/engines/rego/src/messages/walks.rego index 44c801548..ebbfcb5e1 100644 --- a/engines/rego/src/messages/walks.rego +++ b/engines/rego/src/messages/walks.rego @@ -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) } diff --git a/engines/rego/tests/spec_test.rego b/engines/rego/tests/spec_test.rego index 32a920d72..29fe277a3 100644 --- a/engines/rego/tests/spec_test.rego +++ b/engines/rego/tests/spec_test.rego @@ -45,7 +45,6 @@ known_differences := { "sentences / a root from $input or the subject itself read through a named by key from the subject, in a count of or a sum of over items, is said once on the assertion, and each item the clause can't read is said after it / puts the root on the assertion and gives an item entry only to the item the clause can't read", "sentences / a root from $params read through a named by key from $params and then the item's key is read once, before any item, so a root it doesn't have fails the check on an empty list too / fails as absent naming the root when the params have no m and tests is empty", "sentences / a root from $params read through a named by key from the subject and then the item's key is read once, before any item, so a root that has no key for the subject's key fails the check on an empty list too / fails as absent naming the root through the subject's key when the params' m has no such key and tests is empty", - "sentences / a root from $params read through the item's key and then a named by key from $params is read once, before any item, so a root it doesn't have fails the check on an empty list too / fails as absent naming the root when the params have no m and tests is empty", "sentences / a root from $params read through the item's own key, in a one-line every with if any, is not an object, so it fails as unusable on an empty list / fails as unusable naming $params.m when tests is empty", "sentences / a root from $params read through the item's own key, in a one-line every with if any, is null, so it fails as null on an empty list / fails as null naming $params.m when tests is empty", "sentences / a root read through the item's own key, in a one-line every with if any, is read once, before any item, so it fails on an empty list when it is missing, null or not an object / fails as absent naming $params.m and $input.m when neither is there and tests is empty", From 133137c37e0cc8b02e4b865b42999703c4f68f11 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 01:07:27 +0100 Subject: [PATCH 03/57] rego: test that a key from $params in front of the item's key keeps the root read before any item Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/tests/lines/roots_test.rego | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/engines/rego/tests/lines/roots_test.rego b/engines/rego/tests/lines/roots_test.rego index c643abc00..e836b2c20 100644 --- a/engines/rego/tests/lines/roots_test.rego +++ b/engines/rego/tests/lines/roots_test.rego @@ -793,6 +793,18 @@ test_keyed_root_fault_names_a_missing_root_from_input_or_params_by_its_whole_pat ergo._keyed_root_fault({}, ["$$input", "d", "m", {"named_by_field": "key"}]) == {"cause": "null", "text": "$input.d is null"} with data.ergo_document as {"d": null} } +test_a_key_from_params_in_front_of_the_items_key_keeps_the_root_read_before_any_item if { + pr := {"key": "a", "tests": []} + every p in [ + ["$$params", "m", {"ref": ["$$params", "k"]}, {"named_by_field": "key"}], + ["$$params", "m", {"ref": ["$$params", "k"]}, {"named_by_field": "\u0003pr\u0003key"}, {"named_by_field": "key"}], + ["$$params", "m", {"named_by_field": "\u0003pr\u0003key"}, {"ref": ["$$params", "k"]}, {"named_by_field": "key"}], + ] { + ergo._keyed_root_path(p) with input as {"ergo/names": {"ergo/subject": pr}} with data.ergo_params as {"k": "a"} + ergo._keyed_root_fault(pr, p) == {"cause": "absent", "text": "$params.m is missing"} with input as {"ergo/names": {"ergo/subject": pr}} with data.ergo_params as {"k": "a"} + } +} + test_a_root_read_through_two_subject_keys_that_both_fail_takes_the_worst_cause if { p := ["$$params", "m", {"named_by_field": "\u0003pr\u0003key"}, {"named_by_field": "\u0003pr\u0003j"}] every row in [ From 1c0ac52b27970fe8788eb45e8078bb081ba91fac Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 01:08:59 +0100 Subject: [PATCH 04/57] rego: read a root before any item when a key from $params sits in front of the item's key Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/src/lines/roots.rego | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/engines/rego/src/lines/roots.rego b/engines/rego/src/lines/roots.rego index 564091668..c73b851bd 100644 --- a/engines/rego/src/lines/roots.rego +++ b/engines/rego/src/lines/roots.rego @@ -871,6 +871,12 @@ _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_plain_end(p) := min({i | some i, step in p; i > 0; not is_string(step)}) _keyed_off_start(p) if _part_start(p) From 6213dda4e04c6df637a85d3b5123b3f82eaa201e Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 01:10:23 +0100 Subject: [PATCH 05/57] rust: test that a root read through a key from $params and then the item's key has its base read before any item Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rust/engine/src/ops/key_base/tests.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/engines/rust/engine/src/ops/key_base/tests.rs b/engines/rust/engine/src/ops/key_base/tests.rs index 067dba5f3..2e2d4f330 100644 --- a/engines/rust/engine/src/ops/key_base/tests.rs +++ b/engines/rust/engine/src/ops/key_base/tests.rs @@ -688,3 +688,22 @@ fn a_counted_item_clause_is_kept_even_when_its_text_is_a_base_problem() { "w is 2; o is 5, which isn't an object; o is 5, which isn't an object; $params.k is missing" ); } + +#[test] +fn a_root_read_through_a_key_from_params_and_then_the_items_key_has_its_base_read_before_any_item() +{ + let subject = json!({"tests": []}); + let mut path = keyed(Start::Params, &["m"], "k"); + path.steps.push(Step::Field(Box::new(Path { + start: Start::Own, + steps: vec![Step::Key("key".to_string())], + }))); + let params = json!({"k": "a"}); + let (name, text, cause) = base_of(&path, true, &ctx(&subject, ¶ms, &[])).unwrap(); + assert_eq!( + (name.as_str(), text.as_str(), cause), + ("$params.m", "$params.m is missing", Cause::Absent) + ); + let params = json!({"k": "a", "m": {}}); + assert!(base_of(&path, true, &ctx(&subject, ¶ms, &[])).is_none()); +} From b264611fd3ef8e291645b9f71fe4fbd8bd324f66 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 01:11:40 +0100 Subject: [PATCH 06/57] rust: read a root before any item when a key from $params sits in front of the item's key Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rust/engine/src/ops/key_base.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/engines/rust/engine/src/ops/key_base.rs b/engines/rust/engine/src/ops/key_base.rs index ea4ff6370..5eee64f09 100644 --- a/engines/rust/engine/src/ops/key_base.rs +++ b/engines/rust/engine/src/ops/key_base.rs @@ -226,7 +226,11 @@ pub fn base_of(path: &Path, item_keys: bool, ctx: &Ctx) -> Option<(String, Strin if super::for_line::path_reads_unbound_alias(key, ctx) { return None; } - key_flaw(key, ctx)?; + if key_flaw(key, ctx).is_none() + && !(item_keys && subject_keys_then_an_items_key(&path.steps[at..], ctx)) + { + return None; + } } Step::Field(key) if !item_keys @@ -262,6 +266,9 @@ fn subject_keys_then_an_items_key(steps: &[Step], ctx: &Ctx) -> bool { path::names_the_subject(&key.start) && matches!(path::resolve(step, ctx), Ok(path::Resolved::Key(_))) } + Step::Ref(key) => { + !super::for_line::path_reads_unbound_alias(key, ctx) && key_flaw(key, ctx).is_none() + } _ => false, }) } From 9861717acb6f11f45c5adb4ce21436138d57c02c Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 01:12:04 +0100 Subject: [PATCH 07/57] docs: list the fixes and keep the inputs the two engines leave out in spec/OPEN.md Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- CHANGELOG.md | 1 + engines/rust/CHANGELOG.md | 1 + spec/OPEN.md | 3 +-- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18580a4cb..63cacf1e0 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 +- 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. - 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. diff --git a/engines/rust/CHANGELOG.md b/engines/rust/CHANGELOG.md index 80d966c2c..1c98239d7 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 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. - A sentence under a `for` line that reads the line's alias only as the `named by` key of `$params` or `$input` on the right of `is in`, like `count of zw whose k is in $params.m named by x is at most 5`, is left out on an empty list with `, if any,`, as it is in `ergo.rego`, so the check passes. It used to run before any item and fail on an item it couldn't decide. A count that never ran is no longer among the row's `inputs`. The part before such a key, like `$params.m` in `$params.m named by x`, is read with each item too, and not before any item, so it no longer fails the check on an empty list when it is missing or `null`. - A `named by` key from the subject in a `whose … exists`, like `pr.key` in `count of tests whose $params.m named by pr.key exists is 0`, is read once, before any item, as with the other phrases ([tally.whose](../../spec/semantics.md#counts-and-sums-in-sentences), [for.roots](../../spec/semantics.md#for)). A key that is missing, `null` or isn't text fails the check, like `pr.key is {}, which isn't text`, even when the list is empty, with or without `, if any,`. It passed before. This changes the report of a policy that has one. diff --git a/spec/OPEN.md b/spec/OPEN.md index c2a62df61..ecdb435f0 100644 --- a/spec/OPEN.md +++ b/spec/OPEN.md @@ -97,8 +97,7 @@ OPA 1.20.2 crashes when it compares a number whose exponent is beyond ±1e6 with - **A key from the subject that can't be read, beside a root that is missing or `null`, in a one-line `every` or `some`, an `every … that` or a `for` line (type 3).** With no params and the key `[]`, `every tests whose v equals $params.d.m named by pr.key exists` fails as `unusable` in both engines. `ergo.rego` says `pr.key is [], which isn't text; $params.d.m named by pr.key is missing` and the Rust engine says only `pr.key is [], which isn't text`, as both engines do for `count of`. A key that is missing, `null` or `3` beside a root that is `null` is the same, in `every`, `some` and `every … that`, with the root `$params.m`, `$input.m`, `pr.m` or the parent's `art.m`: with no key, the params `{"m": null}` and `tests` `[{}]`, `every tests whose v equals $params.m named by pr.key exists` fails as `absent` in both engines, with `pr.key is missing; item 1 of tests: v is missing` in the Rust engine, and `ergo.rego` adds `$params.m is null` after the key. A `for` line's second `whose` is the same: with subjects `art` from `arts` and `pr` from `every art.prs`, the key `3`, `xs` `[{}]` and `tests` `[{"v": 1}]`, `for: every xs as x, every tests whose v equals x.m named by pr.key, if any, as t` with `t exists` fails as `unusable` in both engines, with `pr.key is 3, which isn't text` in the Rust engine and `pr.key is 3, which isn't text; item 1 of xs: x.m named by pr.key is missing` in `ergo.rego`, and `first of tests whose v equals x.m named by pr.key as t` too. [problems.all_said](semantics.md#which-problems-a-message-says) says "A message SHOULD say every problem Ergo finds", and the root can't be read whatever the key holds, so `ergo.rego` follows it here. On `main` `ergo.rego` failed the first one as `absent`. No step is scheduled yet. - **A one-line walk under a `for` line whose root is the line's alias read through a key from the subject says the key twice (type 3, [problems.where_said](semantics.md#which-problems-a-message-says)).** With no key, `xs` `[{"m": null}]` and `tests` `[{}]`, `every tests whose v equals x.m named by pr.key exists` under `for: every xs as x` fails as `absent` in both engines, with `pr.key is missing; item 1 of xs: item 1 of tests: v is missing` in the Rust engine and `pr.key is missing; item 1 of xs: pr.key is missing; x.m is null; item 1 of xs: item 1 of tests: v is missing` in `ergo.rego`. problems.where_said says a key read from outside the item is said once, with no item in front, so the Rust engine follows it, though `ergo.rego` also names `x.m is null`, which [problems.all_said](semantics.md#which-problems-a-message-says) asks for. With `tests` `[{}, {"v": 1}]`, `sum of tests.v that equals x.m named by pr.key is 1` says `pr.key is missing; item 1 of xs: item 1 of tests: v is missing` in the Rust engine and `pr.key is missing; item 1 of tests: v is missing` in `ergo.rego`, which drops `item 1 of xs:` in front. No step is scheduled yet. - **A chain of a key from the subject and then the item's own key, over an empty list, when the first step of the root is missing from an object that exists (type 1, [tally.walk](semantics.md#counts-and-sums-in-sentences), [for.roots](semantics.md#for)).** tally.walk says "one that's missing or `null` fails it as `absent` or `null`, even when the list is empty", and for.roots says "Each root is read once, before any item". 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` passes in both engines, and should fail as `absent` with `$params.m named by pr.key is missing`, as it does when `named by pr.key` is the last key. Case: `sentences` "a root from $params read through a named by key from the subject and then the item's key is read once, before any item, so a root that has no key for the subject's key fails the check on an empty list too", in `known_differences` and in `engines/rust/known-failures.txt`. The case pins the `count` form and not the other forms. The step: the next burn-down pull request, so that both engines read the root up to the subject's key before any item. -- **A chain of the item's own key and then a key from `$params`, over an empty list, when the root can't be read (type 1, [tally.walk](semantics.md#counts-and-sums-in-sentences), [for.roots](semantics.md#for)).** tally.walk says "one that's missing or `null` fails it as `absent` or `null`, even when the list is empty", and for.roots says "Each root is read once, before any item". With no `m` in the params, the params' `k` holding `"a"` and `tests` `[]`, `count of tests whose v equals $params.m named by key named by $params.k is 0` passes in `ergo.rego` and fails as `absent` with `$params.m is missing` in the Rust engine, which is right. The same goes for `sum of v of tests whose v equals $params.m named by key named by $params.k is 0`. On `main` too. Case: `sentences` "a root from $params read through the item's key and then a named by key from $params is read once, before any item, so a root it doesn't have fails the check on an empty list too", in `known_differences`. The case pins the `count` form. The step: the next burn-down pull request (B8), so that `ergo.rego` reads the root before any item when the chain ends in a key from `$params`. -- **A chain with a key from `$params` in front of the item's own key, over an empty list, when the root can't be read (type 1, both engines, [tally.walk](semantics.md#counts-and-sums-in-sentences), [for.roots](semantics.md#for)).** tally.walk says "one that's missing or `null` fails it as `absent` or `null`, even when the list is empty", and for.roots says "Each root is read once, before any item". With no `m` in the params, the params' `k` holding `"a"` and `tests` `[]`, `count of tests whose v equals $params.m named by $params.k named by key is 0` passes in both engines, and should fail as `absent` with `$params.m is missing`. `$params.m named by $params.k named by pr.key named by key` and `$params.m named by pr.key named by $params.k named by key` pass in both too, and `$params.m named by $params.k` and `$params.m named by pr.key named by key` alone fail. The Rust engine reads only the keys of the subject that come before the item's key, so a `$params` key in front still skips reading the root. On `main` too. Case: `sentences` "a root from $params read through a named by key from $params and then the item's key is read once, before any item, so a root it doesn't have fails the check on an empty list too", in `known_differences` and in `engines/rust/known-failures.txt`. The case pins the `count` form. The step: the next burn-down pull request (B8), so that both engines read the root before any item whatever the keys in front of the item's key. +- **A chain with a key from `$params` in front of the item's own key, over an empty list, when the root can't be read, leaves the root and the key out of the row's `inputs` (type 2, both engines, [tally.walk](semantics.md#counts-and-sums-in-sentences), [for.roots](semantics.md#for)).** With no `m` in the params, the params' `k` holding `"a"` and `tests` `[]`, `count of tests whose v equals $params.m named by $params.k named by key is 0` fails in both engines as `absent` with `$params.m is missing`, as it should. But neither engine lists `$params.m named by $params.k named by key` (`absent`) and `$params.k` (`usable`) in the row's `inputs`: both put them only in the check's `$refs`, as `$params.m` and `$params.k`. Case: `sentences` "a root from $params read through a named by key from $params and then the item's key is read once, before any item, so a root it doesn't have fails the check on an empty list too", in `known_differences` and in `engines/rust/known-failures.txt`. The step: the next burn-down pull request, so that both engines list the root and the key in the row's `inputs`. - **A `null` key from the subject on an empty list, in a one-line `every` or `some` (type 2).** With no params, the key `null` and `tests` `[]`, `every tests whose v equals $params.m named by pr.key exists` and `some tests whose v equals $params.m named by pr.key exists` fail as `null` in `ergo.rego` with `pr.key is null; tests is []`, and as `absent` in the Rust engine with `$params.m named by pr.key is missing; pr.key is null; tests is []`. [tally.whose](semantics.md#counts-and-sums-in-sentences) says "each item takes the cause of its own paths, and the row takes the worst of all", and `$params.m` is missing whatever the key holds, so the Rust engine is right. `count of tests whose v equals $params.zz named by pr.key is 0` with `key` `null` is the same: `ergo.rego` says `null` with `pr.key is null`, and the Rust engine says `absent` with `$params.zz named by pr.key is missing; pr.key is null`. With no `m` and the params' `k` `null`, `count of tests whose v equals $params.m named by $params.k named by key is 0` on `[]` is the same, with `$params.k is null` in `ergo.rego` and `$params.m is missing; $params.k is null` in the Rust engine, in the other orders of the keys too. With no `m` and `tests` `[]`, `some tests whose v equals $params.m named by key named by pr.key exists` says `value` with `tests is []` in `ergo.rego` and `absent` with `$params.m is missing; tests is []` in the Rust engine. With no `m` and `tests` `[{"v": 1, "key": "b", "j": "c"}, {"v": 1, "key": "b", "j": 3}]`, `count of tests whose v equals $params.m named by key named by j is 0` says `absent` with `$params.m is missing` in `ergo.rego` and `unusable` with `$params.m is missing; item 2 of tests: j is 3, which isn't text` in the Rust engine, which follows problems.all_said. On `main` too. No step is scheduled yet. - **A root that can't be read, beside a chain of keys that can't be read or a sum, in `ergo.rego` (type 3, [problems.all_said](semantics.md#which-problems-a-message-says), [problems.where_said](semantics.md#which-problems-a-message-says)).** With no `m` in the params and `tests` `[{"v": 1, "key": "b", "j": "c"}, {"v": 1, "key": "b"}]`, `count of tests whose v equals $params.m named by key named by j is 0` says `$params.m is missing` in `ergo.rego` and `$params.m is missing; item 2 of tests: j is missing` in the Rust engine, and with `j` `3` in the second item `ergo.rego` drops `item 2 of tests: j is 3, which isn't text` in the same way, so it no longer says the second key's problem, as it did on `main`. With `tests` `[]`, `sum of v of tests whose v equals $params.m named by key named by pr.key is 0` fails as `absent` in both engines, with `$params.m is missing` in the Rust engine and `sum of v of tests whose v equals $params.m named by key named by pr.key is 0 is false` in `ergo.rego`, which never names `$params.m`. With `named by art.key` or `named by art` where `art` holds an object, both engines fail as `unusable` with `art is an object with 2 keys, which isn't text`, and the Rust engine adds `; $params.m is missing`. No step is scheduled yet. - **A `count of`, `every` or `some` whose `whose` reads a parent's or the subject's field through a `null` key from the subject (type 2).** With subjects `art` from `arts` and `pr` from `every art.prs`, the parent's `m` holding `{"a": 1}`, the key `null` and `tests` holding `[{"v": 1}]`, `count of tests whose art.m named by pr.key is 1 is 0` fails in `ergo.rego` as `absent` with `item 1 of tests: .art.m named by pr.key is missing`, and in the Rust engine as `null` with `pr.key is null`. [tally.whose](semantics.md#counts-and-sums-in-sentences) says the key "is always said, once and before any item", so the Rust engine is right. A one-line `every` or `some` is the same, and so is a root from the subject: with the key `null` and `tests` `[{"v": 1}, {}]`, `every tests whose pr named by pr.key is 1, if any, exists` fails in `ergo.rego` as `absent` with `item 1 of tests: .pr named by pr.key is missing; item 2 of tests: .pr named by pr.key is missing`, and in the Rust engine as `null` with `pr.key is null`, and `art.m`, `pr.m` and `some` give the same. The other way round, with `key` `null` and `tests` `[{"v": 1}]`, `count of tests whose t2 named by pr.key exists is 0` and, under `for: every xs, if any, as x`, `count of tests whose x.m named by pr.key exists is 0` fail as `null` with `pr.key is null` in the Rust engine and as `absent` in `ergo.rego`. On `main` too. No case pins it. The step is in `ergo.rego`'s read of a path on the left of a `whose` that starts at a parent or the subject and ends with a key from the subject. From 9e032c1a9ea3cdfcfdb27f1ad46a1e3000d429c2 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 01:29:51 +0100 Subject: [PATCH 08/57] rego: test that a bound line alias in front of the item's key reads the root before any item of the walked list Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/tests/lines/roots_test.rego | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/engines/rego/tests/lines/roots_test.rego b/engines/rego/tests/lines/roots_test.rego index e836b2c20..49cf2ab69 100644 --- a/engines/rego/tests/lines/roots_test.rego +++ b/engines/rego/tests/lines/roots_test.rego @@ -805,6 +805,19 @@ test_a_key_from_params_in_front_of_the_items_key_keeps_the_root_read_before_any_ } } +test_a_bound_line_alias_in_front_of_the_items_key_reads_the_root_before_any_item_of_the_walked_list if { + pr := {"key": "a", "tests": []} + every p in [ + ["$$params", "m", {"named_by": "x"}, {"named_by_field": "key"}], + ["$$params", "m", {"named_by": "x"}, {"ref": ["$$params", "k"]}, {"named_by_field": "key"}], + ["$$params", "m", {"ref": ["$$params", "k"]}, {"named_by": "x"}, {"named_by_field": "key"}], + ] { + ergo._keyed_root_path(p) with input as {"ergo/names": {"ergo/subject": pr, "x": "a"}} with data.ergo_params as {"k": "a"} + ergo._keyed_root_fault(pr, p) == {"cause": "absent", "text": "$params.m is missing"} with input as {"ergo/names": {"ergo/subject": pr, "x": "a"}} with data.ergo_params as {"k": "a"} + not ergo._keyed_root_path(p) with input as {"ergo/names": {"ergo/subject": pr}} with data.ergo_params as {"k": "a"} + } +} + test_a_root_read_through_two_subject_keys_that_both_fail_takes_the_worst_cause if { p := ["$$params", "m", {"named_by_field": "\u0003pr\u0003key"}, {"named_by_field": "\u0003pr\u0003j"}] every row in [ From e776f693799dad2259ab4ec2cdd07494327973b3 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 01:30:36 +0100 Subject: [PATCH 09/57] rego: read a root before any item through a bound line alias in front of the item's key Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/src/lines/roots.rego | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/engines/rego/src/lines/roots.rego b/engines/rego/src/lines/roots.rego index c73b851bd..7a22f648f 100644 --- a/engines/rego/src/lines/roots.rego +++ b/engines/rego/src/lines/roots.rego @@ -877,6 +877,11 @@ _keyed_read_before(step) if { 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) From dd9ccd9860cf12d257a1b6053b6675b2fb9ecad3 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 01:31:13 +0100 Subject: [PATCH 10/57] rust: test that a root read through the item's key and then an unbound line alias is not read before any item Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rust/engine/src/ops/key_base/tests.rs | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/engines/rust/engine/src/ops/key_base/tests.rs b/engines/rust/engine/src/ops/key_base/tests.rs index 2e2d4f330..7200a96ba 100644 --- a/engines/rust/engine/src/ops/key_base/tests.rs +++ b/engines/rust/engine/src/ops/key_base/tests.rs @@ -707,3 +707,46 @@ fn a_root_read_through_a_key_from_params_and_then_the_items_key_has_its_base_rea let params = json!({"k": "a", "m": {}}); assert!(base_of(&path, true, &ctx(&subject, ¶ms, &[])).is_none()); } + +fn chain(steps: Vec) -> Path { + let mut all = vec![Step::Key("m".to_string())]; + all.extend(steps); + Path { + start: Start::Params, + steps: all, + } +} + +fn items_key() -> Step { + Step::Field(Box::new(Path { + start: Start::Own, + steps: vec![Step::Key("key".to_string())], + })) +} + +fn alias_key() -> Step { + Step::Ref(Box::new(Path { + start: Start::Alias("x".to_string()), + steps: vec![], + })) +} + +fn params_key() -> Step { + Step::Ref(Box::new(Path { + start: Start::Params, + steps: vec![Step::Key("k".to_string())], + })) +} + +#[test] +fn a_root_read_through_the_items_key_and_then_an_unbound_line_alias_is_not_read_before_any_item() { + let subject = json!({"key": "a", "tests": []}); + let params = json!({"k": "a"}); + for steps in [ + vec![items_key(), alias_key()], + vec![items_key(), params_key(), alias_key()], + vec![params_key(), items_key(), alias_key()], + ] { + assert!(base_of(&chain(steps), true, &ctx(&subject, ¶ms, &[])).is_none()); + } +} From 99810a3d0df4a184e25d011cd21bb56b0167f288 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 01:31:39 +0100 Subject: [PATCH 11/57] rust: read no root before any item when a later key reads an unbound line alias Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rust/engine/src/ops/key_base.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/engines/rust/engine/src/ops/key_base.rs b/engines/rust/engine/src/ops/key_base.rs index 5eee64f09..dd3b9d5cd 100644 --- a/engines/rust/engine/src/ops/key_base.rs +++ b/engines/rust/engine/src/ops/key_base.rs @@ -221,11 +221,13 @@ pub fn base_of(path: &Path, item_keys: bool, ctx: &Ctx) -> Option<(String, Strin if !super::walk::reads_outside(path) && path.start != path::Start::Params { return None; } + if path.steps[at..].iter().any(|step| { + matches!(step, Step::Ref(key) | Step::Field(key) if super::for_line::path_reads_unbound_alias(key, ctx)) + }) { + return None; + } match &path.steps[at] { Step::Ref(key) => { - if super::for_line::path_reads_unbound_alias(key, ctx) { - return None; - } if key_flaw(key, ctx).is_none() && !(item_keys && subject_keys_then_an_items_key(&path.steps[at..], ctx)) { From 99e0c1b687d784c04132ba433f0b4b2d720db95f Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 01:32:54 +0100 Subject: [PATCH 12/57] test the causes of a root read through a key from $params and the item's key, and a bound alias in front of it (guards) Guards that pass as they are: `m` null and 3, `k` missing, null, 3 and empty in both engines, and a bound line alias in the chain in the Rust engine. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/tests/lines/roots_test.rego | 12 +++++ engines/rust/engine/src/ops/key_base/tests.rs | 47 +++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/engines/rego/tests/lines/roots_test.rego b/engines/rego/tests/lines/roots_test.rego index 49cf2ab69..33e0e46b8 100644 --- a/engines/rego/tests/lines/roots_test.rego +++ b/engines/rego/tests/lines/roots_test.rego @@ -818,6 +818,18 @@ test_a_bound_line_alias_in_front_of_the_items_key_reads_the_root_before_any_item } } +test_a_root_read_through_a_key_from_params_and_the_items_key_takes_the_roots_cause_and_leaves_a_key_that_cant_be_read_to_the_key if { + pr := {"key": "a", "tests": []} + p := ["$$params", "m", {"ref": ["$$params", "k"]}, {"named_by_field": "key"}] + names := {"ergo/names": {"ergo/subject": pr}} + ergo._keyed_root_fault(pr, p) == {"cause": "null", "text": "$params.m is null"} with input as names with data.ergo_params as {"k": "a", "m": null} + ergo._keyed_root_fault(pr, p) == {"cause": "unusable", "text": "$params.m is 3, which isn't an object"} with input as names with data.ergo_params as {"k": "a", "m": 3} + ergo._keyed_root_fault(pr, p) == {"cause": "absent", "text": "$params.m is missing"} with input as names with data.ergo_params as {"k": ""} + every params in [{}, {"k": null}, {"k": 3}] { + not ergo._keyed_root_path(p) with input as names with data.ergo_params as params + } +} + test_a_root_read_through_two_subject_keys_that_both_fail_takes_the_worst_cause if { p := ["$$params", "m", {"named_by_field": "\u0003pr\u0003key"}, {"named_by_field": "\u0003pr\u0003j"}] every row in [ diff --git a/engines/rust/engine/src/ops/key_base/tests.rs b/engines/rust/engine/src/ops/key_base/tests.rs index 7200a96ba..2ce35053e 100644 --- a/engines/rust/engine/src/ops/key_base/tests.rs +++ b/engines/rust/engine/src/ops/key_base/tests.rs @@ -750,3 +750,50 @@ fn a_root_read_through_the_items_key_and_then_an_unbound_line_alias_is_not_read_ assert!(base_of(&chain(steps), true, &ctx(&subject, ¶ms, &[])).is_none()); } } + +#[test] +fn a_root_read_through_a_key_from_params_and_the_items_key_takes_the_roots_cause_whatever_the_key() +{ + let subject = json!({"key": "a", "tests": []}); + let path = chain(vec![params_key(), items_key()]); + for (params, text, cause) in [ + ( + json!({"k": "a", "m": null}), + "$params.m is null", + Cause::Null, + ), + ( + json!({"k": "a", "m": 3}), + "$params.m is 3, which isn't an object", + Cause::Unusable, + ), + (json!({"k": ""}), "$params.m is missing", Cause::Absent), + (json!({}), "$params.m is missing", Cause::Absent), + (json!({"k": null}), "$params.m is missing", Cause::Absent), + (json!({"k": 3}), "$params.m is missing", Cause::Absent), + ] { + let (_, found, found_cause) = base_of(&path, true, &ctx(&subject, ¶ms, &[])).unwrap(); + assert_eq!((found.as_str(), found_cause), (text, cause)); + } +} + +#[test] +fn a_bound_line_alias_in_front_of_the_items_key_reads_the_root_before_any_item() { + let subject = json!({"key": "a", "tests": []}); + let params = json!({"k": "a"}); + let x = json!("a"); + for steps in [ + vec![alias_key(), items_key()], + vec![alias_key(), params_key(), items_key()], + vec![params_key(), alias_key(), items_key()], + vec![items_key(), alias_key()], + ] { + let path = chain(steps.clone()); + let (_, text, cause) = base_of(&path, true, &ctx(&subject, ¶ms, &[("x", &x)])).unwrap(); + assert_eq!( + (text.as_str(), cause), + ("$params.m is missing", Cause::Absent) + ); + assert!(base_of(&chain(steps), true, &ctx(&subject, ¶ms, &[])).is_none()); + } +} From 7ce58484e40f02297fe4897c52c884253929e530 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 01:33:58 +0100 Subject: [PATCH 13/57] docs: record the line alias forms in the changelogs and reword the inputs entry in spec/OPEN.md The entry for a root read through a key from $params and then the item's key no longer says the row's inputs are settled: no rule decides them, and two cases expect different inputs. The entry on a one-line every with if any names the chain forms, and the entry on roots said again for each item drops the count form, which ergo.rego now says once. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- CHANGELOG.md | 2 +- engines/rust/CHANGELOG.md | 2 +- spec/OPEN.md | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63cacf1e0..fd145ae1c 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 -- 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. +- 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. diff --git a/engines/rust/CHANGELOG.md b/engines/rust/CHANGELOG.md index 1c98239d7..549c10bff 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 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. +- A root read through a `named by` key from `$params` and then the item's `named by` key is read once, before any item, as [tally.walk](../../spec/semantics.md#counts-and-sums-in-sentences) and [for.roots](../../spec/semantics.md#for) say. With no `m` in the params, the params' `k` holding `"a"` and `tests` holding `[]`, `count of tests whose v equals $params.m named by $params.k named by key is 0` used to pass, and now fails as `absent` with `$params.m is missing`. The same goes for a key from the subject beside it, like `$params.m named by pr.key named by $params.k named by key`. Changes the report of such a check. Under `for: every xs, if any, as x`, a root read through the item's key and then the line's alias, like `$params.m named by key named by x`, is no longer read when `xs` holds `[]`, so the check passes there, as [for.roots](../../spec/semantics.md#for) says, where it used to fail as `absent` with `$params.m is missing`. - A sentence under a `for` line that reads the line's alias only as the `named by` key of `$params` or `$input` on the right of `is in`, like `count of zw whose k is in $params.m named by x is at most 5`, is left out on an empty list with `, if any,`, as it is in `ergo.rego`, so the check passes. It used to run before any item and fail on an item it couldn't decide. A count that never ran is no longer among the row's `inputs`. The part before such a key, like `$params.m` in `$params.m named by x`, is read with each item too, and not before any item, so it no longer fails the check on an empty list when it is missing or `null`. - A `named by` key from the subject in a `whose … exists`, like `pr.key` in `count of tests whose $params.m named by pr.key exists is 0`, is read once, before any item, as with the other phrases ([tally.whose](../../spec/semantics.md#counts-and-sums-in-sentences), [for.roots](../../spec/semantics.md#for)). A key that is missing, `null` or isn't text fails the check, like `pr.key is {}, which isn't text`, even when the list is empty, with or without `, if any,`. It passed before. This changes the report of a policy that has one. diff --git a/spec/OPEN.md b/spec/OPEN.md index ecdb435f0..c4047edfd 100644 --- a/spec/OPEN.md +++ b/spec/OPEN.md @@ -92,12 +92,12 @@ OPA 1.20.2 crashes when it compares a number whose exponent is beyond ±1e6 with - **Some chains of keys from the subject name one failing key in `ergo.rego` where the Rust engine names each (type 3, [problems.all_said](semantics.md#which-problems-a-message-says), [problems.where_said](semantics.md#which-problems-a-message-says)).** With three keys, the first `"a"`, then `null` and `3`, `count of` with an item says `pr.k is 3, which isn't text` in `ergo.rego` and adds `; pr.j is null` in the Rust engine, and the same with `{"key": null, "j": 3}` and `tests` `[{"v": 1}]`. Under a `for` line, or in a `for` line's own `whose`, when the root is `null` and has a path or several keys, `ergo.rego` says a key twice: with `for: every tests whose v equals $params.m.d named by pr.key named by pr.j, if any, as t`, `t exists`, `m` `null`, `key` "a", `j` `{}` and `tests` `[]`, it says `pr.j is {}, which isn't text; pr.j is {}, which isn't text; $params.m is null`, where the Rust engine says `pr.j is {}, which isn't text` once, as problems.where_said asks. No step is scheduled yet. - **The wording of a chain of keys that can't be read, in a few shapes (type 3).** `$params.m named by key named by j does not exist` says its problems in a different order in the two engines. Under a `for` line, `first of` has `; tests is []` added in the Rust engine. With `count of tests whose $params.m named by key exists is 0`, the Rust engine says `item 1 of tests: key is missing` and `ergo.rego` says `""`. With `count of tests whose v exists and whose $params.m named by pr.key exists is 0`, `ergo.rego` says `count of … is 0 is false`. No step is scheduled yet. - **The `failures` of a `count of` over a list with items, whose `whose` reads a root through two `named by` keys from the subject (type 3, [row.parts](semantics.md#what-a-row-shows)).** With the params `{"m": {"a": {"y": {"j": 1}}}}`, the subject's `key` holding `"a"` and `j` holding `"q"`, and `tests` holding `[{"v": 1, "pr": "y"}]`, `count of tests whose v equals $params.m named by pr.key named by pr.j is 1` fails as `absent` with `$params.m named by pr.key named by pr.j is missing` in both engines. The Rust engine puts the problem on the assertion, with no item entry, and `ergo.rego` puts it on an `item 1 of tests` entry and gives the assertion the message `""`. It is the shape of the entry below with one key, so its step fixes it too. Case: `sentences` "two named by keys from the subject, one after the other, are both read from the subject and never from the item", in `known_differences`. -- **A root read through the item's own key that can't be read is said again for each item in `ergo.rego` (type 3, [problems.where_said](semantics.md#which-problems-a-message-says)).** With no params and `tests` holding `[{"key": "a", "v": 1}]`, `count of tests whose $params.m named by key is 1 is 0` and `for: every tests whose $params.m named by key is 1, if any, as t` with `t exists` fail as `absent` in both engines, with `$params.m is missing` in the Rust engine and `$params.m is missing; item 1 of tests: $params.m named by key is missing` in `ergo.rego`. The same goes for `$input.m`, for `exists`, `is one of`, `is true`, `matches` and `is in` after the root, and for `m` `null` or `3`. With `m` `null` and `tests` holding `[{"v": 1}]`, the `for` line says `$params.m is null; item 1 of tests: key is missing; $params.m is null` in `ergo.rego`, and the Rust engine says the root once, first. problems.where_said says a problem in something read from outside the item is said once, with no item in front, so the Rust engine is right. On `main` `ergo.rego` passed these on an empty list and named only the items here. A chain of the item's own key and a key from the subject, in either order, does the same: with the subject's `key` holding `"a"` and `tests` holding `[{"v": 1, "key": "b"}]`, `count of tests whose $params.m named by pr.key named by key is 1 is 0` says `$params.m is missing; item 1 of tests: $params.m named by pr.key named by key is missing` in `ergo.rego` and `$params.m is missing` in the Rust engine, and with `m` `null` or `3` the item says `$params.m is null` or `$params.m is 3, which isn't an object` again. A one-line `every` over that list names only the item in `ergo.rego`, on `main` too. With items, a chain ending in a key from `$params` still names every item: `count of tests whose v equals $params.m named by key named by $params.k is 0` says `$params.m is missing; item 1 of tests: $params.m named by key named by $params.k is missing` in `ergo.rego` where the chain ending in `pr.key` says only `$params.m is missing`, and `for: every tests whose v equals $params.m named by key named by pr.key, if any, as t` says `$params.m is missing` and then `item N of tests: $params.m named by key named by pr.key is missing` for each item, where the Rust engine says only the root. The step that fixes it: `ergo.rego` leaves a root it has said out of each item's problems, as it does after `equals` and `is at least`. +- **A root read through the item's own key that can't be read is said again for each item in `ergo.rego` (type 3, [problems.where_said](semantics.md#which-problems-a-message-says)).** With no params and `tests` holding `[{"key": "a", "v": 1}]`, `count of tests whose $params.m named by key is 1 is 0` and `for: every tests whose $params.m named by key is 1, if any, as t` with `t exists` fail as `absent` in both engines, with `$params.m is missing` in the Rust engine and `$params.m is missing; item 1 of tests: $params.m named by key is missing` in `ergo.rego`. The same goes for `$input.m`, for `exists`, `is one of`, `is true`, `matches` and `is in` after the root, and for `m` `null` or `3`. With `m` `null` and `tests` holding `[{"v": 1}]`, the `for` line says `$params.m is null; item 1 of tests: key is missing; $params.m is null` in `ergo.rego`, and the Rust engine says the root once, first. problems.where_said says a problem in something read from outside the item is said once, with no item in front, so the Rust engine is right. On `main` `ergo.rego` passed these on an empty list and named only the items here. A chain of the item's own key and a key from the subject, in either order, does the same: with the subject's `key` holding `"a"` and `tests` holding `[{"v": 1, "key": "b"}]`, `count of tests whose $params.m named by pr.key named by key is 1 is 0` says `$params.m is missing; item 1 of tests: $params.m named by pr.key named by key is missing` in `ergo.rego` and `$params.m is missing` in the Rust engine, and with `m` `null` or `3` the item says `$params.m is null` or `$params.m is 3, which isn't an object` again. A one-line `every` over that list names only the item in `ergo.rego`, on `main` too. With items, `for: every tests whose v equals $params.m named by key named by pr.key, if any, as t` says `$params.m is missing` and then `item N of tests: $params.m named by key named by pr.key is missing` for each item, where the Rust engine says only the root. The step that fixes it: `ergo.rego` leaves a root it has said out of each item's problems, as it does after `equals` and `is at least`. - **The `failures` of a `count of` over a list with items, whose `whose` reads a root through a `named by` key from the subject that the root doesn't have (type 3, [row.parts](semantics.md#what-a-row-shows)).** With no params, `count of xs whose v equals $params.m named by pr.k is 1`, the key `"a"` and `xs` holding `[{"v": 1}]` fails as `absent` with `$params.m named by pr.k is missing` in both engines. `ergo.rego` puts the problem on an `item 1 of xs` entry, as the `sentences` case "a key from the subject that can't be read, in a relative clause" pins, and the Rust engine puts it on the assertion, with no item entry. row.parts says "something read outside the item sits on the assertion, once, and items hold only their own problems", so the Rust engine follows the rule and the case doesn't. The same goes for `pr named by pr.k`, and for the key `null`. It is the same with items the clause can't read: with the params `{"m": {"a": 1}}`, the key `"b"` and `tests` holding `[{"v": 1}, {}]`, `count of tests whose v equals $input.m named by pr.key is 0` says `$input.m named by pr.key is missing; item 2 of tests: v is missing` in both engines, and `ergo.rego` adds an `item 1 of tests` entry that holds the root's problem, for `pr named by pr.key`, `count of tests.v that …` and `sum of tests.v whose $params.m named by pr.key is 1` too. The `sentences` case "a root from $input or the subject itself read through a named by key from the subject, in a count of or a sum of over items, ..." follows the rule, so it is in `known_differences`. The step that fixes it: a decision on the case's rows, then `ergo.rego` reads the root before any item there too. - **A key from the subject that can't be read, beside a root that is missing or `null`, in a one-line `every` or `some`, an `every … that` or a `for` line (type 3).** With no params and the key `[]`, `every tests whose v equals $params.d.m named by pr.key exists` fails as `unusable` in both engines. `ergo.rego` says `pr.key is [], which isn't text; $params.d.m named by pr.key is missing` and the Rust engine says only `pr.key is [], which isn't text`, as both engines do for `count of`. A key that is missing, `null` or `3` beside a root that is `null` is the same, in `every`, `some` and `every … that`, with the root `$params.m`, `$input.m`, `pr.m` or the parent's `art.m`: with no key, the params `{"m": null}` and `tests` `[{}]`, `every tests whose v equals $params.m named by pr.key exists` fails as `absent` in both engines, with `pr.key is missing; item 1 of tests: v is missing` in the Rust engine, and `ergo.rego` adds `$params.m is null` after the key. A `for` line's second `whose` is the same: with subjects `art` from `arts` and `pr` from `every art.prs`, the key `3`, `xs` `[{}]` and `tests` `[{"v": 1}]`, `for: every xs as x, every tests whose v equals x.m named by pr.key, if any, as t` with `t exists` fails as `unusable` in both engines, with `pr.key is 3, which isn't text` in the Rust engine and `pr.key is 3, which isn't text; item 1 of xs: x.m named by pr.key is missing` in `ergo.rego`, and `first of tests whose v equals x.m named by pr.key as t` too. [problems.all_said](semantics.md#which-problems-a-message-says) says "A message SHOULD say every problem Ergo finds", and the root can't be read whatever the key holds, so `ergo.rego` follows it here. On `main` `ergo.rego` failed the first one as `absent`. No step is scheduled yet. - **A one-line walk under a `for` line whose root is the line's alias read through a key from the subject says the key twice (type 3, [problems.where_said](semantics.md#which-problems-a-message-says)).** With no key, `xs` `[{"m": null}]` and `tests` `[{}]`, `every tests whose v equals x.m named by pr.key exists` under `for: every xs as x` fails as `absent` in both engines, with `pr.key is missing; item 1 of xs: item 1 of tests: v is missing` in the Rust engine and `pr.key is missing; item 1 of xs: pr.key is missing; x.m is null; item 1 of xs: item 1 of tests: v is missing` in `ergo.rego`. problems.where_said says a key read from outside the item is said once, with no item in front, so the Rust engine follows it, though `ergo.rego` also names `x.m is null`, which [problems.all_said](semantics.md#which-problems-a-message-says) asks for. With `tests` `[{}, {"v": 1}]`, `sum of tests.v that equals x.m named by pr.key is 1` says `pr.key is missing; item 1 of xs: item 1 of tests: v is missing` in the Rust engine and `pr.key is missing; item 1 of tests: v is missing` in `ergo.rego`, which drops `item 1 of xs:` in front. No step is scheduled yet. - **A chain of a key from the subject and then the item's own key, over an empty list, when the first step of the root is missing from an object that exists (type 1, [tally.walk](semantics.md#counts-and-sums-in-sentences), [for.roots](semantics.md#for)).** tally.walk says "one that's missing or `null` fails it as `absent` or `null`, even when the list is empty", and for.roots says "Each root is read once, before any item". 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` passes in both engines, and should fail as `absent` with `$params.m named by pr.key is missing`, as it does when `named by pr.key` is the last key. Case: `sentences` "a root from $params read through a named by key from the subject and then the item's key is read once, before any item, so a root that has no key for the subject's key fails the check on an empty list too", in `known_differences` and in `engines/rust/known-failures.txt`. The case pins the `count` form and not the other forms. The step: the next burn-down pull request, so that both engines read the root up to the subject's key before any item. -- **A chain with a key from `$params` in front of the item's own key, over an empty list, when the root can't be read, leaves the root and the key out of the row's `inputs` (type 2, both engines, [tally.walk](semantics.md#counts-and-sums-in-sentences), [for.roots](semantics.md#for)).** With no `m` in the params, the params' `k` holding `"a"` and `tests` `[]`, `count of tests whose v equals $params.m named by $params.k named by key is 0` fails in both engines as `absent` with `$params.m is missing`, as it should. But neither engine lists `$params.m named by $params.k named by key` (`absent`) and `$params.k` (`usable`) in the row's `inputs`: both put them only in the check's `$refs`, as `$params.m` and `$params.k`. Case: `sentences` "a root from $params read through a named by key from $params and then the item's key is read once, before any item, so a root it doesn't have fails the check on an empty list too", in `known_differences` and in `engines/rust/known-failures.txt`. The step: the next burn-down pull request, so that both engines list the root and the key in the row's `inputs`. +- **Which `inputs` a root read through a key that can be read and then the item's own key puts on the row, over an empty list (type 2, both engines, [tally.inputs](semantics.md#counts-and-sums-in-sentences), [tally.whose](semantics.md#counts-and-sums-in-sentences)).** With no `m` in the params, the params' `k` holding `"a"` and `tests` `[]`, `count of tests whose v equals $params.m named by $params.k named by key is 0` fails in both engines as `absent` with `$params.m is missing`, as it should. No rule decides the row's `inputs` here: tally.inputs names only the count and the walked list, and tally.whose puts a key on the assertion's inputs only when it is missing or `null`. The two cases disagree: the case below expects `$params.m named by $params.k named by key` (`absent`) and `$params.k` (`usable`) in the inputs, and the `sentences` case for `$params.m named by key named by $params.k` ("a root from $params read through the item's key and then a named by key from $params …"), which both engines pass, expects no input for the root or the key. Both engines list neither, and put them only in the check's `$refs`. Case: `sentences` "a root from $params read through a named by key from $params and then the item's key is read once, before any item, so a root it doesn't have fails the check on an empty list too", in `known_differences` and in `engines/rust/known-failures.txt`. The step: a decision on which inputs such a row lists, and then both cases follow it. - **A `null` key from the subject on an empty list, in a one-line `every` or `some` (type 2).** With no params, the key `null` and `tests` `[]`, `every tests whose v equals $params.m named by pr.key exists` and `some tests whose v equals $params.m named by pr.key exists` fail as `null` in `ergo.rego` with `pr.key is null; tests is []`, and as `absent` in the Rust engine with `$params.m named by pr.key is missing; pr.key is null; tests is []`. [tally.whose](semantics.md#counts-and-sums-in-sentences) says "each item takes the cause of its own paths, and the row takes the worst of all", and `$params.m` is missing whatever the key holds, so the Rust engine is right. `count of tests whose v equals $params.zz named by pr.key is 0` with `key` `null` is the same: `ergo.rego` says `null` with `pr.key is null`, and the Rust engine says `absent` with `$params.zz named by pr.key is missing; pr.key is null`. With no `m` and the params' `k` `null`, `count of tests whose v equals $params.m named by $params.k named by key is 0` on `[]` is the same, with `$params.k is null` in `ergo.rego` and `$params.m is missing; $params.k is null` in the Rust engine, in the other orders of the keys too. With no `m` and `tests` `[]`, `some tests whose v equals $params.m named by key named by pr.key exists` says `value` with `tests is []` in `ergo.rego` and `absent` with `$params.m is missing; tests is []` in the Rust engine. With no `m` and `tests` `[{"v": 1, "key": "b", "j": "c"}, {"v": 1, "key": "b", "j": 3}]`, `count of tests whose v equals $params.m named by key named by j is 0` says `absent` with `$params.m is missing` in `ergo.rego` and `unusable` with `$params.m is missing; item 2 of tests: j is 3, which isn't text` in the Rust engine, which follows problems.all_said. On `main` too. No step is scheduled yet. - **A root that can't be read, beside a chain of keys that can't be read or a sum, in `ergo.rego` (type 3, [problems.all_said](semantics.md#which-problems-a-message-says), [problems.where_said](semantics.md#which-problems-a-message-says)).** With no `m` in the params and `tests` `[{"v": 1, "key": "b", "j": "c"}, {"v": 1, "key": "b"}]`, `count of tests whose v equals $params.m named by key named by j is 0` says `$params.m is missing` in `ergo.rego` and `$params.m is missing; item 2 of tests: j is missing` in the Rust engine, and with `j` `3` in the second item `ergo.rego` drops `item 2 of tests: j is 3, which isn't text` in the same way, so it no longer says the second key's problem, as it did on `main`. With `tests` `[]`, `sum of v of tests whose v equals $params.m named by key named by pr.key is 0` fails as `absent` in both engines, with `$params.m is missing` in the Rust engine and `sum of v of tests whose v equals $params.m named by key named by pr.key is 0 is false` in `ergo.rego`, which never names `$params.m`. With `named by art.key` or `named by art` where `art` holds an object, both engines fail as `unusable` with `art is an object with 2 keys, which isn't text`, and the Rust engine adds `; $params.m is missing`. No step is scheduled yet. - **A `count of`, `every` or `some` whose `whose` reads a parent's or the subject's field through a `null` key from the subject (type 2).** With subjects `art` from `arts` and `pr` from `every art.prs`, the parent's `m` holding `{"a": 1}`, the key `null` and `tests` holding `[{"v": 1}]`, `count of tests whose art.m named by pr.key is 1 is 0` fails in `ergo.rego` as `absent` with `item 1 of tests: .art.m named by pr.key is missing`, and in the Rust engine as `null` with `pr.key is null`. [tally.whose](semantics.md#counts-and-sums-in-sentences) says the key "is always said, once and before any item", so the Rust engine is right. A one-line `every` or `some` is the same, and so is a root from the subject: with the key `null` and `tests` `[{"v": 1}, {}]`, `every tests whose pr named by pr.key is 1, if any, exists` fails in `ergo.rego` as `absent` with `item 1 of tests: .pr named by pr.key is missing; item 2 of tests: .pr named by pr.key is missing`, and in the Rust engine as `null` with `pr.key is null`, and `art.m`, `pr.m` and `some` give the same. The other way round, with `key` `null` and `tests` `[{"v": 1}]`, `count of tests whose t2 named by pr.key exists is 0` and, under `for: every xs, if any, as x`, `count of tests whose x.m named by pr.key exists is 0` fail as `null` with `pr.key is null` in the Rust engine and as `absent` in `ergo.rego`. On `main` too. No case pins it. The step is in `ergo.rego`'s read of a path on the left of a `whose` that starts at a parent or the subject and ends with a key from the subject. @@ -232,7 +232,7 @@ The spec doesn't settle these yet, because the two engines give different report ## Where both engines differ from a rule -- **A one-line `every` with `, if any,` whose `whose` reads a root through the item's own key passes in both engines on an empty list when the root can't be read (type 1, both engines, [tally.walk](semantics.md#counts-and-sums-in-sentences), [for.roots](semantics.md#for), [problems.same_path](semantics.md#which-problems-a-message-says)).** tally.walk says "The same goes for every root [for.roots](#for) names, … `$params` and `$input`, wherever the check reads it: an `every` or `some` phrase, a `whose`, …", and for.roots says "Each root is read once, before any item". With no params and `tests` `[]`, `every tests whose $params.m named by key is 1, if any, exists` passes in both engines, and the same with `$input.m`, `$params.m.d` and the parent's `art.m` holding `3`. Both engines fail `count of tests whose $params.m named by key is 1 is 0` and the `for` line `every tests whose $params.m named by key is 1, if any, as t` as `absent` with `$params.m is missing`, and the Rust engine fails the one-line `every` too under `for: every xs, if any, as x` with `xs` `[]`. So the one-line form should fail as `absent` with `$params.m is missing`. On `main` too. Cases: `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" and the two groups for a `$params.m` that is null and not an object, known failures of both engines. The step that fixes it: both engines read the root before any item in a one-line `every … , if any,`. +- **A one-line `every` with `, if any,` whose `whose` reads a root through the item's own key passes in both engines on an empty list when the root can't be read (type 1, both engines, [tally.walk](semantics.md#counts-and-sums-in-sentences), [for.roots](semantics.md#for), [problems.same_path](semantics.md#which-problems-a-message-says)).** tally.walk says "The same goes for every root [for.roots](#for) names, … `$params` and `$input`, wherever the check reads it: an `every` or `some` phrase, a `whose`, …", and for.roots says "Each root is read once, before any item". With no params and `tests` `[]`, `every tests whose $params.m named by key is 1, if any, exists` passes in both engines, and the same with `$input.m`, `$params.m.d` and the parent's `art.m` holding `3`. A chain passes too: with the params' `k` holding `"a"` and the subject's `key` holding `"a"`, `every tests whose v equals $params.m named by $params.k named by key, if any, exists`, `… named by key named by $params.k, if any, exists` and `… named by pr.key named by key, if any, exists`. Both engines fail `count of tests whose $params.m named by key is 1 is 0` and the `for` line `every tests whose $params.m named by key is 1, if any, as t` as `absent` with `$params.m is missing`, and the Rust engine fails the one-line `every` too under `for: every xs, if any, as x` with `xs` `[]`. So the one-line form should fail as `absent` with `$params.m is missing`. On `main` too. Cases: `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" and the two groups for a `$params.m` that is null and not an object, known failures of both engines. The step that fixes it: both engines read the root before any item in a one-line `every … , if any,`. - **A `named by` key from the subject after the line's alias, under a `for` line with items, is said with the line's item in front by a case (type 3, both engines, a case differs from a rule, [tally.whose](semantics.md#counts-and-sums-in-sentences), [problems.where_said](semantics.md#which-problems-a-message-says)).** With `for: every ms as mm`, `count of xs whose v equals mm named by pr.k is 1`, no `k` on the subject and `ms` and `xs` holding one item each, both engines fail as `absent` with `pr.k is missing`, said once on the assertion. The `sentences` case "a named by key from the subject after a parent or an alias, inside a relative clause" says `item 1 of ms: pr.k is missing`, with the problem on an `item 1 of ms` entry. tally.whose says a key that is missing "is always said, once and before any item", and problems.where_said says a problem in something read from the subject "SHOULD be said once, before any item, with no item in front", so the case differs from both. It is a known failure of both engines. The step that fixes it: a decision on the case's row. - **A `named by` key from the subject that isn't text is listed as `usable`, and two cases say so (type 2, both engines, a case differs from a rule, [path.field_step](semantics.md#reading-a-path)).** With `tests` holding `[]` and the subject's `key` holding `3`, `count of tests whose m named by pr.key is 1 is 0` fails as `unusable` with `pr.key is 3, which isn't text` in both engines, and both list the input `key` with the outcome `usable`. path.field_step says a field that isn't a string ends the path `unusable`, and [What a row shows](semantics.md#what-a-row-shows) says an input's outcome is `unusable` "when the value was read fine but the check can't use it", as the Rust engine lists `$input.k` holding `3`. The `sentences` cases "a named by key from the subject after any path, inside a relative clause" and "a key from the subject that can't be read, in a relative clause" pin a key holding `3` as `usable`, so those cases differ from path.field_step and the outcome rule, which say `unusable`; nothing here proposes a fix, and a decision has to say which of the two is right before any engine or case changes. From 3fbe8ccc60768afec3b5f45d7742eb081e7778d9 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 01:38:08 +0100 Subject: [PATCH 14/57] spec: add cases for a root read through the line alias and the item's key, in either order With xs holding an item and no m in the params the check fails as absent naming item 1 of xs, and with xs empty and if any it passes, since the root is read with each item and not at all when there is none. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rust/sentences/tests/oracle/checks.rs | 12 + spec/cases/sentences/cases.json | 312 +++++++++++++++++- 2 files changed, 323 insertions(+), 1 deletion(-) diff --git a/engines/rust/sentences/tests/oracle/checks.rs b/engines/rust/sentences/tests/oracle/checks.rs index 5d2efeca3..e17cae2e1 100644 --- a/engines/rust/sentences/tests/oracle/checks.rs +++ b/engines/rust/sentences/tests/oracle/checks.rs @@ -133,6 +133,18 @@ pub const CHECK_OK: &[(&str, &str, &[&str], &[&str])] = &[ &[], &[], ), + ( + "count of tests whose v equals $params.m named by key named by x is 0", + "count of tests whose v equals $params.m named by key named by x is 0", + &[], + &[], + ), + ( + "count of tests whose v equals $params.m named by x named by key is 0", + "count of tests whose v equals $params.m named by x named by key is 0", + &[], + &[], + ), ( "every tests whose $input.m named by key is 1, if any, exists", "every tests whose $input.m named by key is 1, if any, exists", diff --git a/spec/cases/sentences/cases.json b/spec/cases/sentences/cases.json index e5d990002..124526b5b 100644 --- a/spec/cases/sentences/cases.json +++ b/spec/cases/sentences/cases.json @@ -107336,5 +107336,315 @@ }, {"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": "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": "fails as absent with the item in front when xs has one item and the params have no m", + "input": { + "prs": [ + { + "id": "p", + "tests": [ + { + "key": "a", + "v": 1 + } + ], + "xs": [ + "a" + ] + } + ] + }, + "results": [ + { + "cause": "absent", + "check": "alias_first", + "failures": [ + { + "cause": "absent", + "failures": [ + { + "cause": "absent", + "failures": [], + "inputs": [ + { + "locations": [ + "/prs/0/tests/0" + ], + "name": "count of tests whose v equals $params.m named by x named by key", + "value": null + } + ], + "kind": "item", + "locations": [ + "/prs/0/xs/0" + ], + "message": "$params.m is missing", + "name": "item 1 of xs", + "value": "a" + } + ], + "inputs": [], + "kind": "assertion", + "locations": [ + "$policy:/requirements/r/checks/alias_first/assert" + ], + "message": "", + "name": "count of tests whose v equals $params.m named by x named by key is 0" + } + ], + "inputs": [ + { + "locations": [ + "/prs/0/tests/0" + ], + "name": "tests[]", + "outcome": "usable", + "value": [ + { + "key": "a", + "v": 1 + } + ] + }, + { + "locations": [ + "/prs/0/xs/0" + ], + "name": "xs[]", + "outcome": "usable", + "value": [ + "a" + ] + } + ], + "message": "item 1 of xs: $params.m is missing", + "passed": false, + "requirement": "r", + "subject": { + "id": "p", + "type": "pr" + } + }, + { + "cause": "absent", + "check": "key_first", + "failures": [ + { + "cause": "absent", + "failures": [ + { + "cause": "absent", + "failures": [], + "inputs": [ + { + "locations": [ + "/prs/0/tests/0" + ], + "name": "count of tests whose v equals $params.m named by key named by x", + "value": null + } + ], + "kind": "item", + "locations": [ + "/prs/0/xs/0" + ], + "message": "$params.m is missing", + "name": "item 1 of xs", + "value": "a" + } + ], + "inputs": [], + "kind": "assertion", + "locations": [ + "$policy:/requirements/r/checks/key_first/assert" + ], + "message": "", + "name": "count of tests whose v equals $params.m named by key named by x is 0" + } + ], + "inputs": [ + { + "locations": [ + "/prs/0/tests/0" + ], + "name": "tests[]", + "outcome": "usable", + "value": [ + { + "key": "a", + "v": 1 + } + ] + }, + { + "locations": [ + "/prs/0/xs/0" + ], + "name": "xs[]", + "outcome": "usable", + "value": [ + "a" + ] + } + ], + "message": "item 1 of xs: $params.m is missing", + "passed": false, + "requirement": "r", + "subject": { + "id": "p", + "type": "pr" + } + } + ], + "rules": [ + "for.roots", + "for.if_any", + "tally.walk" + ] + } + ], + "description": "a root from $params read through the line alias and the item's key, in either order, is read with each item, so a root it doesn't have fails the check when xs has an item, naming the item", + "params": {}, + "policy": { + "ergo_spec": "{{spec}}", + "requirements": { + "r": { + "checks": { + "alias_first": { + "assert": "count of tests whose v equals $params.m named by x named by key is 0", + "for": "every xs, if any, as x" + }, + "key_first": { + "assert": "count of tests whose v equals $params.m named by key named by x is 0", + "for": "every xs, if any, as x" + } + }, + "min_subjects": 0, + "subject": "pr" + } + }, + "subjects": { + "pr": { + "from": "prs", + "identified_by": "id" + } + } + } + }, + { + "cases": [ + { + "description": "passes when xs is empty and the params have no m", + "input": { + "prs": [ + { + "id": "p", + "tests": [ + { + "key": "a", + "v": 1 + } + ], + "xs": [] + } + ] + }, + "results": [ + { + "cause": "satisfied", + "check": "alias_first", + "inputs": [ + { + "locations": [ + "/prs/0/tests/0" + ], + "name": "tests[]", + "value": [ + { + "key": "a", + "v": 1 + } + ] + }, + { + "locations": [], + "name": "xs[]", + "value": [] + } + ], + "passed": true, + "requirement": "r", + "subject": { + "id": "p", + "type": "pr" + } + }, + { + "cause": "satisfied", + "check": "key_first", + "inputs": [ + { + "locations": [ + "/prs/0/tests/0" + ], + "name": "tests[]", + "value": [ + { + "key": "a", + "v": 1 + } + ] + }, + { + "locations": [], + "name": "xs[]", + "value": [] + } + ], + "passed": true, + "requirement": "r", + "subject": { + "id": "p", + "type": "pr" + } + } + ], + "rules": [ + "for.roots", + "for.if_any", + "tally.walk" + ] + } + ], + "description": "a root from $params read through the line alias and the item's key, in either order, is not read at all when xs is empty with if any, so the check passes whether or not the root can be read", + "params": {}, + "policy": { + "ergo_spec": "{{spec}}", + "requirements": { + "r": { + "checks": { + "alias_first": { + "assert": "count of tests whose v equals $params.m named by x named by key is 0", + "for": "every xs, if any, as x" + }, + "key_first": { + "assert": "count of tests whose v equals $params.m named by key named by x is 0", + "for": "every xs, if any, as x" + } + }, + "min_subjects": 0, + "subject": "pr" + } + }, + "subjects": { + "pr": { + "from": "prs", + "identified_by": "id" + } + } + } + } ] From a1ca8b97ec89abb5f930ea3292326f5a4001c724 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 01:38:16 +0100 Subject: [PATCH 15/57] docs: say the cases for the line alias and the item's key copy the Rust rows in spec/OPEN.md Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- spec/OPEN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/OPEN.md b/spec/OPEN.md index c4047edfd..7471a0bba 100644 --- a/spec/OPEN.md +++ b/spec/OPEN.md @@ -104,7 +104,7 @@ OPA 1.20.2 crashes when it compares a number whose exponent is beyond ±1e6 with - **The message of an `item` entry of a `for` line whose list is read through an alias's field that is missing (type 3).** With `for: every ab.items as c`, `assert: c.ok is true` and `ab` holding `[{"ok": true}, {"ok": false}]`, both engines fail as `absent` and say `item 1 of ab: items is missing; item 2 of ab: items is missing`. The message of each item entry is `item 1 of ab: items is missing` in the Rust engine and `items is missing` in `ergo.rego`. With a quoted key like `"a; b"` in place of `items`, it is the same, and the quoted `; ` reads fine in both engines. - **A `named by` key from the subject holding `3`, in `first of` under a `for` line, fails as `absent` in `ergo.rego` and `unusable` in Rust (type 2).** With `for: every xs as x, first of tests whose m named by pr.key is 1 as t`, `assert: t exists`, `key` `3`, `tests` `[]` and `xs` `[{"a": 1}]`, `ergo.rego` says `absent` with `tests is []` and the Rust engine says `unusable` with `pr.key is 3, which isn't text; tests is []`, which follows [path.field_step](semantics.md#reading-a-path). - **The assertion entry of `every tests whose $params.m named by $params.k is 1 exists` lacks the `$params.k` input in `ergo.rego` (type 3).** With the params `{"m": {"a": 1}, "k": "a"}` and `tests` `[]`, the Rust engine lists `$params.k` in the assertion entry's `inputs` and `ergo.rego` lists none. -- **The rows of the `sentences` cases of a root read through a `named by` key from the subject copy the Rust engine for fields no rule decides (type 3).** The groups "a root from $params read through a named by key from the subject ..." (the three of them, with the key on the left of a `whose` and under `for: every xs, if any, as x`) and "a root from $input or the subject itself read through a named by key from the subject ..." (the three of them) pin the verdict, the cause and the message, which [tally.whose](semantics.md#counts-and-sums-in-sentences) and [for.roots](semantics.md#for) decide. A row has to be written whole, so the rows also hold what no rule says (and the rows of the one-line `every` and the line alias cases written for the entries above hold them too, copied from the `count of` rows): whether `$params.m named by pr.key` is an entry of `inputs` at all ([walk.inputs](semantics.md#every-and-some) says both that it lists the path and its key, and that a `$params` path isn't an entry of `inputs`), the `locations` of the count entry (`[]`), whether `tests[]` is in the row's `inputs`, the `locations` of `xs[]` and the `inputs` of an item's entry. The group "a named by key from the subject that isn't text, on the left of a whose with exists, ..." also pins the subject's `key` holding `{}` as an input with the outcome `usable`, and `$params.m named by pr.key` with the outcome `unusable` and the value `null`, which no rule says either, as it is with `is 1`. The two groups for a root read through the item's own key and a key from the subject, in either order, over an empty list with no `m` in the params, copy the Rust engine in the same way (the `key` input with the outcome `usable`, and `$params:` as the location of the missing root, as the nearest rows have it). The cases for a chain with a key from `$params` and the item's key, in either order, copy the same nearest rows and the Rust engine's rows (the `$params.k` input with the outcome `usable`, and `$params:` and `$params:/k` as locations), and the case for a chain of the subject's key and then the item's key, with the params `{"m": {}}`, copies the rows of the nearest case in the same way, with `$params:/m` as the location of the root and `$params.m named by pr.key is missing` as the message, which no rule words for a missing step after a subject key. The group "a count of or sum of whose whose or that reads the line's alias, with or without a named by key, ..." copies the rows of the nearest `for` case on an empty list with `, if any,`, with `tests[].v` holding `[null]` at the item's location and, on the row without `, if any,`, the outcome `usable`. They are what the Rust engine gives, and `ergo.rego` gives the same. Settle them with one rule and then check the rows. +- **The rows of the `sentences` cases of a root read through a `named by` key from the subject copy the Rust engine for fields no rule decides (type 3).** The groups "a root from $params read through a named by key from the subject ..." (the three of them, with the key on the left of a `whose` and under `for: every xs, if any, as x`) and "a root from $input or the subject itself read through a named by key from the subject ..." (the three of them) pin the verdict, the cause and the message, which [tally.whose](semantics.md#counts-and-sums-in-sentences) and [for.roots](semantics.md#for) decide. A row has to be written whole, so the rows also hold what no rule says (and the rows of the one-line `every` and the line alias cases written for the entries above hold them too, copied from the `count of` rows): whether `$params.m named by pr.key` is an entry of `inputs` at all ([walk.inputs](semantics.md#every-and-some) says both that it lists the path and its key, and that a `$params` path isn't an entry of `inputs`), the `locations` of the count entry (`[]`), whether `tests[]` is in the row's `inputs`, the `locations` of `xs[]` and the `inputs` of an item's entry. The group "a named by key from the subject that isn't text, on the left of a whose with exists, ..." also pins the subject's `key` holding `{}` as an input with the outcome `usable`, and `$params.m named by pr.key` with the outcome `unusable` and the value `null`, which no rule says either, as it is with `is 1`. The two groups for a root read through the item's own key and a key from the subject, in either order, over an empty list with no `m` in the params, copy the Rust engine in the same way (the `key` input with the outcome `usable`, and `$params:` as the location of the missing root, as the nearest rows have it). The cases for a chain with a key from `$params` and the item's key, in either order, copy the same nearest rows and the Rust engine's rows (the `$params.k` input with the outcome `usable`, and `$params:` and `$params:/k` as locations), and the case for a chain of the subject's key and then the item's key, with the params `{"m": {}}`, copies the rows of the nearest case in the same way, with `$params:/m` as the location of the root and `$params.m named by pr.key is missing` as the message, which no rule words for a missing step after a subject key. The group "a count of or sum of whose whose or that reads the line's alias, with or without a named by key, ..." copies the rows of the nearest `for` case on an empty list with `, if any,`, with `tests[].v` holding `[null]` at the item's location and, on the row without `, if any,`, the outcome `usable`. They are what the Rust engine gives, and `ergo.rego` gives the same. The two groups for a root read through the line alias and the item's key, in either order, under `for: every xs, if any, as x`, copy the Rust engine's rows in the same way, for `inputs` and `failures`, and pin only the verdict, the cause and the message by rule. Settle them with one rule and then check the rows. - **A chain of two keys from the subject after `exists`, over a list with items, when both keys fail or the value between them can't take a key (type 2, both engines).** The verdicts agree, and with `tests` `[]` so do the cause and the message. With `tests` `[{"v": 1}]`, `pr.key` missing and `pr.j` `3`, `every tests whose $params.m named by pr.key named by pr.j exists exists` fails as `unusable` with `pr.j is 3, which isn't text; pr.key is missing` in the Rust engine, and as `absent` with `pr.key is missing` in `ergo.rego`. [problems.all_said](semantics.md#which-problems-a-message-says) says a message says every problem and the row's cause is the worst of them, so `ergo.rego` is wrong there. The same `count of … is 0` fails as `unusable` in both, but `ergo.rego` says only `pr.key is missing`, and with both keys `null` it says `pr.key is null, and pr.j is null` where the Rust engine says `pr.j is null; pr.key is null`. With `pr.key` `"a"`, `pr.j` `"b"` and the params `{"m": {"a": 1}}`, `count of tests whose $params.m named by pr.key named by pr.j exists is 0` says `item 1 of tests: $params.m named by pr.key is 1, which isn't an object` in the Rust engine, where `ergo.rego` says it once, before any item, with no item in front, as [problems.where_said](semantics.md#which-problems-a-message-says) says for a problem in something read from outside the item. The step that fixes it: `ergo.rego` reads every key of the chain before the items when the list has items too, and the Rust engine says the value between the keys before any item after `exists`. The spec doesn't settle these yet, because the two engines give different reports. Unless a line says otherwise, both fail and pass the same checks. From 5c616b4696afa9481cd97c709688462981d09861 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 02:46:11 +0100 Subject: [PATCH 16/57] 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 746112e3366436dae29731c62792996649a623b7 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 02:52:24 +0100 Subject: [PATCH 17/57] 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 fbcbd4fb9b487b42aa33bca938b84f0328646126 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 02:54:16 +0100 Subject: [PATCH 18/57] 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 f8eff711a9e7b8a8b4215e5f7a598a5d6a6d7546 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 02:59:03 +0100 Subject: [PATCH 19/57] 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 ad930d2d1a4d7edfcf244e8feb55fef8676db9c2 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 02:59:35 +0100 Subject: [PATCH 20/57] 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 5136946c20fffbae87577213597d2ea4769140a7 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 03:22:13 +0100 Subject: [PATCH 21/57] 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 bf37c6959ac08e240bd15cbb81d70912c95fce7b Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 03:26:16 +0100 Subject: [PATCH 22/57] 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 50aa158de4fb5eab99c899d8a90df5e61f6015de Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 03:26:24 +0100 Subject: [PATCH 23/57] 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`. From 21fcc38e57fbe8bbf8e2ebff01e24afadbeac59d Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 04:31:13 +0100 Subject: [PATCH 24/57] rego: add a failing test that a keyed root is read through the subject's key before the item's key Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/tests/lines/roots_test.rego | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/engines/rego/tests/lines/roots_test.rego b/engines/rego/tests/lines/roots_test.rego index 33e0e46b8..68ccadcd4 100644 --- a/engines/rego/tests/lines/roots_test.rego +++ b/engines/rego/tests/lines/roots_test.rego @@ -805,6 +805,15 @@ test_a_key_from_params_in_front_of_the_items_key_keeps_the_root_read_before_any_ } } +test_keyed_root_fault_reads_the_root_through_the_subjects_key_before_the_items_key if { + pr := {"key": "a", "tests": []} + p := ["$$params", "m", {"named_by_field": "\u0003pr\u0003key"}, {"named_by_field": "key"}] + ergo._keyed_root_fault(pr, p) == {"cause": "absent", "text": "$params.m named by pr.key is missing"} with input as {"ergo/names": {"ergo/subject": pr}} with data.ergo_params as {"m": {}} + ergo._keyed_root_fault(pr, p) == {"cause": "null", "text": "$params.m named by pr.key is null"} with input as {"ergo/names": {"ergo/subject": pr}} with data.ergo_params as {"m": {"a": null}} + ergo._keyed_root_fault(pr, p) == {"cause": "absent", "text": "$params.m is missing"} with input as {"ergo/names": {"ergo/subject": pr}} with data.ergo_params as {} + not ergo._keyed_root_fault(pr, p) with input as {"ergo/names": {"ergo/subject": pr}} with data.ergo_params as {"m": {"a": {}}} +} + test_a_bound_line_alias_in_front_of_the_items_key_reads_the_root_before_any_item_of_the_walked_list if { pr := {"key": "a", "tests": []} every p in [ From 6bdc27043c06006c6c9d332a98adf222af8045d3 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 04:33:34 +0100 Subject: [PATCH 25/57] rego: read a keyed root through the subject's key before any item, so a root with no key for it fails on an empty list Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/src/lines/roots.rego | 9 +++++++-- engines/rego/tests/spec_test.rego | 1 - 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/engines/rego/src/lines/roots.rego b/engines/rego/src/lines/roots.rego index 7a22f648f..582722604 100644 --- a/engines/rego/src/lines/roots.rego +++ b/engines/rego/src/lines/roots.rego @@ -892,7 +892,7 @@ _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_read_end(p, k)); f := _keyed_prefix_fault(subj, p, j, k)] count(fs) > 0 } @@ -908,14 +908,19 @@ _keyed_prefix_fault(subj, p, j, k) := {"cause": st, "text": _name_key_said([_inp _keyed_prefix_stops(j, k, v) } +_keyed_read_end(p, k) := _keyed_item_at(p) if _keyed_root_path(p) + +else := k + _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 diff --git a/engines/rego/tests/spec_test.rego b/engines/rego/tests/spec_test.rego index 9f9fc9d9e..36132f7e5 100644 --- a/engines/rego/tests/spec_test.rego +++ b/engines/rego/tests/spec_test.rego @@ -41,7 +41,6 @@ known_differences := { "sentences / a named by key from the subject after a parent or an alias, inside a relative clause / fails as absent once when the subject has no k", "sentences / a root from $input or the subject itself read through a named by key from the subject, in a count of or a sum of over items, is said once on the assertion, and each item the clause can't read is said after it / puts the root on the assertion and gives an item entry only to the item the clause can't read", "sentences / a root from $params read through a named by key from $params and then the item's key is read once, before any item, so a root it doesn't have fails the check on an empty list too / fails as absent naming the root when the params have no m and tests is empty", - "sentences / a root from $params read through a named by key from the subject and then the item's key is read once, before any item, so a root that has no key for the subject's key fails the check on an empty list too / fails as absent naming the root through the subject's key when the params' m has no such key and tests is empty", "sentences / a root from $params read through the item's own key, in a one-line every with if any, is not an object, so it fails as unusable on an empty list / fails as unusable naming $params.m when tests is empty", "sentences / a root from $params read through the item's own key, in a one-line every with if any, is null, so it fails as null on an empty list / fails as null naming $params.m when tests is empty", "sentences / a root read through the item's own key, in a one-line every with if any, is read once, before any item, so it fails on an empty list when it is missing, null or not an object / fails as absent naming $params.m and $input.m when neither is there and tests is empty", From 3df60564e57459beb8f09b9c069dd2d2881ee112 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 04:34:55 +0100 Subject: [PATCH 26/57] rust: add a failing test that a keyed root is read through the subject's key before the item's key Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rust/engine/src/ops/key_base/tests.rs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/engines/rust/engine/src/ops/key_base/tests.rs b/engines/rust/engine/src/ops/key_base/tests.rs index 2ce35053e..a175ea43b 100644 --- a/engines/rust/engine/src/ops/key_base/tests.rs +++ b/engines/rust/engine/src/ops/key_base/tests.rs @@ -708,6 +708,55 @@ fn a_root_read_through_a_key_from_params_and_then_the_items_key_has_its_base_rea assert!(base_of(&path, true, &ctx(&subject, ¶ms, &[])).is_none()); } +fn subject_key() -> Step { + Step::Field(Box::new(Path { + start: Start::Part(Box::new(crate::path::PartStart { + name: "pr".to_string(), + base: Start::Alias(crate::path::OUTER.to_string()), + steps: vec![], + id: None, + })), + steps: vec![Step::Key("key".to_string())], + })) +} + +#[test] +fn a_root_read_through_the_subjects_key_and_then_the_items_key_is_read_up_to_the_items_key_before_any_item() + { + let subject = json!({"key": "a", "tests": []}); + let path = chain(vec![subject_key(), items_key()]); + for (params, text, cause) in [ + ( + json!({"m": {}}), + "$params.m named by pr.key is missing", + Cause::Absent, + ), + ( + json!({"m": {"a": null}}), + "$params.m named by pr.key is null", + Cause::Null, + ), + (json!({}), "$params.m is missing", Cause::Absent), + ] { + let found = base_of( + &path, + true, + &ctx(&subject, ¶ms, &[(crate::path::OUTER, &subject)]), + ) + .map(|(_, t, c)| (t, c)); + assert_eq!(found, Some((text.to_string(), cause))); + } + let params = json!({"m": {"a": {}}}); + assert!( + base_of( + &path, + true, + &ctx(&subject, ¶ms, &[(crate::path::OUTER, &subject)]) + ) + .is_none() + ); +} + fn chain(steps: Vec) -> Path { let mut all = vec![Step::Key("m".to_string())]; all.extend(steps); From 63b2f05034536eea5350ddeb0e78332513990a1e Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 04:36:04 +0100 Subject: [PATCH 27/57] rust: read a keyed root up to the item's key before any item, so a root with no key for the subject's key fails on an empty list The test that pinned no fault for $params.m named by $params.k when m is {} now says it is missing, as tally.walk and for.roots say. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rust/engine/src/ops/key_base.rs | 62 ++++++++++++++----- engines/rust/engine/src/ops/key_base/tests.rs | 6 ++ engines/rust/known-failures.txt | 1 - 3 files changed, 52 insertions(+), 17 deletions(-) diff --git a/engines/rust/engine/src/ops/key_base.rs b/engines/rust/engine/src/ops/key_base.rs index dd3b9d5cd..983be8370 100644 --- a/engines/rust/engine/src/ops/key_base.rs +++ b/engines/rust/engine/src/ops/key_base.rs @@ -253,26 +253,56 @@ pub fn base_of(path: &Path, item_keys: bool, ctx: &Ctx) -> Option<(String, Strin if keys.is_empty() || keys.len() != at { return None; } - base_flaw(&path.start, &keys, false, ctx).map(|(text, cause, input)| (input.name, text, cause)) + if let Some((text, cause, input)) = base_flaw(&path.start, &keys, false, ctx) { + return Some((input.name, text, cause)); + } + let end = at + items_key_at(&path.steps[at..], ctx).filter(|_| item_keys)?; + let prefix = Path { + start: path.start.clone(), + steps: path.steps[..end].to_vec(), + }; + let named = name::name(&prefix); + match path::read(&prefix, ctx) { + path::Read { + outcome: Outcome::Absent, + .. + } => Some((named.clone(), format!("{named} is missing"), Cause::Absent)), + path::Read { + outcome: Outcome::Null, + .. + } => Some((named.clone(), format!("{named} is null"), Cause::Null)), + path::Read { + value: Some(value), .. + } if !value.is_object() => { + let text = message::isnt(&named, value, "an object"); + Some((named, text, Cause::Unusable)) + } + _ => None, + } } fn subject_keys_then_an_items_key(steps: &[Step], ctx: &Ctx) -> bool { - let Some(at) = steps.iter().position(|step| { + items_key_at(steps, ctx).is_some() +} + +fn items_key_at(steps: &[Step], ctx: &Ctx) -> Option { + let at = steps.iter().position(|step| { matches!(step, Step::Field(key) if matches!(key.start, path::Start::Subject | path::Start::Own)) - }) else { - return false; - }; - steps[..at].iter().all(|step| match step { - Step::Key(_) => true, - Step::Field(key) => { - path::names_the_subject(&key.start) - && matches!(path::resolve(step, ctx), Ok(path::Resolved::Key(_))) - } - Step::Ref(key) => { - !super::for_line::path_reads_unbound_alias(key, ctx) && key_flaw(key, ctx).is_none() - } - _ => false, - }) + })?; + steps[..at] + .iter() + .all(|step| match step { + Step::Key(_) => true, + Step::Field(key) => { + path::names_the_subject(&key.start) + && matches!(path::resolve(step, ctx), Ok(path::Resolved::Key(_))) + } + Step::Ref(key) => { + !super::for_line::path_reads_unbound_alias(key, ctx) && key_flaw(key, ctx).is_none() + } + _ => false, + }) + .then_some(at) } /// The key and base problems of every path `check` reads. diff --git a/engines/rust/engine/src/ops/key_base/tests.rs b/engines/rust/engine/src/ops/key_base/tests.rs index a175ea43b..b2970eec1 100644 --- a/engines/rust/engine/src/ops/key_base/tests.rs +++ b/engines/rust/engine/src/ops/key_base/tests.rs @@ -705,6 +705,12 @@ fn a_root_read_through_a_key_from_params_and_then_the_items_key_has_its_base_rea ("$params.m", "$params.m is missing", Cause::Absent) ); let params = json!({"k": "a", "m": {}}); + let (_, text, cause) = base_of(&path, true, &ctx(&subject, ¶ms, &[])).unwrap(); + assert_eq!( + (text.as_str(), cause), + ("$params.m named by $params.k is missing", Cause::Absent) + ); + let params = json!({"k": "a", "m": {"a": {}}}); assert!(base_of(&path, true, &ctx(&subject, ¶ms, &[])).is_none()); } diff --git a/engines/rust/known-failures.txt b/engines/rust/known-failures.txt index a08572995..be5c06d39 100644 --- a/engines/rust/known-failures.txt +++ b/engines/rust/known-failures.txt @@ -416,7 +416,6 @@ sentences / a named by key from the subject after any path, inside a relative cl sentences / a named by key on the right of every, after a part, a parent, an alias, $params or $input / fails as unusable once when the subject's key isn't text sentences / a named by on the right of every that can't be read / names the key that is null, as the plain check does, when m is null too sentences / a root from $params read through a named by key from $params and then the item's key is read once, before any item, so a root it doesn't have fails the check on an empty list too / fails as absent naming the root when the params have no m and tests is empty -sentences / a root from $params read through a named by key from the subject and then the item's key is read once, before any item, so a root that has no key for the subject's key fails the check on an empty list too / fails as absent naming the root through the subject's key when the params' m has no such key and tests is empty sentences / a root from $params read through the item's own key, in a one-line every with if any, is not an object, so it fails as unusable on an empty list / fails as unusable naming $params.m when tests is empty sentences / a root from $params read through the item's own key, in a one-line every with if any, is null, so it fails as null on an empty list / fails as null naming $params.m when tests is empty sentences / a root name on the right of some in a from line's condition, read up front / fails the candidate once, with no item named, even when its list is empty From 36c1c08fe9d48bd1c09183daddbe57500ff7c30a Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 04:36:47 +0100 Subject: [PATCH 28/57] docs: say in the changelogs that a keyed root is read through the subject's key before any item, and drop its open entry Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- CHANGELOG.md | 1 + engines/rust/CHANGELOG.md | 1 + spec/OPEN.md | 1 - 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 086799094..72cc4dfee 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 +- 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`. 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. diff --git a/engines/rust/CHANGELOG.md b/engines/rust/CHANGELOG.md index fa0a07570..4a83a53ed 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 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`. 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`. diff --git a/spec/OPEN.md b/spec/OPEN.md index 569dc43ff..bbe592d6d 100644 --- a/spec/OPEN.md +++ b/spec/OPEN.md @@ -96,7 +96,6 @@ OPA 1.20.2 crashes when it compares a number whose exponent is beyond ±1e6 with - **The `failures` of a `count of` over a list with items, whose `whose` reads a root through a `named by` key from the subject that the root doesn't have (type 3, [row.parts](semantics.md#what-a-row-shows)).** With no params, `count of xs whose v equals $params.m named by pr.k is 1`, the key `"a"` and `xs` holding `[{"v": 1}]` fails as `absent` with `$params.m named by pr.k is missing` in both engines. `ergo.rego` puts the problem on an `item 1 of xs` entry, as the `sentences` case "a key from the subject that can't be read, in a relative clause" pins, and the Rust engine puts it on the assertion, with no item entry. row.parts says "something read outside the item sits on the assertion, once, and items hold only their own problems", so the Rust engine follows the rule and the case doesn't. The same goes for `pr named by pr.k`, and for the key `null`. It is the same with items the clause can't read: with the params `{"m": {"a": 1}}`, the key `"b"` and `tests` holding `[{"v": 1}, {}]`, `count of tests whose v equals $input.m named by pr.key is 0` says `$input.m named by pr.key is missing; item 2 of tests: v is missing` in both engines, and `ergo.rego` adds an `item 1 of tests` entry that holds the root's problem, for `pr named by pr.key`, `count of tests.v that …` and `sum of tests.v whose $params.m named by pr.key is 1` too. The `sentences` case "a root from $input or the subject itself read through a named by key from the subject, in a count of or a sum of over items, ..." follows the rule, so it is in `known_differences`. The step that fixes it: a decision on the case's rows, then `ergo.rego` reads the root before any item there too. - **A key from the subject that can't be read, beside a root that is missing or `null`, in a one-line `every` or `some`, an `every … that` or a `for` line (type 3).** With no params and the key `[]`, `every tests whose v equals $params.d.m named by pr.key exists` fails as `unusable` in both engines. `ergo.rego` says `pr.key is [], which isn't text; $params.d.m named by pr.key is missing` and the Rust engine says only `pr.key is [], which isn't text`, as both engines do for `count of`. A key that is missing, `null` or `3` beside a root that is `null` is the same, in `every`, `some` and `every … that`, with the root `$params.m`, `$input.m`, `pr.m` or the parent's `art.m`: with no key, the params `{"m": null}` and `tests` `[{}]`, `every tests whose v equals $params.m named by pr.key exists` fails as `absent` in both engines, with `pr.key is missing; item 1 of tests: v is missing` in the Rust engine, and `ergo.rego` adds `$params.m is null` after the key. A `for` line's second `whose` is the same: with subjects `art` from `arts` and `pr` from `every art.prs`, the key `3`, `xs` `[{}]` and `tests` `[{"v": 1}]`, `for: every xs as x, every tests whose v equals x.m named by pr.key, if any, as t` with `t exists` fails as `unusable` in both engines, with `pr.key is 3, which isn't text` in the Rust engine and `pr.key is 3, which isn't text; item 1 of xs: x.m named by pr.key is missing` in `ergo.rego`, and `first of tests whose v equals x.m named by pr.key as t` too. [problems.all_said](semantics.md#which-problems-a-message-says) says "A message SHOULD say every problem Ergo finds", and the root can't be read whatever the key holds, so `ergo.rego` follows it here. On `main` `ergo.rego` failed the first one as `absent`. No step is scheduled yet. - **A one-line walk under a `for` line whose root is the line's alias read through a key from the subject says the key twice (type 3, [problems.where_said](semantics.md#which-problems-a-message-says)).** With no key, `xs` `[{"m": null}]` and `tests` `[{}]`, `every tests whose v equals x.m named by pr.key exists` under `for: every xs as x` fails as `absent` in both engines, with `pr.key is missing; item 1 of xs: item 1 of tests: v is missing` in the Rust engine and `pr.key is missing; item 1 of xs: pr.key is missing; x.m is null; item 1 of xs: item 1 of tests: v is missing` in `ergo.rego`. problems.where_said says a key read from outside the item is said once, with no item in front, so the Rust engine follows it, though `ergo.rego` also names `x.m is null`, which [problems.all_said](semantics.md#which-problems-a-message-says) asks for. With `tests` `[{}, {"v": 1}]`, `sum of tests.v that equals x.m named by pr.key is 1` says `pr.key is missing; item 1 of xs: item 1 of tests: v is missing` in the Rust engine and `pr.key is missing; item 1 of tests: v is missing` in `ergo.rego`, which drops `item 1 of xs:` in front. No step is scheduled yet. -- **A chain of a key from the subject and then the item's own key, over an empty list, when the first step of the root is missing from an object that exists (type 1, [tally.walk](semantics.md#counts-and-sums-in-sentences), [for.roots](semantics.md#for)).** tally.walk says "one that's missing or `null` fails it as `absent` or `null`, even when the list is empty", and for.roots says "Each root is read once, before any item". 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` passes in both engines, and should fail as `absent` with `$params.m named by pr.key is missing`, as it does when `named by pr.key` is the last key. Case: `sentences` "a root from $params read through a named by key from the subject and then the item's key is read once, before any item, so a root that has no key for the subject's key fails the check on an empty list too", in `known_differences` and in `engines/rust/known-failures.txt`. The case pins the `count` form and not the other forms. The step: the next burn-down pull request, so that both engines read the root up to the subject's key before any item. - **Which `inputs` a root read through a key that can be read and then the item's own key puts on the row, over an empty list (type 2, both engines, [tally.inputs](semantics.md#counts-and-sums-in-sentences), [tally.whose](semantics.md#counts-and-sums-in-sentences)).** With no `m` in the params, the params' `k` holding `"a"` and `tests` `[]`, `count of tests whose v equals $params.m named by $params.k named by key is 0` fails in both engines as `absent` with `$params.m is missing`, as it should. No rule decides the row's `inputs` here: tally.inputs names only the count and the walked list, and tally.whose puts a key on the assertion's inputs only when it is missing or `null`. The two cases disagree: the case below expects `$params.m named by $params.k named by key` (`absent`) and `$params.k` (`usable`) in the inputs, and the `sentences` case for `$params.m named by key named by $params.k` ("a root from $params read through the item's key and then a named by key from $params …"), which both engines pass, expects no input for the root or the key. Both engines list neither, and put them only in the check's `$refs`. Case: `sentences` "a root from $params read through a named by key from $params and then the item's key is read once, before any item, so a root it doesn't have fails the check on an empty list too", in `known_differences` and in `engines/rust/known-failures.txt`. The step: a decision on which inputs such a row lists, and then both cases follow it. - **A `null` key from the subject on an empty list, in a one-line `every` or `some` (type 2).** With no params, the key `null` and `tests` `[]`, `every tests whose v equals $params.m named by pr.key exists` and `some tests whose v equals $params.m named by pr.key exists` fail as `null` in `ergo.rego` with `pr.key is null; tests is []`, and as `absent` in the Rust engine with `$params.m named by pr.key is missing; pr.key is null; tests is []`. [tally.whose](semantics.md#counts-and-sums-in-sentences) says "each item takes the cause of its own paths, and the row takes the worst of all", and `$params.m` is missing whatever the key holds, so the Rust engine is right. `count of tests whose v equals $params.zz named by pr.key is 0` with `key` `null` is the same: `ergo.rego` says `null` with `pr.key is null`, and the Rust engine says `absent` with `$params.zz named by pr.key is missing; pr.key is null`. With no `m` and the params' `k` `null`, `count of tests whose v equals $params.m named by $params.k named by key is 0` on `[]` is the same, with `$params.k is null` in `ergo.rego` and `$params.m is missing; $params.k is null` in the Rust engine, in the other orders of the keys too. With no `m` and `tests` `[]`, `some tests whose v equals $params.m named by key named by pr.key exists` says `value` with `tests is []` in `ergo.rego` and `absent` with `$params.m is missing; tests is []` in the Rust engine. With no `m` and `tests` `[{"v": 1, "key": "b", "j": "c"}, {"v": 1, "key": "b", "j": 3}]`, `count of tests whose v equals $params.m named by key named by j is 0` says `absent` with `$params.m is missing` in `ergo.rego` and `unusable` with `$params.m is missing; item 2 of tests: j is 3, which isn't text` in the Rust engine, which follows problems.all_said. On `main` too. No step is scheduled yet. - **A root that can't be read, beside a chain of keys that can't be read or a sum, in `ergo.rego` (type 3, [problems.all_said](semantics.md#which-problems-a-message-says), [problems.where_said](semantics.md#which-problems-a-message-says)).** With no `m` in the params and `tests` `[{"v": 1, "key": "b", "j": "c"}, {"v": 1, "key": "b"}]`, `count of tests whose v equals $params.m named by key named by j is 0` says `$params.m is missing` in `ergo.rego` and `$params.m is missing; item 2 of tests: j is missing` in the Rust engine, and with `j` `3` in the second item `ergo.rego` drops `item 2 of tests: j is 3, which isn't text` in the same way, so it no longer says the second key's problem, as it did on `main`. With `tests` `[]`, `sum of v of tests whose v equals $params.m named by key named by pr.key is 0` fails as `absent` in both engines, with `$params.m is missing` in the Rust engine and `sum of v of tests whose v equals $params.m named by key named by pr.key is 0 is false` in `ergo.rego`, which never names `$params.m`. With `named by art.key` or `named by art` where `art` holds an object, both engines fail as `unusable` with `art is an object with 2 keys, which isn't text`, and the Rust engine adds `; $params.m is missing`. No step is scheduled yet. From 2c4556ef1c4b43bf810573828efef0d359fee639 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 05:01:17 +0100 Subject: [PATCH 29/57] rego: add a failing test that a prefix read through the subject's key that isn't an object fails as unusable Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/tests/lines/roots_test.rego | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/engines/rego/tests/lines/roots_test.rego b/engines/rego/tests/lines/roots_test.rego index 68ccadcd4..bdd1d3548 100644 --- a/engines/rego/tests/lines/roots_test.rego +++ b/engines/rego/tests/lines/roots_test.rego @@ -814,6 +814,18 @@ test_keyed_root_fault_reads_the_root_through_the_subjects_key_before_the_items_k not ergo._keyed_root_fault(pr, p) with input as {"ergo/names": {"ergo/subject": pr}} with data.ergo_params as {"m": {"a": {}}} } +test_keyed_root_fault_fails_a_prefix_read_through_the_subjects_key_that_isnt_an_object_as_unusable if { + pr := {"key": "a", "k1": "a", "k2": "c", "tests": []} + names := {"ergo/names": {"ergo/subject": pr}} + p := ["$$params", "m", {"named_by_field": "\u0003pr\u0003key"}, {"named_by_field": "key"}] + ergo._keyed_root_fault(pr, p) == {"cause": "unusable", "text": "$params.m named by pr.key is 3, which isn't an object"} with input as names with data.ergo_params as {"m": {"a": 3}} + ergo._keyed_root_fault(pr, p) == {"cause": "unusable", "text": "$params.m named by pr.key is [], which isn't an object"} with input as names with data.ergo_params as {"m": {"a": []}} + ergo._keyed_root_fault(pr, p) == {"cause": "unusable", "text": "$params.m named by pr.key is \"s\", which isn't an object"} with input as names with data.ergo_params as {"m": {"a": "s"}} + ergo._keyed_root_fault(pr, p) == {"cause": "absent", "text": "$params.m named by pr.key is missing"} with input as names with data.ergo_params as {"m": {}} + chain := ["$$params", "m", {"named_by_field": "\u0003pr\u0003k1"}, {"named_by_field": "\u0003pr\u0003k2"}, {"named_by_field": "key"}] + ergo._keyed_root_fault(pr, chain) == {"cause": "unusable", "text": "$params.m named by pr.k1 is 3, which isn't an object"} with input as names with data.ergo_params as {"m": {"a": 3}} +} + test_a_bound_line_alias_in_front_of_the_items_key_reads_the_root_before_any_item_of_the_walked_list if { pr := {"key": "a", "tests": []} every p in [ From 5fe4c50f43cf705700cdc92c9f9c911a120890fa Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 05:03:16 +0100 Subject: [PATCH 30/57] rego: name a prefix read through the subject's key that isn't an object, so the root fails as unusable on an empty list Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/src/lines/roots.rego | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/rego/src/lines/roots.rego b/engines/rego/src/lines/roots.rego index 582722604..b35211eee 100644 --- a/engines/rego/src/lines/roots.rego +++ b/engines/rego/src/lines/roots.rego @@ -900,7 +900,7 @@ _keyed_prefix_fault(subj, p, j, k) := {"cause": st, "text": _name_key_said([_inp 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) From 1f98417d8cfad89cc142ed386c7c95600fb94a68 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 05:03:42 +0100 Subject: [PATCH 31/57] rego: drop the unreachable end of a keyed read, since every caller reads a keyed root Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/src/lines/roots.rego | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/engines/rego/src/lines/roots.rego b/engines/rego/src/lines/roots.rego index b35211eee..15cc006b0 100644 --- a/engines/rego/src/lines/roots.rego +++ b/engines/rego/src/lines/roots.rego @@ -892,7 +892,7 @@ _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, _keyed_read_end(p, 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 } @@ -908,10 +908,6 @@ _keyed_prefix_fault(subj, p, j, k) := {"cause": st, "text": _name_key_said([_inp _keyed_prefix_stops(j, k, v) } -_keyed_read_end(p, k) := _keyed_item_at(p) if _keyed_root_path(p) - -else := k - _keyed_state_value := {"absent": _absent, "null": null} _keyed_named(p, j, k, st) := _as_subject_part(array.slice(p, 0, k)) if { From 40280f9958482667312fbc522d1adaf0ea605eb6 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 05:06:28 +0100 Subject: [PATCH 32/57] rust: add a failing test that a step before the item's key that isn't an object fails the root as unusable Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rust/engine/src/ops/key_base/tests.rs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/engines/rust/engine/src/ops/key_base/tests.rs b/engines/rust/engine/src/ops/key_base/tests.rs index b2970eec1..de3897f70 100644 --- a/engines/rust/engine/src/ops/key_base/tests.rs +++ b/engines/rust/engine/src/ops/key_base/tests.rs @@ -852,3 +852,34 @@ fn a_bound_line_alias_in_front_of_the_items_key_reads_the_root_before_any_item() assert!(base_of(&chain(steps), true, &ctx(&subject, ¶ms, &[])).is_none()); } } + +#[test] +fn a_root_read_through_the_subjects_key_fails_as_unusable_where_a_step_before_the_items_key_isnt_an_object() + { + let subject = json!({"key": "a", "tests": []}); + let x = json!("c"); + for (steps, params, text) in [ + ( + vec![subject_key(), params_key(), items_key()], + json!({"m": {"a": "s"}, "k": "c"}), + "$params.m named by pr.key is \"s\", which isn't an object", + ), + ( + vec![subject_key(), alias_key(), items_key()], + json!({"m": {"a": 3}}), + "$params.m named by pr.key is 3, which isn't an object", + ), + ] { + let found = base_of( + &chain(steps), + true, + &ctx( + &subject, + ¶ms, + &[(crate::path::OUTER, &subject), ("x", &x)], + ), + ) + .map(|(_, t, c)| (t, c)); + assert_eq!(found, Some((text.to_string(), Cause::Unusable))); + } +} From a6069d97d0206e272eaa7ca58dac3610a8658070 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 05:07:40 +0100 Subject: [PATCH 33/57] rust: read each step before the item's key, so one that isn't an object fails the root as unusable on an empty list Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rust/engine/src/ops/key_base.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/engines/rust/engine/src/ops/key_base.rs b/engines/rust/engine/src/ops/key_base.rs index 983be8370..b6b76572b 100644 --- a/engines/rust/engine/src/ops/key_base.rs +++ b/engines/rust/engine/src/ops/key_base.rs @@ -257,6 +257,17 @@ pub fn base_of(path: &Path, item_keys: bool, ctx: &Ctx) -> Option<(String, Strin return Some((input.name, text, cause)); } let end = at + items_key_at(&path.steps[at..], ctx).filter(|_| item_keys)?; + for stop in at + 1..end { + let before = Path { + start: path.start.clone(), + steps: path.steps[..stop].to_vec(), + }; + if let Some(value) = path::read(&before, ctx).value.filter(|v| !v.is_object()) { + let named = name::name(&before); + let text = message::isnt(&named, &value, "an object"); + return Some((named, text, Cause::Unusable)); + } + } let prefix = Path { start: path.start.clone(), steps: path.steps[..end].to_vec(), From 47434d2494597613cd2b654cbd1ca6d5d4200e2c Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 05:08:06 +0100 Subject: [PATCH 34/57] docs: name every form a keyed root read before any item changes, and list the Rust engine's new causes as open Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- CHANGELOG.md | 2 +- engines/rust/CHANGELOG.md | 2 +- spec/OPEN.md | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72cc4dfee..a29cde778 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 -- 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`. 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. diff --git a/engines/rust/CHANGELOG.md b/engines/rust/CHANGELOG.md index 4a83a53ed..7868aa873 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 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`. 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. In the Rust engine alone, a one-line `some` or `every` without `, if any,` on an empty list now takes the root's cause, like `absent` with `$params.m named by pr.key is missing; tests is []` where it said `value` with `tests is []`, and `count of tests.v that equals $params.m named by pr.key named by key is 0` with an item that isn't an object fails as `not_an_object`, naming the root and the item, where it said `absent`. 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`. diff --git a/spec/OPEN.md b/spec/OPEN.md index bbe592d6d..2115e921f 100644 --- a/spec/OPEN.md +++ b/spec/OPEN.md @@ -97,7 +97,8 @@ OPA 1.20.2 crashes when it compares a number whose exponent is beyond ±1e6 with - **A key from the subject that can't be read, beside a root that is missing or `null`, in a one-line `every` or `some`, an `every … that` or a `for` line (type 3).** With no params and the key `[]`, `every tests whose v equals $params.d.m named by pr.key exists` fails as `unusable` in both engines. `ergo.rego` says `pr.key is [], which isn't text; $params.d.m named by pr.key is missing` and the Rust engine says only `pr.key is [], which isn't text`, as both engines do for `count of`. A key that is missing, `null` or `3` beside a root that is `null` is the same, in `every`, `some` and `every … that`, with the root `$params.m`, `$input.m`, `pr.m` or the parent's `art.m`: with no key, the params `{"m": null}` and `tests` `[{}]`, `every tests whose v equals $params.m named by pr.key exists` fails as `absent` in both engines, with `pr.key is missing; item 1 of tests: v is missing` in the Rust engine, and `ergo.rego` adds `$params.m is null` after the key. A `for` line's second `whose` is the same: with subjects `art` from `arts` and `pr` from `every art.prs`, the key `3`, `xs` `[{}]` and `tests` `[{"v": 1}]`, `for: every xs as x, every tests whose v equals x.m named by pr.key, if any, as t` with `t exists` fails as `unusable` in both engines, with `pr.key is 3, which isn't text` in the Rust engine and `pr.key is 3, which isn't text; item 1 of xs: x.m named by pr.key is missing` in `ergo.rego`, and `first of tests whose v equals x.m named by pr.key as t` too. [problems.all_said](semantics.md#which-problems-a-message-says) says "A message SHOULD say every problem Ergo finds", and the root can't be read whatever the key holds, so `ergo.rego` follows it here. On `main` `ergo.rego` failed the first one as `absent`. No step is scheduled yet. - **A one-line walk under a `for` line whose root is the line's alias read through a key from the subject says the key twice (type 3, [problems.where_said](semantics.md#which-problems-a-message-says)).** With no key, `xs` `[{"m": null}]` and `tests` `[{}]`, `every tests whose v equals x.m named by pr.key exists` under `for: every xs as x` fails as `absent` in both engines, with `pr.key is missing; item 1 of xs: item 1 of tests: v is missing` in the Rust engine and `pr.key is missing; item 1 of xs: pr.key is missing; x.m is null; item 1 of xs: item 1 of tests: v is missing` in `ergo.rego`. problems.where_said says a key read from outside the item is said once, with no item in front, so the Rust engine follows it, though `ergo.rego` also names `x.m is null`, which [problems.all_said](semantics.md#which-problems-a-message-says) asks for. With `tests` `[{}, {"v": 1}]`, `sum of tests.v that equals x.m named by pr.key is 1` says `pr.key is missing; item 1 of xs: item 1 of tests: v is missing` in the Rust engine and `pr.key is missing; item 1 of tests: v is missing` in `ergo.rego`, which drops `item 1 of xs:` in front. No step is scheduled yet. - **Which `inputs` a root read through a key that can be read and then the item's own key puts on the row, over an empty list (type 2, both engines, [tally.inputs](semantics.md#counts-and-sums-in-sentences), [tally.whose](semantics.md#counts-and-sums-in-sentences)).** With no `m` in the params, the params' `k` holding `"a"` and `tests` `[]`, `count of tests whose v equals $params.m named by $params.k named by key is 0` fails in both engines as `absent` with `$params.m is missing`, as it should. No rule decides the row's `inputs` here: tally.inputs names only the count and the walked list, and tally.whose puts a key on the assertion's inputs only when it is missing or `null`. The two cases disagree: the case below expects `$params.m named by $params.k named by key` (`absent`) and `$params.k` (`usable`) in the inputs, and the `sentences` case for `$params.m named by key named by $params.k` ("a root from $params read through the item's key and then a named by key from $params …"), which both engines pass, expects no input for the root or the key. Both engines list neither, and put them only in the check's `$refs`. Case: `sentences` "a root from $params read through a named by key from $params and then the item's key is read once, before any item, so a root it doesn't have fails the check on an empty list too", in `known_differences` and in `engines/rust/known-failures.txt`. The step: a decision on which inputs such a row lists, and then both cases follow it. -- **A `null` key from the subject on an empty list, in a one-line `every` or `some` (type 2).** With no params, the key `null` and `tests` `[]`, `every tests whose v equals $params.m named by pr.key exists` and `some tests whose v equals $params.m named by pr.key exists` fail as `null` in `ergo.rego` with `pr.key is null; tests is []`, and as `absent` in the Rust engine with `$params.m named by pr.key is missing; pr.key is null; tests is []`. [tally.whose](semantics.md#counts-and-sums-in-sentences) says "each item takes the cause of its own paths, and the row takes the worst of all", and `$params.m` is missing whatever the key holds, so the Rust engine is right. `count of tests whose v equals $params.zz named by pr.key is 0` with `key` `null` is the same: `ergo.rego` says `null` with `pr.key is null`, and the Rust engine says `absent` with `$params.zz named by pr.key is missing; pr.key is null`. With no `m` and the params' `k` `null`, `count of tests whose v equals $params.m named by $params.k named by key is 0` on `[]` is the same, with `$params.k is null` in `ergo.rego` and `$params.m is missing; $params.k is null` in the Rust engine, in the other orders of the keys too. With no `m` and `tests` `[]`, `some tests whose v equals $params.m named by key named by pr.key exists` says `value` with `tests is []` in `ergo.rego` and `absent` with `$params.m is missing; tests is []` in the Rust engine. With no `m` and `tests` `[{"v": 1, "key": "b", "j": "c"}, {"v": 1, "key": "b", "j": 3}]`, `count of tests whose v equals $params.m named by key named by j is 0` says `absent` with `$params.m is missing` in `ergo.rego` and `unusable` with `$params.m is missing; item 2 of tests: j is 3, which isn't text` in the Rust engine, which follows problems.all_said. On `main` too. No step is scheduled yet. +- **A `null` key from the subject on an empty list, in a one-line `every` or `some` (type 2).** With no params, the key `null` and `tests` `[]`, `every tests whose v equals $params.m named by pr.key exists` and `some tests whose v equals $params.m named by pr.key exists` fail as `null` in `ergo.rego` with `pr.key is null; tests is []`, and as `absent` in the Rust engine with `$params.m named by pr.key is missing; pr.key is null; tests is []`. [tally.whose](semantics.md#counts-and-sums-in-sentences) says "each item takes the cause of its own paths, and the row takes the worst of all", and `$params.m` is missing whatever the key holds, so the Rust engine is right. `count of tests whose v equals $params.zz named by pr.key is 0` with `key` `null` is the same: `ergo.rego` says `null` with `pr.key is null`, and the Rust engine says `absent` with `$params.zz named by pr.key is missing; pr.key is null`. With no `m` and the params' `k` `null`, `count of tests whose v equals $params.m named by $params.k named by key is 0` on `[]` is the same, with `$params.k is null` in `ergo.rego` and `$params.m is missing; $params.k is null` in the Rust engine, in the other orders of the keys too. With no `m` and `tests` `[]`, `some tests whose v equals $params.m named by key named by pr.key exists` says `value` with `tests is []` in `ergo.rego` and `absent` with `$params.m is missing; tests is []` in the Rust engine. With no `m` and `tests` `[{"v": 1, "key": "b", "j": "c"}, {"v": 1, "key": "b", "j": 3}]`, `count of tests whose v equals $params.m named by key named by j is 0` says `absent` with `$params.m is missing` in `ergo.rego` and `unusable` with `$params.m is missing; item 2 of tests: j is 3, which isn't text` in the Rust engine, which follows problems.all_said. On `main` too. With a key from the subject in front of the item's key, the Rust engine also takes the root's cause where `ergo.rego` doesn't: with the params `{"m": {}}`, `key` "a" and `tests` `[]`, `some tests whose v equals $params.m named by pr.key named by key exists` says `value` with `tests is []` in `ergo.rego` and `absent` with `$params.m named by pr.key is missing; tests is []` in the Rust engine, and the same with `m.a` `null`, `3` or `[]`, and with `every`. Since #960, where the Rust engine reads the root before any item. No step is scheduled yet. +- **A root read through the subject's key beside an item that isn't an object (type 2).** With the params `{"m": {}}`, `key` "a" and `tests` `[{"v": 1, "key": "b"}]`, `count of tests.v that equals $params.m named by pr.key named by key is 0` fails as `absent` with `item 1 of tests: v: $params.m named by pr.key named by key is missing` in `ergo.rego`, and as `not_an_object` with `$params.m named by pr.key is missing; item 1 of tests: v is 1, which isn't an object` in the Rust engine. [problems.all_said](semantics.md#which-problems-a-message-says) says every problem and the worst cause, so the Rust engine is right. Since #960. The step that fixes it reads the root before any item in `ergo.rego`'s `that` too. - **A root that can't be read, beside a chain of keys that can't be read or a sum, in `ergo.rego` (type 3, [problems.all_said](semantics.md#which-problems-a-message-says), [problems.where_said](semantics.md#which-problems-a-message-says)).** With no `m` in the params and `tests` `[{"v": 1, "key": "b", "j": "c"}, {"v": 1, "key": "b"}]`, `count of tests whose v equals $params.m named by key named by j is 0` says `$params.m is missing` in `ergo.rego` and `$params.m is missing; item 2 of tests: j is missing` in the Rust engine, and with `j` `3` in the second item `ergo.rego` drops `item 2 of tests: j is 3, which isn't text` in the same way, so it no longer says the second key's problem, as it did on `main`. With `tests` `[]`, `sum of v of tests whose v equals $params.m named by key named by pr.key is 0` fails as `absent` in both engines, with `$params.m is missing` in the Rust engine and `sum of v of tests whose v equals $params.m named by key named by pr.key is 0 is false` in `ergo.rego`, which never names `$params.m`. With `named by art.key` or `named by art` where `art` holds an object, both engines fail as `unusable` with `art is an object with 2 keys, which isn't text`, and the Rust engine adds `; $params.m is missing`. No step is scheduled yet. - **A `count of`, `every` or `some` whose `whose` reads a parent's or the subject's field through a `null` key from the subject (type 2).** With subjects `art` from `arts` and `pr` from `every art.prs`, the parent's `m` holding `{"a": 1}`, the key `null` and `tests` holding `[{"v": 1}]`, `count of tests whose art.m named by pr.key is 1 is 0` fails in `ergo.rego` as `absent` with `item 1 of tests: .art.m named by pr.key is missing`, and in the Rust engine as `null` with `pr.key is null`. [tally.whose](semantics.md#counts-and-sums-in-sentences) says the key "is always said, once and before any item", so the Rust engine is right. A one-line `every` or `some` is the same, and so is a root from the subject: with the key `null` and `tests` `[{"v": 1}, {}]`, `every tests whose pr named by pr.key is 1, if any, exists` fails in `ergo.rego` as `absent` with `item 1 of tests: .pr named by pr.key is missing; item 2 of tests: .pr named by pr.key is missing`, and in the Rust engine as `null` with `pr.key is null`, and `art.m`, `pr.m` and `some` give the same. The other way round, with `key` `null` and `tests` `[{"v": 1}]`, `count of tests whose t2 named by pr.key exists is 0` and, under `for: every xs, if any, as x`, `count of tests whose x.m named by pr.key exists is 0` fail as `null` with `pr.key is null` in the Rust engine and as `absent` in `ergo.rego`. On `main` too. No case pins it. The step is in `ergo.rego`'s read of a path on the left of a `whose` that starts at a parent or the subject and ends with a key from the subject. - **The message of an `item` entry of a `for` line whose list is read through an alias's field that is missing (type 3).** With `for: every ab.items as c`, `assert: c.ok is true` and `ab` holding `[{"ok": true}, {"ok": false}]`, both engines fail as `absent` and say `item 1 of ab: items is missing; item 2 of ab: items is missing`. The message of each item entry is `item 1 of ab: items is missing` in the Rust engine and `items is missing` in `ergo.rego`. With a quoted key like `"a; b"` in place of `items`, it is the same, and the quoted `; ` reads fine in both engines. From 6e502d7218e99f3221d22a97ff92322a36b637ad Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 05:12:13 +0100 Subject: [PATCH 35/57] spec: add cases for a root read through the subject's key that isn't an object, and the null one, before the item's key on an empty list Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/tests/spec_test.rego | 1 + engines/rust/sentences/tests/oracle/checks.rs | 6 + spec/OPEN.md | 4 +- spec/cases/sentences/cases.json | 519 ++++++++++++++++++ 4 files changed, 529 insertions(+), 1 deletion(-) diff --git a/engines/rego/tests/spec_test.rego b/engines/rego/tests/spec_test.rego index 36132f7e5..c0b355103 100644 --- a/engines/rego/tests/spec_test.rego +++ b/engines/rego/tests/spec_test.rego @@ -43,6 +43,7 @@ known_differences := { "sentences / a root from $params read through a named by key from $params and then the item's key is read once, before any item, so a root it doesn't have fails the check on an empty list too / fails as absent naming the root when the params have no m and tests is empty", "sentences / a root from $params read through the item's own key, in a one-line every with if any, is not an object, so it fails as unusable on an empty list / fails as unusable naming $params.m when tests is empty", "sentences / a root from $params read through the item's own key, in a one-line every with if any, is null, so it fails as null on an empty list / fails as null naming $params.m when tests is empty", + "sentences / a root from $params read through two named by keys from the subject and then the item's key fails the check on an empty list too, when the first one finds a value that isn't an object / fails as unusable naming the value the first key finds when it is 3 and tests is empty", "sentences / a root read through the item's own key, in a one-line every with if any, is read once, before any item, so it fails on an empty list when it is missing, null or not an object / fails as absent naming $params.m and $input.m when neither is there and tests is empty", "sentences / a root read through the item's own key, in a one-line every with if any, is read once, before any item, so it fails on an empty list when it is missing, null or not an object / fails as null naming $input.m when it is null and tests is empty", "sentences / a root read through the item's own key, in a one-line every with if any, is read once, before any item, so it fails on an empty list when it is missing, null or not an object / fails as unusable naming $input.m when it is 3 and tests is empty", diff --git a/engines/rust/sentences/tests/oracle/checks.rs b/engines/rust/sentences/tests/oracle/checks.rs index e17cae2e1..47f94bad3 100644 --- a/engines/rust/sentences/tests/oracle/checks.rs +++ b/engines/rust/sentences/tests/oracle/checks.rs @@ -273,6 +273,12 @@ pub const CHECK_OK: &[(&str, &str, &[&str], &[&str])] = &[ &[], &[], ), + ( + "count of tests whose v equals $params.m named by pr.k1 named by pr.k2 named by key is 0", + "count of tests whose v equals $params.m named by pr.k1 named by pr.k2 named by key is 0", + &[], + &[], + ), ( "count of tests whose v equals x.m named by pr.key is 0", "count of tests whose v equals x.m named by pr.key is 0", diff --git a/spec/OPEN.md b/spec/OPEN.md index 2115e921f..d13f553b0 100644 --- a/spec/OPEN.md +++ b/spec/OPEN.md @@ -100,11 +100,13 @@ OPA 1.20.2 crashes when it compares a number whose exponent is beyond ±1e6 with - **A `null` key from the subject on an empty list, in a one-line `every` or `some` (type 2).** With no params, the key `null` and `tests` `[]`, `every tests whose v equals $params.m named by pr.key exists` and `some tests whose v equals $params.m named by pr.key exists` fail as `null` in `ergo.rego` with `pr.key is null; tests is []`, and as `absent` in the Rust engine with `$params.m named by pr.key is missing; pr.key is null; tests is []`. [tally.whose](semantics.md#counts-and-sums-in-sentences) says "each item takes the cause of its own paths, and the row takes the worst of all", and `$params.m` is missing whatever the key holds, so the Rust engine is right. `count of tests whose v equals $params.zz named by pr.key is 0` with `key` `null` is the same: `ergo.rego` says `null` with `pr.key is null`, and the Rust engine says `absent` with `$params.zz named by pr.key is missing; pr.key is null`. With no `m` and the params' `k` `null`, `count of tests whose v equals $params.m named by $params.k named by key is 0` on `[]` is the same, with `$params.k is null` in `ergo.rego` and `$params.m is missing; $params.k is null` in the Rust engine, in the other orders of the keys too. With no `m` and `tests` `[]`, `some tests whose v equals $params.m named by key named by pr.key exists` says `value` with `tests is []` in `ergo.rego` and `absent` with `$params.m is missing; tests is []` in the Rust engine. With no `m` and `tests` `[{"v": 1, "key": "b", "j": "c"}, {"v": 1, "key": "b", "j": 3}]`, `count of tests whose v equals $params.m named by key named by j is 0` says `absent` with `$params.m is missing` in `ergo.rego` and `unusable` with `$params.m is missing; item 2 of tests: j is 3, which isn't text` in the Rust engine, which follows problems.all_said. On `main` too. With a key from the subject in front of the item's key, the Rust engine also takes the root's cause where `ergo.rego` doesn't: with the params `{"m": {}}`, `key` "a" and `tests` `[]`, `some tests whose v equals $params.m named by pr.key named by key exists` says `value` with `tests is []` in `ergo.rego` and `absent` with `$params.m named by pr.key is missing; tests is []` in the Rust engine, and the same with `m.a` `null`, `3` or `[]`, and with `every`. Since #960, where the Rust engine reads the root before any item. No step is scheduled yet. - **A root read through the subject's key beside an item that isn't an object (type 2).** With the params `{"m": {}}`, `key` "a" and `tests` `[{"v": 1, "key": "b"}]`, `count of tests.v that equals $params.m named by pr.key named by key is 0` fails as `absent` with `item 1 of tests: v: $params.m named by pr.key named by key is missing` in `ergo.rego`, and as `not_an_object` with `$params.m named by pr.key is missing; item 1 of tests: v is 1, which isn't an object` in the Rust engine. [problems.all_said](semantics.md#which-problems-a-message-says) says every problem and the worst cause, so the Rust engine is right. Since #960. The step that fixes it reads the root before any item in `ergo.rego`'s `that` too. - **A root that can't be read, beside a chain of keys that can't be read or a sum, in `ergo.rego` (type 3, [problems.all_said](semantics.md#which-problems-a-message-says), [problems.where_said](semantics.md#which-problems-a-message-says)).** With no `m` in the params and `tests` `[{"v": 1, "key": "b", "j": "c"}, {"v": 1, "key": "b"}]`, `count of tests whose v equals $params.m named by key named by j is 0` says `$params.m is missing` in `ergo.rego` and `$params.m is missing; item 2 of tests: j is missing` in the Rust engine, and with `j` `3` in the second item `ergo.rego` drops `item 2 of tests: j is 3, which isn't text` in the same way, so it no longer says the second key's problem, as it did on `main`. With `tests` `[]`, `sum of v of tests whose v equals $params.m named by key named by pr.key is 0` fails as `absent` in both engines, with `$params.m is missing` in the Rust engine and `sum of v of tests whose v equals $params.m named by key named by pr.key is 0 is false` in `ergo.rego`, which never names `$params.m`. With `named by art.key` or `named by art` where `art` holds an object, both engines fail as `unusable` with `art is an object with 2 keys, which isn't text`, and the Rust engine adds `; $params.m is missing`. No step is scheduled yet. +- **A sum of a root read through the subject's key that finds a value that isn't an object says another message in `ergo.rego` (type 3, [problems.all_said](semantics.md#which-problems-a-message-says)).** With the params `{"m": {"a": 3}}`, `key` "a" and `tests` `[]`, `sum of v of tests whose v equals $params.m named by pr.key named by key is 0` fails as `unusable` in both engines, with `$params.m named by pr.key is 3, which isn't an object` in the Rust engine and `sum of v of tests whose v equals $params.m named by pr.key named by key needs more than 15 digits` in `ergo.rego`, which doesn't name the root. It is the same on `main`. +- **The root entry of a chain of two keys from the subject, when the first finds a value that isn't an object, has the outcome `absent` in `ergo.rego` and `unusable` in the Rust engine (type 2, [tally.inputs](semantics.md#counts-and-sums-in-sentences)).** With the params `{"m": {"a": 3}}`, `k1` "a", `k2` "b" and `tests` `[]`, `count of tests whose v equals $params.m named by pr.k1 named by pr.k2 named by key is 0` fails as `unusable` with `$params.m named by pr.k1 is 3, which isn't an object` in both engines, and the entry `$params.m named by pr.k1 named by pr.k2 named by key` of `inputs` has the outcome `unusable` in the Rust engine and `absent` in `ergo.rego`. With one key from the subject, both say `unusable`. The case "fails as unusable naming the value the first key finds when it is 3 and tests is empty" is listed in `known_differences`. - **A `count of`, `every` or `some` whose `whose` reads a parent's or the subject's field through a `null` key from the subject (type 2).** With subjects `art` from `arts` and `pr` from `every art.prs`, the parent's `m` holding `{"a": 1}`, the key `null` and `tests` holding `[{"v": 1}]`, `count of tests whose art.m named by pr.key is 1 is 0` fails in `ergo.rego` as `absent` with `item 1 of tests: .art.m named by pr.key is missing`, and in the Rust engine as `null` with `pr.key is null`. [tally.whose](semantics.md#counts-and-sums-in-sentences) says the key "is always said, once and before any item", so the Rust engine is right. A one-line `every` or `some` is the same, and so is a root from the subject: with the key `null` and `tests` `[{"v": 1}, {}]`, `every tests whose pr named by pr.key is 1, if any, exists` fails in `ergo.rego` as `absent` with `item 1 of tests: .pr named by pr.key is missing; item 2 of tests: .pr named by pr.key is missing`, and in the Rust engine as `null` with `pr.key is null`, and `art.m`, `pr.m` and `some` give the same. The other way round, with `key` `null` and `tests` `[{"v": 1}]`, `count of tests whose t2 named by pr.key exists is 0` and, under `for: every xs, if any, as x`, `count of tests whose x.m named by pr.key exists is 0` fail as `null` with `pr.key is null` in the Rust engine and as `absent` in `ergo.rego`. On `main` too. No case pins it. The step is in `ergo.rego`'s read of a path on the left of a `whose` that starts at a parent or the subject and ends with a key from the subject. - **The message of an `item` entry of a `for` line whose list is read through an alias's field that is missing (type 3).** With `for: every ab.items as c`, `assert: c.ok is true` and `ab` holding `[{"ok": true}, {"ok": false}]`, both engines fail as `absent` and say `item 1 of ab: items is missing; item 2 of ab: items is missing`. The message of each item entry is `item 1 of ab: items is missing` in the Rust engine and `items is missing` in `ergo.rego`. With a quoted key like `"a; b"` in place of `items`, it is the same, and the quoted `; ` reads fine in both engines. - **A `named by` key from the subject holding `3`, in `first of` under a `for` line, fails as `absent` in `ergo.rego` and `unusable` in Rust (type 2).** With `for: every xs as x, first of tests whose m named by pr.key is 1 as t`, `assert: t exists`, `key` `3`, `tests` `[]` and `xs` `[{"a": 1}]`, `ergo.rego` says `absent` with `tests is []` and the Rust engine says `unusable` with `pr.key is 3, which isn't text; tests is []`, which follows [path.field_step](semantics.md#reading-a-path). - **The assertion entry of `every tests whose $params.m named by $params.k is 1 exists` lacks the `$params.k` input in `ergo.rego` (type 3).** With the params `{"m": {"a": 1}, "k": "a"}` and `tests` `[]`, the Rust engine lists `$params.k` in the assertion entry's `inputs` and `ergo.rego` lists none. -- **The rows of the `sentences` cases of a root read through a `named by` key from the subject copy the Rust engine for fields no rule decides (type 3).** The groups "a root from $params read through a named by key from the subject ..." (the three of them, with the key on the left of a `whose` and under `for: every xs, if any, as x`) and "a root from $input or the subject itself read through a named by key from the subject ..." (the three of them) pin the verdict, the cause and the message, which [tally.whose](semantics.md#counts-and-sums-in-sentences) and [for.roots](semantics.md#for) decide. A row has to be written whole, so the rows also hold what no rule says (and the rows of the one-line `every` and the line alias cases written for the entries above hold them too, copied from the `count of` rows): whether `$params.m named by pr.key` is an entry of `inputs` at all ([walk.inputs](semantics.md#every-and-some) says both that it lists the path and its key, and that a `$params` path isn't an entry of `inputs`), the `locations` of the count entry (`[]`), whether `tests[]` is in the row's `inputs`, the `locations` of `xs[]` and the `inputs` of an item's entry. The group "a named by key from the subject that isn't text, on the left of a whose with exists, ..." also pins the subject's `key` holding `{}` as an input with the outcome `usable`, and `$params.m named by pr.key` with the outcome `unusable` and the value `null`, which no rule says either, as it is with `is 1`. The two groups for a root read through the item's own key and a key from the subject, in either order, over an empty list with no `m` in the params, copy the Rust engine in the same way (the `key` input with the outcome `usable`, and `$params:` as the location of the missing root, as the nearest rows have it). The cases for a chain with a key from `$params` and the item's key, in either order, copy the same nearest rows and the Rust engine's rows (the `$params.k` input with the outcome `usable`, and `$params:` and `$params:/k` as locations), and the case for a chain of the subject's key and then the item's key, with the params `{"m": {}}`, copies the rows of the nearest case in the same way, with `$params:/m` as the location of the root and `$params.m named by pr.key is missing` as the message, which no rule words for a missing step after a subject key. The group "a count of or sum of whose whose or that reads the line's alias, with or without a named by key, ..." copies the rows of the nearest `for` case on an empty list with `, if any,`, with `tests[].v` holding `[null]` at the item's location and, on the row without `, if any,`, the outcome `usable`. They are what the Rust engine gives, and `ergo.rego` gives the same. The two groups for a root read through the line alias and the item's key, in either order, under `for: every xs, if any, as x`, copy the Rust engine's rows in the same way, for `inputs` and `failures`, and pin only the verdict, the cause and the message by rule. Settle them with one rule and then check the rows. +- **The rows of the `sentences` cases of a root read through a `named by` key from the subject copy the Rust engine for fields no rule decides (type 3).** The groups "a root from $params read through a named by key from the subject ..." (the three of them, with the key on the left of a `whose` and under `for: every xs, if any, as x`) and "a root from $input or the subject itself read through a named by key from the subject ..." (the three of them) pin the verdict, the cause and the message, which [tally.whose](semantics.md#counts-and-sums-in-sentences) and [for.roots](semantics.md#for) decide. A row has to be written whole, so the rows also hold what no rule says (and the rows of the one-line `every` and the line alias cases written for the entries above hold them too, copied from the `count of` rows): whether `$params.m named by pr.key` is an entry of `inputs` at all ([walk.inputs](semantics.md#every-and-some) says both that it lists the path and its key, and that a `$params` path isn't an entry of `inputs`), the `locations` of the count entry (`[]`), whether `tests[]` is in the row's `inputs`, the `locations` of `xs[]` and the `inputs` of an item's entry. The group "a named by key from the subject that isn't text, on the left of a whose with exists, ..." also pins the subject's `key` holding `{}` as an input with the outcome `usable`, and `$params.m named by pr.key` with the outcome `unusable` and the value `null`, which no rule says either, as it is with `is 1`. The two groups for a root read through the item's own key and a key from the subject, in either order, over an empty list with no `m` in the params, copy the Rust engine in the same way (the `key` input with the outcome `usable`, and `$params:` as the location of the missing root, as the nearest rows have it). The cases for a chain with a key from `$params` and the item's key, in either order, copy the same nearest rows and the Rust engine's rows (the `$params.k` input with the outcome `usable`, and `$params:` and `$params:/k` as locations), and the case for a chain of the subject's key and then the item's key, with the params `{"m": {}}`, copies the rows of the nearest case in the same way, with `$params:/m` as the location of the root and `$params.m named by pr.key is missing` as the message, which no rule words for a missing step after a subject key. The group "a count of or sum of whose whose or that reads the line's alias, with or without a named by key, ..." copies the rows of the nearest `for` case on an empty list with `, if any,`, with `tests[].v` holding `[null]` at the item's location and, on the row without `, if any,`, the outcome `usable`. They are what the Rust engine gives, and `ergo.rego` gives the same. The two groups for a root read through the line alias and the item's key, in either order, under `for: every xs, if any, as x`, copy the Rust engine's rows in the same way, for `inputs` and `failures`, and pin only the verdict, the cause and the message by rule. The four groups for a root read through the subject's key and then the item's key, with the params' `m` `null`, `{"a": 3}` or `{"a": []}`, and for two keys from the subject with `{"a": 3}`, over an empty list, copy the Rust engine's rows for `inputs` and `failures` in the same way, after the verdict, the cause and the message, which tally.walk and for.roots decide, were the same in both engines. Settle them with one rule and then check the rows. - **A chain of two keys from the subject after `exists`, over a list with items, when both keys fail or the value between them can't take a key (type 2, both engines).** The verdicts agree, and with `tests` `[]` so do the cause and the message. With `tests` `[{"v": 1}]`, `pr.key` missing and `pr.j` `3`, `every tests whose $params.m named by pr.key named by pr.j exists exists` fails as `unusable` with `pr.j is 3, which isn't text; pr.key is missing` in the Rust engine, and as `absent` with `pr.key is missing` in `ergo.rego`. [problems.all_said](semantics.md#which-problems-a-message-says) says a message says every problem and the row's cause is the worst of them, so `ergo.rego` is wrong there. The same `count of … is 0` fails as `unusable` in both, but `ergo.rego` says only `pr.key is missing`, and with both keys `null` it says `pr.key is null, and pr.j is null` where the Rust engine says `pr.j is null; pr.key is null`. With `pr.key` `"a"`, `pr.j` `"b"` and the params `{"m": {"a": 1}}`, `count of tests whose $params.m named by pr.key named by pr.j exists is 0` says `item 1 of tests: $params.m named by pr.key is 1, which isn't an object` in the Rust engine, where `ergo.rego` says it once, before any item, with no item in front, as [problems.where_said](semantics.md#which-problems-a-message-says) says for a problem in something read from outside the item. The step that fixes it: `ergo.rego` reads every key of the chain before the items when the list has items too, and the Rust engine says the value between the keys before any item after `exists`. The spec doesn't settle these yet, because the two engines give different reports. Unless a line says otherwise, both fail and pass the same checks. diff --git a/spec/cases/sentences/cases.json b/spec/cases/sentences/cases.json index 9b31f8b39..e0d977b85 100644 --- a/spec/cases/sentences/cases.json +++ b/spec/cases/sentences/cases.json @@ -107647,5 +107647,524 @@ } } } + }, + { + "cases": [ + { + "description": "fails as null naming the root when the params' m is null and tests is empty", + "input": { + "prs": [ + { + "id": "p", + "key": "a", + "tests": [] + } + ] + }, + "results": [ + { + "cause": "null", + "check": "count", + "failures": [ + { + "cause": "null", + "failures": [], + "inputs": [ + { + "locations": [], + "name": "count of tests whose v equals $params.m named by pr.key named by key", + "value": null + }, + { + "locations": [ + "$params:/m" + ], + "name": "$params.m named by pr.key named by key", + "outcome": "null", + "value": null + }, + { + "locations": [ + "/prs/0/key" + ], + "name": "key", + "outcome": "usable", + "value": "a" + } + ], + "kind": "assertion", + "locations": [ + "$policy:/requirements/r/checks/count" + ], + "message": "$params.m is null", + "name": "count of tests whose v equals $params.m named by pr.key named by key is 0" + } + ], + "inputs": [ + { + "locations": [], + "name": "count of tests whose v equals $params.m named by pr.key named by key", + "value": null + }, + { + "locations": [], + "name": "tests[]", + "outcome": "usable", + "value": [] + }, + { + "locations": [ + "$params:/m" + ], + "name": "$params.m named by pr.key named by key", + "outcome": "null", + "value": null + }, + { + "locations": [ + "/prs/0/key" + ], + "name": "key", + "outcome": "usable", + "value": "a" + } + ], + "message": "$params.m is null", + "passed": false, + "requirement": "r", + "subject": { + "id": "p", + "type": "pr" + } + } + ], + "rules": [ + "tally.walk", + "sentence.path.subject.step", + "path.field_step" + ] + } + ], + "description": "a root from $params that is null, read through a named by key from the subject and then the item's key, fails the check on an empty list too", + "params": { + "m": null + }, + "policy": { + "ergo_spec": "{{spec}}", + "requirements": { + "r": { + "checks": { + "count": "count of tests whose v equals $params.m named by pr.key named by key is 0" + }, + "min_subjects": 0, + "subject": "pr" + } + }, + "subjects": { + "pr": { + "from": "prs", + "identified_by": "id" + } + } + } + }, + { + "cases": [ + { + "description": "fails as unusable naming the value the subject's key finds when it is 3 and tests is empty", + "input": { + "prs": [ + { + "id": "p", + "key": "a", + "tests": [] + } + ] + }, + "results": [ + { + "cause": "unusable", + "check": "count", + "failures": [ + { + "cause": "unusable", + "failures": [], + "inputs": [ + { + "locations": [], + "name": "count of tests whose v equals $params.m named by pr.key named by key", + "value": null + }, + { + "locations": [ + "$params:/m/a" + ], + "name": "$params.m named by pr.key named by key", + "outcome": "unusable", + "value": null + }, + { + "locations": [ + "/prs/0/key" + ], + "name": "key", + "outcome": "usable", + "value": "a" + } + ], + "kind": "assertion", + "locations": [ + "$policy:/requirements/r/checks/count" + ], + "message": "$params.m named by pr.key is 3, which isn't an object", + "name": "count of tests whose v equals $params.m named by pr.key named by key is 0" + } + ], + "inputs": [ + { + "locations": [], + "name": "count of tests whose v equals $params.m named by pr.key named by key", + "value": null + }, + { + "locations": [], + "name": "tests[]", + "outcome": "usable", + "value": [] + }, + { + "locations": [ + "$params:/m/a" + ], + "name": "$params.m named by pr.key named by key", + "outcome": "unusable", + "value": null + }, + { + "locations": [ + "/prs/0/key" + ], + "name": "key", + "outcome": "usable", + "value": "a" + } + ], + "message": "$params.m named by pr.key is 3, which isn't an object", + "passed": false, + "requirement": "r", + "subject": { + "id": "p", + "type": "pr" + } + } + ], + "rules": [ + "tally.walk", + "sentence.path.subject.step", + "path.field_step" + ] + } + ], + "description": "a root from $params read through a named by key from the subject that finds a value that isn't an object, and then the item's key, fails the check on an empty list too", + "params": { + "m": { + "a": 3 + } + }, + "policy": { + "ergo_spec": "{{spec}}", + "requirements": { + "r": { + "checks": { + "count": "count of tests whose v equals $params.m named by pr.key named by key is 0" + }, + "min_subjects": 0, + "subject": "pr" + } + }, + "subjects": { + "pr": { + "from": "prs", + "identified_by": "id" + } + } + } + }, + { + "cases": [ + { + "description": "fails as unusable naming the value the subject's key finds when it is an empty list and tests is empty", + "input": { + "prs": [ + { + "id": "p", + "key": "a", + "tests": [] + } + ] + }, + "results": [ + { + "cause": "unusable", + "check": "count", + "failures": [ + { + "cause": "unusable", + "failures": [], + "inputs": [ + { + "locations": [], + "name": "count of tests whose v equals $params.m named by pr.key named by key", + "value": null + }, + { + "locations": [ + "$params:/m/a" + ], + "name": "$params.m named by pr.key named by key", + "outcome": "unusable", + "value": null + }, + { + "locations": [ + "/prs/0/key" + ], + "name": "key", + "outcome": "usable", + "value": "a" + } + ], + "kind": "assertion", + "locations": [ + "$policy:/requirements/r/checks/count" + ], + "message": "$params.m named by pr.key is [], which isn't an object", + "name": "count of tests whose v equals $params.m named by pr.key named by key is 0" + } + ], + "inputs": [ + { + "locations": [], + "name": "count of tests whose v equals $params.m named by pr.key named by key", + "value": null + }, + { + "locations": [], + "name": "tests[]", + "outcome": "usable", + "value": [] + }, + { + "locations": [ + "$params:/m/a" + ], + "name": "$params.m named by pr.key named by key", + "outcome": "unusable", + "value": null + }, + { + "locations": [ + "/prs/0/key" + ], + "name": "key", + "outcome": "usable", + "value": "a" + } + ], + "message": "$params.m named by pr.key is [], which isn't an object", + "passed": false, + "requirement": "r", + "subject": { + "id": "p", + "type": "pr" + } + } + ], + "rules": [ + "tally.walk", + "sentence.path.subject.step", + "path.field_step" + ] + } + ], + "description": "a root from $params read through a named by key from the subject that finds a list, and then the item's key, fails the check on an empty list too", + "params": { + "m": { + "a": [] + } + }, + "policy": { + "ergo_spec": "{{spec}}", + "requirements": { + "r": { + "checks": { + "count": "count of tests whose v equals $params.m named by pr.key named by key is 0" + }, + "min_subjects": 0, + "subject": "pr" + } + }, + "subjects": { + "pr": { + "from": "prs", + "identified_by": "id" + } + } + } + }, + { + "cases": [ + { + "description": "fails as unusable naming the value the first key finds when it is 3 and tests is empty", + "input": { + "prs": [ + { + "id": "p", + "k1": "a", + "k2": "b", + "tests": [] + } + ] + }, + "results": [ + { + "cause": "unusable", + "check": "count", + "failures": [ + { + "cause": "unusable", + "failures": [], + "inputs": [ + { + "locations": [], + "name": "count of tests whose v equals $params.m named by pr.k1 named by pr.k2 named by key", + "value": null + }, + { + "locations": [ + "$params:/m/a" + ], + "name": "$params.m named by pr.k1 named by pr.k2 named by key", + "outcome": "unusable", + "value": null + }, + { + "locations": [ + "/prs/0/k1" + ], + "name": "k1", + "outcome": "usable", + "value": "a" + }, + { + "locations": [ + "/prs/0/k2" + ], + "name": "k2", + "outcome": "usable", + "value": "b" + }, + { + "locations": [ + "/prs/0" + ], + "name": "key", + "outcome": "absent", + "value": null + } + ], + "kind": "assertion", + "locations": [ + "$policy:/requirements/r/checks/count" + ], + "message": "$params.m named by pr.k1 is 3, which isn't an object", + "name": "count of tests whose v equals $params.m named by pr.k1 named by pr.k2 named by key is 0" + } + ], + "inputs": [ + { + "locations": [], + "name": "count of tests whose v equals $params.m named by pr.k1 named by pr.k2 named by key", + "value": null + }, + { + "locations": [], + "name": "tests[]", + "outcome": "usable", + "value": [] + }, + { + "locations": [ + "$params:/m/a" + ], + "name": "$params.m named by pr.k1 named by pr.k2 named by key", + "outcome": "unusable", + "value": null + }, + { + "locations": [ + "/prs/0/k1" + ], + "name": "k1", + "outcome": "usable", + "value": "a" + }, + { + "locations": [ + "/prs/0/k2" + ], + "name": "k2", + "outcome": "usable", + "value": "b" + }, + { + "locations": [ + "/prs/0" + ], + "name": "key", + "outcome": "absent", + "value": null + } + ], + "message": "$params.m named by pr.k1 is 3, which isn't an object", + "passed": false, + "requirement": "r", + "subject": { + "id": "p", + "type": "pr" + } + } + ], + "rules": [ + "tally.walk", + "sentence.path.subject.step", + "path.field_step" + ] + } + ], + "description": "a root from $params read through two named by keys from the subject and then the item's key fails the check on an empty list too, when the first one finds a value that isn't an object", + "params": { + "m": { + "a": 3 + } + }, + "policy": { + "ergo_spec": "{{spec}}", + "requirements": { + "r": { + "checks": { + "count": "count of tests whose v equals $params.m named by pr.k1 named by pr.k2 named by key is 0" + }, + "min_subjects": 0, + "subject": "pr" + } + }, + "subjects": { + "pr": { + "from": "prs", + "identified_by": "id" + } + } + } } ] From 572c62ded327a2429cc6826a5456ac650cddfbfa Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 05:12:41 +0100 Subject: [PATCH 36/57] rego: list the call of a keyed prefix fault to the message that names it among the known backward calls Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/layers-known.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/engines/rego/layers-known.txt b/engines/rego/layers-known.txt index ce9920c18..9cff45b6d 100644 --- a/engines/rego/layers-known.txt +++ b/engines/rego/layers-known.txt @@ -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 From 518035d65769fe9815a78fb6c4807734f891e1f8 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 06:09:16 +0100 Subject: [PATCH 37/57] rust: drop a needless borrow in key_base Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rust/engine/src/ops/key_base.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/rust/engine/src/ops/key_base.rs b/engines/rust/engine/src/ops/key_base.rs index b6b76572b..3167288ba 100644 --- a/engines/rust/engine/src/ops/key_base.rs +++ b/engines/rust/engine/src/ops/key_base.rs @@ -264,7 +264,7 @@ pub fn base_of(path: &Path, item_keys: bool, ctx: &Ctx) -> Option<(String, Strin }; if let Some(value) = path::read(&before, ctx).value.filter(|v| !v.is_object()) { let named = name::name(&before); - let text = message::isnt(&named, &value, "an object"); + let text = message::isnt(&named, value, "an object"); return Some((named, text, Cause::Unusable)); } } From 4e2e256d6878c6ba2b1a5119beb012f8831d7784 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 06:10:46 +0100 Subject: [PATCH 38/57] docs: say what main does for the sum with a wrong-typed prefix Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- spec/OPEN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/OPEN.md b/spec/OPEN.md index d13f553b0..5dd951a97 100644 --- a/spec/OPEN.md +++ b/spec/OPEN.md @@ -100,7 +100,7 @@ OPA 1.20.2 crashes when it compares a number whose exponent is beyond ±1e6 with - **A `null` key from the subject on an empty list, in a one-line `every` or `some` (type 2).** With no params, the key `null` and `tests` `[]`, `every tests whose v equals $params.m named by pr.key exists` and `some tests whose v equals $params.m named by pr.key exists` fail as `null` in `ergo.rego` with `pr.key is null; tests is []`, and as `absent` in the Rust engine with `$params.m named by pr.key is missing; pr.key is null; tests is []`. [tally.whose](semantics.md#counts-and-sums-in-sentences) says "each item takes the cause of its own paths, and the row takes the worst of all", and `$params.m` is missing whatever the key holds, so the Rust engine is right. `count of tests whose v equals $params.zz named by pr.key is 0` with `key` `null` is the same: `ergo.rego` says `null` with `pr.key is null`, and the Rust engine says `absent` with `$params.zz named by pr.key is missing; pr.key is null`. With no `m` and the params' `k` `null`, `count of tests whose v equals $params.m named by $params.k named by key is 0` on `[]` is the same, with `$params.k is null` in `ergo.rego` and `$params.m is missing; $params.k is null` in the Rust engine, in the other orders of the keys too. With no `m` and `tests` `[]`, `some tests whose v equals $params.m named by key named by pr.key exists` says `value` with `tests is []` in `ergo.rego` and `absent` with `$params.m is missing; tests is []` in the Rust engine. With no `m` and `tests` `[{"v": 1, "key": "b", "j": "c"}, {"v": 1, "key": "b", "j": 3}]`, `count of tests whose v equals $params.m named by key named by j is 0` says `absent` with `$params.m is missing` in `ergo.rego` and `unusable` with `$params.m is missing; item 2 of tests: j is 3, which isn't text` in the Rust engine, which follows problems.all_said. On `main` too. With a key from the subject in front of the item's key, the Rust engine also takes the root's cause where `ergo.rego` doesn't: with the params `{"m": {}}`, `key` "a" and `tests` `[]`, `some tests whose v equals $params.m named by pr.key named by key exists` says `value` with `tests is []` in `ergo.rego` and `absent` with `$params.m named by pr.key is missing; tests is []` in the Rust engine, and the same with `m.a` `null`, `3` or `[]`, and with `every`. Since #960, where the Rust engine reads the root before any item. No step is scheduled yet. - **A root read through the subject's key beside an item that isn't an object (type 2).** With the params `{"m": {}}`, `key` "a" and `tests` `[{"v": 1, "key": "b"}]`, `count of tests.v that equals $params.m named by pr.key named by key is 0` fails as `absent` with `item 1 of tests: v: $params.m named by pr.key named by key is missing` in `ergo.rego`, and as `not_an_object` with `$params.m named by pr.key is missing; item 1 of tests: v is 1, which isn't an object` in the Rust engine. [problems.all_said](semantics.md#which-problems-a-message-says) says every problem and the worst cause, so the Rust engine is right. Since #960. The step that fixes it reads the root before any item in `ergo.rego`'s `that` too. - **A root that can't be read, beside a chain of keys that can't be read or a sum, in `ergo.rego` (type 3, [problems.all_said](semantics.md#which-problems-a-message-says), [problems.where_said](semantics.md#which-problems-a-message-says)).** With no `m` in the params and `tests` `[{"v": 1, "key": "b", "j": "c"}, {"v": 1, "key": "b"}]`, `count of tests whose v equals $params.m named by key named by j is 0` says `$params.m is missing` in `ergo.rego` and `$params.m is missing; item 2 of tests: j is missing` in the Rust engine, and with `j` `3` in the second item `ergo.rego` drops `item 2 of tests: j is 3, which isn't text` in the same way, so it no longer says the second key's problem, as it did on `main`. With `tests` `[]`, `sum of v of tests whose v equals $params.m named by key named by pr.key is 0` fails as `absent` in both engines, with `$params.m is missing` in the Rust engine and `sum of v of tests whose v equals $params.m named by key named by pr.key is 0 is false` in `ergo.rego`, which never names `$params.m`. With `named by art.key` or `named by art` where `art` holds an object, both engines fail as `unusable` with `art is an object with 2 keys, which isn't text`, and the Rust engine adds `; $params.m is missing`. No step is scheduled yet. -- **A sum of a root read through the subject's key that finds a value that isn't an object says another message in `ergo.rego` (type 3, [problems.all_said](semantics.md#which-problems-a-message-says)).** With the params `{"m": {"a": 3}}`, `key` "a" and `tests` `[]`, `sum of v of tests whose v equals $params.m named by pr.key named by key is 0` fails as `unusable` in both engines, with `$params.m named by pr.key is 3, which isn't an object` in the Rust engine and `sum of v of tests whose v equals $params.m named by pr.key named by key needs more than 15 digits` in `ergo.rego`, which doesn't name the root. It is the same on `main`. +- **A sum of a root read through the subject's key that finds a value that isn't an object says another message in `ergo.rego` (type 3, [problems.all_said](semantics.md#which-problems-a-message-says)).** With the params `{"m": {"a": 3}}`, `key` "a" and `tests` `[]`, `sum of v of tests whose v equals $params.m named by pr.key named by key is 0` fails as `unusable` in both engines, with `$params.m named by pr.key is 3, which isn't an object` in the Rust engine and `sum of v of tests whose v equals $params.m named by pr.key named by key needs more than 15 digits` in `ergo.rego`, which doesn't name the root. On `main` both engines pass this check, because neither reads the root before an item and the list is empty. Since #960. - **The root entry of a chain of two keys from the subject, when the first finds a value that isn't an object, has the outcome `absent` in `ergo.rego` and `unusable` in the Rust engine (type 2, [tally.inputs](semantics.md#counts-and-sums-in-sentences)).** With the params `{"m": {"a": 3}}`, `k1` "a", `k2` "b" and `tests` `[]`, `count of tests whose v equals $params.m named by pr.k1 named by pr.k2 named by key is 0` fails as `unusable` with `$params.m named by pr.k1 is 3, which isn't an object` in both engines, and the entry `$params.m named by pr.k1 named by pr.k2 named by key` of `inputs` has the outcome `unusable` in the Rust engine and `absent` in `ergo.rego`. With one key from the subject, both say `unusable`. The case "fails as unusable naming the value the first key finds when it is 3 and tests is empty" is listed in `known_differences`. - **A `count of`, `every` or `some` whose `whose` reads a parent's or the subject's field through a `null` key from the subject (type 2).** With subjects `art` from `arts` and `pr` from `every art.prs`, the parent's `m` holding `{"a": 1}`, the key `null` and `tests` holding `[{"v": 1}]`, `count of tests whose art.m named by pr.key is 1 is 0` fails in `ergo.rego` as `absent` with `item 1 of tests: .art.m named by pr.key is missing`, and in the Rust engine as `null` with `pr.key is null`. [tally.whose](semantics.md#counts-and-sums-in-sentences) says the key "is always said, once and before any item", so the Rust engine is right. A one-line `every` or `some` is the same, and so is a root from the subject: with the key `null` and `tests` `[{"v": 1}, {}]`, `every tests whose pr named by pr.key is 1, if any, exists` fails in `ergo.rego` as `absent` with `item 1 of tests: .pr named by pr.key is missing; item 2 of tests: .pr named by pr.key is missing`, and in the Rust engine as `null` with `pr.key is null`, and `art.m`, `pr.m` and `some` give the same. The other way round, with `key` `null` and `tests` `[{"v": 1}]`, `count of tests whose t2 named by pr.key exists is 0` and, under `for: every xs, if any, as x`, `count of tests whose x.m named by pr.key exists is 0` fail as `null` with `pr.key is null` in the Rust engine and as `absent` in `ergo.rego`. On `main` too. No case pins it. The step is in `ergo.rego`'s read of a path on the left of a `whose` that starts at a parent or the subject and ends with a key from the subject. - **The message of an `item` entry of a `for` line whose list is read through an alias's field that is missing (type 3).** With `for: every ab.items as c`, `assert: c.ok is true` and `ab` holding `[{"ok": true}, {"ok": false}]`, both engines fail as `absent` and say `item 1 of ab: items is missing; item 2 of ab: items is missing`. The message of each item entry is `item 1 of ab: items is missing` in the Rust engine and `items is missing` in `ergo.rego`. With a quoted key like `"a; b"` in place of `items`, it is the same, and the quoted `; ` reads fine in both engines. From 8a66412e405779b177585891a88cbb0a60375626 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 06:31:58 +0100 Subject: [PATCH 39/57] rego: add a failing test that a one-line walk reads a root through the item's key before any item Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/tests/lines/roots_test.rego | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/engines/rego/tests/lines/roots_test.rego b/engines/rego/tests/lines/roots_test.rego index bdd1d3548..e6148fd61 100644 --- a/engines/rego/tests/lines/roots_test.rego +++ b/engines/rego/tests/lines/roots_test.rego @@ -971,3 +971,15 @@ test_a_whose_root_read_through_a_named_by_key_that_is_the_line_alias_holding_a_n names := ergo._bound({"ergo/subject": subj, "$at": {"names": {}}}, "x", 3, "/xs/0") ergo._root_read_flaw(subj, cond) == "unusable" with input as {"ergo/names": names} with data.ergo_params as {"m": {"a": [1]}} } + +test_a_one_line_walk_reads_a_root_through_the_items_key_before_any_item if { + every sentence in ["every tests whose $params.m named by key is 1, if any, exists", "some tests whose $params.m named by key is 1, if any, exists"] { + check := ergo._s_written_check(sentence) + subj := {"tests": []} + names := {"ergo/names": {"ergo/subject": subj}} + ergo._walk_root_flaw(check, subj) == "absent" with input as names with data.ergo_params as {} + ergo._walk_root_flaw(check, subj) == "null" with input as names with data.ergo_params as {"m": null} + ergo._walk_root_flaw(check, subj) == "unusable" with input as names with data.ergo_params as {"m": 3} + ergo._walk_root_flaw(check, subj) == "" with input as names with data.ergo_params as {"m": {}} + } +} From 697e07eb79d25e86be632616649d8d39bac2fe26 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 06:32:54 +0100 Subject: [PATCH 40/57] rego: test the some form without if any, since if any belongs to every Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/tests/lines/roots_test.rego | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/rego/tests/lines/roots_test.rego b/engines/rego/tests/lines/roots_test.rego index e6148fd61..3f4b38507 100644 --- a/engines/rego/tests/lines/roots_test.rego +++ b/engines/rego/tests/lines/roots_test.rego @@ -973,7 +973,7 @@ test_a_whose_root_read_through_a_named_by_key_that_is_the_line_alias_holding_a_n } test_a_one_line_walk_reads_a_root_through_the_items_key_before_any_item if { - every sentence in ["every tests whose $params.m named by key is 1, if any, exists", "some tests whose $params.m named by key is 1, if any, exists"] { + every sentence in ["every tests whose $params.m named by key is 1, if any, exists", "some tests whose $params.m named by key is 1 exists"] { check := ergo._s_written_check(sentence) subj := {"tests": []} names := {"ergo/names": {"ergo/subject": subj}} From ff09e9c4603decab2eb811ba6c9bfef9e125988e Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 06:37:24 +0100 Subject: [PATCH 41/57] rust: add a failing test that a one-line walk reads a root through the item's key before any item Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rust/engine/src/ops/walk/tests.rs | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/engines/rust/engine/src/ops/walk/tests.rs b/engines/rust/engine/src/ops/walk/tests.rs index 82a2078bd..c71228186 100644 --- a/engines/rust/engine/src/ops/walk/tests.rs +++ b/engines/rust/engine/src/ops/walk/tests.rs @@ -3008,3 +3008,27 @@ fn every_distinct_over_a_field_of_the_kept_items_checks_each_value_of_the_field_ assert_eq!(kept_row.rich, dotted_row.rich, "{kept}"); } } + +#[test] +fn a_root_read_through_the_items_key_is_read_before_any_item_when_the_list_is_empty() { + let Check::Walk(walk) = lowered("every items whose $params.m named by key is 1, if any, exists") + else { + panic!("not a walk"); + }; + let subject = json!({"items": []}); + let input = json!({}); + for (params, said) in [ + (json!({}), vec![(Cause::Absent, "$params.m is missing")]), + (json!({"m": null}), vec![(Cause::Null, "$params.m is null")]), + ( + json!({"m": 3}), + vec![(Cause::Unusable, "$params.m is 3, which isn't an object")], + ), + (json!({"m": {}}), vec![]), + ] { + let context = ctx(&subject, &input, Some(¶ms)); + let roots = whose_roots(&walk, &outer(&context), false); + let got: Vec<(Cause, &str)> = roots.iter().map(|r| (r.cause, r.text.as_str())).collect(); + assert_eq!(got, said, "{params}"); + } +} From 7b238af068e695cc68ca3ecc0ead022e65c4d2f2 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 06:37:28 +0100 Subject: [PATCH 42/57] rego: read a root through the item's key before any item in a one-line every or some Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/src/lines/roots.rego | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/engines/rego/src/lines/roots.rego b/engines/rego/src/lines/roots.rego index 15cc006b0..ccc07b6a0 100644 --- a/engines/rego/src/lines/roots.rego +++ b/engines/rego/src/lines/roots.rego @@ -834,10 +834,12 @@ _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), [c | check.op in _walk_ops; some c in object.get(check, "whose", [])]) + _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) From 6ab770b3d29ada1592517b9c67d78d3d9982aca9 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 06:39:58 +0100 Subject: [PATCH 43/57] rust: read a root through the item's key before any item in a one-line every or some Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rust/engine/src/ops/walk.rs | 7 +++++++ engines/rust/engine/src/ops/walk/tests.rs | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/engines/rust/engine/src/ops/walk.rs b/engines/rust/engine/src/ops/walk.rs index 03ed9aa1e..fc5ca5e97 100644 --- a/engines/rust/engine/src/ops/walk.rs +++ b/engines/rust/engine/src/ops/walk.rs @@ -2202,6 +2202,13 @@ fn whose_roots(walk: &Walk, outer: &Ctx, failing: bool) -> Vec { if failing { once(&mut roots, message::root_clauses(&whose, outer)); } + let keyed = whose + .iter() + .flat_map(|check| check.paths()) + .filter_map(|path| super::key_base::base_of(path, true, outer)) + .map(|(name, text, cause)| Clause::root(&name, cause, text)) + .collect(); + once(&mut roots, keyed); roots } diff --git a/engines/rust/engine/src/ops/walk/tests.rs b/engines/rust/engine/src/ops/walk/tests.rs index c71228186..f8702bd27 100644 --- a/engines/rust/engine/src/ops/walk/tests.rs +++ b/engines/rust/engine/src/ops/walk/tests.rs @@ -3011,7 +3011,8 @@ fn every_distinct_over_a_field_of_the_kept_items_checks_each_value_of_the_field_ #[test] fn a_root_read_through_the_items_key_is_read_before_any_item_when_the_list_is_empty() { - let Check::Walk(walk) = lowered("every items whose $params.m named by key is 1, if any, exists") + let Check::Walk(walk) = + lowered("every items whose $params.m named by key is 1, if any, exists") else { panic!("not a walk"); }; From d20d13a3f5a03c24e09f481414e33a407233af09 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 06:41:02 +0100 Subject: [PATCH 44/57] docs: say a one-line every reads a root through the item's key before any item, and drop the two cases Rust passes from its known failures Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- CHANGELOG.md | 1 + engines/rust/CHANGELOG.md | 1 + engines/rust/known-failures.txt | 2 -- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a29cde778..71f1a4cff 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 +- A one-line `every` or `some` whose `whose` reads a root through the item's own `named by` key 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 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. diff --git a/engines/rust/CHANGELOG.md b/engines/rust/CHANGELOG.md index 7868aa873..38cb95c7e 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 one-line `every` or `some` whose `whose` reads a root through the item's own `named by` key 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 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. In the Rust engine alone, a one-line `some` or `every` without `, if any,` on an empty list now takes the root's cause, like `absent` with `$params.m named by pr.key is missing; tests is []` where it said `value` with `tests is []`, and `count of tests.v that equals $params.m named by pr.key named by key is 0` with an item that isn't an object fails as `not_an_object`, naming the root and the item, where it said `absent`. 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`. diff --git a/engines/rust/known-failures.txt b/engines/rust/known-failures.txt index be5c06d39..27869b129 100644 --- a/engines/rust/known-failures.txt +++ b/engines/rust/known-failures.txt @@ -416,8 +416,6 @@ sentences / a named by key from the subject after any path, inside a relative cl sentences / a named by key on the right of every, after a part, a parent, an alias, $params or $input / fails as unusable once when the subject's key isn't text sentences / a named by on the right of every that can't be read / names the key that is null, as the plain check does, when m is null too sentences / a root from $params read through a named by key from $params and then the item's key is read once, before any item, so a root it doesn't have fails the check on an empty list too / fails as absent naming the root when the params have no m and tests is empty -sentences / a root from $params read through the item's own key, in a one-line every with if any, is not an object, so it fails as unusable on an empty list / fails as unusable naming $params.m when tests is empty -sentences / a root from $params read through the item's own key, in a one-line every with if any, is null, so it fails as null on an empty list / fails as null naming $params.m when tests is empty sentences / a root name on the right of some in a from line's condition, read up front / fails the candidate once, with no item named, even when its list is empty sentences / a root read through the item's own key, in a one-line every with if any, is read once, before any item, so it fails on an empty list when it is missing, null or not an object / fails as absent naming $params.m and $input.m when neither is there and tests is empty sentences / a root read through the item's own key, in a one-line every with if any, is read once, before any item, so it fails on an empty list when it is missing, null or not an object / fails as null naming $input.m when it is null and tests is empty From 6a165b411d945bf423e344c93afbab2b1643a9cd Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 06:52:04 +0100 Subject: [PATCH 45/57] spec: drop the two rows that pass from the known differences, and say in OPEN.md what still differs after the one-line every fix 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 | 5 +++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/engines/rego/tests/spec_test.rego b/engines/rego/tests/spec_test.rego index c0b355103..a78ce5e18 100644 --- a/engines/rego/tests/spec_test.rego +++ b/engines/rego/tests/spec_test.rego @@ -41,8 +41,6 @@ known_differences := { "sentences / a named by key from the subject after a parent or an alias, inside a relative clause / fails as absent once when the subject has no k", "sentences / a root from $input or the subject itself read through a named by key from the subject, in a count of or a sum of over items, is said once on the assertion, and each item the clause can't read is said after it / puts the root on the assertion and gives an item entry only to the item the clause can't read", "sentences / a root from $params read through a named by key from $params and then the item's key is read once, before any item, so a root it doesn't have fails the check on an empty list too / fails as absent naming the root when the params have no m and tests is empty", - "sentences / a root from $params read through the item's own key, in a one-line every with if any, is not an object, so it fails as unusable on an empty list / fails as unusable naming $params.m when tests is empty", - "sentences / a root from $params read through the item's own key, in a one-line every with if any, is null, so it fails as null on an empty list / fails as null naming $params.m when tests is empty", "sentences / a root from $params read through two named by keys from the subject and then the item's key fails the check on an empty list too, when the first one finds a value that isn't an object / fails as unusable naming the value the first key finds when it is 3 and tests is empty", "sentences / a root read through the item's own key, in a one-line every with if any, is read once, before any item, so it fails on an empty list when it is missing, null or not an object / fails as absent naming $params.m and $input.m when neither is there and tests is empty", "sentences / a root read through the item's own key, in a one-line every with if any, is read once, before any item, so it fails on an empty list when it is missing, null or not an object / fails as null naming $input.m when it is null and tests is empty", diff --git a/spec/OPEN.md b/spec/OPEN.md index 5dd951a97..8199b2d5e 100644 --- a/spec/OPEN.md +++ b/spec/OPEN.md @@ -97,7 +97,7 @@ OPA 1.20.2 crashes when it compares a number whose exponent is beyond ±1e6 with - **A key from the subject that can't be read, beside a root that is missing or `null`, in a one-line `every` or `some`, an `every … that` or a `for` line (type 3).** With no params and the key `[]`, `every tests whose v equals $params.d.m named by pr.key exists` fails as `unusable` in both engines. `ergo.rego` says `pr.key is [], which isn't text; $params.d.m named by pr.key is missing` and the Rust engine says only `pr.key is [], which isn't text`, as both engines do for `count of`. A key that is missing, `null` or `3` beside a root that is `null` is the same, in `every`, `some` and `every … that`, with the root `$params.m`, `$input.m`, `pr.m` or the parent's `art.m`: with no key, the params `{"m": null}` and `tests` `[{}]`, `every tests whose v equals $params.m named by pr.key exists` fails as `absent` in both engines, with `pr.key is missing; item 1 of tests: v is missing` in the Rust engine, and `ergo.rego` adds `$params.m is null` after the key. A `for` line's second `whose` is the same: with subjects `art` from `arts` and `pr` from `every art.prs`, the key `3`, `xs` `[{}]` and `tests` `[{"v": 1}]`, `for: every xs as x, every tests whose v equals x.m named by pr.key, if any, as t` with `t exists` fails as `unusable` in both engines, with `pr.key is 3, which isn't text` in the Rust engine and `pr.key is 3, which isn't text; item 1 of xs: x.m named by pr.key is missing` in `ergo.rego`, and `first of tests whose v equals x.m named by pr.key as t` too. [problems.all_said](semantics.md#which-problems-a-message-says) says "A message SHOULD say every problem Ergo finds", and the root can't be read whatever the key holds, so `ergo.rego` follows it here. On `main` `ergo.rego` failed the first one as `absent`. No step is scheduled yet. - **A one-line walk under a `for` line whose root is the line's alias read through a key from the subject says the key twice (type 3, [problems.where_said](semantics.md#which-problems-a-message-says)).** With no key, `xs` `[{"m": null}]` and `tests` `[{}]`, `every tests whose v equals x.m named by pr.key exists` under `for: every xs as x` fails as `absent` in both engines, with `pr.key is missing; item 1 of xs: item 1 of tests: v is missing` in the Rust engine and `pr.key is missing; item 1 of xs: pr.key is missing; x.m is null; item 1 of xs: item 1 of tests: v is missing` in `ergo.rego`. problems.where_said says a key read from outside the item is said once, with no item in front, so the Rust engine follows it, though `ergo.rego` also names `x.m is null`, which [problems.all_said](semantics.md#which-problems-a-message-says) asks for. With `tests` `[{}, {"v": 1}]`, `sum of tests.v that equals x.m named by pr.key is 1` says `pr.key is missing; item 1 of xs: item 1 of tests: v is missing` in the Rust engine and `pr.key is missing; item 1 of tests: v is missing` in `ergo.rego`, which drops `item 1 of xs:` in front. No step is scheduled yet. - **Which `inputs` a root read through a key that can be read and then the item's own key puts on the row, over an empty list (type 2, both engines, [tally.inputs](semantics.md#counts-and-sums-in-sentences), [tally.whose](semantics.md#counts-and-sums-in-sentences)).** With no `m` in the params, the params' `k` holding `"a"` and `tests` `[]`, `count of tests whose v equals $params.m named by $params.k named by key is 0` fails in both engines as `absent` with `$params.m is missing`, as it should. No rule decides the row's `inputs` here: tally.inputs names only the count and the walked list, and tally.whose puts a key on the assertion's inputs only when it is missing or `null`. The two cases disagree: the case below expects `$params.m named by $params.k named by key` (`absent`) and `$params.k` (`usable`) in the inputs, and the `sentences` case for `$params.m named by key named by $params.k` ("a root from $params read through the item's key and then a named by key from $params …"), which both engines pass, expects no input for the root or the key. Both engines list neither, and put them only in the check's `$refs`. Case: `sentences` "a root from $params read through a named by key from $params and then the item's key is read once, before any item, so a root it doesn't have fails the check on an empty list too", in `known_differences` and in `engines/rust/known-failures.txt`. The step: a decision on which inputs such a row lists, and then both cases follow it. -- **A `null` key from the subject on an empty list, in a one-line `every` or `some` (type 2).** With no params, the key `null` and `tests` `[]`, `every tests whose v equals $params.m named by pr.key exists` and `some tests whose v equals $params.m named by pr.key exists` fail as `null` in `ergo.rego` with `pr.key is null; tests is []`, and as `absent` in the Rust engine with `$params.m named by pr.key is missing; pr.key is null; tests is []`. [tally.whose](semantics.md#counts-and-sums-in-sentences) says "each item takes the cause of its own paths, and the row takes the worst of all", and `$params.m` is missing whatever the key holds, so the Rust engine is right. `count of tests whose v equals $params.zz named by pr.key is 0` with `key` `null` is the same: `ergo.rego` says `null` with `pr.key is null`, and the Rust engine says `absent` with `$params.zz named by pr.key is missing; pr.key is null`. With no `m` and the params' `k` `null`, `count of tests whose v equals $params.m named by $params.k named by key is 0` on `[]` is the same, with `$params.k is null` in `ergo.rego` and `$params.m is missing; $params.k is null` in the Rust engine, in the other orders of the keys too. With no `m` and `tests` `[]`, `some tests whose v equals $params.m named by key named by pr.key exists` says `value` with `tests is []` in `ergo.rego` and `absent` with `$params.m is missing; tests is []` in the Rust engine. With no `m` and `tests` `[{"v": 1, "key": "b", "j": "c"}, {"v": 1, "key": "b", "j": 3}]`, `count of tests whose v equals $params.m named by key named by j is 0` says `absent` with `$params.m is missing` in `ergo.rego` and `unusable` with `$params.m is missing; item 2 of tests: j is 3, which isn't text` in the Rust engine, which follows problems.all_said. On `main` too. With a key from the subject in front of the item's key, the Rust engine also takes the root's cause where `ergo.rego` doesn't: with the params `{"m": {}}`, `key` "a" and `tests` `[]`, `some tests whose v equals $params.m named by pr.key named by key exists` says `value` with `tests is []` in `ergo.rego` and `absent` with `$params.m named by pr.key is missing; tests is []` in the Rust engine, and the same with `m.a` `null`, `3` or `[]`, and with `every`. Since #960, where the Rust engine reads the root before any item. No step is scheduled yet. +- **A `null` key from the subject on an empty list, in a one-line `every` or `some` (type 2).** With no params, the key `null` and `tests` `[]`, `every tests whose v equals $params.m named by pr.key exists` and `some tests whose v equals $params.m named by pr.key exists` fail as `null` in `ergo.rego` with `pr.key is null; tests is []`, and as `absent` in the Rust engine with `$params.m named by pr.key is missing; pr.key is null; tests is []`. [tally.whose](semantics.md#counts-and-sums-in-sentences) says "each item takes the cause of its own paths, and the row takes the worst of all", and `$params.m` is missing whatever the key holds, so the Rust engine is right. `count of tests whose v equals $params.zz named by pr.key is 0` with `key` `null` is the same: `ergo.rego` says `null` with `pr.key is null`, and the Rust engine says `absent` with `$params.zz named by pr.key is missing; pr.key is null`. With no `m` and the params' `k` `null`, `count of tests whose v equals $params.m named by $params.k named by key is 0` on `[]` is the same, with `$params.k is null` in `ergo.rego` and `$params.m is missing; $params.k is null` in the Rust engine, in the other orders of the keys too. With no `m` and `tests` `[]`, `some tests whose v equals $params.m named by key named by pr.key exists` says `value` with `tests is []` in `ergo.rego` and `absent` with `$params.m is missing; tests is []` in the Rust engine. With no `m` and `tests` `[{"v": 1, "key": "b", "j": "c"}, {"v": 1, "key": "b", "j": 3}]`, `count of tests whose v equals $params.m named by key named by j is 0` says `absent` with `$params.m is missing` in `ergo.rego` and `unusable` with `$params.m is missing; item 2 of tests: j is 3, which isn't text` in the Rust engine, which follows problems.all_said. On `main` too. With a key from the subject in front of the item's key, the Rust engine also takes the root's cause where `ergo.rego` doesn't: with the params `{"m": {}}`, `key` "a" and `tests` `[]`, `some tests whose v equals $params.m named by pr.key named by key exists` says `absent` with `$params.m named by pr.key is missing` in `ergo.rego` and the same followed by `; tests is []` in the Rust engine (the cause agrees, since both engines read the root before any item, and only the wording differs, type 3), and the same with `m.a` `null`, `3` or `[]`, and with `every`. No step is scheduled yet. - **A root read through the subject's key beside an item that isn't an object (type 2).** With the params `{"m": {}}`, `key` "a" and `tests` `[{"v": 1, "key": "b"}]`, `count of tests.v that equals $params.m named by pr.key named by key is 0` fails as `absent` with `item 1 of tests: v: $params.m named by pr.key named by key is missing` in `ergo.rego`, and as `not_an_object` with `$params.m named by pr.key is missing; item 1 of tests: v is 1, which isn't an object` in the Rust engine. [problems.all_said](semantics.md#which-problems-a-message-says) says every problem and the worst cause, so the Rust engine is right. Since #960. The step that fixes it reads the root before any item in `ergo.rego`'s `that` too. - **A root that can't be read, beside a chain of keys that can't be read or a sum, in `ergo.rego` (type 3, [problems.all_said](semantics.md#which-problems-a-message-says), [problems.where_said](semantics.md#which-problems-a-message-says)).** With no `m` in the params and `tests` `[{"v": 1, "key": "b", "j": "c"}, {"v": 1, "key": "b"}]`, `count of tests whose v equals $params.m named by key named by j is 0` says `$params.m is missing` in `ergo.rego` and `$params.m is missing; item 2 of tests: j is missing` in the Rust engine, and with `j` `3` in the second item `ergo.rego` drops `item 2 of tests: j is 3, which isn't text` in the same way, so it no longer says the second key's problem, as it did on `main`. With `tests` `[]`, `sum of v of tests whose v equals $params.m named by key named by pr.key is 0` fails as `absent` in both engines, with `$params.m is missing` in the Rust engine and `sum of v of tests whose v equals $params.m named by key named by pr.key is 0 is false` in `ergo.rego`, which never names `$params.m`. With `named by art.key` or `named by art` where `art` holds an object, both engines fail as `unusable` with `art is an object with 2 keys, which isn't text`, and the Rust engine adds `; $params.m is missing`. No step is scheduled yet. - **A sum of a root read through the subject's key that finds a value that isn't an object says another message in `ergo.rego` (type 3, [problems.all_said](semantics.md#which-problems-a-message-says)).** With the params `{"m": {"a": 3}}`, `key` "a" and `tests` `[]`, `sum of v of tests whose v equals $params.m named by pr.key named by key is 0` fails as `unusable` in both engines, with `$params.m named by pr.key is 3, which isn't an object` in the Rust engine and `sum of v of tests whose v equals $params.m named by pr.key named by key needs more than 15 digits` in `ergo.rego`, which doesn't name the root. On `main` both engines pass this check, because neither reads the root before an item and the list is empty. Since #960. @@ -236,7 +236,8 @@ The spec doesn't settle these yet, because the two engines give different report ## Where both engines differ from a rule -- **A one-line `every` with `, if any,` whose `whose` reads a root through the item's own key passes in both engines on an empty list when the root can't be read (type 1, both engines, [tally.walk](semantics.md#counts-and-sums-in-sentences), [for.roots](semantics.md#for), [problems.same_path](semantics.md#which-problems-a-message-says)).** tally.walk says "The same goes for every root [for.roots](#for) names, … `$params` and `$input`, wherever the check reads it: an `every` or `some` phrase, a `whose`, …", and for.roots says "Each root is read once, before any item". With no params and `tests` `[]`, `every tests whose $params.m named by key is 1, if any, exists` passes in both engines, and the same with `$input.m`, `$params.m.d` and the parent's `art.m` holding `3`. A chain passes too: with the params' `k` holding `"a"` and the subject's `key` holding `"a"`, `every tests whose v equals $params.m named by $params.k named by key, if any, exists`, `… named by key named by $params.k, if any, exists` and `… named by pr.key named by key, if any, exists`. Both engines fail `count of tests whose $params.m named by key is 1 is 0` and the `for` line `every tests whose $params.m named by key is 1, if any, as t` as `absent` with `$params.m is missing`, and the Rust engine fails the one-line `every` too under `for: every xs, if any, as x` with `xs` `[]`. So the one-line form should fail as `absent` with `$params.m is missing`. On `main` too. Cases: `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" and the two groups for a `$params.m` that is null and not an object, known failures of both engines. The step that fixes it: both engines read the root before any item in a one-line `every … , if any,`. +- **The order of the `inputs` of a one-line `every` or `some` whose `whose` reads a root through the item's own key, over an empty list (type 2, both engines, [walk.inputs](semantics.md#every-and-some)).** With no `m` in the input and `tests` `[]`, `every tests whose $input.m named by key is 1, if any, exists` fails in both engines as `absent` with `$input.m is missing`, since the root is read before any item ([for.roots](semantics.md#for)). Both engines list the same two inputs, `$input.m` and `tests[]`, but they put `$input.m` first and the case puts `tests[]` first. No rule in walk.inputs says which comes first, and the cases on `main` use both orders (136 put the root first, sorted by name, and 21 the walked list). The same holds when `$input.m` is `null` or `3`. Cases: `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" (three rows), in `known_differences` and in `engines/rust/known-failures.txt`. The step: decide the order of `inputs`, and then the three rows follow it. +- **A root read through the item's own key, as a list, with a field after it, over an empty list in a one-line `every … , if any,`: `ergo.rego` passes where the Rust engine fails (type 1, [for.roots](semantics.md#for), [tally.walk](semantics.md#counts-and-sums-in-sentences)).** With `m` holding `[]` in the input, or in the params, and `tests` `[]`, `every tests whose $input.m.d named by key is 1, if any, exists` fails as `unusable` with `$input.m is [], which isn't an object` in the Rust engine and passes in `ergo.rego`, and the same with `$params.m.d`. With one item both engines fail it, and with `null`, `3` or text in place of the list both fail on an empty list too. So the root should fail as `unusable`. Found on the change that made the Rust engine read the root first. There is no spec case yet: the step is a case with the right verdict, listed as a known failure of `ergo.rego`, and then the fix in `ergo.rego`. - **A `named by` key from the subject after the line's alias, under a `for` line with items, is said with the line's item in front by a case (type 3, both engines, a case differs from a rule, [tally.whose](semantics.md#counts-and-sums-in-sentences), [problems.where_said](semantics.md#which-problems-a-message-says)).** With `for: every ms as mm`, `count of xs whose v equals mm named by pr.k is 1`, no `k` on the subject and `ms` and `xs` holding one item each, both engines fail as `absent` with `pr.k is missing`, said once on the assertion. The `sentences` case "a named by key from the subject after a parent or an alias, inside a relative clause" says `item 1 of ms: pr.k is missing`, with the problem on an `item 1 of ms` entry. tally.whose says a key that is missing "is always said, once and before any item", and problems.where_said says a problem in something read from the subject "SHOULD be said once, before any item, with no item in front", so the case differs from both. It is a known failure of both engines. The step that fixes it: a decision on the case's row. - **A `named by` key from the subject that isn't text is listed as `usable`, and two cases say so (type 2, both engines, a case differs from a rule, [path.field_step](semantics.md#reading-a-path)).** With `tests` holding `[]` and the subject's `key` holding `3`, `count of tests whose m named by pr.key is 1 is 0` fails as `unusable` with `pr.key is 3, which isn't text` in both engines, and both list the input `key` with the outcome `usable`. path.field_step says a field that isn't a string ends the path `unusable`, and [What a row shows](semantics.md#what-a-row-shows) says an input's outcome is `unusable` "when the value was read fine but the check can't use it", as the Rust engine lists `$input.k` holding `3`. The `sentences` cases "a named by key from the subject after any path, inside a relative clause" and "a key from the subject that can't be read, in a relative clause" pin a key holding `3` as `usable`, so those cases differ from path.field_step and the outcome rule, which say `unusable`; nothing here proposes a fix, and a decision has to say which of the two is right before any engine or case changes. From 1c0b9c10a501e901df3e56e9ec03ed87e87b0dd6 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 07:32:02 +0100 Subject: [PATCH 46/57] spec: drop the three more rows that ergo.rego now passes from the known differences Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/tests/spec_test.rego | 3 --- 1 file changed, 3 deletions(-) diff --git a/engines/rego/tests/spec_test.rego b/engines/rego/tests/spec_test.rego index a78ce5e18..e5a1112b4 100644 --- a/engines/rego/tests/spec_test.rego +++ b/engines/rego/tests/spec_test.rego @@ -11,9 +11,6 @@ known_differences := { "derived / a parent's name used as the named by key of a count's whose, with no for line, is read before any item, so it fails on an empty list too / fails as unusable on a parent that isn't text, before any item, whether es is empty, null or missing", "derived / an every or some whose whose reads a root from $input through a key the item holds fails on the root, said once, when each item reads fine / the root is a number", "derived / an every or some whose whose reads a root from $input through a key the item holds fails on the root, said once, when each item reads fine / the root is an empty list", - "derived / an every or some whose whose reads a root from $input through a key the item holds fails on the root, said once, when each item reads fine / the root is missing", - "derived / an every or some whose whose reads a root from $input through a key the item holds fails on the root, said once, when each item reads fine / the root is null", - "derived / an every or some whose whose reads a root from $params through a key the item holds fails on the root, said once, when each item reads fine / the root is null", "field_of / a field in front of a list with whose and a list along the field, named like a for alias, is the alias, which shadows the field of the same name / the alias holds the sha the phrase wants, and the commit of the kept pull request does not", "field_of / a field in front of a list with whose, named like a for alias, is the alias, which shadows a field with the same name / the alias is the text the phrase wants, and the unit test's own field isn't", "field_of / a field with a dot in front of a list with whose and a list along the field, named like a for alias, reads the field and not the alias / the commit of the kept pull request is ok, and the alias holds a sha that is not", From 4cde2824ed7332f41e8d6dd0dc915c92d9d69753 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 07:49:38 +0100 Subject: [PATCH 47/57] rego: test that a one-line walk leaves a root a contains reads through the item's key to each item Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/tests/lines/roots_test.rego | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/engines/rego/tests/lines/roots_test.rego b/engines/rego/tests/lines/roots_test.rego index 3f4b38507..c4ff6e668 100644 --- a/engines/rego/tests/lines/roots_test.rego +++ b/engines/rego/tests/lines/roots_test.rego @@ -983,3 +983,13 @@ test_a_one_line_walk_reads_a_root_through_the_items_key_before_any_item if { ergo._walk_root_flaw(check, subj) == "" with input as names with data.ergo_params as {"m": {}} } } + +test_a_one_line_walk_leaves_a_root_that_a_contains_reads_through_the_items_key_to_each_item if { + every sentence in ["every tests whose tags contains $params.m named by key, if any, exists", "some tests whose tags contains $params.m named by key exists"] { + check := ergo._s_written_check(sentence) + subj := {"tests": []} + names := {"ergo/names": {"ergo/subject": subj}} + ergo._walk_root_flaw(check, subj) == "" with input as names with data.ergo_params as {"m": null} + ergo._walk_root_said(check, subj) == [] with input as names with data.ergo_params as {"m": null} + } +} From 7d62dda67c248b6aa4c939a0aec4556e535c9fa4 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 07:51:07 +0100 Subject: [PATCH 48/57] rego: leave a root a contains reads through the item's key to each item in a one-line every or some, so it is said once Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/src/lines/roots.rego | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/engines/rego/src/lines/roots.rego b/engines/rego/src/lines/roots.rego index ccc07b6a0..a9f5db0eb 100644 --- a/engines/rego/src/lines/roots.rego +++ b/engines/rego/src/lines/roots.rego @@ -838,7 +838,11 @@ _for_keyed_roots_said(check, subj) := [[f.cause, f.text] | some f in _keyed_root else := [] -_keyed_whose_conds(check) := array.concat(_for_line_whose_conds(check), [c | check.op in _walk_ops; some c in object.get(check, "whose", [])]) +_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"]) if object.get(c, "cmp", null) == "includes" + +else := c _keyed_root_faults(subj, whose) := _once([x[2] | some x in sort([[i, f.text, f] | some c in whose From 836df3159863411c9c53dab9fc6dec8e4ebeac57 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 07:52:15 +0100 Subject: [PATCH 49/57] rego: test that a root read through the item's key names a list before a field as a step that isn't an object Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/tests/lines/roots_test.rego | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/engines/rego/tests/lines/roots_test.rego b/engines/rego/tests/lines/roots_test.rego index c4ff6e668..4adbde413 100644 --- a/engines/rego/tests/lines/roots_test.rego +++ b/engines/rego/tests/lines/roots_test.rego @@ -786,6 +786,11 @@ test_keyed_root_fault_names_a_step_before_the_last_that_isnt_an_object if { not ergo._keyed_root_fault({}, p) with data.ergo_document as {"m": {"a": {}}} } +test_keyed_root_fault_names_a_list_before_a_field_as_a_step_that_isnt_an_object if { + ergo._keyed_root_fault({}, ["$$input", "m", "d", {"named_by_field": "key"}]) == {"cause": "unusable", "text": "$input.m is [], which isn't an object"} with data.ergo_document as {"m": []} + ergo._keyed_root_fault({}, ["$$params", "m", "d", {"named_by_field": "key"}]) == {"cause": "unusable", "text": "$params.m is [{\"d\": {}}], which isn't an object"} with data.ergo_params as {"m": [{"d": {}}]} +} + test_keyed_root_fault_names_a_missing_root_from_input_or_params_by_its_whole_path_and_a_null_step_alone if { ergo._keyed_root_fault({}, ["$$input", "m", "a", {"named_by_field": "key"}]) == {"cause": "absent", "text": "$input.m.a is missing"} with data.ergo_document as {} ergo._keyed_root_fault({}, ["$$input", "d", "m", {"named_by_field": "key"}]) == {"cause": "absent", "text": "$input.d.m is missing"} with data.ergo_document as {} From 832992807d086fa3d7a3a01020793150085687e1 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 07:56:58 +0100 Subject: [PATCH 50/57] rego: fail a root read through the item's key when a list sits before a field, even on an empty list Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/src/lines/roots.rego | 8 -------- spec/OPEN.md | 1 - 2 files changed, 9 deletions(-) diff --git a/engines/rego/src/lines/roots.rego b/engines/rego/src/lines/roots.rego index a9f5db0eb..7b00ddb22 100644 --- a/engines/rego/src/lines/roots.rego +++ b/engines/rego/src/lines/roots.rego @@ -911,7 +911,6 @@ _keyed_prefix_fault(subj, p, j, k) := {"cause": st, "text": _name_key_said([_inp _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} @@ -922,13 +921,6 @@ _keyed_named(p, j, k, st) := _as_subject_part(array.slice(p, 0, k)) if { _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( diff --git a/spec/OPEN.md b/spec/OPEN.md index 8199b2d5e..5a9e1d249 100644 --- a/spec/OPEN.md +++ b/spec/OPEN.md @@ -237,7 +237,6 @@ The spec doesn't settle these yet, because the two engines give different report ## Where both engines differ from a rule - **The order of the `inputs` of a one-line `every` or `some` whose `whose` reads a root through the item's own key, over an empty list (type 2, both engines, [walk.inputs](semantics.md#every-and-some)).** With no `m` in the input and `tests` `[]`, `every tests whose $input.m named by key is 1, if any, exists` fails in both engines as `absent` with `$input.m is missing`, since the root is read before any item ([for.roots](semantics.md#for)). Both engines list the same two inputs, `$input.m` and `tests[]`, but they put `$input.m` first and the case puts `tests[]` first. No rule in walk.inputs says which comes first, and the cases on `main` use both orders (136 put the root first, sorted by name, and 21 the walked list). The same holds when `$input.m` is `null` or `3`. Cases: `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" (three rows), in `known_differences` and in `engines/rust/known-failures.txt`. The step: decide the order of `inputs`, and then the three rows follow it. -- **A root read through the item's own key, as a list, with a field after it, over an empty list in a one-line `every … , if any,`: `ergo.rego` passes where the Rust engine fails (type 1, [for.roots](semantics.md#for), [tally.walk](semantics.md#counts-and-sums-in-sentences)).** With `m` holding `[]` in the input, or in the params, and `tests` `[]`, `every tests whose $input.m.d named by key is 1, if any, exists` fails as `unusable` with `$input.m is [], which isn't an object` in the Rust engine and passes in `ergo.rego`, and the same with `$params.m.d`. With one item both engines fail it, and with `null`, `3` or text in place of the list both fail on an empty list too. So the root should fail as `unusable`. Found on the change that made the Rust engine read the root first. There is no spec case yet: the step is a case with the right verdict, listed as a known failure of `ergo.rego`, and then the fix in `ergo.rego`. - **A `named by` key from the subject after the line's alias, under a `for` line with items, is said with the line's item in front by a case (type 3, both engines, a case differs from a rule, [tally.whose](semantics.md#counts-and-sums-in-sentences), [problems.where_said](semantics.md#which-problems-a-message-says)).** With `for: every ms as mm`, `count of xs whose v equals mm named by pr.k is 1`, no `k` on the subject and `ms` and `xs` holding one item each, both engines fail as `absent` with `pr.k is missing`, said once on the assertion. The `sentences` case "a named by key from the subject after a parent or an alias, inside a relative clause" says `item 1 of ms: pr.k is missing`, with the problem on an `item 1 of ms` entry. tally.whose says a key that is missing "is always said, once and before any item", and problems.where_said says a problem in something read from the subject "SHOULD be said once, before any item, with no item in front", so the case differs from both. It is a known failure of both engines. The step that fixes it: a decision on the case's row. - **A `named by` key from the subject that isn't text is listed as `usable`, and two cases say so (type 2, both engines, a case differs from a rule, [path.field_step](semantics.md#reading-a-path)).** With `tests` holding `[]` and the subject's `key` holding `3`, `count of tests whose m named by pr.key is 1 is 0` fails as `unusable` with `pr.key is 3, which isn't text` in both engines, and both list the input `key` with the outcome `usable`. path.field_step says a field that isn't a string ends the path `unusable`, and [What a row shows](semantics.md#what-a-row-shows) says an input's outcome is `unusable` "when the value was read fine but the check can't use it", as the Rust engine lists `$input.k` holding `3`. The `sentences` cases "a named by key from the subject after any path, inside a relative clause" and "a key from the subject that can't be read, in a relative clause" pin a key holding `3` as `usable`, so those cases differ from path.field_step and the outcome rule, which say `unusable`; nothing here proposes a fix, and a decision has to say which of the two is right before any engine or case changes. From 05e0968121fbb74a94c9e6f0cd20dfe8b5d16b42 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 08:20:03 +0100 Subject: [PATCH 51/57] rego: test that a one-line walk leaves a root on the value side of any comparison to each item Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/tests/lines/roots_test.rego | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/engines/rego/tests/lines/roots_test.rego b/engines/rego/tests/lines/roots_test.rego index 4adbde413..93e66588f 100644 --- a/engines/rego/tests/lines/roots_test.rego +++ b/engines/rego/tests/lines/roots_test.rego @@ -989,12 +989,20 @@ test_a_one_line_walk_reads_a_root_through_the_items_key_before_any_item if { } } -test_a_one_line_walk_leaves_a_root_that_a_contains_reads_through_the_items_key_to_each_item if { - every sentence in ["every tests whose tags contains $params.m named by key, if any, exists", "some tests whose tags contains $params.m named by key exists"] { +test_a_one_line_walk_leaves_a_root_on_the_value_side_to_each_item if { + every sentence in [ + "every tests whose tags contains $params.m named by key, if any, exists", + "some tests whose tags contains $params.m named by key exists", + "every tests whose v is one of $params.m named by key, if any, exists", + "every tests whose v is $params.m named by key, if any, exists", + "every tests whose v is at least $params.m named by key, if any, exists", + ] { check := ergo._s_written_check(sentence) subj := {"tests": []} names := {"ergo/names": {"ergo/subject": subj}} - ergo._walk_root_flaw(check, subj) == "" with input as names with data.ergo_params as {"m": null} - ergo._walk_root_said(check, subj) == [] with input as names with data.ergo_params as {"m": null} + every params in [{}, {"m": null}, {"m": 3}] { + ergo._walk_root_flaw(check, subj) == "" with input as names with data.ergo_params as params + ergo._walk_root_said(check, subj) == [] with input as names with data.ergo_params as params + } } } From ed87ca1aa809874966c119b6a3606e3e609287bb Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 08:20:33 +0100 Subject: [PATCH 52/57] rego: read only the left side of a one-line walk's whose through the item's key before any item Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/src/lines/roots.rego | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/engines/rego/src/lines/roots.rego b/engines/rego/src/lines/roots.rego index 7b00ddb22..e0f09f275 100644 --- a/engines/rego/src/lines/roots.rego +++ b/engines/rego/src/lines/roots.rego @@ -840,9 +840,7 @@ 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"]) if object.get(c, "cmp", null) == "includes" - -else := c +_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 From 010b74e4dab29b727fe7f2557282d4f53a5eff3e Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 08:21:11 +0100 Subject: [PATCH 53/57] rust: test that a one-line walk leaves a root on the value side of its whose to each item Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rust/engine/src/ops/walk/tests.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/engines/rust/engine/src/ops/walk/tests.rs b/engines/rust/engine/src/ops/walk/tests.rs index f8702bd27..331290c2f 100644 --- a/engines/rust/engine/src/ops/walk/tests.rs +++ b/engines/rust/engine/src/ops/walk/tests.rs @@ -3033,3 +3033,25 @@ fn a_root_read_through_the_items_key_is_read_before_any_item_when_the_list_is_em assert_eq!(got, said, "{params}"); } } + +#[test] +fn a_root_on_the_value_side_of_a_whose_is_left_to_each_item_when_the_list_is_empty() { + for sentence in [ + "every items whose v is $params.m named by key, if any, exists", + "every items whose v is at least $params.m named by key, if any, exists", + "every items whose v is one of $params.m named by key, if any, exists", + "every items whose tags contains $params.m named by key, if any, exists", + ] { + let Check::Walk(walk) = lowered(sentence) else { + panic!("not a walk"); + }; + let subject = json!({"items": []}); + let input = json!({}); + for params in [json!({}), json!({"m": null}), json!({"m": 3})] { + let context = ctx(&subject, &input, Some(¶ms)); + let roots = whose_roots(&walk, &outer(&context), false); + let got: Vec<&str> = roots.iter().map(|r| r.text.as_str()).collect(); + assert!(got.is_empty(), "{sentence} {params} {got:?}"); + } + } +} From 62fe2d06a235f1191068cf2bf175bc787feeb81b Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 08:21:11 +0100 Subject: [PATCH 54/57] rust: read only the left side of a one-line walk's whose through the item's key before any item Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rust/engine/src/ops/walk.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/rust/engine/src/ops/walk.rs b/engines/rust/engine/src/ops/walk.rs index fc5ca5e97..eafd9daa1 100644 --- a/engines/rust/engine/src/ops/walk.rs +++ b/engines/rust/engine/src/ops/walk.rs @@ -2204,7 +2204,7 @@ fn whose_roots(walk: &Walk, outer: &Ctx, failing: bool) -> Vec { } let keyed = whose .iter() - .flat_map(|check| check.paths()) + .filter_map(|check| check.left_path()) .filter_map(|path| super::key_base::base_of(path, true, outer)) .map(|(name, text, cause)| Clause::root(&name, cause, text)) .collect(); From 4b32a0ddc6c11ac43017a2673cec425911cd07e4 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 08:28:00 +0100 Subject: [PATCH 55/57] spec: record the shared type 1s of a value-side or subject root in a one-line every, and pin the list-prefix root Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/tests/spec_test.rego | 7 +++++- engines/rust/known-failures.txt | 5 ++++ engines/rust/sentences/tests/oracle/checks.rs | 24 +++++++++++++++++++ spec/OPEN.md | 6 ++++- spec/cases/sentences/cases.json | 4 ++++ 5 files changed, 44 insertions(+), 2 deletions(-) diff --git a/engines/rego/tests/spec_test.rego b/engines/rego/tests/spec_test.rego index e5a1112b4..73cfeab06 100644 --- a/engines/rego/tests/spec_test.rego +++ b/engines/rego/tests/spec_test.rego @@ -38,14 +38,19 @@ known_differences := { "sentences / a named by key from the subject after a parent or an alias, inside a relative clause / fails as absent once when the subject has no k", "sentences / a root from $input or the subject itself read through a named by key from the subject, in a count of or a sum of over items, is said once on the assertion, and each item the clause can't read is said after it / puts the root on the assertion and gives an item entry only to the item the clause can't read", "sentences / a root from $params read through a named by key from $params and then the item's key is read once, before any item, so a root it doesn't have fails the check on an empty list too / fails as absent naming the root when the params have no m and tests is empty", + "sentences / a root from $params read through the item's own key on the value side of a whose, in a one-line every with if any, is read before any item, so it fails as unusable on an empty list when it is not an object / fails as unusable naming $params.m when tests is empty", + "sentences / a root from $params read through the item's own key on the value side of a whose, in a one-line every with if any, is read before any item, so it fails on an empty list when it is missing / fails as absent naming $params.m when tests is empty", "sentences / a root from $params read through two named by keys from the subject and then the item's key fails the check on an empty list too, when the first one finds a value that isn't an object / fails as unusable naming the value the first key finds when it is 3 and tests is empty", + "sentences / a root from the subject read through the item's own key, in a one-line every with if any, is read before any item, so it fails on an empty list when it is missing, null or not an object / fails as absent naming pr.m when it is missing and tests is empty", + "sentences / a root from the subject read through the item's own key, in a one-line every with if any, is read before any item, so it fails on an empty list when it is missing, null or not an object / fails as null naming pr.m when it is null and tests is empty", + "sentences / a root from the subject read through the item's own key, in a one-line every with if any, is read before any item, so it fails on an empty list when it is missing, null or not an object / fails as unusable naming pr.m when it is 3 and tests is empty", "sentences / a root read through the item's own key, in a one-line every with if any, is read once, before any item, so it fails on an empty list when it is missing, null or not an object / fails as absent naming $params.m and $input.m when neither is there and tests is empty", "sentences / a root read through the item's own key, in a one-line every with if any, is read once, before any item, so it fails on an empty list when it is missing, null or not an object / fails as null naming $input.m when it is null and tests is empty", "sentences / a root read through the item's own key, in a one-line every with if any, is read once, before any item, so it fails on an empty list when it is missing, null or not an object / fails as unusable naming $input.m when it is 3 and tests is empty", "sentences / a root read through the key of an earlier line's alias that is not text fails the check, once, before any item, even when the later line has no item / fails as unusable on an empty xs with if any when y is 3", "sentences / a that of a count of that reads an earlier line's alias as the key, and the later line's alias only on the right of the comparison, can't decide an item, so it fails even when the later line has no item / fails on an empty xs with if any when item 2 of zw is not an object", - "sentences / a that of a count of that reads the line's alias as a named by key, after an earlier line's alias, has nothing to check on an empty later list with if any, so it passes whatever the items of the counted list are / passes on an empty xs with if any when item 2 of zw is not an object", "sentences / a that of a count of that reads the line's alias as a named by key, after an earlier line's alias, has nothing to check on an empty later list with if any, so it passes whatever the items of the counted list are / passes on an empty xs with if any when item 2 of zw has no k", + "sentences / 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 / 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/engines/rust/known-failures.txt b/engines/rust/known-failures.txt index 27869b129..35cc3baa5 100644 --- a/engines/rust/known-failures.txt +++ b/engines/rust/known-failures.txt @@ -416,6 +416,11 @@ sentences / a named by key from the subject after any path, inside a relative cl sentences / a named by key on the right of every, after a part, a parent, an alias, $params or $input / fails as unusable once when the subject's key isn't text sentences / a named by on the right of every that can't be read / names the key that is null, as the plain check does, when m is null too sentences / a root from $params read through a named by key from $params and then the item's key is read once, before any item, so a root it doesn't have fails the check on an empty list too / fails as absent naming the root when the params have no m and tests is empty +sentences / a root from $params read through the item's own key on the value side of a whose, in a one-line every with if any, is read before any item, so it fails as unusable on an empty list when it is not an object / fails as unusable naming $params.m when tests is empty +sentences / a root from $params read through the item's own key on the value side of a whose, in a one-line every with if any, is read before any item, so it fails on an empty list when it is missing / fails as absent naming $params.m when tests is empty +sentences / a root from the subject read through the item's own key, in a one-line every with if any, is read before any item, so it fails on an empty list when it is missing, null or not an object / fails as absent naming pr.m when it is missing and tests is empty +sentences / a root from the subject read through the item's own key, in a one-line every with if any, is read before any item, so it fails on an empty list when it is missing, null or not an object / fails as null naming pr.m when it is null and tests is empty +sentences / a root from the subject read through the item's own key, in a one-line every with if any, is read before any item, so it fails on an empty list when it is missing, null or not an object / fails as unusable naming pr.m when it is 3 and tests is empty sentences / a root name on the right of some in a from line's condition, read up front / fails the candidate once, with no item named, even when its list is empty sentences / a root read through the item's own key, in a one-line every with if any, is read once, before any item, so it fails on an empty list when it is missing, null or not an object / fails as absent naming $params.m and $input.m when neither is there and tests is empty sentences / a root read through the item's own key, in a one-line every with if any, is read once, before any item, so it fails on an empty list when it is missing, null or not an object / fails as null naming $input.m when it is null and tests is empty diff --git a/engines/rust/sentences/tests/oracle/checks.rs b/engines/rust/sentences/tests/oracle/checks.rs index 47f94bad3..daeb6f9af 100644 --- a/engines/rust/sentences/tests/oracle/checks.rs +++ b/engines/rust/sentences/tests/oracle/checks.rs @@ -157,6 +157,30 @@ pub const CHECK_OK: &[(&str, &str, &[&str], &[&str])] = &[ &[], &[], ), + ( + "every tests whose $params.m.d named by key is 1, if any, exists", + "every tests whose $params.m.d named by key is 1, if any, exists", + &[], + &[], + ), + ( + "every tests whose pr.m named by key is 1, if any, exists", + "every tests whose pr.m named by key is 1, if any, exists", + &[], + &[], + ), + ( + "every tests whose tags contains $params.m named by key, if any, exists", + "every tests whose tags contains $params.m named by key, if any, exists", + &[], + &[], + ), + ( + "every tests whose v is in $params.m named by key, if any, exists", + "every tests whose v is in $params.m named by key, if any, exists", + &[], + &[], + ), ( "count of tests whose v equals $params.m named by key is 0", "count of tests whose v equals $params.m named by key is 0", diff --git a/spec/OPEN.md b/spec/OPEN.md index 5a9e1d249..621f583e4 100644 --- a/spec/OPEN.md +++ b/spec/OPEN.md @@ -101,12 +101,14 @@ OPA 1.20.2 crashes when it compares a number whose exponent is beyond ±1e6 with - **A root read through the subject's key beside an item that isn't an object (type 2).** With the params `{"m": {}}`, `key` "a" and `tests` `[{"v": 1, "key": "b"}]`, `count of tests.v that equals $params.m named by pr.key named by key is 0` fails as `absent` with `item 1 of tests: v: $params.m named by pr.key named by key is missing` in `ergo.rego`, and as `not_an_object` with `$params.m named by pr.key is missing; item 1 of tests: v is 1, which isn't an object` in the Rust engine. [problems.all_said](semantics.md#which-problems-a-message-says) says every problem and the worst cause, so the Rust engine is right. Since #960. The step that fixes it reads the root before any item in `ergo.rego`'s `that` too. - **A root that can't be read, beside a chain of keys that can't be read or a sum, in `ergo.rego` (type 3, [problems.all_said](semantics.md#which-problems-a-message-says), [problems.where_said](semantics.md#which-problems-a-message-says)).** With no `m` in the params and `tests` `[{"v": 1, "key": "b", "j": "c"}, {"v": 1, "key": "b"}]`, `count of tests whose v equals $params.m named by key named by j is 0` says `$params.m is missing` in `ergo.rego` and `$params.m is missing; item 2 of tests: j is missing` in the Rust engine, and with `j` `3` in the second item `ergo.rego` drops `item 2 of tests: j is 3, which isn't text` in the same way, so it no longer says the second key's problem, as it did on `main`. With `tests` `[]`, `sum of v of tests whose v equals $params.m named by key named by pr.key is 0` fails as `absent` in both engines, with `$params.m is missing` in the Rust engine and `sum of v of tests whose v equals $params.m named by key named by pr.key is 0 is false` in `ergo.rego`, which never names `$params.m`. With `named by art.key` or `named by art` where `art` holds an object, both engines fail as `unusable` with `art is an object with 2 keys, which isn't text`, and the Rust engine adds `; $params.m is missing`. No step is scheduled yet. - **A sum of a root read through the subject's key that finds a value that isn't an object says another message in `ergo.rego` (type 3, [problems.all_said](semantics.md#which-problems-a-message-says)).** With the params `{"m": {"a": 3}}`, `key` "a" and `tests` `[]`, `sum of v of tests whose v equals $params.m named by pr.key named by key is 0` fails as `unusable` in both engines, with `$params.m named by pr.key is 3, which isn't an object` in the Rust engine and `sum of v of tests whose v equals $params.m named by pr.key named by key needs more than 15 digits` in `ergo.rego`, which doesn't name the root. On `main` both engines pass this check, because neither reads the root before an item and the list is empty. Since #960. +- **The `outcome` of a root that isn't an object, read through the item's own key in a one-line `some` without `, if any,` over an empty list (type 2, [walk.inputs](semantics.md#every-and-some)).** With `m` holding `3` and `tests` `[]`, `some tests whose v is $input.m named by key exists` fails in both engines, but the root's entry has the outcome `usable` in the Rust engine and `unusable` in `ergo.rego`. The `derived` rows want `usable` and the `sentences` rows want `unusable`, so the cases contradict each other. It joins the open question of the rule for `inputs`. +- **The list's own problem beside a root read through the item's own key, in a one-line `some` without `, if any,` over an empty list (type 3, `ergo.rego` only, [problems.all_said](semantics.md#which-problems-a-message-says)).** With no `m` in the params and `tests` `[]`, `some tests whose v is $params.m named by key exists` says `$params.m is missing; tests is []` in the Rust engine and only `$params.m is missing` in `ergo.rego`. - **The root entry of a chain of two keys from the subject, when the first finds a value that isn't an object, has the outcome `absent` in `ergo.rego` and `unusable` in the Rust engine (type 2, [tally.inputs](semantics.md#counts-and-sums-in-sentences)).** With the params `{"m": {"a": 3}}`, `k1` "a", `k2` "b" and `tests` `[]`, `count of tests whose v equals $params.m named by pr.k1 named by pr.k2 named by key is 0` fails as `unusable` with `$params.m named by pr.k1 is 3, which isn't an object` in both engines, and the entry `$params.m named by pr.k1 named by pr.k2 named by key` of `inputs` has the outcome `unusable` in the Rust engine and `absent` in `ergo.rego`. With one key from the subject, both say `unusable`. The case "fails as unusable naming the value the first key finds when it is 3 and tests is empty" is listed in `known_differences`. - **A `count of`, `every` or `some` whose `whose` reads a parent's or the subject's field through a `null` key from the subject (type 2).** With subjects `art` from `arts` and `pr` from `every art.prs`, the parent's `m` holding `{"a": 1}`, the key `null` and `tests` holding `[{"v": 1}]`, `count of tests whose art.m named by pr.key is 1 is 0` fails in `ergo.rego` as `absent` with `item 1 of tests: .art.m named by pr.key is missing`, and in the Rust engine as `null` with `pr.key is null`. [tally.whose](semantics.md#counts-and-sums-in-sentences) says the key "is always said, once and before any item", so the Rust engine is right. A one-line `every` or `some` is the same, and so is a root from the subject: with the key `null` and `tests` `[{"v": 1}, {}]`, `every tests whose pr named by pr.key is 1, if any, exists` fails in `ergo.rego` as `absent` with `item 1 of tests: .pr named by pr.key is missing; item 2 of tests: .pr named by pr.key is missing`, and in the Rust engine as `null` with `pr.key is null`, and `art.m`, `pr.m` and `some` give the same. The other way round, with `key` `null` and `tests` `[{"v": 1}]`, `count of tests whose t2 named by pr.key exists is 0` and, under `for: every xs, if any, as x`, `count of tests whose x.m named by pr.key exists is 0` fail as `null` with `pr.key is null` in the Rust engine and as `absent` in `ergo.rego`. On `main` too. No case pins it. The step is in `ergo.rego`'s read of a path on the left of a `whose` that starts at a parent or the subject and ends with a key from the subject. - **The message of an `item` entry of a `for` line whose list is read through an alias's field that is missing (type 3).** With `for: every ab.items as c`, `assert: c.ok is true` and `ab` holding `[{"ok": true}, {"ok": false}]`, both engines fail as `absent` and say `item 1 of ab: items is missing; item 2 of ab: items is missing`. The message of each item entry is `item 1 of ab: items is missing` in the Rust engine and `items is missing` in `ergo.rego`. With a quoted key like `"a; b"` in place of `items`, it is the same, and the quoted `; ` reads fine in both engines. - **A `named by` key from the subject holding `3`, in `first of` under a `for` line, fails as `absent` in `ergo.rego` and `unusable` in Rust (type 2).** With `for: every xs as x, first of tests whose m named by pr.key is 1 as t`, `assert: t exists`, `key` `3`, `tests` `[]` and `xs` `[{"a": 1}]`, `ergo.rego` says `absent` with `tests is []` and the Rust engine says `unusable` with `pr.key is 3, which isn't text; tests is []`, which follows [path.field_step](semantics.md#reading-a-path). - **The assertion entry of `every tests whose $params.m named by $params.k is 1 exists` lacks the `$params.k` input in `ergo.rego` (type 3).** With the params `{"m": {"a": 1}, "k": "a"}` and `tests` `[]`, the Rust engine lists `$params.k` in the assertion entry's `inputs` and `ergo.rego` lists none. -- **The rows of the `sentences` cases of a root read through a `named by` key from the subject copy the Rust engine for fields no rule decides (type 3).** The groups "a root from $params read through a named by key from the subject ..." (the three of them, with the key on the left of a `whose` and under `for: every xs, if any, as x`) and "a root from $input or the subject itself read through a named by key from the subject ..." (the three of them) pin the verdict, the cause and the message, which [tally.whose](semantics.md#counts-and-sums-in-sentences) and [for.roots](semantics.md#for) decide. A row has to be written whole, so the rows also hold what no rule says (and the rows of the one-line `every` and the line alias cases written for the entries above hold them too, copied from the `count of` rows): whether `$params.m named by pr.key` is an entry of `inputs` at all ([walk.inputs](semantics.md#every-and-some) says both that it lists the path and its key, and that a `$params` path isn't an entry of `inputs`), the `locations` of the count entry (`[]`), whether `tests[]` is in the row's `inputs`, the `locations` of `xs[]` and the `inputs` of an item's entry. The group "a named by key from the subject that isn't text, on the left of a whose with exists, ..." also pins the subject's `key` holding `{}` as an input with the outcome `usable`, and `$params.m named by pr.key` with the outcome `unusable` and the value `null`, which no rule says either, as it is with `is 1`. The two groups for a root read through the item's own key and a key from the subject, in either order, over an empty list with no `m` in the params, copy the Rust engine in the same way (the `key` input with the outcome `usable`, and `$params:` as the location of the missing root, as the nearest rows have it). The cases for a chain with a key from `$params` and the item's key, in either order, copy the same nearest rows and the Rust engine's rows (the `$params.k` input with the outcome `usable`, and `$params:` and `$params:/k` as locations), and the case for a chain of the subject's key and then the item's key, with the params `{"m": {}}`, copies the rows of the nearest case in the same way, with `$params:/m` as the location of the root and `$params.m named by pr.key is missing` as the message, which no rule words for a missing step after a subject key. The group "a count of or sum of whose whose or that reads the line's alias, with or without a named by key, ..." copies the rows of the nearest `for` case on an empty list with `, if any,`, with `tests[].v` holding `[null]` at the item's location and, on the row without `, if any,`, the outcome `usable`. They are what the Rust engine gives, and `ergo.rego` gives the same. The two groups for a root read through the line alias and the item's key, in either order, under `for: every xs, if any, as x`, copy the Rust engine's rows in the same way, for `inputs` and `failures`, and pin only the verdict, the cause and the message by rule. The four groups for a root read through the subject's key and then the item's key, with the params' `m` `null`, `{"a": 3}` or `{"a": []}`, and for two keys from the subject with `{"a": 3}`, over an empty list, copy the Rust engine's rows for `inputs` and `failures` in the same way, after the verdict, the cause and the message, which tally.walk and for.roots decide, were the same in both engines. Settle them with one rule and then check the rows. +- **The rows of the `sentences` cases of a root read through a `named by` key from the subject copy the Rust engine for fields no rule decides (type 3).** The groups "a root from $params read through a named by key from the subject ..." (the three of them, with the key on the left of a `whose` and under `for: every xs, if any, as x`) and "a root from $input or the subject itself read through a named by key from the subject ..." (the three of them) pin the verdict, the cause and the message, which [tally.whose](semantics.md#counts-and-sums-in-sentences) and [for.roots](semantics.md#for) decide. A row has to be written whole, so the rows also hold what no rule says (and the rows of the one-line `every` and the line alias cases written for the entries above hold them too, copied from the `count of` rows): whether `$params.m named by pr.key` is an entry of `inputs` at all ([walk.inputs](semantics.md#every-and-some) says both that it lists the path and its key, and that a `$params` path isn't an entry of `inputs`), the `locations` of the count entry (`[]`), whether `tests[]` is in the row's `inputs`, the `locations` of `xs[]` and the `inputs` of an item's entry. The group "a named by key from the subject that isn't text, on the left of a whose with exists, ..." also pins the subject's `key` holding `{}` as an input with the outcome `usable`, and `$params.m named by pr.key` with the outcome `unusable` and the value `null`, which no rule says either, as it is with `is 1`. The three groups for a root on the value side of a one-line `every`, or from the subject, read through the item's own key over an empty list, which both engines pass, copy the rows of the nearest one-line `every` case that fails ("a root from $params read through the item's own key, in a one-line every with if any, is not an object …"), since no engine gives a failing row for them. The two groups for a root read through the item's own key and a key from the subject, in either order, over an empty list with no `m` in the params, copy the Rust engine in the same way (the `key` input with the outcome `usable`, and `$params:` as the location of the missing root, as the nearest rows have it). The cases for a chain with a key from `$params` and the item's key, in either order, copy the same nearest rows and the Rust engine's rows (the `$params.k` input with the outcome `usable`, and `$params:` and `$params:/k` as locations), and the case for a chain of the subject's key and then the item's key, with the params `{"m": {}}`, copies the rows of the nearest case in the same way, with `$params:/m` as the location of the root and `$params.m named by pr.key is missing` as the message, which no rule words for a missing step after a subject key. The group "a count of or sum of whose whose or that reads the line's alias, with or without a named by key, ..." copies the rows of the nearest `for` case on an empty list with `, if any,`, with `tests[].v` holding `[null]` at the item's location and, on the row without `, if any,`, the outcome `usable`. They are what the Rust engine gives, and `ergo.rego` gives the same. The two groups for a root read through the line alias and the item's key, in either order, under `for: every xs, if any, as x`, copy the Rust engine's rows in the same way, for `inputs` and `failures`, and pin only the verdict, the cause and the message by rule. The four groups for a root read through the subject's key and then the item's key, with the params' `m` `null`, `{"a": 3}` or `{"a": []}`, and for two keys from the subject with `{"a": 3}`, over an empty list, copy the Rust engine's rows for `inputs` and `failures` in the same way, after the verdict, the cause and the message, which tally.walk and for.roots decide, were the same in both engines. Settle them with one rule and then check the rows. - **A chain of two keys from the subject after `exists`, over a list with items, when both keys fail or the value between them can't take a key (type 2, both engines).** The verdicts agree, and with `tests` `[]` so do the cause and the message. With `tests` `[{"v": 1}]`, `pr.key` missing and `pr.j` `3`, `every tests whose $params.m named by pr.key named by pr.j exists exists` fails as `unusable` with `pr.j is 3, which isn't text; pr.key is missing` in the Rust engine, and as `absent` with `pr.key is missing` in `ergo.rego`. [problems.all_said](semantics.md#which-problems-a-message-says) says a message says every problem and the row's cause is the worst of them, so `ergo.rego` is wrong there. The same `count of … is 0` fails as `unusable` in both, but `ergo.rego` says only `pr.key is missing`, and with both keys `null` it says `pr.key is null, and pr.j is null` where the Rust engine says `pr.j is null; pr.key is null`. With `pr.key` `"a"`, `pr.j` `"b"` and the params `{"m": {"a": 1}}`, `count of tests whose $params.m named by pr.key named by pr.j exists is 0` says `item 1 of tests: $params.m named by pr.key is 1, which isn't an object` in the Rust engine, where `ergo.rego` says it once, before any item, with no item in front, as [problems.where_said](semantics.md#which-problems-a-message-says) says for a problem in something read from outside the item. The step that fixes it: `ergo.rego` reads every key of the chain before the items when the list has items too, and the Rust engine says the value between the keys before any item after `exists`. The spec doesn't settle these yet, because the two engines give different reports. Unless a line says otherwise, both fail and pass the same checks. @@ -236,6 +238,8 @@ The spec doesn't settle these yet, because the two engines give different report ## Where both engines differ from a rule +- **A root on the value side of a one-line `every` or `some … whose`, read through the item's own key, over an empty list (type 1, both engines, [tally.walk](semantics.md#counts-and-sums-in-sentences), [for.roots](semantics.md#for)).** With no `m` in the params (or `m` holding `3`) and `tests` `[]`, `every tests whose v is in $params.m named by key, if any, exists` and `every tests whose tags contains $params.m named by key, if any, exists` pass in both engines. tally.walk says the list a whose looks in is read before any item, on an empty list too, and a root that's missing fails as `absent` and one of the wrong type as `unusable`, even when the list is empty, and the `count of` form already fails so in both engines. The same holds for the value side of every other comparison, like `is`, `is at least` and `is one of`. The two `sentences` groups "a root from $params read through the item's own key on the value side of a whose …" pin the right verdict and are known failures in both engines. The `derived` case "a count or every whose whose reads a root outside the item through a key the item holds says the root and then the list's own problem / the root is null and the list is empty" pins `every xs whose tags contains $input.m named by key, if any, exists` as passing, which is the wrong verdict, and has to change with the fix. Fix: read the root of the `whose` on the value side before any item, in `_keyed_walk_cond` and `_keyed_whose_conds` (`engines/rego/src/lines/roots.rego`) and in the Rust engine's `whose_roots` (`engine/src/ops/walk.rs`), which both read only the left side today. +- **A root from the subject in a one-line `every … whose`, read through the item's own key, over an empty list (type 1, both engines, [tally.walk](semantics.md#counts-and-sums-in-sentences), [for.roots](semantics.md#for)).** With the subject's `m` missing, `null` or `3` (or `[]` in `pr.m.d`) and `tests` `[]`, `every tests whose pr.m named by key is 1, if any, exists` passes in both engines, and so does `count of tests whose pr.m named by key is 1 is 0`. tally.walk says such a root fails as `absent`, `null` or `unusable` even when the list is empty, as a root from `$params` or `$input` does. The `sentences` group "a root from the subject read through the item's own key, in a one-line every with if any, …" pins the right verdict and is a known failure in both engines. Fix: read a subject root through the item's key before any item, as `_keyed_root_path` and the Rust engine's `key_base::base_of` do for `$params` and `$input`. - **The order of the `inputs` of a one-line `every` or `some` whose `whose` reads a root through the item's own key, over an empty list (type 2, both engines, [walk.inputs](semantics.md#every-and-some)).** With no `m` in the input and `tests` `[]`, `every tests whose $input.m named by key is 1, if any, exists` fails in both engines as `absent` with `$input.m is missing`, since the root is read before any item ([for.roots](semantics.md#for)). Both engines list the same two inputs, `$input.m` and `tests[]`, but they put `$input.m` first and the case puts `tests[]` first. No rule in walk.inputs says which comes first, and the cases on `main` use both orders (136 put the root first, sorted by name, and 21 the walked list). The same holds when `$input.m` is `null` or `3`. Cases: `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" (three rows), in `known_differences` and in `engines/rust/known-failures.txt`. The step: decide the order of `inputs`, and then the three rows follow it. - **A `named by` key from the subject after the line's alias, under a `for` line with items, is said with the line's item in front by a case (type 3, both engines, a case differs from a rule, [tally.whose](semantics.md#counts-and-sums-in-sentences), [problems.where_said](semantics.md#which-problems-a-message-says)).** With `for: every ms as mm`, `count of xs whose v equals mm named by pr.k is 1`, no `k` on the subject and `ms` and `xs` holding one item each, both engines fail as `absent` with `pr.k is missing`, said once on the assertion. The `sentences` case "a named by key from the subject after a parent or an alias, inside a relative clause" says `item 1 of ms: pr.k is missing`, with the problem on an `item 1 of ms` entry. tally.whose says a key that is missing "is always said, once and before any item", and problems.where_said says a problem in something read from the subject "SHOULD be said once, before any item, with no item in front", so the case differs from both. It is a known failure of both engines. The step that fixes it: a decision on the case's row. diff --git a/spec/cases/sentences/cases.json b/spec/cases/sentences/cases.json index e0d977b85..d60a3311d 100644 --- a/spec/cases/sentences/cases.json +++ b/spec/cases/sentences/cases.json @@ -88972,6 +88972,10 @@ {"description": "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", "policy": {"ergo_spec": "{{spec}}", "subjects": {"pr": {"from": "prs", "identified_by": "id"}}, "requirements": {"r": {"subject": "pr", "min_subjects": 0, "checks": {"ep": "every tests whose $params.m named by key is 1, if any, exists", "ei": "every tests whose $input.m named by key is 1, if any, exists"}}}}, "params": {}, "cases": [{"description": "fails as absent naming $params.m and $input.m when neither is there and tests is empty", "rules": ["tally.walk", "for.roots", "problems.same_path"], "input": {"prs": [{"id": "p", "tests": []}]}, "results": [{"cause": "absent", "check": "ei", "failures": [{"cause": "absent", "failures": [], "inputs": [{"locations": [""], "name": "$input.m", "outcome": "absent", "value": null}], "kind": "assertion", "locations": ["$policy:/requirements/r/checks/ei"], "message": "$input.m is missing", "name": "every tests whose $input.m named by key is 1, if any, exists"}], "inputs": [{"locations": [], "name": "tests[]", "outcome": "usable", "value": []}, {"locations": [""], "name": "$input.m", "outcome": "absent", "value": null}], "message": "$input.m is missing", "passed": false, "requirement": "r", "subject": {"id": "p", "type": "pr"}}, {"cause": "absent", "check": "ep", "failures": [{"cause": "absent", "failures": [], "inputs": [], "kind": "assertion", "locations": ["$policy:/requirements/r/checks/ep"], "message": "$params.m is missing", "name": "every tests whose $params.m named by key is 1, if any, exists"}], "inputs": [{"locations": [], "name": "tests[]", "outcome": "usable", "value": []}], "message": "$params.m is missing", "passed": false, "requirement": "r", "subject": {"id": "p", "type": "pr"}}]}, {"description": "fails as null naming $input.m when it is null and tests is empty", "rules": ["tally.walk", "for.roots", "problems.same_path"], "input": {"m": null, "prs": [{"id": "p", "tests": []}]}, "results": [{"cause": "null", "check": "ei", "failures": [{"cause": "null", "failures": [], "inputs": [{"locations": ["/m"], "name": "$input.m", "outcome": "null", "value": null}], "kind": "assertion", "locations": ["$policy:/requirements/r/checks/ei"], "message": "$input.m is null", "name": "every tests whose $input.m named by key is 1, if any, exists"}], "inputs": [{"locations": [], "name": "tests[]", "outcome": "usable", "value": []}, {"locations": ["/m"], "name": "$input.m", "outcome": "null", "value": null}], "message": "$input.m is null", "passed": false, "requirement": "r", "subject": {"id": "p", "type": "pr"}}, {"cause": "absent", "check": "ep", "failures": [{"cause": "absent", "failures": [], "inputs": [], "kind": "assertion", "locations": ["$policy:/requirements/r/checks/ep"], "message": "$params.m is missing", "name": "every tests whose $params.m named by key is 1, if any, exists"}], "inputs": [{"locations": [], "name": "tests[]", "outcome": "usable", "value": []}], "message": "$params.m is missing", "passed": false, "requirement": "r", "subject": {"id": "p", "type": "pr"}}]}, {"description": "fails as unusable naming $input.m when it is 3 and tests is empty", "rules": ["tally.walk", "for.roots", "problems.same_path"], "input": {"m": 3, "prs": [{"id": "p", "tests": []}]}, "results": [{"cause": "unusable", "check": "ei", "failures": [{"cause": "unusable", "failures": [], "inputs": [{"locations": ["/m"], "name": "$input.m", "outcome": "unusable", "value": 3}], "kind": "assertion", "locations": ["$policy:/requirements/r/checks/ei"], "message": "$input.m is 3, which isn't an object", "name": "every tests whose $input.m named by key is 1, if any, exists"}], "inputs": [{"locations": [], "name": "tests[]", "outcome": "usable", "value": []}, {"locations": ["/m"], "name": "$input.m", "outcome": "unusable", "value": 3}], "message": "$input.m is 3, which isn't an object", "passed": false, "requirement": "r", "subject": {"id": "p", "type": "pr"}}, {"cause": "absent", "check": "ep", "failures": [{"cause": "absent", "failures": [], "inputs": [], "kind": "assertion", "locations": ["$policy:/requirements/r/checks/ep"], "message": "$params.m is missing", "name": "every tests whose $params.m named by key is 1, if any, exists"}], "inputs": [{"locations": [], "name": "tests[]", "outcome": "usable", "value": []}], "message": "$params.m is missing", "passed": false, "requirement": "r", "subject": {"id": "p", "type": "pr"}}]}]}, {"description": "a root from $params read through the item's own key, in a one-line every with if any, is null, so it fails as null on an empty list", "policy": {"ergo_spec": "{{spec}}", "subjects": {"pr": {"from": "prs", "identified_by": "id"}}, "requirements": {"r": {"subject": "pr", "min_subjects": 0, "checks": {"ep": "every tests whose $params.m named by key is 1, if any, exists"}}}}, "params": {"m": null}, "cases": [{"description": "fails as null naming $params.m when tests is empty", "rules": ["tally.walk", "for.roots", "problems.same_path"], "input": {"prs": [{"id": "p", "tests": []}]}, "results": [{"cause": "null", "check": "ep", "failures": [{"cause": "null", "failures": [], "inputs": [], "kind": "assertion", "locations": ["$policy:/requirements/r/checks/ep"], "message": "$params.m is null", "name": "every tests whose $params.m named by key is 1, if any, exists"}], "inputs": [{"locations": [], "name": "tests[]", "outcome": "usable", "value": []}], "message": "$params.m is null", "passed": false, "requirement": "r", "subject": {"id": "p", "type": "pr"}}]}]}, {"description": "a root from $params read through the item's own key, in a one-line every with if any, is not an object, so it fails as unusable on an empty list", "policy": {"ergo_spec": "{{spec}}", "subjects": {"pr": {"from": "prs", "identified_by": "id"}}, "requirements": {"r": {"subject": "pr", "min_subjects": 0, "checks": {"ep": "every tests whose $params.m named by key is 1, if any, exists"}}}}, "params": {"m": 3}, "cases": [{"description": "fails as unusable naming $params.m when tests is empty", "rules": ["tally.walk", "for.roots", "problems.same_path"], "input": {"prs": [{"id": "p", "tests": []}]}, "results": [{"cause": "unusable", "check": "ep", "failures": [{"cause": "unusable", "failures": [], "inputs": [], "kind": "assertion", "locations": ["$policy:/requirements/r/checks/ep"], "message": "$params.m is 3, which isn't an object", "name": "every tests whose $params.m named by key is 1, if any, exists"}], "inputs": [{"locations": [], "name": "tests[]", "outcome": "usable", "value": []}], "message": "$params.m is 3, which isn't an object", "passed": false, "requirement": "r", "subject": {"id": "p", "type": "pr"}}]}]}, + {"description": "a root from $params read through the item's own key on the value side of a whose, in a one-line every with if any, is read before any item, so it fails on an empty list when it is missing", "policy": {"ergo_spec": "{{spec}}", "subjects": {"pr": {"from": "prs", "identified_by": "id"}}, "requirements": {"r": {"subject": "pr", "min_subjects": 0, "checks": {"ei": "every tests whose v is in $params.m named by key, if any, exists", "ec": "every tests whose tags contains $params.m named by key, if any, exists"}}}}, "params": {}, "cases": [{"description": "fails as absent naming $params.m when tests is empty", "rules": ["tally.walk", "for.roots"], "input": {"prs": [{"id": "p", "tests": []}]}, "results": [{"cause": "absent", "check": "ec", "failures": [{"cause": "absent", "failures": [], "inputs": [], "kind": "assertion", "locations": ["$policy:/requirements/r/checks/ec"], "message": "$params.m is missing", "name": "every tests whose tags contains $params.m named by key, if any, exists"}], "inputs": [{"locations": [], "name": "tests[]", "outcome": "usable", "value": []}], "message": "$params.m is missing", "passed": false, "requirement": "r", "subject": {"id": "p", "type": "pr"}}, {"cause": "absent", "check": "ei", "failures": [{"cause": "absent", "failures": [], "inputs": [], "kind": "assertion", "locations": ["$policy:/requirements/r/checks/ei"], "message": "$params.m is missing", "name": "every tests whose v is in $params.m named by key, if any, exists"}], "inputs": [{"locations": [], "name": "tests[]", "outcome": "usable", "value": []}], "message": "$params.m is missing", "passed": false, "requirement": "r", "subject": {"id": "p", "type": "pr"}}]}]}, + {"description": "a root from $params read through the item's own key on the value side of a whose, in a one-line every with if any, is read before any item, so it fails as unusable on an empty list when it is not an object", "policy": {"ergo_spec": "{{spec}}", "subjects": {"pr": {"from": "prs", "identified_by": "id"}}, "requirements": {"r": {"subject": "pr", "min_subjects": 0, "checks": {"ei": "every tests whose v is in $params.m named by key, if any, exists", "ec": "every tests whose tags contains $params.m named by key, if any, exists"}}}}, "params": {"m": 3}, "cases": [{"description": "fails as unusable naming $params.m when tests is empty", "rules": ["tally.walk", "for.roots"], "input": {"prs": [{"id": "p", "tests": []}]}, "results": [{"cause": "unusable", "check": "ec", "failures": [{"cause": "unusable", "failures": [], "inputs": [], "kind": "assertion", "locations": ["$policy:/requirements/r/checks/ec"], "message": "$params.m is 3, which isn't an object", "name": "every tests whose tags contains $params.m named by key, if any, exists"}], "inputs": [{"locations": [], "name": "tests[]", "outcome": "usable", "value": []}], "message": "$params.m is 3, which isn't an object", "passed": false, "requirement": "r", "subject": {"id": "p", "type": "pr"}}, {"cause": "unusable", "check": "ei", "failures": [{"cause": "unusable", "failures": [], "inputs": [], "kind": "assertion", "locations": ["$policy:/requirements/r/checks/ei"], "message": "$params.m is 3, which isn't an object", "name": "every tests whose v is in $params.m named by key, if any, exists"}], "inputs": [{"locations": [], "name": "tests[]", "outcome": "usable", "value": []}], "message": "$params.m is 3, which isn't an object", "passed": false, "requirement": "r", "subject": {"id": "p", "type": "pr"}}]}]}, + {"description": "a root from the subject read through the item's own key, in a one-line every with if any, is read before any item, so it fails on an empty list when it is missing, null or not an object", "policy": {"ergo_spec": "{{spec}}", "subjects": {"pr": {"from": "prs", "identified_by": "id"}}, "requirements": {"r": {"subject": "pr", "min_subjects": 0, "checks": {"es": "every tests whose pr.m named by key is 1, if any, exists"}}}}, "params": {}, "cases": [{"description": "fails as absent naming pr.m when it is missing and tests is empty", "rules": ["tally.walk", "for.roots"], "input": {"prs": [{"id": "p", "tests": []}]}, "results": [{"cause": "absent", "check": "es", "failures": [{"cause": "absent", "failures": [], "inputs": [], "kind": "assertion", "locations": ["$policy:/requirements/r/checks/es"], "message": "pr.m is missing", "name": "every tests whose pr.m named by key is 1, if any, exists"}], "inputs": [{"locations": [], "name": "tests[]", "outcome": "usable", "value": []}], "message": "pr.m is missing", "passed": false, "requirement": "r", "subject": {"id": "p", "type": "pr"}}]}, {"description": "fails as null naming pr.m when it is null and tests is empty", "rules": ["tally.walk", "for.roots"], "input": {"prs": [{"id": "p", "tests": [], "m": null}]}, "results": [{"cause": "null", "check": "es", "failures": [{"cause": "null", "failures": [], "inputs": [], "kind": "assertion", "locations": ["$policy:/requirements/r/checks/es"], "message": "pr.m is null", "name": "every tests whose pr.m named by key is 1, if any, exists"}], "inputs": [{"locations": [], "name": "tests[]", "outcome": "usable", "value": []}], "message": "pr.m is null", "passed": false, "requirement": "r", "subject": {"id": "p", "type": "pr"}}]}, {"description": "fails as unusable naming pr.m when it is 3 and tests is empty", "rules": ["tally.walk", "for.roots"], "input": {"prs": [{"id": "p", "tests": [], "m": 3}]}, "results": [{"cause": "unusable", "check": "es", "failures": [{"cause": "unusable", "failures": [], "inputs": [], "kind": "assertion", "locations": ["$policy:/requirements/r/checks/es"], "message": "pr.m is 3, which isn't an object", "name": "every tests whose pr.m named by key is 1, if any, exists"}], "inputs": [{"locations": [], "name": "tests[]", "outcome": "usable", "value": []}], "message": "pr.m is 3, which isn't an object", "passed": false, "requirement": "r", "subject": {"id": "p", "type": "pr"}}]}]}, + {"description": "a root from $params read through the item's own key after a field, in a one-line every with if any, fails as unusable on an empty list when the step before the field is a list", "policy": {"ergo_spec": "{{spec}}", "subjects": {"pr": {"from": "prs", "identified_by": "id"}}, "requirements": {"r": {"subject": "pr", "min_subjects": 0, "checks": {"el": "every tests whose $params.m.d named by key is 1, if any, exists"}}}}, "params": {"m": []}, "cases": [{"description": "fails as unusable naming $params.m when it is [] and tests is empty", "rules": ["tally.walk", "for.roots"], "input": {"prs": [{"id": "p", "tests": []}]}, "results": [{"cause": "unusable", "check": "el", "failures": [{"cause": "unusable", "failures": [], "inputs": [], "kind": "assertion", "locations": ["$policy:/requirements/r/checks/el"], "message": "$params.m is [], which isn't an object", "name": "every tests whose $params.m.d named by key is 1, if any, exists"}], "inputs": [{"locations": [], "name": "tests[]", "outcome": "usable", "value": []}], "message": "$params.m is [], which isn't an object", "passed": false, "requirement": "r", "subject": {"id": "p", "type": "pr"}}]}]}, {"description": "a root from $params read through the line alias's key depends on the item, so the check is left out when xs is empty, whether or not the root can be read", "policy": {"ergo_spec": "{{spec}}", "subjects": {"pr": {"from": "prs", "identified_by": "id"}}, "requirements": {"r": {"subject": "pr", "min_subjects": 0, "checks": {"alias": {"for": "every xs, if any, as x", "assert": "count of tests whose $params.m named by x.k exists is 0"}}}}}, "params": {}, "cases": [{"description": "passes when xs and tests are empty and the params have no m", "rules": ["for.if_any", "for.second_items", "for.roots"], "input": {"prs": [{"id": "p", "tests": [], "xs": []}]}, "results": [{"cause": "satisfied", "check": "alias", "inputs": [{"locations": [], "name": "tests[]", "value": []}, {"locations": [], "name": "xs[]", "value": []}], "passed": true, "requirement": "r", "subject": {"id": "p", "type": "pr"}}]}]}, {"description": "the examples the rules for where a name resolves were decided on", "policy": {"ergo_spec": "{{spec}}", "subjects": {"pr": {"from": "prs", "identified_by": "id"}}, "requirements": {"r": {"subject": "pr", "checks": {"username_in_focus": "count of approvers.username whose state is \"APPROVED\" is 1", "approvers_in_focus": "count of approvers whose state is \"APPROVED\" is 1", "right_side_from_the_subject": "every approvers.username does not equal author", "count_right_side": "count of approvers is at least min_approvals", "two_fields_of_an_item_after_every": "every approvers.approved_at is after assigned_at", "two_fields_of_an_item_in_a_whose": "count of deployments whose finished_at is after started_at is 1", "subject_field_in_a_clause": "count of approvers whose username does not equal pr.author is 1", "bare_name_in_a_clause": "count of approvers whose username does not equal author is 1", "whole_subject": "pr is an object", "two_clauses_and_a_new_assertion": "count of approvers whose state is \"APPROVED\" and whose username does not equal pr.author is at least 1 and author is \"ann\""}}}}, "cases": [{"description": "each check reads its names where the rules say, on the pull request of the decision", "rules": ["sentence.resolve.root", "sentence.resolve.focus", "sentence.resolve.clause", "sentence.path.subject.step", "sentence.assert.and", "walk.items", "tally.whose", "message.items"], "input": {"prs": [{"id": "p1", "author": "ann", "min_approvals": 2, "approvers": [{"username": "bob", "state": "APPROVED", "assigned_at": "2026-01-02T00:00:00Z", "approved_at": "2026-01-03T00:00:00Z"}, {"username": "ann", "state": "APPROVED", "assigned_at": "2026-01-04T00:00:00Z", "approved_at": "2026-01-03T00:00:00Z"}], "deployments": [{"started_at": "2026-01-02T00:00:00Z", "finished_at": "2026-01-03T00:00:00Z"}, {"started_at": "2026-01-05T00:00:00Z", "finished_at": "2026-01-04T00:00:00Z"}]}]}, "results": [ { From 362da8aa6bd301b20ba4b4424ed12db415387bee Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 08:28:32 +0100 Subject: [PATCH 56/57] docs: say the one-line walk reads only the left side's root through the item's key before any item 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 71f1a4cff..dd5d38daf 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 -- A one-line `every` or `some` whose `whose` reads a root through the item's own `named by` key 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 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. diff --git a/engines/rust/CHANGELOG.md b/engines/rust/CHANGELOG.md index 38cb95c7e..9838243a0 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 one-line `every` or `some` whose `whose` reads a root through the item's own `named by` key 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 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. In the Rust engine alone, a one-line `some` or `every` without `, if any,` on an empty list now takes the root's cause, like `absent` with `$params.m named by pr.key is missing; tests is []` where it said `value` with `tests is []`, and `count of tests.v that equals $params.m named by pr.key named by key is 0` with an item that isn't an object fails as `not_an_object`, naming the root and the item, where it said `absent`. 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`. From e5e16196b8b042b6ba3e7a29161949c62d354789 Mon Sep 17 00:00:00 2001 From: Julien Biezemans Date: Sat, 5 Dec 2026 09:30:32 +0100 Subject: [PATCH 57/57] spec: put back the three known differences that the narrowing makes fail again Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01MzW4N4nUhpU9sV5yVyXkyn --- engines/rego/tests/spec_test.rego | 3 +++ spec/OPEN.md | 1 + 2 files changed, 4 insertions(+) diff --git a/engines/rego/tests/spec_test.rego b/engines/rego/tests/spec_test.rego index 73cfeab06..5e7acadba 100644 --- a/engines/rego/tests/spec_test.rego +++ b/engines/rego/tests/spec_test.rego @@ -11,6 +11,9 @@ known_differences := { "derived / a parent's name used as the named by key of a count's whose, with no for line, is read before any item, so it fails on an empty list too / fails as unusable on a parent that isn't text, before any item, whether es is empty, null or missing", "derived / an every or some whose whose reads a root from $input through a key the item holds fails on the root, said once, when each item reads fine / the root is a number", "derived / an every or some whose whose reads a root from $input through a key the item holds fails on the root, said once, when each item reads fine / the root is an empty list", + "derived / an every or some whose whose reads a root from $input through a key the item holds fails on the root, said once, when each item reads fine / the root is missing", + "derived / an every or some whose whose reads a root from $input through a key the item holds fails on the root, said once, when each item reads fine / the root is null", + "derived / an every or some whose whose reads a root from $params through a key the item holds fails on the root, said once, when each item reads fine / the root is null", "field_of / a field in front of a list with whose and a list along the field, named like a for alias, is the alias, which shadows the field of the same name / the alias holds the sha the phrase wants, and the commit of the kept pull request does not", "field_of / a field in front of a list with whose, named like a for alias, is the alias, which shadows a field with the same name / the alias is the text the phrase wants, and the unit test's own field isn't", "field_of / a field with a dot in front of a list with whose and a list along the field, named like a for alias, reads the field and not the alias / the commit of the kept pull request is ok, and the alias holds a sha that is not", diff --git a/spec/OPEN.md b/spec/OPEN.md index 621f583e4..4a3c11c96 100644 --- a/spec/OPEN.md +++ b/spec/OPEN.md @@ -93,6 +93,7 @@ OPA 1.20.2 crashes when it compares a number whose exponent is beyond ±1e6 with - **The wording of a chain of keys that can't be read, in a few shapes (type 3).** `$params.m named by key named by j does not exist` says its problems in a different order in the two engines. Under a `for` line, `first of` has `; tests is []` added in the Rust engine. With `count of tests whose $params.m named by key exists is 0`, the Rust engine says `item 1 of tests: key is missing` and `ergo.rego` says `""`. With `count of tests whose v exists and whose $params.m named by pr.key exists is 0`, `ergo.rego` says `count of … is 0 is false`. No step is scheduled yet. - **The `failures` of a `count of` over a list with items, whose `whose` reads a root through two `named by` keys from the subject (type 3, [row.parts](semantics.md#what-a-row-shows)).** With the params `{"m": {"a": {"y": {"j": 1}}}}`, the subject's `key` holding `"a"` and `j` holding `"q"`, and `tests` holding `[{"v": 1, "pr": "y"}]`, `count of tests whose v equals $params.m named by pr.key named by pr.j is 1` fails as `absent` with `$params.m named by pr.key named by pr.j is missing` in both engines. The Rust engine puts the problem on the assertion, with no item entry, and `ergo.rego` puts it on an `item 1 of tests` entry and gives the assertion the message `""`. It is the shape of the entry below with one key, so its step fixes it too. Case: `sentences` "two named by keys from the subject, one after the other, are both read from the subject and never from the item", in `known_differences`. - **A root read through the item's own key that can't be read is said again for each item in `ergo.rego` (type 3, [problems.where_said](semantics.md#which-problems-a-message-says)).** With no params and `tests` holding `[{"key": "a", "v": 1}]`, `count of tests whose $params.m named by key is 1 is 0` and `for: every tests whose $params.m named by key is 1, if any, as t` with `t exists` fail as `absent` in both engines, with `$params.m is missing` in the Rust engine and `$params.m is missing; item 1 of tests: $params.m named by key is missing` in `ergo.rego`. The same goes for `$input.m`, for `exists`, `is one of`, `is true`, `matches` and `is in` after the root, and for `m` `null` or `3`. With `m` `null` and `tests` holding `[{"v": 1}]`, the `for` line says `$params.m is null; item 1 of tests: key is missing; $params.m is null` in `ergo.rego`, and the Rust engine says the root once, first. problems.where_said says a problem in something read from outside the item is said once, with no item in front, so the Rust engine is right. On `main` `ergo.rego` passed these on an empty list and named only the items here. A chain of the item's own key and a key from the subject, in either order, does the same: with the subject's `key` holding `"a"` and `tests` holding `[{"v": 1, "key": "b"}]`, `count of tests whose $params.m named by pr.key named by key is 1 is 0` says `$params.m is missing; item 1 of tests: $params.m named by pr.key named by key is missing` in `ergo.rego` and `$params.m is missing` in the Rust engine, and with `m` `null` or `3` the item says `$params.m is null` or `$params.m is 3, which isn't an object` again. A one-line `every` over that list names only the item in `ergo.rego`, on `main` too. With items, `for: every tests whose v equals $params.m named by key named by pr.key, if any, as t` says `$params.m is missing` and then `item N of tests: $params.m named by key named by pr.key is missing` for each item, where the Rust engine says only the root. The step that fixes it: `ergo.rego` leaves a root it has said out of each item's problems, as it does after `equals` and `is at least`. +- **A root read through the item's own key, said on each item entry in `ergo.rego` and once on the assertion by the cases, in a one-line `every` or `some … whose` when each item reads fine (type 3, [problems.where_said](semantics.md#which-problems-a-message-says)).** With `$input.m` missing or `null`, or `$params.m` `null`, and `tests` holding items that have the key, `ergo.rego` says `item 1 of tests: $params.m is null` on the item's entry, where the `derived` group "an every or some whose whose reads a root from $input or $params through a key the item holds fails on the root, said once, when each item reads fine" wants `$params.m is null` once on the assertion. The verdict and the cause are the same in both engines, and the Rust engine passes these cases. Cases: the `derived` rows for `$input` missing, `$input` null and `$params` null, in `known_differences` only. The step: say the root once in `ergo.rego`, then drop the rows. - **The `failures` of a `count of` over a list with items, whose `whose` reads a root through a `named by` key from the subject that the root doesn't have (type 3, [row.parts](semantics.md#what-a-row-shows)).** With no params, `count of xs whose v equals $params.m named by pr.k is 1`, the key `"a"` and `xs` holding `[{"v": 1}]` fails as `absent` with `$params.m named by pr.k is missing` in both engines. `ergo.rego` puts the problem on an `item 1 of xs` entry, as the `sentences` case "a key from the subject that can't be read, in a relative clause" pins, and the Rust engine puts it on the assertion, with no item entry. row.parts says "something read outside the item sits on the assertion, once, and items hold only their own problems", so the Rust engine follows the rule and the case doesn't. The same goes for `pr named by pr.k`, and for the key `null`. It is the same with items the clause can't read: with the params `{"m": {"a": 1}}`, the key `"b"` and `tests` holding `[{"v": 1}, {}]`, `count of tests whose v equals $input.m named by pr.key is 0` says `$input.m named by pr.key is missing; item 2 of tests: v is missing` in both engines, and `ergo.rego` adds an `item 1 of tests` entry that holds the root's problem, for `pr named by pr.key`, `count of tests.v that …` and `sum of tests.v whose $params.m named by pr.key is 1` too. The `sentences` case "a root from $input or the subject itself read through a named by key from the subject, in a count of or a sum of over items, ..." follows the rule, so it is in `known_differences`. The step that fixes it: a decision on the case's rows, then `ergo.rego` reads the root before any item there too. - **A key from the subject that can't be read, beside a root that is missing or `null`, in a one-line `every` or `some`, an `every … that` or a `for` line (type 3).** With no params and the key `[]`, `every tests whose v equals $params.d.m named by pr.key exists` fails as `unusable` in both engines. `ergo.rego` says `pr.key is [], which isn't text; $params.d.m named by pr.key is missing` and the Rust engine says only `pr.key is [], which isn't text`, as both engines do for `count of`. A key that is missing, `null` or `3` beside a root that is `null` is the same, in `every`, `some` and `every … that`, with the root `$params.m`, `$input.m`, `pr.m` or the parent's `art.m`: with no key, the params `{"m": null}` and `tests` `[{}]`, `every tests whose v equals $params.m named by pr.key exists` fails as `absent` in both engines, with `pr.key is missing; item 1 of tests: v is missing` in the Rust engine, and `ergo.rego` adds `$params.m is null` after the key. A `for` line's second `whose` is the same: with subjects `art` from `arts` and `pr` from `every art.prs`, the key `3`, `xs` `[{}]` and `tests` `[{"v": 1}]`, `for: every xs as x, every tests whose v equals x.m named by pr.key, if any, as t` with `t exists` fails as `unusable` in both engines, with `pr.key is 3, which isn't text` in the Rust engine and `pr.key is 3, which isn't text; item 1 of xs: x.m named by pr.key is missing` in `ergo.rego`, and `first of tests whose v equals x.m named by pr.key as t` too. [problems.all_said](semantics.md#which-problems-a-message-says) says "A message SHOULD say every problem Ergo finds", and the root can't be read whatever the key holds, so `ergo.rego` follows it here. On `main` `ergo.rego` failed the first one as `absent`. No step is scheduled yet. - **A one-line walk under a `for` line whose root is the line's alias read through a key from the subject says the key twice (type 3, [problems.where_said](semantics.md#which-problems-a-message-says)).** With no key, `xs` `[{"m": null}]` and `tests` `[{}]`, `every tests whose v equals x.m named by pr.key exists` under `for: every xs as x` fails as `absent` in both engines, with `pr.key is missing; item 1 of xs: item 1 of tests: v is missing` in the Rust engine and `pr.key is missing; item 1 of xs: pr.key is missing; x.m is null; item 1 of xs: item 1 of tests: v is missing` in `ergo.rego`. problems.where_said says a key read from outside the item is said once, with no item in front, so the Rust engine follows it, though `ergo.rego` also names `x.m is null`, which [problems.all_said](semantics.md#which-problems-a-message-says) asks for. With `tests` `[{}, {"v": 1}]`, `sum of tests.v that equals x.m named by pr.key is 1` says `pr.key is missing; item 1 of xs: item 1 of tests: v is missing` in the Rust engine and `pr.key is missing; item 1 of tests: v is missing` in `ergo.rego`, which drops `item 1 of xs:` in front. No step is scheduled yet.