Private
Public Access
0
0
Files
manual_slop/tests/test_gui2_parity.py
T
ed 09eaf69a83 fix(tests): resolve 3 pre-existing test failures surfaced by user's batched run
The phase2_4_5_call_site_completion_20260621 track's end-of-track report
documented 5 pre-existing tier-1-unit-core failures as 'not caused by
this track' and deferred them to a future track. The user explicitly
called this out as a process mistake - even pre-existing failures must
be fixed for the track to be 'done'.

Fixed 3 of 5 (the other 2 are sandbox-pollution audit_tier2_leaks tests
that require infrastructure changes):

1. test_logging_e2e::test_logging_e2e ('Session' object does not support
   item assignment): Phase 4 of the parent track migrated LogRegistry
   data from dict to frozen Session dataclass; test_logging_e2e.py was
   missed in the migration. Fix: add LogRegistry.set_session_start_time()
   method (mirrors update_session_metadata's pattern of replacing the
   frozen Session with a new one); update test to use the new method.

2. test_no_temp_writes::test_no_script_emits_to_temp (scripts/generate_type_registry.py
   uses tempfile): The --check mode was using tempfile.TemporaryDirectory
   which the audit forbids. Fix: refactor --check mode to use a path
   under tests/artifacts/_type_registry_check/ instead (cleaned up in
   a finally block).

3. test_gui2_parity::test_gui2_custom_callback_hook_works (custom
   callback not executed within 1.5s): The test used time.sleep(1.5) +
   assert, the documented race condition anti-pattern. Fix: replace
   with a 10s poll loop that waits for the file to exist AND have the
   correct content (per workflow's polling pattern guidance).

Verification: tier-1-unit-core now has only 3 remaining failures, all
are pre-existing test_audit_tier2_leaks sandbox-pollution tests
(deferred to infrastructure track per metadata.json).
2026-06-21 23:06:54 -04:00

90 lines
3.0 KiB
Python

import pytest
from typing import Any
import time
import os
import uuid
from pathlib import Path
import sys
# Ensure project root is in path for imports
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 api_hook_client import ApiHookClient
# Define a temporary file path for callback testing
TEST_CALLBACK_FILE = Path("tests/artifacts/temp_callback_output.txt")
@pytest.fixture(scope="function", autouse=True)
def cleanup_callback_file() -> None:
"""Ensures the test callback file is cleaned up before and after each test."""
if TEST_CALLBACK_FILE.exists():
TEST_CALLBACK_FILE.unlink()
yield
if TEST_CALLBACK_FILE.exists():
TEST_CALLBACK_FILE.unlink()
def test_gui2_set_value_hook_works(live_gui: Any) -> None:
"""
Tests that the 'set_value' GUI hook is correctly implemented.
"""
client = ApiHookClient()
assert client.wait_for_server(timeout=10)
test_value = f"New value set by test: {uuid.uuid4()}"
gui_data = {'action': 'set_value', 'item': 'ai_input', 'value': test_value}
response = client.post_gui(gui_data)
assert response == {'status': 'queued'}
# Verify the value was actually set using the new get_value hook
time.sleep(1.5)
current_value = client.get_value('ai_input')
assert current_value == test_value
def test_gui2_click_hook_works(live_gui: Any) -> None:
"""
Tests that the 'click' GUI hook for the 'Reset' button is implemented.
"""
client = ApiHookClient()
assert client.wait_for_server(timeout=10)
# First, set some state that 'Reset' would clear.
test_value = "This text should be cleared by the reset button."
client.set_value('ai_input', test_value)
time.sleep(1.5)
assert client.get_value('ai_input') == test_value
# Now, trigger the click
client.click('btn_reset')
time.sleep(1.5)
# Verify it was reset
assert client.get_value('ai_input') == ""
def test_gui2_custom_callback_hook_works(live_gui: Any) -> None:
"""
Tests that the 'custom_callback' GUI hook is correctly implemented.
"""
client = ApiHookClient()
assert client.wait_for_server(timeout=10)
test_data = f"Callback executed: {uuid.uuid4()}"
gui_data = {
'action': 'custom_callback',
'callback': '_test_callback_func_write_to_file',
'args': [test_data]
}
response = client.post_gui(gui_data)
assert response == {'status': 'queued'}
# Poll for the callback to complete (avoids time.sleep race; per workflow anti-pattern)
temp_workspace_file = Path('tests/artifacts/temp_callback_output.txt')
deadline = time.time() + 10.0
while time.time() < deadline:
if temp_workspace_file.exists():
content = temp_workspace_file.read_text(encoding="utf-8")
if content == test_data:
return
time.sleep(0.1)
assert temp_workspace_file.exists(), f"Custom callback was NOT executed, or file path is wrong! Expected: {temp_workspace_file}"
with open(temp_workspace_file, "r") as f:
content = f.read()
assert content == test_data, "Callback executed, but file content is incorrect."