Repository navigation
Commit b09780e
authored
feat(coderabbit-config): flag unknown keys inside schema-open objects (BE-7786) (#188)
* feat(coderabbit-config): flag unknown keys inside schema-open objects (BE-7786)
The unknown-key check only reported keys jsonschema complained about, which
means only the five objects upstream's schema closes with an explicit
`additionalProperties: false`. 103 more objects declare `properties` and say
nothing about the rest — `reviews`, `chat`, `knowledge_base`,
`code_generation` and every individual tool config among them — so a typo
inside one (`reviews.profil`, `golangci-lint.enabld`) produced no finding in
either mode, even though CodeRabbit strips those keys exactly like a
root-level one.
Adds a conservative schema-walk that closes the gap. A node counts as closed
BY OMISSION only when it declares a `properties` block and none of the twelve
keywords that let an object accept a name it does not list; the walk descends
only through matched properties and `items`, never into a combinator branch,
an `additionalProperties` schema, or the value under a key it just reported,
and it stays silent where the document and the schema disagree about shape
(that is a type error, and jsonschema already says so). The two halves are
disjoint by construction — one needs the keyword present, the other needs it
absent — so nothing is reported twice.
Findings share one builder with the jsonschema path, so severity, wording,
path, line resolution and the "did you mean" hint are identical by
construction; non-string YAML keys are coerced for display, which also stops
an integer key rendering as a list index. The walk's findings count toward
MAX_FINDINGS with the jsonschema ones, and the walk is itself bounded by a
key-inspection budget (the document is PR-controlled and aliased YAML is
walkable as a much larger tree) that reports a partial scan rather than
letting it read as a clean one.
* fix(coderabbit-config): cap findings after fan-out, name keys by source spelling, bound list traversal (BE-7786)
Addresses the cursor-review panel findings on #188.
* The `islice` on `iter_errors` bounds the ERROR count, not the finding
count: `additionalProperties: false` reports a whole mapping in ONE
error and `_extra_keys` splits it into one finding per key, so 150
unknown root keys emitted 150 annotations into a public run log with
`truncated` still False — and drove `remaining` to 0, silently
disabling the by-omission walk on top. Re-apply the cap to the
findings themselves before anything is derived from their number.
* A walk that gave up early was only a note, and a note does not reach
the exit code — so `strict_unknown_keys: true` exited 0 over keys
nothing ever looked at. It is now a finding at the unknown-key
severity: warn-only mode is unchanged, strict mode fails.
* List elements recursed without charging the walk budget, leaving array
traversal outside the bound its own comment claimed. Charge per node
visit as well as per key, so an alias-amplified nested list is covered.
* `bounded` is set where the walk actually bails rather than derived from
the leftover budget: an exact landing on MAX_WALK_KEYS was a full walk
reported as partial, and a MAX_WALK_DEPTH cutoff was a partial walk
reported as clean.
* `str()` on a loaded key is not its source spelling — `true:`/`on:`/`yes:`
all annotated `reviews.True`, `0x10:` `reviews.16`, `null:` `reviews.None`,
each naming a key that appears nowhere in the file and each losing its
line number, because the lookup then compared "True" against the node's
"true". Resolve key nodes tag-aware and read both name and line off the
matched node.
* The "did you mean" hint was written for the specific-name case; nested
unknown keys are dominated by generic ones (`enabled` sits at ~72 places
in the schema), so `reviews.tools.enabled` was answered with three wrong
`issue_enrichment.*` homes. Prefer candidates under the offending key's
own parent, and stay silent past three.
* Docstring/README: the two unknown-key halves being duplicate-free is a
fact about THIS vendored schema, not a property of the two conditions —
now stated as such, with `OpennessTest` pinning the premises ($ref
absent, no properties node carrying a combinator).
* Document the by-omission staleness window: a property upstream ADDS
reads as unknown until the schema refresh and each caller's pin land,
which under strict mode is a hard failure on a key the repo was right
to add.
* docs(coderabbit-config): document the partial-scan severity row; correct a stale test comment (BE-7786)
The caller doc's severity table did not carry the new behaviour: an
unknown-key scan that stops early warns by default and fails under
`strict_unknown_keys`, which is the same "I could not check must never
look like a pass" rule the exit-2 row above it states.
The comment on the non-string-key test still named `_key_line`, which the
previous commit replaced with `_key_node`, and still described `str()`
coercion as the fix when it is now only the fallback.1 parent 0071828 commit b09780e
6 files changed
Lines changed: 823 additions & 44 deletions
File tree
- .github
- coderabbit-config
- tests
- workflows
- docs/callers
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
49 | 83 | | |
50 | 84 | | |
51 | 85 | | |
| |||
0 commit comments