Files
AIPass/src/aipass/trigger/tests/test_startup_handler.py
T
PatrickandClaude Opus 4.6 44bab11040 fix(memory): remove rollover from startup chain + add sentence-transformers dep
Two fixes:

1. Remove _run_memory_check() from trigger startup handler — rollover no
   longer fires on every drone command. Rollover is now on-demand only
   (drone @memory rollover) or via the watcher daemon. This eliminates the
   noisy "Memory - Rollover Execution" banner from every drone invocation.

2. Add sentence-transformers>=2.0 to pyproject.toml [memory] extras — the
   embedding subprocess was failing because torch/sentence-transformers
   were missing from the dependency list. chromadb alone is insufficient;
   the custom embed_subprocess.py requires sentence-transformers directly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-02 18:55:15 -07:00

83 lines
2.6 KiB
Python

# =================== AIPass ====================
# Name: test_startup_handler.py
# Description: Tests for startup event handler
# Version: 1.0.0
# Created: 2026-04-25
# Modified: 2026-04-25
# =============================================
"""Tests for startup event handler."""
import pytest
from unittest.mock import MagicMock
from pathlib import Path
@pytest.fixture(autouse=True)
def _mock_infrastructure(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
"""Mock heavy infrastructure imports before importing the handler module."""
import sys
from aipass.trigger.apps.config import atomic_write_json
mock_config = MagicMock()
mock_config.TRIGGER_ROOT = tmp_path
mock_config.atomic_write_json = atomic_write_json
monkeypatch.setitem(sys.modules, "aipass.trigger.apps.config", mock_config)
mock_json_handler = MagicMock()
mock_json_handler.log_operation = MagicMock(return_value=True)
json_pkg = MagicMock()
json_pkg.json_handler = mock_json_handler
monkeypatch.setitem(sys.modules, "aipass.trigger.apps.handlers.json", json_pkg)
monkeypatch.setitem(
sys.modules,
"aipass.trigger.apps.handlers.json.json_handler",
mock_json_handler,
)
monkeypatch.delitem(
sys.modules,
"aipass.trigger.apps.handlers.events.startup",
raising=False,
)
def _import_startup():
"""Import fresh after mocking."""
import aipass.trigger.apps.handlers.events.startup as m
return m
class TestHandleStartup:
"""Tests for handle_startup."""
def test_calls_error_catchup_with_fire_event(self) -> None:
"""Passes fire_event kwarg to _run_error_catchup."""
mod = _import_startup()
mod._run_error_catchup = MagicMock()
fire_event = MagicMock()
mod.handle_startup(fire_event=fire_event)
mod._run_error_catchup.assert_called_once_with(fire_event) # type: ignore[union-attr]
def test_passes_none_when_no_fire_event(self) -> None:
"""Without fire_event kwarg, passes None to error catchup."""
mod = _import_startup()
mod._run_error_catchup = MagicMock()
mod.handle_startup()
mod._run_error_catchup.assert_called_once_with(None) # type: ignore[union-attr]
def test_extra_kwargs_do_not_crash(self) -> None:
"""Arbitrary extra kwargs are silently ignored."""
mod = _import_startup()
mod._run_error_catchup = MagicMock()
mod.handle_startup(fire_event=MagicMock(), extra_arg="ignored", count=42)
mod._run_error_catchup.assert_called_once() # type: ignore[union-attr]