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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
"""Smoke tests for the workflow system.
Scope:
- Store CRUD (insert, list, upsert, run-create, run-step-update).
- Seed idempotency.
- Runner with fake brain: brain_prompt step produces the expected output.
- Runner with template expansion (``{{prev.output}}`` + ``{{input.X}}``).
- Runner error path: speak without a broken dep goes through, tool_call without a registry fails cleanly.
No real brain providers, no real SQLite file on disk — everything is
tempdir + fakes. The pattern mirrors ``tests/unit/clis/test_smoke.py`` etc.
"""
from __future__ import annotations
from pathlib import Path
import pytest
from dodaios.core.bus import EventBus
from dodaios.workflows import (
WorkflowRunner,
WorkflowStore,
ensure_seed_workflows,
)
from dodaios.workflows.schema import (
BrainPromptStep,
CronTrigger,
HarnessDispatchStep,
ManualTrigger,
ShellCmdStep,
SpeakStep,
WorkflowDef,
)
# ----------------------------------------------------------------------
# Fixtures
# ----------------------------------------------------------------------
@pytest.fixture
async def store(tmp_path: Path) -> WorkflowStore:
s = WorkflowStore(tmp_path / "wf.sqlite")
await s.init()
yield s
await s.close()
class FakeBrain:
"""Async callable that echoes the prompt — sufficient for runner tests."""
def __init__(self) -> None:
self.calls: list[str] = []
async def __call__(self, prompt: str) -> str:
self.calls.append(prompt)
return f"ECHO: {prompt[:80]}"
# ----------------------------------------------------------------------
# Store
# ----------------------------------------------------------------------
async def test_store_upsert_and_list(store: WorkflowStore) -> None:
wf = WorkflowDef(
name="Test",
description="smoke",
trigger=ManualTrigger(),
steps=(SpeakStep(text="hi"),),
)
wid = await store.upsert_workflow(wf)
rows = await store.list_workflows()
assert len(rows) == 1
assert rows[0]["id"] == wid
assert rows[0]["name"] == "Test"
assert rows[0]["trigger_type"] == "manual"
async def test_store_cron_trigger_persists_expression(store: WorkflowStore) -> None:
wf = WorkflowDef(
name="Cron",
trigger=CronTrigger(expression="30 7 * * *"),
steps=(SpeakStep(text="hi"),),
)
await store.upsert_workflow(wf)
rows = await store.list_workflows()
assert rows[0]["trigger_type"] == "cron"
assert rows[0]["cron_expression"] == "30 7 * * *"
async def test_store_upsert_is_idempotent(store: WorkflowStore) -> None:
wf = WorkflowDef(
name="X",
trigger=ManualTrigger(),
steps=(SpeakStep(text="a"),),
)
wid1 = await store.upsert_workflow(wf)
wid2 = await store.upsert_workflow(wf)
assert wid1 == wid2
rows = await store.list_workflows()
assert len(rows) == 1
async def test_seed_is_idempotent(store: WorkflowStore) -> None:
first = await ensure_seed_workflows(store)
# The current seed count derives from SEED_WORKFLOWS — robust against additions.
from dodaios.workflows.seed import SEED_WORKFLOWS
assert first == len(SEED_WORKFLOWS)
second = await ensure_seed_workflows(store)
assert second == 0
async def test_code_review_seed_has_no_phantom_harness(store: WorkflowStore) -> None:
from dodaios.workflows.seed import SEED_WORKFLOWS
code_review = next(wf for wf in SEED_WORKFLOWS if wf.name == "Code Review")
assert isinstance(code_review.steps[0], ShellCmdStep)
assert not any(isinstance(step, HarnessDispatchStep) for step in code_review.steps)
async def test_legacy_openclaw_seed_is_migrated(store: WorkflowStore) -> None:
from dodaios.workflows.seed import SEED_WORKFLOWS
replacement = next(wf for wf in SEED_WORKFLOWS if wf.name == "Code Review")
legacy = replacement.model_copy(update={
"steps": (
HarnessDispatchStep(
label="Legacy dispatch",
harness="openclaw",
prompt="Review the pending changes in this repository.",
),
),
"tags": ("demo", "harness", "git"),
})
await store.upsert_workflow(legacy)
added = await ensure_seed_workflows(store)
migrated = await store.get_def(str(replacement.id))
assert added == len(SEED_WORKFLOWS) - 1
assert migrated is not None
assert isinstance(migrated.steps[0], ShellCmdStep)
async def test_runs_crud(store: WorkflowStore) -> None:
wf = WorkflowDef(
name="X",
trigger=ManualTrigger(),
steps=(SpeakStep(text="a"),),
)
wid = await store.upsert_workflow(wf)
run_id = await store.create_run(wid, trigger="manual")
await store.update_run_state(run_id, "running")
await store.start_step(run_id, 1, "speak", "say hi")
await store.finish_step(run_id, 1, success=True, output="hi")
await store.update_run_state(run_id, "completed")
run = await store.get_run(run_id)
assert run is not None
assert run["state"] == "completed"
assert len(run["steps"]) == 1
assert run["steps"][0]["success"] == 1
# ----------------------------------------------------------------------
# Runner
# ----------------------------------------------------------------------
async def test_runner_brain_prompt_executes_and_publishes_events(
store: WorkflowStore,
) -> None:
bus = EventBus()
captured: list[str] = []
bus.subscribe_all(lambda e: captured.append(type(e).__name__))
brain = FakeBrain()
runner = WorkflowRunner(store=store, bus=bus, brain=brain)
wf = WorkflowDef(
name="Echo",
trigger=ManualTrigger(),
steps=(
BrainPromptStep(prompt="sag hallo", max_output_chars=500),
SpeakStep(text="{{prev.output}}"),
),
)
wid = await store.upsert_workflow(wf)
run_id = await runner.trigger(wid)
# Wait one micro-turn — the runner runs as an asyncio.create_task.
import asyncio
for _ in range(50):
await asyncio.sleep(0.01)
run = await store.get_run(run_id)
if run and run["state"] == "completed":
break
else:
pytest.fail("Run did not finish within 500ms")
assert brain.calls == ["sag hallo"]
run = await store.get_run(run_id)
assert run["state"] == "completed"
assert len(run["steps"]) == 2
# Step 1: brain_prompt → ECHO-Text
assert "ECHO:" in run["steps"][0]["output"]
# Step 2: speak hat prev.output via Template expanded bekommen
assert "ECHO:" in run["steps"][1]["output"]
# Event-Sequenz: WorkflowStarted, WorkflowStepStarted x2, WorkflowStepCompleted x2,
# WorkflowCompleted, plus AnnouncementRequested vom Speak-Step.
assert "WorkflowStarted" in captured
assert "WorkflowCompleted" in captured
assert captured.count("WorkflowStepStarted") == 2
assert captured.count("WorkflowStepCompleted") == 2
assert "AnnouncementRequested" in captured
async def test_runner_input_variable_expansion(store: WorkflowStore) -> None:
bus = EventBus()
brain = FakeBrain()
runner = WorkflowRunner(store=store, bus=bus, brain=brain)
wf = WorkflowDef(
name="URL",
trigger=ManualTrigger(),
steps=(
BrainPromptStep(prompt="Fasse {{input.url}} zusammen"),
),
)
wid = await store.upsert_workflow(wf)
run_id = await runner.trigger(wid, input_data={"url": "https://x.test"})
import asyncio
for _ in range(50):
await asyncio.sleep(0.01)
run = await store.get_run(run_id)
if run and run["state"] == "completed":
break
else:
pytest.fail("Run not finished")
assert brain.calls == ["Fasse https://x.test zusammen"]
async def test_runner_without_brain_fails_cleanly(store: WorkflowStore) -> None:
"""brain_prompt without a BrainManager → clean error state, no crash."""
bus = EventBus()
runner = WorkflowRunner(store=store, bus=bus, brain=None)
wf = WorkflowDef(
name="No-Brain",
trigger=ManualTrigger(),
steps=(BrainPromptStep(prompt="hi"),),
)
wid = await store.upsert_workflow(wf)
run_id = await runner.trigger(wid)
import asyncio
for _ in range(50):
await asyncio.sleep(0.01)
run = await store.get_run(run_id)
if run and run["state"] in ("completed", "failed"):
break
run = await store.get_run(run_id)
assert run["state"] == "failed"
assert "Brain" in (run["error"] or "")
# ----------------------------------------------------------------------
# External-Integration-Steps (shell_cmd + telegram_send)
# ----------------------------------------------------------------------
async def test_runner_shell_cmd_captures_stdout(
store: WorkflowStore, tmp_path: Path,
) -> None:
"""shell_cmd with a simple Python script — stdout lands in output.
A file-based script avoids the escaping hell of ``-c "print(...)"``
on Windows and tests the realistic case (gws/git-style CLI).
"""
import sys
from dodaios.workflows.schema import ShellCmdStep
script = tmp_path / "echo.py"
script.write_text("print('hallo_workflow')", encoding="utf-8")
bus = EventBus()
runner = WorkflowRunner(store=store, bus=bus)
cmd = f'"{sys.executable}" "{script}"'
wf = WorkflowDef(
name="Shell-Echo",
trigger=ManualTrigger(),
steps=(ShellCmdStep(command=cmd, timeout_s=10.0),),
)
wid = await store.upsert_workflow(wf)
run_id = await runner.trigger(wid)
import asyncio
for _ in range(200):
await asyncio.sleep(0.02)
run = await store.get_run(run_id)
if run and run["state"] in ("completed", "failed"):
break
run = await store.get_run(run_id)
assert run["state"] == "completed", f"Runner failed: {run['error']}"
assert "hallo_workflow" in run["steps"][0]["output"]
async def test_runner_shell_cmd_nonzero_exit_fails(
store: WorkflowStore, tmp_path: Path,
) -> None:
"""Exit-Code != 0 → Step failed + Error-Text."""
import sys
from dodaios.workflows.schema import ShellCmdStep
script = tmp_path / "fail.py"
script.write_text("import sys; sys.exit(7)", encoding="utf-8")
bus = EventBus()
runner = WorkflowRunner(store=store, bus=bus)
cmd = f'"{sys.executable}" "{script}"'
wf = WorkflowDef(
name="Shell-Fail",
trigger=ManualTrigger(),
steps=(ShellCmdStep(command=cmd, timeout_s=5.0),),
)
wid = await store.upsert_workflow(wf)
run_id = await runner.trigger(wid)
import asyncio
for _ in range(200):
await asyncio.sleep(0.02)
run = await store.get_run(run_id)
if run and run["state"] in ("completed", "failed"):
break
run = await store.get_run(run_id)
assert run["state"] == "failed"
err = (run["error"] or "").lower()
assert "exit_code" in err or "7" in err
async def test_runner_telegram_without_token_fails_cleanly(
store: WorkflowStore, monkeypatch: pytest.MonkeyPatch,
) -> None:
"""telegram_send without a token → clean error with setup hint."""
from dodaios.workflows.schema import TelegramSendStep
# Token lookup guaranteed empty. monkeypatch makes sure no
# logged-in keyring key from the real dev machine gets read in.
monkeypatch.delenv("TELEGRAM_BOT_TOKEN", raising=False)
monkeypatch.setattr(
"dodaios.core.config.get_secret",
lambda key, env_fallback=None: None,
)
bus = EventBus()
runner = WorkflowRunner(store=store, bus=bus)
wf = WorkflowDef(
name="TG-No-Token",
trigger=ManualTrigger(),
steps=(TelegramSendStep(text="hi"),),
)
wid = await store.upsert_workflow(wf)
run_id = await runner.trigger(wid)
import asyncio
for _ in range(50):
await asyncio.sleep(0.01)
run = await store.get_run(run_id)
if run and run["state"] in ("completed", "failed"):
break
run = await store.get_run(run_id)
assert run["state"] == "failed"
err = run["error"] or ""
assert "telegram" in err.lower()
assert "token" in err.lower()
async def test_runner_telegram_posts_to_api(
store: WorkflowStore, monkeypatch: pytest.MonkeyPatch,
) -> None:
"""telegram_send with token + chat ID → POST to the bot API, payload correct.
We mock ``httpx.AsyncClient.post`` to return a 200 OK and
check that the body contains chat_id/text as expected.
"""
from dodaios.workflows.schema import TelegramSendStep
monkeypatch.setenv("TELEGRAM_BOT_TOKEN", "TESTTOKEN")
monkeypatch.setattr(
"dodaios.core.config.get_secret",
lambda key, env_fallback=None: "TESTTOKEN" if key == "telegram_bot_token" else None,
)
captured_payloads: list[dict] = []
class _FakeResp:
status_code = 200
def json(self) -> dict:
return {"ok": True}
class _FakeClient:
def __init__(self, *_, **__): pass
async def __aenter__(self): return self
async def __aexit__(self, *_): return False
async def post(self, url: str, json: dict): # noqa: A002
captured_payloads.append({"url": url, "body": json})
return _FakeResp()
monkeypatch.setattr("httpx.AsyncClient", _FakeClient)
bus = EventBus()
runner = WorkflowRunner(store=store, bus=bus)
wf = WorkflowDef(
name="TG-Send",
trigger=ManualTrigger(),
steps=(TelegramSendStep(text="hallo von jarvis", chat_id="987654"),),
)
wid = await store.upsert_workflow(wf)
run_id = await runner.trigger(wid)
import asyncio
for _ in range(50):
await asyncio.sleep(0.01)
run = await store.get_run(run_id)
if run and run["state"] in ("completed", "failed"):
break
run = await store.get_run(run_id)
assert run["state"] == "completed", f"Error: {run['error']}"
assert len(captured_payloads) == 1
body = captured_payloads[0]["body"]
assert body["chat_id"] == "987654"
assert body["text"] == "hallo von jarvis"
assert "TESTTOKEN" in captured_payloads[0]["url"]
# ----------------------------------------------------------------------
# Runtime dependency attachment (audit AU-03)
# ----------------------------------------------------------------------
#
# The runner defined ``attach_harness_manager`` and ``attach_tools`` but the
# bootstrap never called them, so EVERY ``tool_call`` step died on "Tool
# registry/executor not available" and every ``harness_dispatch`` step on
# "No HarnessManager available". These two tests pin the wiring down.
class FakeTool:
"""Minimal Tool stand-in — the executor is what calls it, not the runner."""
name = "note_down"
def __init__(self) -> None:
self.calls: list[dict] = []
class FakeToolExecutor:
"""Stands in for ToolExecutor — records the call, returns a ToolResult."""
def __init__(self) -> None:
self.calls: list[tuple[str, dict, str]] = []
async def execute(self, tool, args: dict, **kwargs): # noqa: ANN001
from dodaios.core.protocols import ToolResult
self.calls.append((tool.name, dict(args), kwargs.get("user_utterance", "")))
tool.calls.append(dict(args))
return ToolResult(success=True, output={"stored": args.get("text")})
class FakeBrainWithTools:
"""Brain stand-in exposing the two attributes BrainToolSurface reads."""
def __init__(self, tools: dict, executor: FakeToolExecutor) -> None:
self._tools = tools
self._executor = executor
@property
def _tool_executor_ref(self) -> FakeToolExecutor:
return self._executor
async def test_runner_tool_call_reaches_the_tool_via_attached_brain_surface(
store: WorkflowStore,
) -> None:
"""``tool_call`` runs the tool once the brain surface is attached.
Also covers the reason the surface is a live view: the brain replaces
``_tools`` wholesale on every ``refresh_tools()`` (each CLI/MCP connect),
so we swap the dict AFTER attaching and the runner must still find the
tool the brain holds *now*.
"""
from dodaios.workflows.runner import BrainToolSurface
from dodaios.workflows.schema import ToolCallStep
executor = FakeToolExecutor()
brain = FakeBrainWithTools({}, executor)
bus = EventBus()
runner = WorkflowRunner(store=store, bus=bus)
surface = BrainToolSurface(lambda: brain)
runner.attach_tools(surface, surface)
# The tool only shows up after the attachment — as it does in the real
# bootstrap, where the brain builds in the background.
tool = FakeTool()
brain._tools = {"note_down": tool}
wf = WorkflowDef(
name="Tool-Call",
trigger=ManualTrigger(),
steps=(
BrainPromptStep(prompt="what is going on"),
ToolCallStep(tool_name="note_down", args={"text": "{{prev.output}}"}),
),
)
# brain_prompt feeds the tool arg, so the template path is covered too.
runner.attach_brain(FakeBrain())
wid = await store.upsert_workflow(wf)
run_id = await runner.trigger(wid)
import asyncio
for _ in range(200):
await asyncio.sleep(0.02)
run = await store.get_run(run_id)
if run and run["state"] in ("completed", "failed"):
break
run = await store.get_run(run_id)
assert run["state"] == "completed", f"Runner failed: {run['error']}"
assert len(executor.calls) == 1
tool_name, args, utterance = executor.calls[0]
assert tool_name == "note_down"
assert args["text"].startswith("ECHO:")
assert utterance == "<workflow:note_down>"
assert tool.calls == [args]
assert "stored" in run["steps"][1]["output"]
async def test_runner_harness_dispatch_reaches_the_attached_manager(
store: WorkflowStore,
) -> None:
"""``harness_dispatch`` streams from the manager instead of raising."""
from dodaios.core.protocols import HarnessResult
class FakeHarnessManager:
def __init__(self) -> None:
self.dispatched: list[tuple[str, str, bool]] = []
async def dispatch(self, name: str, task): # noqa: ANN001
self.dispatched.append((name, task.prompt, task.allow_computer_use))
yield HarnessResult(stdout="window focused")
yield HarnessResult(stdout="", exit_code=0, is_final=True)
manager = FakeHarnessManager()
bus = EventBus()
runner = WorkflowRunner(store=store, bus=bus)
runner.attach_harness_manager(manager)
wf = WorkflowDef(
name="Harness-Dispatch",
trigger=ManualTrigger(),
steps=(
HarnessDispatchStep(
harness="jarvis_agent",
prompt="bring the window to the front",
allow_computer_use=True,
),
),
)
wid = await store.upsert_workflow(wf)
run_id = await runner.trigger(wid)
import asyncio
for _ in range(200):
await asyncio.sleep(0.02)
run = await store.get_run(run_id)
if run and run["state"] in ("completed", "failed"):
break
run = await store.get_run(run_id)
assert run["state"] == "completed", f"Runner failed: {run['error']}"
assert manager.dispatched == [
("jarvis_agent", "bring the window to the front", True)
]
assert run["steps"][0]["output"] == "window focused"
# ----------------------------------------------------------------------
# Speak-step language
# ----------------------------------------------------------------------
def test_speak_step_language_defaults_to_auto() -> None:
assert SpeakStep(text="hi").language == "auto"
@pytest.mark.parametrize(
("pinned", "expected"),
[("auto", "pt"), ("", "pt"), ("es", "es"), ("de", "de")],
)
async def test_speak_step_follows_ambient_language_unless_pinned(
store: WorkflowStore,
monkeypatch: pytest.MonkeyPatch,
pinned: str,
expected: str,
) -> None:
"""An unpinned speak step speaks the ambient answer language at run time;
an explicit language on the persisted step still wins."""
import asyncio
from dodaios.core.events import AnnouncementRequested
from dodaios.workflows import runner as runner_module
monkeypatch.setattr(runner_module, "resolve_ambient_language", lambda: "pt")
bus = EventBus()
spoken: list[AnnouncementRequested] = []
bus.subscribe(AnnouncementRequested, spoken.append)
runner = WorkflowRunner(store=store, bus=bus, brain=FakeBrain())
wf = WorkflowDef(
name="Speak",
trigger=ManualTrigger(),
steps=(SpeakStep(text="hello", language=pinned),),
)
wid = await store.upsert_workflow(wf)
run_id = await runner.trigger(wid)
for _ in range(50):
await asyncio.sleep(0.01)
run = await store.get_run(run_id)
if run and run["state"] == "completed":
break
else:
pytest.fail("Run did not finish within 500ms")
announcements = [e for e in spoken if e.text == "hello"]
assert [e.language for e in announcements] == [expected]