Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

10.9 KB
Raw Blame
"""Unit tests for ``dodaios.skills.authoring_request``.

The resolver states one rule: when the user asks to CREATE a skill, every
service they name is the skill's CONTENT, never a command — so a brand
mentioned inside the request must not capture the turn. Precision over
recall: every entry in the "misses" section is a hard negative.

Lightweight fakes, no ``unittest.mock`` (AGENTS.md testing convention).
"""
from __future__ import annotations

from dataclasses import dataclass, field

import pytest

from dodaios.skills.authoring_request import (
    AUTHORING_SKILL_NAME,
    is_skill_authoring_request,
    is_skill_lifecycle_request,
    resolve_skill_authoring_request,
    skill_meta_kind,
)
from dodaios.skills.match_eval import BAND_FIRE, BAND_NONE, SOURCE_TRIGGER


@dataclass
class _FakeSkill:
    name: str
    frontmatter: object | None = None
    state: str = "validated"
    body: str = ""
    resources: dict = field(default_factory=dict)


class _FakeRegistry:
    def __init__(self, names: list[str]) -> None:
        self._skills = [_FakeSkill(name=n) for n in names]

    def list_active(self) -> list[_FakeSkill]:
        return list(self._skills)


#: The exact transcript of the 2026-08-18 17:51 voice turn that this module
#: exists for — verbatim, filler words and misheard "Lenya Tickets" included.
LIVE_UTTERANCE = (
    "Ich möchte, dass du mich bitte einen neuen Skill erstellst und zwar morgen "  # i18n-allow: transcript
    "routine, der soll immer unter früh um 6 Uhr ähm ähm getriggert werden, "  # i18n-allow: transcript
    "gesetzt wird jeden Morgen um 6 Uhr, wo all meine E-Mails, Lenya Tickets und "  # i18n-allow: transcript
    "ähm alle wichtigen Kalendereinträge ähm abgespielt werden und dann ein "  # i18n-allow: transcript
    "schönes Lied abgespielt wird mit YouTube Music zum Aufstehen und zwar ein "  # i18n-allow: transcript
    "Klassiker aus den 80er, wie Country Road oder so ETC immer was neues."  # i18n-allow: transcript
)


# ---------------------------------------------------------------------------
# Hits — the request is an authoring request
# ---------------------------------------------------------------------------


@pytest.mark.parametrize(
    "utterance",
    [
        LIVE_UTTERANCE,
        "erstell mir einen skill der abends das licht dimmt",  # i18n-allow: test input
        "bau mir bitte einen neuen skill für die morgenroutine",  # i18n-allow: test input
        "kannst du einen skill erstellen der jeden morgen meine mails vorliest",  # i18n-allow: test input
        "leg einen neuen skill an: fokusmodus",  # i18n-allow: test input
        "mach aus diesem workflow einen skill",  # i18n-allow: test input
        "erstell skill morgenroutine",  # i18n-allow: test input
        "Skill erstellen: Abendroutine mit Spotify",  # i18n-allow: test input
        "dass er einen skill erstellt der abends das licht dimmt",  # i18n-allow: test input
        "create a skill that reads my calendar every morning",
        "turn this into a skill",
        "make me a new skill for the evening",
        "set up a skill for my monday review",
        "crea un skill que lea mi correo",  # i18n-allow: test input
        # the product's synonyms for "a skill" — one word away from the live bug
        "erstell mir eine morgenroutine für 6 uhr",  # i18n-allow: test input
        "leg eine abendroutine an, die spotify leise dreht",  # i18n-allow: test input
        "bau mir eine automatisierung die jeden montag slack zusammenfasst",  # i18n-allow: test input
        "erstell mir einen workflow der abends die tickets zusammenfasst",  # i18n-allow: test input
        "create a routine that reads my calendar",
        "crea una rutina que lea mi correo",  # i18n-allow: test input
        "cria-me um skill que leia o meu correio",  # i18n-allow: test input
        "cria uma rotina que resuma o slack às segundas",  # i18n-allow: test input
        "quero que construas uma nova automatização para os emails",  # i18n-allow: test input
        "cria uma skill que leia o meu calendário",  # i18n-allow: test input
        "cria um skill que leia o meu correio",  # i18n-allow: test input
        "cria um workflow para os relatórios",  # i18n-allow: test input
        "faz-me um workflow que resuma as tarefas",  # i18n-allow: test input
    ],
)
def test_authoring_requests_are_detected(utterance: str) -> None:
    assert is_skill_authoring_request(utterance) is True


# ---------------------------------------------------------------------------
# Misses — hard negatives that must never resolve
# ---------------------------------------------------------------------------


@pytest.mark.parametrize(
    "utterance",
    [
        # run / use / toggle / delete an existing skill
        "nutz den skill morning-routine bitte",  # i18n-allow: test input
        "starte den skill deep-work-mode",  # i18n-allow: test input
        "mach den skill deep-work-mode aus",  # i18n-allow: test input
        "lösch den skill abendroutine",  # i18n-allow: test input
        "starte den skill den du gestern erstellt hast",  # i18n-allow: test input
        "run the skill I created yesterday",
        # questions about skills
        "welche skills habe ich",  # i18n-allow: test input
        "wie erstelle ich einen skill",  # i18n-allow: test input
        "was ist ein skill",  # i18n-allow: test input
        "how do I create a skill?",
        # the skills only in a genitive / "of my" — a request ABOUT skills
        "erstell mir eine übersicht meiner skills",  # i18n-allow: test input
        "erstell mir eine liste aller skills",  # i18n-allow: test input
        "make a list of my skills",
        # no skill word at all — ordinary domain requests stay with their skills
        "erstell mir eine mail an das team",  # i18n-allow: test input
        "spiel musik auf youtube music",  # i18n-allow: test input
        "schreib eine mail an das team",  # i18n-allow: test input
        # a routine RUN or a routine mentioned, not created
        "starte die morgenroutine",  # i18n-allow: test input
        "was steht heute in meiner routine",  # i18n-allow: test input
        "erinnere mich an meine routine",  # i18n-allow: test input
        "como crio um skill",  # i18n-allow: test input
        "cria uma lista dos meus skills",  # i18n-allow: test input
        "kümmere dich um die skills",  # i18n-allow: test input
        # German "um" is a preposition, never the Portuguese article
        "Schreib mir, was ich tun muss, um Skills zu aktivieren",  # i18n-allow: test input
        "Mach das, um Workflows zu starten",  # i18n-allow: test input
        "erklär mir, wie ich vorgehe, um Routinen zu nutzen",  # i18n-allow: test input
        "",
    ],
)
def test_non_authoring_requests_are_ignored(utterance: str) -> None:
    assert is_skill_authoring_request(utterance) is False


# ---------------------------------------------------------------------------
# Lifecycle — switch off / on, delete, list, show a SKILL
# ---------------------------------------------------------------------------


@pytest.mark.parametrize(
    "utterance",
    [
        "deaktiviere den skill morgenroutine",  # i18n-allow: test input
        "aktiviere den skill morgenroutine",  # i18n-allow: test input
        "lösch den skill abendroutine",  # i18n-allow: test input
        "schalt den spotify skill aus",  # i18n-allow: test input
        "zeig mir meine skills",  # i18n-allow: test input
        "disable the youtube music skill",
        "remove the skill I created yesterday",
        "desactiva el skill de spotify",  # i18n-allow: test input
        "desativa o skill do spotify",  # i18n-allow: test input
        "mostra-me os meus skills",  # i18n-allow: test input
    ],
)
def test_lifecycle_requests_are_detected(utterance: str) -> None:
    assert is_skill_lifecycle_request(utterance) is True
    assert skill_meta_kind(utterance) == "lifecycle"


@pytest.mark.parametrize(
    "utterance",
    [
        "schalt das licht aus",  # i18n-allow: test input — no skill word: the smart-home connector's turn
        "mach die musik aus",  # i18n-allow: test input
        "welche skills habe ich",  # i18n-allow: test input — a question, answered not acted on
        "nutz den skill morning-routine bitte",  # i18n-allow: test input — a use, not a lifecycle
        "starte die morgenroutine",  # i18n-allow: test input
    ],
)
def test_non_lifecycle_requests_are_ignored(utterance: str) -> None:
    assert is_skill_lifecycle_request(utterance) is False


def test_creation_outranks_lifecycle_in_one_sentence() -> None:
    assert skill_meta_kind("erstell einen neuen skill und lösch den alten skill") == "authoring"  # i18n-allow: test input


def test_lifecycle_resolves_to_nobody_even_with_skill_creator_active() -> None:
    registry = _FakeRegistry(["plugin-youtube_music", AUTHORING_SKILL_NAME])
    resolution = resolve_skill_authoring_request("deaktiviere den youtube music skill", registry)  # i18n-allow: test input
    assert resolution is not None
    assert resolution.kind == "lifecycle"
    assert resolution.skill is None
    assert resolution.decision.top is None


# ---------------------------------------------------------------------------
# Resolution
# ---------------------------------------------------------------------------


def test_resolves_to_the_active_skill_creator_with_trigger_grade_rights() -> None:
    registry = _FakeRegistry(["plugin-youtube_music", AUTHORING_SKILL_NAME, "morning-routine"])
    resolution = resolve_skill_authoring_request(LIVE_UTTERANCE, registry)
    assert resolution is not None
    assert resolution.skill is not None
    assert resolution.skill.name == AUTHORING_SKILL_NAME
    assert resolution.decision.band == BAND_FIRE
    assert resolution.decision.source == SOURCE_TRIGGER
    assert resolution.decision.top is not None
    assert resolution.decision.top.skill_name == AUTHORING_SKILL_NAME


def test_resolves_to_nobody_when_skill_creator_is_not_active() -> None:
    """The protection does not depend on the builtin: a disabled skill-creator
    still means NO other skill may capture, and the create-skill tool owns it."""
    registry = _FakeRegistry(["plugin-youtube_music", "morning-routine"])
    resolution = resolve_skill_authoring_request(LIVE_UTTERANCE, registry)
    assert resolution is not None
    assert resolution.skill is None
    assert resolution.decision.band == BAND_NONE
    assert resolution.decision.top is None


def test_returns_none_for_a_non_authoring_request() -> None:
    registry = _FakeRegistry([AUTHORING_SKILL_NAME])
    assert resolve_skill_authoring_request("spiel musik auf youtube music", registry) is None  # i18n-allow: test input


def test_never_raises_on_a_broken_registry() -> None:
    class _Broken:
        def list_active(self):  # noqa: ANN202
            raise RuntimeError("boom")

    resolution = resolve_skill_authoring_request(LIVE_UTTERANCE, _Broken())
    assert resolution is not None
    assert resolution.skill is None
    assert resolve_skill_authoring_request(LIVE_UTTERANCE, None) is not None