Skip to content

Commit d0aa077

Browse files
author
Solomon
committed
fix(check-schema): use <schema>-specific grep to avoid <enum id=> FP
`grep -oP 'id="[^"]*"' | head -1` matched the first `id=` attribute in the file, which could be from a `<enum id="...">` element that appears before `<schema id="...">` in schema files that define GSettings enums. Reproduced on caffeine: three `<enum>` elements precede the `<schema>` element, causing the wrong ID to be extracted and triggering false FAIL results for `schema/id-matches` and `schema/filename-convention`. Fix: introduce `extract_schema_id()` which pre-filters to lines containing `<schema\b` before extracting the `id=` attribute. The old one-liner is replaced at all three call sites. Fixes false positive reported in field test 2026-03-22.
1 parent e74c508 commit d0aa077

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

skills/ego-lint/scripts/check-schema.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88
set -euo pipefail
99

1010
EXT_DIR="$(cd "${1:-.}" && pwd)"
11+
12+
# Extract the schema id from a .gschema.xml file.
13+
# Uses a <schema>-specific grep to avoid picking up <enum id=> or other
14+
# elements that appear before <schema id=> in files with multiple top-level
15+
# elements (e.g. caffeine's schema has three <enum> elements first).
16+
extract_schema_id() {
17+
local file="$1"
18+
grep -P '<schema\b' "$file" | grep -oP 'id="[^"]*"' | head -1 | sed 's/id="//;s/"//'
19+
}
20+
1121
METADATA="$EXT_DIR/metadata.json"
1222
# src/ layout fallback
1323
[[ ! -f "$METADATA" && -f "$EXT_DIR/src/metadata.json" ]] && METADATA="$EXT_DIR/src/metadata.json"
@@ -53,8 +63,8 @@ echo "PASS|schema/exists|Found ${#schema_files[@]} schema file(s)"
5363
# Validate schema IDs match metadata
5464
if [[ "$has_settings_schema" == true ]]; then
5565
for schema_file in "${schema_files[@]}"; do
56-
# Extract schema id from XML
57-
schema_id="$(grep -oP 'id="[^"]*"' "$schema_file" | head -1 | sed 's/id="//;s/"//')"
66+
# Extract schema id from XML (use extract_schema_id to avoid matching <enum id=> etc.)
67+
schema_id="$(extract_schema_id "$schema_file")"
5868
if [[ "$schema_id" == "$settings_schema" ]]; then
5969
echo "PASS|schema/id-matches|Schema ID '$schema_id' matches metadata.json settings-schema"
6070
else
@@ -65,7 +75,7 @@ fi
6575

6676
# Validate schema filename convention: <schema-id>.gschema.xml
6777
for schema_file in "${schema_files[@]}"; do
68-
schema_id="$(grep -oP 'id="[^"]*"' "$schema_file" | head -1 | sed 's/id="//;s/"//')"
78+
schema_id="$(extract_schema_id "$schema_file")"
6979
if [[ -n "$schema_id" ]]; then
7080
expected_filename="${schema_id}.gschema.xml"
7181
actual_filename="$(basename "$schema_file")"
@@ -97,7 +107,7 @@ done
97107

98108
# Check for GNOME trademark in schema IDs
99109
for schema_file in "${schema_files[@]}"; do
100-
schema_id="$(grep -oP 'id="[^"]*"' "$schema_file" | head -1 | sed 's/id="//;s/"//')"
110+
schema_id="$(extract_schema_id "$schema_file")"
101111
if [[ -n "$schema_id" ]]; then
102112
# Strip the standard prefix (case-insensitive), then check for 'gnome' in the extension-specific part
103113
lower_id="${schema_id,,}"

0 commit comments

Comments
 (0)