From 2a30e626216266d2cc9b8b29c94c523f9538f3d0 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Fri, 27 Feb 2026 23:20:42 -0500 Subject: [PATCH] test(sim): Setup framework for robust live sim verification --- api_hook_client.py | 20 ++++++++++++++++++++ tests/test_api_hook_client.py | 35 +++++++++++++++++++++++++++++++++++ tests/visual_sim_mma_v2.py | 20 ++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 tests/visual_sim_mma_v2.py diff --git a/api_hook_client.py b/api_hook_client.py index c41c28f..2b44509 100644 --- a/api_hook_client.py +++ b/api_hook_client.py @@ -162,6 +162,26 @@ class ApiHookClient: pass return None + def get_text_value(self, item_tag): + """Wraps get_value and returns its string representation, or None.""" + val = self.get_value(item_tag) + return str(val) if val is not None else None + + def get_node_status(self, node_tag): + """Wraps get_value for a DAG node or queries the diagnostic endpoint for its status.""" + val = self.get_value(node_tag) + if val is not None: + return val + try: + diag = self._make_request('GET', '/api/gui/diagnostics') + if 'nodes' in diag and node_tag in diag['nodes']: + return diag['nodes'][node_tag] + if node_tag in diag: + return diag[node_tag] + except Exception: + pass + return None + def click(self, item, *args, **kwargs): """Simulates a click on a GUI button or item.""" user_data = kwargs.pop('user_data', None) diff --git a/tests/test_api_hook_client.py b/tests/test_api_hook_client.py index d3620ed..444df8a 100644 --- a/tests/test_api_hook_client.py +++ b/tests/test_api_hook_client.py @@ -63,3 +63,38 @@ def test_unsupported_method_error(): client = ApiHookClient() with pytest.raises(ValueError, match="Unsupported HTTP method"): client._make_request('PUT', '/some_endpoint', data={'key': 'value'}) + +def test_get_text_value(): + """ + Test retrieval of string representation using get_text_value. + """ + client = ApiHookClient() + with patch.object(client, 'get_value', return_value=123): + assert client.get_text_value("dummy_tag") == "123" + + with patch.object(client, 'get_value', return_value=None): + assert client.get_text_value("dummy_tag") is None + +def test_get_node_status(): + """ + Test retrieval of DAG node status using get_node_status. + """ + client = ApiHookClient() + # When get_value returns a status directly + with patch.object(client, 'get_value', return_value="running"): + assert client.get_node_status("my_node") == "running" + + # When get_value returns None and diagnostics provides a nodes dict + with patch.object(client, 'get_value', return_value=None): + with patch.object(client, '_make_request', return_value={'nodes': {'my_node': 'completed'}}): + assert client.get_node_status("my_node") == "completed" + + # When get_value returns None and diagnostics provides a direct key + with patch.object(client, 'get_value', return_value=None): + with patch.object(client, '_make_request', return_value={'my_node': 'failed'}): + assert client.get_node_status("my_node") == "failed" + + # When neither works + with patch.object(client, 'get_value', return_value=None): + with patch.object(client, '_make_request', return_value={}): + assert client.get_node_status("my_node") is None diff --git a/tests/visual_sim_mma_v2.py b/tests/visual_sim_mma_v2.py new file mode 100644 index 0000000..7edf0ac --- /dev/null +++ b/tests/visual_sim_mma_v2.py @@ -0,0 +1,20 @@ +import pytest +import time +import sys +import os + +# Ensure project root is in path +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) + +from api_hook_client import ApiHookClient + +@pytest.mark.integration +def test_mma_epic_simulation(live_gui): + """ + Integration test for MMA epic simulation. + Red Phase: asserts False. + """ + client = ApiHookClient() + assert client.wait_for_server(timeout=10) + + assert False, "Red Phase: Not yet implemented"