half an attempt to asyncify tests + deprecate old temp path creation

This commit is contained in:
lda
2026-06-11 05:01:33 +07:00 Verified
parent d695fd7533
commit 9dae4a8445
32 changed files with 782 additions and 753 deletions
+8 -12
View File
@@ -1,7 +1,5 @@
from __future__ import annotations
import asyncio
from pydantic import BaseModel
from wf_authoring import build_async_registry, node
@@ -33,7 +31,7 @@ class InferredAsyncOutput(BaseModel):
echoed: str
def test_async_registry_accepts_sync_and_async_specs() -> None:
async def test_async_registry_accepts_sync_and_async_specs() -> None:
@node()
def sync_echo(
payload: InferredEchoInput,
@@ -54,14 +52,14 @@ def test_async_registry_accepts_sync_and_async_specs() -> None:
async def run_handler(name: str, value: str) -> dict[str, object]:
return await registry[name]({"value": value}, ctx)
sync_result = asyncio.run(run_handler("sync_echo", "hello"))
async_result = asyncio.run(run_handler("async_echo", "world"))
sync_result = await run_handler("sync_echo", "hello")
async_result = await run_handler("async_echo", "world")
assert sync_result == {"outcome": "ok", "output": {"echoed": "hello"}}
assert async_result == {"outcome": "ok", "output": {"echoed": "async:world"}}
def test_execute_workflow_async_runs_with_async_registry() -> None:
async def test_execute_workflow_async_runs_with_async_registry() -> None:
workflow, _ = build_authoring_demo_workflow()
registry = build_async_registry(
drive_list_files_spec,
@@ -71,12 +69,10 @@ def test_execute_workflow_async_runs_with_async_registry() -> None:
mark_email_skipped_spec,
)
run = asyncio.run(
execute_workflow_async(
workflow,
{"folder_id": "demo-folder", "should_email": False},
registry,
)
run = await execute_workflow_async(
workflow,
{"folder_id": "demo-folder", "should_email": False},
registry,
)
assert run.status == RunStatus.COMPLETED
@@ -1,6 +1,5 @@
from __future__ import annotations
import asyncio
from typing import Any, cast
import pytest
@@ -33,8 +32,8 @@ def test_authoring_concurrent_foreach_collects_item_errors() -> None:
assert error["item"] == "bad"
def test_authoring_async_concurrent_foreach_commits_in_item_order() -> None:
run = asyncio.run(run_async_ordered_example())
async def test_authoring_async_concurrent_foreach_commits_in_item_order() -> None:
run = await run_async_ordered_example()
assert run.status == RunStatus.COMPLETED
assert run.output["seen"] == ["a", "b", "c"]
+5 -9
View File
@@ -1,7 +1,5 @@
from __future__ import annotations
import asyncio
from pydantic import BaseModel
from examples.authoring_workflow_as_node import (
@@ -63,7 +61,7 @@ def test_subgraph_node_wraps_compiled_workflow() -> None:
assert "summary" in result["output"]
def test_async_subgraph_node_wraps_async_compiled_workflow() -> None:
async def test_async_subgraph_node_wraps_async_compiled_workflow() -> None:
class ChildInput(BaseModel):
text: str
@@ -114,12 +112,10 @@ def test_async_subgraph_node_wraps_async_compiled_workflow() -> None:
parent.set_entry_point(step)
parent.connect(step, "ok", END)
run = asyncio.run(
execute_workflow_async(
parent.compile(),
{"text": "hello"},
build_async_registry(wrapped),
)
run = await execute_workflow_async(
parent.compile(),
{"text": "hello"},
build_async_registry(wrapped),
)
assert run.status == RunStatus.COMPLETED