import pytest import time import sys import os import json sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src"))) from src import api_hook_client @pytest.mark.integration def test_undo_redo_lifecycle(live_gui): client = api_hook_client.ApiHookClient() assert client.wait_for_server(timeout=15), "Hook server did not start" # 1. Set initial state client.set_value('temperature', 0.5) client.set_value('ai_input', "Initial Input") time.sleep(0.5) # Wait for debounce timer to start if it was triggered # Trigger a snapshot by waiting for debounce time.sleep(2.0) # 2. Change state client.set_value('temperature', 1.5) client.set_value('ai_input', "Modified Input") # Wait for debounce to push "Modified" state to history time.sleep(2.0) # Verify current state assert client.get_value('temperature') == 1.5 assert client.get_value('ai_input') == "Modified Input" # 3. Undo print("Sending Undo...") # Since we don't have a direct 'undo' hook, we can use 'click' if we added a button, # or we can simulate the hotkey if the hook API supports it. # Actually, I'll add a 'btn_undo' and 'btn_redo' to clickable actions for testing. client.click('btn_undo') # Wait for state to revert time.sleep(0.5) # Should be back to initial state # Note: Undo moves 'current' to redo stack and pops from undo. # If we were at 'Modified', and we undo, we should get 'Initial'. assert client.get_value('ai_input') == "Initial Input" assert client.get_value('temperature') == 0.5 # 4. Redo print("Sending Redo...") client.click('btn_redo') time.sleep(0.5) assert client.get_value('ai_input') == "Modified Input" assert client.get_value('temperature') == 1.5 print("Undo/Redo lifecycle test PASSED.")