fix: Detect duplicates between front<->rear ports mapping (#3821)

* fix: extend front/rear port check to modules

* fix: detect duplicates between front<->rear ports mapping

---------

Co-authored-by: Harry <Harry@cadby.co.uk>
This commit is contained in:
Marcin Zieba
2025-12-30 10:19:17 +01:00
committed by GitHub
parent c932b12e92
commit 8af496076a
3 changed files with 16 additions and 2 deletions

View File

@@ -31,7 +31,7 @@ front-ports:
color: 00ffff
- name: '{module}:B-2'
type: mpo
rear_port: '{module}:A-2'
rear_port: '{module}:B-2'
rear_port_position: 1
color: 00ffff
- name: '{module}:B-3'

View File

@@ -26,7 +26,7 @@ front-ports:
rear_port_position: 1
- name: '{module}:B-2'
type: mpo
rear_port: '{module}:A-2'
rear_port: '{module}:B-2'
rear_port_position: 1
- name: '{module}:B-3'
type: mpo

View File

@@ -211,6 +211,7 @@ def test_definitions(file_path, schema, change_type):
rp.get("name") for rp in rear_ports if isinstance(rp, dict)
}
rear_port_positions = {}
for fp in front_ports:
if not isinstance(fp, dict):
continue
@@ -225,6 +226,19 @@ def test_definitions(file_path, schema, change_type):
pytrace=False,
)
# Check for duplicate (rear_port, rear_port_position) combinations
if rear_port_ref:
rear_port_pos = fp.get("rear_port_position", 1)
key = (rear_port_ref, rear_port_pos)
if key in rear_port_positions:
pytest.fail(
f"{file_path}: front-port '{fp.get('name')}' has duplicate "
f"(rear_port, rear_port_position) = ('{rear_port_ref}', {rear_port_pos}). "
f"Already used by front-port '{rear_port_positions[key]}'.",
pytrace=False,
)
rear_port_positions[key] = fp.get("name")
# Verify the slug is valid, only if the definition type is a Device
if this_device.isDevice:
assert this_device.verify_slug(KNOWN_SLUGS), pytest.fail(this_device.failureMessage, False)