Skip to content

Commit b3efc9d

Browse files
committed
fix(connection-selection): consistency fixes
1 parent 561791b commit b3efc9d

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

ardupilot_methodic_configurator/frontend_tkinter_connection_selection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ def __init__( # pylint: disable=too-many-arguments, too-many-positional-argumen
8080
# Load saved connection history from ProgramSettings and cache it to avoid
8181
# repeated disk reads on every periodic port-refresh cycle.
8282
self._connection_history_cache: list[str] = ProgramSettings.get_connection_history()
83-
for conn in self._connection_history_cache:
84-
self.flight_controller.add_connection(conn)
83+
# Perform an initial connection discovery using the cached history so the
84+
# combobox starts from the same source-of-truth list that refresh uses.
85+
self.flight_controller.discover_connections(preserved_connections=self._connection_history_cache)
8586

8687
# Create a read-only combobox for flight controller connection selection
8788
self.conn_selection_combobox = PairTupleCombobox(

tests/test_backend_flightcontroller_connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,9 @@ def test_preserved_connection_survives_port_rediscovery(self) -> None:
483483
GIVEN: User has previously used a custom connection (e.g. a TCP address stored in history)
484484
WHEN: discover_connections() is called again (periodic 3s refresh) and returns different ports
485485
AND the caller supplies the history list as preserved_connections
486-
THEN: The preserved connection should still be present in the combobox
487-
AND: Auto-discovered ports that disappeared should be gone
488-
AND: Newly auto-discovered ports should appear
486+
THEN: The preserved connection should still be present in the available connections list/tuples
487+
AND: Auto-discovered ports that disappeared should be gone from the available connections list/tuples
488+
AND: Newly auto-discovered ports should appear in the available connections list/tuples
489489
"""
490490
# Given: Connection manager with a mocked serial port discovery
491491
mock_discovery = Mock()

tests/test_frontend_tkinter_connection_selection.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -804,8 +804,8 @@ def test_periodic_refresh_starts_on_init(
804804
AND: root.after should have been called to schedule the next recurring refresh
805805
AND: The widget should not be in a refreshing state after initialization completes
806806
"""
807-
periodic_widget._mock_fc.discover_connections.assert_called_once_with( # type: ignore[attr-defined]
808-
progress_callback=None, preserved_connections=[]
807+
periodic_widget._mock_fc.discover_connections.assert_any_call( # type: ignore[attr-defined]
808+
preserved_connections=[]
809809
)
810810
mock_parent.root.after.assert_called_with(3000, periodic_widget._refresh_ports)
811811
assert periodic_widget._is_refreshing is False
@@ -1004,12 +1004,12 @@ def test_history_cache_is_populated_from_program_settings_on_startup(self) -> No
10041004

10051005
def test_stored_connections_are_registered_with_flight_controller_on_init(self) -> None:
10061006
"""
1007-
Each connection in the loaded history is registered with the flight controller.
1007+
History connections are passed to discover_connections on init.
10081008
10091009
GIVEN: ProgramSettings holds two previously used connections
10101010
WHEN: ConnectionSelectionWidgets is initialized
1011-
THEN: flight_controller.add_connection should have been called once per stored entry
1012-
AND: Each call should use the exact stored connection string
1011+
THEN: flight_controller.discover_connections should have been called with preserved_connections
1012+
AND: The preserved_connections should contain each stored entry
10131013
"""
10141014
history = ["COM1", "tcp:127.0.0.1:5761"]
10151015
mock_parent = MagicMock()
@@ -1036,9 +1036,8 @@ def test_stored_connections_are_registered_with_flight_controller_on_init(self)
10361036
download_params_on_connect=False,
10371037
)
10381038

1039-
calls = [call[0][0] for call in mock_fc.add_connection.call_args_list]
1040-
assert "COM1" in calls
1041-
assert "tcp:127.0.0.1:5761" in calls
1039+
mock_fc.discover_connections.assert_any_call(preserved_connections=history)
1040+
mock_fc.add_connection.assert_not_called()
10421041

10431042
def test_history_cache_is_empty_when_settings_has_no_stored_connections(self) -> None:
10441043
"""
@@ -1162,7 +1161,7 @@ def test_persist_and_cache_deduplicates_existing_matching_cache_entry(
11621161
self, persist_widget: tuple[ConnectionSelectionWidgets, MagicMock, MagicMock]
11631162
) -> None:
11641163
"""
1165-
_persist_and_cache_connection removes the old occurrence of a re-used connection.
1164+
_persist_and_cache_connection removes the old occurrence of a reused connection.
11661165
11671166
GIVEN: The cache already contains "COM3" at position 2
11681167
WHEN: "COM3" is persisted again (user reconnects to a previous device)

0 commit comments

Comments
 (0)