From 35822aab0883b38ecb943fb53b86203ab5898fa8 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Mon, 2 Mar 2026 20:54:25 -0500 Subject: [PATCH] chore(test): Centralize app_instance and mock_app fixtures in conftest.py --- conductor/tracks.md | 7 ++++ .../plan.md | 2 +- config.toml | 4 +- project_history.toml | 2 +- tests/conftest.py | 39 +++++++++++++++++++ 5 files changed, 50 insertions(+), 4 deletions(-) diff --git a/conductor/tracks.md b/conductor/tracks.md index f8d7a60..424e8fe 100644 --- a/conductor/tracks.md +++ b/conductor/tracks.md @@ -4,6 +4,13 @@ This file tracks all major tracks for the project. Each track has its own detail --- +## Current Tracks + +- [~] **Track: Tech Debt & Test Discipline Cleanup** +*Link: [./tracks/tech_debt_and_test_cleanup_20260302/](./tracks/tech_debt_and_test_cleanup_20260302/)* + +--- + ## Completed / Archived - [x] **Track: Conductor Workflow Improvements** diff --git a/conductor/tracks/tech_debt_and_test_cleanup_20260302/plan.md b/conductor/tracks/tech_debt_and_test_cleanup_20260302/plan.md index 64c0752..9703ce5 100644 --- a/conductor/tracks/tech_debt_and_test_cleanup_20260302/plan.md +++ b/conductor/tracks/tech_debt_and_test_cleanup_20260302/plan.md @@ -7,7 +7,7 @@ Architecture reference: [docs/guide_architecture.md](../../../docs/guide_archite ## Phase 1: Test Suite Deduplication and Centralization Focus: Move `app_instance` and `mock_app` to `tests/conftest.py` and remove them from individual test files. -- [ ] Task 1.1: Add `app_instance` and `mock_app` fixtures to `tests/conftest.py`. Ensure they properly yield the App instance and tear down. +- [~] Task 1.1: Add `app_instance` and `mock_app` fixtures to `tests/conftest.py`. Ensure they properly yield the App instance and tear down. - [ ] Task 1.2: Remove local `app_instance` and `mock_app` fixtures from all 13 identified test files. (Tier 3 Worker string replacement / rewrite). - [ ] Task 1.3: Delete `tests/test_ast_parser_curated.py` if its contents are fully duplicated in `test_ast_parser.py`, or merge any missing tests. - [ ] Task 1.4: Run the test suite (`pytest`) to ensure no fixture resolution errors. diff --git a/config.toml b/config.toml index 746ada0..cfbcfce 100644 --- a/config.toml +++ b/config.toml @@ -1,6 +1,6 @@ [ai] provider = "gemini_cli" -model = "gemini-2.0-flash" +model = "gemini-2.5-flash-lite" temperature = 0.0 max_tokens = 8192 history_trunc_limit = 8000 @@ -15,7 +15,7 @@ paths = [ "C:\\projects\\manual_slop\\tests\\artifacts\\temp_livetoolssim.toml", "C:\\projects\\manual_slop\\tests\\artifacts\\temp_liveexecutionsim.toml", ] -active = "C:\\projects\\manual_slop\\tests\\artifacts\\temp_project.toml" +active = "C:\\projects\\manual_slop\\tests\\artifacts\\temp_liveexecutionsim.toml" [gui.show_windows] "Context Hub" = true diff --git a/project_history.toml b/project_history.toml index 70ffa18..66a0777 100644 --- a/project_history.toml +++ b/project_history.toml @@ -8,5 +8,5 @@ active = "main" [discussions.main] git_commit = "" -last_updated = "2026-03-02T19:29:42" +last_updated = "2026-03-02T19:55:24" history = [] diff --git a/tests/conftest.py b/tests/conftest.py index f04e896..9f9cbef 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,11 +8,13 @@ import sys import datetime from pathlib import Path from typing import Generator, Any +from unittest.mock import patch, MagicMock # Ensure project root is in path sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) import ai_client +from gui_2 import App @pytest.fixture(autouse=True) def reset_ai_client() -> Generator[None, None, None]: @@ -22,6 +24,43 @@ def reset_ai_client() -> Generator[None, None, None]: ai_client.set_provider("gemini", "gemini-2.5-flash-lite") yield +@pytest.fixture +def app_instance() -> Generator[App, None, None]: + """ + Centralized App instance with all external side effects mocked. + Matches the pattern used in test_token_viz.py and test_gui_phase4.py. + """ + with ( + patch('gui_2.load_config', return_value={ + 'ai': {'provider': 'gemini', 'model': 'gemini-2.5-flash-lite'}, + 'projects': {'paths': [], 'active': ''}, + 'gui': {'show_windows': {}} + }), + patch('gui_2.save_config'), + patch('gui_2.project_manager'), + patch('gui_2.session_logger'), + patch('gui_2.immapp.run'), + patch.object(App, '_load_active_project'), + patch.object(App, '_fetch_models'), + patch.object(App, '_load_fonts'), + patch.object(App, '_post_init'), + patch.object(App, '_prune_old_logs'), + patch.object(App, '_init_ai_and_hooks') + ): + app = App() + yield app + # Cleanup: Ensure asyncio loop is stopped + if hasattr(app, '_loop') and app._loop.is_running(): + app._loop.call_soon_threadsafe(app._loop.stop) + +@pytest.fixture +def mock_app(app_instance: App) -> App: + """ + Simpler fixture returning a mocked App instance. + Reuses app_instance for automatic cleanup and consistent mocking. + """ + return app_instance + class VerificationLogger: """High-signal reporting for automated tests, inspired by Unreal Engine's diagnostic style.""" def __init__(self, test_name: str, script_name: str):