From 76e983fbd2d19e66886455690e7a5ddec8b1b66a Mon Sep 17 00:00:00 2001 From: miro Date: Mon, 17 Jun 2024 04:32:34 +0100 Subject: [PATCH] common_qa blacklist tests --- .github/workflows/coverage.yml | 1 + .github/workflows/unit_tests.yml | 1 + test/end2end/minicroft.py | 2 + test/end2end/session/test_blacklist.py | 91 ++++++++++++++++++++ test/end2end/skill-ovos-fakewiki/__init__.py | 14 +++ test/end2end/skill-ovos-fakewiki/setup.py | 23 +++++ 6 files changed, 132 insertions(+) create mode 100644 test/end2end/skill-ovos-fakewiki/__init__.py create mode 100755 test/end2end/skill-ovos-fakewiki/setup.py diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 3eaee7eb7e3e..2a43a2e23be1 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -33,6 +33,7 @@ jobs: pip install ./test/end2end/skill-old-stop pip install ./test/end2end/skill-fake-fm pip install ./test/end2end/skill-fake-fm-legacy + pip install ./test/end2end/skill-ovos-fakewiki pip install ./test/end2end/metadata-test-plugin - name: Install core repo run: | diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 5ef94d4d1c31..9f687c7e3931 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -60,6 +60,7 @@ jobs: pip install ./test/end2end/skill-old-stop pip install ./test/end2end/skill-fake-fm pip install ./test/end2end/skill-fake-fm-legacy + pip install ./test/end2end/skill-ovos-fakewiki pip install ./test/end2end/metadata-test-plugin - name: Install core repo run: | diff --git a/test/end2end/minicroft.py b/test/end2end/minicroft.py index cdc8d81972aa..118c21d346d6 100644 --- a/test/end2end/minicroft.py +++ b/test/end2end/minicroft.py @@ -10,6 +10,8 @@ from ovos_utils.process_utils import ProcessState from ovos_workshop.skills.fallback import FallbackSkill +LOG.set_level("DEBUG") + class MiniCroft(SkillManager): def __init__(self, skill_ids, *args, **kwargs): diff --git a/test/end2end/session/test_blacklist.py b/test/end2end/session/test_blacklist.py index 70209b039bfc..78743591ffda 100644 --- a/test/end2end/session/test_blacklist.py +++ b/test/end2end/session/test_blacklist.py @@ -388,3 +388,94 @@ def wait_for_n_messages(n): for idx, m in enumerate(messages): self.assertEqual(m.msg_type, expected_messages[idx]) + +class TestCommonQuery(TestCase): + + def setUp(self): + self.skill_id = "ovos-skill-fakewiki.openvoiceos" + self.core = get_minicroft(self.skill_id) + # self.core.intent_service.common_qa.common_query_skills = [self.skill_id] + + def tearDown(self) -> None: + self.core.stop() + + def test_common_qa(self): + SessionManager.sessions = {} + SessionManager.default_session = SessionManager.sessions["default"] = Session("default") + SessionManager.default_session.lang = "en-us" + SessionManager.default_session.pipeline = ["common_qa"] + messages = [] + + def new_msg(msg): + nonlocal messages + m = Message.deserialize(msg) + if m.msg_type in ["ovos.skills.settings_changed", + "ovos.common_play.status"]: + return # skip these, only happen in 1st run + messages.append(m) + print(len(messages), msg) + + def wait_for_n_messages(n): + nonlocal messages + t = time.time() + while len(messages) < n: + sleep(0.1) + if time.time() - t > 10: + raise RuntimeError("did not get the number of expected messages under 10 seconds") + + self.core.bus.on("message", new_msg) + + sess = Session("123", + blacklisted_skills=[], + pipeline=["common_qa"]) + utt = Message("recognizer_loop:utterance", + {"utterances": ["what is the speed of light"]}, + {"session": sess.serialize()}) + self.core.bus.emit(utt) + + # confirm all expected messages are sent + expected_messages = [ + "recognizer_loop:utterance", + "enclosure.mouth.think", + "question:query", + "question:query.response", # searching + "question:query.response", # response + "enclosure.mouth.reset", + "question:action", + "intent.service.skills.activate", + "intent.service.skills.activated", + f"{self.skill_id}.activate", + "enclosure.active_skill", + "speak", # answer + "enclosure.active_skill", + "speak", # callback + "mycroft.skill.handler.complete", + "ovos.utterance.handled" + ] + wait_for_n_messages(len(expected_messages)) + + self.assertEqual(len(expected_messages), len(messages)) + + for idx, m in enumerate(messages): + self.assertEqual(m.msg_type, expected_messages[idx]) + + messages = [] + sess.blacklisted_skills = [self.skill_id] + utt = Message("recognizer_loop:utterance", + {"utterances": ["invalid"]}, + {"session": sess.serialize()}) + self.core.bus.emit(utt) + + # confirm intent failure + expected_messages = [ + "recognizer_loop:utterance", + "mycroft.audio.play_sound", + "complete_intent_failure", + "ovos.utterance.handled" + ] + wait_for_n_messages(len(expected_messages)) + + self.assertEqual(len(expected_messages), len(messages)) + + for idx, m in enumerate(messages): + self.assertEqual(m.msg_type, expected_messages[idx]) diff --git a/test/end2end/skill-ovos-fakewiki/__init__.py b/test/end2end/skill-ovos-fakewiki/__init__.py new file mode 100644 index 000000000000..2ca23a259678 --- /dev/null +++ b/test/end2end/skill-ovos-fakewiki/__init__.py @@ -0,0 +1,14 @@ +from ovos_workshop.skills.common_query_skill import CommonQuerySkill, CQSMatchLevel + + +class UnWikiSkill(CommonQuerySkill): + + # common query integration + def CQS_match_query_phrase(self, utt): + response = "42" + return (utt, CQSMatchLevel.EXACT, response, + {'query': utt, 'answer': response}) + + def CQS_action(self, phrase, data): + """ If selected show gui """ + self.speak("selected") diff --git a/test/end2end/skill-ovos-fakewiki/setup.py b/test/end2end/skill-ovos-fakewiki/setup.py new file mode 100755 index 000000000000..e38e6177b5bc --- /dev/null +++ b/test/end2end/skill-ovos-fakewiki/setup.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +from setuptools import setup + +# skill_id=package_name:SkillClass +PLUGIN_ENTRY_POINT = 'ovos-skill-fakewiki.openvoiceos=ovos_skill_fakewiki:UnWikiSkill' + +setup( + # this is the package name that goes on pip + name='ovos-skill-fakewiki', + version='0.0.1', + description='this is a OVOS test skill for the common query framework', + url='https://github.com/OpenVoiceOS/ovos-core', + author='JarbasAi', + author_email='jarbasai@mailfence.com', + license='Apache-2.0', + package_dir={"ovos_skill_fakewiki": ""}, + package_data={'ovos_skill_fakewiki': ['locale/*']}, + packages=['ovos_skill_fakewiki'], + include_package_data=True, + install_requires=["ovos-workshop"], + keywords='ovos skill plugin', + entry_points={'ovos.plugin.skill': PLUGIN_ENTRY_POINT} +)