Private
Public Access
0
0
Files
manual_slop/tests/test_phase6_engine.py
T
ed 8f11340b38 refactor(consumers): migrate 85 'from src.models import' sites to direct subsystem imports
Per post_module_taxonomy_de_cruft_20260627 Phase 2 (FR7). Each
'from src.models import X' for a moved class is rewritten to
'from src.<destination> import X':

  Ticket, Track, WorkerContext, TrackState, TrackMetadata,
    ThinkingSegment, EMPTY_TRACK_STATE            -> src.mma
  ProjectContext, ProjectMeta, ProjectOutput, ProjectFiles,
    ProjectScreenshots, ProjectDiscussion, EMPTY_PROJECT_CONTEXT -> src.project
  FileItem, Preset, ContextPreset, ContextFileEntry,
    NamedViewPreset                                -> src.project_files
  Tool, ToolPreset                                 -> src.tool_presets
  BiasProfile                                      -> src.tool_bias
  TextEditorConfig, ExternalEditorConfig,
    EMPTY_TEXT_EDITOR_CONFIG                       -> src.external_editor
  Persona                                          -> src.personas
  WorkspaceProfile                                -> src.workspace_manager
  MCPServerConfig, MCPConfiguration, VectorStoreConfig,
    RAGConfig, load_mcp_config                      -> src.mcp_client

NOT touched (kept on src.models; Phase 3 or Phase 4 will move them):
  GenerateRequest, ConfirmRequest, DEFAULT_TOOL_CATEGORIES, Metadata, PROVIDERS

Migration was performed by the one-time script
scripts/tier2/artifacts/post_module_taxonomy_de_cruft_20260627/migrate_imports.py
which uses a class-to-module map and re.sub() to rewrite each
'from src.models import X' line.

Total: 85 import lines rewritten across 71 files.

Note: this commit depends on the v2 SHIPPED work
(origin/tier2/module_taxonomy_refactor_20260627) being merged into
this branch NEXT. On master (without the v2 SHIPPED commits), the
destination modules do not exist and these imports would fail.
2026-06-26 13:34:03 -04:00

87 lines
3.3 KiB
Python

from unittest.mock import MagicMock, patch
from src.multi_agent_conductor import ConductorEngine, run_worker_lifecycle
from src.mma import Ticket, Track, WorkerContext
from src import ai_client
from src.result_types import Result
def test_worker_streaming_intermediate():
ticket = Ticket(id="T-001", description="Test", status="todo", assigned_to="worker")
context = WorkerContext(ticket_id="T-001", model_name="test-model", messages=[])
event_queue = MagicMock()
with (
patch("src.ai_client.send") as mock_send,
patch("src.multi_agent_conductor._queue_put") as mock_q_put,
patch("src.multi_agent_conductor.confirm_spawn", return_value=(True, "p", "c")),
patch("src.ai_client.reset_session"),
patch("src.ai_client.set_provider"),
patch("src.ai_client.get_provider"),
patch("src.ai_client.get_comms_log", return_value=[])
):
def side_effect(*args, **kwargs):
cb = ai_client.comms_log_callback
if cb:
cb({"kind": "tool_call", "payload": {"name": "test_tool", "script": "echo hello"}})
cb({"kind": "tool_result", "payload": {"name": "test_tool", "output": "hello"}})
return Result(data="DONE")
mock_send.side_effect = side_effect
run_worker_lifecycle(ticket, context, event_queue=event_queue)
# _queue_put(event_queue, event_name, payload)
responses = [call.args[2] for call in mock_q_put.call_args_list if call.args[1] == "response"]
assert any("[TOOL CALL]" in r.get("text", "") for r in responses)
assert any("[TOOL RESULT]" in r.get("text", "") for r in responses)
def test_per_tier_model_persistence():
# Mock UI frameworks before importing gui_2
mock_imgui = MagicMock()
with patch.dict("sys.modules", {
"imgui_bundle": MagicMock(),
"imgui_bundle.imgui": mock_imgui,
"imgui_bundle.hello_imgui": MagicMock(),
"imgui_bundle.immapp": MagicMock(),
}):
from src.gui_2 import App
with (
patch("src.gui_2.project_manager.load_project", return_value={}),
patch("src.gui_2.project_manager.migrate_from_legacy_config", return_value={}),
patch("src.gui_2.project_manager.save_project"),
patch("src.app_controller.AppController.save_config"),
patch("src.gui_2.theme.load_from_config"),
patch("src.gui_2.ai_client.set_provider"),
patch("src.gui_2.ai_client.list_models", return_value=["gpt-4", "claude-3"]),
patch("src.performance_monitor.PerformanceMonitor"),
patch("src.gui_2.api_hooks.HookServer"),
patch("src.gui_2.session_logger.open_session"),
patch("src.gui_2.session_logger.reset_session")
):
app = App()
app.controller.available_models = ["gpt-4", "claude-3"]
tier = "Tier 3"
model = "claude-3"
# Simulate 'Tier Model Config' UI logic
app.controller.mma_tier_usage[tier]["model"] = model
app.controller.project.setdefault("mma", {}).setdefault("tier_models", {})[tier] = model
assert app.controller.project["mma"]["tier_models"][tier] == model
def test_retry_escalation():
# This test verifies the retry escalation logic works
# We test the core concept: when a ticket is blocked, retry_count should increment
ticket = Ticket(id="T-001", description="Test", status="todo", assigned_to="worker")
# Simulate what happens when a ticket gets blocked
ticket.status = "blocked"
ticket.retry_count += 1
assert ticket.status == "blocked"
assert ticket.retry_count == 1
# Verify escalation can happen
assert ticket.retry_count < 2 # Should be eligible for retry