From 0a9939b34bce86d4cab8dd05d83595fb7b4cfeb5 Mon Sep 17 00:00:00 2001 From: mikecarper Date: Tue, 20 Oct 2026 13:35:03 -0700 Subject: [PATCH] test: align CLI help checks with bounded output --- test/test_indicator_exclusive_transport.py | 17 +++++++++++++++-- test/test_nrf52_uf2reset_cli.py | 14 +++++++++++++- test/test_storage_layout_cli.py | 10 +++++++--- test/test_touch_debug_cli.py | 3 ++- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/test/test_indicator_exclusive_transport.py b/test/test_indicator_exclusive_transport.py index bb65a31ea..a18698fc9 100644 --- a/test/test_indicator_exclusive_transport.py +++ b/test/test_indicator_exclusive_transport.py @@ -144,8 +144,21 @@ assert 'strcmp(command, "get companion.transport") == 0' in local assert 'strncmp(command, "set companion.transport", 23) == 0' in local assert '"OK - companion transport %s saved; reboot required"' in local assert '"Error: failed to save companion transport"' in local -assert 'terminalOutput().print(" get companion.transport\\r\\n")' in mesh -assert 'terminalOutput().print(" set companion.transport \\r\\n")' in mesh +help_start = mesh.index(' } else if (strcmp(command, "help") == 0) {') +help_end = mesh.index(' } else if (handleCommand(command, 0, local_reply))', help_start) +help_body = mesh[help_start:help_end] +# Help uses one selected terminal reference while each native USB write stays +# bounded. Keep both policy-specific commands on that same selected stream. +help_output = re.search(r"auto& (\w+) = terminalOutput\(\);", help_body) +assert help_output +help_transport = re.search( + r"#if defined\(COMPANION_EXCLUSIVE_WIFI_BLE\)(.*?)#endif", + help_body, + re.DOTALL, +) +assert help_transport +for text in (" get companion.transport\\r\\n", " set companion.transport \\r\\n"): + assert f'{help_output[1]}.print("{text}")' in help_transport[1] assert "WebUI unavailable while Bluetooth transport is active" in mesh diff --git a/test/test_nrf52_uf2reset_cli.py b/test/test_nrf52_uf2reset_cli.py index 7fc44d4c7..20f22d76f 100644 --- a/test/test_nrf52_uf2reset_cli.py +++ b/test/test_nrf52_uf2reset_cli.py @@ -2,6 +2,7 @@ """Pin local UF2 reset support across every nRF52 text CLI family.""" from pathlib import Path +import re ROOT = Path(__file__).resolve().parents[1] @@ -35,7 +36,18 @@ assert "sender_timestamp == 0" in common assert "sender_timestamp == 0 && mesh::cli::isUf2ResetCommand(command)" in companion assert "board.rebootToUf2Bootloader()" in companion -assert 'terminalOutput().println(" uf2reset");' in companion +help_start = companion.index(' } else if (strcmp(command, "help") == 0) {') +help_end = companion.index(' } else if (handleCommand(command, 0, local_reply))', help_start) +help_body = companion[help_start:help_end] +help_output = re.search(r"auto& (\w+) = terminalOutput\(\);", help_body) +assert help_output +# Bounded help writes use the cached selected stream; UF2 help stays nRF-only. +assert re.search( + r"#if defined\(NRF52_PLATFORM\)\s+" + + re.escape(f'{help_output[1]}.println(" uf2reset");') + + r"\s+#endif", + help_body, +) assert "mesh::cli::isUf2ResetCommand(command)" in chat assert "board.rebootToUf2Bootloader()" in chat diff --git a/test/test_storage_layout_cli.py b/test/test_storage_layout_cli.py index 514a3cffd..046aa583b 100644 --- a/test/test_storage_layout_cli.py +++ b/test/test_storage_layout_cli.py @@ -140,10 +140,14 @@ int main() { re.DOTALL, ), ) - self.assertIn( - 'terminalOutput().print(" get storage.layout\\r\\n");', - companion, + help_start = companion.index(' } else if (strcmp(command, "help") == 0) {') + help_end = companion.index( + ' } else if (handleCommand(command, 0, local_reply))', help_start ) + help_body = companion[help_start:help_end] + self.assertRegex(help_body, r"auto& \w+ = terminalOutput\(\);") + # This line may share a bounded help chunk with adjacent commands. + self.assertIn('" get storage.layout\\r\\n"', help_body) # ESP-IDF discovery and every platform-specific result live only in the # shared formatter; neither role owns a second copy. diff --git a/test/test_touch_debug_cli.py b/test/test_touch_debug_cli.py index d545eca83..42c41ddfb 100644 --- a/test/test_touch_debug_cli.py +++ b/test/test_touch_debug_cli.py @@ -159,7 +159,8 @@ int main() { self.assertIn("handleLocalControlCommand(command, reply, reply_capacity)", handler) terminal = extract_braced(mesh, "void MyMesh::handleTerminalCommand(") self.assertIn("handleLocalControlCommand(command, local_reply, sizeof(local_reply))", terminal) - self.assertIn('get display.touch\\r\\n', terminal) + help_body = extract_braced(terminal, 'else if (strcmp(command, "help") == 0)') + self.assertIn('get/set display.touch (this boot)\\r\\n', help_body) # No persistent preference schema or write is involved. setter = extract_braced(local, 'if (strncmp(command, "set display.touch", 17) == 0') self.assertNotIn("savePrefs", setter)