fix(i-e): BUG-099 geschlossen — tote workstream-Tests entfernt, Import-Test korrigiert

app.ai.agent_workstream und app.workflows.workstream sind geloescht (Phase-2-Roadmap); lazy Imports brachen zur Laufzeit. Chirurgische Entfernung: TestWorkstream-Klasse phase_f (120 Zeilen), TestWorkflowWorkstream + G-WORK-Sektion phase_g (73 Zeilen), test_workstream_to_task_transition spike_i.

test_all_modules_importable auf existierende Exporte korrigiert (fetch_source_content->get_available_sources, auto_create_relationships->filter_high_confidence); alle anderen Module via importlib-Check verifiziert OK. ruff: 21 Findings auto-gefixt, 1 F841-Vorbestand belassen.

Beweis: phase_f+phase_g+spike_i 88/88 passed in 19.16s; to_workstream_block()-Tests bleiben valide (existiert in app.ai.knowledge_sources).
This commit is contained in:
Agent Zero
2026-08-25 22:02:59 +02:00
parent 9e1d202610
commit df9f86bd12
3 changed files with 16 additions and 242 deletions
+2 -125
View File
@@ -17,17 +17,15 @@ Covers:
from __future__ import annotations
import asyncio
import json
import uuid
from dataclasses import dataclass, field
from datetime import UTC, datetime
from typing import Any
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from app.ai.agent_loop import ReActResult, ReActStep, run_react_loop
from app.ai.agent_loop import run_react_loop
from app.ai.agent_permissions import (
AgentPermissionContext,
check_agent_execute_permission,
@@ -37,7 +35,7 @@ from app.ai.agent_permissions import (
)
from app.ai.context_builder import ReActSystemPromptBuilder, build_agent_context
from app.ai.data_policy import enforce_data_policy
from app.ai.skill_registry import SkillDefinition, SkillRegistry, get_skill_registry
from app.ai.skill_registry import SkillDefinition, get_skill_registry
from app.ai.transparency import is_ai_participant, mark_as_ai_generated
from app.core.approval import (
ApprovalRequest,
@@ -47,7 +45,6 @@ from app.core.approval import (
)
from app.core.error_codes import ApiError
# ──────────────────────────────────────────────────────────────────────────
# No-op overrides of conftest DB fixtures — these tests use mocks only
# ──────────────────────────────────────────────────────────────────────────
@@ -1204,126 +1201,6 @@ class TestTransparency:
assert is_ai_participant("u2", "human") is False
# ══════════════════════════════════════════════════════════════════════════
# 8. Workstream tests
# ══════════════════════════════════════════════════════════════════════════
class TestWorkstream:
@pytest.mark.asyncio
async def test_post_agent_message_creates_message(self, tenant_id, mock_db):
"""post_agent_message calls send_message and returns the message ID."""
agent_id = uuid.uuid4()
run_id = uuid.uuid4()
conv_id = uuid.uuid4()
message_id = uuid.uuid4()
with patch(
"app.plugins.builtins.kommunikation.services.send_message",
new_callable=AsyncMock,
) as mock_send:
mock_send.return_value = message_id
with patch(
"app.ai.agent_workstream._get_or_create_agent_channel",
new_callable=AsyncMock,
) as mock_channel:
mock_channel.return_value = conv_id
from app.ai.agent_workstream import post_agent_message
result = await post_agent_message(
mock_db,
tenant_id,
agent_id,
run_id,
"Hello from agent",
)
assert result == message_id
mock_send.assert_awaited_once()
call_kwargs = mock_send.await_args.kwargs
assert call_kwargs["sender_type"] == "agent"
assert call_kwargs["sender_id"] == agent_id
assert call_kwargs["conversation_id"] == conv_id
assert call_kwargs["content"] == "Hello from agent"
# AI-generated metadata attached
assert call_kwargs["metadata"]["ai_generated"] is True
@pytest.mark.asyncio
async def test_post_agent_step_creates_action_card(self, tenant_id, mock_db):
"""post_agent_step creates an action_card message."""
agent_id = uuid.uuid4()
run_id = uuid.uuid4()
message_id = uuid.uuid4()
with patch(
"app.plugins.builtins.kommunikation.services.send_message",
new_callable=AsyncMock,
) as mock_send:
mock_send.return_value = message_id
with patch(
"app.ai.agent_workstream._get_or_create_agent_channel",
new_callable=AsyncMock,
) as mock_channel:
mock_channel.return_value = uuid.uuid4()
from app.ai.agent_workstream import post_agent_step
result = await post_agent_step(
mock_db,
tenant_id,
agent_id,
run_id,
step_number=1,
thought="Thinking...",
action="search",
observation="Found 3",
)
assert result == message_id
call_kwargs = mock_send.await_args.kwargs
assert call_kwargs["blocks"][0]["type"] == "action_card"
assert call_kwargs["blocks"][0]["data"]["step_number"] == 1
assert call_kwargs["blocks"][0]["data"]["action"] == "search"
@pytest.mark.asyncio
async def test_post_agent_result_includes_cost_and_status(self, tenant_id, mock_db):
"""post_agent_result includes cost and status in block data."""
agent_id = uuid.uuid4()
run_id = uuid.uuid4()
message_id = uuid.uuid4()
with patch(
"app.plugins.builtins.kommunikation.services.send_message",
new_callable=AsyncMock,
) as mock_send:
mock_send.return_value = message_id
with patch(
"app.ai.agent_workstream._get_or_create_agent_channel",
new_callable=AsyncMock,
) as mock_channel:
mock_channel.return_value = uuid.uuid4()
from app.ai.agent_workstream import post_agent_result
result = await post_agent_result(
mock_db,
tenant_id,
agent_id,
run_id,
final_content="Done",
total_cost_usd=0.123456,
steps_taken=4,
status="completed",
)
assert result == message_id
call_kwargs = mock_send.await_args.kwargs
assert call_kwargs["content"] == "Done"
block_data = call_kwargs["blocks"][0]["data"]
assert block_data["status"] == "completed"
assert block_data["steps_taken"] == 4
assert block_data["total_cost_usd"] == pytest.approx(0.123456)
assert block_data["run_id"] == str(run_id)
# ══════════════════════════════════════════════════════════════════════════
# 9. Budget limit tests
# ══════════════════════════════════════════════════════════════════════════