Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ovoscope/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import inspect
import dataclasses
import gc
import json
import threading
from copy import deepcopy
from time import sleep, time
from typing import Union, List, Dict, Any, Optional

Check failure on line 8 in ovoscope/__init__.py

View workflow job for this annotation

GitHub Actions / lint / lint

ruff (UP035)

ovoscope/__init__.py:8:1: UP035 `typing.Dict` is deprecated, use `dict` instead

Check failure on line 8 in ovoscope/__init__.py

View workflow job for this annotation

GitHub Actions / lint / lint

ruff (UP035)

ovoscope/__init__.py:8:1: UP035 `typing.List` is deprecated, use `list` instead

from ovos_bus_client.message import Message
from ovos_bus_client.session import SessionManager, Session
from ovos_config.config import Configuration
from ovos_config.models import LocalConf
from ovos_core.intent_services import IntentService

Check failure on line 14 in ovoscope/__init__.py

View workflow job for this annotation

GitHub Actions / lint / lint

ruff (F401)

ovoscope/__init__.py:14:39: F401 `ovos_core.intent_services.IntentService` imported but unused help: Remove unused import: `ovos_core.intent_services.IntentService`
from ovos_core.skill_manager import SkillManager
from ovos_plugin_manager.skills import find_skill_plugins
from ovos_utils.fakebus import FakeBus
Expand All @@ -21,8 +21,8 @@
from ovos_workshop.skills.api import SkillApi
from ovos_workshop.skills.ovos import OVOSSkill

Check failure on line 22 in ovoscope/__init__.py

View workflow job for this annotation

GitHub Actions / lint / lint

ruff (I001)

ovoscope/__init__.py:1:1: I001 Import block is un-sorted or un-formatted help: Organize imports

SerializedMessage = Dict[str, Union[str, Dict[str, Any]]]

Check failure on line 24 in ovoscope/__init__.py

View workflow job for this annotation

GitHub Actions / lint / lint

ruff (UP006)

ovoscope/__init__.py:24:42: UP006 Use `dict` instead of `Dict` for type annotation help: Replace with `dict`

Check failure on line 24 in ovoscope/__init__.py

View workflow job for this annotation

GitHub Actions / lint / lint

ruff (UP007)

ovoscope/__init__.py:24:31: UP007 Use `X | Y` for type annotations help: Convert to `X | Y`

Check failure on line 24 in ovoscope/__init__.py

View workflow job for this annotation

GitHub Actions / lint / lint

ruff (UP006)

ovoscope/__init__.py:24:21: UP006 Use `dict` instead of `Dict` for type annotation help: Replace with `dict`
SerializedTest = Dict[str, Union[str, bool, List[str], SerializedMessage]]

Check failure on line 25 in ovoscope/__init__.py

View workflow job for this annotation

GitHub Actions / lint / lint

ruff (UP006)

ovoscope/__init__.py:25:45: UP006 Use `list` instead of `List` for type annotation help: Replace with `list`

Check failure on line 25 in ovoscope/__init__.py

View workflow job for this annotation

GitHub Actions / lint / lint

ruff (UP007)

ovoscope/__init__.py:25:28: UP007 Use `X | Y` for type annotations help: Convert to `X | Y`

Check failure on line 25 in ovoscope/__init__.py

View workflow job for this annotation

GitHub Actions / lint / lint

ruff (UP006)

ovoscope/__init__.py:25:18: UP006 Use `dict` instead of `Dict` for type annotation help: Replace with `dict`

DEFAULT_IGNORED = ["ovos.skills.settings_changed"]
GUI_IGNORED = ["gui.clear.namespace",
Expand Down Expand Up @@ -978,7 +978,10 @@
)
sleep(0.1)
return croft
except Exception:
except BaseException:
# pytest-timeout's Failed and KeyboardInterrupt derive from
# BaseException, not Exception; catching only Exception here let
# them skip cleanup and leak the started MiniCroft process.
croft.stop()
raise

Expand Down
13 changes: 13 additions & 0 deletions test/unittests/test_minicroft.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Unit tests for MiniCroft and get_minicroft()."""
import threading
import unittest
from unittest.mock import patch

from ovos_bus_client.message import Message
from ovos_spec_tools import SpecMessage
Expand Down Expand Up @@ -83,6 +84,18 @@ def test_returns_minicroft_instance(self):
finally:
mc.stop()

def test_basedexception_during_boot_still_stops_croft(self):
"""A BaseException (e.g. pytest-timeout's Failed, or a real
KeyboardInterrupt) raised while waiting for READY must still trigger
croft.stop() before propagating. Regression test for get_minicroft's
cleanup handler only catching `Exception`, which let BaseException
subclasses skip cleanup and leak the started MiniCroft process."""
with patch.object(MiniCroft, "start", side_effect=KeyboardInterrupt), \
patch.object(MiniCroft, "stop") as mock_stop:
with self.assertRaises(KeyboardInterrupt):
get_minicroft([])
mock_stop.assert_called_once()


class TestMiniCroftSessionManagerBusRestore(unittest.TestCase):
"""MiniCroft must not leak its FakeBus into the process-wide
Expand Down
Loading