From 9e7d55c3fd0eff0733559d01c285b13c70992a08 Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Wed, 19 Aug 2026 21:30:13 -0700 Subject: [PATCH 1/3] fix(coderabbit-config): rank findings under the cap, index key nodes once per mapping (BE-7786) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Round-2 review findings. The first two are regressions in the round-1 fix itself, not in the original change. * HIGH — the round-1 cap truncated in error-sort order, and the root `additionalProperties` error has an EMPTY `absolute_path`, so it sorts first and fans out to one finding per unknown key. 150 unknown root keys plus one `maxLength` violation therefore sliced the file-rejecting error away and left 100 warnings: exit 0 on a config CodeRabbit rejects WHOLE. Findings now carry a rank and `_apply_cap` drops the lowest first, so a file-rejecting error is never crowded out. The compensating note could not have covered this — a note does not reach the exit code, the same argument that turned the bounded-walk report into a finding. * HIGH — the cap bounded the output but not the work: `_extra_keys` returns every extra key in the mapping, and each finding rescanned all of `parent.value` constructing candidate keys. ~50k unknown root keys fit inside MAX_CONFIG_BYTES and cost ~1e9 constructions, so the job burned to its timeout instead of printing 100 annotations. The fan-out now stops at the cap, and the resolved-key -> node map is built once per mapping and cached on the composed node. 20k keys: 1.6s. * The incomplete-scan report was appended after both truncation sites, so a run that filled the cap emitted MAX_FINDINGS + 1 alongside a note saying only the first MAX_FINDINGS are reported. It goes through the same cap now, ranked above unknown keys so it is not the one dropped. * `_suggest_home` compared `_format_path`'s `[0]` against `_index_schema_paths`' `[]`, so neither the parent preference nor the self-exclusion could ever match for a key under a list element. Both vocabularies are normalized before the comparison. * Two keys still fell back to `str()`, reproducing the defect round 1 fixed: a `.nan:` key (NaN is not equal to itself, so it missed its own entry) and a merge-keyed mapping (`safe_load` flattens `<<: *anchor`, but the composed node keeps only `<<`). The index normalizes NaN and expands merge sources, with explicit keys keeping YAML's own precedence over merged ones and a cycle guard for `&x [*x]`. * `bounded` was set on ENTRY to `walk`, so spending the last budget unit on a known key whose value is a scalar flagged the trailing visit as a partial walk — a fully walked document reported as stopped early, which is a hard error under `strict_unknown_keys`. A node with nothing to inspect now returns before the bail-out. * The cutoff message said "after MAX_WALK_KEYS keys" while the counter also charges node visits, and the docs claimed the five explicitly closed objects were exempt from the vendored-schema staleness window. They are not: a key upstream adds at the root is missing from the vendored `properties` and its `additionalProperties: false` rejects it just the same. Both corrected. 87 tests (up from 72); every case above is pinned. --- .github/coderabbit-config/README.md | 15 +- .../check_coderabbit_config.py | 239 ++++++++++++++---- .../tests/test_check_coderabbit_config.py | 148 +++++++++++ docs/callers/coderabbit-config-validate.md | 15 +- 4 files changed, 362 insertions(+), 55 deletions(-) diff --git a/.github/coderabbit-config/README.md b/.github/coderabbit-config/README.md index 33ab206f..d991a2cb 100644 --- a/.github/coderabbit-config/README.md +++ b/.github/coderabbit-config/README.md @@ -73,13 +73,16 @@ pins the two premises that rule it out today — the schema carries no `$ref`, a no node declaring `properties` also carries a combinator — so a schema refresh that breaks either fails there rather than double-annotating a real PR. -**The by-omission half is only as current as the vendored schema.** It reads those -103 objects as closed against the copy committed here, so a property upstream ADDS -is an unknown key until `refresh-coderabbit-schema.yml` lands the bump and each -caller's pin moves. Warn-only mode absorbs that as a warning; a caller running +**The unknown-key check is only as current as the vendored schema.** Every object +is judged against the copy committed here, so a property upstream ADDS is an +unknown key until `refresh-coderabbit-schema.yml` lands the bump and each caller's +pin moves. Warn-only mode absorbs that as a warning; a caller running `strict_unknown_keys: true` gets a hard failure on a key it was right to add. Same -freshness, opposite sign, as catching a key upstream removed — see the caller doc's -rollout section. +freshness, opposite sign, as catching a key upstream removed. Neither half is +exempt — a root-level addition is missing from the vendored `properties` list and +the vendored `additionalProperties: false` rejects it just as the by-omission rule +would; by-omission is merely the larger surface (103 objects against 5). See the +caller doc's rollout section. A stripped key is not a cosmetic problem. The recurring instance is a `tools:` block written at the document root instead of under `reviews:` — the schema root diff --git a/.github/coderabbit-config/check_coderabbit_config.py b/.github/coderabbit-config/check_coderabbit_config.py index 3efe0e02..fae8aa6a 100644 --- a/.github/coderabbit-config/check_coderabbit_config.py +++ b/.github/coderabbit-config/check_coderabbit_config.py @@ -92,6 +92,19 @@ class of problem rather than what a schema library calls "invalid": MAX_CONFIG_BYTES = 512 * 1024 MAX_FINDINGS = 100 +# What a finding costs the reader if the cap drops it, highest kept first. +# +# The cap cannot simply slice the list: findings come out in document order, the +# root `additionalProperties` error has an EMPTY `absolute_path` and therefore +# sorts first, and it fans out to one finding per unknown key. So ~150 unknown +# root keys plus one `maxLength` violation would slice the file-rejecting error +# away and leave 100 warnings — exit 0 on a config CodeRabbit rejects WHOLE. +# Ranking is what keeps that from happening; the truncation note cannot, because +# a note does not reach the exit code. +_RANK_UNKNOWN = 0 # a stripped key: the document still loads without it +_RANK_INCOMPLETE = 1 # "the scan did not finish" — drop it and a partial run reads as complete +_RANK_REJECTING = 2 # CodeRabbit discards the WHOLE file over this one + # Keywords whose violation CodeRabbit tolerates by STRIPPING the offending key, # rather than rejecting the document. Everything else is file-rejecting. STRIPPED_KEYWORDS = frozenset({"additionalProperties", "unevaluatedProperties"}) @@ -151,6 +164,21 @@ class of problem rather than what a schema library calls "invalid": # property elsewhere in the schema is likely the intended one. _SUGGESTABLE_KEY_RE = re.compile(r"^[A-Za-z][A-Za-z0-9_.-]{2,}$") +# `_format_path` spells an array element `[0]`; `_index_schema_paths` spells the +# same position `[]`. `_suggest_home` compares the two vocabularies, so it +# normalizes with this first — otherwise no schema candidate can ever share the +# parent of a key under a list element, and the parent-preference half of the +# hint silently never applies there. +_ARRAY_INDEX_RE = re.compile(r"\[\d+\]") + +# Stands in for NaN in `_index_key`, which needs a key equal to itself. +_NAN_KEY = object() + +# `_index_key`'s "this key cannot be indexed at all" answer. A distinct sentinel +# rather than None, because None is itself a perfectly ordinary YAML key (`null:`) +# and must index like any other. +_UNINDEXABLE = object() + # How many homes may be named before the hint stops being a hint. A name with # more plausible homes than this has no single likely one, so listing the # alphabetically-first few is guessing out loud — see `_suggest_home`. @@ -241,10 +269,13 @@ def _suggest_home(key, schema_index, offending_path): """ if not isinstance(key, str) or not _SUGGESTABLE_KEY_RE.match(key): return "" - candidates = [p for p in schema_index.get(key, []) if p != offending_path] + # Both comparisons below are against `_index_schema_paths` spellings, which + # write an array position `[]` where `_format_path` writes `[0]`. + normalized = _ARRAY_INDEX_RE.sub("[]", offending_path) + candidates = [p for p in schema_index.get(key, []) if p != normalized] if not candidates: return "" - parent = offending_path.rsplit(".", 1)[0] if "." in offending_path else "" + parent = normalized.rsplit(".", 1)[0] if "." in normalized else "" if parent: nearer = [c for c in candidates if c.startswith(f"{parent}.")] if nearer: @@ -255,6 +286,24 @@ def _suggest_home(key, schema_index, offending_path): return f" Did you mean {shown}?" +def _apply_cap(tagged): + """Trim `[(rank, finding)]` to MAX_FINDINGS. Returns (findings, was_capped). + + Drops the lowest-ranked entries first and, within a rank, the ones latest in + the document — so what survives is still in emission order, and a + file-rejecting error is never crowded out by unknown-key warnings that + happened to sort ahead of it. + """ + if len(tagged) <= MAX_FINDINGS: + return [finding for _rank, finding in tagged], False + doomed = set( + sorted(range(len(tagged)), key=lambda i: (tagged[i][0], -i))[ + : len(tagged) - MAX_FINDINGS + ] + ) + return [f for i, (_rank, f) in enumerate(tagged) if i not in doomed], True + + def _extra_keys(error): """The property names an `additionalProperties: false` error actually rejected. @@ -316,6 +365,85 @@ def _resolved_key(key_node): return getattr(key_node, "value", None) +def _index_key(value): + """A hashable, REFLEXIVE stand-in for a constructed key, or None if there is none. + + Two keys `safe_load` produces are not usable as dict lookups on their own. + NaN is not equal to itself, so a `.nan:` key would miss its own entry and + fall back to `str()` — reproducing the very "path naming a key that is not in + the file" defect this lookup exists to prevent. An unhashable key (a list, + from a complex `? [a, b]` key) cannot be indexed at all and comes back as + `_UNINDEXABLE` — NOT as None, which is an ordinary YAML key (`null:`). + """ + if isinstance(value, float) and value != value: + return _NAN_KEY + try: + hash(value) + except TypeError: + return _UNINDEXABLE + return value + + +def _merge_entries(value_node, seen=None): + """The (key_node, value_node) pairs a `<<:` merge brings into a mapping. + + `safe_load` FLATTENS `<<: *anchor` into the mapping it sits in, but the + composed node keeps only the `<<` key — so without this every merged-in key + is a key the loaded document has and the node tree does not, which is the + `str()` fallback and a lost line number again. A merge value is a mapping or + a sequence of them; `seen` guards the self-referential alias (`a: &x [*x]`) + that composes into a cyclic node graph. + """ + if seen is None: + seen = set() + if id(value_node) in seen: + return [] + seen.add(id(value_node)) + if isinstance(value_node, yaml.MappingNode): + return list(value_node.value) + if isinstance(value_node, yaml.SequenceNode): + out = [] + for item in value_node.value: + out.extend(_merge_entries(item, seen)) + return out + return [] + + +def _resolved_key_index(parent): + """`{resolved key -> key node}` for one composed mapping, built once and cached. + + Built once because the alternative is quadratic: `_extra_keys` can hand back + every key in the mapping, and rescanning `parent.value` per finding — + constructing each candidate key on the way — is ~1e9 constructions for a 50k + key mapping that still fits inside `MAX_CONFIG_BYTES`. The cache lives on the + composed node, which is rebuilt per `validate` call, so it cannot go stale. + + Explicit keys win over merged ones, which is YAML's own merge precedence and + the same precedence `safe_load` applied when it built the document. + """ + index = getattr(parent, "_coderabbit_key_index", None) + if index is not None: + return index + index = {} + merged = [] + for key_node, value_node in parent.value: + if getattr(key_node, "tag", None) == "tag:yaml.org,2002:merge": + merged.extend(_merge_entries(value_node)) + continue + indexed = _index_key(_resolved_key(key_node)) + if indexed is not _UNINDEXABLE: + index.setdefault(indexed, key_node) + for key_node, _value_node in merged: + indexed = _index_key(_resolved_key(key_node)) + if indexed is not _UNINDEXABLE: + index.setdefault(indexed, key_node) + try: + parent._coderabbit_key_index = index + except AttributeError: # pragma: no cover - a node type that forbids the attribute + pass + return index + + def _key_node(node, parent_parts, key): """The composed KEY node for `key` inside the mapping at `parent_parts`, or None. @@ -329,13 +457,10 @@ def _key_node(node, parent_parts, key): parent = _descend(parent, part) if not isinstance(parent, yaml.MappingNode): return None - for key_node, _ in parent.value: - try: - if _resolved_key(key_node) == key: - return key_node - except Exception: # pragma: no cover - an exotic key that will not compare - continue - return None + indexed = _index_key(key) + if indexed is _UNINDEXABLE: + return None + return _resolved_key_index(parent).get(indexed) def _descend(node, part): @@ -451,6 +576,14 @@ def _walk_unknown_keys(data, schema, node, schema_index, severity, limit): def walk(value, subschema, path, depth): if len(findings) >= limit: return + # A scalar leaf or an empty container holds nothing to inspect: visiting + # it costs no budget and leaves nothing unchecked. Tested BEFORE the + # bail-out, because otherwise spending the last unit of budget on a known + # key whose value is a scalar (`reviews.profile: chill`) would flag the + # trailing visit as a partial walk — reporting a fully walked document as + # stopped early, which is a hard error under `strict_unknown_keys`. + if not isinstance(value, (dict, list)) or not value: + return if remaining_keys[0] <= 0 or depth > MAX_WALK_DEPTH: bounded[0] = True return @@ -576,6 +709,14 @@ def _order(error): truncated = len(raw_errors) > MAX_FINDINGS del raw_errors[MAX_FINDINGS:] + # `islice` above bounds the ERROR count, not the finding count: one + # `additionalProperties: false` error reports a whole mapping and `_extra_keys` + # splits it into one finding per key, so a single error can fan out past the + # cap on its own. Findings are therefore collected TAGGED with what they cost + # the reader if dropped, and the cap is applied once, at the end, over the + # whole list — see `_apply_cap`. + tagged = [] + for error in sorted(raw_errors, key=_order): parent_parts = list(error.absolute_path) if error.validator in STRIPPED_KEYWORDS: @@ -583,54 +724,57 @@ def _order(error): if not extras: # The subschema shape defeated the recomputation; report the # library's own message rather than dropping the finding. - findings.append( + tagged.append( ( - unknown_severity, - _format_path(parent_parts), - _line_for_path(node, parent_parts), - error.message, + _RANK_UNKNOWN, + ( + unknown_severity, + _format_path(parent_parts), + _line_for_path(node, parent_parts), + error.message, + ), ) ) continue for key in extras: - findings.append( - _unknown_key_finding( - unknown_severity, node, parent_parts, key, schema_index + if len(tagged) >= MAX_FINDINGS: + # Stop DOING the work, not merely stop printing it. `extras` + # is every extra key in the mapping, each finding costs a + # key-node lookup, and `k00000: 1` is ten bytes — so a root + # mapping of ~50k unknown keys fits inside MAX_CONFIG_BYTES + # and would burn the job to its timeout building annotations + # that the cap below then throws away. + truncated = True + break + tagged.append( + ( + _RANK_UNKNOWN, + _unknown_key_finding( + unknown_severity, node, parent_parts, key, schema_index + ), ) ) continue path_str = _format_path(parent_parts) - findings.append( - ("error", path_str, _line_for_path(node, parent_parts), _describe(error, path_str)) + tagged.append( + ( + _RANK_REJECTING, + ("error", path_str, _line_for_path(node, parent_parts), _describe(error, path_str)), + ) ) - # `islice` above bounds the ERROR count, not the finding count, and one error - # fans out to many findings: `additionalProperties: false` reports a whole - # mapping in a SINGLE error and `_extra_keys` splits it into one finding per - # unknown key, so 150 unknown root keys arrive here as 150 findings from one - # error. Re-apply the cap to the findings themselves before anything is - # derived from their number — unfixed, that overflow printed 150 annotations - # into a public run log with `truncated` still False, and drove `remaining` - # to 0, silently disabling the by-omission walk on top. - if len(findings) > MAX_FINDINGS: - del findings[MAX_FINDINGS:] - truncated = True - # The other 103 objects: closed by OMISSION, so jsonschema said nothing about # them. Appended after the jsonschema findings rather than merged into their # sort, which keeps both halves in document order within themselves and the # whole list stable run to run. One past `remaining` so an overflow is # detectable; `remaining` can be 0, in which case a single walk finding is # enough to prove the combined total passed the cap. - remaining = MAX_FINDINGS - len(findings) + remaining = max(0, MAX_FINDINGS - len(tagged)) walked, walk_bounded = _walk_unknown_keys( data, schema, node, schema_index, unknown_severity, remaining + 1 ) - if len(walked) > remaining: - del walked[remaining:] - truncated = True - findings.extend(walked) + tagged.extend((_RANK_UNKNOWN, f) for f in walked) if walk_bounded: # Say so rather than let a partial walk read as a clean one — the same @@ -643,18 +787,25 @@ def _order(error): # "I could not check" reading as a pass that an oversized config exits 2 # for. Warn-only mode is unchanged: it stays a warning, exactly like the # unknown keys it could not go looking for. - findings.append( + tagged.append( ( - unknown_severity, - "(document root)", - None, - f"the unknown-key scan stopped early — after {MAX_WALK_KEYS} keys " - f"or at depth {MAX_WALK_DEPTH} (a very large or heavily aliased " - f"document) — so nested keys past that point were NOT checked. " - f"This run cannot vouch for them.", + _RANK_INCOMPLETE, + ( + unknown_severity, + "(document root)", + None, + f"the unknown-key scan stopped early — after inspecting " + f"{MAX_WALK_KEYS} keys and nodes, or at depth {MAX_WALK_DEPTH} " + f"(a very large or heavily aliased document) — so nested keys " + f"past that point were NOT checked. This run cannot vouch for " + f"them.", + ), ) ) + findings, capped = _apply_cap(tagged) + truncated = truncated or capped + if truncated: notes.append( f"more than {MAX_FINDINGS} schema violations in this file — only the " diff --git a/.github/coderabbit-config/tests/test_check_coderabbit_config.py b/.github/coderabbit-config/tests/test_check_coderabbit_config.py index b202483f..a28df756 100644 --- a/.github/coderabbit-config/tests/test_check_coderabbit_config.py +++ b/.github/coderabbit-config/tests/test_check_coderabbit_config.py @@ -701,6 +701,154 @@ def test_main_exits_zero_by_default_and_one_under_strict(self): self.assertIn("::error ", out) +class CapAndBudgetTest(unittest.TestCase): + """The cap, the walk budget, and the key lookup under adversarial input. + + Every case here is a defect the review panel found in the FIRST fix for the + unknown-key gap, not in the code that gap was found in — so each is pinned + where a re-simplification would reintroduce it. + """ + + def test_a_file_rejecting_error_is_never_crowded_out_by_unknown_keys(self): + # The root `additionalProperties` error has an empty `absolute_path`, so + # it sorts FIRST, and it fans out to one finding per unknown key. A cap + # that just sliced the list would drop the `maxLength` violation behind + # 150 warnings — and exit 0 on a config CodeRabbit rejects WHOLE. + text = "tone_instructions: " + ("x" * 300) + "\n" + text += "".join(f"zzz{i}: 1\n" for i in range(150)) + findings, notes = checker.validate(text, SCHEMA) + self.assertEqual(len(findings), checker.MAX_FINDINGS) + self.assertTrue(any("only the first" in n for n in notes), msg=f"{notes}") + rejecting = [f for f in findings if "characters" in f[3]] + self.assertEqual(len(rejecting), 1, msg="the maxLength error was capped away") + self.assertIn("error", severities(findings)) + + def test_the_unknown_key_fan_out_stops_working_at_the_cap(self): + # The cap bounds the OUTPUT; this bounds the WORK. `k00000: 1` is ten + # bytes, so ~50k unknown root keys fit inside MAX_CONFIG_BYTES, and + # building a finding for each one used to rescan the whole mapping. + text = "".join(f"k{i:05d}: 1\n" for i in range(20_000)) + self.assertLess(len(text), checker.MAX_CONFIG_BYTES) + findings, notes = checker.validate(text, SCHEMA) + self.assertEqual(len(findings), checker.MAX_FINDINGS) + self.assertTrue(any("only the first" in n for n in notes), msg=f"{notes}") + + def test_the_key_index_is_built_once_per_mapping(self): + # The bound behind the test above: one construction pass per mapping, not + # one per finding. Without the cache this is quadratic. + node = yaml.compose("reviews:\n" + "".join(f" k{i}: 1\n" for i in range(50))) + reviews = node.value[0][1] + first = checker._resolved_key_index(reviews) + self.assertIs(checker._resolved_key_index(reviews), first) + self.assertEqual(len(first), 50) + + def test_the_incomplete_scan_report_fits_under_the_cap(self): + # It is a finding like any other, so a run that filled the cap and then + # hit a walk bound must not emit MAX_FINDINGS + 1 alongside a note saying + # only the first MAX_FINDINGS are reported. + text = "reviews:\n" + "".join(f" unk{i}: 1\n" for i in range(150)) + with budget(keys=3): + findings, _ = checker.validate(text, SCHEMA) + self.assertLessEqual(len(findings), checker.MAX_FINDINGS) + self.assertTrue(any("cannot vouch" in f[3] for f in findings), msg=f"{findings}") + + def test_the_incomplete_scan_report_outranks_an_unknown_key(self): + # Which one the cap drops matters: losing an unknown key costs one + # annotation, losing this one makes a partial run read as a complete one. + tagged = [(checker._RANK_UNKNOWN, ("warning", f"k{i}", None, "x")) + for i in range(checker.MAX_FINDINGS)] + tagged.append((checker._RANK_INCOMPLETE, ("warning", "(document root)", None, "vouch"))) + kept, capped = checker._apply_cap(tagged) + self.assertTrue(capped) + self.assertEqual(len(kept), checker.MAX_FINDINGS) + self.assertIn("vouch", [f[3] for f in kept]) + + def test_the_cap_keeps_survivors_in_emission_order(self): + tagged = [(checker._RANK_UNKNOWN, ("warning", f"k{i}", None, "x")) + for i in range(checker.MAX_FINDINGS + 10)] + kept, capped = checker._apply_cap(tagged) + self.assertTrue(capped) + self.assertEqual([f[1] for f in kept], + [f"k{i}" for i in range(checker.MAX_FINDINGS)]) + + def test_a_suggestion_parent_matches_across_the_two_path_vocabularies(self): + # `_format_path` spells an array element `[0]`; `_index_schema_paths` + # spells it `[]`. Unnormalized, no candidate can share the parent of a + # key under a list element and the parent-preference half never applies. + index = {"enabled": [ + "reviews.path_instructions[].tools.golangci.enabled", + "chat.enabled", "code_generation.enabled", "knowledge_base.enabled", + "reviews.tools.a.enabled", "reviews.tools.b.enabled", + ]} + hint = checker._suggest_home( + "enabled", index, "reviews.path_instructions[0].tools.enabled" + ) + self.assertIn("reviews.path_instructions[].tools.golangci.enabled", hint) + + def test_a_suggestion_does_not_propose_the_offending_position_itself(self): + # Self-exclusion also has to cross the two vocabularies. + index = {"path": ["reviews.path_instructions[].path"]} + self.assertEqual( + checker._suggest_home("path", index, "reviews.path_instructions[0].path"), "" + ) + + def test_a_nan_key_is_still_found_in_the_composed_tree(self): + # NaN is not equal to itself, so a plain dict lookup misses its own entry + # and falls back to `str()` — the "names a key that is not in the file, + # with no line" defect this lookup exists to prevent. + findings, _ = checker.validate("reviews:\n .nan: x\n", SCHEMA) + self.assertEqual(len(findings), 1, msg=f"{messages(findings)}") + self.assertEqual(findings[0][2], 2) + self.assertIn(".nan", findings[0][1]) + + def test_a_null_key_indexes_like_any_other(self): + # Regression guard on the sentinel: None is an ordinary YAML key, and + # must not be confused with "this key cannot be indexed". + findings, _ = checker.validate("reviews:\n null: x\n", SCHEMA) + self.assertEqual([(f[1], f[2]) for f in findings], [("reviews.null", 2)]) + + def test_a_merge_key_does_not_lose_the_keys_it_brings_in(self): + # `safe_load` FLATTENS `<<: *anchor`, but the composed `reviews` node + # holds only `<<` — so a merged-in key had no node, and fell back to + # `str()` at `reviews.True` with no line. + text = "base: &b\n true: 1\nreviews:\n <<: *b\n" + findings, _ = checker.validate(text, SCHEMA) + merged = [f for f in findings if f[1].startswith("reviews.")] + self.assertEqual(len(merged), 1, msg=f"{messages(findings)}") + self.assertEqual(merged[0][1], "reviews.true") + self.assertEqual(merged[0][2], 2) + + def test_an_explicit_key_wins_over_a_merged_one(self): + # YAML's own merge precedence, and the precedence `safe_load` applied. + text = "base: &b\n profil: merged\nreviews:\n <<: *b\n profil: explicit\n" + findings, _ = checker.validate(text, SCHEMA) + merged = [f for f in findings if f[1] == "reviews.profil"] + self.assertEqual(len(merged), 1, msg=f"{messages(findings)}") + self.assertEqual(merged[0][2], 5) # the explicit key's line, not line 2 + + def test_a_self_referential_alias_does_not_hang_the_merge_expansion(self): + # `&x [*x]` composes into a cyclic node graph. + node = yaml.compose("a: &x [*x]\n") + self.assertEqual(checker._merge_entries(node.value[0][1]), []) + + def test_spending_the_last_budget_on_a_scalar_is_not_a_partial_walk(self): + # The trailing `walk(child, ...)` for a KNOWN key whose value is a scalar + # has nothing to inspect, so arriving there with an exhausted budget + # leaves nothing unchecked — and must not report a fully walked document + # as stopped early, which is a hard error under strict mode. + text = "reviews:\n profile: chill\n" + with budget(keys=4): # two node visits + two keys, nothing left over + findings, _ = checker.validate(text, SCHEMA) + self.assertEqual(findings, [], msg=f"{messages(findings)}") + + def test_an_incomplete_scan_message_names_what_the_counter_counts(self): + # The budget is charged per node visit as well as per key, so a + # list-heavy document exhausts it after far fewer than MAX_WALK_KEYS keys. + with budget(keys=1): + findings, _ = checker.validate(STALE_GITHUB_CHECKS, SCHEMA) + self.assertIn("keys and nodes", findings[0][3]) + + class OpennessTest(unittest.TestCase): """Facts about the VENDORED schema that decide what the walk reports. diff --git a/docs/callers/coderabbit-config-validate.md b/docs/callers/coderabbit-config-validate.md index 72a3137c..c86b0f43 100644 --- a/docs/callers/coderabbit-config-validate.md +++ b/docs/callers/coderabbit-config-validate.md @@ -72,17 +72,22 @@ python3 -m pip install --require-hashes --only-binary=:all: \ python3 .github/coderabbit-config/check_coderabbit_config.py --root /path/to/your/repo ``` -**The by-omission half has a staleness window — mind it before turning strict on.** -The 103 by-omission objects are read as closed against the schema *vendored at -your pinned `workflows_ref`*, so a property upstream ADDS — a new linter under +**The unknown-key check has a staleness window — mind it before turning strict on.** +Every object is judged against the schema *vendored at your pinned +`workflows_ref`*, so a property upstream ADDS — a new linter under `reviews.tools`, a new knob on an existing one — is an unknown key to this checker until two things land: the weekly `refresh-coderabbit-schema.yml` PR in `Comfy-Org/github-workflows`, **and** your repo's SHA bump on top of it. In default warn-only mode that window costs you a warning on a config CodeRabbit is perfectly happy with. Under `strict_unknown_keys: true` it is a hard CI failure, on whatever unrelated PR happens to be open, over a key you were right to add. -The five *explicitly* closed objects (the document root among them) have no such -window — jsonschema reports those straight from the keyword. + +The window is a property of the vendored schema being older than upstream, **not** +of which half detects the key, so neither half is exempt: a key upstream adds at +the document root (or under `knowledge_base.mcp`) is missing from the vendored +`properties` list, and the vendored `additionalProperties: false` rejects it just +the same. The by-omission half is only the *larger* surface — 103 objects against +5 — not the only one. That is the trade `strict_unknown_keys` makes, not a bug: the same freshness that lets the checker catch a key upstream REMOVED is what makes it briefly wrong about From e257047604ba2fe1a65031b2d52833fee53a129a Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Wed, 19 Aug 2026 22:33:56 -0700 Subject: [PATCH 2/3] fix(coderabbit-config): keep the walk budget bounding WORK, expand merges transitively (BE-7786) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Round-3 review findings on this PR's own fixes. Exempting a leaf visit from the bail-out flag also exempted it from the BUDGET, and the list branch recurses once per element with no budget check of its own — so `MAX_WALK_KEYS` stopped bounding `walk()` calls and started bounding only non-empty containers. A 1.6 KB aliased document over a nested-`items` schema took 1.0 s and reported `bounded=False` ("I saw the whole thing"); it is 0.03 s now. Only the FLAG is gated on there being something to inspect; the visit is charged either way, which is what `test_list_traversal_is_charged_against_the_walk_budget` was written to hold. `_merge_entries` stopped at one level while PyYAML's `flatten_mapping` is transitive, so `a: &a {x: 1}` / `b: &b {<<: *a}` / `reviews: {<<: *b}` put `x` under `reviews` in the loaded document and a literal `"<<"` in the index — the `str()` fallback with no line number, one level deeper. And `_descend` compared raw key text, so an ancestor arriving through a merge ended the descent at `<<`: same defect one level up. The index now carries the value node too and `_descend` routes through it, which also stops `on:`/`true:` being read as a list index (a bool IS an int). The truncation note still said "only the first N are reported" after ranking made the survivors not a prefix, and `_index_key`'s summary line named a `None` sentinel the function never returns. `OpennessTest` gains the premise behind the one gap left open by design: the `islice` over `iter_errors` is unranked FIFO and runs a stage before `_apply_cap`, so it could in principle drop a file-rejecting error — it cannot against this schema because every self-closing object is either unmultiplied or under a `maxItems`-bounded array, and a refresh that changes that now fails here. 93 tests, up from 87. --- .../check_coderabbit_config.py | 112 ++++++++++----- .../tests/test_check_coderabbit_config.py | 130 +++++++++++++++++- 2 files changed, 205 insertions(+), 37 deletions(-) diff --git a/.github/coderabbit-config/check_coderabbit_config.py b/.github/coderabbit-config/check_coderabbit_config.py index fae8aa6a..11ef7814 100644 --- a/.github/coderabbit-config/check_coderabbit_config.py +++ b/.github/coderabbit-config/check_coderabbit_config.py @@ -366,7 +366,7 @@ def _resolved_key(key_node): def _index_key(value): - """A hashable, REFLEXIVE stand-in for a constructed key, or None if there is none. + """A hashable, REFLEXIVE stand-in for a constructed key, or `_UNINDEXABLE`. Two keys `safe_load` produces are not usable as dict lookups on their own. NaN is not equal to itself, so a `.nan:` key would miss its own entry and @@ -393,6 +393,15 @@ def _merge_entries(value_node, seen=None): `str()` fallback and a lost line number again. A merge value is a mapping or a sequence of them; `seen` guards the self-referential alias (`a: &x [*x]`) that composes into a cyclic node graph. + + TRANSITIVE, because `flatten_mapping` is: it flattens a merged mapping before + splicing it in, so `a: &a {x: 1}` / `b: &b {<<: *a}` / `reviews: {<<: *b}` + puts `x` under `reviews` in the loaded document. Stopping at one level would + index a literal `"<<"` instead and lose `x`'s line — the same defect this + function exists to fix, one level deeper. A merged mapping's OWN keys are + returned ahead of what it merged in, because `node.value = merge + node.value` + plus dict-assignment order is what gives them precedence, and this list is + consumed first-wins. """ if seen is None: seen = set() @@ -400,7 +409,13 @@ def _merge_entries(value_node, seen=None): return [] seen.add(id(value_node)) if isinstance(value_node, yaml.MappingNode): - return list(value_node.value) + own, inherited = [], [] + for key_node, child in value_node.value: + if getattr(key_node, "tag", None) == "tag:yaml.org,2002:merge": + inherited.extend(_merge_entries(child, seen)) + else: + own.append((key_node, child)) + return own + inherited if isinstance(value_node, yaml.SequenceNode): out = [] for item in value_node.value: @@ -410,7 +425,7 @@ def _merge_entries(value_node, seen=None): def _resolved_key_index(parent): - """`{resolved key -> key node}` for one composed mapping, built once and cached. + """`{resolved key -> (key node, value node)}` for one mapping, built once and cached. Built once because the alternative is quadratic: `_extra_keys` can hand back every key in the mapping, and rescanning `parent.value` per finding — @@ -419,7 +434,14 @@ def _resolved_key_index(parent): composed node, which is rebuilt per `validate` call, so it cannot go stale. Explicit keys win over merged ones, which is YAML's own merge precedence and - the same precedence `safe_load` applied when it built the document. + the same precedence `safe_load` applied when it built the document. Merge keys + themselves never reach the index: `_merge_entries` drops them at the single + point it expands them, so `merged` holds only real keys the loaded document + actually has. + + Carries the VALUE node too, so `_descend` can route through a merge as well — + an ancestor that arrives via `<<:` is in the loaded document and not in the + composed mapping's own pairs, which is the same lost line number one level up. """ index = getattr(parent, "_coderabbit_key_index", None) if index is not None: @@ -432,11 +454,11 @@ def _resolved_key_index(parent): continue indexed = _index_key(_resolved_key(key_node)) if indexed is not _UNINDEXABLE: - index.setdefault(indexed, key_node) - for key_node, _value_node in merged: + index.setdefault(indexed, (key_node, value_node)) + for key_node, value_node in merged: indexed = _index_key(_resolved_key(key_node)) if indexed is not _UNINDEXABLE: - index.setdefault(indexed, key_node) + index.setdefault(indexed, (key_node, value_node)) try: parent._coderabbit_key_index = index except AttributeError: # pragma: no cover - a node type that forbids the attribute @@ -444,6 +466,16 @@ def _resolved_key_index(parent): return index +def _index_entry(node, key): + """The `(key node, value node)` pair `key` resolves to in a composed mapping.""" + if not isinstance(node, yaml.MappingNode): + return None + indexed = _index_key(key) + if indexed is _UNINDEXABLE: + return None + return _resolved_key_index(node).get(indexed) + + def _key_node(node, parent_parts, key): """The composed KEY node for `key` inside the mapping at `parent_parts`, or None. @@ -455,25 +487,29 @@ def _key_node(node, parent_parts, key): if parent is None: return None parent = _descend(parent, part) - if not isinstance(parent, yaml.MappingNode): - return None - indexed = _index_key(key) - if indexed is _UNINDEXABLE: - return None - return _resolved_key_index(parent).get(indexed) + entry = _index_entry(parent, key) + return entry[0] if entry else None def _descend(node, part): - if isinstance(part, int): + """The composed value node one path step below `node`, or None. + + Mapping steps go through `_resolved_key_index` rather than a raw text compare + on `key_node.value`, for the two reasons that index exists: a path part is a + key `safe_load` RESOLVED (`on:` arrives here as True, never as `"on"`), and a + key merged in through `<<:` lives in the loaded document but not in this + mapping's own pairs. Either mismatch ends the descent early, and every caller + reads that as "no such node" — an invented `str()` path with no line number. + """ + # `not isinstance(part, bool)`: a bool IS an int in Python, and `on:` / + # `true:` are ordinary YAML KEYS — reading one as a list index would send the + # descent down the sequence branch and end it there. + if isinstance(part, int) and not isinstance(part, bool): if not isinstance(node, yaml.SequenceNode) or part >= len(node.value): return None return node.value[part] - if not isinstance(node, yaml.MappingNode): - return None - for key_node, value_node in node.value: - if getattr(key_node, "value", None) == part: - return value_node - return None + entry = _index_entry(node, part) + return entry[1] if entry else None def _unknown_key_finding(severity, node, parent_parts, key, schema_index): @@ -576,18 +612,26 @@ def _walk_unknown_keys(data, schema, node, schema_index, severity, limit): def walk(value, subschema, path, depth): if len(findings) >= limit: return - # A scalar leaf or an empty container holds nothing to inspect: visiting - # it costs no budget and leaves nothing unchecked. Tested BEFORE the - # bail-out, because otherwise spending the last unit of budget on a known - # key whose value is a scalar (`reviews.profile: chill`) would flag the - # trailing visit as a partial walk — reporting a fully walked document as - # stopped early, which is a hard error under `strict_unknown_keys`. - if not isinstance(value, (dict, list)) or not value: - return + # A scalar leaf or an empty container holds nothing to inspect, so + # arriving at one with the budget already gone leaves nothing unchecked: + # spending the last unit on a known key whose value is a scalar + # (`reviews.profile: chill`) must not flag the trailing visit as a partial + # walk — reporting a fully walked document as stopped early, which is a + # hard error under `strict_unknown_keys`. Only the BAIL-OUT FLAG is gated + # on there being something to inspect; the visit itself is still CHARGED. + # Making leaf visits free would take the walk's call count out of + # `MAX_WALK_KEYS`' hands altogether — the list branch below recurses once + # per element with no budget check of its own, so a single aliased list of + # scalars would cost one unit and buy unboundedly many free calls, each + # allocating a fresh `path`. + inspectable = isinstance(value, (dict, list)) and bool(value) if remaining_keys[0] <= 0 or depth > MAX_WALK_DEPTH: - bounded[0] = True + if inspectable: + bounded[0] = True return remaining_keys[0] -= 1 + if not inspectable: + return if isinstance(value, list): items = subschema.get("items") if isinstance(items, dict): @@ -807,9 +851,15 @@ def _order(error): truncated = truncated or capped if truncated: + # Not "the first N": `_apply_cap` drops by RANK, so what survives is no + # longer a prefix of the findings — for 150 unknown root keys plus one + # `maxLength` violation it is unknown keys 1-99 plus a violation that came + # after all of them. Describing the survivors as a prefix would misname + # what the reader is looking at. notes.append( - f"more than {MAX_FINDINGS} schema violations in this file — only the " - f"first {MAX_FINDINGS} are reported. Fix these and re-run." + f"more than {MAX_FINDINGS} schema violations in this file — {MAX_FINDINGS} " + f"are reported and the least consequential were dropped, so file-rejecting " + f"errors survive ahead of unknown keys. Fix these and re-run." ) return findings, notes diff --git a/.github/coderabbit-config/tests/test_check_coderabbit_config.py b/.github/coderabbit-config/tests/test_check_coderabbit_config.py index a28df756..df16a2fa 100644 --- a/.github/coderabbit-config/tests/test_check_coderabbit_config.py +++ b/.github/coderabbit-config/tests/test_check_coderabbit_config.py @@ -599,7 +599,7 @@ def test_findings_count_toward_the_shared_cap_and_note_the_truncation(self): nested = "reviews:\n" + "".join(f" unknown_nested_{i}: 1\n" for i in range(60)) findings, notes = checker.validate(root + nested, SCHEMA) self.assertEqual(len(findings), checker.MAX_FINDINGS) - self.assertTrue(any("only the first" in n for n in notes), msg=f"{notes}") + self.assertTrue(any("were dropped" in n for n in notes), msg=f"{notes}") def test_a_bounded_walk_says_so_rather_than_reporting_clean(self): # A partial scan must never read like a completed one. Forced via the @@ -675,7 +675,7 @@ def test_one_error_fanning_out_still_respects_the_findings_cap(self): text = "".join(f"unknown_root_{i}: 1\n" for i in range(checker.MAX_FINDINGS + 50)) findings, notes = checker.validate(text, SCHEMA) self.assertEqual(len(findings), checker.MAX_FINDINGS) - self.assertTrue(any("only the first" in n for n in notes), msg=f"{notes}") + self.assertTrue(any("were dropped" in n for n in notes), msg=f"{notes}") def test_main_exits_zero_by_default_and_one_under_strict(self): import tempfile @@ -718,7 +718,7 @@ def test_a_file_rejecting_error_is_never_crowded_out_by_unknown_keys(self): text += "".join(f"zzz{i}: 1\n" for i in range(150)) findings, notes = checker.validate(text, SCHEMA) self.assertEqual(len(findings), checker.MAX_FINDINGS) - self.assertTrue(any("only the first" in n for n in notes), msg=f"{notes}") + self.assertTrue(any("were dropped" in n for n in notes), msg=f"{notes}") rejecting = [f for f in findings if "characters" in f[3]] self.assertEqual(len(rejecting), 1, msg="the maxLength error was capped away") self.assertIn("error", severities(findings)) @@ -731,7 +731,7 @@ def test_the_unknown_key_fan_out_stops_working_at_the_cap(self): self.assertLess(len(text), checker.MAX_CONFIG_BYTES) findings, notes = checker.validate(text, SCHEMA) self.assertEqual(len(findings), checker.MAX_FINDINGS) - self.assertTrue(any("only the first" in n for n in notes), msg=f"{notes}") + self.assertTrue(any("were dropped" in n for n in notes), msg=f"{notes}") def test_the_key_index_is_built_once_per_mapping(self): # The bound behind the test above: one construction pass per mapping, not @@ -744,8 +744,8 @@ def test_the_key_index_is_built_once_per_mapping(self): def test_the_incomplete_scan_report_fits_under_the_cap(self): # It is a finding like any other, so a run that filled the cap and then - # hit a walk bound must not emit MAX_FINDINGS + 1 alongside a note saying - # only the first MAX_FINDINGS are reported. + # hit a walk bound must not emit MAX_FINDINGS + 1 alongside a note that + # says MAX_FINDINGS are reported. text = "reviews:\n" + "".join(f" unk{i}: 1\n" for i in range(150)) with budget(keys=3): findings, _ = checker.validate(text, SCHEMA) @@ -826,11 +826,81 @@ def test_an_explicit_key_wins_over_a_merged_one(self): self.assertEqual(len(merged), 1, msg=f"{messages(findings)}") self.assertEqual(merged[0][2], 5) # the explicit key's line, not line 2 + def test_a_merge_nested_inside_an_anchor_is_expanded_too(self): + # PyYAML's `flatten_mapping` is TRANSITIVE — it flattens the merged + # mapping before splicing it in — so `profil` reaches `reviews` two merges + # away and is a real key of the loaded document. Expanding only one level + # indexed a literal `<<` instead, and the finding fell back to `str()` + # with no line: the defect `_merge_entries` exists to fix, one deeper. + text = "a: &a\n profil: one\nb: &b\n <<: *a\nreviews:\n <<: *b\n" + findings, _ = checker.validate(text, SCHEMA) + merged = [f for f in findings if f[1].startswith("reviews.")] + self.assertEqual(len(merged), 1, msg=f"{messages(findings)}") + self.assertEqual(merged[0][1], "reviews.profil") + self.assertEqual(merged[0][2], 2) # `profil:` in the outermost anchor + + def test_a_nested_merge_does_not_index_the_merge_key_itself(self): + # `<<` is not a key the loaded document has, so it must never reach the + # index — one entry per real key, and nothing named `<<`. + node = yaml.compose("a: &a\n x: 1\nb: &b\n <<: *a\n y: 2\n") + entries = checker._merge_entries(node.value[1][1]) + self.assertEqual([k.value for k, _v in entries], ["y", "x"]) + + def test_a_key_under_a_merged_ANCESTOR_still_finds_its_line(self): + # The ancestor arrives through the merge too, so the DESCENT has to go + # through the index as well: `reviews.tools` is in the loaded document + # and nowhere in the composed `reviews` node's own pairs, so a raw + # text compare ended the descent at `<<` and lost the line. + text = ( + "base: &b\n" + " tools:\n" + " htmlhint:\n" + " bogus: 1\n" + "reviews:\n" + " <<: *b\n" + ) + findings, _ = checker.validate(text, SCHEMA) + hit = [f for f in findings if f[1].endswith("htmlhint.bogus")] + self.assertEqual(len(hit), 1, msg=f"{messages(findings)}") + self.assertEqual(hit[0][1], "reviews.tools.htmlhint.bogus") + self.assertEqual(hit[0][2], 4) + + def test_a_descent_step_matches_the_key_safe_load_resolved(self): + # `_descend`'s contract, pinned at the helper: a path part is a key + # `safe_load` RESOLVED, so `on:` arrives as True — which a raw compare + # against the node's source text `"on"` never matched, and which the + # sequence branch would swallow as a list index (a bool IS an int). + text = "reviews:\n tools:\n on:\n bogus: 1\n" + node = yaml.compose(text) + step = checker._descend(checker._descend(node, "reviews"), "tools") + self.assertIsNotNone(checker._descend(step, True)) + def test_a_self_referential_alias_does_not_hang_the_merge_expansion(self): # `&x [*x]` composes into a cyclic node graph. node = yaml.compose("a: &x [*x]\n") self.assertEqual(checker._merge_entries(node.value[0][1]), []) + def test_scalar_elements_are_charged_against_the_walk_budget(self): + # Exempting a leaf from the BAIL-OUT FLAG is not the same as exempting it + # from the BUDGET. The list branch recurses once per element with no + # budget check of its own, so an uncharged leaf visit would let a single + # aliased list of scalars cost one unit and buy unboundedly many calls — + # `MAX_WALK_KEYS` would then bound non-empty containers, not work done. + data = {"c": [1] * 50, "d": {"unk": 1}} + schema = { + "type": "object", + "properties": { + "c": {"type": "array", "items": {"type": "object", "properties": {}}}, + "d": {"type": "object", "properties": {}}, + }, + } + with budget(keys=20): # 6 units without the per-element charge, 56 with it + findings, bounded = checker._walk_unknown_keys( + data, schema, None, {}, "warning", 100 + ) + self.assertTrue(bounded, msg=f"{findings}") + self.assertEqual(findings, []) + def test_spending_the_last_budget_on_a_scalar_is_not_a_partial_walk(self): # The trailing `walk(child, ...)` for a KNOWN key whose value is a scalar # has nothing to inspect, so arriving there with an exhausted budget @@ -925,6 +995,54 @@ def test_the_schema_carries_no_ref(self): self.assertNotIn('"$ref"', raw) self.assertNotIn('"$dynamicRef"', raw) + def test_a_rejecting_error_cannot_be_crowded_out_before_ranking(self): + # `_apply_cap` ranks findings, but the `islice` over `iter_errors` runs a + # stage EARLIER and is unranked FIFO in schema order — a file-rejecting + # error arriving as error MAX_FINDINGS + 1 is deleted before ranking ever + # sees it, which is the same exit-0-on-a-whole-file-rejection the rank + # exists to prevent. It cannot happen against THIS schema, and this is the + # premise: only a STRIPPED-keyword error is non-rejecting, only a literal + # `false` produces one (a schema-VALUED `additionalProperties` descends + # and yields the child's keyword instead), and every object that closes + # itself that way is either unmultiplied or sits under an array whose + # `maxItems` bounds it. So the stripped errors one document can raise are + # bounded well under MAX_FINDINGS. A refresh that closes the item of an + # unbounded array — or adds `unevaluatedProperties: false` anywhere — + # reopens the hole, and should fail HERE rather than in a consumer's CI. + infinite = float("inf") + total = 0 + + def walk(node, multiplier): + nonlocal total + if isinstance(node, list): + for item in node: + walk(item, multiplier) + return + if not isinstance(node, dict): + return + if any(node.get(k) is False for k in checker.STRIPPED_KEYWORDS): + total += multiplier + for key in ("properties", "patternProperties", "$defs", "definitions", + "dependentSchemas"): + for sub in (node.get(key) or {}).values(): + walk(sub, multiplier) + for key in ("additionalProperties", "propertyNames", "not", + "if", "then", "else", "unevaluatedProperties"): + walk(node.get(key), multiplier) + for key in ("anyOf", "oneOf", "allOf"): + walk(node.get(key), multiplier) + if "items" in node: + # An array raises one error per ELEMENT below it; `maxItems` is + # the only thing that bounds how many elements there can be. + bound = node.get("maxItems") + walk( + node["items"], + multiplier * (bound if isinstance(bound, int) else infinite), + ) + + walk(SCHEMA, 1) + self.assertLess(total, checker.MAX_FINDINGS, msg=f"{total}") + def test_the_document_root_is_the_explicitly_closed_case(self): self.assertIs(SCHEMA.get("additionalProperties"), False) From b88e7f21b5bacd531a096acbc1417bcbc444e467 Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Wed, 19 Aug 2026 23:18:01 -0700 Subject: [PATCH 3/3] fix(coderabbit-config): bound the merge expansion, key the descent on the node (BE-7786) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Round-4 review findings. The transitive merge expansion had no depth bound. A `<<:` chain of ~1500 links is ~37 KB — far inside MAX_CONFIG_BYTES — and `safe_load` flattens it fine while this expansion, costing more frames per link, blew the recursion limit; `RecursionError` is not a `yaml.YAMLError`, so it escaped `validate` and killed an advisory check with a traceback. Bounded at `_MAX_MERGE_DEPTH`, degrading to the documented `str()` fallback. PyYAML's own `flatten_mapping` can lose the same race first (anchors in a lazily constructed sequence, so `reviews` flattens before them) — that now raises `ConfigError` and exits 2, like an oversized config: "I could not check this" must not read as "this is fine". `_descend` typed the PATH PART instead of the node, so an integer mapping key went down the sequence branch and died there. Reachable today: `reviews.mutually_exclusive_groups` takes arbitrary property names, so `1:` is legal and a rejecting error below it lost its line and rendered as `...[1]` — a list position the file does not have. `_descend` now dispatches on the node and `_format_path` is given the document so it can tell an integer key from a list index. The index was first-wins throughout, but `construct_mapping` assigns per pair, so `safe_load` keeps the LAST: a duplicate key annotated its earlier twin's line, and where a mapping carries two `<<:` keys the earlier one won here and the later one won in the document. Explicit keys now assign unconditionally and merge groups are consumed in reverse. `_apply_cap`'s docstring claimed a document-order tie-break; the two halves are concatenated, so it is emission order — corrected, with why the walk's overflow finding is deliberately the first dropped. `test_a_rejecting_error_cannot_be_crowded_out_before_ranking` modelled `maxItems` as a multiplicity bound, which it is not — jsonschema keeps validating elements past it. Reformulated to assert the four facts that actually hold, including that `maxItems` precedes `items` in key order so its REJECTING error is emitted ahead of the element errors. Verified by mutation: all four clauses fail when broken. 99 tests, up from 93. --- .../check_coderabbit_config.py | 156 ++++++++++---- .../tests/test_check_coderabbit_config.py | 196 ++++++++++++++---- 2 files changed, 276 insertions(+), 76 deletions(-) diff --git a/.github/coderabbit-config/check_coderabbit_config.py b/.github/coderabbit-config/check_coderabbit_config.py index 11ef7814..042b33a1 100644 --- a/.github/coderabbit-config/check_coderabbit_config.py +++ b/.github/coderabbit-config/check_coderabbit_config.py @@ -171,6 +171,13 @@ class of problem rather than what a schema library calls "invalid": # hint silently never applies there. _ARRAY_INDEX_RE = re.compile(r"\[\d+\]") +# How deep a `<<:` chain `_merge_entries` will follow. Real configs merge one or +# two levels; the bound is here because the expansion is recursive over +# PR-controlled input and `RecursionError` is not a `yaml.YAMLError` — see +# `_merge_entries`. Well under the interpreter's own limit, and well past any +# chain a human writes. +_MAX_MERGE_DEPTH = 50 + # Stands in for NaN in `_index_key`, which needs a key equal to itself. _NAN_KEY = object() @@ -213,16 +220,30 @@ def _esc_prop(text): return _esc_cmd(text).replace(":", "%3A").replace(",", "%2C") -def _format_path(path_parts): - """Render a JSON-pointer-ish path as `reviews.path_instructions[0].path`.""" +def _format_path(path_parts, node=None): + """Render a JSON-pointer-ish path as `reviews.path_instructions[0].path`. + + `node` is the composed document, and it is what tells an integer LIST + POSITION apart from an integer mapping KEY — `1:` is a legal YAML key, and + `reviews.mutually_exclusive_groups` accepts arbitrary property names, so + rendering every int as `[1]` names a list position the file does not have. + Without a node (compose failed, or a caller with no document in hand) the + int-is-a-position reading stands, which is the common case by far. + """ if not path_parts: return "(document root)" out = "" + current = node for part in path_parts: - if isinstance(part, int): + position = isinstance(part, int) and not isinstance(part, bool) + if position and current is not None and not isinstance(current, yaml.SequenceNode): + position = False + if position: out += f"[{part}]" else: out += f".{part}" if out else str(part) + if current is not None: + current = _descend(current, part) return out @@ -290,9 +311,18 @@ def _apply_cap(tagged): """Trim `[(rank, finding)]` to MAX_FINDINGS. Returns (findings, was_capped). Drops the lowest-ranked entries first and, within a rank, the ones latest in - the document — so what survives is still in emission order, and a + EMISSION order — so what survives is still in emission order, and a file-rejecting error is never crowded out by unknown-key warnings that happened to sort ahead of it. + + Emission order, not document order: the two unknown-key halves are + CONCATENATED rather than merged into one sort (which is what keeps each half + internally in document order and the whole list stable run to run), so every + by-omission walk finding sorts after every jsonschema one whatever line it + sits on. The consequence is deliberate: `remaining` is 0 exactly when the + jsonschema half already filled the cap, so the walk's one overflow finding is + the first thing dropped — it exists to prove the combined total passed the + cap, and `truncated` carries that fact into the note either way. """ if len(tagged) <= MAX_FINDINGS: return [finding for _rank, finding in tagged], False @@ -384,7 +414,7 @@ def _index_key(value): return value -def _merge_entries(value_node, seen=None): +def _merge_entries(value_node, seen=None, depth=0): """The (key_node, value_node) pairs a `<<:` merge brings into a mapping. `safe_load` FLATTENS `<<: *anchor` into the mapping it sits in, but the @@ -402,24 +432,35 @@ def _merge_entries(value_node, seen=None): returned ahead of what it merged in, because `node.value = merge + node.value` plus dict-assignment order is what gives them precedence, and this list is consumed first-wins. + + DEPTH-BOUNDED, because the transitivity is recursive and the input is + PR-controlled: a merge chain of ~1000 links (`a0: &a0 {x: 1}`, then each + `aN: &aN {<<: *a(N-1)}`) is a few tens of KB — far under `MAX_CONFIG_BYTES` — + and `safe_load` flattens it fine, but this expansion costs more frames per + link than `flatten_mapping` does and would blow the interpreter's recursion + limit first. `RecursionError` is not a `yaml.YAMLError`, so it would escape + `validate` uncaught and kill the checker with a traceback: a warn-only + caller's advisory annotation turned into a hard CI failure by a config file. + Past the bound the merge is simply not expanded, which degrades to the + documented `str()` fallback — a lost line number, not a crash. """ if seen is None: seen = set() - if id(value_node) in seen: + if depth > _MAX_MERGE_DEPTH or id(value_node) in seen: return [] seen.add(id(value_node)) if isinstance(value_node, yaml.MappingNode): own, inherited = [], [] for key_node, child in value_node.value: if getattr(key_node, "tag", None) == "tag:yaml.org,2002:merge": - inherited.extend(_merge_entries(child, seen)) + inherited.extend(_merge_entries(child, seen, depth + 1)) else: own.append((key_node, child)) return own + inherited if isinstance(value_node, yaml.SequenceNode): out = [] for item in value_node.value: - out.extend(_merge_entries(item, seen)) + out.extend(_merge_entries(item, seen, depth + 1)) return out return [] @@ -433,11 +474,20 @@ def _resolved_key_index(parent): key mapping that still fits inside `MAX_CONFIG_BYTES`. The cache lives on the composed node, which is rebuilt per `validate` call, so it cannot go stale. - Explicit keys win over merged ones, which is YAML's own merge precedence and - the same precedence `safe_load` applied when it built the document. Merge keys - themselves never reach the index: `_merge_entries` drops them at the single - point it expands them, so `merged` holds only real keys the loaded document - actually has. + Precedence follows the document `safe_load` built, which is not simply + "first wins". `flatten_mapping` leaves `node.value = merge + explicit` and + `construct_mapping` ASSIGNS per pair, so the LAST pair wins: explicit keys + beat merged ones (they come after), a duplicate key beats its earlier twin + (`profile:` written twice annotates the second), and where a mapping carries + two `<<:` keys the later one beats the earlier. Hence the explicit loop + assigns unconditionally while the merged pass is first-wins over merge groups + taken in REVERSE — the two together reproduce that ordering. Within one merge + group first-wins is already right: a merged mapping's own keys precede what it + merged in, and `flatten_mapping` reverses a merge SEQUENCE for the same reason. + + Merge keys themselves never reach the index: `_merge_entries` drops them at + the single point it expands them, so `merged` holds only real keys the loaded + document actually has. Carries the VALUE node too, so `_descend` can route through a merge as well — an ancestor that arrives via `<<:` is in the loaded document and not in the @@ -447,18 +497,19 @@ def _resolved_key_index(parent): if index is not None: return index index = {} - merged = [] + merge_groups = [] for key_node, value_node in parent.value: if getattr(key_node, "tag", None) == "tag:yaml.org,2002:merge": - merged.extend(_merge_entries(value_node)) + merge_groups.append(_merge_entries(value_node)) continue indexed = _index_key(_resolved_key(key_node)) if indexed is not _UNINDEXABLE: - index.setdefault(indexed, (key_node, value_node)) - for key_node, value_node in merged: - indexed = _index_key(_resolved_key(key_node)) - if indexed is not _UNINDEXABLE: - index.setdefault(indexed, (key_node, value_node)) + index[indexed] = (key_node, value_node) + for group in reversed(merge_groups): + for key_node, value_node in group: + indexed = _index_key(_resolved_key(key_node)) + if indexed is not _UNINDEXABLE: + index.setdefault(indexed, (key_node, value_node)) try: parent._coderabbit_key_index = index except AttributeError: # pragma: no cover - a node type that forbids the attribute @@ -500,12 +551,18 @@ def _descend(node, part): key merged in through `<<:` lives in the loaded document but not in this mapping's own pairs. Either mismatch ends the descent early, and every caller reads that as "no such node" — an invented `str()` path with no line number. + + Which branch to take is decided by the NODE, not by the part's Python type: + `1:` and `true:` are ordinary YAML mapping KEYS (and a bool IS an int), so + typing the part would send them down the sequence branch and end the descent + there. `reviews.mutually_exclusive_groups` is the reachable case — it takes + arbitrary property names, so a rejecting error below an integer key arrives + with an int path part while the node is a mapping. """ - # `not isinstance(part, bool)`: a bool IS an int in Python, and `on:` / - # `true:` are ordinary YAML KEYS — reading one as a list index would send the - # descent down the sequence branch and end it there. - if isinstance(part, int) and not isinstance(part, bool): - if not isinstance(node, yaml.SequenceNode) or part >= len(node.value): + if isinstance(node, yaml.SequenceNode): + if not isinstance(part, int) or isinstance(part, bool): + return None + if not 0 <= part < len(node.value): return None return node.value[part] entry = _index_entry(node, part) @@ -531,11 +588,13 @@ def _unknown_key_finding(severity, node, parent_parts, key, schema_index): node fixes both together. The `str()` coercion survives as the fallback for a key whose node cannot be - found (an aliased or merge-keyed mapping the composed tree will not follow), - where it is still needed: without it `_format_path` would render an integer - key as a LIST INDEX (`reviews[1]` for `reviews: {1: x}`). `_suggest_home` - needs no coercion guard of its own — `_SUGGESTABLE_KEY_RE` already rejects - anything that is not a plausible property name. + found (a merge chain past `_MAX_MERGE_DEPTH`, say), where a raw integer key + would otherwise reach `_format_path` as a bare part. `_format_path` is told + the document now and no longer reads an integer mapping key as a list + position on its own, but the coercion still keeps the two halves — name and + path — spelled the same way. `_suggest_home` needs no coercion guard of its + own: `_SUGGESTABLE_KEY_RE` already rejects anything that is not a plausible + property name. """ key_node = _key_node(node, parent_parts, key) text = getattr(key_node, "value", None) @@ -545,11 +604,11 @@ def _unknown_key_finding(severity, node, parent_parts, key, schema_index): else: name = key if isinstance(key, str) else str(key) line = None - full = _format_path(parent_parts + [name]) + full = _format_path(parent_parts + [name], node) where = ( "at the document root" if not parent_parts - else f"under `{_format_path(parent_parts)}`" + else f"under `{_format_path(parent_parts, node)}`" ) return ( severity, @@ -704,6 +763,21 @@ def validate(text, schema, strict_unknown_keys=False): try: data = yaml.safe_load(text) + except RecursionError: + # PyYAML's own `flatten_mapping` recurses per `<<:` link, and a merge + # chain long enough to exhaust the interpreter's stack is a few tens of + # KB — well inside `MAX_CONFIG_BYTES`, and PR-controlled. `RecursionError` + # is not a `yaml.YAMLError`, so uncaught it escapes here and kills the + # checker with a traceback: an advisory, warn-only check turned into a + # hard CI failure by a config file. Reported as exit 2 for the same reason + # an oversized config is — "I could not check this" must never come out + # looking like "this is fine", and it is not a finding about the config's + # CONTENT the way a parse error is. + raise ConfigError( + "this config is nested or `<<:`-chained too deeply for the YAML " + "loader to build — refusing to guess at it. A real CodeRabbit config " + "does not need a merge chain hundreds of links long." + ) except yaml.YAMLError as exc: line = None mark = getattr(exc, "problem_mark", None) @@ -730,6 +804,10 @@ def validate(text, schema, strict_unknown_keys=False): node = yaml.compose(text) except yaml.YAMLError: # pragma: no cover - unreachable after a clean load node = None + except RecursionError: # pragma: no cover - safe_load raises first in practice + # Only the line numbers are lost, and `_unknown_key_finding` already has a + # no-node path — so degrade rather than refuse a document that LOADED. + node = None schema_index = _index_schema_paths(schema) validator = Draft202012Validator(schema) @@ -773,7 +851,7 @@ def _order(error): _RANK_UNKNOWN, ( unknown_severity, - _format_path(parent_parts), + _format_path(parent_parts, node), _line_for_path(node, parent_parts), error.message, ), @@ -800,7 +878,7 @@ def _order(error): ) continue - path_str = _format_path(parent_parts) + path_str = _format_path(parent_parts, node) tagged.append( ( _RANK_REJECTING, @@ -1112,7 +1190,15 @@ def main(argv=None): with open(config_path, "r", encoding="utf-8", errors="replace") as f: text = f.read() - findings, notes = validate(text, schema, strict_unknown_keys=args.strict_unknown_keys) + try: + findings, notes = validate( + text, schema, strict_unknown_keys=args.strict_unknown_keys + ) + except ConfigError as exc: + msg = _esc_cmd(exc) + print(f"FAIL: {msg}") + print(f"::error::coderabbit-config: {msg}") + return 2 return _emit(findings, notes, config_rel) diff --git a/.github/coderabbit-config/tests/test_check_coderabbit_config.py b/.github/coderabbit-config/tests/test_check_coderabbit_config.py index df16a2fa..5b7a4f2a 100644 --- a/.github/coderabbit-config/tests/test_check_coderabbit_config.py +++ b/.github/coderabbit-config/tests/test_check_coderabbit_config.py @@ -880,6 +880,93 @@ def test_a_self_referential_alias_does_not_hang_the_merge_expansion(self): node = yaml.compose("a: &x [*x]\n") self.assertEqual(checker._merge_entries(node.value[0][1]), []) + def test_a_deep_merge_chain_degrades_instead_of_crashing(self): + # PR-controlled input: ~1500 `<<:` links is a few tens of KB, far inside + # MAX_CONFIG_BYTES. The expansion here is recursive and `RecursionError` + # is not a `yaml.YAMLError`, so unbounded it escapes `validate` and kills + # an advisory check with a traceback. Past `_MAX_MERGE_DEPTH` the merge is + # simply not expanded — a lost line number, not a crash. + n = 1500 + text = ( + "a0: &a0\n profil: 1\n" + + "".join(f"a{i}: &a{i}\n <<: *a{i - 1}\n" for i in range(1, n)) + + f"reviews:\n <<: *a{n - 1}\n" + ) + findings, _ = checker.validate(text, SCHEMA) # must not raise + self.assertEqual(len(findings), checker.MAX_FINDINGS) + + def test_a_merge_chain_inside_the_bound_still_resolves_its_line(self): + # The bound is a backstop, not the working path: a chain a human might + # actually write still gets its key node and its line. + n = 20 + text = ( + "a0: &a0\n profil: 1\n" + + "".join(f"a{i}: &a{i}\n <<: *a{i - 1}\n" for i in range(1, n)) + + f"reviews:\n <<: *a{n - 1}\n" + ) + findings, _ = checker.validate(text, SCHEMA) + merged = [f for f in findings if f[1] == "reviews.profil"] + self.assertEqual(len(merged), 1, msg=f"{messages(findings)}") + self.assertEqual(merged[0][2], 2) # `profil:` in the first anchor + + def test_a_merge_chain_the_loader_itself_cannot_build_exits_two(self): + # `flatten_mapping` recurses per link too, and in this shape (anchors in a + # lazily-constructed sequence, so `reviews` is flattened first) PyYAML + # blows its own stack before this file gets a turn. "I could not check + # this" must exit 2, like an oversized config — never 0, and never a + # traceback. + import tempfile + + n = 1500 + text = ( + "_anchors:\n - &a0\n profil: 1\n" + + "".join(f" - &a{i}\n <<: *a{i - 1}\n" for i in range(1, n)) + + f"reviews:\n <<: *a{n - 1}\n" + ) + with self.assertRaises(checker.ConfigError): + checker.validate(text, SCHEMA) + with tempfile.TemporaryDirectory() as tmp: + with open(os.path.join(tmp, ".coderabbit.yaml"), "w", encoding="utf-8") as f: + f.write(text) + buf = io.StringIO() + with redirect_stdout(buf): + code = checker.main(["--root", tmp, "--schema", SCHEMA_PATH]) + out = buf.getvalue() + self.assertEqual(code, 2, msg=out) + self.assertIn("::error::", out) + + def test_an_integer_mapping_key_is_not_read_as_a_list_index(self): + # `reviews.mutually_exclusive_groups` accepts arbitrary property names, so + # `1:` is a legal key there and a rejecting error below it arrives with an + # INT path part while the node is a mapping. Typing the part rather than + # the node sent the descent down the sequence branch: no line at all, and + # a path (`...[1]`) naming a list position the file does not have. + text = "reviews:\n mutually_exclusive_groups:\n 1:\n - only-one\n" + findings, _ = checker.validate(text, SCHEMA) + short = [f for f in findings if "too short" in f[3]] + self.assertEqual(len(short), 1, msg=f"{messages(findings)}") + self.assertEqual(short[0][1], "reviews.mutually_exclusive_groups.1") + self.assertEqual(short[0][2], 4) + + def test_a_duplicate_key_is_annotated_on_the_one_safe_load_kept(self): + # `construct_mapping` assigns per pair, so the LAST duplicate wins and the + # error is about ITS value — annotating line 2's valid `chill` for a + # complaint about line 3's `7` points the reader at the wrong line. + text = "reviews:\n profile: chill\n profile: 7\n" + findings, _ = checker.validate(text, SCHEMA) + self.assertTrue(findings, msg="expected a type/enum error") + self.assertEqual({f[2] for f in findings}, {3}, msg=f"{findings}") + + def test_the_later_of_two_merge_keys_wins_like_safe_load(self): + # `flatten_mapping` accumulates a-then-b into ONE merge list and dict + # assignment lets b win, so a first-wins pass over the merge groups in + # document order picked a — the opposite of the loaded document. + text = "a: &a\n profil: 1\nb: &b\n profil: 2\nreviews:\n <<: *a\n <<: *b\n" + findings, _ = checker.validate(text, SCHEMA) + merged = [f for f in findings if f[1] == "reviews.profil"] + self.assertEqual(len(merged), 1, msg=f"{messages(findings)}") + self.assertEqual(merged[0][2], 4) # b's `profil:`, not a's on line 2 + def test_scalar_elements_are_charged_against_the_walk_budget(self): # Exempting a leaf from the BAIL-OUT FLAG is not the same as exempting it # from the BUDGET. The list branch recurses once per element with no @@ -996,52 +1083,79 @@ def test_the_schema_carries_no_ref(self): self.assertNotIn('"$dynamicRef"', raw) def test_a_rejecting_error_cannot_be_crowded_out_before_ranking(self): - # `_apply_cap` ranks findings, but the `islice` over `iter_errors` runs a - # stage EARLIER and is unranked FIFO in schema order — a file-rejecting - # error arriving as error MAX_FINDINGS + 1 is deleted before ranking ever - # sees it, which is the same exit-0-on-a-whole-file-rejection the rank - # exists to prevent. It cannot happen against THIS schema, and this is the - # premise: only a STRIPPED-keyword error is non-rejecting, only a literal - # `false` produces one (a schema-VALUED `additionalProperties` descends - # and yields the child's keyword instead), and every object that closes - # itself that way is either unmultiplied or sits under an array whose - # `maxItems` bounds it. So the stripped errors one document can raise are - # bounded well under MAX_FINDINGS. A refresh that closes the item of an - # unbounded array — or adds `unevaluatedProperties: false` anywhere — - # reopens the hole, and should fail HERE rather than in a consumer's CI. - infinite = float("inf") - total = 0 - - def walk(node, multiplier): - nonlocal total + """The premise `_apply_cap` cannot enforce: the `islice` runs a stage earlier. + + `islice(iter_errors(...), MAX_FINDINGS + 1)` is unranked FIFO in schema + order, so a file-rejecting error arriving past the cap is deleted before + ranking ever sees it — the same exit-0-on-a-whole-file-rejection the rank + exists to prevent. It needs MAX_FINDINGS *stripped* errors ahead of it + (one rejecting error among them and the exit code is 1 regardless), and + against THIS schema that cannot be assembled. Four facts make it so, each + asserted below rather than summarized in a number — `maxItems` is NOT one + of them as a multiplicity bound, because jsonschema keeps validating + elements past it (a 150-element array really does raise 150 of them). + """ + stripped_false, unbounded_multipliers, arrays_over_closed = [], [], [] + + def walk(node, path, multiplied): if isinstance(node, list): - for item in node: - walk(item, multiplier) + for i, item in enumerate(node): + walk(item, f"{path}[{i}]", multiplied) return if not isinstance(node, dict): return - if any(node.get(k) is False for k in checker.STRIPPED_KEYWORDS): - total += multiplier - for key in ("properties", "patternProperties", "$defs", "definitions", - "dependentSchemas"): - for sub in (node.get(key) or {}).values(): - walk(sub, multiplier) - for key in ("additionalProperties", "propertyNames", "not", - "if", "then", "else", "unevaluatedProperties"): - walk(node.get(key), multiplier) + for keyword in checker.STRIPPED_KEYWORDS: + if node.get(keyword) is False: + (arrays_over_closed if multiplied else stripped_false).append(path) + for key in ("properties", "$defs", "definitions", "dependentSchemas"): + for name, sub in (node.get(key) or {}).items(): + walk(sub, f"{path}.{key}.{name}", multiplied) + for key in ("propertyNames", "not", "if", "then", "else"): + walk(node.get(key), f"{path}.{key}", multiplied) for key in ("anyOf", "oneOf", "allOf"): - walk(node.get(key), multiplier) - if "items" in node: - # An array raises one error per ELEMENT below it; `maxItems` is - # the only thing that bounds how many elements there can be. - bound = node.get("maxItems") - walk( - node["items"], - multiplier * (bound if isinstance(bound, int) else infinite), - ) - - walk(SCHEMA, 1) - self.assertLess(total, checker.MAX_FINDINGS, msg=f"{total}") + walk(node.get(key), f"{path}.{key}", multiplied) + # A schema-valued `additionalProperties` / `patternProperties` applies + # to unboundedly many properties of ONE instance object, so anything + # closed underneath is multiplied by nothing this bound can see. + for key in ("additionalProperties", "patternProperties"): + sub = node.get(key) + subs = sub.values() if key == "patternProperties" and isinstance(sub, dict) else [sub] + for one in subs: + if isinstance(one, dict): + before = len(stripped_false) + len(arrays_over_closed) + walk(one, f"{path}.{key}", multiplied) + if len(stripped_false) + len(arrays_over_closed) > before: + unbounded_multipliers.append(f"{path}.{key}") + for key in ("items", "prefixItems", "unevaluatedItems", "contains"): + if key in node: + before = len(stripped_false) + len(arrays_over_closed) + walk(node[key], f"{path}.{key}", True) + if len(stripped_false) + len(arrays_over_closed) > before: + arrays_over_closed.append((path, node)) + + walk(SCHEMA, "$", False) + + # 1. `unevaluatedProperties` is the other stripped keyword and is absent, + # so `additionalProperties: false` is the only source. + self.assertNotIn('"unevaluatedProperties"', json.dumps(SCHEMA)) + + # 2. Nothing closed sits under a schema-valued `additionalProperties` or a + # `patternProperties` — one instance object could then raise arbitrarily + # many stripped errors with no rejecting error implied. + self.assertEqual(unbounded_multipliers, []) + + # 3. Every array over a closed object declares `maxItems`, and declares it + # BEFORE `items` in key order. That is what actually saves this case: + # exceeding it raises a REJECTING `maxItems` error, and `iter_errors` + # walks a node's keywords in schema key order, so that error is emitted + # ahead of the element errors it would otherwise be buried under. + for path, array in [x for x in arrays_over_closed if isinstance(x, tuple)]: + keys = list(array.keys()) + self.assertIn("maxItems", keys, msg=path) + self.assertLess(keys.index("maxItems"), keys.index("items"), msg=path) + + # 4. What is left is unmultiplied: at most one stripped error each. + self.assertLess(len(stripped_false), checker.MAX_FINDINGS, msg=f"{stripped_false}") def test_the_document_root_is_the_explicitly_closed_case(self): self.assertIs(SCHEMA.get("additionalProperties"), False)