Skip to content

Commit 9d9750e

Browse files
committed
fix(hack): tighten resourcesPreset enum check
Address review feedback from gemini-code-assist on hack/check-rd-presets.sh:26 and coderabbitai on hack/check-rd-presets.sh:37. - Switch the jq enum extractor from a description-substring heuristic (test("preset"; "i")) to a JSON path-suffix selector that matches fields literally named resourcesPreset. Eliminates false positives from unrelated fields whose descriptions happen to mention "preset". - Use grep -F for literal enum membership so the "." in entries like t1.nano cannot accidentally match arbitrary characters (e.g. a typo t1xnano would have satisfied t1.nano under basic regex). Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent cca54d8 commit 9d9750e

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎hack/check-rd-presets.sh‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,22 @@ for f in packages/system/*-rd/cozyrds/*.yaml; do
2121
if [ -z "$schema" ]; then
2222
continue
2323
fi
24-
# The schema is a JSON blob. Pull every resourcesPreset enum out of it.
24+
# Pull every resourcesPreset enum out of the schema. Key on the JSON
25+
# path ending in "resourcesPreset" rather than a description heuristic,
26+
# so an unrelated field with "preset" in its description does not match.
2527
enums=$(printf '%s' "$schema" | jq -r '
26-
[.. | objects | select(has("enum") and (.description? // "" | test("preset"; "i")))]
27-
| .[].enum[]
28+
[paths(type == "object" and has("enum")) as $p
29+
| select($p[-1] == "resourcesPreset")
30+
| getpath($p).enum[]]
31+
| .[]
2832
' 2>/dev/null || true)
2933
if [ -z "$enums" ]; then
3034
continue
3135
fi
3236
missing=()
3337
for want in "${EXPECTED[@]}"; do
34-
if ! printf '%s\n' "$enums" | grep -qx "$want"; then
38+
# -F: literal match so the `.` in t1.nano does not match any character.
39+
if ! printf '%s\n' "$enums" | grep -Fqx -- "$want"; then
3540
missing+=("$want")
3641
fi
3742
done

0 commit comments

Comments
 (0)