Skip to content

Commit 8399589

Browse files
ZviBaratzSolomon
andauthored
fix(ego-lint): avoid false FAIL when enum-id precedes schema-id in check-schema (#148)
## Problem `check-schema.sh` extracts the schema ID using: ```bash grep -oP 'id="[^"]*"' "$schema_file" | head -1 | sed 's/id="//;s/"//' ``` This grabs the **first** `id=` attribute in the file — which may belong to a `<enum>` element that appears before the `<schema>` element. **Reproduced on caffeine** (`caffeine@patapon.info`): the schema file defines three `<enum id="...">` elements before `<schema id="org.gnome.shell.extensions.caffeine">`. The old code extracted the enum ID (`org.gnome.shell.extensions.caffeine.context-control`), causing two false FAILs: - `schema/id-matches` — ID didn't match `metadata.json settings-schema` - `schema/filename-convention` — expected filename based on wrong ID ## Fix Introduce `extract_schema_id()` helper that pre-filters to lines matching `<schema\b` before extracting `id=`: ```bash extract_schema_id() { local file="$1" grep -P '<schema\b' "$file" | grep -oP 'id="[^"]*"' | head -1 | sed 's/id="//;s/"//' } ``` The old inline one-liner is replaced at all three call sites (`schema/id-matches`, `schema/filename-convention`, `schema/gnome-trademark`). ## Test Before fix on caffeine: ``` FAIL|schema/id-matches|Schema ID 'org.gnome.shell.extensions.caffeine.context-control' does not match ... FAIL|schema/filename-convention|Schema filename 'org.gnome.shell.extensions.caffeine.gschema.xml' MUST be '...' ``` After fix on caffeine: ``` PASS|schema/id-matches|Schema ID 'org.gnome.shell.extensions.caffeine' matches metadata.json settings-schema PASS|schema/filename-convention|Schema filename matches ID: org.gnome.shell.extensions.caffeine.gschema.xml ``` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Solomon <sol@nanoclaw.dev>
1 parent 2962779 commit 8399589

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)