Skip to content

Commit b37f678

Browse files
deploy: ef1e9f8
1 parent 038e916 commit b37f678

256 files changed

Lines changed: 928 additions & 505 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2.0/llms-full.txt

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12274,6 +12274,204 @@ async def long_task(items: list) -> dict:
1227412274

1227512275
This mirrors the standard-library precedent set by `asyncio.CancelledError` and `KeyboardInterrupt`.
1227612276

12277+
## Testing
12278+
12279+
Workflow authors should be able to test workflow code without a running server
12280+
or worker. The `durable_workflow.testing` module ships two entry points:
12281+
12282+
- `WorkflowEnvironment` drives a workflow to completion in a single Python
12283+
process against user-registered activity mocks.
12284+
- `replay_history` and `replay_history_file` replay a captured production
12285+
history against current workflow code and raise on any non-determinism.
12286+
12287+
Both entry points reuse the same `durable_workflow.workflow.replay` machinery
12288+
the worker uses at runtime, so a workflow that passes its test harness behaves
12289+
the same way under a real worker.
12290+
12291+
### WorkflowEnvironment
12292+
12293+
`WorkflowEnvironment` dispatches yielded workflow commands against registered
12294+
mocks and auto-fires timers, side effects, and search-attribute upserts. Tests
12295+
do not need a real clock, Redis, or server.
12296+
12297+
```python
12298+
from durable_workflow import workflow
12299+
from durable_workflow.testing import WorkflowEnvironment
12300+
12301+
@workflow.defn(name="greeter")
12302+
class Greeter:
12303+
def run(self, ctx, name: str):
12304+
greeting = yield ctx.schedule_activity("greet", [name])
12305+
return greeting
12306+
12307+
def test_greeter_returns_activity_result() -> None:
12308+
env = WorkflowEnvironment()
12309+
env.register_activity_result("greet", "hello, world")
12310+
12311+
result = env.execute_workflow(Greeter, "world")
12312+
12313+
assert result == "hello, world"
12314+
```
12315+
12316+
| Method | Purpose |
12317+
| --- | --- |
12318+
| `register_activity_result(name, result)` | Return `result` for every call to activity `name`. Use this when the test does not care about arguments. |
12319+
| `register_activity(name, fn)` | Call `fn(*arguments)` for each scheduled invocation of activity `name`. Use this when the mock must vary with arguments or capture invocations. |
12320+
| `register_child_workflow_result(workflow_type, result)` | Return `result` when the workflow starts a child of type `workflow_type`. |
12321+
| `signal(name, args=None)` | Queue a signal to be delivered before the next replay iteration. The harness injects a `SignalReceived` event and dispatches it to the registered `@workflow.signal` handler. |
12322+
| `execute_workflow(workflow_cls, *args, run_id="test-run")` | Drive the workflow to a terminal state and return its result. Raises `WorkflowFailed` when the workflow ends in the failed state. |
12323+
12324+
The harness fails loudly on missing fixtures:
12325+
12326+
- scheduling an activity that has no registered mock raises `KeyError`
12327+
- starting a child workflow that has no registered mock raises `KeyError`
12328+
- a workflow that never reaches a terminal state within the iteration limit
12329+
(default `1000`) raises `RuntimeError`
12330+
12331+
Pass `iteration_limit=...` to `WorkflowEnvironment(...)` to tune the cap for
12332+
workflows that legitimately iterate more than the default.
12333+
12334+
#### Callable activity mocks
12335+
12336+
Use `register_activity` when the mock needs to respond based on arguments or
12337+
record calls:
12338+
12339+
```python
12340+
def test_callable_mock_captures_arguments() -> None:
12341+
captured: list[str] = []
12342+
12343+
def record_greet(name: str) -> str:
12344+
captured.append(name)
12345+
return f"greeted:{name}"
12346+
12347+
env = WorkflowEnvironment()
12348+
env.register_activity("greet", record_greet)
12349+
12350+
assert env.execute_workflow(Greeter, "alice") == "greeted:alice"
12351+
assert captured == ["alice"]
12352+
```
12353+
12354+
#### Signals
12355+
12356+
Signals queued with `env.signal(...)` are drained before the next replay
12357+
iteration. The signal payload is wrapped in the same `{codec, blob}` envelope
12358+
the worker sees at runtime and dispatched to the workflow's registered
12359+
`@workflow.signal` handler:
12360+
12361+
```python
12362+
@workflow.defn(name="approval")
12363+
class Approval:
12364+
def __init__(self) -> None:
12365+
self.approved_by: str | None = None
12366+
12367+
@workflow.signal("approve")
12368+
def on_approve(self, by: str) -> None:
12369+
self.approved_by = by
12370+
12371+
def run(self, ctx):
12372+
yield ctx.schedule_activity("wait", [])
12373+
return {"approved_by": self.approved_by}
12374+
12375+
def test_signal_is_delivered_before_run_returns() -> None:
12376+
env = WorkflowEnvironment()
12377+
env.register_activity_result("wait", None)
12378+
env.signal("approve", ["alice"])
12379+
12380+
result = env.execute_workflow(Approval)
12381+
12382+
assert result == {"approved_by": "alice"}
12383+
```
12384+
12385+
#### Timers, side effects, and search attributes
12386+
12387+
The harness auto-fires the corresponding history event for each of these
12388+
commands, so workflows do not block on wall-clock time inside tests:
12389+
12390+
- `ctx.sleep(seconds)` → `TimerFired`
12391+
- `ctx.side_effect(...)` → `SideEffectRecorded`
12392+
- `ctx.upsert_search_attributes(...)` → `SearchAttributesUpserted`
12393+
- `workflow.version(...)` markers → `VersionMarkerRecorded`
12394+
12395+
`ContinueAsNew` is intentionally not supported in the harness; drive each run
12396+
explicitly with a separate `execute_workflow` call to assert continue-as-new
12397+
inputs deterministically.
12398+
12399+
#### Failure assertions
12400+
12401+
Workflows that raise a Python exception surface as `WorkflowFailed`:
12402+
12403+
```python
12404+
import pytest
12405+
from durable_workflow.errors import WorkflowFailed
12406+
12407+
@workflow.defn(name="failing")
12408+
class Failing:
12409+
def run(self, ctx):
12410+
yield ctx.schedule_activity("step", [])
12411+
raise RuntimeError("boom")
12412+
12413+
def test_workflow_failure_surfaces_as_workflow_failed() -> None:
12414+
env = WorkflowEnvironment()
12415+
env.register_activity_result("step", None)
12416+
12417+
with pytest.raises(WorkflowFailed) as exc_info:
12418+
env.execute_workflow(Failing)
12419+
12420+
assert "boom" in str(exc_info.value)
12421+
```
12422+
12423+
### Replay testing against production history
12424+
12425+
Use `replay_history` to regression-test a workflow change against a real
12426+
history captured from the server. The replayer runs the current workflow code
12427+
against the recorded event sequence and raises if it yields a different
12428+
command than the one history recorded — the definition of a non-determinism
12429+
bug.
12430+
12431+
```python
12432+
from durable_workflow import Client
12433+
from durable_workflow.testing import replay_history
12434+
12435+
async with Client("http://localhost:8080") as client:
12436+
history = await client.get_history("order-42", run_id="...")
12437+
12438+
replay_history(OrderWorkflow, history["events"], start_input=["order-42"])
12439+
```
12440+
12441+
A workflow that previously completed must still complete when replayed
12442+
against the same history. If the workflow code changed in a way that diverges
12443+
from the recorded sequence (reordered activity calls, removed branches,
12444+
changed activity types), `replay_history` raises so the regression is caught
12445+
in CI rather than in production.
12446+
12447+
`replay_history_file` is a convenience wrapper that reads a JSON file in
12448+
either of two shapes: a top-level list of events, or a dict with an `events`
12449+
key matching the `get_history` response shape:
12450+
12451+
```python
12452+
from durable_workflow.testing import replay_history_file
12453+
12454+
replay_history_file(
12455+
OrderWorkflow,
12456+
"tests/histories/order-42.json",
12457+
start_input=["order-42"],
12458+
)
12459+
```
12460+
12461+
Both functions accept an optional `payload_codec` override. Leave it unset to
12462+
use the codec the history recorded.
12463+
12464+
### Test Harness Reference
12465+
12466+
| Symbol | Purpose |
12467+
| --- | --- |
12468+
| `durable_workflow.testing.WorkflowEnvironment` | In-process test harness. Drive a workflow to completion against registered activity and child-workflow mocks. |
12469+
| `durable_workflow.testing.replay_history(workflow_cls, events, start_input=None, *, run_id="", payload_codec=None)` | Replay a history event sequence against current workflow code. Raises on non-determinism. |
12470+
| `durable_workflow.testing.replay_history_file(workflow_cls, path, start_input=None, *, run_id="", payload_codec=None)` | Load a JSON history from disk and replay it. Accepts either a top-level list of events or a dict with an `events` key. |
12471+
| `durable_workflow.errors.WorkflowFailed` | Raised by `execute_workflow` when the workflow terminates in the failed state. |
12472+
| `durable_workflow.errors.WorkflowCancelled` | Terminal state when the workflow was cancelled. Inherits from `BaseException`. |
12473+
| `durable_workflow.errors.WorkflowTerminated` | Terminal state when the workflow was terminated by the server. Inherits from `BaseException`. |
12474+
1227712475
## Payload Codecs
1227812476

1227912477
Every payload that crosses the worker-protocol boundary is codec-tagged. v2 ships a single language-neutral codec, **`avro`**, which is the Python SDK's default for every outgoing client and worker payload — matching the server, PHP, and every other polyglot SDK.

404.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414

1515
<link rel="search" type="application/opensearchdescription+xml" title="Durable Workflow" href="/opensearch.xml"><link rel="stylesheet" href="/assets/css/styles.bdb910b5.css">
16-
<link rel="preload" href="/assets/js/runtime~main.1e2dc8ff.js" as="script">
16+
<link rel="preload" href="/assets/js/runtime~main.55c78a9f.js" as="script">
1717
<link rel="preload" href="/assets/js/main.487c4086.js" as="script">
1818
</head>
1919
<body class="navigation-with-keyboard">
2020
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"dark")}()</script><div id="__docusaurus">
2121
<div role="region" aria-label="Skip to main content"><a class="skipToContent_fXgn" href="#docusaurus_skipToContent_fallback">Skip to main content</a></div><nav class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Toggle navigation bar" aria-expanded="false" class="navbar__toggle clean-btn" type="button"><svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/"><div class="navbar__logo"><img src="/img/logo.svg" alt="Workflow Logo" class="themedImage_ToTc themedImage--light_HNdA"><img src="/img/logo.svg" alt="Workflow Logo" class="themedImage_ToTc themedImage--dark_i4oU"></div><b class="navbar__title text--truncate">Durable Workflow</b></a><a class="navbar__item navbar__link" href="/docs/installation/">Docs</a><div class="navbar__item dropdown dropdown--hoverable"><a class="navbar__link" aria-haspopup="true" aria-expanded="false" role="button" href="/docs/introduction/">1.x</a><ul class="dropdown__menu"><li><a class="dropdown__link" href="/docs/2.0/introduction/">2.0</a></li><li><a class="dropdown__link" href="/docs/introduction/">1.x</a></li></ul></div><a class="navbar__item navbar__link" href="/blog/">Blog</a></div><div class="navbar__items navbar__items--right"><a href="https://github.com/durable-workflow/workflow" target="_blank" rel="noopener noreferrer" aria-label="Star Durable Workflow on GitHub" class="navbar-github-star-link navbar__item navbar__link" label="Star on GitHub"><svg aria-hidden="true" class="navbar-github-star-link__icon" viewBox="0 0 16 16"><path d="M8 0C3.58 0 0 3.58 0 8a8.01 8.01 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.5-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82A7.56 7.56 0 0 1 8 4.76c.68 0 1.36.09 2 .27 1.53-1.03 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.28.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8Z"></path></svg><span class="navbar-github-star-link__count" title="GitHub stars">1.2K</span></a><a href="https://github.com/durable-workflow/workflow" target="_blank" rel="noopener noreferrer" aria-label="Star Durable Workflow on GitHub" class="navbar-github-star-link navbar__link navbar-github-star-link--mobile-topbar" label="Star on GitHub"><svg aria-hidden="true" class="navbar-github-star-link__icon" viewBox="0 0 16 16"><path d="M8 0C3.58 0 0 3.58 0 8a8.01 8.01 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.5-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82A7.56 7.56 0 0 1 8 4.76c.68 0 1.36.09 2 .27 1.53-1.03 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.28.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8Z"></path></svg><span class="navbar-github-star-link__count" title="GitHub stars">1.2K</span></a><div class="toggle_vylO colorModeToggle_x44X"><button class="clean-btn toggleButton_gllP toggleButtonDisabled_aARS" type="button" disabled="" title="Switch between dark and light mode (currently dark mode)" aria-label="Switch between dark and light mode (currently dark mode)" aria-live="polite"><svg viewBox="0 0 24 24" width="24" height="24" class="lightToggleIcon_pyhR"><path fill="currentColor" d="M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.99c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06c-0.39,0.39-0.39,1.03,0,1.41 s1.03,0.39,1.41,0L19.42,5.99z M7.05,18.36c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06 c-0.39,0.39-0.39,1.03,0,1.41s1.03,0.39,1.41,0L7.05,18.36z"></path></svg><svg viewBox="0 0 24 24" width="24" height="24" class="darkToggleIcon_wfgR"><path fill="currentColor" d="M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27C17.45,17.19,14.93,19,12,19 c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z M12,3c-4.97,0-9,4.03-9,9s4.03,9,9,9s9-4.03,9-9c0-0.46-0.04-0.92-0.1-1.36 c-0.98,1.37-2.58,2.26-4.4,2.26c-2.98,0-5.4-2.42-5.4-5.4c0-1.81,0.89-3.42,2.26-4.4C12.92,3.04,12.46,3,12,3L12,3z"></path></svg></button></div><div class="searchBox_ZlJk"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><svg width="20" height="20" class="DocSearch-Search-Icon" viewBox="0 0 20 20"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"></span></button></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div></nav><div id="docusaurus_skipToContent_fallback" class="main-wrapper mainWrapper_z2l0"><main class="container margin-vert--xl"><div class="row"><div class="col col--6 col--offset-3"><h1 class="hero__title">Page Not Found</h1><p>We could not find what you were looking for.</p><p>Please contact the owner of the site that linked you to the original URL and let them know their link is broken.</p></div></div></main></div><div><footer class="footer footer--dark"><div class="container container-fluid"><div class="row footer__links"><div class="col footer__col"><div class="footer__title">Docs</div><ul class="footer__items clean-list"><li class="footer__item"><a class="footer__link-item" href="/docs/introduction/">Introduction</a></li><li class="footer__item"><a class="footer__link-item" href="/docs/installation/">Installation</a></li></ul></div><div class="col footer__col"><div class="footer__title">Community</div><ul class="footer__items clean-list"><li class="footer__item"><a href="https://discord.gg/xu5aDDpqVy" target="_blank" rel="noopener noreferrer" class="footer__link-item">Discord<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://x.com/DurableWorkflow" target="_blank" rel="noopener noreferrer" class="footer__link-item">X<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li></ul></div><div class="col footer__col"><div class="footer__title">More</div><ul class="footer__items clean-list"><li class="footer__item"><a href="https://durable-workflow.com/llms-full.txt" target="_blank" rel="noopener noreferrer" class="footer__link-item">LLM Docs<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://packagist.org/packages/durable-workflow/workflow" target="_blank" rel="noopener noreferrer" class="footer__link-item">Packagist<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li></ul></div></div><div class="footer__bottom text--center"><div class="footer__copyright">Copyright © 2026 <a href="https://durable-workflow.com">Durable Workflow</a>.</div></div></div></footer></div></div>
22-
<script src="/assets/js/runtime~main.1e2dc8ff.js"></script>
22+
<script src="/assets/js/runtime~main.55c78a9f.js"></script>
2323
<script src="/assets/js/main.487c4086.js"></script>
2424
</body>
2525
</html>

assets/js/6f1c5ced.c4c6ad77.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/6f1c5ced.dfab9d76.js

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

blog/ai-image-moderation-with-laravel-workflow/index.html

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)