This commit is contained in:
@@ -3,7 +3,8 @@ from dataclasses import replace
|
||||
from test_config import settings
|
||||
|
||||
from lai_automation.git import ChangeSummary
|
||||
from lai_automation.policy import evaluate_changes
|
||||
from lai_automation.models import FailureReport
|
||||
from lai_automation.policy import evaluate_changes, evaluate_report_scope
|
||||
|
||||
|
||||
def test_policy_accepts_small_application_change() -> None:
|
||||
@@ -52,3 +53,33 @@ def test_policy_rejects_symlinks(tmp_path) -> None:
|
||||
(tmp_path / "link.php").symlink_to("/etc/passwd")
|
||||
result = evaluate_changes(ChangeSummary(("link.php",), 1, 0), settings(), tmp_path)
|
||||
assert not result.allowed
|
||||
|
||||
|
||||
def test_cross_database_report_requires_application_orchestration() -> None:
|
||||
report = FailureReport(
|
||||
id=56,
|
||||
chat_message_id=1,
|
||||
source="user_feedback",
|
||||
category="incorrect_answer",
|
||||
user_feedback="Use cockpit_config.time_registration",
|
||||
feedback_type="wrong_result",
|
||||
expected_behavior="Join cockpit_config manager_id and FK_AuftragPos",
|
||||
prompt="Hours in April",
|
||||
response="0 hours",
|
||||
sql_query="SELECT 0",
|
||||
error_message=None,
|
||||
context={},
|
||||
)
|
||||
|
||||
rejected = evaluate_report_scope(
|
||||
report,
|
||||
ChangeSummary(("config/erp_semantics.php", "tests/Unit/FixTest.php"), 20, 2),
|
||||
)
|
||||
accepted = evaluate_report_scope(
|
||||
report,
|
||||
ChangeSummary(("app/Http/Controllers/ChatController.php", "tests/Unit/FixTest.php"), 20, 2),
|
||||
)
|
||||
|
||||
assert not rejected.allowed
|
||||
assert "staged orchestration" in rejected.errors[0]
|
||||
assert accepted.allowed
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import threading
|
||||
from pathlib import Path
|
||||
from unittest.mock import Mock, patch
|
||||
from unittest.mock import MagicMock, Mock, patch
|
||||
|
||||
from test_config import settings
|
||||
|
||||
@@ -44,6 +44,7 @@ def test_stop_signal_interrupts_worker_wait() -> None:
|
||||
|
||||
def test_database_credentials_are_only_passed_to_test_process() -> None:
|
||||
worker = AutomationWorker(settings())
|
||||
worker._prepare_test_schema = Mock()
|
||||
workspace = Mock()
|
||||
workspace.run.return_value = Mock(returncode=0, stdout="ok", stderr="")
|
||||
|
||||
@@ -61,8 +62,25 @@ def test_database_credentials_are_only_passed_to_test_process() -> None:
|
||||
assert environment["COCKPIT_CONFIG_DATABASE"] == "cockpit_agent_test"
|
||||
|
||||
|
||||
def test_test_schema_creates_minimal_erp_lookup(monkeypatch) -> None:
|
||||
worker = AutomationWorker(settings())
|
||||
cursor = Mock()
|
||||
connection = MagicMock()
|
||||
connection.cursor.return_value.__enter__.return_value = cursor
|
||||
connect = Mock(return_value=connection)
|
||||
monkeypatch.setattr("lai_automation.worker.pymysql.connect", connect)
|
||||
|
||||
worker._prepare_test_schema()
|
||||
|
||||
assert connect.call_args.kwargs["database"] == "customer_agent_test"
|
||||
assert "CREATE TABLE IF NOT EXISTS FK_Nummerkreis" in cursor.execute.call_args.args[0]
|
||||
assert cursor.executemany.call_args.args[1][0] == (3, "Rechnung", "RG")
|
||||
connection.close.assert_called_once()
|
||||
|
||||
|
||||
def test_validation_commands_are_logged_without_output(caplog) -> None:
|
||||
worker = AutomationWorker(settings())
|
||||
worker._prepare_test_schema = Mock()
|
||||
workspace = Mock()
|
||||
workspace.run.return_value = Mock(returncode=0, stdout="sensitive output", stderr="")
|
||||
|
||||
@@ -76,6 +94,7 @@ def test_validation_commands_are_logged_without_output(caplog) -> None:
|
||||
|
||||
def test_failed_validation_preserves_start_and_end_of_long_output() -> None:
|
||||
worker = AutomationWorker(settings())
|
||||
worker._prepare_test_schema = Mock()
|
||||
workspace = Mock()
|
||||
workspace.run.return_value = Mock(
|
||||
returncode=1,
|
||||
|
||||
Reference in New Issue
Block a user