diff --git a/tests/build_scripts/test_location_message_policy_integration.py b/tests/build_scripts/test_location_message_policy_integration.py index 9ea76045..63cc42a3 100644 --- a/tests/build_scripts/test_location_message_policy_integration.py +++ b/tests/build_scripts/test_location_message_policy_integration.py @@ -5,6 +5,20 @@ CPP = ROOT / "lib/tdeck_ui/UI/LXMF/UIManager.cpp" HEADER = ROOT / "lib/tdeck_ui/UI/LXMF/UIManager.h" +def guarded_block(source: str, condition: str) -> tuple[int, int]: + condition_start = source.index(condition) + open_brace = source.index("{", condition_start) + depth = 0 + for index in range(open_brace, len(source)): + if source[index] == "{": + depth += 1 + elif source[index] == "}": + depth -= 1 + if depth == 0: + return open_brace, index + raise AssertionError("unterminated guarded block") + + def test_inbound_location_policy_precedes_chat_persistence(): source = CPP.read_text() handler = source[source.index("void UIManager::on_message_received") :] @@ -19,6 +33,19 @@ def test_inbound_location_policy_precedes_chat_persistence(): assert "message.source_hash()" in handler[:save] assert "location_decision.authenticated_sender" in handler[:save] + guard_start, guard_end = guarded_block( + handler, + "if (message.signature_validated() &&\n" + " source_hash.size() == Telemetry::PEER_ID_SIZE)", + ) + guarded = handler[guard_start:guard_end] + assert "RNS::Utilities::OS::ltime()" in guarded + assert "classifyInboundLocationMessage" in guarded + assert "_peer_locations.apply" in guarded + assert "location_decision.authenticated_sender" in guarded + assert handler.count("classifyInboundLocationMessage") == 1 + assert handler.count("_peer_locations.apply") == 1 + def test_peer_location_store_is_durable_ui_manager_state(): header = HEADER.read_text() diff --git a/tests/build_scripts/test_tdeck_environment_isolation.py b/tests/build_scripts/test_tdeck_environment_isolation.py index d2753ea5..ea11ab2d 100644 --- a/tests/build_scripts/test_tdeck_environment_isolation.py +++ b/tests/build_scripts/test_tdeck_environment_isolation.py @@ -2,6 +2,9 @@ from pathlib import Path ROOT = Path(__file__).resolve().parents[2] CONFIG = ROOT / "platformio.ini" +MAIN = ROOT / "src/main.cpp" +HARDWARE_RUNNER = ROOT / "tests/hardware/run_e2e.sh" +VOICE_README = ROOT / "tools/voice_test/README.md" def section(text: str, name: str) -> str: @@ -19,5 +22,18 @@ def test_test_hooks_are_isolated_from_production_tdeck(): assert "PYXIS_TEST_TCP_PORT" not in production assert "extends = env:tdeck" in instrumented assert "-DPYXIS_TEST_HOOKS" in instrumented - assert "PYXIS_TEST_TCP_HOST" in instrumented - assert "PYXIS_TEST_TCP_PORT" in instrumented + assert '\'-DPYXIS_TEST_TCP_HOST="${sysenv.PYXIS_TEST_TCP_HOST}"\'' in instrumented + assert '\'-DPYXIS_TEST_TCP_PORT="${sysenv.PYXIS_TEST_TCP_PORT}"\'' in instrumented + + +def test_test_hook_defaults_and_harness_target_are_safe(): + main = MAIN.read_text() + hook_defaults = main[main.index("#ifdef PYXIS_TEST_HOOKS") : main.index("#include ")] + assert '#define PYXIS_TEST_TCP_HOST ""' in hook_defaults + assert '#define PYXIS_TEST_TCP_PORT ""' in hook_defaults + + runner = HARDWARE_RUNNER.read_text() + assert 'PYXIS_ENV="${PYXIS_ENV:-tdeck-test}"' in runner + + voice_readme = VOICE_README.read_text() + assert "pio run -e tdeck-test" in voice_readme