From 3a025f41e08174b5f4f689adca67d1453bfe2be8 Mon Sep 17 00:00:00 2001 From: zvecr Date: Thu, 17 Jul 2025 00:42:12 +0100 Subject: [PATCH 1/2] Ensure keyboard aliases do not point to themselves --- lib/python/qmk/cli/ci/validate_aliases.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/python/qmk/cli/ci/validate_aliases.py b/lib/python/qmk/cli/ci/validate_aliases.py index 8b062dbe566..f891a599050 100644 --- a/lib/python/qmk/cli/ci/validate_aliases.py +++ b/lib/python/qmk/cli/ci/validate_aliases.py @@ -32,6 +32,10 @@ def ci_validate_aliases(cli): success = True for alias in aliases.keys(): target = aliases[alias].get('target', None) + if alias == target: + cli.log.error(f'Keyboard alias {alias} should not point to itself') + success = False + if not _target_keyboard_exists(target): cli.log.error(f'Keyboard alias {alias} has a target that doesn\'t exist: {target}') success = False From 60f2f215c24a56fe5603b9889406da608fef9b1f Mon Sep 17 00:00:00 2001 From: zvecr Date: Thu, 17 Jul 2025 03:56:40 +0100 Subject: [PATCH 2/2] Also check for circular refs --- lib/python/qmk/cli/ci/validate_aliases.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/python/qmk/cli/ci/validate_aliases.py b/lib/python/qmk/cli/ci/validate_aliases.py index f891a599050..4f2fe6c9412 100644 --- a/lib/python/qmk/cli/ci/validate_aliases.py +++ b/lib/python/qmk/cli/ci/validate_aliases.py @@ -25,6 +25,21 @@ def _target_keyboard_exists(target): return True +def _alias_not_self(alias): + """Check if alias points to itself, either directly or within a circular reference + """ + aliases = keyboard_alias_definitions() + + found = set() + while alias in aliases: + found.add(alias) + alias = aliases[alias].get('target', alias) + if alias in found: + return False + + return True + + @cli.subcommand('Validates the list of keyboard aliases.', hidden=True) def ci_validate_aliases(cli): aliases = keyboard_alias_definitions() @@ -32,11 +47,11 @@ def ci_validate_aliases(cli): success = True for alias in aliases.keys(): target = aliases[alias].get('target', None) - if alias == target: + if not _alias_not_self(alias): cli.log.error(f'Keyboard alias {alias} should not point to itself') success = False - if not _target_keyboard_exists(target): + elif not _target_keyboard_exists(target): cli.log.error(f'Keyboard alias {alias} has a target that doesn\'t exist: {target}') success = False