diff --git a/skills/ego-lint/scripts/check-schema.sh b/skills/ego-lint/scripts/check-schema.sh index 83be2f9..0908f5c 100755 --- a/skills/ego-lint/scripts/check-schema.sh +++ b/skills/ego-lint/scripts/check-schema.sh @@ -9,13 +9,27 @@ set -euo pipefail EXT_DIR="$(cd "${1:-.}" && pwd)" -# Extract the schema id from a .gschema.xml file. -# Uses a -specific grep to avoid picking up or other -# elements that appear before in files with multiple top-level -# elements (e.g. caffeine's schema has three elements first). +# Extract ALL schema ids from a .gschema.xml file. +# Filters to or other elements. +extract_all_schema_ids() { + local file="$1" + grep -P ' etc.) - schema_id="$(extract_schema_id "$schema_file")" - if [[ "$schema_id" == "$settings_schema" ]]; then - echo "PASS|schema/id-matches|Schema ID '$schema_id' matches metadata.json settings-schema" + # Check whether settings-schema appears as ANY in the file. + # Multi-schema XML (e.g. main schema + .keybindings sub-schema) must not + # fail just because a sub-schema appears first. + if schema_id_in_file "$schema_file" "$settings_schema"; then + echo "PASS|schema/id-matches|Schema ID '$settings_schema' found in $(basename "$schema_file")" else - echo "FAIL|schema/id-matches|Schema ID '$schema_id' does not match metadata.json settings-schema '$settings_schema'" + all_ids="$(extract_all_schema_ids "$schema_file" | paste -sd ' ')" + echo "FAIL|schema/id-matches|settings-schema '$settings_schema' not found in $(basename "$schema_file") (found: ${all_ids})" fi done fi -# Validate schema filename convention: .gschema.xml +# Validate schema filename convention: .gschema.xml +# When settings-schema is defined in metadata.json, the file MUST be named +# after that ID (the primary schema). For extensions without settings-schema, +# fall back to the first schema ID found in the file. for schema_file in "${schema_files[@]}"; do - schema_id="$(extract_schema_id "$schema_file")" - if [[ -n "$schema_id" ]]; then - expected_filename="${schema_id}.gschema.xml" + if [[ "$has_settings_schema" == true ]]; then + ref_id="$settings_schema" + else + ref_id="$(extract_schema_id "$schema_file")" + fi + if [[ -n "$ref_id" ]]; then + expected_filename="${ref_id}.gschema.xml" actual_filename="$(basename "$schema_file")" if [[ "$actual_filename" == "$expected_filename" ]]; then - echo "PASS|schema/filename-convention|Schema filename matches ID: $actual_filename" + echo "PASS|schema/filename-convention|Schema filename matches settings-schema: $actual_filename" else echo "FAIL|schema/filename-convention|Schema filename '$actual_filename' MUST be '$expected_filename'" fi diff --git a/tests/fixtures/multi-schema@test/extension.js b/tests/fixtures/multi-schema@test/extension.js new file mode 100644 index 0000000..2ecc148 --- /dev/null +++ b/tests/fixtures/multi-schema@test/extension.js @@ -0,0 +1,6 @@ +import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js'; + +export default class MultiSchemaExtension extends Extension { + enable() {} + disable() {} +} diff --git a/tests/fixtures/multi-schema@test/metadata.json b/tests/fixtures/multi-schema@test/metadata.json new file mode 100644 index 0000000..d1db00f --- /dev/null +++ b/tests/fixtures/multi-schema@test/metadata.json @@ -0,0 +1,8 @@ +{ + "uuid": "multi-schema@test", + "name": "Multi-Schema Test", + "description": "Tests that schema/id-matches passes when settings-schema appears after a sub-schema (e.g. .keybindings) in gschema.xml", + "shell-version": ["48"], + "settings-schema": "org.gnome.shell.extensions.multi-schema", + "url": "https://github.com/test/multi-schema" +} diff --git a/tests/fixtures/multi-schema@test/schemas/org.gnome.shell.extensions.multi-schema.gschema.xml b/tests/fixtures/multi-schema@test/schemas/org.gnome.shell.extensions.multi-schema.gschema.xml new file mode 100644 index 0000000..4ba6f9c --- /dev/null +++ b/tests/fixtures/multi-schema@test/schemas/org.gnome.shell.extensions.multi-schema.gschema.xml @@ -0,0 +1,19 @@ + + + + + + ["<Super>Left"] + Move left keybinding + + + + + + true + Enable feature + + + diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 2f08504..4941aae 100755 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -466,6 +466,15 @@ assert_exit_code "exits with 1 (has failures)" 1 assert_output_contains "fails on schema filename" "\[FAIL\].*schema/filename-convention" echo "" +# --- multi-schema (sub-schema appears before main schema in XML) --- +echo "=== multi-schema ===" +run_lint "multi-schema@test" +assert_output_not_contains "no schema/id-matches FAIL for multi-schema XML" "\[FAIL\].*schema/id-matches" +assert_output_not_contains "no schema/filename-convention FAIL for multi-schema XML" "\[FAIL\].*schema/filename-convention" +assert_output_contains "id-matches passes for multi-schema XML" "\[PASS\].*schema/id-matches" +assert_output_contains "filename-convention passes for multi-schema XML" "\[PASS\].*schema/filename-convention" +echo "" + # --- gnome46-compat --- echo "=== gnome46-compat ===" run_lint "gnome46-compat@test"